1 /* Extended attribute handling for AFS. We use xattrs to get and set metadata
2 * instead of providing pioctl().
4 * Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
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.
13 #include <linux/slab.h>
15 #include <linux/xattr.h>
18 static const char afs_xattr_list[] =
24 * Retrieve a list of the supported xattrs.
26 ssize_t afs_listxattr(struct dentry *dentry, char *buffer, size_t size)
29 return sizeof(afs_xattr_list);
30 if (size < sizeof(afs_xattr_list))
32 memcpy(buffer, afs_xattr_list, sizeof(afs_xattr_list));
33 return sizeof(afs_xattr_list);
37 * Get the name of the cell on which a file resides.
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)
44 struct afs_vnode *vnode = AFS_FS_I(inode);
45 struct afs_cell *cell = vnode->volume->cell;
48 namelen = cell->name_len;
53 memcpy(buffer, cell->name, size);
57 static const struct xattr_handler afs_xattr_afs_cell_handler = {
59 .get = afs_xattr_get_cell,
63 * Get the volume ID, vnode ID and vnode uniquifier of a file as a sequence of
64 * hex numbers separated by colons.
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)
71 struct afs_vnode *vnode = AFS_FS_I(inode);
72 char text[8 + 1 + 8 + 1 + 8 + 1];
75 len = sprintf(text, "%x:%x:%x",
76 vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique);
81 memcpy(buffer, text, len);
85 static const struct xattr_handler afs_xattr_afs_fid_handler = {
87 .get = afs_xattr_get_fid,
91 * Get the name of the volume on which a file resides.
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)
98 struct afs_vnode *vnode = AFS_FS_I(inode);
99 const char *volname = vnode->volume->name;
102 namelen = strlen(volname);
107 memcpy(buffer, volname, size);
111 static const struct xattr_handler afs_xattr_afs_volume_handler = {
112 .name = "afs.volume",
113 .get = afs_xattr_get_volume,
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,