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.
5 * Written by David Howells (dhowells@redhat.com)
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[] =
25 * Retrieve a list of the supported xattrs.
27 ssize_t afs_listxattr(struct dentry *dentry, char *buffer, size_t size)
30 return sizeof(afs_xattr_list);
31 if (size < sizeof(afs_xattr_list))
33 memcpy(buffer, afs_xattr_list, sizeof(afs_xattr_list));
34 return sizeof(afs_xattr_list);
40 static int afs_xattr_get_acl(const struct xattr_handler *handler,
41 struct dentry *dentry,
42 struct inode *inode, const char *name,
43 void *buffer, size_t size)
45 struct afs_fs_cursor fc;
46 struct afs_vnode *vnode = AFS_FS_I(inode);
47 struct afs_acl *acl = NULL;
51 key = afs_request_key(vnode->volume->cell);
56 if (afs_begin_vnode_operation(&fc, vnode, key)) {
57 while (afs_select_fileserver(&fc)) {
58 fc.cb_break = afs_calc_vnode_cb_break(vnode);
59 acl = afs_fs_fetch_acl(&fc);
62 afs_check_for_remote_deletion(&fc, fc.vnode);
63 afs_vnode_commit_status(&fc, vnode, fc.cb_break);
64 ret = afs_end_vnode_operation(&fc);
73 memcpy(buffer, acl->data, acl->size);
83 static const struct xattr_handler afs_xattr_afs_acl_handler = {
85 .get = afs_xattr_get_acl,
89 * Get the name of the cell on which a file resides.
91 static int afs_xattr_get_cell(const struct xattr_handler *handler,
92 struct dentry *dentry,
93 struct inode *inode, const char *name,
94 void *buffer, size_t size)
96 struct afs_vnode *vnode = AFS_FS_I(inode);
97 struct afs_cell *cell = vnode->volume->cell;
100 namelen = cell->name_len;
105 memcpy(buffer, cell->name, namelen);
109 static const struct xattr_handler afs_xattr_afs_cell_handler = {
111 .get = afs_xattr_get_cell,
115 * Get the volume ID, vnode ID and vnode uniquifier of a file as a sequence of
116 * hex numbers separated by colons.
118 static int afs_xattr_get_fid(const struct xattr_handler *handler,
119 struct dentry *dentry,
120 struct inode *inode, const char *name,
121 void *buffer, size_t size)
123 struct afs_vnode *vnode = AFS_FS_I(inode);
124 char text[16 + 1 + 24 + 1 + 8 + 1];
127 /* The volume ID is 64-bit, the vnode ID is 96-bit and the
128 * uniquifier is 32-bit.
130 len = sprintf(text, "%llx:", vnode->fid.vid);
131 if (vnode->fid.vnode_hi)
132 len += sprintf(text + len, "%x%016llx",
133 vnode->fid.vnode_hi, vnode->fid.vnode);
135 len += sprintf(text + len, "%llx", vnode->fid.vnode);
136 len += sprintf(text + len, ":%x", vnode->fid.unique);
142 memcpy(buffer, text, len);
146 static const struct xattr_handler afs_xattr_afs_fid_handler = {
148 .get = afs_xattr_get_fid,
152 * Get the name of the volume on which a file resides.
154 static int afs_xattr_get_volume(const struct xattr_handler *handler,
155 struct dentry *dentry,
156 struct inode *inode, const char *name,
157 void *buffer, size_t size)
159 struct afs_vnode *vnode = AFS_FS_I(inode);
160 const char *volname = vnode->volume->name;
163 namelen = strlen(volname);
168 memcpy(buffer, volname, namelen);
172 static const struct xattr_handler afs_xattr_afs_volume_handler = {
173 .name = "afs.volume",
174 .get = afs_xattr_get_volume,
177 const struct xattr_handler *afs_xattr_handlers[] = {
178 &afs_xattr_afs_acl_handler,
179 &afs_xattr_afs_cell_handler,
180 &afs_xattr_afs_fid_handler,
181 &afs_xattr_afs_volume_handler,