summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSatoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>2014-08-01 11:44:21 +0900
committerDavid Sterba <dsterba@suse.cz>2014-08-22 15:07:04 +0200
commit91b33340576e9c59353a89f0edb7b72a5a60ad3f (patch)
tree9d4419ca90279b312f22ab4b2f925b1c80bb2428
parentf0884b5dc30c134bcb87a43342ca26d0773295ee (diff)
downloadbtrfs-progs-91b33340576e9c59353a89f0edb7b72a5a60ad3f.tar.gz
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>
-rw-r--r--cmds-subvolume.c9
-rw-r--r--utils.c12
-rw-r--r--utils.h1
3 files changed, 16 insertions, 6 deletions
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index c589284..29ded12 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -126,8 +126,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: incorrect subvolume name '%s'\n",
newname);
goto out;
@@ -301,8 +300,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;
@@ -672,8 +670,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;
diff --git a/utils.c b/utils.c
index 4f17583..d2397e8 100644
--- a/utils.c
+++ b/utils.c
@@ -2405,3 +2405,15 @@ int test_minimum_size(const char *file, u32 leafsize)
close(fd);
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, "..");
+}
diff --git a/utils.h b/utils.h
index d7d2ad5..e3d80c1 100644
--- a/utils.h
+++ b/utils.h
@@ -116,6 +116,7 @@ int get_device_info(int fd, u64 devid,
int test_uuid_unique(char *fs_uuid);
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: