Skip to content

Commit 5bfb91c

Browse files
fs/ntfs3: Implement simple fileattr
fileattr added to support chattr. Supported attributes: compressed and immutable. Signed-off-by: Konstantin Komarov <[email protected]>
1 parent 1ff2e95 commit 5bfb91c

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed

fs/ntfs3/file.c

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/compat.h>
1414
#include <linux/falloc.h>
1515
#include <linux/fiemap.h>
16+
#include <linux/fileattr.h>
1617

1718
#include "debug.h"
1819
#include "ntfs.h"
@@ -48,6 +49,62 @@ static int ntfs_ioctl_fitrim(struct ntfs_sb_info *sbi, unsigned long arg)
4849
return 0;
4950
}
5051

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+
u32 flags = fa->flags;
86+
unsigned int new_fl = 0;
87+
88+
if (fileattr_has_fsx(fa))
89+
return -EOPNOTSUPP;
90+
91+
if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL))
92+
return -EOPNOTSUPP;
93+
94+
if (flags & FS_IMMUTABLE_FL)
95+
new_fl |= S_IMMUTABLE;
96+
97+
if (flags & FS_APPEND_FL)
98+
new_fl |= S_APPEND;
99+
100+
inode_set_flags(inode, new_fl, S_IMMUTABLE | S_APPEND);
101+
102+
inode_set_ctime_current(inode);
103+
mark_inode_dirty(inode);
104+
105+
return 0;
106+
}
107+
51108
long ntfs_ioctl(struct file *filp, u32 cmd, unsigned long arg)
52109
{
53110
struct inode *inode = file_inode(filp);
@@ -77,20 +134,27 @@ int ntfs_getattr(struct mnt_idmap *idmap, const struct path *path,
77134
struct inode *inode = d_inode(path->dentry);
78135
struct ntfs_inode *ni = ntfs_i(inode);
79136

137+
stat->result_mask |= STATX_BTIME;
138+
stat->btime = ni->i_crtime;
139+
stat->blksize = ni->mi.sbi->cluster_size; /* 512, 1K, ..., 2M */
140+
141+
if (inode->i_flags & S_IMMUTABLE)
142+
stat->attributes |= STATX_ATTR_IMMUTABLE;
143+
144+
if (inode->i_flags & S_APPEND)
145+
stat->attributes |= STATX_ATTR_APPEND;
146+
80147
if (is_compressed(ni))
81148
stat->attributes |= STATX_ATTR_COMPRESSED;
82149

83150
if (is_encrypted(ni))
84151
stat->attributes |= STATX_ATTR_ENCRYPTED;
85152

86-
stat->attributes_mask |= STATX_ATTR_COMPRESSED | STATX_ATTR_ENCRYPTED;
153+
stat->attributes_mask |= STATX_ATTR_COMPRESSED | STATX_ATTR_ENCRYPTED |
154+
STATX_ATTR_IMMUTABLE | STATX_ATTR_APPEND;
87155

88156
generic_fillattr(idmap, request_mask, inode, stat);
89157

90-
stat->result_mask |= STATX_BTIME;
91-
stat->btime = ni->i_crtime;
92-
stat->blksize = ni->mi.sbi->cluster_size; /* 512, 1K, ..., 2M */
93-
94158
return 0;
95159
}
96160

@@ -1223,6 +1287,8 @@ const struct inode_operations ntfs_file_inode_operations = {
12231287
.get_acl = ntfs_get_acl,
12241288
.set_acl = ntfs_set_acl,
12251289
.fiemap = ntfs_fiemap,
1290+
.fileattr_get = ntfs_fileattr_get,
1291+
.fileattr_set = ntfs_fileattr_set,
12261292
};
12271293

12281294
const struct file_operations ntfs_file_operations = {

fs/ntfs3/namei.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ const struct inode_operations ntfs_dir_inode_operations = {
509509
.getattr = ntfs_getattr,
510510
.listxattr = ntfs_listxattr,
511511
.fiemap = ntfs_fiemap,
512+
.fileattr_get = ntfs_fileattr_get,
513+
.fileattr_set = ntfs_fileattr_set,
512514
};
513515

514516
const struct inode_operations ntfs_special_inode_operations = {

fs/ntfs3/ntfs_fs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ extern const struct file_operations ntfs_dir_operations;
497497
extern const struct file_operations ntfs_legacy_dir_operations;
498498

499499
/* 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);
500503
int ntfs_getattr(struct mnt_idmap *idmap, const struct path *path,
501504
struct kstat *stat, u32 request_mask, u32 flags);
502505
int ntfs3_setattr(struct mnt_idmap *idmap, struct dentry *dentry,

0 commit comments

Comments
 (0)