[PATCH v2] erofs-utils: lib: correctly set {u,g}id in erofs_rebuild_make_root()
Gao Xiang
hsiangkao at linux.alibaba.com
Wed Jan 14 18:44:04 AEDT 2026
On 2026/1/14 15:38, Yifan Zhao wrote:
> In rebuild mode, the {u,g}id of the root inode is currently defaulted
> to 0 and is not controlled by --force_{u,g}id. This behavior also
> causes the {u,g}id of intermediate directories created by
> `erofs_rebuild_mkdir()` to be set to 0.
>
> This patch fixes the behavior by explicitly setting permissions for the
> root inode:
>
> - If --force-{u,g}id is not specified, it now defaults to the current
> user's {u,g}id.
> - If --force-{u,g}id is specified, it correctly updates the ownership
> for all files and directories.
>
> Signed-off-by: Yifan Zhao <zhaoyifan28 at huawei.com>
> ---
> include/erofs/inode.h | 3 ++-
> lib/inode.c | 5 ++++-
> mkfs/main.c | 2 +-
> 3 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/include/erofs/inode.h b/include/erofs/inode.h
> index 8b91771..2a7af31 100644
> --- a/include/erofs/inode.h
> +++ b/include/erofs/inode.h
> @@ -48,7 +48,8 @@ int erofs_importer_load_tree(struct erofs_importer *im, bool rebuild,
> struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_importer *im,
> int fd, const char *name);
> int erofs_fixup_root_inode(struct erofs_inode *root);
> -struct erofs_inode *erofs_rebuild_make_root(struct erofs_sb_info *sbi);
> +struct erofs_inode *erofs_rebuild_make_root(struct erofs_importer *im,
> + struct erofs_sb_info *sbi);
>
> #ifdef __cplusplus
> }
> diff --git a/lib/inode.c b/lib/inode.c
> index 26fefa2..4f87757 100644
> --- a/lib/inode.c
> +++ b/lib/inode.c
> @@ -2375,7 +2375,8 @@ int erofs_fixup_root_inode(struct erofs_inode *root)
> return err;
> }
>
> -struct erofs_inode *erofs_rebuild_make_root(struct erofs_sb_info *sbi)
> +struct erofs_inode *erofs_rebuild_make_root(struct erofs_importer *im,
> + struct erofs_sb_info *sbi)
> {
we could support !im, I mean
struct erofs_importer_params *params = im ? im->params : NULL;
> struct erofs_inode *root;
>
> @@ -2384,6 +2385,8 @@ struct erofs_inode *erofs_rebuild_make_root(struct erofs_sb_info *sbi)
> return root;
> root->i_srcpath = strdup("/");
> root->i_mode = S_IFDIR | 0777;
> + root->i_uid = im->params->fixed_uid == -1 ? getuid() : im->params->fixed_uid;
> + root->i_gid = im->params->fixed_gid == -1 ? getgid() : im->params->fixed_gid;
root->i_uid = params && params->fixed_uid < 0 ? getuid() :
params->fixed_uid;
...
Thanks,
Gao Xiang
More information about the Linux-erofs
mailing list