aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGao Xiang <hsiangkao@linux.alibaba.com>2023-09-20 13:12:23 +0800
committerGao Xiang <hsiangkao@linux.alibaba.com>2023-09-20 19:35:12 +0800
commit4fe36e57f20649f07fbd9e94dcb5f53a68a3f985 (patch)
tree222b056bf3245f09814bece8957be0d5cba089b2
parentc58fa46e949f419fdb02669c1e0f4e2665042173 (diff)
downloaderofs-utils-4fe36e57f20649f07fbd9e94dcb5f53a68a3f985.tar.gz
erofs-utils: lib: fix --force-{g,u}id support for tarerofs
Temporarily move the common part into __erofs_fill_inode() for tarerofs. Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Link: https://lore.kernel.org/r/20230920051223.657008-1-hsiangkao@linux.alibaba.com
-rw-r--r--include/erofs/inode.h2
-rw-r--r--lib/inode.c19
-rw-r--r--lib/tar.c16
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 d321602..fb062a1 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 54acba5..0744972 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) {