Skip to content

Commit eeb0819

Browse files
fs/ntfs3: remove ability to change compression on mounted volume
Remove all the code related to changing compression on the fly because it's not safe and not maintainable. Signed-off-by: Konstantin Komarov <[email protected]>
1 parent 766797c commit eeb0819

File tree

5 files changed

+0
-240
lines changed

5 files changed

+0
-240
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/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)