@@ -738,6 +738,23 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia,
738738 return 0 ;
739739 }
740740
741+ crypt_stat = & ecryptfs_inode_to_private (inode )-> crypt_stat ;
742+ lower_size_before_truncate =
743+ upper_size_to_lower_size (crypt_stat , i_size );
744+ lower_size_after_truncate =
745+ upper_size_to_lower_size (crypt_stat , ia -> ia_size );
746+ if (lower_size_after_truncate > lower_size_before_truncate ) {
747+ /*
748+ * The eCryptfs inode and the new *lower* size are mixed here
749+ * because we may not have the lower i_mutex held and/or it may
750+ * not be appropriate to call inode_newsize_ok() with inodes
751+ * from other filesystems.
752+ */
753+ rc = inode_newsize_ok (inode , lower_size_after_truncate );
754+ if (rc )
755+ return rc ;
756+ }
757+
741758 rc = ecryptfs_get_lower_file (dentry , inode );
742759 if (rc )
743760 return rc ;
@@ -756,7 +773,6 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia,
756773 goto out ;
757774 }
758775
759- crypt_stat = & ecryptfs_inode_to_private (d_inode (dentry ))-> crypt_stat ;
760776 if (!(crypt_stat -> flags & ECRYPTFS_ENCRYPTED )) {
761777 truncate_setsize (inode , ia -> ia_size );
762778 lower_ia -> ia_size = ia -> ia_size ;
@@ -791,10 +807,6 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia,
791807 * We are reducing the size of the ecryptfs file, and need to know if we
792808 * need to reduce the size of the lower file.
793809 */
794- lower_size_before_truncate =
795- upper_size_to_lower_size (crypt_stat , i_size );
796- lower_size_after_truncate =
797- upper_size_to_lower_size (crypt_stat , ia -> ia_size );
798810 if (lower_size_after_truncate < lower_size_before_truncate ) {
799811 lower_ia -> ia_size = lower_size_after_truncate ;
800812 lower_ia -> ia_valid |= ATTR_SIZE ;
@@ -806,28 +818,6 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia,
806818 return rc ;
807819}
808820
809- static int ecryptfs_inode_newsize_ok (struct inode * inode , loff_t offset )
810- {
811- struct ecryptfs_crypt_stat * crypt_stat ;
812- loff_t lower_oldsize , lower_newsize ;
813-
814- crypt_stat = & ecryptfs_inode_to_private (inode )-> crypt_stat ;
815- lower_oldsize = upper_size_to_lower_size (crypt_stat ,
816- i_size_read (inode ));
817- lower_newsize = upper_size_to_lower_size (crypt_stat , offset );
818- if (lower_newsize > lower_oldsize ) {
819- /*
820- * The eCryptfs inode and the new *lower* size are mixed here
821- * because we may not have the lower i_mutex held and/or it may
822- * not be appropriate to call inode_newsize_ok() with inodes
823- * from other filesystems.
824- */
825- return inode_newsize_ok (inode , lower_newsize );
826- }
827-
828- return 0 ;
829- }
830-
831821/**
832822 * ecryptfs_truncate
833823 * @dentry: The ecryptfs layer dentry
@@ -844,10 +834,6 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length)
844834 struct iattr lower_ia = { .ia_valid = 0 };
845835 int rc ;
846836
847- rc = ecryptfs_inode_newsize_ok (d_inode (dentry ), new_length );
848- if (rc )
849- return rc ;
850-
851837 rc = truncate_upper (dentry , & ia , & lower_ia );
852838 if (!rc && lower_ia .ia_valid & ATTR_SIZE ) {
853839 struct dentry * lower_dentry = ecryptfs_dentry_to_lower (dentry );
@@ -939,10 +925,6 @@ static int ecryptfs_setattr(struct mnt_idmap *idmap,
939925 if (ia -> ia_valid & ATTR_FILE )
940926 lower_ia .ia_file = ecryptfs_file_to_lower (ia -> ia_file );
941927 if (ia -> ia_valid & ATTR_SIZE ) {
942- rc = ecryptfs_inode_newsize_ok (inode , ia -> ia_size );
943- if (rc )
944- goto out ;
945-
946928 rc = truncate_upper (dentry , ia , & lower_ia );
947929 if (rc < 0 )
948930 goto out ;
0 commit comments