1414
1515#include <linux/compat.h>
1616#include <linux/mount.h>
17+ #include <linux/fileattr.h>
1718#include "ubifs.h"
1819
1920/* Need to be kept consistent with checked flags in ioctl2ubifs() */
@@ -103,7 +104,7 @@ static int ubifs2ioctl(int ubifs_flags)
103104
104105static int setflags (struct inode * inode , int flags )
105106{
106- int oldflags , err , release ;
107+ int err , release ;
107108 struct ubifs_inode * ui = ubifs_inode (inode );
108109 struct ubifs_info * c = inode -> i_sb -> s_fs_info ;
109110 struct ubifs_budget_req req = { .dirtied_ino = 1 ,
@@ -114,11 +115,6 @@ static int setflags(struct inode *inode, int flags)
114115 return err ;
115116
116117 mutex_lock (& ui -> ui_mutex );
117- oldflags = ubifs2ioctl (ui -> flags );
118- err = vfs_ioc_setflags_prepare (inode , oldflags , flags );
119- if (err )
120- goto out_unlock ;
121-
122118 ui -> flags &= ~ioctl2ubifs (UBIFS_SETTABLE_IOCTL_FLAGS );
123119 ui -> flags |= ioctl2ubifs (flags );
124120 ubifs_set_inode_flags (inode );
@@ -132,54 +128,52 @@ static int setflags(struct inode *inode, int flags)
132128 if (IS_SYNC (inode ))
133129 err = write_inode_now (inode , 1 );
134130 return err ;
131+ }
135132
136- out_unlock :
137- mutex_unlock (& ui -> ui_mutex );
138- ubifs_release_budget (c , & req );
139- return err ;
133+ int ubifs_fileattr_get (struct dentry * dentry , struct fileattr * fa )
134+ {
135+ struct inode * inode = d_inode (dentry );
136+ int flags = ubifs2ioctl (ubifs_inode (inode )-> flags );
137+
138+ if (d_is_special (dentry ))
139+ return - ENOTTY ;
140+
141+ dbg_gen ("get flags: %#x, i_flags %#x" , flags , inode -> i_flags );
142+ fileattr_fill_flags (fa , flags );
143+
144+ return 0 ;
140145}
141146
142- long ubifs_ioctl (struct file * file , unsigned int cmd , unsigned long arg )
147+ int ubifs_fileattr_set (struct user_namespace * mnt_userns ,
148+ struct dentry * dentry , struct fileattr * fa )
143149{
144- int flags , err ;
145- struct inode * inode = file_inode ( file ) ;
150+ struct inode * inode = d_inode ( dentry ) ;
151+ int flags = fa -> flags ;
146152
147- switch (cmd ) {
148- case FS_IOC_GETFLAGS :
149- flags = ubifs2ioctl (ubifs_inode (inode )-> flags );
153+ if (d_is_special (dentry ))
154+ return - ENOTTY ;
150155
151- dbg_gen ( "get flags: %#x, i_flags %#x" , flags , inode -> i_flags );
152- return put_user ( flags , ( int __user * ) arg ) ;
156+ if ( fileattr_has_fsx ( fa ))
157+ return - EOPNOTSUPP ;
153158
154- case FS_IOC_SETFLAGS : {
155- if (IS_RDONLY (inode ))
156- return - EROFS ;
159+ if (flags & ~UBIFS_GETTABLE_IOCTL_FLAGS )
160+ return - EOPNOTSUPP ;
157161
158- if (!inode_owner_or_capable (& init_user_ns , inode ))
159- return - EACCES ;
162+ flags &= UBIFS_SETTABLE_IOCTL_FLAGS ;
160163
161- if (get_user ( flags , ( int __user * ) arg ))
162- return - EFAULT ;
164+ if (! S_ISDIR ( inode -> i_mode ))
165+ flags &= ~ FS_DIRSYNC_FL ;
163166
164- if ( flags & ~ UBIFS_GETTABLE_IOCTL_FLAGS )
165- return - EOPNOTSUPP ;
166- flags &= UBIFS_SETTABLE_IOCTL_FLAGS ;
167+ dbg_gen ( "set flags: %#x, i_flags %#x" , flags , inode -> i_flags );
168+ return setflags ( inode , flags ) ;
169+ }
167170
168- if (!S_ISDIR (inode -> i_mode ))
169- flags &= ~FS_DIRSYNC_FL ;
171+ long ubifs_ioctl (struct file * file , unsigned int cmd , unsigned long arg )
172+ {
173+ int err ;
174+ struct inode * inode = file_inode (file );
170175
171- /*
172- * Make sure the file-system is read-write and make sure it
173- * will not become read-only while we are changing the flags.
174- */
175- err = mnt_want_write_file (file );
176- if (err )
177- return err ;
178- dbg_gen ("set flags: %#x, i_flags %#x" , flags , inode -> i_flags );
179- err = setflags (inode , flags );
180- mnt_drop_write_file (file );
181- return err ;
182- }
176+ switch (cmd ) {
183177 case FS_IOC_SET_ENCRYPTION_POLICY : {
184178 struct ubifs_info * c = inode -> i_sb -> s_fs_info ;
185179
0 commit comments