So that external programs can directly use it.

Signed-off-by: Gao Xiang <hsiang...@linux.alibaba.com>
---
 include/erofs/inode.h |  1 +
 lib/inode.c           | 25 ++++++++++++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/include/erofs/inode.h b/include/erofs/inode.h
index 5d6bc98..46d989c 100644
--- a/include/erofs/inode.h
+++ b/include/erofs/inode.h
@@ -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);
diff --git a/lib/inode.c b/lib/inode.c
index 9d7d518..14bd00a 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -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);
-- 
2.39.3

Reply via email to