aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_attr.c
diff options
context:
space:
mode:
authorLachlan McIlroy <lachlan@redback.melbourne.sgi.com>2008-06-22 23:23:01 -0400
committerNiv Sardi <xaiki@debian.org>2008-07-28 02:58:49 -0400
commit0ec585163ac81e329bde25fb6311a043a1c63952 (patch)
tree304193ab41f88e5d82e51053bbd7d21fbfb7a83f /fs/xfs/xfs_attr.c
parentd532506cd8b59543b376e155508f88a03a81dad1 (diff)
[XFS] Use the generic xattr methods.
Use the generic set, get and removexattr methods and supply the s_xattr array with fine-grained handlers. All XFS/Linux highlevel attr handling is rewritten from scratch and placed into fs/xfs/linux-2.6/xfs_xattr.c so that it's separated from the generic low-level code. SGI-PV: 982343 SGI-Modid: xfs-linux-melb:xfs-kern:31234a Signed-off-by: Christoph Hellwig <hch@infradead.org> Signed-off-by: Tim Shimmin <tes@sgi.com> Signed-off-by: Lachlan McIlroy <lachlan@sgi.com>
Diffstat (limited to 'fs/xfs/xfs_attr.c')
-rw-r--r--fs/xfs/xfs_attr.c272
1 files changed, 0 insertions, 272 deletions
diff --git a/fs/xfs/xfs_attr.c b/fs/xfs/xfs_attr.c
index 557dad611de0..9d91af4929b1 100644
--- a/fs/xfs/xfs_attr.c
+++ b/fs/xfs/xfs_attr.c
@@ -57,11 +57,6 @@
57 * Provide the external interfaces to manage attribute lists. 57 * Provide the external interfaces to manage attribute lists.
58 */ 58 */
59 59
60#define ATTR_SYSCOUNT 2
61static struct attrnames posix_acl_access;
62static struct attrnames posix_acl_default;
63static struct attrnames *attr_system_names[ATTR_SYSCOUNT];
64
65/*======================================================================== 60/*========================================================================
66 * Function prototypes for the kernel. 61 * Function prototypes for the kernel.
67 *========================================================================*/ 62 *========================================================================*/
@@ -2378,270 +2373,3 @@ xfs_attr_trace_enter(int type, char *where,
2378 (void *)a13, (void *)a14, (void *)a15); 2373 (void *)a13, (void *)a14, (void *)a15);
2379} 2374}
2380#endif /* XFS_ATTR_TRACE */ 2375#endif /* XFS_ATTR_TRACE */
2381
2382
2383/*========================================================================
2384 * System (pseudo) namespace attribute interface routines.
2385 *========================================================================*/
2386
2387STATIC int
2388posix_acl_access_set(
2389 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2390{
2391 return xfs_acl_vset(vp, data, size, _ACL_TYPE_ACCESS);
2392}
2393
2394STATIC int
2395posix_acl_access_remove(
2396 bhv_vnode_t *vp, char *name, int xflags)
2397{
2398 return xfs_acl_vremove(vp, _ACL_TYPE_ACCESS);
2399}
2400
2401STATIC int
2402posix_acl_access_get(
2403 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2404{
2405 return xfs_acl_vget(vp, data, size, _ACL_TYPE_ACCESS);
2406}
2407
2408STATIC int
2409posix_acl_access_exists(
2410 bhv_vnode_t *vp)
2411{
2412 return xfs_acl_vhasacl_access(vp);
2413}
2414
2415STATIC int
2416posix_acl_default_set(
2417 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2418{
2419 return xfs_acl_vset(vp, data, size, _ACL_TYPE_DEFAULT);
2420}
2421
2422STATIC int
2423posix_acl_default_get(
2424 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2425{
2426 return xfs_acl_vget(vp, data, size, _ACL_TYPE_DEFAULT);
2427}
2428
2429STATIC int
2430posix_acl_default_remove(
2431 bhv_vnode_t *vp, char *name, int xflags)
2432{
2433 return xfs_acl_vremove(vp, _ACL_TYPE_DEFAULT);
2434}
2435
2436STATIC int
2437posix_acl_default_exists(
2438 bhv_vnode_t *vp)
2439{
2440 return xfs_acl_vhasacl_default(vp);
2441}
2442
2443static struct attrnames posix_acl_access = {
2444 .attr_name = "posix_acl_access",
2445 .attr_namelen = sizeof("posix_acl_access") - 1,
2446 .attr_get = posix_acl_access_get,
2447 .attr_set = posix_acl_access_set,
2448 .attr_remove = posix_acl_access_remove,
2449 .attr_exists = posix_acl_access_exists,
2450};
2451
2452static struct attrnames posix_acl_default = {
2453 .attr_name = "posix_acl_default",
2454 .attr_namelen = sizeof("posix_acl_default") - 1,
2455 .attr_get = posix_acl_default_get,
2456 .attr_set = posix_acl_default_set,
2457 .attr_remove = posix_acl_default_remove,
2458 .attr_exists = posix_acl_default_exists,
2459};
2460
2461static struct attrnames *attr_system_names[] =
2462 { &posix_acl_access, &posix_acl_default };
2463
2464
2465/*========================================================================
2466 * Namespace-prefix-style attribute name interface routines.
2467 *========================================================================*/
2468
2469STATIC int
2470attr_generic_set(
2471 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2472{
2473 return -xfs_attr_set(xfs_vtoi(vp), name, data, size, xflags);
2474}
2475
2476STATIC int
2477attr_generic_get(
2478 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2479{
2480 int error, asize = size;
2481
2482 error = xfs_attr_get(xfs_vtoi(vp), name, data, &asize, xflags);
2483 if (!error)
2484 return asize;
2485 return -error;
2486}
2487
2488STATIC int
2489attr_generic_remove(
2490 bhv_vnode_t *vp, char *name, int xflags)
2491{
2492 return -xfs_attr_remove(xfs_vtoi(vp), name, xflags);
2493}
2494
2495STATIC int
2496attr_generic_listadd(
2497 attrnames_t *prefix,
2498 attrnames_t *namesp,
2499 void *data,
2500 size_t size,
2501 ssize_t *result)
2502{
2503 char *p = data + *result;
2504
2505 *result += prefix->attr_namelen;
2506 *result += namesp->attr_namelen + 1;
2507 if (!size)
2508 return 0;
2509 if (*result > size)
2510 return -ERANGE;
2511 strcpy(p, prefix->attr_name);
2512 p += prefix->attr_namelen;
2513 strcpy(p, namesp->attr_name);
2514 p += namesp->attr_namelen + 1;
2515 return 0;
2516}
2517
2518STATIC int
2519attr_system_list(
2520 bhv_vnode_t *vp,
2521 void *data,
2522 size_t size,
2523 ssize_t *result)
2524{
2525 attrnames_t *namesp;
2526 int i, error = 0;
2527
2528 for (i = 0; i < ATTR_SYSCOUNT; i++) {
2529 namesp = attr_system_names[i];
2530 if (!namesp->attr_exists || !namesp->attr_exists(vp))
2531 continue;
2532 error = attr_generic_listadd(&attr_system, namesp,
2533 data, size, result);
2534 if (error)
2535 break;
2536 }
2537 return error;
2538}
2539
2540int
2541attr_generic_list(
2542 bhv_vnode_t *vp, void *data, size_t size, int xflags, ssize_t *result)
2543{
2544 attrlist_cursor_kern_t cursor = { 0 };
2545 int error;
2546
2547 error = xfs_attr_list(xfs_vtoi(vp), data, size, xflags, &cursor);
2548 if (error > 0)
2549 return -error;
2550 *result = -error;
2551 return attr_system_list(vp, data, size, result);
2552}
2553
2554attrnames_t *
2555attr_lookup_namespace(
2556 char *name,
2557 struct attrnames **names,
2558 int nnames)
2559{
2560 int i;
2561
2562 for (i = 0; i < nnames; i++)
2563 if (!strncmp(name, names[i]->attr_name, names[i]->attr_namelen))
2564 return names[i];
2565 return NULL;
2566}
2567
2568STATIC int
2569attr_system_set(
2570 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2571{
2572 attrnames_t *namesp;
2573 int error;
2574
2575 if (xflags & ATTR_CREATE)
2576 return -EINVAL;
2577
2578 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2579 if (!namesp)
2580 return -EOPNOTSUPP;
2581 error = namesp->attr_set(vp, name, data, size, xflags);
2582 if (!error)
2583 error = vn_revalidate(vp);
2584 return error;
2585}
2586
2587STATIC int
2588attr_system_get(
2589 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2590{
2591 attrnames_t *namesp;
2592
2593 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2594 if (!namesp)
2595 return -EOPNOTSUPP;
2596 return namesp->attr_get(vp, name, data, size, xflags);
2597}
2598
2599STATIC int
2600attr_system_remove(
2601 bhv_vnode_t *vp, char *name, int xflags)
2602{
2603 attrnames_t *namesp;
2604
2605 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2606 if (!namesp)
2607 return -EOPNOTSUPP;
2608 return namesp->attr_remove(vp, name, xflags);
2609}
2610
2611struct attrnames attr_system = {
2612 .attr_name = "system.",
2613 .attr_namelen = sizeof("system.") - 1,
2614 .attr_flag = ATTR_SYSTEM,
2615 .attr_get = attr_system_get,
2616 .attr_set = attr_system_set,
2617 .attr_remove = attr_system_remove,
2618};
2619
2620struct attrnames attr_trusted = {
2621 .attr_name = "trusted.",
2622 .attr_namelen = sizeof("trusted.") - 1,
2623 .attr_flag = ATTR_ROOT,
2624 .attr_get = attr_generic_get,
2625 .attr_set = attr_generic_set,
2626 .attr_remove = attr_generic_remove,
2627};
2628
2629struct attrnames attr_secure = {
2630 .attr_name = "security.",
2631 .attr_namelen = sizeof("security.") - 1,
2632 .attr_flag = ATTR_SECURE,
2633 .attr_get = attr_generic_get,
2634 .attr_set = attr_generic_set,
2635 .attr_remove = attr_generic_remove,
2636};
2637
2638struct attrnames attr_user = {
2639 .attr_name = "user.",
2640 .attr_namelen = sizeof("user.") - 1,
2641 .attr_get = attr_generic_get,
2642 .attr_set = attr_generic_set,
2643 .attr_remove = attr_generic_remove,
2644};
2645
2646struct attrnames *attr_namespaces[] =
2647 { &attr_system, &attr_trusted, &attr_secure, &attr_user };