erofs-utils: lib: split erofs_iflush()
authorGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 7 Jun 2024 09:53:19 +0000 (17:53 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 11 Jun 2024 09:28:12 +0000 (17:28 +0800)
So that external programs can directly use it.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240607095319.2169172-2-hsiangkao@linux.alibaba.com
include/erofs/inode.h
lib/inode.c

index 5d6bc981576148c964cb71333e1802f39c131b0a..46d989ce24a87beaf236f269c5b63dd0e3cea96a 100644 (file)
@@ -31,6 +31,7 @@ struct erofs_inode *erofs_iget(dev_t dev, ino_t ino);
 struct erofs_inode *erofs_iget_by_nid(erofs_nid_t nid);
 unsigned int erofs_iput(struct erofs_inode *inode);
 erofs_nid_t erofs_lookupnid(struct erofs_inode *inode);
+int erofs_iflush(struct erofs_inode *inode);
 struct erofs_dentry *erofs_d_alloc(struct erofs_inode *parent,
                                   const char *name);
 int erofs_rebuild_dump_tree(struct erofs_inode *dir);
index 9d7d518c3c1f951e56c58ea8ce336f8b897ec48e..14bd00aee8452a3aee411b42a11eb7b6989198a7 100644 (file)
@@ -493,18 +493,22 @@ int erofs_write_unencoded_file(struct erofs_inode *inode, int fd, u64 fpos)
        return write_uncompressed_file_from_fd(inode, fd);
 }
 
-static int erofs_bh_flush_write_inode(struct erofs_buffer_head *bh)
+int erofs_iflush(struct erofs_inode *inode)
 {
-       struct erofs_inode *const inode = bh->fsprivate;
-       struct erofs_sb_info *sbi = inode->sbi;
        const u16 icount = EROFS_INODE_XATTR_ICOUNT(inode->xattr_isize);
-       erofs_off_t off = erofs_btell(bh, false);
+       struct erofs_sb_info *sbi = inode->sbi;
+       erofs_off_t off;
        union {
                struct erofs_inode_compact dic;
                struct erofs_inode_extended die;
-       } u = { {0}, };
+       } u = {};
        int ret;
 
+       if (inode->bh)
+               off = erofs_btell(inode->bh, false);
+       else
+               off = erofs_iloc(inode);
+
        switch (inode->inode_isize) {
        case sizeof(struct erofs_inode_compact):
                u.dic.i_format = cpu_to_le16(0 | (inode->datalayout << 1));
@@ -616,7 +620,18 @@ static int erofs_bh_flush_write_inode(struct erofs_buffer_head *bh)
                                return ret;
                }
        }
+       return 0;
+}
 
+static int erofs_bh_flush_write_inode(struct erofs_buffer_head *bh)
+{
+       struct erofs_inode *inode = bh->fsprivate;
+       int ret;
+
+       DBG_BUGON(inode->bh != bh);
+       ret = erofs_iflush(inode);
+       if (ret)
+               return ret;
        inode->bh = NULL;
        erofs_iput(inode);
        return erofs_bh_flush_generic_end(bh);