@@ -116,6 +116,7 @@ struct f2fs_mount_info {
116116#define F2FS_FEATURE_ATOMIC_WRITE 0x0004
117117#define F2FS_FEATURE_EXTRA_ATTR 0x0008
118118#define F2FS_FEATURE_PRJQUOTA 0x0010
119+ #define F2FS_FEATURE_INODE_CHKSUM 0x0020
119120
120121#define F2FS_HAS_FEATURE (sb , mask ) \
121122((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -1085,6 +1086,9 @@ struct f2fs_sb_info {
10851086/* Reference to checksum algorithm driver via cryptoapi */
10861087struct crypto_shash * s_chksum_driver ;
10871088
1089+ /* Precomputed FS UUID checksum for seeding other checksums */
1090+ __u32 s_chksum_seed ;
1091+
10881092/* For fault injection */
10891093#ifdef CONFIG_F2FS_FAULT_INJECTION
10901094struct f2fs_fault_info fault_info ;
@@ -1176,6 +1180,27 @@ static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc,
11761180return f2fs_crc32 (sbi , buf , buf_size ) == blk_crc ;
11771181}
11781182
1183+ static inline u32 f2fs_chksum (struct f2fs_sb_info * sbi , u32 crc ,
1184+ const void * address , unsigned int length )
1185+ {
1186+ struct {
1187+ struct shash_desc shash ;
1188+ char ctx [4 ];
1189+ } desc ;
1190+ int err ;
1191+
1192+ BUG_ON (crypto_shash_descsize (sbi -> s_chksum_driver ) != sizeof (desc .ctx ));
1193+
1194+ desc .shash .tfm = sbi -> s_chksum_driver ;
1195+ desc .shash .flags = 0 ;
1196+ * (u32 * )desc .ctx = crc ;
1197+
1198+ err = crypto_shash_update (& desc .shash , address , length );
1199+ BUG_ON (err );
1200+
1201+ return * (u32 * )desc .ctx ;
1202+ }
1203+
11791204static inline struct f2fs_inode_info * F2FS_I (struct inode * inode )
11801205{
11811206return container_of (inode , struct f2fs_inode_info , vfs_inode );
@@ -2285,6 +2310,8 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
22852310 * inode.c
22862311 */
22872312void f2fs_set_inode_flags (struct inode * inode );
2313+ bool f2fs_inode_chksum_verify (struct f2fs_sb_info * sbi , struct page * page );
2314+ void f2fs_inode_chksum_set (struct f2fs_sb_info * sbi , struct page * page );
22882315struct inode * f2fs_iget (struct super_block * sb , unsigned long ino );
22892316struct inode * f2fs_iget_retry (struct super_block * sb , unsigned long ino );
22902317int try_to_free_nats (struct f2fs_sb_info * sbi , int nr_shrink );
@@ -2869,6 +2896,11 @@ static inline int f2fs_sb_has_project_quota(struct super_block *sb)
28692896return F2FS_HAS_FEATURE (sb , F2FS_FEATURE_PRJQUOTA );
28702897}
28712898
2899+ static inline int f2fs_sb_has_inode_chksum (struct super_block * sb )
2900+ {
2901+ return F2FS_HAS_FEATURE (sb , F2FS_FEATURE_INODE_CHKSUM );
2902+ }
2903+
28722904#ifdef CONFIG_BLK_DEV_ZONED
28732905static inline int get_blkz_type (struct f2fs_sb_info * sbi ,
28742906struct block_device * bdev , block_t blkaddr )
0 commit comments