KaiGai Kohei | 652ecc2 | 2006-05-13 15:18:27 +0900 | [diff] [blame^] | 1 | /* |
| 2 | * JFFS2 -- Journalling Flash File System, Version 2. |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 3 | * |
KaiGai Kohei | 652ecc2 | 2006-05-13 15:18:27 +0900 | [diff] [blame^] | 4 | * Copyright (C) 2006 NEC Corporation |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 5 | * |
KaiGai Kohei | 652ecc2 | 2006-05-13 15:18:27 +0900 | [diff] [blame^] | 6 | * Created by KaiGai Kohei <kaigai@ak.jp.nec.com> |
| 7 | * |
| 8 | * For licensing information, see the file 'LICENCE' in this directory. |
| 9 | * |
| 10 | */ |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 11 | #include <linux/kernel.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/fs.h> |
| 14 | #include <linux/time.h> |
| 15 | #include <linux/crc32.h> |
| 16 | #include <linux/jffs2.h> |
| 17 | #include <linux/xattr.h> |
| 18 | #include <linux/posix_acl_xattr.h> |
| 19 | #include <linux/mtd/mtd.h> |
| 20 | #include "nodelist.h" |
| 21 | |
| 22 | static size_t jffs2_acl_size(int count) |
| 23 | { |
| 24 | if (count <= 4) { |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 25 | return sizeof(struct jffs2_acl_header) |
| 26 | + count * sizeof(struct jffs2_acl_entry_short); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 27 | } else { |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 28 | return sizeof(struct jffs2_acl_header) |
| 29 | + 4 * sizeof(struct jffs2_acl_entry_short) |
| 30 | + (count - 4) * sizeof(struct jffs2_acl_entry); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 31 | } |
| 32 | } |
| 33 | |
| 34 | static int jffs2_acl_count(size_t size) |
| 35 | { |
| 36 | size_t s; |
| 37 | |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 38 | size -= sizeof(struct jffs2_acl_header); |
| 39 | s = size - 4 * sizeof(struct jffs2_acl_entry_short); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 40 | if (s < 0) { |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 41 | if (size % sizeof(struct jffs2_acl_entry_short)) |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 42 | return -1; |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 43 | return size / sizeof(struct jffs2_acl_entry_short); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 44 | } else { |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 45 | if (s % sizeof(struct jffs2_acl_entry)) |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 46 | return -1; |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 47 | return s / sizeof(struct jffs2_acl_entry) + 4; |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | static struct posix_acl *jffs2_acl_from_medium(const void *value, size_t size) |
| 52 | { |
| 53 | const char *end = (char *)value + size; |
| 54 | struct posix_acl *acl; |
| 55 | uint32_t ver; |
| 56 | int i, count; |
| 57 | |
| 58 | if (!value) |
| 59 | return NULL; |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 60 | if (size < sizeof(struct jffs2_acl_header)) |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 61 | return ERR_PTR(-EINVAL); |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 62 | ver = je32_to_cpu(((struct jffs2_acl_header *)value)->a_version); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 63 | if (ver != JFFS2_ACL_VERSION) { |
| 64 | JFFS2_WARNING("Invalid ACL version. (=%u)\n", ver); |
| 65 | return ERR_PTR(-EINVAL); |
| 66 | } |
| 67 | |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 68 | value = (char *)value + sizeof(struct jffs2_acl_header); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 69 | count = jffs2_acl_count(size); |
| 70 | if (count < 0) |
| 71 | return ERR_PTR(-EINVAL); |
| 72 | if (count == 0) |
| 73 | return NULL; |
| 74 | |
| 75 | acl = posix_acl_alloc(count, GFP_KERNEL); |
| 76 | if (!acl) |
| 77 | return ERR_PTR(-ENOMEM); |
| 78 | |
| 79 | for (i=0; i < count; i++) { |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 80 | struct jffs2_acl_entry *entry = (struct jffs2_acl_entry *)value; |
| 81 | if ((char *)value + sizeof(struct jffs2_acl_entry_short) > end) |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 82 | goto fail; |
| 83 | acl->a_entries[i].e_tag = je16_to_cpu(entry->e_tag); |
| 84 | acl->a_entries[i].e_perm = je16_to_cpu(entry->e_perm); |
| 85 | switch (acl->a_entries[i].e_tag) { |
| 86 | case ACL_USER_OBJ: |
| 87 | case ACL_GROUP_OBJ: |
| 88 | case ACL_MASK: |
| 89 | case ACL_OTHER: |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 90 | value = (char *)value + sizeof(struct jffs2_acl_entry_short); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 91 | acl->a_entries[i].e_id = ACL_UNDEFINED_ID; |
| 92 | break; |
| 93 | |
| 94 | case ACL_USER: |
| 95 | case ACL_GROUP: |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 96 | value = (char *)value + sizeof(struct jffs2_acl_entry); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 97 | if ((char *)value > end) |
| 98 | goto fail; |
| 99 | acl->a_entries[i].e_id = je32_to_cpu(entry->e_id); |
| 100 | break; |
| 101 | |
| 102 | default: |
| 103 | goto fail; |
| 104 | } |
| 105 | } |
| 106 | if (value != end) |
| 107 | goto fail; |
| 108 | return acl; |
| 109 | fail: |
| 110 | posix_acl_release(acl); |
| 111 | return ERR_PTR(-EINVAL); |
| 112 | } |
| 113 | |
| 114 | static void *jffs2_acl_to_medium(const struct posix_acl *acl, size_t *size) |
| 115 | { |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 116 | struct jffs2_acl_header *jffs2_acl; |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 117 | char *e; |
| 118 | size_t i; |
| 119 | |
| 120 | *size = jffs2_acl_size(acl->a_count); |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 121 | jffs2_acl = kmalloc(sizeof(struct jffs2_acl_header) |
| 122 | + acl->a_count * sizeof(struct jffs2_acl_entry), |
| 123 | GFP_KERNEL); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 124 | if (!jffs2_acl) |
| 125 | return ERR_PTR(-ENOMEM); |
| 126 | jffs2_acl->a_version = cpu_to_je32(JFFS2_ACL_VERSION); |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 127 | e = (char *)jffs2_acl + sizeof(struct jffs2_acl_header); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 128 | for (i=0; i < acl->a_count; i++) { |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 129 | struct jffs2_acl_entry *entry = (struct jffs2_acl_entry *)e; |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 130 | entry->e_tag = cpu_to_je16(acl->a_entries[i].e_tag); |
| 131 | entry->e_perm = cpu_to_je16(acl->a_entries[i].e_perm); |
| 132 | switch(acl->a_entries[i].e_tag) { |
| 133 | case ACL_USER: |
| 134 | case ACL_GROUP: |
| 135 | entry->e_id = cpu_to_je32(acl->a_entries[i].e_id); |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 136 | e += sizeof(struct jffs2_acl_entry); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 137 | break; |
| 138 | |
| 139 | case ACL_USER_OBJ: |
| 140 | case ACL_GROUP_OBJ: |
| 141 | case ACL_MASK: |
| 142 | case ACL_OTHER: |
KaiGai Kohei | de1f72f | 2006-05-13 15:13:27 +0900 | [diff] [blame] | 143 | e += sizeof(struct jffs2_acl_entry_short); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 144 | break; |
| 145 | |
| 146 | default: |
| 147 | goto fail; |
| 148 | } |
| 149 | } |
| 150 | return (char *)jffs2_acl; |
| 151 | fail: |
| 152 | kfree(jffs2_acl); |
| 153 | return ERR_PTR(-EINVAL); |
| 154 | } |
| 155 | |
| 156 | static struct posix_acl *jffs2_iget_acl(struct inode *inode, struct posix_acl **i_acl) |
| 157 | { |
| 158 | struct posix_acl *acl = JFFS2_ACL_NOT_CACHED; |
| 159 | |
| 160 | spin_lock(&inode->i_lock); |
| 161 | if (*i_acl != JFFS2_ACL_NOT_CACHED) |
| 162 | acl = posix_acl_dup(*i_acl); |
| 163 | spin_unlock(&inode->i_lock); |
| 164 | return acl; |
| 165 | } |
| 166 | |
| 167 | static void jffs2_iset_acl(struct inode *inode, struct posix_acl **i_acl, struct posix_acl *acl) |
| 168 | { |
| 169 | spin_lock(&inode->i_lock); |
| 170 | if (*i_acl != JFFS2_ACL_NOT_CACHED) |
| 171 | posix_acl_release(*i_acl); |
| 172 | *i_acl = posix_acl_dup(acl); |
| 173 | spin_unlock(&inode->i_lock); |
| 174 | } |
| 175 | |
| 176 | static struct posix_acl *jffs2_get_acl(struct inode *inode, int type) |
| 177 | { |
| 178 | struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); |
| 179 | struct posix_acl *acl; |
| 180 | char *value = NULL; |
| 181 | int rc, xprefix; |
| 182 | |
| 183 | switch (type) { |
| 184 | case ACL_TYPE_ACCESS: |
| 185 | acl = jffs2_iget_acl(inode, &f->i_acl_access); |
| 186 | if (acl != JFFS2_ACL_NOT_CACHED) |
| 187 | return acl; |
| 188 | xprefix = JFFS2_XPREFIX_ACL_ACCESS; |
| 189 | break; |
| 190 | case ACL_TYPE_DEFAULT: |
| 191 | acl = jffs2_iget_acl(inode, &f->i_acl_default); |
| 192 | if (acl != JFFS2_ACL_NOT_CACHED) |
| 193 | return acl; |
| 194 | xprefix = JFFS2_XPREFIX_ACL_DEFAULT; |
| 195 | break; |
| 196 | default: |
| 197 | return ERR_PTR(-EINVAL); |
| 198 | } |
| 199 | rc = do_jffs2_getxattr(inode, xprefix, "", NULL, 0); |
| 200 | if (rc > 0) { |
| 201 | value = kmalloc(rc, GFP_KERNEL); |
| 202 | if (!value) |
| 203 | return ERR_PTR(-ENOMEM); |
| 204 | rc = do_jffs2_getxattr(inode, xprefix, "", value, rc); |
| 205 | } |
| 206 | if (rc > 0) { |
| 207 | acl = jffs2_acl_from_medium(value, rc); |
| 208 | } else if (rc == -ENODATA || rc == -ENOSYS) { |
| 209 | acl = NULL; |
| 210 | } else { |
| 211 | acl = ERR_PTR(rc); |
| 212 | } |
| 213 | if (value) |
| 214 | kfree(value); |
| 215 | if (!IS_ERR(acl)) { |
| 216 | switch (type) { |
| 217 | case ACL_TYPE_ACCESS: |
| 218 | jffs2_iset_acl(inode, &f->i_acl_access, acl); |
| 219 | break; |
| 220 | case ACL_TYPE_DEFAULT: |
| 221 | jffs2_iset_acl(inode, &f->i_acl_default, acl); |
| 222 | break; |
| 223 | } |
| 224 | } |
| 225 | return acl; |
| 226 | } |
| 227 | |
| 228 | static int jffs2_set_acl(struct inode *inode, int type, struct posix_acl *acl) |
| 229 | { |
| 230 | struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); |
| 231 | size_t size = 0; |
| 232 | char *value = NULL; |
| 233 | int rc, xprefix; |
| 234 | |
| 235 | if (S_ISLNK(inode->i_mode)) |
| 236 | return -EOPNOTSUPP; |
| 237 | |
| 238 | switch (type) { |
| 239 | case ACL_TYPE_ACCESS: |
| 240 | xprefix = JFFS2_XPREFIX_ACL_ACCESS; |
| 241 | if (acl) { |
| 242 | mode_t mode = inode->i_mode; |
| 243 | rc = posix_acl_equiv_mode(acl, &mode); |
| 244 | if (rc < 0) |
| 245 | return rc; |
| 246 | if (inode->i_mode != mode) { |
| 247 | inode->i_mode = mode; |
| 248 | jffs2_dirty_inode(inode); |
| 249 | } |
| 250 | if (rc == 0) |
| 251 | acl = NULL; |
| 252 | } |
| 253 | break; |
| 254 | case ACL_TYPE_DEFAULT: |
| 255 | xprefix = JFFS2_XPREFIX_ACL_DEFAULT; |
| 256 | if (!S_ISDIR(inode->i_mode)) |
| 257 | return acl ? -EACCES : 0; |
| 258 | break; |
| 259 | default: |
| 260 | return -EINVAL; |
| 261 | } |
| 262 | if (acl) { |
| 263 | value = jffs2_acl_to_medium(acl, &size); |
| 264 | if (IS_ERR(value)) |
| 265 | return PTR_ERR(value); |
| 266 | } |
| 267 | |
| 268 | rc = do_jffs2_setxattr(inode, xprefix, "", value, size, 0); |
| 269 | if (value) |
| 270 | kfree(value); |
| 271 | if (!rc) { |
| 272 | switch(type) { |
| 273 | case ACL_TYPE_ACCESS: |
| 274 | jffs2_iset_acl(inode, &f->i_acl_access, acl); |
| 275 | break; |
| 276 | case ACL_TYPE_DEFAULT: |
| 277 | jffs2_iset_acl(inode, &f->i_acl_default, acl); |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | return rc; |
| 282 | } |
| 283 | |
| 284 | static int jffs2_check_acl(struct inode *inode, int mask) |
| 285 | { |
| 286 | struct posix_acl *acl; |
| 287 | int rc; |
| 288 | |
| 289 | acl = jffs2_get_acl(inode, ACL_TYPE_ACCESS); |
| 290 | if (IS_ERR(acl)) |
| 291 | return PTR_ERR(acl); |
| 292 | if (acl) { |
| 293 | rc = posix_acl_permission(inode, acl, mask); |
| 294 | posix_acl_release(acl); |
| 295 | return rc; |
| 296 | } |
| 297 | return -EAGAIN; |
| 298 | } |
| 299 | |
| 300 | int jffs2_permission(struct inode *inode, int mask, struct nameidata *nd) |
| 301 | { |
| 302 | return generic_permission(inode, mask, jffs2_check_acl); |
| 303 | } |
| 304 | |
| 305 | int jffs2_init_acl(struct inode *inode, struct inode *dir) |
| 306 | { |
| 307 | struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); |
| 308 | struct posix_acl *acl = NULL, *clone; |
| 309 | mode_t mode; |
| 310 | int rc = 0; |
| 311 | |
| 312 | f->i_acl_access = JFFS2_ACL_NOT_CACHED; |
| 313 | f->i_acl_default = JFFS2_ACL_NOT_CACHED; |
| 314 | if (!S_ISLNK(inode->i_mode)) { |
| 315 | acl = jffs2_get_acl(dir, ACL_TYPE_DEFAULT); |
| 316 | if (IS_ERR(acl)) |
| 317 | return PTR_ERR(acl); |
| 318 | if (!acl) |
| 319 | inode->i_mode &= ~current->fs->umask; |
| 320 | } |
| 321 | if (acl) { |
| 322 | if (S_ISDIR(inode->i_mode)) { |
| 323 | rc = jffs2_set_acl(inode, ACL_TYPE_DEFAULT, acl); |
| 324 | if (rc) |
| 325 | goto cleanup; |
| 326 | } |
| 327 | clone = posix_acl_clone(acl, GFP_KERNEL); |
| 328 | rc = -ENOMEM; |
| 329 | if (!clone) |
| 330 | goto cleanup; |
| 331 | mode = inode->i_mode; |
| 332 | rc = posix_acl_create_masq(clone, &mode); |
| 333 | if (rc >= 0) { |
| 334 | inode->i_mode = mode; |
| 335 | if (rc > 0) |
| 336 | rc = jffs2_set_acl(inode, ACL_TYPE_ACCESS, clone); |
| 337 | } |
| 338 | posix_acl_release(clone); |
| 339 | } |
| 340 | cleanup: |
| 341 | posix_acl_release(acl); |
| 342 | return rc; |
| 343 | } |
| 344 | |
| 345 | void jffs2_clear_acl(struct inode *inode) |
| 346 | { |
| 347 | struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); |
| 348 | |
| 349 | if (f->i_acl_access && f->i_acl_access != JFFS2_ACL_NOT_CACHED) { |
| 350 | posix_acl_release(f->i_acl_access); |
| 351 | f->i_acl_access = JFFS2_ACL_NOT_CACHED; |
| 352 | } |
| 353 | if (f->i_acl_default && f->i_acl_default != JFFS2_ACL_NOT_CACHED) { |
| 354 | posix_acl_release(f->i_acl_default); |
| 355 | f->i_acl_default = JFFS2_ACL_NOT_CACHED; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | int jffs2_acl_chmod(struct inode *inode) |
| 360 | { |
| 361 | struct posix_acl *acl, *clone; |
| 362 | int rc; |
| 363 | |
| 364 | if (S_ISLNK(inode->i_mode)) |
| 365 | return -EOPNOTSUPP; |
| 366 | acl = jffs2_get_acl(inode, ACL_TYPE_ACCESS); |
| 367 | if (IS_ERR(acl) || !acl) |
| 368 | return PTR_ERR(acl); |
| 369 | clone = posix_acl_clone(acl, GFP_KERNEL); |
| 370 | posix_acl_release(acl); |
| 371 | if (!clone) |
| 372 | return -ENOMEM; |
| 373 | rc = posix_acl_chmod_masq(clone, inode->i_mode); |
| 374 | if (!rc) |
| 375 | rc = jffs2_set_acl(inode, ACL_TYPE_ACCESS, clone); |
| 376 | posix_acl_release(clone); |
| 377 | return rc; |
| 378 | } |
| 379 | |
| 380 | static size_t jffs2_acl_access_listxattr(struct inode *inode, char *list, size_t list_size, |
| 381 | const char *name, size_t name_len) |
| 382 | { |
| 383 | const int retlen = sizeof(POSIX_ACL_XATTR_ACCESS); |
| 384 | |
| 385 | if (list && retlen <= list_size) |
| 386 | strcpy(list, POSIX_ACL_XATTR_ACCESS); |
| 387 | return retlen; |
| 388 | } |
| 389 | |
| 390 | static size_t jffs2_acl_default_listxattr(struct inode *inode, char *list, size_t list_size, |
| 391 | const char *name, size_t name_len) |
| 392 | { |
| 393 | const int retlen = sizeof(POSIX_ACL_XATTR_DEFAULT); |
| 394 | |
| 395 | if (list && retlen <= list_size) |
| 396 | strcpy(list, POSIX_ACL_XATTR_DEFAULT); |
| 397 | return retlen; |
| 398 | } |
| 399 | |
| 400 | static int jffs2_acl_getxattr(struct inode *inode, int type, void *buffer, size_t size) |
| 401 | { |
| 402 | struct posix_acl *acl; |
| 403 | int rc; |
| 404 | |
| 405 | acl = jffs2_get_acl(inode, type); |
| 406 | if (IS_ERR(acl)) |
| 407 | return PTR_ERR(acl); |
| 408 | if (!acl) |
| 409 | return -ENODATA; |
| 410 | rc = posix_acl_to_xattr(acl, buffer, size); |
| 411 | posix_acl_release(acl); |
| 412 | |
| 413 | return rc; |
| 414 | } |
| 415 | |
| 416 | static int jffs2_acl_access_getxattr(struct inode *inode, const char *name, void *buffer, size_t size) |
| 417 | { |
| 418 | if (name[0] != '\0') |
| 419 | return -EINVAL; |
| 420 | return jffs2_acl_getxattr(inode, ACL_TYPE_ACCESS, buffer, size); |
| 421 | } |
| 422 | |
| 423 | static int jffs2_acl_default_getxattr(struct inode *inode, const char *name, void *buffer, size_t size) |
| 424 | { |
| 425 | if (name[0] != '\0') |
| 426 | return -EINVAL; |
| 427 | return jffs2_acl_getxattr(inode, ACL_TYPE_DEFAULT, buffer, size); |
| 428 | } |
| 429 | |
| 430 | static int jffs2_acl_setxattr(struct inode *inode, int type, const void *value, size_t size) |
| 431 | { |
| 432 | struct posix_acl *acl; |
| 433 | int rc; |
| 434 | |
| 435 | if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER)) |
| 436 | return -EPERM; |
| 437 | |
| 438 | if (value) { |
| 439 | acl = posix_acl_from_xattr(value, size); |
| 440 | if (IS_ERR(acl)) |
| 441 | return PTR_ERR(acl); |
| 442 | if (acl) { |
| 443 | rc = posix_acl_valid(acl); |
| 444 | if (rc) |
| 445 | goto out; |
| 446 | } |
| 447 | } else { |
| 448 | acl = NULL; |
| 449 | } |
| 450 | rc = jffs2_set_acl(inode, type, acl); |
| 451 | out: |
| 452 | posix_acl_release(acl); |
| 453 | return rc; |
| 454 | } |
| 455 | |
| 456 | static int jffs2_acl_access_setxattr(struct inode *inode, const char *name, |
| 457 | const void *buffer, size_t size, int flags) |
| 458 | { |
| 459 | if (name[0] != '\0') |
| 460 | return -EINVAL; |
| 461 | return jffs2_acl_setxattr(inode, ACL_TYPE_ACCESS, buffer, size); |
| 462 | } |
| 463 | |
| 464 | static int jffs2_acl_default_setxattr(struct inode *inode, const char *name, |
| 465 | const void *buffer, size_t size, int flags) |
| 466 | { |
| 467 | if (name[0] != '\0') |
| 468 | return -EINVAL; |
| 469 | return jffs2_acl_setxattr(inode, ACL_TYPE_DEFAULT, buffer, size); |
| 470 | } |
| 471 | |
| 472 | struct xattr_handler jffs2_acl_access_xattr_handler = { |
| 473 | .prefix = POSIX_ACL_XATTR_ACCESS, |
| 474 | .list = jffs2_acl_access_listxattr, |
| 475 | .get = jffs2_acl_access_getxattr, |
| 476 | .set = jffs2_acl_access_setxattr, |
| 477 | }; |
| 478 | |
| 479 | struct xattr_handler jffs2_acl_default_xattr_handler = { |
| 480 | .prefix = POSIX_ACL_XATTR_DEFAULT, |
| 481 | .list = jffs2_acl_default_listxattr, |
| 482 | .get = jffs2_acl_default_getxattr, |
| 483 | .set = jffs2_acl_default_setxattr, |
| 484 | }; |