Skip to content

Commit 0ddaf72

Browse files
Andreas GruenbacherAl Viro
Andreas Gruenbacher
authored and
Al Viro
committed
squashfs: xattr simplifications
Now that the xattr handler is passed to the xattr handler operations, we have access to the attribute name prefix, so simplify the squashfs xattr handlers a bit. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Cc: Phillip Lougher <phillip@squashfs.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent e409de9 commit 0ddaf72

File tree

1 file changed

+31
-59
lines changed

1 file changed

+31
-59
lines changed

fs/squashfs/xattr.c

Lines changed: 31 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -212,96 +212,68 @@ static int squashfs_xattr_get(struct inode *inode, int name_index,
212212
}
213213

214214

215-
/*
216-
* User namespace support
217-
*/
218-
static size_t squashfs_user_list(const struct xattr_handler *handler,
219-
struct dentry *d, char *list, size_t list_size,
220-
const char *name, size_t name_len)
215+
static size_t squashfs_xattr_handler_list(const struct xattr_handler *handler,
216+
struct dentry *d, char *list,
217+
size_t list_size, const char *name,
218+
size_t name_len)
221219
{
222-
if (list && XATTR_USER_PREFIX_LEN <= list_size)
223-
memcpy(list, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
224-
return XATTR_USER_PREFIX_LEN;
220+
int len = strlen(handler->prefix);
221+
222+
if (list && len <= list_size)
223+
memcpy(list, handler->prefix, len);
224+
return len;
225225
}
226226

227-
static int squashfs_user_get(const struct xattr_handler *handler,
228-
struct dentry *d, const char *name, void *buffer,
229-
size_t size)
227+
static int squashfs_xattr_handler_get(const struct xattr_handler *handler,
228+
struct dentry *d, const char *name,
229+
void *buffer, size_t size)
230230
{
231231
if (name[0] == '\0')
232232
return -EINVAL;
233233

234-
return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_USER, name,
234+
return squashfs_xattr_get(d_inode(d), handler->flags, name,
235235
buffer, size);
236236
}
237237

238+
/*
239+
* User namespace support
240+
*/
238241
static const struct xattr_handler squashfs_xattr_user_handler = {
239242
.prefix = XATTR_USER_PREFIX,
240-
.list = squashfs_user_list,
241-
.get = squashfs_user_get
243+
.flags = SQUASHFS_XATTR_USER,
244+
.list = squashfs_xattr_handler_list,
245+
.get = squashfs_xattr_handler_get
242246
};
243247

244248
/*
245249
* Trusted namespace support
246250
*/
247-
static size_t squashfs_trusted_list(const struct xattr_handler *handler,
248-
struct dentry *d, char *list,
249-
size_t list_size, const char *name,
250-
size_t name_len)
251+
static size_t squashfs_trusted_xattr_handler_list(const struct xattr_handler *handler,
252+
struct dentry *d, char *list,
253+
size_t list_size, const char *name,
254+
size_t name_len)
251255
{
252256
if (!capable(CAP_SYS_ADMIN))
253257
return 0;
254-
255-
if (list && XATTR_TRUSTED_PREFIX_LEN <= list_size)
256-
memcpy(list, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN);
257-
return XATTR_TRUSTED_PREFIX_LEN;
258-
}
259-
260-
static int squashfs_trusted_get(const struct xattr_handler *handler,
261-
struct dentry *d, const char *name,
262-
void *buffer, size_t size)
263-
{
264-
if (name[0] == '\0')
265-
return -EINVAL;
266-
267-
return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_TRUSTED, name,
268-
buffer, size);
258+
return squashfs_xattr_handler_list(handler, d, list, list_size, name,
259+
name_len);
269260
}
270261

271262
static const struct xattr_handler squashfs_xattr_trusted_handler = {
272263
.prefix = XATTR_TRUSTED_PREFIX,
273-
.list = squashfs_trusted_list,
274-
.get = squashfs_trusted_get
264+
.flags = SQUASHFS_XATTR_TRUSTED,
265+
.list = squashfs_trusted_xattr_handler_list,
266+
.get = squashfs_xattr_handler_get
275267
};
276268

277269
/*
278270
* Security namespace support
279271
*/
280-
static size_t squashfs_security_list(const struct xattr_handler *handler,
281-
struct dentry *d, char *list,
282-
size_t list_size, const char *name,
283-
size_t name_len)
284-
{
285-
if (list && XATTR_SECURITY_PREFIX_LEN <= list_size)
286-
memcpy(list, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN);
287-
return XATTR_SECURITY_PREFIX_LEN;
288-
}
289-
290-
static int squashfs_security_get(const struct xattr_handler *handler,
291-
struct dentry *d, const char *name,
292-
void *buffer, size_t size)
293-
{
294-
if (name[0] == '\0')
295-
return -EINVAL;
296-
297-
return squashfs_xattr_get(d_inode(d), SQUASHFS_XATTR_SECURITY, name,
298-
buffer, size);
299-
}
300-
301272
static const struct xattr_handler squashfs_xattr_security_handler = {
302273
.prefix = XATTR_SECURITY_PREFIX,
303-
.list = squashfs_security_list,
304-
.get = squashfs_security_get
274+
.flags = SQUASHFS_XATTR_SECURITY,
275+
.list = squashfs_xattr_handler_list,
276+
.get = squashfs_xattr_handler_get
305277
};
306278

307279
static const struct xattr_handler *squashfs_xattr_handler(int type)

0 commit comments

Comments
 (0)