BTRFS_BLOCK_GROUP_METADATA |
BTRFS_BLOCK_GROUP_DATA);
if (ret == -ENOSPC) {
- fprintf(stderr,
- "no space to allocate data/metadata chunk\n");
+ error("no space to allocate data/metadata chunk");
goto err;
}
BUG_ON(ret);
&chunk_start, &chunk_size,
BTRFS_BLOCK_GROUP_METADATA);
if (ret == -ENOSPC) {
- fprintf(stderr, "no space to allocate metadata chunk\n");
+ error("no space to allocate metadata chunk");
goto err;
}
BUG_ON(ret);
&chunk_start, &chunk_size,
BTRFS_BLOCK_GROUP_DATA);
if (ret == -ENOSPC) {
- fprintf(stderr, "no space to allocate data chunk\n");
+ error("no space to allocate data chunk");
goto err;
}
BUG_ON(ret);
ret = btrfs_alloc_chunk(trans, root->fs_info->extent_root,
&chunk_start, &chunk_size, type);
if (ret == -ENOSPC) {
- fprintf(stderr, "not enough free space\n");
+ error("not enough free space to allocate chunk");
exit(1);
}
BUG_ON(ret);
} else if (strcasecmp(s, "single") == 0) {
return 0;
} else {
- fprintf(stderr, "Unknown profile %s\n", s);
+ error("unknown profile %s", s);
exit(1);
}
/* not reached */
int len = strlen(input);
if (len >= BTRFS_LABEL_SIZE) {
- fprintf(stderr, "Label %s is too long (max %d)\n", input,
+ error("label %s is too long (max %d)", input,
BTRFS_LABEL_SIZE - 1);
exit(1);
}
if (ret < 0) {
if(errno == ENOTSUP)
return 0;
- fprintf(stderr, "get a list of xattr failed for %s\n",
- file_name);
+ error("getting a list of xattr failed for %s: %s", file_name,
+ strerror(errno));
return ret;
}
if (ret == 0)
if (ret < 0) {
if(errno == ENOTSUP)
return 0;
- fprintf(stderr, "get a xattr value failed for %s attr %s\n",
- file_name, cur_name);
+ error("gettig a xattr value failed for %s attr %s: %s",
+ file_name, cur_name, strerror(errno));
return ret;
}
cur_name_len, cur_value,
ret, objectid);
if (ret) {
- fprintf(stderr, "insert a xattr item failed for %s\n",
- file_name);
+ error("inserting a xattr item failed for %s: %s",
+ file_name, strerror(-ret));
}
cur_name = strtok(next_location, &delimiter);
ret = readlink(path_name, buf, sizeof(buf));
if (ret <= 0) {
- fprintf(stderr, "readlink failed for %s\n", path_name);
+ error("readlink failed for %s: %s", path_name, strerror(errno));
goto fail;
}
if (ret >= sizeof(buf)) {
- fprintf(stderr, "symlink too long for %s\n", path_name);
+ error("symlink too long for %s", path_name);
ret = -1;
goto fail;
}
fd = open(path_name, O_RDONLY);
if (fd == -1) {
- fprintf(stderr, "%s open failed\n", path_name);
+ error("cannot open %s: %s", path_name, strerror(errno));
return ret;
}
ret_read = pread64(fd, buffer, st->st_size, bytes_read);
if (ret_read == -1) {
- fprintf(stderr, "%s read failed\n", path_name);
+ error("cannot read %s at offset %llu length %llu: %s",
+ path_name, (unsigned long long)bytes_read,
+ (unsigned long long)st->st_size,
+ strerror(errno));
free(buffer);
goto end;
}
ret_read = pread64(fd, eb->data, sectorsize, file_pos + bytes_read);
if (ret_read == -1) {
- fprintf(stderr, "%s read failed\n", path_name);
+ error("cannot read %s at offset %llu length %llu: %s",
+ path_name,
+ (unsigned long long)file_pos + bytes_read,
+ (unsigned long long)sectorsize,
+ strerror(errno));
goto end;
}
ret = write_and_map_eb(trans, root, eb);
if (ret) {
- fprintf(stderr, "output file write failed\n");
+ error("failed to write %s", path_name);
goto end;
}
dir_entry->dir_name = dir_name;
dir_entry->path = realpath(dir_name, real_path);
if (!dir_entry->path) {
- fprintf(stderr, "get directory real path error\n");
+ error("realpath failed for %s: %s", dir_name, strerror(errno));
ret = -1;
goto fail_no_dir;
}
btrfs_set_key_type(&root_dir_key, BTRFS_INODE_ITEM_KEY);
ret = btrfs_lookup_inode(trans, root, &path, &root_dir_key, 1);
if (ret) {
- fprintf(stderr, "root dir lookup error\n");
+ error("failed to lookup root dir: %d", ret);
goto fail_no_dir;
}
parent_inum = parent_dir_entry->inum;
parent_dir_name = parent_dir_entry->dir_name;
if (chdir(parent_dir_entry->path)) {
- fprintf(stderr, "chdir error for %s\n",
- parent_dir_name);
+ error("chdir failed for %s: %s",
+ parent_dir_name, strerror(errno));
ret = -1;
goto fail_no_files;
}
directory_select, NULL);
if (count == -1)
{
- fprintf(stderr, "scandir for %s failed: %s\n",
+ error("scandir failed for %s: %s",
parent_dir_name, strerror (errno));
ret = -1;
goto fail;
cur_file = files[i];
if (lstat(cur_file->d_name, &st) == -1) {
- fprintf(stderr, "lstat failed for file %s\n",
- cur_file->d_name);
+ error("lstat failed for %s: %s",
+ cur_file->d_name, strerror(errno));
ret = -1;
goto fail;
}
cur_file->d_name,
&st, &dir_index_cnt);
if (ret) {
- fprintf(stderr, "add_directory_items failed\n");
+ error("unable to add directory items for %s: %d",
+ cur_file->d_name, ret);
goto fail;
}
continue;
}
if (ret) {
- fprintf(stderr, "add_inode_items failed\n");
+ error("unable to add inode items for %s: %d",
+ cur_file->d_name, ret);
goto fail;
}
ret = add_xattr_item(trans, root,
cur_inum, cur_file->d_name);
if (ret) {
- fprintf(stderr, "add_xattr_item failed\n");
+ error("unable to add xattr items for %s: %d",
+ cur_file->d_name, ret);
if(ret != -ENOTSUP)
goto fail;
}
cur_inum, parent_inum, &st,
cur_file->d_name, out_fd);
if (ret) {
- fprintf(stderr, "add_file_items failed\n");
+ error("unable to add file items for %s: %d",
+ cur_file->d_name, ret);
goto fail;
}
} else if (S_ISLNK(st.st_mode)) {
ret = add_symbolic_link(trans, root,
cur_inum, cur_file->d_name);
if (ret) {
- fprintf(stderr, "add_symbolic_link failed\n");
+ error("unable to add symlink for %s: %d",
+ cur_file->d_name, ret);
goto fail;
}
}
ret = lstat(source_dir, &root_st);
if (ret) {
- fprintf(stderr, "unable to lstat the %s\n", source_dir);
+ error("unable to lstat %s: %s", source_dir, strerror(errno));
goto out;
}
trans = btrfs_start_transaction(root, 1);
ret = traverse_directory(trans, root, source_dir, &dir_head, out_fd);
if (ret) {
- fprintf(stderr, "unable to traverse_directory\n");
+ error("unable to traverse directory %s: %d", source_dir, ret);
goto fail;
}
btrfs_commit_transaction(trans, root);
ret = ftw(dir_name, ftw_add_entry_size, 10);
dir_size = global_total_size;
if (ret < 0) {
- fprintf(stderr, "ftw subdir walk of '%s' failed: %s\n",
- dir_name, strerror(errno));
+ error("ftw subdir walk of %s failed: %s", dir_name,
+ strerror(errno));
exit(1);
}
data_profile_opt = 1;
break;
case 'l':
- fprintf(stderr,
- "WARNING: --leafsize is deprecated, use --nodesize\n");
+ warning("--leafsize is deprecated, use --nodesize");
case 'n':
nodesize = parse_size(optarg);
nodesize_forced = 1;
tmp = btrfs_parse_fs_features(tmp, &features);
if (tmp) {
- fprintf(stderr,
- "Unrecognized filesystem feature '%s'\n",
+ error("unrecognized filesystem feature '%s'",
tmp);
free(orig);
exit(1);
print_usage(1);
if (source_dir_set && dev_cnt > 1) {
- fprintf(stderr,
- "The -r option is limited to a single device\n");
+ error("the option -r is limited to a single device");
exit(1);
}
uuid_t dummy_uuid;
if (uuid_parse(fs_uuid, dummy_uuid) != 0) {
- fprintf(stderr, "could not parse UUID: %s\n", fs_uuid);
+ error("could not parse UUID: %s", fs_uuid);
exit(1);
}
if (!test_uuid_unique(fs_uuid)) {
- fprintf(stderr, "non-unique UUID: %s\n", fs_uuid);
+ error("non-unique UUID: %s", fs_uuid);
exit(1);
}
}
if (metadata_profile_opt || data_profile_opt) {
if (metadata_profile != data_profile) {
- fprintf(stderr,
- "ERROR: With mixed block groups data and metadata profiles must be the same\n");
+ error(
+ "with mixed block groups data and metadata profiles must be the same");
exit(1);
}
}
/* Check device/block_count after the nodesize is determined */
if (block_count && block_count < btrfs_min_dev_size(nodesize)) {
- fprintf(stderr,
- "Size '%llu' is too small to make a usable filesystem\n",
+ error("size %llu is too small to make a usable filesystem",
block_count);
- fprintf(stderr,
- "Minimum size for btrfs filesystem is %llu\n",
+ error("minimum size for btrfs filesystem is %llu",
btrfs_min_dev_size(nodesize));
exit(1);
}
path = argv[i];
ret = test_minimum_size(path, nodesize);
if (ret < 0) {
- fprintf(stderr, "Failed to check size for '%s': %s\n",
+ error("failed to check size for %s: %s",
path, strerror(-ret));
exit (1);
}
if (ret > 0) {
- fprintf(stderr,
- "'%s' is too small to make a usable filesystem\n",
+ error("'%s' is too small to make a usable filesystem",
path);
- fprintf(stderr,
- "Minimum size for each btrfs device is %llu.\n",
+ error("minimum size for each btrfs device is %llu",
btrfs_min_dev_size(nodesize));
exit(1);
}
*/
fd = open(file, O_RDWR);
if (fd < 0) {
- fprintf(stderr, "unable to open %s: %s\n", file,
- strerror(errno));
+ error("unable to open %s: %s", file, strerror(errno));
exit(1);
}
ret = btrfs_prepare_device(fd, file, &dev_block_count,
exit(1);
}
if (block_count && block_count > dev_block_count) {
- fprintf(stderr, "%s is smaller than requested size\n", file);
+ error("%s is smaller than requested size, expected %llu, found %llu",
+ file,
+ (unsigned long long)block_count,
+ (unsigned long long)dev_block_count);
exit(1);
}
} else {
fd = open_target(file);
if (fd < 0) {
- fprintf(stderr, "unable to open the %s\n", file);
+ error("unable to open %s: %s", file, strerror(errno));
exit(1);
}
block_count = source_dir_size;
ret = zero_output_file(fd, block_count);
if (ret) {
- fprintf(stderr, "unable to zero the output file\n");
+ error("unable to zero the output file");
exit(1);
}
/* our "device" is the new image file */
/* To create the first block group and chunk 0 in make_btrfs */
if (dev_block_count < BTRFS_MKFS_SYSTEM_GROUP_SIZE) {
- fprintf(stderr, "device is too small to make filesystem\n");
+ error("device is too small to make filesystem, must be at least %llu",
+ (unsigned long long)BTRFS_MKFS_SYSTEM_GROUP_SIZE);
exit(1);
}
if (group_profile_max_safe_loss(metadata_profile) <
group_profile_max_safe_loss(data_profile)){
- fprintf(stderr,
- "WARNING: metadata has lower redundancy than data!\n\n");
+ warning("metadata has lower redundancy than data!\n");
}
mkfs_cfg.label = label;
ret = make_btrfs(fd, &mkfs_cfg, NULL);
if (ret) {
- fprintf(stderr, "error during mkfs: %s\n", strerror(-ret));
+ error("error during mkfs: %s", strerror(-ret));
exit(1);
}
root = open_ctree(file, 0, OPEN_CTREE_WRITES);
if (!root) {
- fprintf(stderr, "Open ctree failed\n");
+ error("open ctree failed");
close(fd);
exit(1);
}
ret = create_metadata_block_groups(root, mixed, &allocation);
if (ret) {
- fprintf(stderr, "failed to create default block groups\n");
+ error("failed to create default block groups: %d", ret);
exit(1);
}
trans = btrfs_start_transaction(root, 1);
if (!trans) {
- fprintf(stderr, "failed to start transaction\n");
+ error("failed to start transaction");
exit(1);
}
ret = create_data_block_groups(trans, root, mixed, &allocation);
if (ret) {
- fprintf(stderr, "failed to create default data block groups\n");
+ error("failed to create default data block groups: %d", ret);
exit(1);
}
ret = make_root_dir(trans, root, &allocation);
if (ret) {
- fprintf(stderr, "failed to setup the root directory\n");
+ error("failed to setup the root directory: %d", ret);
exit(1);
}
trans = btrfs_start_transaction(root, 1);
if (!trans) {
- fprintf(stderr, "failed to start transaction\n");
+ error("failed to start transaction");
exit(1);
}
*/
fd = open(file, O_RDWR);
if (fd < 0) {
- fprintf(stderr, "unable to open %s: %s\n", file,
- strerror(errno));
+ error("unable to open %s: %s", file, strerror(errno));
exit(1);
}
ret = btrfs_device_already_in_root(root, fd,
BTRFS_SUPER_INFO_OFFSET);
if (ret) {
- fprintf(stderr, "skipping duplicate device %s in FS\n",
+ error("skipping duplicate device %s in the filesystem",
file);
close(fd);
continue;
ret = cleanup_temp_chunks(root->fs_info, &allocation, data_profile,
metadata_profile, metadata_profile);
if (ret < 0) {
- fprintf(stderr, "Failed to cleanup temporary chunks\n");
+ error("failed to cleanup temporary chunks: %d", ret);
goto out;
}