Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

f2fs: introduce F2FS_FEATURE_LOST_FOUND feature

This patch introduces a new feature, F2FS_FEATURE_LOST_FOUND, which
is set by mkfs. mkfs creates a directory named lost+found, which saves
unreachable files. If fsck finds a file which has no parent, or its
parent is removed by fsck, the file will be placed under lost+found
directory by fsck.

lost+found directory could not be encrypted. As a result, the root
directory cannot be encrypted too. So if LOST_FOUND feature is enabled,
let's avoid to encrypt root directory.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

authored by

Sheng Yong and committed by
Jaegeuk Kim
b7c409de da5ce874

+21
+2
fs/f2fs/f2fs.h
··· 144 144 #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 145 145 #define F2FS_FEATURE_QUOTA_INO 0x0080 146 146 #define F2FS_FEATURE_INODE_CRTIME 0x0100 147 + #define F2FS_FEATURE_LOST_FOUND 0x0200 147 148 148 149 #define F2FS_HAS_FEATURE(sb, mask) \ 149 150 ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) ··· 3215 3214 F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR); 3216 3215 F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO); 3217 3216 F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); 3217 + F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); 3218 3218 3219 3219 #ifdef CONFIG_BLK_DEV_ZONED 3220 3220 static inline int get_blkz_type(struct f2fs_sb_info *sbi,
+12
fs/f2fs/super.c
··· 1891 1891 static int f2fs_set_context(struct inode *inode, const void *ctx, size_t len, 1892 1892 void *fs_data) 1893 1893 { 1894 + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 1895 + 1896 + /* 1897 + * Encrypting the root directory is not allowed because fsck 1898 + * expects lost+found directory to exist and remain unencrypted 1899 + * if LOST_FOUND feature is enabled. 1900 + * 1901 + */ 1902 + if (f2fs_sb_has_lost_found(sbi->sb) && 1903 + inode->i_ino == F2FS_ROOT_INO(sbi)) 1904 + return -EPERM; 1905 + 1894 1906 return f2fs_setxattr(inode, F2FS_XATTR_INDEX_ENCRYPTION, 1895 1907 F2FS_XATTR_NAME_ENCRYPTION_CONTEXT, 1896 1908 ctx, len, fs_data, XATTR_CREATE);
+7
fs/f2fs/sysfs.c
··· 116 116 if (f2fs_sb_has_inode_crtime(sb)) 117 117 len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 118 118 len ? ", " : "", "inode_crtime"); 119 + if (f2fs_sb_has_lost_found(sb)) 120 + len += snprintf(buf + len, PAGE_SIZE - len, "%s%s", 121 + len ? ", " : "", "lost_found"); 119 122 len += snprintf(buf + len, PAGE_SIZE - len, "\n"); 120 123 return len; 121 124 } ··· 295 292 FEAT_FLEXIBLE_INLINE_XATTR, 296 293 FEAT_QUOTA_INO, 297 294 FEAT_INODE_CRTIME, 295 + FEAT_LOST_FOUND, 298 296 }; 299 297 300 298 static ssize_t f2fs_feature_show(struct f2fs_attr *a, ··· 311 307 case FEAT_FLEXIBLE_INLINE_XATTR: 312 308 case FEAT_QUOTA_INO: 313 309 case FEAT_INODE_CRTIME: 310 + case FEAT_LOST_FOUND: 314 311 return snprintf(buf, PAGE_SIZE, "supported\n"); 315 312 } 316 313 return 0; ··· 391 386 F2FS_FEATURE_RO_ATTR(flexible_inline_xattr, FEAT_FLEXIBLE_INLINE_XATTR); 392 387 F2FS_FEATURE_RO_ATTR(quota_ino, FEAT_QUOTA_INO); 393 388 F2FS_FEATURE_RO_ATTR(inode_crtime, FEAT_INODE_CRTIME); 389 + F2FS_FEATURE_RO_ATTR(lost_found, FEAT_LOST_FOUND); 394 390 395 391 #define ATTR_LIST(name) (&f2fs_attr_##name.attr) 396 392 static struct attribute *f2fs_attrs[] = { ··· 447 441 ATTR_LIST(flexible_inline_xattr), 448 442 ATTR_LIST(quota_ino), 449 443 ATTR_LIST(inode_crtime), 444 + ATTR_LIST(lost_found), 450 445 NULL, 451 446 }; 452 447