diff options
author | David Sterba <dsterba@suse.cz> | 2015-04-17 18:20:32 +0200 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2015-04-22 18:21:47 +0200 |
commit | e57dc6c753e5eb1ed240ffefee7c80e22da08999 (patch) | |
tree | 1a7b921865d2d39593241b5c3321e16b39d4b8ab /cmds-filesystem.c | |
parent | 7ffccaf0c3b4d4979d7d74bab3d79d9541a6e665 (diff) |
btrfs-progs: fi resize: accept only directories as paths
Resize of a filesystem image does not work as expected. This has been
confusing and can have bad consequences as people have reported,
resizing the wrong filesystem.
Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'cmds-filesystem.c')
-rw-r--r-- | cmds-filesystem.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 188dbf0c..c9a34e4d 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -1234,6 +1234,7 @@ static int cmd_resize(int argc, char **argv) int fd, res, len, e; char *amount, *path; DIR *dirstream = NULL; + struct stat st; if (check_argc_exact(argc, 3)) usage(cmd_resize_usage); @@ -1248,6 +1249,20 @@ static int cmd_resize(int argc, char **argv) return 1; } + res = stat(path, &st); + if (res < 0) { + fprintf(stderr, "ERROR: resize: cannot stat %s: %s\n", + path, strerror(errno)); + return 1; + } + if (!S_ISDIR(st.st_mode)) { + fprintf(stderr, + "ERROR: resize works on mounted filesystems and accepts only\n" + "directories as argument. Passing file containing a btrfs image\n" + "would resize the underlying filesystem instead of the image.\n"); + return 1; + } + fd = open_file_or_dir(path, &dirstream); if (fd < 0) { fprintf(stderr, "ERROR: can't access '%s'\n", path); |