Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* Extended attribute handling for AFS.  We use xattrs to get and set metadata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * instead of providing pioctl().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * Deal with the result of a successful fetch ACL operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static void afs_acl_success(struct afs_operation *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	afs_vnode_commit_status(op, &op->file[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static void afs_acl_put(struct afs_operation *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	kfree(op->acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static const struct afs_operation_ops afs_fetch_acl_operation = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	.issue_afs_rpc	= afs_fs_fetch_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	.success	= afs_acl_success,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	.put		= afs_acl_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * Get a file's ACL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static int afs_xattr_get_acl(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			     struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 			     struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 			     void *buffer, size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct afs_operation *op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	struct afs_vnode *vnode = AFS_FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct afs_acl *acl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	op = afs_alloc_operation(NULL, vnode->volume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (IS_ERR(op))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	afs_op_set_vnode(op, 0, vnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	op->ops = &afs_fetch_acl_operation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	afs_begin_vnode_operation(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	afs_wait_for_operation(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	acl = op->acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	op->acl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	ret = afs_put_operation(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		ret = acl->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		if (size > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			if (acl->size <= size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 				memcpy(buffer, acl->data, acl->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 				ret = -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	kfree(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static bool afs_make_acl(struct afs_operation *op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			 const void *buffer, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct afs_acl *acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	acl = kmalloc(sizeof(*acl) + size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (!acl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		afs_op_nomem(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	acl->size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	memcpy(acl->data, buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	op->acl = acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static const struct afs_operation_ops afs_store_acl_operation = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	.issue_afs_rpc	= afs_fs_store_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	.success	= afs_acl_success,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	.put		= afs_acl_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * Set a file's AFS3 ACL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static int afs_xattr_set_acl(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)                              struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)                              struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)                              const void *buffer, size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct afs_operation *op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct afs_vnode *vnode = AFS_FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (flags == XATTR_CREATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	op = afs_alloc_operation(NULL, vnode->volume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (IS_ERR(op))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	afs_op_set_vnode(op, 0, vnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (!afs_make_acl(op, buffer, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return afs_put_operation(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	op->ops = &afs_store_acl_operation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return afs_do_sync_operation(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static const struct xattr_handler afs_xattr_afs_acl_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	.name   = "afs.acl",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	.get    = afs_xattr_get_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	.set    = afs_xattr_set_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static const struct afs_operation_ops yfs_fetch_opaque_acl_operation = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	.issue_yfs_rpc	= yfs_fs_fetch_opaque_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	.success	= afs_acl_success,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	/* Don't free op->yacl in .put here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * Get a file's YFS ACL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static int afs_xattr_get_yfs(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			     struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			     struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			     void *buffer, size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	struct afs_operation *op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct afs_vnode *vnode = AFS_FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct yfs_acl *yacl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	char buf[16], *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	int which = 0, dsize, ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (strcmp(name, "acl") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		which = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	else if (strcmp(name, "acl_inherited") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		which = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	else if (strcmp(name, "acl_num_cleaned") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		which = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	else if (strcmp(name, "vol_acl") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		which = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	yacl = kzalloc(sizeof(struct yfs_acl), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (!yacl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (which == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		yacl->flags |= YFS_ACL_WANT_ACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	else if (which == 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		yacl->flags |= YFS_ACL_WANT_VOL_ACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	op = afs_alloc_operation(NULL, vnode->volume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (IS_ERR(op))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		goto error_yacl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	afs_op_set_vnode(op, 0, vnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	op->yacl = yacl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	op->ops = &yfs_fetch_opaque_acl_operation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	afs_begin_vnode_operation(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	afs_wait_for_operation(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	ret = afs_put_operation(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		switch (which) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			data = yacl->acl->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			dsize = yacl->acl->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			data = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			dsize = scnprintf(buf, sizeof(buf), "%u", yacl->inherit_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			data = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			dsize = scnprintf(buf, sizeof(buf), "%u", yacl->num_cleaned);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			data = yacl->vol_acl->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			dsize = yacl->vol_acl->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			goto error_yacl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		ret = dsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		if (size > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			if (dsize <= size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 				memcpy(buffer, data, dsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 				ret = -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	} else if (ret == -ENOTSUPP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		ret = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) error_yacl:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	yfs_free_opaque_acl(yacl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static const struct afs_operation_ops yfs_store_opaque_acl2_operation = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	.issue_yfs_rpc	= yfs_fs_store_opaque_acl2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	.success	= afs_acl_success,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	.put		= afs_acl_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)  * Set a file's YFS ACL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static int afs_xattr_set_yfs(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)                              struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)                              struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)                              const void *buffer, size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct afs_operation *op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct afs_vnode *vnode = AFS_FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (flags == XATTR_CREATE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	    strcmp(name, "acl") != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	op = afs_alloc_operation(NULL, vnode->volume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (IS_ERR(op))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	afs_op_set_vnode(op, 0, vnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (!afs_make_acl(op, buffer, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		return afs_put_operation(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	op->ops = &yfs_store_opaque_acl2_operation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	ret = afs_do_sync_operation(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (ret == -ENOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		ret = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static const struct xattr_handler afs_xattr_yfs_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	.prefix	= "afs.yfs.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	.get	= afs_xattr_get_yfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	.set	= afs_xattr_set_yfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * Get the name of the cell on which a file resides.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static int afs_xattr_get_cell(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			      struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			      struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			      void *buffer, size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	struct afs_vnode *vnode = AFS_FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	struct afs_cell *cell = vnode->volume->cell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	size_t namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	namelen = cell->name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	if (size == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		return namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (namelen > size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	memcpy(buffer, cell->name, namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static const struct xattr_handler afs_xattr_afs_cell_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	.name	= "afs.cell",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	.get	= afs_xattr_get_cell,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)  * Get the volume ID, vnode ID and vnode uniquifier of a file as a sequence of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  * hex numbers separated by colons.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static int afs_xattr_get_fid(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			     struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			     struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			     void *buffer, size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	struct afs_vnode *vnode = AFS_FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	char text[16 + 1 + 24 + 1 + 8 + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	/* The volume ID is 64-bit, the vnode ID is 96-bit and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	 * uniquifier is 32-bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	len = scnprintf(text, sizeof(text), "%llx:", vnode->fid.vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (vnode->fid.vnode_hi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		len += scnprintf(text + len, sizeof(text) - len, "%x%016llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 				vnode->fid.vnode_hi, vnode->fid.vnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		len += scnprintf(text + len, sizeof(text) - len, "%llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 				 vnode->fid.vnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	len += scnprintf(text + len, sizeof(text) - len, ":%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			 vnode->fid.unique);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	if (size == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	if (len > size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	memcpy(buffer, text, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static const struct xattr_handler afs_xattr_afs_fid_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	.name	= "afs.fid",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	.get	= afs_xattr_get_fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)  * Get the name of the volume on which a file resides.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) static int afs_xattr_get_volume(const struct xattr_handler *handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			      struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 			      struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			      void *buffer, size_t size, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	struct afs_vnode *vnode = AFS_FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	const char *volname = vnode->volume->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	size_t namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	namelen = strlen(volname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (size == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		return namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	if (namelen > size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	memcpy(buffer, volname, namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	return namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static const struct xattr_handler afs_xattr_afs_volume_handler = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	.name	= "afs.volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	.get	= afs_xattr_get_volume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) const struct xattr_handler *afs_xattr_handlers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	&afs_xattr_afs_acl_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	&afs_xattr_afs_cell_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	&afs_xattr_afs_fid_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	&afs_xattr_afs_volume_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	&afs_xattr_yfs_handler,		/* afs.yfs. prefix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) };