Skip to content

Commit 1e098de

Browse files
committed
Pull ntfs3 updates from Konstantin Komarov: "New code: - add missed "nocase" in ntfs_show_options - extend information on failures/errors - small optimizations Fixes: - some logic errors - some dead code was removed - code is refactored and reformatted according to the new version of clang-format Code removal: - 'noacsrules' option. Currently, this option does not work properly, and its use leads to unstable results. If we figure out how to implement it without errors, we will add it later - writepage" * tag 'ntfs3_for_6.4' of https://github.com/Paragon-Software-Group/linux-ntfs3: (30 commits) fs/ntfs3: Fix root inode checking fs/ntfs3: Print details about mount fails fs/ntfs3: Add missed "nocase" in ntfs_show_options fs/ntfs3: Code formatting and refactoring fs/ntfs3: Changed ntfs_get_acl() to use dentry fs/ntfs3: Remove field sbi->used.bitmap.set_tail fs/ntfs3: Undo critial modificatins to keep directory consistency fs/ntfs3: Undo endian changes fs/ntfs3: Optimization in ntfs_set_state() fs/ntfs3: Fix ntfs_create_inode() fs/ntfs3: Remove noacsrules fs/ntfs3: Use bh_read to simplify code fs/ntfs3: Fix a possible null-pointer dereference in ni_clear() fs/ntfs3: Refactoring of various minor issues fs/ntfs3: Restore overflow checking for attr size in mi_enum_attr fs/ntfs3: Check for extremely large size of $AttrDef fs/ntfs3: Improved checking of attribute's name length fs/ntfs3: Add null pointer checks fs/ntfs3: fix spelling mistake "attibute" -> "attribute" fs/ntfs3: Add length check in indx_get_root ...
2 parents 56c455b + 788ee16 commit 1e098de

17 files changed

Lines changed: 528 additions & 457 deletions

File tree

Documentation/filesystems/ntfs3.rst

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,6 @@ this table marked with no it means default is without **no**.
6161
directories, fmask applies only to files and dmask only to directories.
6262
* - fmask=
6363

64-
* - noacsrules
65-
- "No access rules" mount option sets access rights for files/folders to
66-
777 and owner/group to root. This mount option absorbs all other
67-
permissions.
68-
69-
- Permissions change for files/folders will be reported as successful,
70-
but they will remain 777.
71-
72-
- Owner/group change will be reported as successful, butthey will stay
73-
as root.
74-
7564
* - nohidden
7665
- Files with the Windows-specific HIDDEN (FILE_ATTRIBUTE_HIDDEN) attribute
7766
will not be shown under Linux.

fs/ntfs3/attrib.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,8 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
405405
int err = 0;
406406
struct ntfs_sb_info *sbi = ni->mi.sbi;
407407
u8 cluster_bits = sbi->cluster_bits;
408-
bool is_mft =
409-
ni->mi.rno == MFT_REC_MFT && type == ATTR_DATA && !name_len;
408+
bool is_mft = ni->mi.rno == MFT_REC_MFT && type == ATTR_DATA &&
409+
!name_len;
410410
u64 old_valid, old_size, old_alloc, new_alloc, new_alloc_tmp;
411411
struct ATTRIB *attr = NULL, *attr_b;
412412
struct ATTR_LIST_ENTRY *le, *le_b;
@@ -531,11 +531,10 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
531531
pre_alloc = 0;
532532
if (type == ATTR_DATA && !name_len &&
533533
sbi->options->prealloc) {
534-
pre_alloc =
535-
bytes_to_cluster(
536-
sbi,
537-
get_pre_allocated(new_size)) -
538-
new_alen;
534+
pre_alloc = bytes_to_cluster(
535+
sbi, get_pre_allocated(
536+
new_size)) -
537+
new_alen;
539538
}
540539

541540
/* Get the last LCN to allocate from. */
@@ -573,8 +572,8 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
573572
err = attr_allocate_clusters(
574573
sbi, run, vcn, lcn, to_allocate, &pre_alloc,
575574
is_mft ? ALLOCATE_MFT : ALLOCATE_DEF, &alen,
576-
is_mft ? 0
577-
: (sbi->record_size -
575+
is_mft ? 0 :
576+
(sbi->record_size -
578577
le32_to_cpu(rec->used) + 8) /
579578
3 +
580579
1,

fs/ntfs3/bitmap.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ static struct kmem_cache *ntfs_enode_cachep;
4040

4141
int __init ntfs3_init_bitmap(void)
4242
{
43-
ntfs_enode_cachep =
44-
kmem_cache_create("ntfs3_enode_cache", sizeof(struct e_node), 0,
45-
SLAB_RECLAIM_ACCOUNT, NULL);
43+
ntfs_enode_cachep = kmem_cache_create("ntfs3_enode_cache",
44+
sizeof(struct e_node), 0,
45+
SLAB_RECLAIM_ACCOUNT, NULL);
4646
return ntfs_enode_cachep ? 0 : -ENOMEM;
4747
}
4848

@@ -286,9 +286,9 @@ static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,
286286
if (wnd->uptodated != 1) {
287287
/* Check bits before 'bit'. */
288288
ib = wnd->zone_bit == wnd->zone_end ||
289-
bit < wnd->zone_end
290-
? 0
291-
: wnd->zone_end;
289+
bit < wnd->zone_end ?
290+
0 :
291+
wnd->zone_end;
292292

293293
while (bit > ib && wnd_is_free_hlp(wnd, bit - 1, 1)) {
294294
bit -= 1;
@@ -297,9 +297,9 @@ static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,
297297

298298
/* Check bits after 'end_in'. */
299299
ib = wnd->zone_bit == wnd->zone_end ||
300-
end_in > wnd->zone_bit
301-
? wnd->nbits
302-
: wnd->zone_bit;
300+
end_in > wnd->zone_bit ?
301+
wnd->nbits :
302+
wnd->zone_bit;
303303

304304
while (end_in < ib && wnd_is_free_hlp(wnd, end_in, 1)) {
305305
end_in += 1;
@@ -417,8 +417,8 @@ static void wnd_remove_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len)
417417
return;
418418
n3 = rb_first(&wnd->count_tree);
419419
wnd->extent_max =
420-
n3 ? rb_entry(n3, struct e_node, count.node)->count.key
421-
: 0;
420+
n3 ? rb_entry(n3, struct e_node, count.node)->count.key :
421+
0;
422422
return;
423423
}
424424

@@ -658,7 +658,8 @@ int wnd_init(struct wnd_bitmap *wnd, struct super_block *sb, size_t nbits)
658658
if (!wnd->bits_last)
659659
wnd->bits_last = wbits;
660660

661-
wnd->free_bits = kcalloc(wnd->nwnd, sizeof(u16), GFP_NOFS | __GFP_NOWARN);
661+
wnd->free_bits =
662+
kcalloc(wnd->nwnd, sizeof(u16), GFP_NOFS | __GFP_NOWARN);
662663
if (!wnd->free_bits)
663664
return -ENOMEM;
664665

fs/ntfs3/file.c

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,21 @@ static int ntfs_ioctl_fitrim(struct ntfs_sb_info *sbi, unsigned long arg)
2222
{
2323
struct fstrim_range __user *user_range;
2424
struct fstrim_range range;
25+
struct block_device *dev;
2526
int err;
2627

2728
if (!capable(CAP_SYS_ADMIN))
2829
return -EPERM;
2930

30-
if (!bdev_max_discard_sectors(sbi->sb->s_bdev))
31+
dev = sbi->sb->s_bdev;
32+
if (!bdev_max_discard_sectors(dev))
3133
return -EOPNOTSUPP;
3234

3335
user_range = (struct fstrim_range __user *)arg;
3436
if (copy_from_user(&range, user_range, sizeof(range)))
3537
return -EFAULT;
3638

37-
range.minlen = max_t(u32, range.minlen,
38-
bdev_discard_granularity(sbi->sb->s_bdev));
39+
range.minlen = max_t(u32, range.minlen, bdev_discard_granularity(dev));
3940

4041
err = ntfs_trim_fs(sbi, &range);
4142
if (err < 0)
@@ -190,8 +191,8 @@ static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to)
190191

191192
for (; idx < idx_end; idx += 1, from = 0) {
192193
page_off = (loff_t)idx << PAGE_SHIFT;
193-
to = (page_off + PAGE_SIZE) > vbo_to ? (vbo_to - page_off)
194-
: PAGE_SIZE;
194+
to = (page_off + PAGE_SIZE) > vbo_to ? (vbo_to - page_off) :
195+
PAGE_SIZE;
195196
iblock = page_off >> inode->i_blkbits;
196197

197198
page = find_or_create_page(mapping, idx,
@@ -223,16 +224,10 @@ static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to)
223224
set_buffer_uptodate(bh);
224225

225226
if (!buffer_uptodate(bh)) {
226-
lock_buffer(bh);
227-
bh->b_end_io = end_buffer_read_sync;
228-
get_bh(bh);
229-
submit_bh(REQ_OP_READ, bh);
230-
231-
wait_on_buffer(bh);
232-
if (!buffer_uptodate(bh)) {
227+
err = bh_read(bh, 0);
228+
if (err < 0) {
233229
unlock_page(page);
234230
put_page(page);
235-
err = -EIO;
236231
goto out;
237232
}
238233
}
@@ -570,13 +565,14 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
570565
ni_unlock(ni);
571566
} else {
572567
/* Check new size. */
568+
u8 cluster_bits = sbi->cluster_bits;
573569

574570
/* generic/213: expected -ENOSPC instead of -EFBIG. */
575571
if (!is_supported_holes) {
576572
loff_t to_alloc = new_size - inode_get_bytes(inode);
577573

578574
if (to_alloc > 0 &&
579-
(to_alloc >> sbi->cluster_bits) >
575+
(to_alloc >> cluster_bits) >
580576
wnd_zeroes(&sbi->used.bitmap)) {
581577
err = -ENOSPC;
582578
goto out;
@@ -597,7 +593,7 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
597593
}
598594

599595
if (is_supported_holes) {
600-
CLST vcn = vbo >> sbi->cluster_bits;
596+
CLST vcn = vbo >> cluster_bits;
601597
CLST cend = bytes_to_cluster(sbi, end);
602598
CLST cend_v = bytes_to_cluster(sbi, ni->i_valid);
603599
CLST lcn, clen;
@@ -660,22 +656,12 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
660656
int ntfs3_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
661657
struct iattr *attr)
662658
{
663-
struct super_block *sb = dentry->d_sb;
664-
struct ntfs_sb_info *sbi = sb->s_fs_info;
665659
struct inode *inode = d_inode(dentry);
666660
struct ntfs_inode *ni = ntfs_i(inode);
667661
u32 ia_valid = attr->ia_valid;
668662
umode_t mode = inode->i_mode;
669663
int err;
670664

671-
if (sbi->options->noacsrules) {
672-
/* "No access rules" - Force any changes of time etc. */
673-
attr->ia_valid |= ATTR_FORCE;
674-
/* and disable for editing some attributes. */
675-
attr->ia_valid &= ~(ATTR_UID | ATTR_GID | ATTR_MODE);
676-
ia_valid = attr->ia_valid;
677-
}
678-
679665
err = setattr_prepare(idmap, dentry, attr);
680666
if (err)
681667
goto out;
@@ -719,7 +705,7 @@ int ntfs3_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
719705
}
720706

721707
if (ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE))
722-
ntfs_save_wsl_perm(inode);
708+
ntfs_save_wsl_perm(inode, NULL);
723709
mark_inode_dirty(inode);
724710
out:
725711
return err;
@@ -1065,8 +1051,8 @@ static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
10651051
if (ret)
10661052
goto out;
10671053

1068-
ret = is_compressed(ni) ? ntfs_compress_write(iocb, from)
1069-
: __generic_file_write_iter(iocb, from);
1054+
ret = is_compressed(ni) ? ntfs_compress_write(iocb, from) :
1055+
__generic_file_write_iter(iocb, from);
10701056

10711057
out:
10721058
inode_unlock(inode);
@@ -1118,8 +1104,9 @@ static int ntfs_file_release(struct inode *inode, struct file *file)
11181104
int err = 0;
11191105

11201106
/* If we are last writer on the inode, drop the block reservation. */
1121-
if (sbi->options->prealloc && ((file->f_mode & FMODE_WRITE) &&
1122-
atomic_read(&inode->i_writecount) == 1)) {
1107+
if (sbi->options->prealloc &&
1108+
((file->f_mode & FMODE_WRITE) &&
1109+
atomic_read(&inode->i_writecount) == 1)) {
11231110
ni_lock(ni);
11241111
down_write(&ni->file.run_lock);
11251112

@@ -1159,8 +1146,7 @@ const struct inode_operations ntfs_file_inode_operations = {
11591146
.getattr = ntfs_getattr,
11601147
.setattr = ntfs3_setattr,
11611148
.listxattr = ntfs_listxattr,
1162-
.permission = ntfs_permission,
1163-
.get_inode_acl = ntfs_get_acl,
1149+
.get_acl = ntfs_get_acl,
11641150
.set_acl = ntfs_set_acl,
11651151
.fiemap = ntfs_fiemap,
11661152
};

fs/ntfs3/frecord.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ struct ATTR_STD_INFO *ni_std(struct ntfs_inode *ni)
7676
const struct ATTRIB *attr;
7777

7878
attr = mi_find_attr(&ni->mi, NULL, ATTR_STD, NULL, 0, NULL);
79-
return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO))
80-
: NULL;
79+
return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO)) :
80+
NULL;
8181
}
8282

8383
/*
@@ -91,8 +91,8 @@ struct ATTR_STD_INFO5 *ni_std5(struct ntfs_inode *ni)
9191

9292
attr = mi_find_attr(&ni->mi, NULL, ATTR_STD, NULL, 0, NULL);
9393

94-
return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO5))
95-
: NULL;
94+
return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO5)) :
95+
NULL;
9696
}
9797

9898
/*
@@ -102,7 +102,7 @@ void ni_clear(struct ntfs_inode *ni)
102102
{
103103
struct rb_node *node;
104104

105-
if (!ni->vfs_inode.i_nlink && is_rec_inuse(ni->mi.mrec))
105+
if (!ni->vfs_inode.i_nlink && ni->mi.mrec && is_rec_inuse(ni->mi.mrec))
106106
ni_delete_all(ni);
107107

108108
al_destroy(ni);
@@ -1439,8 +1439,8 @@ int ni_insert_nonresident(struct ntfs_inode *ni, enum ATTR_TYPE type,
14391439
int err;
14401440
CLST plen;
14411441
struct ATTRIB *attr;
1442-
bool is_ext =
1443-
(flags & (ATTR_FLAG_SPARSED | ATTR_FLAG_COMPRESSED)) && !svcn;
1442+
bool is_ext = (flags & (ATTR_FLAG_SPARSED | ATTR_FLAG_COMPRESSED)) &&
1443+
!svcn;
14441444
u32 name_size = ALIGN(name_len * sizeof(short), 8);
14451445
u32 name_off = is_ext ? SIZEOF_NONRESIDENT_EX : SIZEOF_NONRESIDENT;
14461446
u32 run_off = name_off + name_size;
@@ -1645,7 +1645,7 @@ struct ATTR_FILE_NAME *ni_fname_name(struct ntfs_inode *ni,
16451645
{
16461646
struct ATTRIB *attr = NULL;
16471647
struct ATTR_FILE_NAME *fname;
1648-
struct le_str *fns;
1648+
struct le_str *fns;
16491649

16501650
if (le)
16511651
*le = NULL;
@@ -1756,9 +1756,9 @@ int ni_new_attr_flags(struct ntfs_inode *ni, enum FILE_ATTRIBUTE new_fa)
17561756
}
17571757

17581758
/* Resize nonresident empty attribute in-place only. */
1759-
new_asize = (new_aflags & (ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED))
1760-
? (SIZEOF_NONRESIDENT_EX + 8)
1761-
: (SIZEOF_NONRESIDENT + 8);
1759+
new_asize = (new_aflags & (ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED)) ?
1760+
(SIZEOF_NONRESIDENT_EX + 8) :
1761+
(SIZEOF_NONRESIDENT + 8);
17621762

17631763
if (!mi_resize_attr(mi, attr, new_asize - le32_to_cpu(attr->size)))
17641764
return -EOPNOTSUPP;
@@ -2965,14 +2965,14 @@ bool ni_remove_name_undo(struct ntfs_inode *dir_ni, struct ntfs_inode *ni,
29652965
{
29662966
struct ntfs_sb_info *sbi = ni->mi.sbi;
29672967
struct ATTRIB *attr;
2968-
u16 de_key_size = de2 ? le16_to_cpu(de2->key_size) : 0;
2968+
u16 de_key_size;
29692969

29702970
switch (undo_step) {
29712971
case 4:
2972+
de_key_size = le16_to_cpu(de2->key_size);
29722973
if (ni_insert_resident(ni, de_key_size, ATTR_NAME, NULL, 0,
2973-
&attr, NULL, NULL)) {
2974+
&attr, NULL, NULL))
29742975
return false;
2975-
}
29762976
memcpy(Add2Ptr(attr, SIZEOF_RESIDENT), de2 + 1, de_key_size);
29772977

29782978
mi_get_ref(&ni->mi, &de2->ref);
@@ -2981,19 +2981,16 @@ bool ni_remove_name_undo(struct ntfs_inode *dir_ni, struct ntfs_inode *ni,
29812981
de2->flags = 0;
29822982
de2->res = 0;
29832983

2984-
if (indx_insert_entry(&dir_ni->dir, dir_ni, de2, sbi, NULL,
2985-
1)) {
2984+
if (indx_insert_entry(&dir_ni->dir, dir_ni, de2, sbi, NULL, 1))
29862985
return false;
2987-
}
29882986
fallthrough;
29892987

29902988
case 2:
29912989
de_key_size = le16_to_cpu(de->key_size);
29922990

29932991
if (ni_insert_resident(ni, de_key_size, ATTR_NAME, NULL, 0,
2994-
&attr, NULL, NULL)) {
2992+
&attr, NULL, NULL))
29952993
return false;
2996-
}
29972994

29982995
memcpy(Add2Ptr(attr, SIZEOF_RESIDENT), de + 1, de_key_size);
29992996
mi_get_ref(&ni->mi, &de->ref);
@@ -3162,9 +3159,9 @@ static bool ni_update_parent(struct ntfs_inode *ni, struct NTFS_DUP_INFO *dup,
31623159
u64 data_size = le64_to_cpu(attr->nres.data_size);
31633160
__le64 valid_le;
31643161

3165-
dup->alloc_size = is_attr_ext(attr)
3166-
? attr->nres.total_size
3167-
: attr->nres.alloc_size;
3162+
dup->alloc_size = is_attr_ext(attr) ?
3163+
attr->nres.total_size :
3164+
attr->nres.alloc_size;
31683165
dup->data_size = attr->nres.data_size;
31693166

31703167
if (new_valid > data_size)
@@ -3258,6 +3255,9 @@ int ni_write_inode(struct inode *inode, int sync, const char *hint)
32583255
return 0;
32593256
}
32603257

3258+
if (!ni->mi.mrec)
3259+
goto out;
3260+
32613261
if (is_rec_inuse(ni->mi.mrec) &&
32623262
!(sbi->flags & NTFS_FLAGS_LOG_REPLAYING) && inode->i_nlink) {
32633263
bool modified = false;
@@ -3360,7 +3360,7 @@ int ni_write_inode(struct inode *inode, int sync, const char *hint)
33603360
ni_unlock(ni);
33613361

33623362
if (err) {
3363-
ntfs_err(sb, "%s r=%lx failed, %d.", hint, inode->i_ino, err);
3363+
ntfs_inode_err(inode, "%s failed, %d.", hint, err);
33643364
ntfs_set_state(sbi, NTFS_DIRTY_ERROR);
33653365
return err;
33663366
}

0 commit comments

Comments
 (0)