fs/ntfs3: Various bug fixes
Subsystems (2)
Konstantin Komarov
maintainercover fs/ntfs3: Various bug fixes
These commits fix 3 xfstests
Patches are based on version with FALLOC_FL_INSERT_RANGE support
https://lore.kernel.org/ntfs3/[email protected]/T/#t
Konstantin Komarov (3):
fs/ntfs3: Do not change mode if ntfs_set_ea failed fs/ntfs3: Check reserved size for maximum allowed fs/ntfs3: extend ni_insert_nonresident to return inserted
ATTR_LIST_ENTRY
fs/ntfs3/attrib.c | 46 +++++++++++++++++++++++++++++++--------------- fs/ntfs3/file.c | 3 --- fs/ntfs3/frecord.c | 4 ++-- fs/ntfs3/index.c | 2 +- fs/ntfs3/ntfs_fs.h | 2 +- fs/ntfs3/xattr.c | 20 ++++++++++---------- 6 files changed, 45 insertions(+), 32 deletions(-)
Signature · 1 line
2.36.1
Konstantin Komarov
maintainerPATCH 1/3 fs/ntfs3: Do not change mode if ntfs_set_ea failed
ntfs_set_ea can fail with NOSPC, so we don't need to change mode in this situation.
Fixes xfstest generic/449
--- fs/ntfs3/xattr.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
fs/ntfs3/xattr.c +10 -10
@@ -547,28 +547,23 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns, {const char *name;size_t size, name_len; -void *value =NULL ; -int err =0 ; +void *value; +int err;int flags; +umode_t mode;if (S_ISLNK (inode->i_mode))return -EOPNOTSUPP ; + mode = inode->i_mode;switch (type) {case ACL_TYPE_ACCESS :/* Do not change i_mode if we are in init_acl */ if (acl && !init_acl) { -umode_t mode; - err =posix_acl_update_mode (mnt_userns, inode, &mode, &acl);if (err) goto out; - -if (inode->i_mode != mode) { - inode->i_mode = mode; -mark_inode_dirty (inode); - } } name =XATTR_NAME_POSIX_ACL_ACCESS ; name_len =sizeof (XATTR_NAME_POSIX_ACL_ACCESS ) -1 ;
@@ -604,8 +599,13 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns, err =ntfs_set_ea (inode, name, name_len, value, size, flags,0 );if (err == -ENODATA && !size) err =0 ;/* Removing non existed xattr. */ -if (!err) +if (!err) {set_cached_acl (inode, type, acl); +if (inode->i_mode != mode) { + inode->i_mode = mode; +mark_inode_dirty (inode); + } + } out:kfree (value);
Signature · 1 line
2.36.1
Konstantin Komarov
maintainerPATCH 2/3 fs/ntfs3: Check reserved size for maximum allowed
In reply to Konstantin KomarovAlso don't mask EFBIG
Fixes xfstest generic/485
--- fs/ntfs3/attrib.c | 11 ++++++++++- fs/ntfs3/file.c | 3 --- 2 files changed, 10 insertions(+), 4 deletions(-)
fs/ntfs3/attrib.c +9 -0
@@ -2114,9 +2114,11 @@ int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)if (!attr_b->non_res) { data_size =le32_to_cpu (attr_b->res.data_size); + alloc_size = data_size; mask = sbi->cluster_mask;/* cluster_size - 1 */ }else { data_size =le64_to_cpu (attr_b->nres.data_size); + alloc_size =le64_to_cpu (attr_b->nres.alloc_size); mask = (sbi->cluster_size << attr_b->nres.c_unit) -1 ; }
@@ -2130,6 +2132,13 @@ int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)return -EINVAL ; } +/* +* valid_size <= data_size <= alloc_size +* Check alloc_size for maximum possible. +*/ +if (bytes > sbi->maxbytes_sparse - alloc_size) +return -EFBIG ; + vcn = vbo >> sbi->cluster_bits; len = bytes >> sbi->cluster_bits;
fs/ntfs3/file.c +0 -3
@@ -732,9 +732,6 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)if (map_locked)filemap_invalidate_unlock (mapping); -if (err == -EFBIG ) - err = -ENOSPC ; -if (!err) { inode->i_ctime = inode->i_mtime =current_time (inode);mark_inode_dirty (inode);
Signature · 1 line
2.36.1
Konstantin Komarov
maintainerPATCH 3/3 fs/ntfs3: extend ni_insert_nonresident to return inserted ATTR_LIST_ENTRY
In reply to Konstantin KomarovFixes xfstest generic/300
--- fs/ntfs3/attrib.c | 35 +++++++++++++++++++++-------------- fs/ntfs3/frecord.c | 4 ++-- fs/ntfs3/index.c | 2 +- fs/ntfs3/ntfs_fs.h | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-)
fs/ntfs3/attrib.c +21 -14
@@ -320,7 +320,7 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr, err =ni_insert_nonresident (ni, attr_s->type,attr_name (attr_s), attr_s->name_len, run,0 , alen, - attr_s->flags, &attr,NULL ); + attr_s->flags, &attr,NULL ,NULL );if (err) goto out3;
@@ -637,7 +637,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,/* Insert new attribute segment. */ err =ni_insert_nonresident (ni, type, name, name_len, run, next_svcn, vcn - next_svcn, - attr_b->flags, &attr, &mi); + attr_b->flags, &attr, &mi,NULL );if (err) goto out;
@@ -855,7 +855,7 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn, goto out; } - asize =le64_to_cpu (attr_b->nres.alloc_size) >> sbi->cluster_bits; + asize =le64_to_cpu (attr_b->nres.alloc_size) >> cluster_bits;if (vcn >= asize) { err = -EINVAL ; goto out;
@@ -1047,7 +1047,7 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn,if (evcn1 > next_svcn) { err =ni_insert_nonresident (ni,ATTR_DATA ,NULL ,0 , run, next_svcn, evcn1 - next_svcn, - attr_b->flags, &attr, &mi); + attr_b->flags, &attr, &mi,NULL );if (err) goto out; }
@@ -1647,7 +1647,7 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,if (evcn1 > next_svcn) { err =ni_insert_nonresident (ni,ATTR_DATA ,NULL ,0 , run, next_svcn, evcn1 - next_svcn, - attr_b->flags, &attr, &mi); + attr_b->flags, &attr, &mi,NULL );if (err) goto out; }
@@ -1812,18 +1812,12 @@ int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes) err =ni_insert_nonresident ( ni,ATTR_DATA ,NULL ,0 , run, next_svcn, evcn1 - eat - next_svcn, a_flags, &attr, - &mi); + &mi, &le);if (err) goto out;/* Layout of records maybe changed. */ attr_b =NULL ; - le =al_find_ex (ni,NULL ,ATTR_DATA ,NULL ,0 , - &next_svcn); -if (!le) { - err = -EINVAL ; - goto out; - } }/* Free all allocated memory. */
@@ -1936,9 +1930,10 @@ int attr_punch_hole(struct ntfs_inode *ni, u64 vbo, u64 bytes, u32 *frame_size)struct ATTRIB *attr =NULL , *attr_b;struct ATTR_LIST_ENTRY *le, *le_b;struct mft_inode *mi, *mi_b; -CLST svcn, evcn1, vcn, len, end, alen, dealloc; +CLST svcn, evcn1, vcn, len, end, alen, dealloc, next_svcn;u64 total_size, alloc_size;u32 mask; +__le16 a_flags;if (!bytes)return 0 ;
@@ -2001,6 +1996,7 @@ int attr_punch_hole(struct ntfs_inode *ni, u64 vbo, u64 bytes, u32 *frame_size) svcn =le64_to_cpu (attr_b->nres.svcn); evcn1 =le64_to_cpu (attr_b->nres.evcn) +1 ; + a_flags = attr_b->flags;if (svcn <= vcn && vcn < evcn1) { attr = attr_b;
@@ -2048,6 +2044,17 @@ int attr_punch_hole(struct ntfs_inode *ni, u64 vbo, u64 bytes, u32 *frame_size) err =mi_pack_runs (mi, attr, run, evcn1 - svcn);if (err) goto out; + next_svcn =le64_to_cpu (attr->nres.evcn) +1 ; +if (next_svcn < evcn1) { + err =ni_insert_nonresident (ni,ATTR_DATA ,NULL , +0 , run, next_svcn, + evcn1 - next_svcn, + a_flags, &attr, &mi, + &le); +if (err) + goto out; +/* Layout of records maybe changed. */ + } }/* Free all allocated memory. */ run_truncate (run,0 );
@@ -2248,7 +2255,7 @@ int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)if (next_svcn < evcn1 + len) { err =ni_insert_nonresident (ni,ATTR_DATA ,NULL ,0 , run, next_svcn, evcn1 + len - next_svcn, - a_flags,NULL ,NULL ); + a_flags,NULL ,NULL ,NULL );if (err) goto out; }
fs/ntfs3/frecord.c +2 -2
@@ -1406,7 +1406,7 @@ int ni_insert_nonresident(struct ntfs_inode *ni, enum ATTR_TYPE type, const __le16 *name, u8 name_len, const struct runs_tree *run, CLST svcn, CLST len, __le16 flags, struct ATTRIB **new_attr, - struct mft_inode **mi) + struct mft_inode **mi, struct ATTR_LIST_ENTRY **le) { int err;CLST plen;
@@ -1439,7 +1439,7 @@ int ni_insert_nonresident(struct ntfs_inode *ni, enum ATTR_TYPE type, } err =ni_insert_attr (ni, type, name, name_len, asize, name_off, svcn, - &attr, mi,NULL ); + &attr, mi, le);if (err) goto out;
fs/ntfs3/index.c +1 -1
@@ -1347,7 +1347,7 @@ static int indx_create_allocate(struct ntfs_index *indx, struct ntfs_inode *ni, goto out; err =ni_insert_nonresident (ni,ATTR_ALLOC , in->name, in->name_len, - &run,0 , len,0 , &alloc,NULL ); + &run,0 , len,0 , &alloc,NULL ,NULL );if (err) goto out1;
fs/ntfs3/ntfs_fs.h +1 -1
@@ -530,7 +530,7 @@ int ni_insert_nonresident(struct ntfs_inode *ni, enum ATTR_TYPE type, const __le16 *name, u8 name_len, const struct runs_tree *run, CLST svcn, CLST len, __le16 flags, struct ATTRIB **new_attr, - struct mft_inode **mi); + struct mft_inode **mi, struct ATTR_LIST_ENTRY **le); int ni_insert_resident(struct ntfs_inode *ni, u32 data_size, enum ATTR_TYPE type, const __le16 *name, u8 name_len, struct ATTRIB **new_attr, struct mft_inode **mi,
Signature · 1 line
2.36.1