@@ -4231,6 +4231,153 @@ int ext4_truncate(struct inode *inode)
4231
4231
return err ;
4232
4232
}
4233
4233
4234
+ static inline u64 ext4_inode_peek_iversion (const struct inode * inode )
4235
+ {
4236
+ if (unlikely (EXT4_I (inode )-> i_flags & EXT4_EA_INODE_FL ))
4237
+ return inode_peek_iversion_raw (inode );
4238
+ else
4239
+ return inode_peek_iversion (inode );
4240
+ }
4241
+
4242
+ static int ext4_inode_blocks_set (struct ext4_inode * raw_inode ,
4243
+ struct ext4_inode_info * ei )
4244
+ {
4245
+ struct inode * inode = & (ei -> vfs_inode );
4246
+ u64 i_blocks = READ_ONCE (inode -> i_blocks );
4247
+ struct super_block * sb = inode -> i_sb ;
4248
+
4249
+ if (i_blocks <= ~0U ) {
4250
+ /*
4251
+ * i_blocks can be represented in a 32 bit variable
4252
+ * as multiple of 512 bytes
4253
+ */
4254
+ raw_inode -> i_blocks_lo = cpu_to_le32 (i_blocks );
4255
+ raw_inode -> i_blocks_high = 0 ;
4256
+ ext4_clear_inode_flag (inode , EXT4_INODE_HUGE_FILE );
4257
+ return 0 ;
4258
+ }
4259
+
4260
+ /*
4261
+ * This should never happen since sb->s_maxbytes should not have
4262
+ * allowed this, sb->s_maxbytes was set according to the huge_file
4263
+ * feature in ext4_fill_super().
4264
+ */
4265
+ if (!ext4_has_feature_huge_file (sb ))
4266
+ return - EFSCORRUPTED ;
4267
+
4268
+ if (i_blocks <= 0xffffffffffffULL ) {
4269
+ /*
4270
+ * i_blocks can be represented in a 48 bit variable
4271
+ * as multiple of 512 bytes
4272
+ */
4273
+ raw_inode -> i_blocks_lo = cpu_to_le32 (i_blocks );
4274
+ raw_inode -> i_blocks_high = cpu_to_le16 (i_blocks >> 32 );
4275
+ ext4_clear_inode_flag (inode , EXT4_INODE_HUGE_FILE );
4276
+ } else {
4277
+ ext4_set_inode_flag (inode , EXT4_INODE_HUGE_FILE );
4278
+ /* i_block is stored in file system block size */
4279
+ i_blocks = i_blocks >> (inode -> i_blkbits - 9 );
4280
+ raw_inode -> i_blocks_lo = cpu_to_le32 (i_blocks );
4281
+ raw_inode -> i_blocks_high = cpu_to_le16 (i_blocks >> 32 );
4282
+ }
4283
+ return 0 ;
4284
+ }
4285
+
4286
+ static int ext4_fill_raw_inode (struct inode * inode , struct ext4_inode * raw_inode )
4287
+ {
4288
+ struct ext4_inode_info * ei = EXT4_I (inode );
4289
+ uid_t i_uid ;
4290
+ gid_t i_gid ;
4291
+ projid_t i_projid ;
4292
+ int block ;
4293
+ int err ;
4294
+
4295
+ err = ext4_inode_blocks_set (raw_inode , ei );
4296
+
4297
+ raw_inode -> i_mode = cpu_to_le16 (inode -> i_mode );
4298
+ i_uid = i_uid_read (inode );
4299
+ i_gid = i_gid_read (inode );
4300
+ i_projid = from_kprojid (& init_user_ns , ei -> i_projid );
4301
+ if (!(test_opt (inode -> i_sb , NO_UID32 ))) {
4302
+ raw_inode -> i_uid_low = cpu_to_le16 (low_16_bits (i_uid ));
4303
+ raw_inode -> i_gid_low = cpu_to_le16 (low_16_bits (i_gid ));
4304
+ /*
4305
+ * Fix up interoperability with old kernels. Otherwise,
4306
+ * old inodes get re-used with the upper 16 bits of the
4307
+ * uid/gid intact.
4308
+ */
4309
+ if (ei -> i_dtime && list_empty (& ei -> i_orphan )) {
4310
+ raw_inode -> i_uid_high = 0 ;
4311
+ raw_inode -> i_gid_high = 0 ;
4312
+ } else {
4313
+ raw_inode -> i_uid_high =
4314
+ cpu_to_le16 (high_16_bits (i_uid ));
4315
+ raw_inode -> i_gid_high =
4316
+ cpu_to_le16 (high_16_bits (i_gid ));
4317
+ }
4318
+ } else {
4319
+ raw_inode -> i_uid_low = cpu_to_le16 (fs_high2lowuid (i_uid ));
4320
+ raw_inode -> i_gid_low = cpu_to_le16 (fs_high2lowgid (i_gid ));
4321
+ raw_inode -> i_uid_high = 0 ;
4322
+ raw_inode -> i_gid_high = 0 ;
4323
+ }
4324
+ raw_inode -> i_links_count = cpu_to_le16 (inode -> i_nlink );
4325
+
4326
+ EXT4_INODE_SET_XTIME (i_ctime , inode , raw_inode );
4327
+ EXT4_INODE_SET_XTIME (i_mtime , inode , raw_inode );
4328
+ EXT4_INODE_SET_XTIME (i_atime , inode , raw_inode );
4329
+ EXT4_EINODE_SET_XTIME (i_crtime , ei , raw_inode );
4330
+
4331
+ raw_inode -> i_dtime = cpu_to_le32 (ei -> i_dtime );
4332
+ raw_inode -> i_flags = cpu_to_le32 (ei -> i_flags & 0xFFFFFFFF );
4333
+ if (likely (!test_opt2 (inode -> i_sb , HURD_COMPAT )))
4334
+ raw_inode -> i_file_acl_high =
4335
+ cpu_to_le16 (ei -> i_file_acl >> 32 );
4336
+ raw_inode -> i_file_acl_lo = cpu_to_le32 (ei -> i_file_acl );
4337
+ ext4_isize_set (raw_inode , ei -> i_disksize );
4338
+
4339
+ raw_inode -> i_generation = cpu_to_le32 (inode -> i_generation );
4340
+ if (S_ISCHR (inode -> i_mode ) || S_ISBLK (inode -> i_mode )) {
4341
+ if (old_valid_dev (inode -> i_rdev )) {
4342
+ raw_inode -> i_block [0 ] =
4343
+ cpu_to_le32 (old_encode_dev (inode -> i_rdev ));
4344
+ raw_inode -> i_block [1 ] = 0 ;
4345
+ } else {
4346
+ raw_inode -> i_block [0 ] = 0 ;
4347
+ raw_inode -> i_block [1 ] =
4348
+ cpu_to_le32 (new_encode_dev (inode -> i_rdev ));
4349
+ raw_inode -> i_block [2 ] = 0 ;
4350
+ }
4351
+ } else if (!ext4_has_inline_data (inode )) {
4352
+ for (block = 0 ; block < EXT4_N_BLOCKS ; block ++ )
4353
+ raw_inode -> i_block [block ] = ei -> i_data [block ];
4354
+ }
4355
+
4356
+ if (likely (!test_opt2 (inode -> i_sb , HURD_COMPAT ))) {
4357
+ u64 ivers = ext4_inode_peek_iversion (inode );
4358
+
4359
+ raw_inode -> i_disk_version = cpu_to_le32 (ivers );
4360
+ if (ei -> i_extra_isize ) {
4361
+ if (EXT4_FITS_IN_INODE (raw_inode , ei , i_version_hi ))
4362
+ raw_inode -> i_version_hi =
4363
+ cpu_to_le32 (ivers >> 32 );
4364
+ raw_inode -> i_extra_isize =
4365
+ cpu_to_le16 (ei -> i_extra_isize );
4366
+ }
4367
+ }
4368
+
4369
+ if (i_projid != EXT4_DEF_PROJID &&
4370
+ !ext4_has_feature_project (inode -> i_sb ))
4371
+ err = err ?: - EFSCORRUPTED ;
4372
+
4373
+ if (EXT4_INODE_SIZE (inode -> i_sb ) > EXT4_GOOD_OLD_INODE_SIZE &&
4374
+ EXT4_FITS_IN_INODE (raw_inode , ei , i_projid ))
4375
+ raw_inode -> i_projid = cpu_to_le32 (i_projid );
4376
+
4377
+ ext4_inode_csum_set (inode , raw_inode , ei );
4378
+ return err ;
4379
+ }
4380
+
4234
4381
/*
4235
4382
* ext4_get_inode_loc returns with an extra refcount against the inode's
4236
4383
* underlying buffer_head on success. If 'in_mem' is true, we have all
@@ -4525,13 +4672,6 @@ static inline void ext4_inode_set_iversion_queried(struct inode *inode, u64 val)
4525
4672
else
4526
4673
inode_set_iversion_queried (inode , val );
4527
4674
}
4528
- static inline u64 ext4_inode_peek_iversion (const struct inode * inode )
4529
- {
4530
- if (unlikely (EXT4_I (inode )-> i_flags & EXT4_EA_INODE_FL ))
4531
- return inode_peek_iversion_raw (inode );
4532
- else
4533
- return inode_peek_iversion (inode );
4534
- }
4535
4675
4536
4676
struct inode * __ext4_iget (struct super_block * sb , unsigned long ino ,
4537
4677
ext4_iget_flags flags , const char * function ,
@@ -4852,50 +4992,6 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
4852
4992
return ERR_PTR (ret );
4853
4993
}
4854
4994
4855
- static int ext4_inode_blocks_set (struct ext4_inode * raw_inode ,
4856
- struct ext4_inode_info * ei )
4857
- {
4858
- struct inode * inode = & (ei -> vfs_inode );
4859
- u64 i_blocks = READ_ONCE (inode -> i_blocks );
4860
- struct super_block * sb = inode -> i_sb ;
4861
-
4862
- if (i_blocks <= ~0U ) {
4863
- /*
4864
- * i_blocks can be represented in a 32 bit variable
4865
- * as multiple of 512 bytes
4866
- */
4867
- raw_inode -> i_blocks_lo = cpu_to_le32 (i_blocks );
4868
- raw_inode -> i_blocks_high = 0 ;
4869
- ext4_clear_inode_flag (inode , EXT4_INODE_HUGE_FILE );
4870
- return 0 ;
4871
- }
4872
-
4873
- /*
4874
- * This should never happen since sb->s_maxbytes should not have
4875
- * allowed this, sb->s_maxbytes was set according to the huge_file
4876
- * feature in ext4_fill_super().
4877
- */
4878
- if (!ext4_has_feature_huge_file (sb ))
4879
- return - EFSCORRUPTED ;
4880
-
4881
- if (i_blocks <= 0xffffffffffffULL ) {
4882
- /*
4883
- * i_blocks can be represented in a 48 bit variable
4884
- * as multiple of 512 bytes
4885
- */
4886
- raw_inode -> i_blocks_lo = cpu_to_le32 (i_blocks );
4887
- raw_inode -> i_blocks_high = cpu_to_le16 (i_blocks >> 32 );
4888
- ext4_clear_inode_flag (inode , EXT4_INODE_HUGE_FILE );
4889
- } else {
4890
- ext4_set_inode_flag (inode , EXT4_INODE_HUGE_FILE );
4891
- /* i_block is stored in file system block size */
4892
- i_blocks = i_blocks >> (inode -> i_blkbits - 9 );
4893
- raw_inode -> i_blocks_lo = cpu_to_le32 (i_blocks );
4894
- raw_inode -> i_blocks_high = cpu_to_le16 (i_blocks >> 32 );
4895
- }
4896
- return 0 ;
4897
- }
4898
-
4899
4995
static void __ext4_update_other_inode_time (struct super_block * sb ,
4900
4996
unsigned long orig_ino ,
4901
4997
unsigned long ino ,
@@ -4956,101 +5052,6 @@ static void ext4_update_other_inodes_time(struct super_block *sb,
4956
5052
rcu_read_unlock ();
4957
5053
}
4958
5054
4959
- static int ext4_fill_raw_inode (struct inode * inode , struct ext4_inode * raw_inode )
4960
- {
4961
- struct ext4_inode_info * ei = EXT4_I (inode );
4962
- uid_t i_uid ;
4963
- gid_t i_gid ;
4964
- projid_t i_projid ;
4965
- int block ;
4966
- int err ;
4967
-
4968
- err = ext4_inode_blocks_set (raw_inode , ei );
4969
-
4970
- raw_inode -> i_mode = cpu_to_le16 (inode -> i_mode );
4971
- i_uid = i_uid_read (inode );
4972
- i_gid = i_gid_read (inode );
4973
- i_projid = from_kprojid (& init_user_ns , ei -> i_projid );
4974
- if (!(test_opt (inode -> i_sb , NO_UID32 ))) {
4975
- raw_inode -> i_uid_low = cpu_to_le16 (low_16_bits (i_uid ));
4976
- raw_inode -> i_gid_low = cpu_to_le16 (low_16_bits (i_gid ));
4977
- /*
4978
- * Fix up interoperability with old kernels. Otherwise,
4979
- * old inodes get re-used with the upper 16 bits of the
4980
- * uid/gid intact.
4981
- */
4982
- if (ei -> i_dtime && list_empty (& ei -> i_orphan )) {
4983
- raw_inode -> i_uid_high = 0 ;
4984
- raw_inode -> i_gid_high = 0 ;
4985
- } else {
4986
- raw_inode -> i_uid_high =
4987
- cpu_to_le16 (high_16_bits (i_uid ));
4988
- raw_inode -> i_gid_high =
4989
- cpu_to_le16 (high_16_bits (i_gid ));
4990
- }
4991
- } else {
4992
- raw_inode -> i_uid_low = cpu_to_le16 (fs_high2lowuid (i_uid ));
4993
- raw_inode -> i_gid_low = cpu_to_le16 (fs_high2lowgid (i_gid ));
4994
- raw_inode -> i_uid_high = 0 ;
4995
- raw_inode -> i_gid_high = 0 ;
4996
- }
4997
- raw_inode -> i_links_count = cpu_to_le16 (inode -> i_nlink );
4998
-
4999
- EXT4_INODE_SET_XTIME (i_ctime , inode , raw_inode );
5000
- EXT4_INODE_SET_XTIME (i_mtime , inode , raw_inode );
5001
- EXT4_INODE_SET_XTIME (i_atime , inode , raw_inode );
5002
- EXT4_EINODE_SET_XTIME (i_crtime , ei , raw_inode );
5003
-
5004
- raw_inode -> i_dtime = cpu_to_le32 (ei -> i_dtime );
5005
- raw_inode -> i_flags = cpu_to_le32 (ei -> i_flags & 0xFFFFFFFF );
5006
- if (likely (!test_opt2 (inode -> i_sb , HURD_COMPAT )))
5007
- raw_inode -> i_file_acl_high =
5008
- cpu_to_le16 (ei -> i_file_acl >> 32 );
5009
- raw_inode -> i_file_acl_lo = cpu_to_le32 (ei -> i_file_acl );
5010
- ext4_isize_set (raw_inode , ei -> i_disksize );
5011
-
5012
- raw_inode -> i_generation = cpu_to_le32 (inode -> i_generation );
5013
- if (S_ISCHR (inode -> i_mode ) || S_ISBLK (inode -> i_mode )) {
5014
- if (old_valid_dev (inode -> i_rdev )) {
5015
- raw_inode -> i_block [0 ] =
5016
- cpu_to_le32 (old_encode_dev (inode -> i_rdev ));
5017
- raw_inode -> i_block [1 ] = 0 ;
5018
- } else {
5019
- raw_inode -> i_block [0 ] = 0 ;
5020
- raw_inode -> i_block [1 ] =
5021
- cpu_to_le32 (new_encode_dev (inode -> i_rdev ));
5022
- raw_inode -> i_block [2 ] = 0 ;
5023
- }
5024
- } else if (!ext4_has_inline_data (inode )) {
5025
- for (block = 0 ; block < EXT4_N_BLOCKS ; block ++ )
5026
- raw_inode -> i_block [block ] = ei -> i_data [block ];
5027
- }
5028
-
5029
- if (likely (!test_opt2 (inode -> i_sb , HURD_COMPAT ))) {
5030
- u64 ivers = ext4_inode_peek_iversion (inode );
5031
-
5032
- raw_inode -> i_disk_version = cpu_to_le32 (ivers );
5033
- if (ei -> i_extra_isize ) {
5034
- if (EXT4_FITS_IN_INODE (raw_inode , ei , i_version_hi ))
5035
- raw_inode -> i_version_hi =
5036
- cpu_to_le32 (ivers >> 32 );
5037
- raw_inode -> i_extra_isize =
5038
- cpu_to_le16 (ei -> i_extra_isize );
5039
- }
5040
- }
5041
-
5042
- if (i_projid != EXT4_DEF_PROJID &&
5043
- !ext4_has_feature_project (inode -> i_sb ))
5044
- err = err ?: - EFSCORRUPTED ;
5045
-
5046
- if (EXT4_INODE_SIZE (inode -> i_sb ) > EXT4_GOOD_OLD_INODE_SIZE &&
5047
- EXT4_FITS_IN_INODE (raw_inode , ei , i_projid ))
5048
- raw_inode -> i_projid = cpu_to_le32 (i_projid );
5049
-
5050
- ext4_inode_csum_set (inode , raw_inode , ei );
5051
- return err ;
5052
- }
5053
-
5054
5055
/*
5055
5056
* Post the struct inode info into an on-disk inode location in the
5056
5057
* buffer-cache. This gobbles the caller's reference to the
0 commit comments