* [PATCH] erofs-utils: Fail the image creation when source path is not a directory file.
@ 2019-08-16 8:56 Pratik Shinde
2019-08-16 12:32 ` Gao Xiang
2019-08-16 15:36 ` Li Guifu
0 siblings, 2 replies; 6+ messages in thread
From: Pratik Shinde @ 2019-08-16 8:56 UTC (permalink / raw)
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 at gmail.com>
---
mkfs/main.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/mkfs/main.c b/mkfs/main.c
index 93cacca..8fbfced 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);
@@ -197,6 +199,15 @@ int main(int argc, char **argv)
usage();
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) {
--
2.9.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] erofs-utils: Fail the image creation when source path is not a directory file.
2019-08-16 8:56 [PATCH] erofs-utils: Fail the image creation when source path is not a directory file Pratik Shinde
@ 2019-08-16 12:32 ` Gao Xiang
2019-08-16 15:36 ` Li Guifu
1 sibling, 0 replies; 6+ messages in thread
From: Gao Xiang @ 2019-08-16 12:32 UTC (permalink / raw)
On Fri, Aug 16, 2019@02:26:20PM +0530, Pratik Shinde wrote:
> 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 at gmail.com>
Applied to dev branch, thank you!
Thanks,
Gao Xiang
> ---
> mkfs/main.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/mkfs/main.c b/mkfs/main.c
> index 93cacca..8fbfced 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);
> @@ -197,6 +199,15 @@ int main(int argc, char **argv)
> usage();
> 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) {
> --
> 2.9.3
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] erofs-utils: Fail the image creation when source path is not a directory file.
2019-08-16 8:56 [PATCH] erofs-utils: Fail the image creation when source path is not a directory file Pratik Shinde
2019-08-16 12:32 ` Gao Xiang
@ 2019-08-16 15:36 ` Li Guifu
2019-08-16 20:43 ` Gao Xiang
1 sibling, 1 reply; 6+ messages in thread
From: Li Guifu @ 2019-08-16 15:36 UTC (permalink / raw)
? 2019/8/16 16:56, Pratik Shinde ??:
> 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 at gmail.com>
It looks good.
Reviewed-by Li Guifu <blucerlee at gmail.com>
Thanks
> ---
> mkfs/main.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/mkfs/main.c b/mkfs/main.c
> index 93cacca..8fbfced 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);
> @@ -197,6 +199,15 @@ int main(int argc, char **argv)
> usage();
> 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) {
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] erofs-utils: Fail the image creation when source path is not a directory file.
2019-08-16 15:36 ` Li Guifu
@ 2019-08-16 20:43 ` Gao Xiang
0 siblings, 0 replies; 6+ messages in thread
From: Gao Xiang @ 2019-08-16 20:43 UTC (permalink / raw)
On Fri, Aug 16, 2019@11:36:24PM +0800, Li Guifu wrote:
>
> ?? 2019/8/16 16:56, Pratik Shinde ????:
> > 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 at gmail.com>
>
> It looks good.
> Reviewed-by Li Guifu <blucerlee at gmail.com>
Fold in the original patch as well :)
Thanks,
Gao Xiang
> Thanks
>
>
> > ---
> > mkfs/main.c | 11 +++++++++++
> > 1 file changed, 11 insertions(+)
> >
> > diff --git a/mkfs/main.c b/mkfs/main.c
> > index 93cacca..8fbfced 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);
> > @@ -197,6 +199,15 @@ int main(int argc, char **argv)
> > usage();
> > 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) {
> >
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] erofs-utils : Fail the image creation when source path is not a directory file.
2019-08-16 7:08 [PATCH] erofs-utils : " Pratik Shinde
@ 2019-08-16 7:37 ` Gao Xiang
0 siblings, 0 replies; 6+ messages in thread
From: Gao Xiang @ 2019-08-16 7:37 UTC (permalink / raw)
Hi Pratik,
On Fri, Aug 16, 2019@12:38:46PM +0530, Pratik Shinde wrote:
> 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.
>
> In the erofs kernel code, we return error in case root inode(read from disk) is not
> a directory.But the mkfs utility lets you create an image based on Regular file
> (S_IFREG) too.
Yes, You are right. :)
Just a minor suggestion, how about moving the logic to main()?
194 err = mkfs_parse_options_cfg(argc, argv);
195 if (err) {
196 if (err == -EINVAL)
197 usage();
198 return 1;
199 }
^ here
200
201 err = dev_open(cfg.c_img_path);
202 if (err) {
203 usage();
204 return 1;
205 }
Does it sound good to you? and I will test this patch later :)
Thanks,
Gao Xiang
>
> Signed-off-by: Pratik Shinde <pratikshinde320 at gmail.com>
> ---
> mkfs/main.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/mkfs/main.c b/mkfs/main.c
> index 93cacca..e72b9e2 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"
> @@ -76,8 +77,8 @@ static int parse_extended_opts(const char *opts)
>
> static int mkfs_parse_options_cfg(int argc, char *argv[])
> {
> - int opt, i;
> -
> + int opt, i, ret;
> + struct stat64 st;
> while ((opt = getopt(argc, argv, "d:z:E:")) != -1) {
> switch (opt) {
> case 'z':
> @@ -135,7 +136,14 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
> erofs_strerror(-errno));
> return -ENOENT;
> }
> -
> + ret = lstat64(cfg.c_src_path, &st);
> + if (ret)
> + return -EINVAL;
> + if ((st.st_mode & S_IFMT) != S_IFDIR) {
> + erofs_err("root of the filesystem is not a directory - %s",
> + cfg.c_src_path);
> + return -EINVAL;
> + }
> if (optind < argc) {
> erofs_err("Unexpected argument: %s\n", argv[optind]);
> return -EINVAL;
> --
> 2.9.3
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] erofs-utils : Fail the image creation when source path is not a directory file.
@ 2019-08-16 7:08 Pratik Shinde
2019-08-16 7:37 ` Gao Xiang
0 siblings, 1 reply; 6+ messages in thread
From: Pratik Shinde @ 2019-08-16 7:08 UTC (permalink / raw)
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.
In the erofs kernel code, we return error in case root inode(read from disk) is not
a directory.But the mkfs utility lets you create an image based on Regular file
(S_IFREG) too.
Signed-off-by: Pratik Shinde <pratikshinde320 at gmail.com>
---
mkfs/main.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/mkfs/main.c b/mkfs/main.c
index 93cacca..e72b9e2 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"
@@ -76,8 +77,8 @@ static int parse_extended_opts(const char *opts)
static int mkfs_parse_options_cfg(int argc, char *argv[])
{
- int opt, i;
-
+ int opt, i, ret;
+ struct stat64 st;
while ((opt = getopt(argc, argv, "d:z:E:")) != -1) {
switch (opt) {
case 'z':
@@ -135,7 +136,14 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
erofs_strerror(-errno));
return -ENOENT;
}
-
+ ret = lstat64(cfg.c_src_path, &st);
+ if (ret)
+ return -EINVAL;
+ if ((st.st_mode & S_IFMT) != S_IFDIR) {
+ erofs_err("root of the filesystem is not a directory - %s",
+ cfg.c_src_path);
+ return -EINVAL;
+ }
if (optind < argc) {
erofs_err("Unexpected argument: %s\n", argv[optind]);
return -EINVAL;
--
2.9.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-08-16 20:43 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-16 8:56 [PATCH] erofs-utils: Fail the image creation when source path is not a directory file Pratik Shinde
2019-08-16 12:32 ` Gao Xiang
2019-08-16 15:36 ` Li Guifu
2019-08-16 20:43 ` Gao Xiang
-- strict thread matches above, loose matches on Subject: below --
2019-08-16 7:08 [PATCH] erofs-utils : " Pratik Shinde
2019-08-16 7:37 ` Gao Xiang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.