2 * Copyright IBM Corporation, 2010
3 * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2.1 of the GNU Lesser General Public License
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 #include <linux/module.h>
17 #include <linux/sched.h>
18 #include <net/9p/9p.h>
19 #include <net/9p/client.h>
24 ssize_t v9fs_fid_xattr_get(struct p9_fid *fid, const char *name,
25 void *buffer, size_t buffer_size)
28 int msize, read_count;
29 u64 offset = 0, attr_size;
30 struct p9_fid *attr_fid;
32 attr_fid = p9_client_xattrwalk(fid, name, &attr_size);
33 if (IS_ERR(attr_fid)) {
34 retval = PTR_ERR(attr_fid);
35 P9_DPRINTK(P9_DEBUG_VFS,
36 "p9_client_attrwalk failed %zd\n", retval);
41 /* request to get the attr_size */
45 if (attr_size > buffer_size) {
49 msize = attr_fid->clnt->msize;
51 if (attr_size > (msize - P9_IOHDRSZ))
52 read_count = msize - P9_IOHDRSZ;
54 read_count = attr_size;
55 read_count = p9_client_read(attr_fid, ((char *)buffer)+offset,
56 NULL, offset, read_count);
58 /* error in xattr read */
63 attr_size -= read_count;
65 /* Total read xattr bytes */
69 p9_client_clunk(attr_fid);
78 * Copy an extended attribute into the buffer
79 * provided, or compute the buffer size required.
80 * Buffer is NULL to compute the size of the buffer required.
82 * Returns a negative error number on failure, or the number of bytes
83 * used / required on success.
85 ssize_t v9fs_xattr_get(struct dentry *dentry, const char *name,
86 void *buffer, size_t buffer_size)
90 P9_DPRINTK(P9_DEBUG_VFS, "%s: name = %s value_len = %zu\n",
91 __func__, name, buffer_size);
92 fid = v9fs_fid_lookup(dentry);
96 return v9fs_fid_xattr_get(fid, name, buffer, buffer_size);
102 * Create, replace or remove an extended attribute for this inode. Buffer
103 * is NULL to remove an existing extended attribute, and non-NULL to
104 * either replace an existing extended attribute, or create a new extended
105 * attribute. The flags XATTR_REPLACE and XATTR_CREATE
106 * specify that an extended attribute must exist and must not exist
107 * previous to the call, respectively.
109 * Returns 0, or a negative error number on failure.
111 int v9fs_xattr_set(struct dentry *dentry, const char *name,
112 const void *value, size_t value_len, int flags)
115 int retval, msize, write_count;
116 struct p9_fid *fid = NULL;
118 P9_DPRINTK(P9_DEBUG_VFS, "%s: name = %s value_len = %zu flags = %d\n",
119 __func__, name, value_len, flags);
121 fid = v9fs_fid_clone(dentry);
123 retval = PTR_ERR(fid);
128 * On success fid points to xattr
130 retval = p9_client_xattrcreate(fid, name, value_len, flags);
132 P9_DPRINTK(P9_DEBUG_VFS,
133 "p9_client_xattrcreate failed %d\n", retval);
136 msize = fid->clnt->msize;;
138 if (value_len > (msize - P9_IOHDRSZ))
139 write_count = msize - P9_IOHDRSZ;
141 write_count = value_len;
142 write_count = p9_client_write(fid, ((char *)value)+offset,
143 NULL, offset, write_count);
144 if (write_count < 0) {
145 /* error in xattr write */
146 retval = write_count;
149 offset += write_count;
150 value_len -= write_count;
152 /* Total read xattr bytes */
156 retval = p9_client_clunk(fid);
160 ssize_t v9fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
162 return v9fs_xattr_get(dentry, NULL, buffer, buffer_size);
165 const struct xattr_handler *v9fs_xattr_handlers[] = {
166 &v9fs_xattr_user_handler,
167 #ifdef CONFIG_9P_FS_POSIX_ACL
168 &v9fs_xattr_acl_access_handler,
169 &v9fs_xattr_acl_default_handler,