acl.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  4. *
  5. * This copyrighted material is made available to anyone wishing to use,
  6. * modify, copy, or redistribute it subject to the terms and conditions
  7. * of the GNU General Public License version 2.
  8. */
  9. #include <linux/sched.h>
  10. #include <linux/slab.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/completion.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/xattr.h>
  15. #include <linux/posix_acl.h>
  16. #include <linux/posix_acl_xattr.h>
  17. #include <linux/gfs2_ondisk.h>
  18. #include "gfs2.h"
  19. #include "incore.h"
  20. #include "acl.h"
  21. #include "xattr.h"
  22. #include "glock.h"
  23. #include "inode.h"
  24. #include "meta_io.h"
  25. #include "trans.h"
  26. #include "util.h"
  27. static const char *gfs2_acl_name(int type)
  28. {
  29. switch (type) {
  30. case ACL_TYPE_ACCESS:
  31. return GFS2_POSIX_ACL_ACCESS;
  32. case ACL_TYPE_DEFAULT:
  33. return GFS2_POSIX_ACL_DEFAULT;
  34. }
  35. return NULL;
  36. }
  37. struct posix_acl *gfs2_get_acl(struct inode *inode, int type)
  38. {
  39. struct gfs2_inode *ip = GFS2_I(inode);
  40. struct posix_acl *acl;
  41. const char *name;
  42. char *data;
  43. int len;
  44. if (!ip->i_eattr)
  45. return NULL;
  46. name = gfs2_acl_name(type);
  47. if (name == NULL)
  48. return ERR_PTR(-EINVAL);
  49. len = gfs2_xattr_acl_get(ip, name, &data);
  50. if (len < 0)
  51. return ERR_PTR(len);
  52. if (len == 0)
  53. return NULL;
  54. acl = posix_acl_from_xattr(&init_user_ns, data, len);
  55. kfree(data);
  56. return acl;
  57. }
  58. int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
  59. {
  60. int error;
  61. int len;
  62. char *data;
  63. const char *name = gfs2_acl_name(type);
  64. BUG_ON(name == NULL);
  65. if (acl && acl->a_count > GFS2_ACL_MAX_ENTRIES(GFS2_SB(inode)))
  66. return -E2BIG;
  67. if (type == ACL_TYPE_ACCESS) {
  68. umode_t mode = inode->i_mode;
  69. error = posix_acl_update_mode(inode, &inode->i_mode, &acl);
  70. if (error)
  71. return error;
  72. if (mode != inode->i_mode)
  73. mark_inode_dirty(inode);
  74. }
  75. if (acl) {
  76. len = posix_acl_to_xattr(&init_user_ns, acl, NULL, 0);
  77. if (len == 0)
  78. return 0;
  79. data = kmalloc(len, GFP_NOFS);
  80. if (data == NULL)
  81. return -ENOMEM;
  82. error = posix_acl_to_xattr(&init_user_ns, acl, data, len);
  83. if (error < 0)
  84. goto out;
  85. } else {
  86. data = NULL;
  87. len = 0;
  88. }
  89. error = __gfs2_xattr_set(inode, name, data, len, 0, GFS2_EATYPE_SYS);
  90. if (error)
  91. goto out;
  92. set_cached_acl(inode, type, acl);
  93. out:
  94. kfree(data);
  95. return error;
  96. }