17
17
#include "xattr.h"
18
18
#include "acl.h"
19
19
20
- #define get_inode_mode (i ) ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
21
- (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
22
-
23
20
static inline size_t f2fs_acl_size (int count )
24
21
{
25
22
if (count <= 4 ) {
@@ -167,19 +164,11 @@ static void *f2fs_acl_to_disk(const struct posix_acl *acl, size_t *size)
167
164
168
165
struct posix_acl * f2fs_get_acl (struct inode * inode , int type )
169
166
{
170
- struct f2fs_sb_info * sbi = F2FS_SB (inode -> i_sb );
171
167
int name_index = F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT ;
172
168
void * value = NULL ;
173
169
struct posix_acl * acl ;
174
170
int retval ;
175
171
176
- if (!test_opt (sbi , POSIX_ACL ))
177
- return NULL ;
178
-
179
- acl = get_cached_acl (inode , type );
180
- if (acl != ACL_NOT_CACHED )
181
- return acl ;
182
-
183
172
if (type == ACL_TYPE_ACCESS )
184
173
name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS ;
185
174
@@ -205,21 +194,15 @@ struct posix_acl *f2fs_get_acl(struct inode *inode, int type)
205
194
return acl ;
206
195
}
207
196
208
- static int f2fs_set_acl (struct inode * inode , int type ,
197
+ static int __f2fs_set_acl (struct inode * inode , int type ,
209
198
struct posix_acl * acl , struct page * ipage )
210
199
{
211
- struct f2fs_sb_info * sbi = F2FS_SB (inode -> i_sb );
212
200
struct f2fs_inode_info * fi = F2FS_I (inode );
213
201
int name_index ;
214
202
void * value = NULL ;
215
203
size_t size = 0 ;
216
204
int error ;
217
205
218
- if (!test_opt (sbi , POSIX_ACL ))
219
- return 0 ;
220
- if (S_ISLNK (inode -> i_mode ))
221
- return - EOPNOTSUPP ;
222
-
223
206
switch (type ) {
224
207
case ACL_TYPE_ACCESS :
225
208
name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS ;
@@ -261,154 +244,31 @@ static int f2fs_set_acl(struct inode *inode, int type,
261
244
return error ;
262
245
}
263
246
264
- int f2fs_init_acl (struct inode * inode , struct inode * dir , struct page * ipage )
247
+ int f2fs_set_acl (struct inode * inode , struct posix_acl * acl , int type )
265
248
{
266
- struct f2fs_sb_info * sbi = F2FS_SB (dir -> i_sb );
267
- struct posix_acl * acl = NULL ;
268
- int error = 0 ;
269
-
270
- if (!S_ISLNK (inode -> i_mode )) {
271
- if (test_opt (sbi , POSIX_ACL )) {
272
- acl = f2fs_get_acl (dir , ACL_TYPE_DEFAULT );
273
- if (IS_ERR (acl ))
274
- return PTR_ERR (acl );
275
- }
276
- if (!acl )
277
- inode -> i_mode &= ~current_umask ();
278
- }
279
-
280
- if (!test_opt (sbi , POSIX_ACL ) || !acl )
281
- goto cleanup ;
282
-
283
- if (S_ISDIR (inode -> i_mode )) {
284
- error = f2fs_set_acl (inode , ACL_TYPE_DEFAULT , acl , ipage );
285
- if (error )
286
- goto cleanup ;
287
- }
288
- error = __posix_acl_create (& acl , GFP_KERNEL , & inode -> i_mode );
289
- if (error < 0 )
290
- return error ;
291
- if (error > 0 )
292
- error = f2fs_set_acl (inode , ACL_TYPE_ACCESS , acl , ipage );
293
- cleanup :
294
- posix_acl_release (acl );
295
- return error ;
249
+ return __f2fs_set_acl (inode , type , acl , NULL );
296
250
}
297
251
298
- int f2fs_acl_chmod (struct inode * inode )
252
+ int f2fs_init_acl (struct inode * inode , struct inode * dir , struct page * ipage )
299
253
{
300
- struct f2fs_sb_info * sbi = F2FS_SB (inode -> i_sb );
301
- struct posix_acl * acl ;
302
- int error ;
303
- umode_t mode = get_inode_mode (inode );
304
-
305
- if (!test_opt (sbi , POSIX_ACL ))
306
- return 0 ;
307
- if (S_ISLNK (mode ))
308
- return - EOPNOTSUPP ;
309
-
310
- acl = f2fs_get_acl (inode , ACL_TYPE_ACCESS );
311
- if (IS_ERR (acl ) || !acl )
312
- return PTR_ERR (acl );
254
+ struct posix_acl * default_acl , * acl ;
255
+ int error = 0 ;
313
256
314
- error = __posix_acl_chmod ( & acl , GFP_KERNEL , mode );
257
+ error = posix_acl_create ( dir , & inode -> i_mode , & default_acl , & acl );
315
258
if (error )
316
259
return error ;
317
260
318
- error = f2fs_set_acl (inode , ACL_TYPE_ACCESS , acl , NULL );
319
- posix_acl_release (acl );
320
- return error ;
321
- }
322
-
323
- static size_t f2fs_xattr_list_acl (struct dentry * dentry , char * list ,
324
- size_t list_size , const char * name , size_t name_len , int type )
325
- {
326
- struct f2fs_sb_info * sbi = F2FS_SB (dentry -> d_sb );
327
- const char * xname = POSIX_ACL_XATTR_DEFAULT ;
328
- size_t size ;
329
-
330
- if (!test_opt (sbi , POSIX_ACL ))
331
- return 0 ;
332
-
333
- if (type == ACL_TYPE_ACCESS )
334
- xname = POSIX_ACL_XATTR_ACCESS ;
335
-
336
- size = strlen (xname ) + 1 ;
337
- if (list && size <= list_size )
338
- memcpy (list , xname , size );
339
- return size ;
340
- }
341
-
342
- static int f2fs_xattr_get_acl (struct dentry * dentry , const char * name ,
343
- void * buffer , size_t size , int type )
344
- {
345
- struct f2fs_sb_info * sbi = F2FS_SB (dentry -> d_sb );
346
- struct posix_acl * acl ;
347
- int error ;
348
-
349
- if (strcmp (name , "" ) != 0 )
350
- return - EINVAL ;
351
- if (!test_opt (sbi , POSIX_ACL ))
352
- return - EOPNOTSUPP ;
353
-
354
- acl = f2fs_get_acl (dentry -> d_inode , type );
355
- if (IS_ERR (acl ))
356
- return PTR_ERR (acl );
357
- if (!acl )
358
- return - ENODATA ;
359
- error = posix_acl_to_xattr (& init_user_ns , acl , buffer , size );
360
- posix_acl_release (acl );
361
-
362
- return error ;
363
- }
364
-
365
- static int f2fs_xattr_set_acl (struct dentry * dentry , const char * name ,
366
- const void * value , size_t size , int flags , int type )
367
- {
368
- struct f2fs_sb_info * sbi = F2FS_SB (dentry -> d_sb );
369
- struct inode * inode = dentry -> d_inode ;
370
- struct posix_acl * acl = NULL ;
371
- int error ;
372
-
373
- if (strcmp (name , "" ) != 0 )
374
- return - EINVAL ;
375
- if (!test_opt (sbi , POSIX_ACL ))
376
- return - EOPNOTSUPP ;
377
- if (!inode_owner_or_capable (inode ))
378
- return - EPERM ;
379
-
380
- if (value ) {
381
- acl = posix_acl_from_xattr (& init_user_ns , value , size );
382
- if (IS_ERR (acl ))
383
- return PTR_ERR (acl );
384
- if (acl ) {
385
- error = posix_acl_valid (acl );
386
- if (error )
387
- goto release_and_out ;
388
- }
389
- } else {
390
- acl = NULL ;
261
+ if (default_acl ) {
262
+ error = __f2fs_set_acl (inode , ACL_TYPE_DEFAULT , default_acl ,
263
+ ipage );
264
+ posix_acl_release (default_acl );
265
+ }
266
+ if (acl ) {
267
+ if (error )
268
+ error = __f2fs_set_acl (inode , ACL_TYPE_ACCESS , acl ,
269
+ ipage );
270
+ posix_acl_release (acl );
391
271
}
392
272
393
- error = f2fs_set_acl (inode , type , acl , NULL );
394
-
395
- release_and_out :
396
- posix_acl_release (acl );
397
273
return error ;
398
274
}
399
-
400
- const struct xattr_handler f2fs_xattr_acl_default_handler = {
401
- .prefix = POSIX_ACL_XATTR_DEFAULT ,
402
- .flags = ACL_TYPE_DEFAULT ,
403
- .list = f2fs_xattr_list_acl ,
404
- .get = f2fs_xattr_get_acl ,
405
- .set = f2fs_xattr_set_acl ,
406
- };
407
-
408
- const struct xattr_handler f2fs_xattr_acl_access_handler = {
409
- .prefix = POSIX_ACL_XATTR_ACCESS ,
410
- .flags = ACL_TYPE_ACCESS ,
411
- .list = f2fs_xattr_list_acl ,
412
- .get = f2fs_xattr_get_acl ,
413
- .set = f2fs_xattr_set_acl ,
414
- };
0 commit comments