]> www.infradead.org Git - mtd-utils.git/commitdiff
fsck.ubifs: Update files' size for check mode
authorZhihao Cheng <chengzhihao1@huawei.com>
Mon, 11 Nov 2024 09:08:03 +0000 (17:08 +0800)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Mon, 11 Nov 2024 09:32:46 +0000 (10:32 +0100)
This is the 7/18 step of fsck. Update files' size according to size
tree for check mode, now all files are updated after replaying journal.

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
ubifs-utils/fsck.ubifs/check_files.c
ubifs-utils/fsck.ubifs/fsck.ubifs.c
ubifs-utils/fsck.ubifs/fsck.ubifs.h
ubifs-utils/libubifs/recovery.c
ubifs-utils/libubifs/ubifs.h

index 29848c4ec217c53a8e306bb9270b99a95ffb8245..0fd6b32a9b2bd002ca8ce8876a99f3c4712773a7 100644 (file)
@@ -309,3 +309,48 @@ out:
        }
        return err;
 }
+
+/**
+ * update_files_size - Update files' size.
+ * @c: UBIFS file-system description object
+ *
+ * This function updates files' size according to @c->size_tree for check mode.
+ */
+void update_files_size(struct ubifs_info *c)
+{
+       struct rb_node *this;
+
+       if (FSCK(c)->mode != CHECK_MODE) {
+               /* Other modes(rw) have updated inode size in place. */
+               dbg_fsck("skip updating files' size%s, in %s",
+                        mode_name(c), c->dev_name);
+               return;
+       }
+
+       log_out(c, "Update files' size");
+
+       this = rb_first(&c->size_tree);
+       while (this) {
+               struct size_entry *e;
+
+               e = rb_entry(this, struct size_entry, rb);
+               this = rb_next(this);
+
+               if (e->exists && e->i_size < e->d_size) {
+                       struct scanned_file *file;
+
+                       file = lookup_file(&FSCK(c)->scanned_files, e->inum);
+                       if (file && file->ino.header.exist &&
+                           file->ino.size < e->d_size) {
+                               dbg_fsck("update file(%lu) size %llu->%llu, in %s",
+                                        e->inum, file->ino.size,
+                                        (unsigned long long)e->d_size,
+                                        c->dev_name);
+                               file->ino.size = e->d_size;
+                       }
+               }
+
+               rb_erase(&e->rb, &c->size_tree);
+               kfree(e);
+       }
+}
index c0b1bf690bcee5a3ca24110e2163e37641080460..ec42fa73eab6a6fb80df5384b3a661f83b32c7c7 100644 (file)
@@ -443,6 +443,8 @@ static int do_fsck(void)
                return err;
        }
 
+       update_files_size(c);
+
        kfree(FSCK(c)->used_lebs);
        destroy_file_tree(c, &FSCK(c)->scanned_files);
        return err;
@@ -481,6 +483,7 @@ int main(int argc, char *argv[])
 
        /*
         * Step 6: Traverse tnc and construct files
+        * Step 7: Update files' size
         */
        err = do_fsck();
        if (err && FSCK(c)->try_rebuild) {
index c917a0e366e324aff9017c342fa04a3951d5370d..4be38b459f23d5e9244b5a9d1d01ffe2773d5fe9 100644 (file)
@@ -297,5 +297,6 @@ int ubifs_rebuild_filesystem(struct ubifs_info *c);
 
 /* check_files.c */
 int traverse_tnc_and_construct_files(struct ubifs_info *c);
+void update_files_size(struct ubifs_info *c);
 
 #endif
index a5133a0f321cd907f685d7373681d642f387275d..905e1645a2f1f99e6e43cf4505f615b5284383a3 100644 (file)
@@ -1081,22 +1081,6 @@ int ubifs_rcvry_gc_commit(struct ubifs_info *c)
        return 0;
 }
 
-/**
- * struct size_entry - inode size information for recovery.
- * @rb: link in the RB-tree of sizes
- * @inum: inode number
- * @i_size: size on inode
- * @d_size: maximum size based on data nodes
- * @exists: indicates whether the inode exists
- */
-struct size_entry {
-       struct rb_node rb;
-       ino_t inum;
-       loff_t i_size;
-       loff_t d_size;
-       int exists;
-};
-
 /**
  * add_ino - add an entry to the size tree.
  * @c: UBIFS file-system description object
index 03150cdb9c758d957eb7d593b6808a9f5295c2e9..72497cd91701c688adc24b3cb082d3a6c88ec35c 100644 (file)
@@ -1297,6 +1297,22 @@ static inline int ubifs_authenticated(const struct ubifs_info *c)
        return c->authenticated;
 }
 
+/**
+ * struct size_entry - inode size information for recovery.
+ * @rb: link in the RB-tree of sizes
+ * @inum: inode number
+ * @i_size: size on inode
+ * @d_size: maximum size based on data nodes
+ * @exists: indicates whether the inode exists
+ */
+struct size_entry {
+       struct rb_node rb;
+       ino_t inum;
+       loff_t i_size;
+       loff_t d_size;
+       int exists;
+};
+
 #ifdef WITH_CRYPTO
 int ubifs_init_authentication(struct ubifs_info *c);
 int ubifs_shash_init(const struct ubifs_info *c, struct shash_desc *desc);