Skip to content

Commit e9d7126

Browse files
committed
Pull ntfs updates from Konstantin Komarov: "Added: - missing direct_IO in ntfs_aops_cmpr - handling of hdr_first_de() return value Fixed: - handling of InitializeFileRecordSegment operation. Removed: - ability to change compression on mounted volume - redundant NULL check" * tag 'ntfs3_for_6.16' of https://github.com/Paragon-Software-Group/linux-ntfs3: fs/ntfs3: remove ability to change compression on mounted volume fs/ntfs3: Fix handling of InitializeFileRecordSegment fs/ntfs3: Add missing direct_IO in ntfs_aops_cmpr fs/ntfs3: handle hdr_first_de() return value fs/ntfs3: Drop redundant NULL check
2 parents b04f9f8 + eeb0819 commit e9d7126

File tree

8 files changed

+28
-257
lines changed

8 files changed

+28
-257
lines changed

fs/ntfs3/attrib.c

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,75 +2605,3 @@ int attr_force_nonresident(struct ntfs_inode *ni)
26052605

26062606
return err;
26072607
}
2608-
2609-
/*
2610-
* Change the compression of data attribute
2611-
*/
2612-
int attr_set_compress(struct ntfs_inode *ni, bool compr)
2613-
{
2614-
struct ATTRIB *attr;
2615-
struct mft_inode *mi;
2616-
2617-
attr = ni_find_attr(ni, NULL, NULL, ATTR_DATA, NULL, 0, NULL, &mi);
2618-
if (!attr)
2619-
return -ENOENT;
2620-
2621-
if (is_attr_compressed(attr) == !!compr) {
2622-
/* Already required compressed state. */
2623-
return 0;
2624-
}
2625-
2626-
if (attr->non_res) {
2627-
u16 run_off;
2628-
u32 run_size;
2629-
char *run;
2630-
2631-
if (attr->nres.data_size) {
2632-
/*
2633-
* There are rare cases when it possible to change
2634-
* compress state without big changes.
2635-
* TODO: Process these cases.
2636-
*/
2637-
return -EOPNOTSUPP;
2638-
}
2639-
2640-
run_off = le16_to_cpu(attr->nres.run_off);
2641-
run_size = le32_to_cpu(attr->size) - run_off;
2642-
run = Add2Ptr(attr, run_off);
2643-
2644-
if (!compr) {
2645-
/* remove field 'attr->nres.total_size'. */
2646-
memmove(run - 8, run, run_size);
2647-
run_off -= 8;
2648-
}
2649-
2650-
if (!mi_resize_attr(mi, attr, compr ? +8 : -8)) {
2651-
/*
2652-
* Ignore rare case when there are no 8 bytes in record with attr.
2653-
* TODO: split attribute.
2654-
*/
2655-
return -EOPNOTSUPP;
2656-
}
2657-
2658-
if (compr) {
2659-
/* Make a gap for 'attr->nres.total_size'. */
2660-
memmove(run + 8, run, run_size);
2661-
run_off += 8;
2662-
attr->nres.total_size = attr->nres.alloc_size;
2663-
}
2664-
attr->nres.run_off = cpu_to_le16(run_off);
2665-
}
2666-
2667-
/* Update attribute flags. */
2668-
if (compr) {
2669-
attr->flags &= ~ATTR_FLAG_SPARSED;
2670-
attr->flags |= ATTR_FLAG_COMPRESSED;
2671-
attr->nres.c_unit = NTFS_LZNT_CUNIT;
2672-
} else {
2673-
attr->flags &= ~ATTR_FLAG_COMPRESSED;
2674-
attr->nres.c_unit = 0;
2675-
}
2676-
mi->dirty = true;
2677-
2678-
return 0;
2679-
}

fs/ntfs3/file.c

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -49,90 +49,6 @@ static int ntfs_ioctl_fitrim(struct ntfs_sb_info *sbi, unsigned long arg)
4949
return 0;
5050
}
5151

52-
/*
53-
* ntfs_fileattr_get - inode_operations::fileattr_get
54-
*/
55-
int ntfs_fileattr_get(struct dentry *dentry, struct fileattr *fa)
56-
{
57-
struct inode *inode = d_inode(dentry);
58-
struct ntfs_inode *ni = ntfs_i(inode);
59-
u32 flags = 0;
60-
61-
if (inode->i_flags & S_IMMUTABLE)
62-
flags |= FS_IMMUTABLE_FL;
63-
64-
if (inode->i_flags & S_APPEND)
65-
flags |= FS_APPEND_FL;
66-
67-
if (is_compressed(ni))
68-
flags |= FS_COMPR_FL;
69-
70-
if (is_encrypted(ni))
71-
flags |= FS_ENCRYPT_FL;
72-
73-
fileattr_fill_flags(fa, flags);
74-
75-
return 0;
76-
}
77-
78-
/*
79-
* ntfs_fileattr_set - inode_operations::fileattr_set
80-
*/
81-
int ntfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
82-
struct fileattr *fa)
83-
{
84-
struct inode *inode = d_inode(dentry);
85-
struct ntfs_inode *ni = ntfs_i(inode);
86-
u32 flags = fa->flags;
87-
unsigned int new_fl = 0;
88-
89-
if (fileattr_has_fsx(fa))
90-
return -EOPNOTSUPP;
91-
92-
if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_COMPR_FL))
93-
return -EOPNOTSUPP;
94-
95-
if (flags & FS_IMMUTABLE_FL)
96-
new_fl |= S_IMMUTABLE;
97-
98-
if (flags & FS_APPEND_FL)
99-
new_fl |= S_APPEND;
100-
101-
/* Allowed to change compression for empty files and for directories only. */
102-
if (!is_dedup(ni) && !is_encrypted(ni) &&
103-
(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) {
104-
int err = 0;
105-
struct address_space *mapping = inode->i_mapping;
106-
107-
/* write out all data and wait. */
108-
filemap_invalidate_lock(mapping);
109-
err = filemap_write_and_wait(mapping);
110-
111-
if (err >= 0) {
112-
/* Change compress state. */
113-
bool compr = flags & FS_COMPR_FL;
114-
err = ni_set_compress(inode, compr);
115-
116-
/* For files change a_ops too. */
117-
if (!err)
118-
mapping->a_ops = compr ? &ntfs_aops_cmpr :
119-
&ntfs_aops;
120-
}
121-
122-
filemap_invalidate_unlock(mapping);
123-
124-
if (err)
125-
return err;
126-
}
127-
128-
inode_set_flags(inode, new_fl, S_IMMUTABLE | S_APPEND);
129-
130-
inode_set_ctime_current(inode);
131-
mark_inode_dirty(inode);
132-
133-
return 0;
134-
}
135-
13652
/*
13753
* ntfs_ioctl - file_operations::unlocked_ioctl
13854
*/
@@ -430,7 +346,6 @@ static int ntfs_extend(struct inode *inode, loff_t pos, size_t count,
430346
}
431347

432348
if (extend_init && !is_compressed(ni)) {
433-
WARN_ON(ni->i_valid >= pos);
434349
err = ntfs_extend_initialized_size(file, ni, ni->i_valid, pos);
435350
if (err)
436351
goto out;
@@ -1409,8 +1324,6 @@ const struct inode_operations ntfs_file_inode_operations = {
14091324
.get_acl = ntfs_get_acl,
14101325
.set_acl = ntfs_set_acl,
14111326
.fiemap = ntfs_fiemap,
1412-
.fileattr_get = ntfs_fileattr_get,
1413-
.fileattr_set = ntfs_fileattr_set,
14141327
};
14151328

14161329
const struct file_operations ntfs_file_operations = {

fs/ntfs3/frecord.c

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3327,77 +3327,3 @@ int ni_write_inode(struct inode *inode, int sync, const char *hint)
33273327

33283328
return 0;
33293329
}
3330-
3331-
/*
3332-
* ni_set_compress
3333-
*
3334-
* Helper for 'ntfs_fileattr_set'.
3335-
* Changes compression for empty files and directories only.
3336-
*/
3337-
int ni_set_compress(struct inode *inode, bool compr)
3338-
{
3339-
int err;
3340-
struct ntfs_inode *ni = ntfs_i(inode);
3341-
struct ATTR_STD_INFO *std;
3342-
const char *bad_inode;
3343-
3344-
if (is_compressed(ni) == !!compr)
3345-
return 0;
3346-
3347-
if (is_sparsed(ni)) {
3348-
/* sparse and compress not compatible. */
3349-
return -EOPNOTSUPP;
3350-
}
3351-
3352-
if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode)) {
3353-
/*Skip other inodes. (symlink,fifo,...) */
3354-
return -EOPNOTSUPP;
3355-
}
3356-
3357-
bad_inode = NULL;
3358-
3359-
ni_lock(ni);
3360-
3361-
std = ni_std(ni);
3362-
if (!std) {
3363-
bad_inode = "no std";
3364-
goto out;
3365-
}
3366-
3367-
if (S_ISREG(inode->i_mode)) {
3368-
err = attr_set_compress(ni, compr);
3369-
if (err) {
3370-
if (err == -ENOENT) {
3371-
/* Fix on the fly? */
3372-
/* Each file must contain data attribute. */
3373-
bad_inode = "no data attribute";
3374-
}
3375-
goto out;
3376-
}
3377-
}
3378-
3379-
ni->std_fa = std->fa;
3380-
if (compr) {
3381-
std->fa &= ~FILE_ATTRIBUTE_SPARSE_FILE;
3382-
std->fa |= FILE_ATTRIBUTE_COMPRESSED;
3383-
} else {
3384-
std->fa &= ~FILE_ATTRIBUTE_COMPRESSED;
3385-
}
3386-
3387-
if (ni->std_fa != std->fa) {
3388-
ni->std_fa = std->fa;
3389-
ni->mi.dirty = true;
3390-
}
3391-
/* update duplicate information and directory entries in ni_write_inode.*/
3392-
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
3393-
err = 0;
3394-
3395-
out:
3396-
ni_unlock(ni);
3397-
if (bad_inode) {
3398-
ntfs_bad_inode(inode, bad_inode);
3399-
err = -EINVAL;
3400-
}
3401-
3402-
return err;
3403-
}

fs/ntfs3/fslog.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,16 +3091,16 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
30913091
inode = ilookup(sbi->sb, rno);
30923092
if (inode) {
30933093
mi = &ntfs_i(inode)->mi;
3094-
} else if (op == InitializeFileRecordSegment) {
3095-
mi = kzalloc(sizeof(struct mft_inode), GFP_NOFS);
3096-
if (!mi)
3097-
return -ENOMEM;
3098-
err = mi_format_new(mi, sbi, rno, 0, false);
3099-
if (err)
3100-
goto out;
31013094
} else {
31023095
/* Read from disk. */
31033096
err = mi_get(sbi, rno, &mi);
3097+
if (err && op == InitializeFileRecordSegment) {
3098+
mi = kzalloc(sizeof(struct mft_inode),
3099+
GFP_NOFS);
3100+
if (!mi)
3101+
return -ENOMEM;
3102+
err = mi_format_new(mi, sbi, rno, 0, false);
3103+
}
31043104
if (err)
31053105
return err;
31063106
}
@@ -3109,15 +3109,13 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
31093109
if (op == DeallocateFileRecordSegment)
31103110
goto skip_load_parent;
31113111

3112-
if (InitializeFileRecordSegment != op) {
3113-
if (rec->rhdr.sign == NTFS_BAAD_SIGNATURE)
3114-
goto dirty_vol;
3115-
if (!check_lsn(&rec->rhdr, rlsn))
3116-
goto out;
3117-
if (!check_file_record(rec, NULL, sbi))
3118-
goto dirty_vol;
3119-
attr = Add2Ptr(rec, roff);
3120-
}
3112+
if (rec->rhdr.sign == NTFS_BAAD_SIGNATURE)
3113+
goto dirty_vol;
3114+
if (!check_lsn(&rec->rhdr, rlsn))
3115+
goto out;
3116+
if (!check_file_record(rec, NULL, sbi))
3117+
goto dirty_vol;
3118+
attr = Add2Ptr(rec, roff);
31213119

31223120
if (is_rec_base(rec) || InitializeFileRecordSegment == op) {
31233121
rno_base = rno;
@@ -3143,7 +3141,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
31433141

31443142
if (inode)
31453143
iput(inode);
3146-
else if (mi)
3144+
else
31473145
mi_put(mi);
31483146

31493147
inode = inode_parent;

fs/ntfs3/index.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,10 @@ static int indx_get_entry_to_replace(struct ntfs_index *indx,
21822182

21832183
e = hdr_first_de(&n->index->ihdr);
21842184
fnd_push(fnd, n, e);
2185+
if (!e) {
2186+
err = -EINVAL;
2187+
goto out;
2188+
}
21852189

21862190
if (!de_is_last(e)) {
21872191
/*
@@ -2203,6 +2207,10 @@ static int indx_get_entry_to_replace(struct ntfs_index *indx,
22032207

22042208
n = fnd->nodes[level];
22052209
te = hdr_first_de(&n->index->ihdr);
2210+
if (!te) {
2211+
err = -EINVAL;
2212+
goto out;
2213+
}
22062214
/* Copy the candidate entry into the replacement entry buffer. */
22072215
re = kmalloc(le16_to_cpu(te->size) + sizeof(u64), GFP_NOFS);
22082216
if (!re) {

fs/ntfs3/inode.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,10 @@ static ssize_t ntfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
805805
ret = 0;
806806
goto out;
807807
}
808+
if (is_compressed(ni)) {
809+
ret = 0;
810+
goto out;
811+
}
808812

809813
ret = blockdev_direct_IO(iocb, inode, iter,
810814
wr ? ntfs_get_block_direct_IO_W :
@@ -2068,5 +2072,6 @@ const struct address_space_operations ntfs_aops_cmpr = {
20682072
.read_folio = ntfs_read_folio,
20692073
.readahead = ntfs_readahead,
20702074
.dirty_folio = block_dirty_folio,
2075+
.direct_IO = ntfs_direct_IO,
20712076
};
20722077
// clang-format on

fs/ntfs3/namei.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,6 @@ const struct inode_operations ntfs_dir_inode_operations = {
507507
.getattr = ntfs_getattr,
508508
.listxattr = ntfs_listxattr,
509509
.fiemap = ntfs_fiemap,
510-
.fileattr_get = ntfs_fileattr_get,
511-
.fileattr_set = ntfs_fileattr_set,
512510
};
513511

514512
const struct inode_operations ntfs_special_inode_operations = {

fs/ntfs3/ntfs_fs.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,6 @@ int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes);
454454
int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes);
455455
int attr_punch_hole(struct ntfs_inode *ni, u64 vbo, u64 bytes, u32 *frame_size);
456456
int attr_force_nonresident(struct ntfs_inode *ni);
457-
int attr_set_compress(struct ntfs_inode *ni, bool compr);
458457

459458
/* Functions from attrlist.c */
460459
void al_destroy(struct ntfs_inode *ni);
@@ -497,9 +496,6 @@ extern const struct file_operations ntfs_dir_operations;
497496
extern const struct file_operations ntfs_legacy_dir_operations;
498497

499498
/* Globals from file.c */
500-
int ntfs_fileattr_get(struct dentry *dentry, struct fileattr *fa);
501-
int ntfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
502-
struct fileattr *fa);
503499
int ntfs_getattr(struct mnt_idmap *idmap, const struct path *path,
504500
struct kstat *stat, u32 request_mask, u32 flags);
505501
int ntfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
@@ -585,7 +581,6 @@ int ni_rename(struct ntfs_inode *dir_ni, struct ntfs_inode *new_dir_ni,
585581
bool *is_bad);
586582

587583
bool ni_is_dirty(struct inode *inode);
588-
int ni_set_compress(struct inode *inode, bool compr);
589584

590585
/* Globals from fslog.c */
591586
bool check_index_header(const struct INDEX_HDR *hdr, size_t bytes);

0 commit comments

Comments
 (0)