Btrfs-progs: added btrfs filesystem label [label] [path] support
PATCH 1/1 Btrfs-progs: added btrfs filesystem label [label] [path] support
Hello,
This patch make use of the new ioctl(2) to set Btrfs label via btrfs filesystem label command.
--- btrfs.c | 7 +++---- btrfs_cmds.c | 27 +++++++++++++++++++++++++++ btrfs_cmds.h | 1 + ctree.h | 6 ++++++ ioctl.h | 2 ++ mkfs.c | 19 ------------------- utils.c | 18 ++++++++++++++++++ utils.h | 1 + 8 files changed, 58 insertions(+), 23 deletions(-)
btrfs.c +3 -4
@@ -108,11 +108,10 @@ static struct Command commands[] = { "device delete", "<dev> [<dev>..] <path>\n" "Remove a device from a filesystem." }, -/* coming soon -{ 2, "filesystem label", "<label> <path>\n" + { do_set_label,2 , +"filesystem label" ,"<label> <path>\n" "Set the label of a filesystem" -} -*/ + }, { 0, 0 , 0 } };
btrfs_cmds.c +27 -0
@@ -834,6 +834,33 @@ int do_set_default_subvol(int nargs, char **argv)return 0 ; } +int do_set_label (int nargs,char **argv) +{ +int fd, ret =0 ; +char *path = argv[2 ]; +char *label =parse_label (argv[1 ]); +size_t len =strlen (label); +struct btrfs_ioctl_fs_label_args label_args; + + fd =open_file_or_dir (path); +if (fd <0 ) { +fprintf (stderr,"ERROR: can't access to '%s'\n" , path); +return 12 ; + } + + label_args.len = len; +snprintf (label_args.label,BTRFS_LABEL_SIZE ,"%s" , label); + ret =ioctl (fd,BTRFS_IOC_FS_SETLABEL , &label_args); +close (fd); +free (label); +if (ret <0 ) { +fprintf (stderr,"ERROR: unable to set a new label\n" ); +return 30 ; + } + +return 0 ; +} +int do_df_filesystem (int nargs,char **argv) {struct btrfs_ioctl_space_args *sargs;
btrfs_cmds.h +1 -0
@@ -32,3 +32,4 @@ int list_subvols(int fd);int do_df_filesystem (int nargs,char **argv);int find_updated_files (int fd,u64 root_id,u64 oldest_gen);int do_find_newer (int argc,char **argv); +int do_set_label (int argc,char **argv);
ctree.h +6 -0
@@ -345,6 +345,12 @@ struct btrfs_super_block {u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE ]; } __attribute__ ((__packed__)); +struct btrfs_ioctl_fs_label_args { +/* label length in bytes */ +__u32 len; +char label[BTRFS_LABEL_SIZE ]; +}; +/* * Compat flags that we support. If any incompat flags are set other
than the
* ones specified below then we will fail to mount
ioctl.h +2 -0
@@ -169,4 +169,6 @@ struct btrfs_ioctl_space_args {#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64)#define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \ struct btrfs_ioctl_space_args) +#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 32, \ + struct btrfs_ioctl_fs_label_args)#endif
mkfs.c +0 -19
@@ -303,25 +303,6 @@ static u64 parse_profile(char *s)return 0 ; } -static char *parse_label (char *input) -{ -int i; -int len =strlen (input); - -if (len >=BTRFS_LABEL_SIZE ) { -fprintf (stderr,"Label %s is too long (max %d)\n" , input, -BTRFS_LABEL_SIZE -1 ); -exit (1 ); - } -for (i =0 ; i < len; i++) { -if (input[i] =='/' || input[i] =='\\' ) { -fprintf (stderr,"invalid label %s\n" , input); -exit (1 ); - } - } -return strdup (input); -} -static struct option long_options[] = { {"alloc-start" ,1 ,NULL ,'A' }, {"byte-count" ,1 ,NULL ,'b' },
utils.c +18 -0
@@ -993,3 +993,21 @@ char *pretty_sizes(u64 size)return pretty; } +char *parse_label (const char *input) +{ +int i; +int len =strlen (input); + +if (len >=BTRFS_LABEL_SIZE ) { +fprintf (stderr,"Label %s is too long (max %d)\n" , input, +BTRFS_LABEL_SIZE -1 ); +exit (1 ); + } +for (i =0 ; i < len; i++) { +if (input[i] =='/' || input[i] =='\\' ) { +fprintf (stderr,"invalid label %s\n" , input); +exit (1 ); + } + } +return strdup (input); +}
utils.h +1 -0
@@ -40,4 +40,5 @@ int check_mounted(const char *devicename);int btrfs_device_already_in_root (struct btrfs_root *root,int fd,int super_offset);char *pretty_sizes (u64 size); +char *parse_label (const char *);#endif
Signature · 1 line
1.7.4.1
PATCH 1/1 Btrfs-progs: added btrfs filesystem label [label] [path] support V2
Revise the patch according to kernel side change.
--- btrfs.c | 7 +++---- btrfs_cmds.c | 34 ++++++++++++++++++++++++++++++++++ btrfs_cmds.h | 1 + ctree.h | 4 ++++ ioctl.h | 2 ++ mkfs.c | 19 ------------------- utils.c | 18 ++++++++++++++++++ utils.h | 1 + 8 files changed, 63 insertions(+), 23 deletions(-)
btrfs.c +3 -4
@@ -108,11 +108,10 @@ static struct Command commands[] = { "device delete", "<dev> [<dev>..] <path>\n" "Remove a device from a filesystem." }, -/* coming soon -{ 2, "filesystem label", "<label> <path>\n" + { do_set_label,2 , +"filesystem label" ,"<label> <path>\n" "Set the label of a filesystem" -} -*/ + }, { 0, 0 , 0 } };
btrfs_cmds.c +34 -0
@@ -834,6 +834,40 @@ int do_set_default_subvol(int nargs, char **argv)return 0 ; } +int do_set_label (int nargs,char **argv) +{ +int fd, ret; +char *path = argv[2 ]; +char *label =parse_label (argv[1 ]); +size_t len =strlen (label); +struct btrfs_ioctl_fs_label_args label_args; + +if (len ==0 || len >=BTRFS_LABEL_SIZE ) { +fprintf (stderr,"ERROR: label length too long ('%s')\n" , + label); +free (label); +return 14 ; + } + + fd =open_file_or_dir (path); +if (fd <0 ) { +free (label); +fprintf (stderr,"ERROR: can't access to '%s'\n" , path); +return 12 ; + } + +strcpy (label_args.label, label); + ret =ioctl (fd,BTRFS_IOC_FS_SETLABEL , &label_args); +close (fd); +free (label); +if (ret <0 ) { +fprintf (stderr,"ERROR: unable to set a new label\n" ); +return 30 ; + } + +return 0 ; +} +int do_df_filesystem (int nargs,char **argv) {struct btrfs_ioctl_space_args *sargs;
btrfs_cmds.h +1 -0
@@ -32,3 +32,4 @@ int list_subvols(int fd);int do_df_filesystem (int nargs,char **argv);int find_updated_files (int fd,u64 root_id,u64 oldest_gen);int do_find_newer (int argc,char **argv); +int do_set_label (int argc,char **argv);
ctree.h +4 -0
@@ -345,6 +345,10 @@ struct btrfs_super_block {u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE ]; } __attribute__ ((__packed__)); +struct btrfs_ioctl_fs_label_args { +char label[BTRFS_LABEL_SIZE ]; +}; +/* * Compat flags that we support. If any incompat flags are set other
than the
* ones specified below then we will fail to mount
ioctl.h +2 -0
@@ -140,6 +140,8 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_fs_label_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks
mkfs.c +0 -19
@@ -303,25 +303,6 @@ static u64 parse_profile(char *s)return 0 ; } -static char *parse_label (char *input) -{ -int i; -int len =strlen (input); - -if (len >=BTRFS_LABEL_SIZE ) { -fprintf (stderr,"Label %s is too long (max %d)\n" , input, -BTRFS_LABEL_SIZE -1 ); -exit (1 ); - } -for (i =0 ; i < len; i++) { -if (input[i] =='/' || input[i] =='\\' ) { -fprintf (stderr,"invalid label %s\n" , input); -exit (1 ); - } - } -return strdup (input); -} -static struct option long_options[] = { {"alloc-start" ,1 ,NULL ,'A' }, {"byte-count" ,1 ,NULL ,'b' },
utils.c +18 -0
@@ -993,3 +993,21 @@ char *pretty_sizes(u64 size)return pretty; } +char *parse_label (const char *input) +{ +int i; +int len =strlen (input); + +if (len >=BTRFS_LABEL_SIZE ) { +fprintf (stderr,"Label %s is too long (max %d)\n" , input, +BTRFS_LABEL_SIZE -1 ); +exit (1 ); + } +for (i =0 ; i < len; i++) { +if (input[i] =='/' || input[i] =='\\' ) { +fprintf (stderr,"invalid label %s\n" , input); +exit (1 ); + } + } +return strdup (input); +}
utils.h +1 -0
@@ -40,4 +40,5 @@ int check_mounted(const char *devicename);int btrfs_device_already_in_root (struct btrfs_root *root,int fd,int super_offset);char *pretty_sizes (u64 size); +char *parse_label (const char *);#endif
Signature · 1 line
1.7.4.1
Quoted 178 lines · Jeff Liu
Hello,
This patch make use of the new ioctl(2) to set Btrfs label via
btrfs filesystem labelcommand.Signed-off-by Jie Liu <[email protected]>--- btrfs.c | 7 +++---- btrfs_cmds.c | 27 +++++++++++++++++++++++++++ btrfs_cmds.h | 1 + ctree.h | 6 ++++++ ioctl.h | 2 ++ mkfs.c | 19 ------------------- utils.c | 18 ++++++++++++++++++ utils.h | 1 + 8 files changed, 58 insertions(+), 23 deletions(-)btrfs.c +3
-4@@ -108,11 +108,10 @@ static struct Command commands[] = { "device delete", "<dev> [<dev>..] <path>\n" "Remove a device from a filesystem." }, -/* coming soon -{ 2, "filesystem label", "<label> <path>\n" + { do_set_label,2 , +"filesystem label" ,"<label> <path>\n" "Set the label of a filesystem" -} -*/ + }, { 0, 0 , 0 } };btrfs_cmds.c +27
-0@@ -834,6 +834,33 @@ int do_set_default_subvol(int nargs, char **argv)return 0 ; } +int do_set_label (int nargs,char **argv) +{ +int fd, ret =0 ; +char *path = argv[2 ]; +char *label =parse_label (argv[1 ]); +size_t len =strlen (label); +struct btrfs_ioctl_fs_label_args label_args; + + fd =open_file_or_dir (path); +if (fd <0 ) { +fprintf (stderr,"ERROR: can't access to '%s'\n" , path); +return 12 ; + } + + label_args.len = len; +snprintf (label_args.label,BTRFS_LABEL_SIZE ,"%s" , label); + ret =ioctl (fd,BTRFS_IOC_FS_SETLABEL , &label_args); +close (fd); +free (label); +if (ret <0 ) { +fprintf (stderr,"ERROR: unable to set a new label\n" ); +return 30 ; + } + +return 0 ; +} +int do_df_filesystem (int nargs,char **argv) {struct btrfs_ioctl_space_args *sargs;btrfs_cmds.h +1
-0@@ -32,3 +32,4 @@ int list_subvols(int fd);int do_df_filesystem (int nargs,char **argv);int find_updated_files (int fd,u64 root_id,u64 oldest_gen);int do_find_newer (int argc,char **argv); +int do_set_label (int argc,char **argv);ctree.h +6
-0@@ -345,6 +345,12 @@ struct btrfs_super_block {u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE ]; } __attribute__ ((__packed__)); +struct btrfs_ioctl_fs_label_args { +/* label length in bytes */ +__u32 len; +char label[BTRFS_LABEL_SIZE ]; +}; +/* * Compat flags that we support. If any incompat flags are set other than the
* ones specified below then we will fail to mountioctl.h +2
-0@@ -169,4 +169,6 @@ struct btrfs_ioctl_space_args {#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64)#define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \ struct btrfs_ioctl_space_args) +#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 32, \ + struct btrfs_ioctl_fs_label_args)#endif mkfs.c +0
-19@@ -303,25 +303,6 @@ static u64 parse_profile(char *s)return 0 ; } -static char *parse_label (char *input) -{ -int i; -int len =strlen (input); - -if (len >=BTRFS_LABEL_SIZE ) { -fprintf (stderr,"Label %s is too long (max %d)\n" , input, -BTRFS_LABEL_SIZE -1 ); -exit (1 ); - } -for (i =0 ; i < len; i++) { -if (input[i] =='/' || input[i] =='\\' ) { -fprintf (stderr,"invalid label %s\n" , input); -exit (1 ); - } - } -return strdup (input); -} -static struct option long_options[] = { {"alloc-start" ,1 ,NULL ,'A' }, {"byte-count" ,1 ,NULL ,'b' },utils.c +18
-0@@ -993,3 +993,21 @@ char *pretty_sizes(u64 size)return pretty; } +char *parse_label (const char *input) +{ +int i; +int len =strlen (input); + +if (len >=BTRFS_LABEL_SIZE ) { +fprintf (stderr,"Label %s is too long (max %d)\n" , input, +BTRFS_LABEL_SIZE -1 ); +exit (1 ); + } +for (i =0 ; i < len; i++) { +if (input[i] =='/' || input[i] =='\\' ) { +fprintf (stderr,"invalid label %s\n" , input); +exit (1 ); + } + } +return strdup (input); +}utils.h +1
-0@@ -40,4 +40,5 @@ int check_mounted(const char *devicename);int btrfs_device_already_in_root (struct btrfs_root *root,int fd,int super_offset);char *pretty_sizes (u64 size); +char *parse_label (const char *);#endif
Re: [PATCH] Btrfs-progs: added btrfs filesystem label [label] [path] support V2
Hi,
are you aware that there is a label support already? Though only for unmounted system, but please have a look at these patches:
https://patchwork.kernel.org/patch/381141/
https://patchwork.kernel.org/patch/842602/
and the patches are part of Hugo's integration for a long time, rather check latest versions so you do not duplicate work.
Quoted 1 line · Jeff Liu
Revise the patch according to kernel side change.
Leave original commit message. If you want to document changes between revised patch version put them ...
Quoted 4 lines
Signed-off-by Jie Liu <[email protected]>---
... here. Git will ignore them when applying the message.
HTH,
david
Quoted 366 lines
btrfs.c | 7 +++---- btrfs_cmds.c | 34 ++++++++++++++++++++++++++++++++++ btrfs_cmds.h | 1 + ctree.h | 4 ++++ ioctl.h | 2 ++ mkfs.c | 19 ------------------- utils.c | 18 ++++++++++++++++++ utils.h | 1 + 8 files changed, 63 insertions(+), 23 deletions(-)btrfs.c +3
-4@@ -108,11 +108,10 @@ static struct Command commands[] = { "device delete", "<dev> [<dev>..] <path>\n" "Remove a device from a filesystem." }, -/* coming soon -{ 2, "filesystem label", "<label> <path>\n" + { do_set_label,2 , +"filesystem label" ,"<label> <path>\n" "Set the label of a filesystem" -} -*/ + }, { 0, 0 , 0 } };btrfs_cmds.c +34
-0@@ -834,6 +834,40 @@ int do_set_default_subvol(int nargs, char **argv)return 0 ; } +int do_set_label (int nargs,char **argv) +{ +int fd, ret; +char *path = argv[2 ]; +char *label =parse_label (argv[1 ]); +size_t len =strlen (label); +struct btrfs_ioctl_fs_label_args label_args; + +if (len ==0 || len >=BTRFS_LABEL_SIZE ) { +fprintf (stderr,"ERROR: label length too long ('%s')\n" , + label); +free (label); +return 14 ; + } + + fd =open_file_or_dir (path); +if (fd <0 ) { +free (label); +fprintf (stderr,"ERROR: can't access to '%s'\n" , path); +return 12 ; + } + +strcpy (label_args.label, label); + ret =ioctl (fd,BTRFS_IOC_FS_SETLABEL , &label_args); +close (fd); +free (label); +if (ret <0 ) { +fprintf (stderr,"ERROR: unable to set a new label\n" ); +return 30 ; + } + +return 0 ; +} +int do_df_filesystem (int nargs,char **argv) {struct btrfs_ioctl_space_args *sargs;btrfs_cmds.h +1
-0@@ -32,3 +32,4 @@ int list_subvols(int fd);int do_df_filesystem (int nargs,char **argv);int find_updated_files (int fd,u64 root_id,u64 oldest_gen);int do_find_newer (int argc,char **argv); +int do_set_label (int argc,char **argv);ctree.h +4
-0@@ -345,6 +345,10 @@ struct btrfs_super_block {u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE ]; } __attribute__ ((__packed__)); +struct btrfs_ioctl_fs_label_args { +char label[BTRFS_LABEL_SIZE ]; +}; +/* * Compat flags that we support. If any incompat flags are set other than the
* ones specified below then we will fail to mountioctl.h +2
-0@@ -140,6 +140,8 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_fs_label_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks mkfs.c +0
-19@@ -303,25 +303,6 @@ static u64 parse_profile(char *s)return 0 ; } -static char *parse_label (char *input) -{ -int i; -int len =strlen (input); - -if (len >=BTRFS_LABEL_SIZE ) { -fprintf (stderr,"Label %s is too long (max %d)\n" , input, -BTRFS_LABEL_SIZE -1 ); -exit (1 ); - } -for (i =0 ; i < len; i++) { -if (input[i] =='/' || input[i] =='\\' ) { -fprintf (stderr,"invalid label %s\n" , input); -exit (1 ); - } - } -return strdup (input); -} -static struct option long_options[] = { {"alloc-start" ,1 ,NULL ,'A' }, {"byte-count" ,1 ,NULL ,'b' },utils.c +18
-0@@ -993,3 +993,21 @@ char *pretty_sizes(u64 size)return pretty; } +char *parse_label (const char *input) +{ +int i; +int len =strlen (input); + +if (len >=BTRFS_LABEL_SIZE ) { +fprintf (stderr,"Label %s is too long (max %d)\n" , input, +BTRFS_LABEL_SIZE -1 ); +exit (1 ); + } +for (i =0 ; i < len; i++) { +if (input[i] =='/' || input[i] =='\\' ) { +fprintf (stderr,"invalid label %s\n" , input); +exit (1 ); + } + } +return strdup (input); +}utils.h +1
-0@@ -40,4 +40,5 @@ int check_mounted(const char *devicename);int btrfs_device_already_in_root (struct btrfs_root *root,int fd,int super_offset);char *pretty_sizes (u64 size); +char *parse_label (const char *);#endif Signature · 1 line
1.7.4.1Quoted 174 lines · Jeff Liu
Hello,
This patch make use of the new ioctl(2) to set Btrfs label via
btrfs filesystem labelcommand.Signed-off-by Jie Liu <[email protected]>---
btrfs.c | 7 +++---- btrfs_cmds.c | 27 +++++++++++++++++++++++++++ btrfs_cmds.h | 1 + ctree.h | 6 ++++++ ioctl.h | 2 ++ mkfs.c | 19 ------------------- utils.c | 18 ++++++++++++++++++ utils.h | 1 + 8 files changed, 58 insertions(+), 23 deletions(-)btrfs.c +3
-4@@ -108,11 +108,10 @@ static struct Command commands[] = { "device delete", "<dev> [<dev>..] <path>\n" "Remove a device from a filesystem." }, -/* coming soon -{ 2, "filesystem label", "<label> <path>\n" + { do_set_label,2 , +"filesystem label" ,"<label> <path>\n" "Set the label of a filesystem" -} -*/ + }, { 0, 0 , 0 } };btrfs_cmds.c +27
-0@@ -834,6 +834,33 @@ int do_set_default_subvol(int nargs, char **argv)return 0 ; } +int do_set_label (int nargs,char **argv) +{ +int fd, ret =0 ; +char *path = argv[2 ]; +char *label =parse_label (argv[1 ]); +size_t len =strlen (label); +struct btrfs_ioctl_fs_label_args label_args; + + fd =open_file_or_dir (path); +if (fd <0 ) { +fprintf (stderr,"ERROR: can't access to '%s'\n" , path); +return 12 ; + } + + label_args.len = len; +snprintf (label_args.label,BTRFS_LABEL_SIZE ,"%s" , label); + ret =ioctl (fd,BTRFS_IOC_FS_SETLABEL , &label_args); +close (fd); +free (label); +if (ret <0 ) { +fprintf (stderr,"ERROR: unable to set a new label\n" ); +return 30 ; + } + +return 0 ; +} +int do_df_filesystem (int nargs,char **argv) {struct btrfs_ioctl_space_args *sargs;btrfs_cmds.h +1
-0@@ -32,3 +32,4 @@ int list_subvols(int fd);int do_df_filesystem (int nargs,char **argv);int find_updated_files (int fd,u64 root_id,u64 oldest_gen);int do_find_newer (int argc,char **argv); +int do_set_label (int argc,char **argv);ctree.h +6
-0@@ -345,6 +345,12 @@ struct btrfs_super_block {u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE ]; } __attribute__ ((__packed__)); +struct btrfs_ioctl_fs_label_args { +/* label length in bytes */ +__u32 len; +char label[BTRFS_LABEL_SIZE ]; +}; +/* * Compat flags that we support. If any incompat flags are set other than the
* ones specified below then we will fail to mountioctl.h +2
-0@@ -169,4 +169,6 @@ struct btrfs_ioctl_space_args {#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64)#define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \ struct btrfs_ioctl_space_args) +#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 32, \ + struct btrfs_ioctl_fs_label_args)#endif mkfs.c +0
-19@@ -303,25 +303,6 @@ static u64 parse_profile(char *s)return 0 ; } -static char *parse_label (char *input) -{ -int i; -int len =strlen (input); - -if (len >=BTRFS_LABEL_SIZE ) { -fprintf (stderr,"Label %s is too long (max %d)\n" , input, -BTRFS_LABEL_SIZE -1 ); -exit (1 ); - } -for (i =0 ; i < len; i++) { -if (input[i] =='/' || input[i] =='\\' ) { -fprintf (stderr,"invalid label %s\n" , input); -exit (1 ); - } - } -return strdup (input); -} -static struct option long_options[] = { {"alloc-start" ,1 ,NULL ,'A' }, {"byte-count" ,1 ,NULL ,'b' },utils.c +18
-0@@ -993,3 +993,21 @@ char *pretty_sizes(u64 size)return pretty; } +char *parse_label (const char *input) +{ +int i; +int len =strlen (input); + +if (len >=BTRFS_LABEL_SIZE ) { +fprintf (stderr,"Label %s is too long (max %d)\n" , input, +BTRFS_LABEL_SIZE -1 ); +exit (1 ); + } +for (i =0 ; i < len; i++) { +if (input[i] =='/' || input[i] =='\\' ) { +fprintf (stderr,"invalid label %s\n" , input); +exit (1 ); + } + } +return strdup (input); +}utils.h +0
-0utils.h int check_mounted(const char *devicename); · line 44
Quoted 5 lines
utils.h +1
-0@@ -40,4 +40,5 @@ int check_mounted(const char *devicename);int btrfs_device_already_in_root (struct btrfs_root *root,int fd,int super_offset);char *pretty_sizes (u64 size); +char *parse_label (const char *);#endif --
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] Btrfs-progs: added btrfs filesystem label [label] [path] support V2
Hi David,
Quoted 10 lines · David Sterba
Hi,
are you aware that there is a label support already? Though only for unmounted system, but please have a look at these patches:
https://patchwork.kernel.org/patch/381141/
https://patchwork.kernel.org/patch/842602/and the patches are part of Hugo's integration for a long time, rather check latest versions so you do not duplicate work.
Thanks for your info! I was not aware of that at that time. :(
I am definitely a newbie to Btrfs and the kernel world, just started to explore it at last week. :-)
Quoted 4 lines · Jeff Liu
Quoted 1 line
Revise the patch according to kernel side change.
Leave original commit message. If you want to document changes between revised patch version put them ...
ok, fixed as below:
From e2990b69ecd3bac8da8023a64c866d16c81a1679 Mon Sep 17 00:00:00 2001
From: Jie Liu <[email protected]>
Date: Fri, 2 Sep 2011 21:07:35 +0800
Subject: [PATCH 1/1] Add btrfs filesystem label [label] [path] support through ioctl.
--- btrfs.c | 7 +++---- btrfs_cmds.c | 34 ++++++++++++++++++++++++++++++++++ btrfs_cmds.h | 1 + ctree.h | 4 ++++ ioctl.h | 2 ++ mkfs.c | 19 ------------------- utils.c | 18 ++++++++++++++++++ utils.h | 1 + 8 files changed, 63 insertions(+), 23 deletions(-)
btrfs.c +3 -4
@@ -108,11 +108,10 @@ static struct Command commands[] = { "device delete", "<dev> [<dev>..] <path>\n" "Remove a device from a filesystem." }, -/* coming soon -{ 2, "filesystem label", "<label> <path>\n" + { do_set_label,2 , +"filesystem label" ,"<label> <path>\n" "Set the label of a filesystem" -} -*/ + }, { 0, 0 , 0 } };
btrfs_cmds.c +34 -0
@@ -834,6 +834,40 @@ int do_set_default_subvol(int nargs, char **argv)return 0 ; } +int do_set_label (int nargs,char **argv) +{ +int fd, ret; +char *path = argv[2 ]; +char *label =parse_label (argv[1 ]); +size_t len =strlen (label); +struct btrfs_ioctl_fs_label_args label_args; + +if (len ==0 || len >=BTRFS_LABEL_SIZE ) { +fprintf (stderr,"ERROR: label length too long ('%s')\n" , + label); +free (label); +return 14 ; + } + + fd =open_file_or_dir (path); +if (fd <0 ) { +free (label); +fprintf (stderr,"ERROR: can't access to '%s'\n" , path); +return 12 ; + } + +strcpy (label_args.label, label); + ret =ioctl (fd,BTRFS_IOC_FS_SETLABEL , &label_args); +close (fd); +free (label); +if (ret <0 ) { +fprintf (stderr,"ERROR: unable to set a new label\n" ); +return 30 ; + } + +return 0 ; +} +int do_df_filesystem (int nargs,char **argv) {struct btrfs_ioctl_space_args *sargs;
btrfs_cmds.h +1 -0
@@ -32,3 +32,4 @@ int list_subvols(int fd);int do_df_filesystem (int nargs,char **argv);int find_updated_files (int fd,u64 root_id,u64 oldest_gen);int do_find_newer (int argc,char **argv); +int do_set_label (int argc,char **argv);
ctree.h +4 -0
@@ -345,6 +345,10 @@ struct btrfs_super_block {u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE ]; } __attribute__ ((__packed__)); +struct btrfs_ioctl_fs_label_args { +char label[BTRFS_LABEL_SIZE ]; +}; +/* * Compat flags that we support. If any incompat flags are set other
than the
* ones specified below then we will fail to mount
ioctl.h +2 -0
@@ -140,6 +140,8 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_fs_label_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks
mkfs.c +0 -19
@@ -303,25 +303,6 @@ static u64 parse_profile(char *s)return 0 ; } -static char *parse_label (char *input) -{ -int i; -int len =strlen (input); - -if (len >=BTRFS_LABEL_SIZE ) { -fprintf (stderr,"Label %s is too long (max %d)\n" , input, -BTRFS_LABEL_SIZE -1 ); -exit (1 ); - } -for (i =0 ; i < len; i++) { -if (input[i] =='/' || input[i] =='\\' ) { -fprintf (stderr,"invalid label %s\n" , input); -exit (1 ); - } - } -return strdup (input); -} -static struct option long_options[] = { {"alloc-start" ,1 ,NULL ,'A' }, {"byte-count" ,1 ,NULL ,'b' },
utils.c +18 -0
@@ -993,3 +993,21 @@ char *pretty_sizes(u64 size)return pretty; } +char *parse_label (const char *input) +{ +int i; +int len =strlen (input); + +if (len >=BTRFS_LABEL_SIZE ) { +fprintf (stderr,"Label %s is too long (max %d)\n" , input, +BTRFS_LABEL_SIZE -1 ); +exit (1 ); + } +for (i =0 ; i < len; i++) { +if (input[i] =='/' || input[i] =='\\' ) { +fprintf (stderr,"invalid label %s\n" , input); +exit (1 ); + } + } +return strdup (input); +}
utils.h +1 -0
@@ -40,4 +40,5 @@ int check_mounted(const char *devicename);int btrfs_device_already_in_root (struct btrfs_root *root,int fd,int super_offset);char *pretty_sizes (u64 size); +char *parse_label (const char *);#endif
Signature · 1 line
1.7.4.1
Quoted 378 lines
Quoted 3 lines
Signed-off-by Jie Liu<[email protected]>---
... here. Git will ignore them when applying the message.
HTH,
davidQuoted 365 lines
btrfs.c | 7 +++---- btrfs_cmds.c | 34 ++++++++++++++++++++++++++++++++++ btrfs_cmds.h | 1 + ctree.h | 4 ++++ ioctl.h | 2 ++ mkfs.c | 19 ------------------- utils.c | 18 ++++++++++++++++++ utils.h | 1 + 8 files changed, 63 insertions(+), 23 deletions(-)btrfs.c +3
-4@@ -108,11 +108,10 @@ static struct Command commands[] = { "device delete", "<dev> [<dev>..]<path>\n" "Remove a device from a filesystem." }, -/* coming soon -{ 2, "filesystem label", "<label> <path>\n" + { do_set_label,2 , +"filesystem label" ,"<label> <path>\n" "Set the label of a filesystem" -} -*/ + }, { 0, 0 , 0 } };btrfs_cmds.c +34
-0@@ -834,6 +834,40 @@ int do_set_default_subvol(int nargs, char **argv)return 0 ; } +int do_set_label (int nargs,char **argv) +{ +int fd, ret; +char *path = argv[2 ]; +char *label =parse_label (argv[1 ]); +size_t len =strlen (label); +struct btrfs_ioctl_fs_label_args label_args; + +if (len ==0 || len>=BTRFS_LABEL_SIZE ) { +fprintf (stderr,"ERROR: label length too long ('%s')\n" , + label); +free (label); +return 14 ; + } + + fd =open_file_or_dir (path); +if (fd<0 ) { +free (label); +fprintf (stderr,"ERROR: can't access to '%s'\n" , path); +return 12 ; + } + +strcpy (label_args.label, label); + ret =ioctl (fd,BTRFS_IOC_FS_SETLABEL ,&label_args); +close (fd); +free (label); +if (ret<0 ) { +fprintf (stderr,"ERROR: unable to set a new label\n" ); +return 30 ; + } + +return 0 ; +} +int do_df_filesystem (int nargs,char **argv) {struct btrfs_ioctl_space_args *sargs;btrfs_cmds.h +1
-0@@ -32,3 +32,4 @@ int list_subvols(int fd);int do_df_filesystem (int nargs,char **argv);int find_updated_files (int fd,u64 root_id,u64 oldest_gen);int do_find_newer (int argc,char **argv); +int do_set_label (int argc,char **argv);ctree.h +4
-0@@ -345,6 +345,10 @@ struct btrfs_super_block {u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE ]; } __attribute__ ((__packed__)); +struct btrfs_ioctl_fs_label_args { +char label[BTRFS_LABEL_SIZE ]; +}; +/* * Compat flags that we support. If any incompat flags are set other than the
* ones specified below then we will fail to mountioctl.h +2
-0@@ -140,6 +140,8 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_fs_label_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks mkfs.c +0
-19@@ -303,25 +303,6 @@ static u64 parse_profile(char *s)return 0 ; } -static char *parse_label (char *input) -{ -int i; -int len =strlen (input); - -if (len>=BTRFS_LABEL_SIZE ) { -fprintf (stderr,"Label %s is too long (max %d)\n" , input, -BTRFS_LABEL_SIZE -1 ); -exit (1 ); - } -for (i =0 ; i< len; i++) { -if (input[i] =='/' || input[i] =='\\' ) { -fprintf (stderr,"invalid label %s\n" , input); -exit (1 ); - } - } -return strdup (input); -} -static struct option long_options[] = { {"alloc-start" ,1 ,NULL ,'A' }, {"byte-count" ,1 ,NULL ,'b' },utils.c +18
-0@@ -993,3 +993,21 @@ char *pretty_sizes(u64 size)return pretty; } +char *parse_label (const char *input) +{ +int i; +int len =strlen (input); + +if (len>=BTRFS_LABEL_SIZE ) { +fprintf (stderr,"Label %s is too long (max %d)\n" , input, +BTRFS_LABEL_SIZE -1 ); +exit (1 ); + } +for (i =0 ; i< len; i++) { +if (input[i] =='/' || input[i] =='\\' ) { +fprintf (stderr,"invalid label %s\n" , input); +exit (1 ); + } + } +return strdup (input); +}utils.h +1
-0@@ -40,4 +40,5 @@ int check_mounted(const char *devicename);int btrfs_device_already_in_root (struct btrfs_root *root,int fd,int super_offset);char *pretty_sizes (u64 size); +char *parse_label (const char *);#endif Signature · 1 line
1.7.4.1Quoted 174 lines · Jeff Liu
Hello,
This patch make use of the new ioctl(2) to set Btrfs label via
btrfs filesystem labelcommand.Signed-off-by Jie Liu<[email protected]>---
btrfs.c | 7 +++---- btrfs_cmds.c | 27 +++++++++++++++++++++++++++ btrfs_cmds.h | 1 + ctree.h | 6 ++++++ ioctl.h | 2 ++ mkfs.c | 19 ------------------- utils.c | 18 ++++++++++++++++++ utils.h | 1 + 8 files changed, 58 insertions(+), 23 deletions(-)btrfs.c +3
-4@@ -108,11 +108,10 @@ static struct Command commands[] = { "device delete", "<dev> [<dev>..]<path>\n" "Remove a device from a filesystem." }, -/* coming soon -{ 2, "filesystem label", "<label> <path>\n" + { do_set_label,2 , +"filesystem label" ,"<label> <path>\n" "Set the label of a filesystem" -} -*/ + }, { 0, 0 , 0 } };btrfs_cmds.c +27
-0@@ -834,6 +834,33 @@ int do_set_default_subvol(int nargs, char **argv)return 0 ; } +int do_set_label (int nargs,char **argv) +{ +int fd, ret =0 ; +char *path = argv[2 ]; +char *label =parse_label (argv[1 ]); +size_t len =strlen (label); +struct btrfs_ioctl_fs_label_args label_args; + + fd =open_file_or_dir (path); +if (fd<0 ) { +fprintf (stderr,"ERROR: can't access to '%s'\n" , path); +return 12 ; + } + + label_args.len = len; +snprintf (label_args.label,BTRFS_LABEL_SIZE ,"%s" , label); + ret =ioctl (fd,BTRFS_IOC_FS_SETLABEL ,&label_args); +close (fd); +free (label); +if (ret<0 ) { +fprintf (stderr,"ERROR: unable to set a new label\n" ); +return 30 ; + } + +return 0 ; +} +int do_df_filesystem (int nargs,char **argv) {struct btrfs_ioctl_space_args *sargs;btrfs_cmds.h +1
-0@@ -32,3 +32,4 @@ int list_subvols(int fd);int do_df_filesystem (int nargs,char **argv);int find_updated_files (int fd,u64 root_id,u64 oldest_gen);int do_find_newer (int argc,char **argv); +int do_set_label (int argc,char **argv);ctree.h +6
-0@@ -345,6 +345,12 @@ struct btrfs_super_block {u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE ]; } __attribute__ ((__packed__)); +struct btrfs_ioctl_fs_label_args { +/* label length in bytes */ +__u32 len; +char label[BTRFS_LABEL_SIZE ]; +}; +/* * Compat flags that we support. If any incompat flags are set other than the
* ones specified below then we will fail to mountioctl.h +2
-0@@ -169,4 +169,6 @@ struct btrfs_ioctl_space_args {#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64)#define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \ struct btrfs_ioctl_space_args) +#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 32, \ + struct btrfs_ioctl_fs_label_args)#endif mkfs.c +0
-19@@ -303,25 +303,6 @@ static u64 parse_profile(char *s)return 0 ; } -static char *parse_label (char *input) -{ -int i; -int len =strlen (input); - -if (len>=BTRFS_LABEL_SIZE ) { -fprintf (stderr,"Label %s is too long (max %d)\n" , input, -BTRFS_LABEL_SIZE -1 ); -exit (1 ); - } -for (i =0 ; i< len; i++) { -if (input[i] =='/' || input[i] =='\\' ) { -fprintf (stderr,"invalid label %s\n" , input); -exit (1 ); - } - } -return strdup (input); -} -static struct option long_options[] = { {"alloc-start" ,1 ,NULL ,'A' }, {"byte-count" ,1 ,NULL ,'b' },utils.c +18
-0@@ -993,3 +993,21 @@ char *pretty_sizes(u64 size)return pretty; } +char *parse_label (const char *input) +{ +int i; +int len =strlen (input); + +if (len>=BTRFS_LABEL_SIZE ) { +fprintf (stderr,"Label %s is too long (max %d)\n" , input, +BTRFS_LABEL_SIZE -1 ); +exit (1 ); + } +for (i =0 ; i< len; i++) { +if (input[i] =='/' || input[i] =='\\' ) { +fprintf (stderr,"invalid label %s\n" , input); +exit (1 ); + } + } +return strdup (input); +}utils.h +0
-0utils.h int check_mounted(const char *devicename); · line 44
Quoted 5 lines
utils.h +1
-0@@ -40,4 +40,5 @@ int check_mounted(const char *devicename);int btrfs_device_already_in_root (struct btrfs_root *root,int fd,int super_offset);char *pretty_sizes (u64 size); +char *parse_label (const char *);#endif --
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] Btrfs-progs: added btrfs filesystem label [label] [path] support V2
ioctl.h struct btrfs_ioctl_space_args { · line 147
Quoted 11 lines · Jeff Liu
ioctl.h +2
-0@@ -140,6 +140,8 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_fs_label_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks
well, it is an unassigned number, but a newly added features should IMHO allocate greater than current max value, ie over 31 in coordination with
https://btrfs.wiki.kernel.org/index.php/Project_ideas#Development_notes.2C_please_read
table.
david
Re: [PATCH] Btrfs-progs: added btrfs filesystem label [label] [path] support V2
=D4=DA 2011-9-2=A3=AC=CF=C2=CE=E711:48=A3=AC David Sterba =D0=B4=B5=C0=A3= =BA
Quoted 6 lines · Jeff Liu
Quoted 5 lines
ioctl.h +0
-0@@ -140,6 +140,8 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \
Quoted 8 lines
ioctl.h struct btrfs_ioctl_space_args { · line 147
Quoted 6 lines
ioctl.h +2
-0struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_fs_label_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks =20
well, it is an unassigned number, but a newly added features should I=
MHO
Quoted 1 line
allocate greater than current max value, ie over 31 in coordination w=
ith
es.2C_please_read
Quoted 2 lines
=20
table.
It sounds reasonable to allocate a greater value, could anyone please c= onfirm it?
Hi Zefan,
What's your ioctl range for online fsck?
Thanks,
-Jeff
Quoted 5 lines
=20
=20
david
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs=
" in
Quoted 2 lines
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] Btrfs-progs: added btrfs filesystem label [label] [path] support V2
In reply to a message not in the archiveQuoted 2 lines · Hugo Mills
Quoted 1 line · Jeff liu
=E5=9C=A8 2011-9-2=EF=BC=8C=E4=B8=8B=E5=8D=8811:48=EF=BC=8C David St=
erba =E5=86=99=E9=81=93=EF=BC=9A
Quoted 13 lines
Quoted 13 lines
Quoted 5 lines · Jeff Liu
Quoted 4 lines
ioctl.h +0
-0@@ -140,6 +140,8 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_vol_args)Quoted 8 lines
ioctl.h struct btrfs_ioctl_space_args { · line 147
Quoted 7 lines
ioctl.h +2
-0#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_fs_label_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks well, it is an unassigned number, but a newly added features should=
IMHO
Quoted 1 line
Quoted 1 line
Quoted 1 line
allocate greater than current max value, ie over 31 in coordination=
with
Quoted 2 lines
Quoted 2 lines
otes.2C_please_read
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
table.
It sounds reasonable to allocate a greater value, could anyone pleas=
e confirm it?
Quoted 2 lines
I'd just take number 50 for yours -- Li can update his patches
later.
Thank you, I'll post a patch for this change later.
-Jeff
Quoted 3 lines
Hugo.
Quoted 1 line
What's your ioctl range for online fsck?
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/1 Btrfs: added new ioctl to set fs label V3
In reply to a message not in the archiveHello,
According to Hugo and David's advise, the ioctl number of BTRFS_IOC_FS_SETLABEL ioctl was changed to 50 now.
--- fs/btrfs/ctree.h | 4 ++++ fs/btrfs/ioctl.c | 36 ++++++++++++++++++++++++++++++++++++ fs/btrfs/ioctl.h | 2 ++ 3 files changed, 42 insertions(+), 0 deletions(-)
fs/btrfs/ctree.h +4 -0
@@ -1259,6 +1259,10 @@ struct btrfs_ioctl_defrag_range_args { }; +struct btrfs_ioctl_fs_label_args { +char label[BTRFS_LABEL_SIZE ]; +}; +/* * inode items have the data typically returned from stat and store other * info about object characteristics. There is one for every file and
dir in
fs/btrfs/ioctl.c +34 -0
@@ -268,6 +268,40 @@ static int btrfs_ioctl_getversion(struct file *file, int __user *arg)return put_user (inode->i_generation, arg); } +static int btrfs_ioctl_fs_setlabel (struct btrfs_root *root,void __user *arg) +{ +struct btrfs_super_block *super_block = &(root->fs_info->super_copy); +struct btrfs_ioctl_fs_label_args *label_args; +struct btrfs_trans_handle *trans; +int ret; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + +if (btrfs_root_readonly (root)) +return -EROFS ; + + label_args =memdup_user (arg,sizeof (*label_args)); +if (IS_ERR (label_args)) +return PTR_ERR (label_args); + + label_args->label[BTRFS_LABEL_SIZE -1 ] ='\0' ; + +mutex_lock (&root->fs_info->volume_mutex); + trans =btrfs_start_transaction (root,0 ); +if (IS_ERR (trans)) { + ret =PTR_ERR (trans); + goto out_unlock; + } +strcpy (super_block->label, label_args->label); +btrfs_end_transaction (trans, root); + +out_unlock: +mutex_unlock (&root->fs_info->volume_mutex); +kfree (label_args); +return 0 ; +} + static noinline int btrfs_ioctl_fitrim(struct file *file, void __user
*arg)
{
struct btrfs_root *root = fdentry(file)->d_sb->s_fs_info;
@@ -2876,6 +2910,8 @@ long btrfs_ioctl(struct file *file, unsigned int
return btrfs_ioctl_fs_info(root, argp);
case BTRFS_IOC_DEV_INFO:
return btrfs_ioctl_dev_info(root, argp);
+ case BTRFS_IOC_FS_SETLABEL:
+ return btrfs_ioctl_fs_setlabel(root, argp);
case BTRFS_IOC_BALANCE:
return btrfs_balance(root->fs_info->dev_root);
case BTRFS_IOC_CLONE:fs/btrfs/ioctl.h +2 -0
@@ -248,4 +248,6 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_dev_info_args)#define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \ struct btrfs_ioctl_fs_info_args) +#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 50, \ + struct btrfs_ioctl_fs_label_args)#endif
Signature · 1 line
1.7.4.1
PATCH 1/1 Btrfs-progs: added btrfs filesystem label [label] [path] support V3
In reply to Jeff LiuFix the ioctl number of BTRFS_IOC_FS_SETLABEL to 50.
--- btrfs.c | 7 +++---- btrfs_cmds.c | 34 ++++++++++++++++++++++++++++++++++ btrfs_cmds.h | 1 + ctree.h | 4 ++++ ioctl.h | 2 ++ mkfs.c | 19 ------------------- utils.c | 18 ++++++++++++++++++ utils.h | 1 + 8 files changed, 63 insertions(+), 23 deletions(-)
btrfs.c +3 -4
@@ -108,11 +108,10 @@ static struct Command commands[] = { "device delete", "<dev> [<dev>..] <path>\n" "Remove a device from a filesystem." }, -/* coming soon -{ 2, "filesystem label", "<label> <path>\n" + { do_set_label,2 , +"filesystem label" ,"<label> <path>\n" "Set the label of a filesystem" -} -*/ + }, { 0, 0 , 0 } };
btrfs_cmds.c +34 -0
@@ -834,6 +834,40 @@ int do_set_default_subvol(int nargs, char **argv)return 0 ; } +int do_set_label (int nargs,char **argv) +{ +int fd, ret; +char *path = argv[2 ]; +char *label =parse_label (argv[1 ]); +size_t len =strlen (label); +struct btrfs_ioctl_fs_label_args label_args; + +if (len ==0 || len >=BTRFS_LABEL_SIZE ) { +fprintf (stderr,"ERROR: label length too long ('%s')\n" , + label); +free (label); +return 14 ; + } + + fd =open_file_or_dir (path); +if (fd <0 ) { +free (label); +fprintf (stderr,"ERROR: can't access to '%s'\n" , path); +return 12 ; + } + +strcpy (label_args.label, label); + ret =ioctl (fd,BTRFS_IOC_FS_SETLABEL , &label_args); +close (fd); +free (label); +if (ret <0 ) { +fprintf (stderr,"ERROR: unable to set a new label\n" ); +return 30 ; + } + +return 0 ; +} +int do_df_filesystem (int nargs,char **argv) {struct btrfs_ioctl_space_args *sargs;
btrfs_cmds.h +1 -0
@@ -32,3 +32,4 @@ int list_subvols(int fd);int do_df_filesystem (int nargs,char **argv);int find_updated_files (int fd,u64 root_id,u64 oldest_gen);int do_find_newer (int argc,char **argv); +int do_set_label (int argc,char **argv);
ctree.h +4 -0
@@ -345,6 +345,10 @@ struct btrfs_super_block {u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE ]; } __attribute__ ((__packed__)); +struct btrfs_ioctl_fs_label_args { +char label[BTRFS_LABEL_SIZE ]; +}; +/* * Compat flags that we support. If any incompat flags are set other
than the
* ones specified below then we will fail to mount
ioctl.h +2 -0
@@ -169,4 +169,6 @@ struct btrfs_ioctl_space_args {#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64)#define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \ struct btrfs_ioctl_space_args) +#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 50, \ + struct btrfs_ioctl_fs_label_args)#endif
mkfs.c +0 -19
@@ -303,25 +303,6 @@ static u64 parse_profile(char *s)return 0 ; } -static char *parse_label (char *input) -{ -int i; -int len =strlen (input); - -if (len >=BTRFS_LABEL_SIZE ) { -fprintf (stderr,"Label %s is too long (max %d)\n" , input, -BTRFS_LABEL_SIZE -1 ); -exit (1 ); - } -for (i =0 ; i < len; i++) { -if (input[i] =='/' || input[i] =='\\' ) { -fprintf (stderr,"invalid label %s\n" , input); -exit (1 ); - } - } -return strdup (input); -} -static struct option long_options[] = { {"alloc-start" ,1 ,NULL ,'A' }, {"byte-count" ,1 ,NULL ,'b' },
utils.c +18 -0
@@ -993,3 +993,21 @@ char *pretty_sizes(u64 size)return pretty; } +char *parse_label (const char *input) +{ +int i; +int len =strlen (input); + +if (len >=BTRFS_LABEL_SIZE ) { +fprintf (stderr,"Label %s is too long (max %d)\n" , input, +BTRFS_LABEL_SIZE -1 ); +exit (1 ); + } +for (i =0 ; i < len; i++) { +if (input[i] =='/' || input[i] =='\\' ) { +fprintf (stderr,"invalid label %s\n" , input); +exit (1 ); + } + } +return strdup (input); +}
utils.h +1 -0
@@ -40,4 +40,5 @@ int check_mounted(const char *devicename);int btrfs_device_already_in_root (struct btrfs_root *root,int fd,int super_offset);char *pretty_sizes (u64 size); +char *parse_label (const char *);#endif
Signature · 1 line
1.7.4.1
Quoted 36 lines · Jeff Liu
Quoted 17 lines · Hugo Mills
Quoted 16 lines · Jeff liu
Quoted 16 lines · Jeff Liu
ioctl.h struct btrfs_ioctl_space_args { · line 147
Quoted 11 lines
ioctl.h +2
-0@@ -140,6 +140,8 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_vol_args)#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ struct btrfs_ioctl_vol_args) +#define BTRFS_IOC_FS_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 5, \ + struct btrfs_ioctl_fs_label_args)/* trans start and trans end are dangerous, and only for * use by applications that know how to avoid the * resulting deadlocks well, it is an unassigned number, but a newly added features should IMHO allocate greater than current max value, ie over 31 in coordination with
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
https://btrfs.wiki.kernel.org/index.php/Project_ideas#Development_notes.2C_please_read
table.
It sounds reasonable to allocate a greater value, could anyone please confirm it?
I'd just take number 50 for yours -- Li can update his patches
later.Thank you, I'll post a patch for this change later.
-Jeff
Quoted 3 lines
Hugo.
Quoted 1 line
What's your ioctl range for online fsck?
Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html