[PATCH 3/2] TEST CODE
Gao Xiang
hsiangkao at linux.alibaba.com
Wed Sep 17 18:16:54 AEST 2025
This reverts commit ad879589e4a281cbd05a1fd9c8d8865a34cd8d87.
---
lib/gzran.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/lib/gzran.c b/lib/gzran.c
index 6a6fddc..6d55c4a 100644
--- a/lib/gzran.c
+++ b/lib/gzran.c
@@ -390,3 +390,54 @@ struct erofs_vfile *erofs_gzran_zinfo_open(struct erofs_vfile *vin,
return ERR_PTR(-EOPNOTSUPP);
}
#endif
+
+#ifdef TEST
+#include <fcntl.h>
+
+int main(int argc, char *argv[])
+{
+ struct erofs_vfile vin, *vout;
+ int zinfo_len, fd, len, offset;
+ char *zinfo_buf;
+ char *outbuf;
+
+ if (argc < 5)
+ exit(1);
+ fd = open(argv[2], O_RDONLY);
+ if (fd < 0)
+ exit(1);
+ zinfo_len = lseek(fd, 0, SEEK_END);
+ if (zinfo_len < 0)
+ exit(1);
+ (void)lseek(fd, 0, SEEK_SET);
+
+ zinfo_buf = malloc(zinfo_len);
+ if (!zinfo_buf)
+ exit(1);
+ if (read(fd, zinfo_buf, zinfo_len) < zinfo_len)
+ exit(1);
+ close(fd);
+
+ fd = open(argv[1], O_RDONLY);
+ if (fd < 0)
+ exit(1);
+ vin = (struct erofs_vfile) {.fd = fd};
+
+ vout = erofs_gzran_zinfo_open(&vin, zinfo_buf, zinfo_len);
+ if (IS_ERR(vout))
+ exit(1);
+ free(zinfo_buf);
+
+ len = atoi(argv[4]);
+ offset = atoi(argv[3]);
+
+ outbuf = malloc(len);
+ if (!outbuf)
+ exit(1);
+ erofs_io_pread(vout, outbuf, len, offset);
+ write(STDOUT_FILENO, outbuf, len);
+ erofs_io_close(vout);
+ return 0;
+}
+
+#endif
--
2.43.5
More information about the Linux-erofs
mailing list