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;
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;
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;
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, "..");
+}
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: