mirror of
https://github.com/kdave/btrfs-progs
synced 2025-02-27 15:30:44 +00:00
btrfs-progs: introduce test_issubvolname() for simplicity
There are many duplicated codes to check if the given string is correct subvolume name. Introduce test_issubvolname() for this purpose for simplicity. Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Cc: David Sterba <dsterba@suse.cz> Cc: Mike Fleetwood <mike.fleetwood@googlemail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
parent
f0884b5dc3
commit
91b3334057
@ -126,8 +126,7 @@ static int cmd_subvol_create(int argc, char **argv)
|
|||||||
dupdir = strdup(dst);
|
dupdir = strdup(dst);
|
||||||
dstdir = dirname(dupdir);
|
dstdir = dirname(dupdir);
|
||||||
|
|
||||||
if (!strcmp(newname, ".") || !strcmp(newname, "..") ||
|
if (!test_issubvolname(newname)) {
|
||||||
strchr(newname, '/') ){
|
|
||||||
fprintf(stderr, "ERROR: incorrect subvolume name '%s'\n",
|
fprintf(stderr, "ERROR: incorrect subvolume name '%s'\n",
|
||||||
newname);
|
newname);
|
||||||
goto out;
|
goto out;
|
||||||
@ -301,8 +300,7 @@ again:
|
|||||||
vname = basename(dupvname);
|
vname = basename(dupvname);
|
||||||
free(cpath);
|
free(cpath);
|
||||||
|
|
||||||
if (!strcmp(vname, ".") || !strcmp(vname, "..") ||
|
if (!test_issubvolname(vname)) {
|
||||||
strchr(vname, '/')) {
|
|
||||||
fprintf(stderr, "ERROR: incorrect subvolume name '%s'\n",
|
fprintf(stderr, "ERROR: incorrect subvolume name '%s'\n",
|
||||||
vname);
|
vname);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
@ -672,8 +670,7 @@ static int cmd_snapshot(int argc, char **argv)
|
|||||||
dstdir = dirname(dupdir);
|
dstdir = dirname(dupdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(newname, ".") || !strcmp(newname, "..") ||
|
if (!test_issubvolname(newname)) {
|
||||||
strchr(newname, '/') ){
|
|
||||||
fprintf(stderr, "ERROR: incorrect snapshot name '%s'\n",
|
fprintf(stderr, "ERROR: incorrect snapshot name '%s'\n",
|
||||||
newname);
|
newname);
|
||||||
goto out;
|
goto out;
|
||||||
|
12
utils.c
12
utils.c
@ -2405,3 +2405,15 @@ int test_minimum_size(const char *file, u32 leafsize)
|
|||||||
close(fd);
|
close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
int test_issubvolname(const char *name)
|
||||||
|
{
|
||||||
|
return name[0] != '\0' && !strchr(name, '/') &&
|
||||||
|
strcmp(name, ".") && strcmp(name, "..");
|
||||||
|
}
|
||||||
|
1
utils.h
1
utils.h
@ -116,6 +116,7 @@ int get_device_info(int fd, u64 devid,
|
|||||||
int test_uuid_unique(char *fs_uuid);
|
int test_uuid_unique(char *fs_uuid);
|
||||||
|
|
||||||
int test_minimum_size(const char *file, u32 leafsize);
|
int test_minimum_size(const char *file, u32 leafsize);
|
||||||
|
int test_issubvolname(const char *name);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Btrfs minimum size calculation is complicated, it should include at least:
|
* Btrfs minimum size calculation is complicated, it should include at least:
|
||||||
|
Loading…
Reference in New Issue
Block a user