From 47c1cfd5e8ec289597f7342f88e103811511f0a8 Mon Sep 17 00:00:00 2001 From: Zhihao Cheng Date: Mon, 11 Nov 2024 17:08:08 +0800 Subject: fsck.ubifs: Move common functions and data structures into check_space.c This is a preparation for adding LPT checking support. Move some data structures and functions into check_space.c, also factor out some common functions in libubifs: 1. Move 'lpts' from rebuild module, make it resuable for non-rebuild_fs modes. 2. Move function 'get_free_leb' from rebuild_fs.c, it could be reused in building LPT. 3. Move function 'build_lpt' from rebuild_fs.c, it could be reused in building LPT. 4. Factor out lpt nodes freeing into a new function ubifs_free_lpt_nodes. 5. Factor out nnode dirty marking implementations into a new function ubifs_make_nnode_dirty. 5. Export the function of nnode number calculation, calc_nnode_num is renamed as ubifs_calc_nnode_num. 6. Export the function of making pnode dirty, do_make_pnode_dirty is renamed as ubifs_make_pnode_dirty. 7. Rename next_pnode_to_dirty to ubifs_find_next_pnode and export it. 8. Export free_buds and expend its parameters. Signed-off-by: Zhihao Cheng Signed-off-by: David Oberhollenzer --- ubifs-utils/fsck.ubifs/fsck.ubifs.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'ubifs-utils/fsck.ubifs/fsck.ubifs.h') diff --git a/ubifs-utils/fsck.ubifs/fsck.ubifs.h b/ubifs-utils/fsck.ubifs/fsck.ubifs.h index 3c0f2af..ade27fe 100644 --- a/ubifs-utils/fsck.ubifs/fsck.ubifs.h +++ b/ubifs-utils/fsck.ubifs/fsck.ubifs.h @@ -48,6 +48,9 @@ enum { SB_CORRUPTED = 0, MST_CORRUPTED, LOG_CORRUPTED, BUD_CORRUPTED, enum { HAS_DATA_CORRUPTED = 1, HAS_TNC_CORRUPTED = 2 }; +typedef int (*calculate_lp_callback)(struct ubifs_info *c, + int index, int *free, int *dirty); + struct scanned_file; /** @@ -199,14 +202,12 @@ struct invalid_file_problem { /** * ubifs_rebuild_info - UBIFS rebuilding information. - * @lpts: lprops table * @write_buf: write buffer for LEB @head_lnum * @head_lnum: current writing LEB number * @head_offs: current writing position in LEB @head_lnum * @need_update_lpt: whether to update lpt while writing index nodes */ struct ubifs_rebuild_info { - struct ubifs_lprops *lpts; void *write_buf; int head_lnum; int head_offs; @@ -222,6 +223,7 @@ struct ubifs_rebuild_info { * @scanned_files: tree of all scanned files * @used_lebs: a bitmap used for recording used lebs * @disconnected_files: regular files without dentries + * @lpts: lprops table * @try_rebuild: %true means that try to rebuild fs when fsck failed * @rebuild: rebuilding-related information */ @@ -232,6 +234,7 @@ struct ubifs_fsck_info { struct rb_root scanned_files; unsigned long *used_lebs; struct list_head disconnected_files; + struct ubifs_lprops *lpts; bool try_rebuild; struct ubifs_rebuild_info *rebuild; }; @@ -321,4 +324,8 @@ int handle_invalid_files(struct ubifs_info *c); int handle_dentry_tree(struct ubifs_info *c); bool tnc_is_empty(struct ubifs_info *c); +/* check_space.c */ +int get_free_leb(struct ubifs_info *c); +int build_lpt(struct ubifs_info *c, calculate_lp_callback calculate_lp_cb); + #endif -- cgit v1.2.3