From a251dd9c71006c66a02064210ae103ed7ac59444 Mon Sep 17 00:00:00 2001 From: Zhihao Cheng Date: Mon, 11 Nov 2024 17:08:05 +0800 Subject: fsck.ubifs: Check and handle unreachable files This is the 9/18 step of fsck. Check and handle unreachable files, the checking rule is same as rebuild mode which has been implemented in file_is_reachable, but the methods of handling are different: 1. Move unreachable regular file into disconnected list, let subsequent steps to handle them with lost+found. 2. Delete unreachable non-regular file. 3. Delete unreachable directory entries. Signed-off-by: Zhihao Cheng Signed-off-by: David Oberhollenzer --- ubifs-utils/fsck.ubifs/extract_files.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'ubifs-utils/fsck.ubifs/extract_files.c') diff --git a/ubifs-utils/fsck.ubifs/extract_files.c b/ubifs-utils/fsck.ubifs/extract_files.c index 51b83b8..b24445b 100644 --- a/ubifs-utils/fsck.ubifs/extract_files.c +++ b/ubifs-utils/fsck.ubifs/extract_files.c @@ -1247,6 +1247,15 @@ retry: dent_node = list_entry(path_list.next, struct scanned_dent_node, list); + handle_invalid_file(c, DENTRY_IS_UNREACHABLE, + dent_node->file, dent_node); + if (FSCK(c)->mode != REBUILD_MODE) { + int err = delete_node(c, &dent_node->key, + dent_node->header.lnum, + dent_node->header.offs); + if (err) + return err; + } dbg_fsck("remove unreachable dentry %s, in %s", c->encrypted && !file->ino.is_xattr ? "" : dent_node->name, c->dev_name); @@ -1260,6 +1269,10 @@ retry: } if (!rb_first(&file->dent_nodes)) { + if (S_ISREG(file->ino.mode)) + handle_invalid_file(c, FILE_IS_DISCONNECTED, file, NULL); + else + handle_invalid_file(c, FILE_HAS_NO_DENT, file, NULL); dbg_fsck("file %lu is unreachable, in %s", file->inum, c->dev_name); return false; } -- cgit v1.2.3