linux-erofs.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] erofs-utils: stop mkfs when access permission denied
@ 2020-11-22  4:27 Li Guifu via Linux-erofs
  2020-11-22  5:37 ` Gao Xiang
  2020-11-22  8:55 ` [PATCH v2] erofs-utils: stop build tree if file fails to open Li Guifu via Linux-erofs
  0 siblings, 2 replies; 3+ messages in thread
From: Li Guifu via Linux-erofs @ 2020-11-22  4:27 UTC (permalink / raw)
  To: linux-erofs

It would not has the permission to access one file when mkfs.erofs
was not run in the root mode, eg run without sudo, So stop and
exit immediately

Signed-off-by: Li Guifu <bluce.lee@aliyun.com>
---
 lib/inode.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/inode.c b/lib/inode.c
index fee5c96..4641561 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -364,6 +364,7 @@ int erofs_write_file(struct erofs_inode *inode)
 	}
 
 	/* fallback to all data uncompressed */
+	errno = 0;
 	fd = open(inode->i_srcpath, O_RDONLY | O_BINARY);
 	if (fd < 0)
 		return -errno;
@@ -908,7 +909,9 @@ struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir)
 			if (ret)
 				return ERR_PTR(ret);
 		} else {
-			erofs_write_file(dir);
+			ret = erofs_write_file(dir);
+			if (ret)
+				return ERR_PTR(ret);
 		}
 
 		erofs_prepare_inode_buffer(dir);
@@ -982,10 +985,11 @@ struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir)
 
 		d->inode = erofs_mkfs_build_tree_from_path(dir, buf);
 		if (IS_ERR(d->inode)) {
+			ret = PTR_ERR(d->inode);
 fail:
 			d->inode = NULL;
 			d->type = EROFS_FT_UNKNOWN;
-			continue;
+			goto err_closedir;
 		}
 
 		d->type = erofs_type_by_mode[d->inode->i_mode >> S_SHIFT];
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] erofs-utils: stop mkfs when access permission denied
  2020-11-22  4:27 [PATCH] erofs-utils: stop mkfs when access permission denied Li Guifu via Linux-erofs
@ 2020-11-22  5:37 ` Gao Xiang
  2020-11-22  8:55 ` [PATCH v2] erofs-utils: stop build tree if file fails to open Li Guifu via Linux-erofs
  1 sibling, 0 replies; 3+ messages in thread
From: Gao Xiang @ 2020-11-22  5:37 UTC (permalink / raw)
  To: Li Guifu, Li Guifu; +Cc: linux-erofs

Hi Guifu,

I'd suggest the following subject...

erofs-utils: stop building tree if file fails to open

On Sun, Nov 22, 2020 at 12:27:59PM +0800, Li Guifu via Linux-erofs wrote:
> It would not has the permission to access one file when mkfs.erofs
> was not run in the root mode, eg run without sudo, So stop and
> exit immediately

stop and exit immediately if it fails to open a file, e.g mkfs.erofs
doesn't run under the root user (e.g. run without sudo.)

> 
> Signed-off-by: Li Guifu <bluce.lee@aliyun.com>
> ---
>  lib/inode.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/inode.c b/lib/inode.c
> index fee5c96..4641561 100644
> --- a/lib/inode.c
> +++ b/lib/inode.c
> @@ -364,6 +364,7 @@ int erofs_write_file(struct erofs_inode *inode)
>  	}
>  
>  	/* fallback to all data uncompressed */
> +	errno = 0;

Why is it necessary, -errno is only used and returned if (fd < 0)

Could you update and resend this?

Thanks,
Gao Xiang

>  	fd = open(inode->i_srcpath, O_RDONLY | O_BINARY);
>  	if (fd < 0)
>  		return -errno;
> @@ -908,7 +909,9 @@ struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir)
>  			if (ret)
>  				return ERR_PTR(ret);
>  		} else {
> -			erofs_write_file(dir);
> +			ret = erofs_write_file(dir);
> +			if (ret)
> +				return ERR_PTR(ret);
>  		}
>  
>  		erofs_prepare_inode_buffer(dir);
> @@ -982,10 +985,11 @@ struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir)
>  
>  		d->inode = erofs_mkfs_build_tree_from_path(dir, buf);
>  		if (IS_ERR(d->inode)) {
> +			ret = PTR_ERR(d->inode);
>  fail:
>  			d->inode = NULL;
>  			d->type = EROFS_FT_UNKNOWN;
> -			continue;
> +			goto err_closedir;
>  		}
>  
>  		d->type = erofs_type_by_mode[d->inode->i_mode >> S_SHIFT];
> -- 
> 2.17.1
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] erofs-utils: stop build tree if file fails to open
  2020-11-22  4:27 [PATCH] erofs-utils: stop mkfs when access permission denied Li Guifu via Linux-erofs
  2020-11-22  5:37 ` Gao Xiang
@ 2020-11-22  8:55 ` Li Guifu via Linux-erofs
  1 sibling, 0 replies; 3+ messages in thread
From: Li Guifu via Linux-erofs @ 2020-11-22  8:55 UTC (permalink / raw)
  To: linux-erofs

stop and exit immediately if it fails to open a file, e.g mkfs.erofs
doesn't run under the root user (e.g. run without sudo.)

Signed-off-by: Li Guifu <bluce.lee@aliyun.com>
---
 lib/inode.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/inode.c b/lib/inode.c
index fee5c96..eb2e0f2 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -908,7 +908,9 @@ struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir)
 			if (ret)
 				return ERR_PTR(ret);
 		} else {
-			erofs_write_file(dir);
+			ret = erofs_write_file(dir);
+			if (ret)
+				return ERR_PTR(ret);
 		}
 
 		erofs_prepare_inode_buffer(dir);
@@ -982,10 +984,11 @@ struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir)
 
 		d->inode = erofs_mkfs_build_tree_from_path(dir, buf);
 		if (IS_ERR(d->inode)) {
+			ret = PTR_ERR(d->inode);
 fail:
 			d->inode = NULL;
 			d->type = EROFS_FT_UNKNOWN;
-			continue;
+			goto err_closedir;
 		}
 
 		d->type = erofs_type_by_mode[d->inode->i_mode >> S_SHIFT];
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-22  8:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-22  4:27 [PATCH] erofs-utils: stop mkfs when access permission denied Li Guifu via Linux-erofs
2020-11-22  5:37 ` Gao Xiang
2020-11-22  8:55 ` [PATCH v2] erofs-utils: stop build tree if file fails to open Li Guifu via Linux-erofs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).