[PATCH] erofs-utils: lib: fix --force-{g,u}id support for tarerofs
Gao Xiang
hsiangkao at linux.alibaba.com
Wed Sep 20 15:12:23 AEST 2023
Temporarily move the common part into __erofs_fill_inode() for tarerofs.
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
include/erofs/inode.h | 2 ++
lib/inode.c | 19 ++++++++++++++++---
lib/tar.c | 16 ++++++++++------
3 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/include/erofs/inode.h b/include/erofs/inode.h
index fe9dda2..bcfd98e 100644
--- a/include/erofs/inode.h
+++ b/include/erofs/inode.h
@@ -34,6 +34,8 @@ struct erofs_dentry *erofs_d_alloc(struct erofs_inode *parent,
const char *name);
int erofs_rebuild_dump_tree(struct erofs_inode *dir);
int erofs_init_empty_dir(struct erofs_inode *dir);
+int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
+ const char *path);
struct erofs_inode *erofs_new_inode(void);
struct erofs_inode *erofs_mkfs_build_tree_from_path(const char *path);
struct erofs_inode *erofs_mkfs_build_special_from_fd(int fd, const char *name);
diff --git a/lib/inode.c b/lib/inode.c
index 4dc8260..b534b0a 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -912,15 +912,15 @@ static int erofs_droid_inode_fsconfig(struct erofs_inode *inode,
}
#endif
-static int erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
- const char *path)
+int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
+ const char *path)
{
int err = erofs_droid_inode_fsconfig(inode, st, path);
struct erofs_sb_info *sbi = inode->sbi;
if (err)
return err;
- inode->i_mode = st->st_mode;
+
inode->i_uid = cfg.c_uid == -1 ? st->st_uid : cfg.c_uid;
inode->i_gid = cfg.c_gid == -1 ? st->st_gid : cfg.c_gid;
@@ -945,6 +945,19 @@ static int erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
default:
break;
}
+
+ return 0;
+}
+
+static int erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
+ const char *path)
+{
+ int err = __erofs_fill_inode(inode, st, path);
+
+ if (err)
+ return err;
+
+ inode->i_mode = st->st_mode;
inode->i_nlink = 1; /* fix up later if needed */
switch (inode->i_mode & S_IFMT) {
diff --git a/lib/tar.c b/lib/tar.c
index b159d70..52036a6 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -923,11 +923,17 @@ new_inode:
if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))
inode->u.i_rdev = erofs_new_encode_dev(st.st_rdev);
}
+
inode->i_srcpath = strdup(eh.path);
- inode->i_uid = st.st_uid;
- inode->i_gid = st.st_gid;
+ if (!inode->i_srcpath) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ ret = __erofs_fill_inode(inode, &st, eh.path);
+ if (ret)
+ goto out;
inode->i_size = st.st_size;
- inode->i_mtime = st.st_mtime;
if (!S_ISDIR(inode->i_mode)) {
if (S_ISLNK(inode->i_mode)) {
@@ -940,10 +946,8 @@ new_inode:
data_offset);
else
ret = tarerofs_write_file_data(inode, tar);
- if (ret) {
- erofs_iput(inode);
+ if (ret)
goto out;
- }
}
inode->i_nlink++;
} else if (!inode->i_nlink) {
--
2.39.3
More information about the Linux-erofs
mailing list