Skip to contentSkip to conversation

erofs-utils: move erofs_writesb() into lib/

PATCH New Gao Xiang 1 participant 2 messages Jun 7, 2024 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/2 erofs-utils: move erofs_writesb() into lib/

So that external programs can directly use it.

---
 include/erofs/internal.h |  4 +++
 lib/super.c              | 52 ++++++++++++++++++++++++++++++++
 mkfs/main.c              | 64 +++-------------------------------------
 3 files changed, 60 insertions(+), 60 deletions(-)
include/erofs/internal.h +4 -0
index d93bfab..f1d85be 100644
@@ -134,6 +134,8 @@ struct erofs_sb_info {
 	bool useqpl;
 };
 
+#define EROFS_SUPER_END (EROFS_SUPER_OFFSET + sizeof(struct erofs_super_block))
+
 /* make sure that any user of the erofs headers has atleast 64bit off_t type */
 extern int erofs_assert_largefile[sizeof(off_t)-8];
 
@@ -393,6 +395,8 @@ struct erofs_map_dev {
 /* super.c */
 int erofs_read_superblock(struct erofs_sb_info *sbi);
 void erofs_put_super(struct erofs_sb_info *sbi);
+int erofs_writesb(struct erofs_sb_info *sbi, struct erofs_buffer_head *sb_bh,
+		  erofs_blk_t *blocks);
 
 /* namei.c */
 int erofs_read_inode_from_disk(struct erofs_inode *vi);
lib/super.c +52 -0

61 lines not on this page · raw message

mkfs/main.c +4 -60

106 lines not on this page · raw message

Signature · 1 line
2.39.3
author
#1 lore raw

PATCH 2/2 erofs-utils: lib: split erofs_iflush()

So that external programs can directly use it.

---
 include/erofs/inode.h |  1 +
 lib/inode.c           | 25 ++++++++++++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)
include/erofs/inode.h +1 -0
index 5d6bc98..46d989c 100644
@@ -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);
lib/inode.c +20 -5
index 9d7d518..14bd00a 100644
@@ -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);
Signature · 1 line
2.39.3