erofs-utils: lib: chagne function definition of erofs_blocklist_open()
PATCH v2 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.
---
v2: Let the caller to close the block_list.
v1: https://lore.kernel.org/all/[email protected]/
--- include/erofs/block_list.h | 4 ++-- lib/block_list.c | 17 +++++++---------- mkfs/main.c | 23 +++++++++++++++-------- 3 files changed, 24 insertions(+), 20 deletions(-)
include/erofs/block_list.h +2 -2
@@ -13,8 +13,8 @@ extern "C"#include "internal.h" -int erofs_blocklist_open (char *filename,bool srcmap); -void erofs_blocklist_close (void ); +int erofs_blocklist_open (FILE *fp,bool srcmap); +FILE *erofs_blocklist_close (void );void tarerofs_blocklist_write (erofs_blk_t blkaddr,erofs_blk_t nblocks,erofs_off_t srcoff);
lib/block_list.c +7 -10
@@ -13,23 +13,20 @@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 ; } -void erofs_blocklist_close (void ) +FILE *erofs_blocklist_close (void ) { -if (!block_list_fp) -return ; - -fclose (block_list_fp); +FILE *ret = block_list_fp; block_list_fp =NULL ; +return ret; }/* XXX: really need to be cleaned up */
mkfs/main.c +15 -8
@@ -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; }
@@ -1417,7 +1424,7 @@ exit:erofs_iput (root);z_erofs_compress_exit ();z_erofs_dedupe_exit (); -erofs_blocklist_close (); +fclose (erofs_blocklist_close ());erofs_dev_close (&sbi);erofs_cleanup_compress_hints ();erofs_cleanup_exclude_rules ();
Signature · 1 line
2.39.3
On 2024/7/2 20:14, Hongzhen Luo wrote:
erofs-utils: lib: change function definition of erofs_blocklist_open()
s/chagne/change/
Quoted 2 lines
Modified the definition of the function
erofs_blocklist_opento accept a file pointer rather than a string, for external use in liberofs.
Modify erofs_blocklist_open to accept a file pointer instead of a file path, making it suitable for external use in liberofs.
Quoted 65 lines
Signed-off-by Hongzhen Luo <[email protected]>---
v2: Let the caller to close theblock_list.
v1: https://lore.kernel.org/all/[email protected]/--- include/erofs/block_list.h | 4 ++-- lib/block_list.c | 17 +++++++---------- mkfs/main.c | 23 +++++++++++++++-------- 3 files changed, 24 insertions(+), 20 deletions(-)include/erofs/block_list.h +2
-2@@ -13,8 +13,8 @@ extern "C"#include "internal.h" -int erofs_blocklist_open (char *filename,bool srcmap); -void erofs_blocklist_close (void ); +int erofs_blocklist_open (FILE *fp,bool srcmap); +FILE *erofs_blocklist_close (void );void tarerofs_blocklist_write (erofs_blk_t blkaddr,erofs_blk_t nblocks,erofs_off_t srcoff);lib/block_list.c +7
-10@@ -13,23 +13,20 @@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 ; } -void erofs_blocklist_close (void ) +FILE *erofs_blocklist_close (void ) { -if (!block_list_fp) -return ; - -fclose (block_list_fp); +FILE *ret = block_list_fp; block_list_fp =NULL ; + return ret;> }/* XXX: really need to be cleaned up */ mkfs/main.c +0
-0
mkfs/main.c int main(int argc, char **argv) · line 1139
Quoted 7 lines
mkfs/main.c +4
-0@@ -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
FILE *blocklist;
Quoted 5 lines
mkfs/main.c +0
-0u32 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);
mkfs/main.c int main(int argc, char **argv) · line 1182
Quoted 10 lines
mkfs/main.c +3
-5return 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" );
blklst = fopen(cfg.block_list_file, "w");
Quoted 8 lines
mkfs/main.c +4
-0+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 ();
mkfs/main.c int main(int argc, char **argv) · line 1219
Quoted 6 lines
mkfs/main.c +1
-2@@ -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" );
blklst = fopen(erofstar.mapfile, "w");
mkfs/main.c exit: · line 1427
Quoted 11 lines
mkfs/main.c +3
-1+if (!mp_fp ||erofs_blocklist_open (mp_fp, true)) { + err = -errno;erofs_err ("failed to open %s" , erofstar.mapfile); goto exit; }@@ -1417,7 +1424,7 @@ exit:erofs_iput (root);z_erofs_compress_exit ();z_erofs_dedupe_exit (); -erofs_blocklist_close (); +fclose (erofs_blocklist_close ());
What if erofs_blocklist_close() returns NULL?
blklst = erofs_blocklist_close(); if (blklst) fclose(blklst);
Thanks,
Gao Xiang
Quoted 3 lines
mkfs/main.c +0
-0erofs_dev_close (&sbi);erofs_cleanup_compress_hints ();erofs_cleanup_exclude_rules ();