btrfs-progs: introduce test_issubvolname() for simplicity
PATCH 1/2 btrfs-progs: introduce test_issubvolname() for simplicity
From: Satoru Takeuchi <[email protected]>
There are many duplicated codes to check if the given string is correct subvolume name. Introduce test_issubvolname() for this purpose for simplicity.
--- cmds-subvolume.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
cmds-subvolume.c +15 -6
@@ -43,6 +43,18 @@ static const char * const subvolume_cmd_group_usage[] = { };/* +* test if name is a correct subvolume name +* this function return +* 0-> name is not a correct subvolume name +* 1-> name is a correct subvolume name +*/ +static int test_issubvolname (char *name) +{ +return name[0 ] !='\0' && !strchr (name,'/' ) && +strcmp (name,"." ) &&strcmp (name,".." ); +} + +/* * test if path is a directory * this function return * 0-> path exists but it is not a directory
@@ -127,8 +139,7 @@ static int cmd_subvol_create(int argc, char **argv) dupdir =strdup (dst); dstdir =dirname (dupdir); -if (!strcmp (newname,"." ) || !strcmp (newname,".." ) || -strchr (newname,'/' ) ){ +if (!test_issubvolname (newname)) {fprintf (stderr,"ERROR: uncorrect subvolume name ('%s')\n" , newname); goto out;
@@ -302,8 +313,7 @@ again: vname =basename (dupvname);free (cpath); -if (!strcmp (vname,"." ) || !strcmp (vname,".." ) || -strchr (vname,'/' )) { +if (!test_issubvolname (vname)) {fprintf (stderr,"ERROR: incorrect subvolume name ('%s')\n" , vname); ret =1 ;
@@ -711,8 +721,7 @@ static int cmd_snapshot(int argc, char **argv) dstdir =dirname (dupdir); } -if (!strcmp (newname,"." ) || !strcmp (newname,".." ) || -strchr (newname,'/' ) ){ +if (!test_issubvolname (newname)) {fprintf (stderr,"ERROR: incorrect snapshot name ('%s')\n" , newname); goto out;
Signature · 1 line
1.9.3
Quoted 5 lines · Satoru Takeuchi
From: Satoru Takeuchi <[email protected]>
There are many duplicated codes to check if the given string is correct subvolume name. Introduce
test_issubvolname()for this purpose for simplicity.
Please move it to utils.c
Hi David,
Quoted 8 lines · David Sterba
Quoted 5 lines · Satoru Takeuchi
From: Satoru Takeuchi <[email protected]>
There are many duplicated codes to check if the given string is correct subvolume name. Introduce
test_issubvolname()for this purpose for simplicity.Please move it to
utils.c
OK, I'll do. In addition, how about moving test_isdir() and test_issubvolume() to utils.c too? These are also utility functions.
Thanks,
Satoru
Quoted 5 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
Quoted 6 lines · Satoru Takeuchi
Hi David,
Quoted 3 lines · David Sterba
Quoted 2 lines · Satoru Takeuchi
From: Satoru Takeuchi <[email protected]>
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
There are many duplicated codes to check if the given string is correct subvolume name. Introduce
test_issubvolname()for this purpose for simplicity.Please move it to
utils.cOK, I'll do. In addition, how about moving
test_isdir()andtest_issubvolume()toutils.ctoo? These are also utility functions.
Yes, makes sense.