Skip to content

Commit 2ca58e3

Browse files
author
Miklos Szeredi
committed
jfs: convert to fileattr
Use the fileattr API to let the VFS handle locking, permission checking and conversion. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Cc: Dave Kleikamp <shaggy@kernel.org>
1 parent 9cbae74 commit 2ca58e3

5 files changed

Lines changed: 49 additions & 85 deletions

File tree

fs/jfs/file.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ int jfs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
130130
const struct inode_operations jfs_file_inode_operations = {
131131
.listxattr = jfs_listxattr,
132132
.setattr = jfs_setattr,
133+
.fileattr_get = jfs_fileattr_get,
134+
.fileattr_set = jfs_fileattr_set,
133135
#ifdef CONFIG_JFS_POSIX_ACL
134136
.get_acl = jfs_get_acl,
135137
.set_acl = jfs_set_acl,
@@ -147,7 +149,5 @@ const struct file_operations jfs_file_operations = {
147149
.fsync = jfs_fsync,
148150
.release = jfs_release,
149151
.unlocked_ioctl = jfs_ioctl,
150-
#ifdef CONFIG_COMPAT
151-
.compat_ioctl = jfs_compat_ioctl,
152-
#endif
152+
.compat_ioctl = compat_ptr_ioctl,
153153
};

fs/jfs/ioctl.c

Lines changed: 40 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/blkdev.h>
1616
#include <asm/current.h>
1717
#include <linux/uaccess.h>
18+
#include <linux/fileattr.h>
1819

1920
#include "jfs_filsys.h"
2021
#include "jfs_debug.h"
@@ -56,69 +57,56 @@ static long jfs_map_ext2(unsigned long flags, int from)
5657
return mapped;
5758
}
5859

60+
int jfs_fileattr_get(struct dentry *dentry, struct fileattr *fa)
61+
{
62+
struct jfs_inode_info *jfs_inode = JFS_IP(d_inode(dentry));
63+
unsigned int flags = jfs_inode->mode2 & JFS_FL_USER_VISIBLE;
5964

60-
long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
65+
if (d_is_special(dentry))
66+
return -ENOTTY;
67+
68+
fileattr_fill_flags(fa, jfs_map_ext2(flags, 0));
69+
70+
return 0;
71+
}
72+
73+
int jfs_fileattr_set(struct user_namespace *mnt_userns,
74+
struct dentry *dentry, struct fileattr *fa)
6175
{
62-
struct inode *inode = file_inode(filp);
76+
struct inode *inode = d_inode(dentry);
6377
struct jfs_inode_info *jfs_inode = JFS_IP(inode);
6478
unsigned int flags;
6579

66-
switch (cmd) {
67-
case JFS_IOC_GETFLAGS:
68-
flags = jfs_inode->mode2 & JFS_FL_USER_VISIBLE;
69-
flags = jfs_map_ext2(flags, 0);
70-
return put_user(flags, (int __user *) arg);
71-
case JFS_IOC_SETFLAGS: {
72-
unsigned int oldflags;
73-
int err;
74-
75-
err = mnt_want_write_file(filp);
76-
if (err)
77-
return err;
78-
79-
if (!inode_owner_or_capable(&init_user_ns, inode)) {
80-
err = -EACCES;
81-
goto setflags_out;
82-
}
83-
if (get_user(flags, (int __user *) arg)) {
84-
err = -EFAULT;
85-
goto setflags_out;
86-
}
80+
if (d_is_special(dentry))
81+
return -ENOTTY;
8782

88-
flags = jfs_map_ext2(flags, 1);
89-
if (!S_ISDIR(inode->i_mode))
90-
flags &= ~JFS_DIRSYNC_FL;
83+
if (fileattr_has_fsx(fa))
84+
return -EOPNOTSUPP;
9185

92-
/* Is it quota file? Do not allow user to mess with it */
93-
if (IS_NOQUOTA(inode)) {
94-
err = -EPERM;
95-
goto setflags_out;
96-
}
86+
flags = jfs_map_ext2(fa->flags, 1);
87+
if (!S_ISDIR(inode->i_mode))
88+
flags &= ~JFS_DIRSYNC_FL;
9789

98-
/* Lock against other parallel changes of flags */
99-
inode_lock(inode);
90+
/* Is it quota file? Do not allow user to mess with it */
91+
if (IS_NOQUOTA(inode))
92+
return -EPERM;
10093

101-
oldflags = jfs_map_ext2(jfs_inode->mode2 & JFS_FL_USER_VISIBLE,
102-
0);
103-
err = vfs_ioc_setflags_prepare(inode, oldflags, flags);
104-
if (err) {
105-
inode_unlock(inode);
106-
goto setflags_out;
107-
}
94+
flags = flags & JFS_FL_USER_MODIFIABLE;
95+
flags |= jfs_inode->mode2 & ~JFS_FL_USER_MODIFIABLE;
96+
jfs_inode->mode2 = flags;
10897

109-
flags = flags & JFS_FL_USER_MODIFIABLE;
110-
flags |= jfs_inode->mode2 & ~JFS_FL_USER_MODIFIABLE;
111-
jfs_inode->mode2 = flags;
112-
113-
jfs_set_inode_flags(inode);
114-
inode_unlock(inode);
115-
inode->i_ctime = current_time(inode);
116-
mark_inode_dirty(inode);
117-
setflags_out:
118-
mnt_drop_write_file(filp);
119-
return err;
120-
}
98+
jfs_set_inode_flags(inode);
99+
inode->i_ctime = current_time(inode);
100+
mark_inode_dirty(inode);
101+
102+
return 0;
103+
}
104+
105+
long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
106+
{
107+
struct inode *inode = file_inode(filp);
121108

109+
switch (cmd) {
122110
case FITRIM:
123111
{
124112
struct super_block *sb = inode->i_sb;
@@ -156,22 +144,3 @@ long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
156144
return -ENOTTY;
157145
}
158146
}
159-
160-
#ifdef CONFIG_COMPAT
161-
long jfs_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
162-
{
163-
/* While these ioctl numbers defined with 'long' and have different
164-
* numbers than the 64bit ABI,
165-
* the actual implementation only deals with ints and is compatible.
166-
*/
167-
switch (cmd) {
168-
case JFS_IOC_GETFLAGS32:
169-
cmd = JFS_IOC_GETFLAGS;
170-
break;
171-
case JFS_IOC_SETFLAGS32:
172-
cmd = JFS_IOC_SETFLAGS;
173-
break;
174-
}
175-
return jfs_ioctl(filp, cmd, arg);
176-
}
177-
#endif

fs/jfs/jfs_dinode.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,4 @@ struct dinode {
160160
#define JFS_FL_USER_MODIFIABLE 0x03F80000
161161
#define JFS_FL_INHERIT 0x03C80000
162162

163-
/* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
164-
#define JFS_IOC_GETFLAGS _IOR('f', 1, long)
165-
#define JFS_IOC_SETFLAGS _IOW('f', 2, long)
166-
167-
#define JFS_IOC_GETFLAGS32 _IOR('f', 1, int)
168-
#define JFS_IOC_SETFLAGS32 _IOW('f', 2, int)
169-
170163
#endif /*_H_JFS_DINODE */

fs/jfs/jfs_inode.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ struct fid;
99

1010
extern struct inode *ialloc(struct inode *, umode_t);
1111
extern int jfs_fsync(struct file *, loff_t, loff_t, int);
12+
extern int jfs_fileattr_get(struct dentry *dentry, struct fileattr *fa);
13+
extern int jfs_fileattr_set(struct user_namespace *mnt_userns,
14+
struct dentry *dentry, struct fileattr *fa);
1215
extern long jfs_ioctl(struct file *, unsigned int, unsigned long);
13-
extern long jfs_compat_ioctl(struct file *, unsigned int, unsigned long);
1416
extern struct inode *jfs_iget(struct super_block *, unsigned long);
1517
extern int jfs_commit_inode(struct inode *, int);
1618
extern int jfs_write_inode(struct inode *, struct writeback_control *);

fs/jfs/namei.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,8 @@ const struct inode_operations jfs_dir_inode_operations = {
15221522
.rename = jfs_rename,
15231523
.listxattr = jfs_listxattr,
15241524
.setattr = jfs_setattr,
1525+
.fileattr_get = jfs_fileattr_get,
1526+
.fileattr_set = jfs_fileattr_set,
15251527
#ifdef CONFIG_JFS_POSIX_ACL
15261528
.get_acl = jfs_get_acl,
15271529
.set_acl = jfs_set_acl,
@@ -1533,9 +1535,7 @@ const struct file_operations jfs_dir_operations = {
15331535
.iterate = jfs_readdir,
15341536
.fsync = jfs_fsync,
15351537
.unlocked_ioctl = jfs_ioctl,
1536-
#ifdef CONFIG_COMPAT
1537-
.compat_ioctl = jfs_compat_ioctl,
1538-
#endif
1538+
.compat_ioctl = compat_ptr_ioctl,
15391539
.llseek = generic_file_llseek,
15401540
};
15411541

0 commit comments

Comments
 (0)