* discard obsolete dnodes after all inodes are created.
  * add new error message if file type (i_mode) is totally wrong.
  * change "-O lost+found" to "-O lost_found".
  * only set filename and bitmap in the second slot of lost+found dentry.
  * handle inode_crtime when creating lost+found inode.
  * fix endiain issue.
  * fix memory leak in fsck_failed_reconnect_file{_dnode|_idnode|_didnode}.
  * translate i_mode to FILE_TYPE instead of F2FS_FT_REG_FILE when
    reconnecting files.
  * get_node_info() reads nat block again if nat entry is invalid.

Commit 390fe587b1 ("fsck.f2fs: support restore lost files into
./lost_found/") restores unreachable files, which have no parent directory
or their parent directories are removed by fsck, to ./lost_found directory.

However, it has several limitations:
  1. ./lost_found dir does not locate inside f2fs, thus it may needs
     another partition to save ./lost_found.
  2. encrypted files are not supported to be restored.
  3. some xattrs may be lost, it depends on whether dump_node() enables
     dumping such xattrs.
  4. not support restoring files on Android devices (the same reason as

In order to address the above limitations, the LOST_FOUND feature is
introduced. This is an ext4-style lost+found. It tries to restore
unreachable files into /lost+found directory inside f2fs.

If LOST_FOUND feature is switched on when mkfs, /lost+found directory is
created by mkfs. It can also be created by mkdir manually. It should be
located right under root directory.

If fsck detects unreachable nids, it scans all these nids, and skips non-
inode or directory inode nodes. For the left nids, they are all file inodes.
Fsck then checks these inodes and update corresponding counters and bitmaps.

From now on, the filesystem is in a "consistent" state, fsck can allocate
blocks safely and start reconnecting files to lost+found. The reconnection
adds new dentry in lost+found and update metadata (i_name, i_pino) of file
inode. If reconnection fails, fsck will clear the counters and bitmaps.
Files reconnected to lost+found will be renamed after its ino number.

However, because of lost+found directory, f2fs should avoid to encrypting
root directory. So f2fs should also check if LOST_FOUND feature is enabled
or not.

I create testcases which inject faults to generate unreachable nids. To
enable LOST_FOUND, we should give "-O lost_found" to mkfs.

        # mkfs.f2fs -O lost_found -O encrypt test.img
        # tree /data/
        ├── dir
        │   ├── foo
        │   └── subdir
        │       └── bar
        ├── encrypt-dir
        │   ├── encrypt-foo
        │   └── encrypt-subdir
        │       └── encrypt-bar
        └── lost+found

        5 directories, 4 files

1) corrupt nat_entry->blk_addr of dir [PASS]
2) corrupt nat_entry->blk_addr of encrypt-dir [PASS]
3) remove lost+found, then corrupt nat_entry->blk_addr of dir [PASS]

Any comments and tests are appreciated.


Sheng Yong (7):
  fsck.f2fs: fix typo
  mkfs.f2fs: introduce mkfs parameters in f2fs_configuration
  f2fs-tools: init f2fs_configuration as 0
  fsck.f2fs: integrate sanity_check_inode to __check_inode_mode
  mkfs.f2fs: create lost+found directory
  fsck.f2fs: read nat block if nat entry is invalid
  fsck.f2fs: reconnect unreachable files to lost+found

 fsck/dir.c              |  19 ++-
 fsck/fsck.c             | 421 +++++++++++++++++++++++++++++++++++++++++++++---
 fsck/fsck.h             |   3 +
 fsck/main.c             |   2 +-
 fsck/mount.c            |   9 +-
 include/f2fs_fs.h       |  11 ++
 lib/libf2fs.c           |  18 +--
 mkfs/f2fs_format.c      | 291 +++++++++++++++++++++++++++------
 mkfs/f2fs_format_main.c |   2 +
 9 files changed, 686 insertions(+), 90 deletions(-)


Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Linux-f2fs-devel mailing list

Reply via email to