if (check_argc_min(argc, 2) || check_argc_max(argc, 3))
usage(cmd_label_usage);
- if (argc > 2)
+ if (argc > 2) {
return set_label(argv[1], argv[2]);
- else
- return get_label(argv[1]);
+ } else {
+ char label[BTRFS_LABEL_SIZE];
+ int ret;
+
+ ret = get_label(argv[1], label);
+ if (!ret)
+ fprintf(stdout, "%s\n", label);
+
+ return ret;
+ }
}
const struct cmd_group filesystem_cmd_group = {
return 0;
}
-static int get_label_unmounted(const char *dev)
+static int get_label_unmounted(const char *dev, char *label)
{
struct btrfs_root *root;
int ret;
if(!root)
return -1;
- fprintf(stdout, "%s\n", root->fs_info->super_copy->label);
+ memcpy(label, root->fs_info->super_copy->label, BTRFS_LABEL_SIZE);
/* Now we close it since we are done. */
close_ctree(root);
return 0;
}
-int get_label(const char *btrfs_dev)
+int get_label(const char *btrfs_dev, char *label)
{
int ret;
- char label[BTRFS_LABEL_SIZE];
if (is_existing_blk_or_reg_file(btrfs_dev))
- ret = get_label_unmounted(btrfs_dev);
- else {
+ ret = get_label_unmounted(btrfs_dev, label);
+ else
ret = get_label_mounted(btrfs_dev, label);
- if (!ret)
- fprintf(stdout, "%s\n", label);
- }
+
return ret;
}
void close_file_or_dir(int fd, DIR *dirstream);
int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
struct btrfs_ioctl_dev_info_args **di_ret);
-int get_label(const char *btrfs_dev);
+int get_label(const char *btrfs_dev, char *label);
int set_label(const char *btrfs_dev, const char *label);
char *__strncpy__null(char *dest, const char *src, size_t n);