check slash in deleting subvolumes

For now, btrfsctl does not check whether subvolume name contains slash
or not. If someone specify subvolume with trailing slash (in case
using shell completion), ioctl returns with EINVAL and this error
may confuse some careless users like me. So, this patch adds check
slashes in subvolume name in deletion same as snapshot/subvolume
creating. But considering shell completion, this fix allows trailing
slash.

Signed-off-by: TARUISI Hiroaki <taruishi.hiroak@jp.fujitsu.com>
This commit is contained in:
TARUISI Hiroaki 2010-09-09 11:19:25 +08:00 committed by Chris Mason
parent 34915ad27b
commit 48f16a69d7
1 changed files with 11 additions and 0 deletions

View File

@ -103,6 +103,7 @@ int main(int ac, char **av)
int i; int i;
unsigned long command = 0; unsigned long command = 0;
int len; int len;
char *pos;
char *fullpath; char *fullpath;
u64 objectid = 0; u64 objectid = 0;
@ -171,6 +172,16 @@ int main(int ac, char **av)
command = BTRFS_IOC_SNAP_DESTROY; command = BTRFS_IOC_SNAP_DESTROY;
name = av[i + 1]; name = av[i + 1];
len = strlen(name); len = strlen(name);
pos = strchr(name, '/');
if (pos) {
if (*(pos + 1) == '\0')
*(pos) = '\0';
else {
fprintf(stderr,
"error: / not allowed in names\n");
exit(1);
}
}
if (len == 0 || len >= BTRFS_VOL_NAME_MAX) { if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
fprintf(stderr, "-D size too long\n"); fprintf(stderr, "-D size too long\n");
exit(1); exit(1);