Skip to contentSkip to conversation

erofs-utils: lib: chagne function definition of erofs_blocklist_open()

PATCH Superseded Hongzhen Luo 2 participants 3 messages Jul 2, 2024 Library code

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: lib: chagne function definition of erofs_blocklist_open()

Modified the definition of the function erofs_blocklist_open to accept a file pointer rather than a string, for external use in liberofs.

---
 include/erofs/block_list.h |  2 +-
 lib/block_list.c           |  9 ++++-----
 mkfs/main.c                | 21 ++++++++++++++-------
 3 files changed, 19 insertions(+), 13 deletions(-)
include/erofs/block_list.h +1 -1
index 9f9975e..00da82c 100644
@@ -13,7 +13,7 @@ extern "C"
 
 #include "internal.h"
 
-int erofs_blocklist_open(char *filename, bool srcmap);
+int erofs_blocklist_open(FILE *fp, bool srcmap);
 void erofs_blocklist_close(void);
 
 void tarerofs_blocklist_write(erofs_blk_t blkaddr, erofs_blk_t nblocks,
lib/block_list.c +4 -5
index f47a746..d11e2cd 100644
@@ -13,12 +13,11 @@
 static FILE *block_list_fp;
 bool srcmap_enabled;
 
-int erofs_blocklist_open(char *filename, bool srcmap)
+int erofs_blocklist_open(FILE *fp, bool srcmap)
 {
-	block_list_fp = fopen(filename, "w");
-
-	if (!block_list_fp)
-		return -errno;
+	if (!fp)
+		return -ENOENT;
+	block_list_fp = fp;
 	srcmap_enabled = srcmap;
 	return 0;
 }
mkfs/main.c +14 -7
index 63ed877..79780d7 100644
@@ -1133,6 +1133,10 @@ int main(int argc, char **argv)
 	erofs_blk_t nblocks;
 	struct timeval t;
 	FILE *packedfile = NULL;
+	FILE  *mp_fp;
+#ifdef WITH_ANDROID	
+	FILE  *cfg_fp;
+#endif
 	u32 crc;
 
 	erofs_init_configure();
@@ -1173,11 +1177,13 @@ int main(int argc, char **argv)
 		erofs_err("failed to load fs config %s", cfg.fs_config_file);
 		return 1;
 	}
-
-	if (cfg.block_list_file &&
-	    erofs_blocklist_open(cfg.block_list_file, false)) {
-		erofs_err("failed to open %s", cfg.block_list_file);
-		return 1;
+	
+	if (cfg.block_list_file) {
+		cfg_fp = fopen(cfg.block_list_file, "w");
+		if (!cfg_fp || erofs_blocklist_open(cfg_fp, false)) {
+			erofs_err("failed to open %s", cfg.block_list_file);
+			return 1;
+		}
 	}
 #endif
 	erofs_show_config();
@@ -1210,8 +1216,9 @@ int main(int argc, char **argv)
 		erofstar.dev = rebuild_src_count + 1;
 
 		if (erofstar.mapfile) {
-			err = erofs_blocklist_open(erofstar.mapfile, true);
-			if (err) {
+			mp_fp = fopen(erofstar.mapfile, "w");
+			if (!mp_fp || erofs_blocklist_open(mp_fp, true)) {
+				err = -errno;
 				erofs_err("failed to open %s", erofstar.mapfile);
 				goto exit;
 			}
Signature · 1 line
2.39.3
#1 lore raw
Quoted 15 lines · Hongzhen Luo

Modified the definition of the function erofs_blocklist_open to accept a file pointer rather than a string, for external use in liberofs.

---
  include/erofs/block_list.h |  2 +-
  lib/block_list.c           |  9 ++++-----
  mkfs/main.c                | 21 ++++++++++++++-------
  3 files changed, 19 insertions(+), 13 deletions(-)
include/erofs/block_list.h +0 -0
index 9f9975e..00da82c 100644

include/erofs/block_list.h extern "C" · line 17

Quoted 6 lines
include/erofs/block_list.h +1 -1
@@ -13,7 +13,7 @@ extern "C"
 
  #include "internal.h"
 
-int erofs_blocklist_open(char *filename, bool srcmap);
+int erofs_blocklist_open(FILE *fp, bool srcmap);
  void erofs_blocklist_close(void);

In that case, should we don't fclose(block_list_fp); but return FILE * instead? As,

FILE *erofs_blocklist_close(void);

And makes the caller to close the FILE *.

Thanks,
Gao Xiang

#2 lore raw
Quoted 27 lines · Gao Xiang
Quoted 15 lines · Hongzhen Luo

Modified the definition of the function erofs_blocklist_open to accept a file pointer rather than a string, for external use in liberofs.

---
  include/erofs/block_list.h |  2 +- lib/block_list.c           |  9 ++++----- mkfs/main.c                | 21 ++++++++++++++-------

  3 files changed, 19 insertions(+), 13 deletions(-)
include/erofs/block_list.h +0 -0
index 9f9975e..00da82c 100644

include/erofs/block_list.h extern "C" · line 16

Quoted 4 lines
include/erofs/block_list.h +1 -0
@@ -13,7 +13,7 @@ extern "C"
     #include "internal.h"
   -int erofs_blocklist_open(char *filename, bool srcmap);
+int erofs_blocklist_open(FILE *fp, bool srcmap);
   void erofs_blocklist_close(void);

In that case, should we don't fclose(block_list_fp); but return FILE * instead? As,

Quoted 6 lines

FILE *erofs_blocklist_close(void);

And makes the caller to close the FILE *.

Thanks,
Gao Xiang

Sure, I will send an updated version later.