~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/afs/xattr.c

Version: ~ [ linux-5.8-rc5 ] ~ [ linux-5.7.8 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.51 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.132 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.188 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.230 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.230 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* Extended attribute handling for AFS.  We use xattrs to get and set metadata
  2  * instead of providing pioctl().
  3  *
  4  * Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
  5  * Written by David Howells (dhowells@redhat.com)
  6  *
  7  * This program is free software; you can redistribute it and/or
  8  * modify it under the terms of the GNU General Public Licence
  9  * as published by the Free Software Foundation; either version
 10  * 2 of the Licence, or (at your option) any later version.
 11  */
 12 
 13 #include <linux/slab.h>
 14 #include <linux/fs.h>
 15 #include <linux/xattr.h>
 16 #include "internal.h"
 17 
 18 static const char afs_xattr_list[] =
 19         "afs.cell\0"
 20         "afs.fid\0"
 21         "afs.volume";
 22 
 23 /*
 24  * Retrieve a list of the supported xattrs.
 25  */
 26 ssize_t afs_listxattr(struct dentry *dentry, char *buffer, size_t size)
 27 {
 28         if (size == 0)
 29                 return sizeof(afs_xattr_list);
 30         if (size < sizeof(afs_xattr_list))
 31                 return -ERANGE;
 32         memcpy(buffer, afs_xattr_list, sizeof(afs_xattr_list));
 33         return sizeof(afs_xattr_list);
 34 }
 35 
 36 /*
 37  * Get the name of the cell on which a file resides.
 38  */
 39 static int afs_xattr_get_cell(const struct xattr_handler *handler,
 40                               struct dentry *dentry,
 41                               struct inode *inode, const char *name,
 42                               void *buffer, size_t size)
 43 {
 44         struct afs_vnode *vnode = AFS_FS_I(inode);
 45         struct afs_cell *cell = vnode->volume->cell;
 46         size_t namelen;
 47 
 48         namelen = cell->name_len;
 49         if (size == 0)
 50                 return namelen;
 51         if (namelen > size)
 52                 return -ERANGE;
 53         memcpy(buffer, cell->name, size);
 54         return namelen;
 55 }
 56 
 57 static const struct xattr_handler afs_xattr_afs_cell_handler = {
 58         .name   = "afs.cell",
 59         .get    = afs_xattr_get_cell,
 60 };
 61 
 62 /*
 63  * Get the volume ID, vnode ID and vnode uniquifier of a file as a sequence of
 64  * hex numbers separated by colons.
 65  */
 66 static int afs_xattr_get_fid(const struct xattr_handler *handler,
 67                              struct dentry *dentry,
 68                              struct inode *inode, const char *name,
 69                              void *buffer, size_t size)
 70 {
 71         struct afs_vnode *vnode = AFS_FS_I(inode);
 72         char text[8 + 1 + 8 + 1 + 8 + 1];
 73         size_t len;
 74 
 75         len = sprintf(text, "%x:%x:%x",
 76                       vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique);
 77         if (size == 0)
 78                 return len;
 79         if (len > size)
 80                 return -ERANGE;
 81         memcpy(buffer, text, len);
 82         return len;
 83 }
 84 
 85 static const struct xattr_handler afs_xattr_afs_fid_handler = {
 86         .name   = "afs.fid",
 87         .get    = afs_xattr_get_fid,
 88 };
 89 
 90 /*
 91  * Get the name of the volume on which a file resides.
 92  */
 93 static int afs_xattr_get_volume(const struct xattr_handler *handler,
 94                               struct dentry *dentry,
 95                               struct inode *inode, const char *name,
 96                               void *buffer, size_t size)
 97 {
 98         struct afs_vnode *vnode = AFS_FS_I(inode);
 99         const char *volname = vnode->volume->name;
100         size_t namelen;
101 
102         namelen = strlen(volname);
103         if (size == 0)
104                 return namelen;
105         if (namelen > size)
106                 return -ERANGE;
107         memcpy(buffer, volname, size);
108         return namelen;
109 }
110 
111 static const struct xattr_handler afs_xattr_afs_volume_handler = {
112         .name   = "afs.volume",
113         .get    = afs_xattr_get_volume,
114 };
115 
116 const struct xattr_handler *afs_xattr_handlers[] = {
117         &afs_xattr_afs_cell_handler,
118         &afs_xattr_afs_fid_handler,
119         &afs_xattr_afs_volume_handler,
120         NULL
121 };
122 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp