1010#include <linux/mount.h>
1111#include <linux/blkdev.h>
1212#include <linux/compat.h>
13+ #include <linux/fileattr.h>
1314
1415#include <cluster/masklog.h>
1516
@@ -61,8 +62,10 @@ static inline int o2info_coherent(struct ocfs2_info_request *req)
6162 return (!(req -> ir_flags & OCFS2_INFO_FL_NON_COHERENT ));
6263}
6364
64- static int ocfs2_get_inode_attr (struct inode * inode , unsigned * flags )
65+ int ocfs2_fileattr_get (struct dentry * dentry , struct fileattr * fa )
6566{
67+ struct inode * inode = d_inode (dentry );
68+ unsigned int flags ;
6669 int status ;
6770
6871 status = ocfs2_inode_lock (inode , NULL , 0 );
@@ -71,43 +74,46 @@ static int ocfs2_get_inode_attr(struct inode *inode, unsigned *flags)
7174 return status ;
7275 }
7376 ocfs2_get_inode_flags (OCFS2_I (inode ));
74- * flags = OCFS2_I (inode )-> ip_attr ;
77+ flags = OCFS2_I (inode )-> ip_attr ;
7578 ocfs2_inode_unlock (inode , 0 );
7679
80+ fileattr_fill_flags (fa , flags & OCFS2_FL_VISIBLE );
81+
7782 return status ;
7883}
7984
80- static int ocfs2_set_inode_attr (struct inode * inode , unsigned flags ,
81- unsigned mask )
85+ int ocfs2_fileattr_set (struct user_namespace * mnt_userns ,
86+ struct dentry * dentry , struct fileattr * fa )
8287{
88+ struct inode * inode = d_inode (dentry );
89+ unsigned int flags = fa -> flags ;
8390 struct ocfs2_inode_info * ocfs2_inode = OCFS2_I (inode );
8491 struct ocfs2_super * osb = OCFS2_SB (inode -> i_sb );
8592 handle_t * handle = NULL ;
8693 struct buffer_head * bh = NULL ;
8794 unsigned oldflags ;
8895 int status ;
8996
90- inode_lock (inode );
97+ if (fileattr_has_fsx (fa ))
98+ return - EOPNOTSUPP ;
9199
92100 status = ocfs2_inode_lock (inode , & bh , 1 );
93101 if (status < 0 ) {
94102 mlog_errno (status );
95103 goto bail ;
96104 }
97105
98- status = - EACCES ;
99- if (!inode_owner_or_capable (& init_user_ns , inode ))
100- goto bail_unlock ;
101-
102106 if (!S_ISDIR (inode -> i_mode ))
103107 flags &= ~OCFS2_DIRSYNC_FL ;
104108
105109 oldflags = ocfs2_inode -> ip_attr ;
106- flags = flags & mask ;
107- flags |= oldflags & ~mask ;
110+ flags = flags & OCFS2_FL_MODIFIABLE ;
111+ flags |= oldflags & ~OCFS2_FL_MODIFIABLE ;
108112
109- status = vfs_ioc_setflags_prepare (inode , oldflags , flags );
110- if (status )
113+ /* Check already done by VFS, but repeat with ocfs lock */
114+ status = - EPERM ;
115+ if ((flags ^ oldflags ) & (FS_APPEND_FL | FS_IMMUTABLE_FL ) &&
116+ !capable (CAP_LINUX_IMMUTABLE ))
111117 goto bail_unlock ;
112118
113119 handle = ocfs2_start_trans (osb , OCFS2_INODE_UPDATE_CREDITS );
@@ -129,8 +135,6 @@ static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
129135bail_unlock :
130136 ocfs2_inode_unlock (inode , 1 );
131137bail :
132- inode_unlock (inode );
133-
134138 brelse (bh );
135139
136140 return status ;
@@ -836,7 +840,6 @@ static int ocfs2_info_handle(struct inode *inode, struct ocfs2_info *info,
836840long ocfs2_ioctl (struct file * filp , unsigned int cmd , unsigned long arg )
837841{
838842 struct inode * inode = file_inode (filp );
839- unsigned int flags ;
840843 int new_clusters ;
841844 int status ;
842845 struct ocfs2_space_resv sr ;
@@ -849,24 +852,6 @@ long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
849852 void __user * argp = (void __user * )arg ;
850853
851854 switch (cmd ) {
852- case OCFS2_IOC_GETFLAGS :
853- status = ocfs2_get_inode_attr (inode , & flags );
854- if (status < 0 )
855- return status ;
856-
857- flags &= OCFS2_FL_VISIBLE ;
858- return put_user (flags , (int __user * ) arg );
859- case OCFS2_IOC_SETFLAGS :
860- if (get_user (flags , (int __user * ) arg ))
861- return - EFAULT ;
862-
863- status = mnt_want_write_file (filp );
864- if (status )
865- return status ;
866- status = ocfs2_set_inode_attr (inode , flags ,
867- OCFS2_FL_MODIFIABLE );
868- mnt_drop_write_file (filp );
869- return status ;
870855 case OCFS2_IOC_RESVSP :
871856 case OCFS2_IOC_RESVSP64 :
872857 case OCFS2_IOC_UNRESVSP :
@@ -959,12 +944,6 @@ long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg)
959944 void __user * argp = (void __user * )arg ;
960945
961946 switch (cmd ) {
962- case OCFS2_IOC32_GETFLAGS :
963- cmd = OCFS2_IOC_GETFLAGS ;
964- break ;
965- case OCFS2_IOC32_SETFLAGS :
966- cmd = OCFS2_IOC_SETFLAGS ;
967- break ;
968947 case OCFS2_IOC_RESVSP :
969948 case OCFS2_IOC_RESVSP64 :
970949 case OCFS2_IOC_UNRESVSP :
0 commit comments