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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/posix_acl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include "reiserfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/xattr.h>
^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/posix_acl_xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "acl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) static int __reiserfs_set_acl(struct reiserfs_transaction_handle *th,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 			    struct inode *inode, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 			    struct posix_acl *acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) reiserfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	int error, error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	size_t jcreate_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	int size = acl ? posix_acl_xattr_size(acl->a_count) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	int update_mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	umode_t mode = inode->i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	 * Pessimism: We can't assume that anything from the xattr root up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	 * has been created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	jcreate_blocks = reiserfs_xattr_jcreate_nblocks(inode) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 			 reiserfs_xattr_nblocks(inode, size) * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	reiserfs_write_lock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	error = journal_begin(&th, inode->i_sb, jcreate_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	reiserfs_write_unlock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (error == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		if (type == ACL_TYPE_ACCESS && acl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			error = posix_acl_update_mode(inode, &mode, &acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 				goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			update_mode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		error = __reiserfs_set_acl(&th, inode, type, acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		if (!error && update_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			inode->i_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		reiserfs_write_lock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		error2 = journal_end(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		reiserfs_write_unlock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		if (error2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			error = error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * Convert from filesystem to in-memory representation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static struct posix_acl *reiserfs_posix_acl_from_disk(const void *value, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	const char *end = (char *)value + size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int n, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct posix_acl *acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (!value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (size < sizeof(reiserfs_acl_header))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (((reiserfs_acl_header *) value)->a_version !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	    cpu_to_le32(REISERFS_ACL_VERSION))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	value = (char *)value + sizeof(reiserfs_acl_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	count = reiserfs_acl_count(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (count < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	acl = posix_acl_alloc(count, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (!acl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	for (n = 0; n < count; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		reiserfs_acl_entry *entry = (reiserfs_acl_entry *) value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		if ((char *)value + sizeof(reiserfs_acl_entry_short) > end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		switch (acl->a_entries[n].e_tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		case ACL_USER_OBJ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		case ACL_GROUP_OBJ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		case ACL_MASK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		case ACL_OTHER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			value = (char *)value +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			    sizeof(reiserfs_acl_entry_short);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		case ACL_USER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			value = (char *)value + sizeof(reiserfs_acl_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			if ((char *)value > end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			acl->a_entries[n].e_uid = 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 				make_kuid(&init_user_ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 					  le32_to_cpu(entry->e_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		case ACL_GROUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			value = (char *)value + sizeof(reiserfs_acl_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			if ((char *)value > end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			acl->a_entries[n].e_gid =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 				make_kgid(&init_user_ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 					  le32_to_cpu(entry->e_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (value != end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	return acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	posix_acl_release(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  * Convert from in-memory to filesystem representation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static void *reiserfs_posix_acl_to_disk(const struct posix_acl *acl, size_t * size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	reiserfs_acl_header *ext_acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	char *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	*size = reiserfs_acl_size(acl->a_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	ext_acl = kmalloc(sizeof(reiserfs_acl_header) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 						  acl->a_count *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 						  sizeof(reiserfs_acl_entry),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 						  GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (!ext_acl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	ext_acl->a_version = cpu_to_le32(REISERFS_ACL_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	e = (char *)ext_acl + sizeof(reiserfs_acl_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	for (n = 0; n < acl->a_count; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		const struct posix_acl_entry *acl_e = &acl->a_entries[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		reiserfs_acl_entry *entry = (reiserfs_acl_entry *) e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		switch (acl->a_entries[n].e_tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		case ACL_USER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			entry->e_id = cpu_to_le32(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 				from_kuid(&init_user_ns, acl_e->e_uid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			e += sizeof(reiserfs_acl_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		case ACL_GROUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			entry->e_id = cpu_to_le32(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 				from_kgid(&init_user_ns, acl_e->e_gid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			e += sizeof(reiserfs_acl_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		case ACL_USER_OBJ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		case ACL_GROUP_OBJ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		case ACL_MASK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		case ACL_OTHER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			e += sizeof(reiserfs_acl_entry_short);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	return (char *)ext_acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	kfree(ext_acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  * Inode operation get_posix_acl().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * inode->i_mutex: down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  * BKL held [before 2.5.x]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	char *name, *value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	struct posix_acl *acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	case ACL_TYPE_ACCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		name = XATTR_NAME_POSIX_ACL_ACCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	case ACL_TYPE_DEFAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		name = XATTR_NAME_POSIX_ACL_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	size = reiserfs_xattr_get(inode, name, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (size < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		if (size == -ENODATA || size == -ENOSYS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		return ERR_PTR(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	value = kmalloc(size, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (!value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	retval = reiserfs_xattr_get(inode, name, value, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (retval == -ENODATA || retval == -ENOSYS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		 * This shouldn't actually happen as it should have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		 * been caught above.. but just in case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		acl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	} else if (retval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		acl = ERR_PTR(retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		acl = reiserfs_posix_acl_from_disk(value, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	kfree(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	return acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * Inode operation set_posix_acl().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * inode->i_mutex: down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  * BKL held [before 2.5.x]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) __reiserfs_set_acl(struct reiserfs_transaction_handle *th, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		 int type, struct posix_acl *acl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	void *value = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	size_t size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	case ACL_TYPE_ACCESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		name = XATTR_NAME_POSIX_ACL_ACCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	case ACL_TYPE_DEFAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		name = XATTR_NAME_POSIX_ACL_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		if (!S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			return acl ? -EACCES : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (acl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		value = reiserfs_posix_acl_to_disk(acl, &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		if (IS_ERR(value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			return (int)PTR_ERR(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	error = reiserfs_xattr_set_handle(th, inode, name, value, size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	 * Ensure that the inode gets dirtied if we're only using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	 * the mode bits and an old ACL didn't exist. We don't need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	 * to check if the inode is hashed here since we won't get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	 * called by reiserfs_inherit_default_acl().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	if (error == -ENODATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		if (type == ACL_TYPE_ACCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	kfree(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (!error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		set_cached_acl(inode, type, acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)  * dir->i_mutex: locked,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)  * inode is new and not released into the wild yet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			     struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			     struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	struct posix_acl *default_acl, *acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	/* ACLs only get applied to files and directories */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (S_ISLNK(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	 * ACLs can only be used on "new" objects, so if it's an old object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	 * there is nothing to inherit from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	if (get_inode_sd_version(dir) == STAT_DATA_V1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		goto apply_umask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	 * Don't apply ACLs to objects in the .reiserfs_priv tree.. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	 * would be useless since permissions are ignored, and a pain because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	 * it introduces locking cycles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (IS_PRIVATE(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		goto apply_umask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	err = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if (default_acl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		err = __reiserfs_set_acl(th, inode, ACL_TYPE_DEFAULT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 					 default_acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		posix_acl_release(default_acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	if (acl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			err = __reiserfs_set_acl(th, inode, ACL_TYPE_ACCESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 						 acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		posix_acl_release(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) apply_umask:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	/* no ACL, apply umask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	inode->i_mode &= ~current_umask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) /* This is used to cache the default acl before a new object is created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)  * The biggest reason for this is to get an idea of how many blocks will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)  * actually be required for the create operation if we must inherit an ACL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  * An ACL write can add up to 3 object creations and an additional file write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  * so we'd prefer not to reserve that many blocks in the journal if we can.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  * It also has the advantage of not loading the ACL with a transaction open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  * this may seem silly, but if the owner of the directory is doing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)  * creation, the ACL may not be loaded since the permissions wouldn't require
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)  * it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)  * We return the number of blocks required for the transaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) int reiserfs_cache_default_acl(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	struct posix_acl *acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	int nblocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	if (IS_PRIVATE(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	acl = get_acl(inode, ACL_TYPE_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	if (acl && !IS_ERR(acl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		int size = reiserfs_acl_size(acl->a_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		/* Other xattrs can be created during inode creation. We don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		 * want to claim too many blocks, so we check to see if we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		 * need to create the tree to the xattrs, and then we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		 * just want two files. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		nblocks = reiserfs_xattr_jcreate_nblocks(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		/* We need to account for writes + bitmaps for two files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		nblocks += reiserfs_xattr_nblocks(inode, size) * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		posix_acl_release(acl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	return nblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  * Called under i_mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) int reiserfs_acl_chmod(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	if (IS_PRIVATE(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	if (get_inode_sd_version(inode) == STAT_DATA_V1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	    !reiserfs_posixacl(inode->i_sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	return posix_acl_chmod(inode, inode->i_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }