From 022cd74567186eb44478dc371d46427ecfb4380b Mon Sep 17 00:00:00 2001 From: Zhihao Cheng Date: Mon, 11 Nov 2024 17:01:08 +0800 Subject: fsck.ubifs: Add rebuilding filesystem support Add rebuilding filesystem support. This is the 1/12 step of rebuilding. Collect files, valid inode nodes, deleted inode nodes, valid dentry nodes and deleted dentry nodes in kinds of trees by scanning nodes from flash. Corrupted nodes(eg. incorrect crc, bad inode size, bad dentry name length, etc.) are dropped during scanning. Larger sqnum node is picked when more than 1 nodes with same index. In this step, trun node and data nodes are put into corresponding file, inode/dentry nodes are put into four trees: valid_inos(nlink != 0), del_inos(nlink is 0), valid_dents(inum != 0), del_dents(inum is 0). Next step will process above four trees to deal deletion situations. Signed-off-by: Zhihao Cheng Signed-off-by: David Oberhollenzer --- ubifs-utils/fsck.ubifs/fsck.ubifs.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (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 aad18d4..df3325e 100644 --- a/ubifs-utils/fsck.ubifs/fsck.ubifs.h +++ b/ubifs-utils/fsck.ubifs/fsck.ubifs.h @@ -174,17 +174,29 @@ struct scanned_file { struct rb_root xattr_files; }; +/** + * ubifs_rebuild_info - UBIFS rebuilding information. + * @scanned_files: tree of all scanned files + */ +struct ubifs_rebuild_info { + struct rb_root scanned_files; +}; + /** * struct ubifs_fsck_info - UBIFS fsck information. * @mode: working mode * @failure_reason: reasons for failed operations * @lpt_status: the status of lpt, could be: %0(OK), %FR_LPT_CORRUPTED or * %FR_LPT_INCORRECT + * @try_rebuild: %true means that try to rebuild fs when fsck failed + * @rebuild: rebuilding-related information */ struct ubifs_fsck_info { int mode; unsigned int failure_reason; unsigned int lpt_status; + bool try_rebuild; + struct ubifs_rebuild_info *rebuild; }; #define FSCK(c) ((struct ubifs_fsck_info*)c->private) @@ -251,4 +263,7 @@ int insert_or_update_file(struct ubifs_info *c, struct rb_root *file_tree, void destroy_file_content(struct ubifs_info *c, struct scanned_file *file); void destroy_file_tree(struct ubifs_info *c, struct rb_root *file_tree); +/* rebuild_fs.c */ +int ubifs_rebuild_filesystem(struct ubifs_info *c); + #endif -- cgit v1.2.3