Skip to contentSkip to conversation

erofs-utils: mkfs: support fragments deduplication

RFC PATCH Superseded Yue Hu 1 participant 1 message Nov 21, 2022 Library code

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Yue Hu

author
#0 lore raw

RFC PATCH 1/1 erofs-utils: mkfs: support fragments deduplication

From: Yue Hu <[email protected]>

Previously, there's no fragments deduplication when this feature is introduced. Let's support it now.

---
 include/erofs/fragments.h |   3 +-
 lib/compress.c            | 117 ++++++++++++++++++++----
 lib/fragments.c           | 188 +++++++++++++++++++++++++++++++++++++-
 lib/inode.c               |  12 ++-
 4 files changed, 299 insertions(+), 21 deletions(-)
include/erofs/fragments.h +2 -1
index 5444384..6c51fc9 100644
@@ -15,8 +15,9 @@ extern "C"
 extern const char *frags_packedname;
 #define EROFS_PACKED_INODE	frags_packedname
 
+int z_erofs_fragments_dedupe(struct erofs_inode *inode, int fd, u32 *crc);
 int z_erofs_pack_fragments(struct erofs_inode *inode, void *data,
-			   unsigned int len);
+			   unsigned int len, u32 crc);
 struct erofs_inode *erofs_mkfs_build_fragments(void);
 int erofs_fragments_init(void);
 void erofs_fragments_exit(void);
lib/compress.c +101 -16

209 lines not on this page · raw message

lib/fragments.c +187 -1

218 lines not on this page · raw message

lib/inode.c +9 -3
index 9de4dec..cb2e057 100644
@@ -406,7 +406,7 @@ static int write_uncompressed_file_from_fd(struct erofs_inode *inode, int fd)
 	return 0;
 }
 
-int erofs_write_file(struct erofs_inode *inode)
+static int erofs_write_file(struct erofs_inode *inode)
 {
 	int ret, fd;
 
@@ -1196,7 +1196,10 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(int fd, const char *name)
 	struct erofs_inode *inode;
 	int ret;
 
-	lseek(fd, 0, SEEK_SET);
+	ret = lseek(fd, 0, SEEK_SET);
+	if (ret == -1)
+		return ERR_PTR(-errno);
+
 	ret = fstat64(fd, &st);
 	if (ret)
 		return ERR_PTR(-errno);
@@ -1223,7 +1226,10 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(int fd, const char *name)
 
 	ret = erofs_write_compressed_file(inode, fd);
 	if (ret == -ENOSPC) {
-		lseek(fd, 0, SEEK_SET);
+		ret = lseek(fd, 0, SEEK_SET);
+		if (ret == -1)
+			return ERR_PTR(-errno);
+
 		ret = write_uncompressed_file_from_fd(inode, fd);
 	}
 
Signature · 1 line
2.17.1