summaryrefslogtreecommitdiff
path: root/cmds-subvolume.c
diff options
context:
space:
mode:
authorEric Sandeen <sandeen@redhat.com>2013-01-25 13:27:47 -0600
committerZach Brown <zab@redhat.com>2013-02-05 16:09:41 -0800
commitbcb2b73358f1c05e6b5c48cfd19e3762cc69c677 (patch)
tree0527a68a1c20f3777f1c5f3559e29c424fb4dde4 /cmds-subvolume.c
parent7ced17b07f9524c999395240458a46e403036d6b (diff)
btrfs-progs: simplify ioctl name copy and null termination
In the places where we copy a string into the name member of btrfs_ioctl_vol_args or btrfs_ioctl_vol_args_v2, we use strncopy (to not overflow the name array) and then set the last position to the null character. Howver, in both cases the arrays are defined with: char name[MAX+1]; hence the last array position is name[MAX]. In most cases, we now insert the null at name[MAX-1] which deprives us of one useful character. Even the above isn't consistent through the code, so make some helper code to make it simple, i.e. strncpy_null(dest, src) which automatically does the right thing based on the size of dest. Thanks to Zach Brown for the macro suggestion. Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Diffstat (limited to 'cmds-subvolume.c')
-rw-r--r--cmds-subvolume.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index 1432b997..ea128fce 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -32,6 +32,7 @@
#include "ctree.h"
#include "commands.h"
+#include "utils.h"
#include "btrfs-list.h"
#include "utils.h"
@@ -138,8 +139,7 @@ static int cmd_subvol_create(int argc, char **argv)
struct btrfs_ioctl_vol_args_v2 args;
memset(&args, 0, sizeof(args));
- strncpy(args.name, newname, BTRFS_SUBVOL_NAME_MAX);
- args.name[BTRFS_SUBVOL_NAME_MAX-1] = 0;
+ strncpy_null(args.name, newname);
args.flags |= BTRFS_SUBVOL_QGROUP_INHERIT;
args.size = qgroup_inherit_size(inherit);
args.qgroup_inherit = inherit;
@@ -149,8 +149,7 @@ static int cmd_subvol_create(int argc, char **argv)
struct btrfs_ioctl_vol_args args;
memset(&args, 0, sizeof(args));
- strncpy(args.name, newname, BTRFS_PATH_NAME_MAX);
- args.name[BTRFS_PATH_NAME_MAX-1] = 0;
+ strncpy_null(args.name, newname);
res = ioctl(fddst, BTRFS_IOC_SUBVOL_CREATE, &args);
}
@@ -250,8 +249,7 @@ again:
}
printf("Delete subvolume '%s/%s'\n", dname, vname);
- strncpy(args.name, vname, BTRFS_PATH_NAME_MAX);
- args.name[BTRFS_PATH_NAME_MAX-1] = 0;
+ strncpy_null(args.name, vname);
res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args);
e = errno;
@@ -597,8 +595,7 @@ static int cmd_snapshot(int argc, char **argv)
args.size = qgroup_inherit_size(inherit);
args.qgroup_inherit = inherit;
}
- strncpy(args.name, newname, BTRFS_SUBVOL_NAME_MAX);
- args.name[BTRFS_SUBVOL_NAME_MAX-1] = 0;
+ strncpy_null(args.name, newname);
res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE_V2, &args);
e = errno;