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>
This commit is contained in:
David Sterba 2015-04-17 18:20:32 +02:00
parent 7ffccaf0c3
commit e57dc6c753
2 changed files with 22 additions and 2 deletions

View File

@ -89,8 +89,13 @@ NOTE: the maximum allowable length shall be less than 256 chars
// Some wording are extracted by the resize2fs man page // Some wording are extracted by the resize2fs man page
*resize* [<devid>:][+/-]<size>[kKmMgGtTpPeE]|[<devid>:]max <path>:: *resize* [<devid>:][+/-]<size>[kKmMgGtTpPeE]|[<devid>:]max <path>::
Resize a filesystem identified by <path> for the underlying device Resize a mounted filesystem identified by directory <path>. A particular device
devid *online*. + can be resized by specifying a <devid>.
+
If <path> is a file containing a btrfs image then resize does not work as
expected and does not resize the image. This would resize the underlying
filesystem instead.
+
The devid can be found with *btrfs filesystem show* and The devid can be found with *btrfs filesystem show* and
defaults to 1 if not specified. defaults to 1 if not specified.
The <size> parameter specifies the new size of the filesystem. The <size> parameter specifies the new size of the filesystem.

View File

@ -1234,6 +1234,7 @@ static int cmd_resize(int argc, char **argv)
int fd, res, len, e; int fd, res, len, e;
char *amount, *path; char *amount, *path;
DIR *dirstream = NULL; DIR *dirstream = NULL;
struct stat st;
if (check_argc_exact(argc, 3)) if (check_argc_exact(argc, 3))
usage(cmd_resize_usage); usage(cmd_resize_usage);
@ -1248,6 +1249,20 @@ static int cmd_resize(int argc, char **argv)
return 1; 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); fd = open_file_or_dir(path, &dirstream);
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "ERROR: can't access '%s'\n", path); fprintf(stderr, "ERROR: can't access '%s'\n", path);