[PATCH] erofs-utils: lib: add fallback for SEEK_{DATA,HOLE}

Gao Xiang hsiangkao at linux.alibaba.com
Tue Jan 6 14:58:18 AEDT 2026


Since SEEK_{DATA,HOLE} are part of the POSIX standard [1].

[1] https://pubs.opengroup.org/onlinepubs/9799919799/functions/lseek.html
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
 include/erofs/io.h | 11 +++++++++++
 lib/blobchunk.c    |  4 ----
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/include/erofs/io.h b/include/erofs/io.h
index 4bc216a2eace..9533efc2d20a 100644
--- a/include/erofs/io.h
+++ b/include/erofs/io.h
@@ -24,6 +24,17 @@ extern "C"
 #define O_BINARY	0
 #endif
 
+/*
+ * seek stuff
+ */
+#ifndef SEEK_DATA
+#define SEEK_DATA	3
+#endif
+
+#ifndef SEEK_HOLE
+#define SEEK_HOLE	4
+#endif
+
 struct erofs_vfile;
 
 struct erofs_vfops {
diff --git a/lib/blobchunk.c b/lib/blobchunk.c
index 3b1c97b5d874..c66bd2020e45 100644
--- a/lib/blobchunk.c
+++ b/lib/blobchunk.c
@@ -277,14 +277,12 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd,
 	u8 *chunkdata;
 	int ret;
 
-#ifdef SEEK_DATA
 	/* if the file is fully sparsed, use one big chunk instead */
 	if (lseek(fd, startoff, SEEK_DATA) < 0 && errno == ENXIO) {
 		chunkbits = ilog2(inode->i_size - 1) + 1;
 		if (chunkbits < sbi->blkszbits)
 			chunkbits = sbi->blkszbits;
 	}
-#endif
 	if (chunkbits - sbi->blkszbits > EROFS_CHUNK_FORMAT_BLKBITS_MASK)
 		chunkbits = EROFS_CHUNK_FORMAT_BLKBITS_MASK + sbi->blkszbits;
 	chunksize = 1ULL << chunkbits;
@@ -332,7 +330,6 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd,
 	}
 
 	for (pos = 0; pos < inode->i_size; pos += len) {
-#ifdef SEEK_DATA
 		off_t offset = lseek(fd, pos + startoff, SEEK_DATA);
 
 		if (offset < 0) {
@@ -369,7 +366,6 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd,
 			len = 0;
 			continue;
 		}
-#endif
 
 		len = min_t(u64, inode->i_size - pos, chunksize);
 		ret = read(fd, chunkdata, len);
-- 
2.43.5



More information about the Linux-erofs mailing list