diff options
author | Pratik Shinde <pratikshinde320@gmail.com> | 2019-08-16 14:26:20 +0530 |
---|---|---|
committer | Gao Xiang <hsiangkao@aol.com> | 2019-08-17 04:38:34 +0800 |
commit | 4b71ae0e2d025700a02ce485c3d49b5bf97cf638 (patch) | |
tree | c5b3b8831443a4d87e6ae24693e73c01db3593cd | |
parent | 0f225449962b4a9716985e7530a395a9500d0de6 (diff) |
erofs-utils: fail the image creation when source path is not a directory file
In the erofs.mkfs utility, if the source path is not a directory,image
creation should not proceed.since root of the filesystem needs to be a directory.
moving the check to main function.
Signed-off-by: Pratik Shinde <pratikshinde320@gmail.com>
Reviewed-by: Li Guifu <blucerlee@gmail.com>
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
-rw-r--r-- | mkfs/main.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/mkfs/main.c b/mkfs/main.c index 93cacca..75e1d47 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -12,6 +12,7 @@ #include <stdlib.h> #include <limits.h> #include <libgen.h> +#include <sys/stat.h> #include "erofs/config.h" #include "erofs/print.h" #include "erofs/cache.h" @@ -187,6 +188,7 @@ int main(int argc, char **argv) struct erofs_buffer_head *sb_bh; struct erofs_inode *root_inode; erofs_nid_t root_nid; + struct stat64 st; erofs_init_configure(); fprintf(stderr, "%s %s\n", basename(argv[0]), cfg.c_version); @@ -198,6 +200,16 @@ int main(int argc, char **argv) return 1; } + err = lstat64(cfg.c_src_path, &st); + if (err) + return 1; + if ((st.st_mode & S_IFMT) != S_IFDIR) { + erofs_err("root of the filesystem is not a directory - %s", + cfg.c_src_path); + usage(); + return 1; + } + err = dev_open(cfg.c_img_path); if (err) { usage(); |