aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs/acl.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/f2fs/acl.c')
-rw-r--r--fs/f2fs/acl.c148
1 files changed, 140 insertions, 8 deletions
diff --git a/fs/f2fs/acl.c b/fs/f2fs/acl.c
index 83b9b5a8d112..1ccb26bc2a0b 100644
--- a/fs/f2fs/acl.c
+++ b/fs/f2fs/acl.c
@@ -162,7 +162,8 @@ fail:
162 return ERR_PTR(-EINVAL); 162 return ERR_PTR(-EINVAL);
163} 163}
164 164
165struct posix_acl *f2fs_get_acl(struct inode *inode, int type) 165static struct posix_acl *__f2fs_get_acl(struct inode *inode, int type,
166 struct page *dpage)
166{ 167{
167 int name_index = F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT; 168 int name_index = F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT;
168 void *value = NULL; 169 void *value = NULL;
@@ -172,12 +173,13 @@ struct posix_acl *f2fs_get_acl(struct inode *inode, int type)
172 if (type == ACL_TYPE_ACCESS) 173 if (type == ACL_TYPE_ACCESS)
173 name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS; 174 name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
174 175
175 retval = f2fs_getxattr(inode, name_index, "", NULL, 0); 176 retval = f2fs_getxattr(inode, name_index, "", NULL, 0, dpage);
176 if (retval > 0) { 177 if (retval > 0) {
177 value = kmalloc(retval, GFP_F2FS_ZERO); 178 value = kmalloc(retval, GFP_F2FS_ZERO);
178 if (!value) 179 if (!value)
179 return ERR_PTR(-ENOMEM); 180 return ERR_PTR(-ENOMEM);
180 retval = f2fs_getxattr(inode, name_index, "", value, retval); 181 retval = f2fs_getxattr(inode, name_index, "", value,
182 retval, dpage);
181 } 183 }
182 184
183 if (retval > 0) 185 if (retval > 0)
@@ -194,6 +196,11 @@ struct posix_acl *f2fs_get_acl(struct inode *inode, int type)
194 return acl; 196 return acl;
195} 197}
196 198
199struct posix_acl *f2fs_get_acl(struct inode *inode, int type)
200{
201 return __f2fs_get_acl(inode, type, NULL);
202}
203
197static int __f2fs_set_acl(struct inode *inode, int type, 204static int __f2fs_set_acl(struct inode *inode, int type,
198 struct posix_acl *acl, struct page *ipage) 205 struct posix_acl *acl, struct page *ipage)
199{ 206{
@@ -229,7 +236,7 @@ static int __f2fs_set_acl(struct inode *inode, int type,
229 if (acl) { 236 if (acl) {
230 value = f2fs_acl_to_disk(acl, &size); 237 value = f2fs_acl_to_disk(acl, &size);
231 if (IS_ERR(value)) { 238 if (IS_ERR(value)) {
232 cond_clear_inode_flag(fi, FI_ACL_MODE); 239 clear_inode_flag(fi, FI_ACL_MODE);
233 return (int)PTR_ERR(value); 240 return (int)PTR_ERR(value);
234 } 241 }
235 } 242 }
@@ -240,7 +247,7 @@ static int __f2fs_set_acl(struct inode *inode, int type,
240 if (!error) 247 if (!error)
241 set_cached_acl(inode, type, acl); 248 set_cached_acl(inode, type, acl);
242 249
243 cond_clear_inode_flag(fi, FI_ACL_MODE); 250 clear_inode_flag(fi, FI_ACL_MODE);
244 return error; 251 return error;
245} 252}
246 253
@@ -249,12 +256,137 @@ int f2fs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
249 return __f2fs_set_acl(inode, type, acl, NULL); 256 return __f2fs_set_acl(inode, type, acl, NULL);
250} 257}
251 258
252int f2fs_init_acl(struct inode *inode, struct inode *dir, struct page *ipage) 259/*
260 * Most part of f2fs_acl_clone, f2fs_acl_create_masq, f2fs_acl_create
261 * are copied from posix_acl.c
262 */
263static struct posix_acl *f2fs_acl_clone(const struct posix_acl *acl,
264 gfp_t flags)
265{
266 struct posix_acl *clone = NULL;
267
268 if (acl) {
269 int size = sizeof(struct posix_acl) + acl->a_count *
270 sizeof(struct posix_acl_entry);
271 clone = kmemdup(acl, size, flags);
272 if (clone)
273 atomic_set(&clone->a_refcount, 1);
274 }
275 return clone;
276}
277
278static int f2fs_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
279{
280 struct posix_acl_entry *pa, *pe;
281 struct posix_acl_entry *group_obj = NULL, *mask_obj = NULL;
282 umode_t mode = *mode_p;
283 int not_equiv = 0;
284
285 /* assert(atomic_read(acl->a_refcount) == 1); */
286
287 FOREACH_ACL_ENTRY(pa, acl, pe) {
288 switch(pa->e_tag) {
289 case ACL_USER_OBJ:
290 pa->e_perm &= (mode >> 6) | ~S_IRWXO;
291 mode &= (pa->e_perm << 6) | ~S_IRWXU;
292 break;
293
294 case ACL_USER:
295 case ACL_GROUP:
296 not_equiv = 1;
297 break;
298
299 case ACL_GROUP_OBJ:
300 group_obj = pa;
301 break;
302
303 case ACL_OTHER:
304 pa->e_perm &= mode | ~S_IRWXO;
305 mode &= pa->e_perm | ~S_IRWXO;
306 break;
307
308 case ACL_MASK:
309 mask_obj = pa;
310 not_equiv = 1;
311 break;
312
313 default:
314 return -EIO;
315 }
316 }
317
318 if (mask_obj) {
319 mask_obj->e_perm &= (mode >> 3) | ~S_IRWXO;
320 mode &= (mask_obj->e_perm << 3) | ~S_IRWXG;
321 } else {
322 if (!group_obj)
323 return -EIO;
324 group_obj->e_perm &= (mode >> 3) | ~S_IRWXO;
325 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
326 }
327
328 *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
329 return not_equiv;
330}
331
332static int f2fs_acl_create(struct inode *dir, umode_t *mode,
333 struct posix_acl **default_acl, struct posix_acl **acl,
334 struct page *dpage)
335{
336 struct posix_acl *p;
337 int ret;
338
339 if (S_ISLNK(*mode) || !IS_POSIXACL(dir))
340 goto no_acl;
341
342 p = __f2fs_get_acl(dir, ACL_TYPE_DEFAULT, dpage);
343 if (IS_ERR(p)) {
344 if (p == ERR_PTR(-EOPNOTSUPP))
345 goto apply_umask;
346 return PTR_ERR(p);
347 }
348
349 if (!p)
350 goto apply_umask;
351
352 *acl = f2fs_acl_clone(p, GFP_NOFS);
353 if (!*acl)
354 return -ENOMEM;
355
356 ret = f2fs_acl_create_masq(*acl, mode);
357 if (ret < 0) {
358 posix_acl_release(*acl);
359 return -ENOMEM;
360 }
361
362 if (ret == 0) {
363 posix_acl_release(*acl);
364 *acl = NULL;
365 }
366
367 if (!S_ISDIR(*mode)) {
368 posix_acl_release(p);
369 *default_acl = NULL;
370 } else {
371 *default_acl = p;
372 }
373 return 0;
374
375apply_umask:
376 *mode &= ~current_umask();
377no_acl:
378 *default_acl = NULL;
379 *acl = NULL;
380 return 0;
381}
382
383int f2fs_init_acl(struct inode *inode, struct inode *dir, struct page *ipage,
384 struct page *dpage)
253{ 385{
254 struct posix_acl *default_acl, *acl; 386 struct posix_acl *default_acl = NULL, *acl = NULL;
255 int error = 0; 387 int error = 0;
256 388
257 error = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl); 389 error = f2fs_acl_create(dir, &inode->i_mode, &default_acl, &acl, dpage);
258 if (error) 390 if (error)
259 return error; 391 return error;
260 392