VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   32 Branches   54 Tags
b24413180f560 (Greg Kroah-Hartman  2017-11-01 15:07:57 +0100   1) // SPDX-License-Identifier: GPL-2.0
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800   2) /*
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800   3)  * linux/fs/hfsplus/xattr.c
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800   4)  *
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800   5)  * Vyacheslav Dubeyko <slava@dubeyko.com>
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800   6)  *
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800   7)  * Logic of processing extended attributes
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800   8)  */
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800   9) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  10) #include "hfsplus_fs.h"
017f8da43e92d (Hin-Tak Leung       2014-06-06 14:36:21 -0700  11) #include <linux/nls.h>
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  12) #include "xattr.h"
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  13) 
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800  14) static int hfsplus_removexattr(struct inode *inode, const char *name);
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800  15) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  16) const struct xattr_handler *hfsplus_xattr_handlers[] = {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  17) 	&hfsplus_xattr_osx_handler,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  18) 	&hfsplus_xattr_user_handler,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  19) 	&hfsplus_xattr_trusted_handler,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  20) 	&hfsplus_xattr_security_handler,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  21) 	NULL
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  22) };
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  23) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  24) static int strcmp_xattr_finder_info(const char *name)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  25) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  26) 	if (name) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  27) 		return strncmp(name, HFSPLUS_XATTR_FINDER_INFO_NAME,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  28) 				sizeof(HFSPLUS_XATTR_FINDER_INFO_NAME));
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  29) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  30) 	return -1;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  31) }
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  32) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  33) static int strcmp_xattr_acl(const char *name)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  34) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  35) 	if (name) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  36) 		return strncmp(name, HFSPLUS_XATTR_ACL_NAME,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  37) 				sizeof(HFSPLUS_XATTR_ACL_NAME));
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  38) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  39) 	return -1;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  40) }
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  41) 
1ad8d63d63e21 (Fabian Frederick    2015-04-16 12:47:07 -0700  42) static bool is_known_namespace(const char *name)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  43) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  44) 	if (strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) &&
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  45) 	    strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) &&
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  46) 	    strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) &&
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  47) 	    strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  48) 		return false;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  49) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  50) 	return true;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  51) }
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800  52) 
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  53) static void hfsplus_init_header_node(struct inode *attr_file,
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  54) 					u32 clump_size,
a99b7069aab8f (Geert Uytterhoeven  2013-11-14 14:32:18 -0800  55) 					char *buf, u16 node_size)
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  56) {
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  57) 	struct hfs_bnode_desc *desc;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  58) 	struct hfs_btree_header_rec *head;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  59) 	u16 offset;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  60) 	__be16 *rec_offsets;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  61) 	u32 hdr_node_map_rec_bits;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  62) 	char *bmp;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  63) 	u32 used_nodes;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  64) 	u32 used_bmp_bytes;
df3d4e7a24089 (Christian Kujau     2014-06-06 14:36:32 -0700  65) 	u64 tmp;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  66) 
a99b7069aab8f (Geert Uytterhoeven  2013-11-14 14:32:18 -0800  67) 	hfs_dbg(ATTR_MOD, "init_hdr_attr_file: clump %u, node_size %u\n",
b73f3d0e70b1f (Fabian Frederick    2014-06-06 14:36:31 -0700  68) 		clump_size, node_size);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  69) 
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  70) 	/* The end of the node contains list of record offsets */
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  71) 	rec_offsets = (__be16 *)(buf + node_size);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  72) 
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  73) 	desc = (struct hfs_bnode_desc *)buf;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  74) 	desc->type = HFS_NODE_HEADER;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  75) 	desc->num_recs = cpu_to_be16(HFSPLUS_BTREE_HDR_NODE_RECS_COUNT);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  76) 	offset = sizeof(struct hfs_bnode_desc);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  77) 	*--rec_offsets = cpu_to_be16(offset);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  78) 
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  79) 	head = (struct hfs_btree_header_rec *)(buf + offset);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  80) 	head->node_size = cpu_to_be16(node_size);
a99b7069aab8f (Geert Uytterhoeven  2013-11-14 14:32:18 -0800  81) 	tmp = i_size_read(attr_file);
a99b7069aab8f (Geert Uytterhoeven  2013-11-14 14:32:18 -0800  82) 	do_div(tmp, node_size);
a99b7069aab8f (Geert Uytterhoeven  2013-11-14 14:32:18 -0800  83) 	head->node_count = cpu_to_be32(tmp);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  84) 	head->free_nodes = cpu_to_be32(be32_to_cpu(head->node_count) - 1);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  85) 	head->clump_size = cpu_to_be32(clump_size);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  86) 	head->attributes |= cpu_to_be32(HFS_TREE_BIGKEYS | HFS_TREE_VARIDXKEYS);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  87) 	head->max_key_len = cpu_to_be16(HFSPLUS_ATTR_KEYLEN - sizeof(u16));
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  88) 	offset += sizeof(struct hfs_btree_header_rec);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  89) 	*--rec_offsets = cpu_to_be16(offset);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  90) 	offset += HFSPLUS_BTREE_HDR_USER_BYTES;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  91) 	*--rec_offsets = cpu_to_be16(offset);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  92) 
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  93) 	hdr_node_map_rec_bits = 8 * (node_size - offset - (4 * sizeof(u16)));
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  94) 	if (be32_to_cpu(head->node_count) > hdr_node_map_rec_bits) {
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  95) 		u32 map_node_bits;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  96) 		u32 map_nodes;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  97) 
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  98) 		desc->next = cpu_to_be32(be32_to_cpu(head->leaf_tail) + 1);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800  99) 		map_node_bits = 8 * (node_size - sizeof(struct hfs_bnode_desc) -
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 100) 					(2 * sizeof(u16)) - 2);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 101) 		map_nodes = (be32_to_cpu(head->node_count) -
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 102) 				hdr_node_map_rec_bits +
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 103) 				(map_node_bits - 1)) / map_node_bits;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 104) 		be32_add_cpu(&head->free_nodes, 0 - map_nodes);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 105) 	}
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 106) 
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 107) 	bmp = buf + offset;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 108) 	used_nodes =
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 109) 		be32_to_cpu(head->node_count) - be32_to_cpu(head->free_nodes);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 110) 	used_bmp_bytes = used_nodes / 8;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 111) 	if (used_bmp_bytes) {
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 112) 		memset(bmp, 0xFF, used_bmp_bytes);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 113) 		bmp += used_bmp_bytes;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 114) 		used_nodes %= 8;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 115) 	}
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 116) 	*bmp = ~(0xFF >> used_nodes);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 117) 	offset += hdr_node_map_rec_bits / 8;
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 118) 	*--rec_offsets = cpu_to_be16(offset);
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 119) }
099e9245e04d5 (Vyacheslav Dubeyko  2013-11-12 15:11:08 -0800 120) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 121) static int hfsplus_create_attributes_file(struct super_block *sb)
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 122) {
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 123) 	int err = 0;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 124) 	struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 125) 	struct inode *attr_file;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 126) 	struct hfsplus_inode_info *hip;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 127) 	u32 clump_size;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 128) 	u16 node_size = HFSPLUS_ATTR_TREE_NODE_SIZE;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 129) 	char *buf;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 130) 	int index, written;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 131) 	struct address_space *mapping;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 132) 	struct page *page;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 133) 	int old_state = HFSPLUS_EMPTY_ATTR_TREE;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 134) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 135) 	hfs_dbg(ATTR_MOD, "create_attr_file: ino %d\n", HFSPLUS_ATTR_CNID);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 136) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 137) check_attr_tree_state_again:
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 138) 	switch (atomic_read(&sbi->attr_tree_state)) {
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 139) 	case HFSPLUS_EMPTY_ATTR_TREE:
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 140) 		if (old_state != atomic_cmpxchg(&sbi->attr_tree_state,
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 141) 						old_state,
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 142) 						HFSPLUS_CREATING_ATTR_TREE))
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 143) 			goto check_attr_tree_state_again;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 144) 		break;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 145) 	case HFSPLUS_CREATING_ATTR_TREE:
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 146) 		/*
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 147) 		 * This state means that another thread is in process
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 148) 		 * of AttributesFile creation. Theoretically, it is
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 149) 		 * possible to be here. But really __setxattr() method
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 150) 		 * first of all calls hfs_find_init() for lookup in
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 151) 		 * B-tree of CatalogFile. This method locks mutex of
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 152) 		 * CatalogFile's B-tree. As a result, if some thread
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 153) 		 * is inside AttributedFile creation operation then
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 154) 		 * another threads will be waiting unlocking of
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 155) 		 * CatalogFile's B-tree's mutex. However, if code will
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 156) 		 * change then we will return error code (-EAGAIN) from
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 157) 		 * here. Really, it means that first try to set of xattr
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 158) 		 * fails with error but second attempt will have success.
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 159) 		 */
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 160) 		return -EAGAIN;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 161) 	case HFSPLUS_VALID_ATTR_TREE:
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 162) 		return 0;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 163) 	case HFSPLUS_FAILED_ATTR_TREE:
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 164) 		return -EOPNOTSUPP;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 165) 	default:
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 166) 		BUG();
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 167) 	}
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 168) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 169) 	attr_file = hfsplus_iget(sb, HFSPLUS_ATTR_CNID);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 170) 	if (IS_ERR(attr_file)) {
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 171) 		pr_err("failed to load attributes file\n");
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 172) 		return PTR_ERR(attr_file);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 173) 	}
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 174) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 175) 	BUG_ON(i_size_read(attr_file) != 0);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 176) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 177) 	hip = HFSPLUS_I(attr_file);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 178) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 179) 	clump_size = hfsplus_calc_btree_clump_size(sb->s_blocksize,
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 180) 						    node_size,
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 181) 						    sbi->sect_count,
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 182) 						    HFSPLUS_ATTR_CNID);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 183) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 184) 	mutex_lock(&hip->extents_lock);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 185) 	hip->clump_blocks = clump_size >> sbi->alloc_blksz_shift;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 186) 	mutex_unlock(&hip->extents_lock);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 187) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 188) 	if (sbi->free_blocks <= (hip->clump_blocks << 1)) {
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 189) 		err = -ENOSPC;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 190) 		goto end_attr_file_creation;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 191) 	}
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 192) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 193) 	while (hip->alloc_blocks < hip->clump_blocks) {
2cd282a1bc6b9 (Sergei Antonov      2014-06-06 14:36:28 -0700 194) 		err = hfsplus_file_extend(attr_file, false);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 195) 		if (unlikely(err)) {
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 196) 			pr_err("failed to extend attributes file\n");
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 197) 			goto end_attr_file_creation;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 198) 		}
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 199) 		hip->phys_size = attr_file->i_size =
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 200) 			(loff_t)hip->alloc_blocks << sbi->alloc_blksz_shift;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 201) 		hip->fs_blocks = hip->alloc_blocks << sbi->fs_shift;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 202) 		inode_set_bytes(attr_file, attr_file->i_size);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 203) 	}
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 204) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 205) 	buf = kzalloc(node_size, GFP_NOFS);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 206) 	if (!buf) {
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 207) 		pr_err("failed to allocate memory for header node\n");
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 208) 		err = -ENOMEM;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 209) 		goto end_attr_file_creation;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 210) 	}
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 211) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 212) 	hfsplus_init_header_node(attr_file, clump_size, buf, node_size);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 213) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 214) 	mapping = attr_file->i_mapping;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 215) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 216) 	index = 0;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 217) 	written = 0;
09cbfeaf1a5a6 (Kirill A. Shutemov  2016-04-01 15:29:47 +0300 218) 	for (; written < node_size; index++, written += PAGE_SIZE) {
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 219) 		void *kaddr;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 220) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 221) 		page = read_mapping_page(mapping, index, NULL);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 222) 		if (IS_ERR(page)) {
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 223) 			err = PTR_ERR(page);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 224) 			goto failed_header_node_init;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 225) 		}
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 226) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 227) 		kaddr = kmap_atomic(page);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 228) 		memcpy(kaddr, buf + written,
09cbfeaf1a5a6 (Kirill A. Shutemov  2016-04-01 15:29:47 +0300 229) 			min_t(size_t, PAGE_SIZE, node_size - written));
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 230) 		kunmap_atomic(kaddr);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 231) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 232) 		set_page_dirty(page);
09cbfeaf1a5a6 (Kirill A. Shutemov  2016-04-01 15:29:47 +0300 233) 		put_page(page);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 234) 	}
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 235) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 236) 	hfsplus_mark_inode_dirty(attr_file, HFSPLUS_I_ATTR_DIRTY);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 237) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 238) 	sbi->attr_tree = hfs_btree_open(sb, HFSPLUS_ATTR_CNID);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 239) 	if (!sbi->attr_tree)
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 240) 		pr_err("failed to load attributes file\n");
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 241) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 242) failed_header_node_init:
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 243) 	kfree(buf);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 244) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 245) end_attr_file_creation:
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 246) 	iput(attr_file);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 247) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 248) 	if (!err)
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 249) 		atomic_set(&sbi->attr_tree_state, HFSPLUS_VALID_ATTR_TREE);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 250) 	else if (err == -ENOSPC)
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 251) 		atomic_set(&sbi->attr_tree_state, HFSPLUS_EMPTY_ATTR_TREE);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 252) 	else
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 253) 		atomic_set(&sbi->attr_tree_state, HFSPLUS_FAILED_ATTR_TREE);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 254) 
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 255) 	return err;
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 256) }
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 257) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 258) int __hfsplus_setxattr(struct inode *inode, const char *name,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 259) 			const void *value, size_t size, int flags)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 260) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 261) 	int err = 0;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 262) 	struct hfs_find_data cat_fd;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 263) 	hfsplus_cat_entry entry;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 264) 	u16 cat_entry_flags, cat_entry_type;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 265) 	u16 folder_finderinfo_len = sizeof(struct DInfo) +
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 266) 					sizeof(struct DXInfo);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 267) 	u16 file_finderinfo_len = sizeof(struct FInfo) +
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 268) 					sizeof(struct FXInfo);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 269) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 270) 	if ((!S_ISREG(inode->i_mode) &&
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 271) 			!S_ISDIR(inode->i_mode)) ||
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 272) 				HFSPLUS_IS_RSRC(inode))
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 273) 		return -EOPNOTSUPP;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 274) 
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800 275) 	if (value == NULL)
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800 276) 		return hfsplus_removexattr(inode, name);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 277) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 278) 	err = hfs_find_init(HFSPLUS_SB(inode->i_sb)->cat_tree, &cat_fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 279) 	if (err) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 280) 		pr_err("can't init xattr find struct\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 281) 		return err;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 282) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 283) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 284) 	err = hfsplus_find_cat(inode->i_sb, inode->i_ino, &cat_fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 285) 	if (err) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 286) 		pr_err("catalog searching failed\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 287) 		goto end_setxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 288) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 289) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 290) 	if (!strcmp_xattr_finder_info(name)) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 291) 		if (flags & XATTR_CREATE) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 292) 			pr_err("xattr exists yet\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 293) 			err = -EOPNOTSUPP;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 294) 			goto end_setxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 295) 		}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 296) 		hfs_bnode_read(cat_fd.bnode, &entry, cat_fd.entryoffset,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 297) 					sizeof(hfsplus_cat_entry));
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 298) 		if (be16_to_cpu(entry.type) == HFSPLUS_FOLDER) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 299) 			if (size == folder_finderinfo_len) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 300) 				memcpy(&entry.folder.user_info, value,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 301) 						folder_finderinfo_len);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 302) 				hfs_bnode_write(cat_fd.bnode, &entry,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 303) 					cat_fd.entryoffset,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 304) 					sizeof(struct hfsplus_cat_folder));
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 305) 				hfsplus_mark_inode_dirty(inode,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 306) 						HFSPLUS_I_CAT_DIRTY);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 307) 			} else {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 308) 				err = -ERANGE;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 309) 				goto end_setxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 310) 			}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 311) 		} else if (be16_to_cpu(entry.type) == HFSPLUS_FILE) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 312) 			if (size == file_finderinfo_len) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 313) 				memcpy(&entry.file.user_info, value,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 314) 						file_finderinfo_len);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 315) 				hfs_bnode_write(cat_fd.bnode, &entry,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 316) 					cat_fd.entryoffset,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 317) 					sizeof(struct hfsplus_cat_file));
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 318) 				hfsplus_mark_inode_dirty(inode,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 319) 						HFSPLUS_I_CAT_DIRTY);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 320) 			} else {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 321) 				err = -ERANGE;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 322) 				goto end_setxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 323) 			}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 324) 		} else {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 325) 			err = -EOPNOTSUPP;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 326) 			goto end_setxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 327) 		}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 328) 		goto end_setxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 329) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 330) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 331) 	if (!HFSPLUS_SB(inode->i_sb)->attr_tree) {
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 332) 		err = hfsplus_create_attributes_file(inode->i_sb);
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 333) 		if (unlikely(err))
95e0d7dbb9b28 (Vyacheslav Dubeyko  2013-11-12 15:11:09 -0800 334) 			goto end_setxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 335) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 336) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 337) 	if (hfsplus_attr_exists(inode, name)) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 338) 		if (flags & XATTR_CREATE) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 339) 			pr_err("xattr exists yet\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 340) 			err = -EOPNOTSUPP;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 341) 			goto end_setxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 342) 		}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 343) 		err = hfsplus_delete_attr(inode, name);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 344) 		if (err)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 345) 			goto end_setxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 346) 		err = hfsplus_create_attr(inode, name, value, size);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 347) 		if (err)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 348) 			goto end_setxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 349) 	} else {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 350) 		if (flags & XATTR_REPLACE) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 351) 			pr_err("cannot replace xattr\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 352) 			err = -EOPNOTSUPP;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 353) 			goto end_setxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 354) 		}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 355) 		err = hfsplus_create_attr(inode, name, value, size);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 356) 		if (err)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 357) 			goto end_setxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 358) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 359) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 360) 	cat_entry_type = hfs_bnode_read_u16(cat_fd.bnode, cat_fd.entryoffset);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 361) 	if (cat_entry_type == HFSPLUS_FOLDER) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 362) 		cat_entry_flags = hfs_bnode_read_u16(cat_fd.bnode,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 363) 				    cat_fd.entryoffset +
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 364) 				    offsetof(struct hfsplus_cat_folder, flags));
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 365) 		cat_entry_flags |= HFSPLUS_XATTR_EXISTS;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 366) 		if (!strcmp_xattr_acl(name))
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 367) 			cat_entry_flags |= HFSPLUS_ACL_EXISTS;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 368) 		hfs_bnode_write_u16(cat_fd.bnode, cat_fd.entryoffset +
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 369) 				offsetof(struct hfsplus_cat_folder, flags),
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 370) 				cat_entry_flags);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 371) 		hfsplus_mark_inode_dirty(inode, HFSPLUS_I_CAT_DIRTY);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 372) 	} else if (cat_entry_type == HFSPLUS_FILE) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 373) 		cat_entry_flags = hfs_bnode_read_u16(cat_fd.bnode,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 374) 				    cat_fd.entryoffset +
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 375) 				    offsetof(struct hfsplus_cat_file, flags));
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 376) 		cat_entry_flags |= HFSPLUS_XATTR_EXISTS;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 377) 		if (!strcmp_xattr_acl(name))
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 378) 			cat_entry_flags |= HFSPLUS_ACL_EXISTS;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 379) 		hfs_bnode_write_u16(cat_fd.bnode, cat_fd.entryoffset +
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 380) 				    offsetof(struct hfsplus_cat_file, flags),
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 381) 				    cat_entry_flags);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 382) 		hfsplus_mark_inode_dirty(inode, HFSPLUS_I_CAT_DIRTY);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 383) 	} else {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 384) 		pr_err("invalid catalog entry type\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 385) 		err = -EIO;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 386) 		goto end_setxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 387) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 388) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 389) end_setxattr:
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 390) 	hfs_find_exit(&cat_fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 391) 	return err;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 392) }
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 393) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 394) static int name_len(const char *xattr_name, int xattr_name_len)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 395) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 396) 	int len = xattr_name_len + 1;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 397) 
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800 398) 	if (!is_known_namespace(xattr_name))
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 399) 		len += XATTR_MAC_OSX_PREFIX_LEN;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 400) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 401) 	return len;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 402) }
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 403) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 404) static int copy_name(char *buffer, const char *xattr_name, int name_len)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 405) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 406) 	int len = name_len;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 407) 	int offset = 0;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 408) 
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800 409) 	if (!is_known_namespace(xattr_name)) {
29774f3f4e5af (Mathieu Malaterre   2019-07-16 16:29:15 -0700 410) 		memcpy(buffer, XATTR_MAC_OSX_PREFIX, XATTR_MAC_OSX_PREFIX_LEN);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 411) 		offset += XATTR_MAC_OSX_PREFIX_LEN;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 412) 		len += XATTR_MAC_OSX_PREFIX_LEN;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 413) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 414) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 415) 	strncpy(buffer + offset, xattr_name, name_len);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 416) 	memset(buffer + offset + name_len, 0, 1);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 417) 	len += 1;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 418) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 419) 	return len;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 420) }
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 421) 
5930122683dff (Al Viro             2016-05-27 10:19:30 -0400 422) int hfsplus_setxattr(struct inode *inode, const char *name,
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 423) 		     const void *value, size_t size, int flags,
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 424) 		     const char *prefix, size_t prefixlen)
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 425) {
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 426) 	char *xattr_name;
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 427) 	int res;
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 428) 
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 429) 	xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 430) 		GFP_KERNEL);
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 431) 	if (!xattr_name)
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 432) 		return -ENOMEM;
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 433) 	strcpy(xattr_name, prefix);
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 434) 	strcpy(xattr_name + prefixlen, name);
5930122683dff (Al Viro             2016-05-27 10:19:30 -0400 435) 	res = __hfsplus_setxattr(inode, xattr_name, value, size, flags);
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 436) 	kfree(xattr_name);
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 437) 	return res;
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 438) }
5e61473ea9f1e (Fabian Frederick    2015-04-16 12:47:01 -0700 439) 
b4c1107cc9626 (Vyacheslav Dubeyko  2013-09-11 14:24:30 -0700 440) static ssize_t hfsplus_getxattr_finder_info(struct inode *inode,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 441) 						void *value, size_t size)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 442) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 443) 	ssize_t res = 0;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 444) 	struct hfs_find_data fd;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 445) 	u16 entry_type;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 446) 	u16 folder_rec_len = sizeof(struct DInfo) + sizeof(struct DXInfo);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 447) 	u16 file_rec_len = sizeof(struct FInfo) + sizeof(struct FXInfo);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 448) 	u16 record_len = max(folder_rec_len, file_rec_len);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 449) 	u8 folder_finder_info[sizeof(struct DInfo) + sizeof(struct DXInfo)];
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 450) 	u8 file_finder_info[sizeof(struct FInfo) + sizeof(struct FXInfo)];
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 451) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 452) 	if (size >= record_len) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 453) 		res = hfs_find_init(HFSPLUS_SB(inode->i_sb)->cat_tree, &fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 454) 		if (res) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 455) 			pr_err("can't init xattr find struct\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 456) 			return res;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 457) 		}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 458) 		res = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 459) 		if (res)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 460) 			goto end_getxattr_finder_info;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 461) 		entry_type = hfs_bnode_read_u16(fd.bnode, fd.entryoffset);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 462) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 463) 		if (entry_type == HFSPLUS_FOLDER) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 464) 			hfs_bnode_read(fd.bnode, folder_finder_info,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 465) 				fd.entryoffset +
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 466) 				offsetof(struct hfsplus_cat_folder, user_info),
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 467) 				folder_rec_len);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 468) 			memcpy(value, folder_finder_info, folder_rec_len);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 469) 			res = folder_rec_len;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 470) 		} else if (entry_type == HFSPLUS_FILE) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 471) 			hfs_bnode_read(fd.bnode, file_finder_info,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 472) 				fd.entryoffset +
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 473) 				offsetof(struct hfsplus_cat_file, user_info),
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 474) 				file_rec_len);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 475) 			memcpy(value, file_finder_info, file_rec_len);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 476) 			res = file_rec_len;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 477) 		} else {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 478) 			res = -EOPNOTSUPP;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 479) 			goto end_getxattr_finder_info;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 480) 		}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 481) 	} else
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 482) 		res = size ? -ERANGE : record_len;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 483) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 484) end_getxattr_finder_info:
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 485) 	if (size >= record_len)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 486) 		hfs_find_exit(&fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 487) 	return res;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 488) }
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 489) 
b4c1107cc9626 (Vyacheslav Dubeyko  2013-09-11 14:24:30 -0700 490) ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 491) 			 void *value, size_t size)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 492) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 493) 	struct hfs_find_data fd;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 494) 	hfsplus_attr_entry *entry;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 495) 	__be32 xattr_record_type;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 496) 	u32 record_type;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 497) 	u16 record_length = 0;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 498) 	ssize_t res = 0;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 499) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 500) 	if ((!S_ISREG(inode->i_mode) &&
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 501) 			!S_ISDIR(inode->i_mode)) ||
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 502) 				HFSPLUS_IS_RSRC(inode))
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 503) 		return -EOPNOTSUPP;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 504) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 505) 	if (!strcmp_xattr_finder_info(name))
b4c1107cc9626 (Vyacheslav Dubeyko  2013-09-11 14:24:30 -0700 506) 		return hfsplus_getxattr_finder_info(inode, value, size);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 507) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 508) 	if (!HFSPLUS_SB(inode->i_sb)->attr_tree)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 509) 		return -EOPNOTSUPP;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 510) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 511) 	entry = hfsplus_alloc_attr_entry();
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 512) 	if (!entry) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 513) 		pr_err("can't allocate xattr entry\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 514) 		return -ENOMEM;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 515) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 516) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 517) 	res = hfs_find_init(HFSPLUS_SB(inode->i_sb)->attr_tree, &fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 518) 	if (res) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 519) 		pr_err("can't init xattr find struct\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 520) 		goto failed_getxattr_init;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 521) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 522) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 523) 	res = hfsplus_find_attr(inode->i_sb, inode->i_ino, name, &fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 524) 	if (res) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 525) 		if (res == -ENOENT)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 526) 			res = -ENODATA;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 527) 		else
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 528) 			pr_err("xattr searching failed\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 529) 		goto out;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 530) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 531) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 532) 	hfs_bnode_read(fd.bnode, &xattr_record_type,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 533) 			fd.entryoffset, sizeof(xattr_record_type));
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 534) 	record_type = be32_to_cpu(xattr_record_type);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 535) 	if (record_type == HFSPLUS_ATTR_INLINE_DATA) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 536) 		record_length = hfs_bnode_read_u16(fd.bnode,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 537) 				fd.entryoffset +
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 538) 				offsetof(struct hfsplus_attr_inline_data,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 539) 				length));
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 540) 		if (record_length > HFSPLUS_MAX_INLINE_DATA_SIZE) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 541) 			pr_err("invalid xattr record size\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 542) 			res = -EIO;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 543) 			goto out;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 544) 		}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 545) 	} else if (record_type == HFSPLUS_ATTR_FORK_DATA ||
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 546) 			record_type == HFSPLUS_ATTR_EXTENTS) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 547) 		pr_err("only inline data xattr are supported\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 548) 		res = -EOPNOTSUPP;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 549) 		goto out;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 550) 	} else {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 551) 		pr_err("invalid xattr record\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 552) 		res = -EIO;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 553) 		goto out;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 554) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 555) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 556) 	if (size) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 557) 		hfs_bnode_read(fd.bnode, entry, fd.entryoffset,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 558) 				offsetof(struct hfsplus_attr_inline_data,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 559) 					raw_bytes) + record_length);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 560) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 561) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 562) 	if (size >= record_length) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 563) 		memcpy(value, entry->inline_data.raw_bytes, record_length);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 564) 		res = record_length;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 565) 	} else
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 566) 		res = size ? -ERANGE : record_length;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 567) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 568) out:
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 569) 	hfs_find_exit(&fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 570) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 571) failed_getxattr_init:
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 572) 	hfsplus_destroy_attr_entry(entry);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 573) 	return res;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 574) }
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 575) 
b296821a7c42f (Al Viro             2016-04-10 20:48:24 -0400 576) ssize_t hfsplus_getxattr(struct inode *inode, const char *name,
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 577) 			 void *value, size_t size,
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 578) 			 const char *prefix, size_t prefixlen)
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 579) {
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 580) 	int res;
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 581) 	char *xattr_name;
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 582) 
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 583) 	xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 584) 			     GFP_KERNEL);
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 585) 	if (!xattr_name)
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 586) 		return -ENOMEM;
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 587) 
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 588) 	strcpy(xattr_name, prefix);
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 589) 	strcpy(xattr_name + prefixlen, name);
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 590) 
b296821a7c42f (Al Viro             2016-04-10 20:48:24 -0400 591) 	res = __hfsplus_getxattr(inode, xattr_name, value, size);
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 592) 	kfree(xattr_name);
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 593) 	return res;
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 594) 
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 595) }
a3cef4cd6886c (Fabian Frederick    2015-04-16 12:46:58 -0700 596) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 597) static inline int can_list(const char *xattr_name)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 598) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 599) 	if (!xattr_name)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 600) 		return 0;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 601) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 602) 	return strncmp(xattr_name, XATTR_TRUSTED_PREFIX,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 603) 			XATTR_TRUSTED_PREFIX_LEN) ||
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 604) 				capable(CAP_SYS_ADMIN);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 605) }
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 606) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 607) static ssize_t hfsplus_listxattr_finder_info(struct dentry *dentry,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 608) 						char *buffer, size_t size)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 609) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 610) 	ssize_t res = 0;
2b0143b5c986b (David Howells       2015-03-17 22:25:59 +0000 611) 	struct inode *inode = d_inode(dentry);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 612) 	struct hfs_find_data fd;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 613) 	u16 entry_type;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 614) 	u8 folder_finder_info[sizeof(struct DInfo) + sizeof(struct DXInfo)];
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 615) 	u8 file_finder_info[sizeof(struct FInfo) + sizeof(struct FXInfo)];
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 616) 	unsigned long len, found_bit;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 617) 	int xattr_name_len, symbols_count;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 618) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 619) 	res = hfs_find_init(HFSPLUS_SB(inode->i_sb)->cat_tree, &fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 620) 	if (res) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 621) 		pr_err("can't init xattr find struct\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 622) 		return res;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 623) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 624) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 625) 	res = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 626) 	if (res)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 627) 		goto end_listxattr_finder_info;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 628) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 629) 	entry_type = hfs_bnode_read_u16(fd.bnode, fd.entryoffset);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 630) 	if (entry_type == HFSPLUS_FOLDER) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 631) 		len = sizeof(struct DInfo) + sizeof(struct DXInfo);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 632) 		hfs_bnode_read(fd.bnode, folder_finder_info,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 633) 				fd.entryoffset +
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 634) 				offsetof(struct hfsplus_cat_folder, user_info),
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 635) 				len);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 636) 		found_bit = find_first_bit((void *)folder_finder_info, len*8);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 637) 	} else if (entry_type == HFSPLUS_FILE) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 638) 		len = sizeof(struct FInfo) + sizeof(struct FXInfo);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 639) 		hfs_bnode_read(fd.bnode, file_finder_info,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 640) 				fd.entryoffset +
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 641) 				offsetof(struct hfsplus_cat_file, user_info),
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 642) 				len);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 643) 		found_bit = find_first_bit((void *)file_finder_info, len*8);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 644) 	} else {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 645) 		res = -EOPNOTSUPP;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 646) 		goto end_listxattr_finder_info;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 647) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 648) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 649) 	if (found_bit >= (len*8))
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 650) 		res = 0;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 651) 	else {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 652) 		symbols_count = sizeof(HFSPLUS_XATTR_FINDER_INFO_NAME) - 1;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 653) 		xattr_name_len =
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 654) 			name_len(HFSPLUS_XATTR_FINDER_INFO_NAME, symbols_count);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 655) 		if (!buffer || !size) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 656) 			if (can_list(HFSPLUS_XATTR_FINDER_INFO_NAME))
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 657) 				res = xattr_name_len;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 658) 		} else if (can_list(HFSPLUS_XATTR_FINDER_INFO_NAME)) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 659) 			if (size < xattr_name_len)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 660) 				res = -ERANGE;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 661) 			else {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 662) 				res = copy_name(buffer,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 663) 						HFSPLUS_XATTR_FINDER_INFO_NAME,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 664) 						symbols_count);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 665) 			}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 666) 		}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 667) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 668) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 669) end_listxattr_finder_info:
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 670) 	hfs_find_exit(&fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 671) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 672) 	return res;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 673) }
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 674) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 675) ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 676) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 677) 	ssize_t err;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 678) 	ssize_t res = 0;
2b0143b5c986b (David Howells       2015-03-17 22:25:59 +0000 679) 	struct inode *inode = d_inode(dentry);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 680) 	struct hfs_find_data fd;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 681) 	u16 key_len = 0;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 682) 	struct hfsplus_attr_key attr_key;
017f8da43e92d (Hin-Tak Leung       2014-06-06 14:36:21 -0700 683) 	char *strbuf;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 684) 	int xattr_name_len;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 685) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 686) 	if ((!S_ISREG(inode->i_mode) &&
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 687) 			!S_ISDIR(inode->i_mode)) ||
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 688) 				HFSPLUS_IS_RSRC(inode))
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 689) 		return -EOPNOTSUPP;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 690) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 691) 	res = hfsplus_listxattr_finder_info(dentry, buffer, size);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 692) 	if (res < 0)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 693) 		return res;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 694) 	else if (!HFSPLUS_SB(inode->i_sb)->attr_tree)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 695) 		return (res == 0) ? -EOPNOTSUPP : res;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 696) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 697) 	err = hfs_find_init(HFSPLUS_SB(inode->i_sb)->attr_tree, &fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 698) 	if (err) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 699) 		pr_err("can't init xattr find struct\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 700) 		return err;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 701) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 702) 
017f8da43e92d (Hin-Tak Leung       2014-06-06 14:36:21 -0700 703) 	strbuf = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN +
017f8da43e92d (Hin-Tak Leung       2014-06-06 14:36:21 -0700 704) 			XATTR_MAC_OSX_PREFIX_LEN + 1, GFP_KERNEL);
017f8da43e92d (Hin-Tak Leung       2014-06-06 14:36:21 -0700 705) 	if (!strbuf) {
017f8da43e92d (Hin-Tak Leung       2014-06-06 14:36:21 -0700 706) 		res = -ENOMEM;
017f8da43e92d (Hin-Tak Leung       2014-06-06 14:36:21 -0700 707) 		goto out;
017f8da43e92d (Hin-Tak Leung       2014-06-06 14:36:21 -0700 708) 	}
017f8da43e92d (Hin-Tak Leung       2014-06-06 14:36:21 -0700 709) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 710) 	err = hfsplus_find_attr(inode->i_sb, inode->i_ino, NULL, &fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 711) 	if (err) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 712) 		if (err == -ENOENT) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 713) 			if (res == 0)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 714) 				res = -ENODATA;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 715) 			goto end_listxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 716) 		} else {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 717) 			res = err;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 718) 			goto end_listxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 719) 		}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 720) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 721) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 722) 	for (;;) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 723) 		key_len = hfs_bnode_read_u16(fd.bnode, fd.keyoffset);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 724) 		if (key_len == 0 || key_len > fd.tree->max_key_len) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 725) 			pr_err("invalid xattr key length: %d\n", key_len);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 726) 			res = -EIO;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 727) 			goto end_listxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 728) 		}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 729) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 730) 		hfs_bnode_read(fd.bnode, &attr_key,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 731) 				fd.keyoffset, key_len + sizeof(key_len));
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 732) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 733) 		if (be32_to_cpu(attr_key.cnid) != inode->i_ino)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 734) 			goto end_listxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 735) 
017f8da43e92d (Hin-Tak Leung       2014-06-06 14:36:21 -0700 736) 		xattr_name_len = NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 737) 		if (hfsplus_uni2asc(inode->i_sb,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 738) 			(const struct hfsplus_unistr *)&fd.key->attr.key_name,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 739) 					strbuf, &xattr_name_len)) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 740) 			pr_err("unicode conversion failed\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 741) 			res = -EIO;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 742) 			goto end_listxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 743) 		}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 744) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 745) 		if (!buffer || !size) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 746) 			if (can_list(strbuf))
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 747) 				res += name_len(strbuf, xattr_name_len);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 748) 		} else if (can_list(strbuf)) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 749) 			if (size < (res + name_len(strbuf, xattr_name_len))) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 750) 				res = -ERANGE;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 751) 				goto end_listxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 752) 			} else
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 753) 				res += copy_name(buffer + res,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 754) 						strbuf, xattr_name_len);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 755) 		}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 756) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 757) 		if (hfs_brec_goto(&fd, 1))
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 758) 			goto end_listxattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 759) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 760) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 761) end_listxattr:
017f8da43e92d (Hin-Tak Leung       2014-06-06 14:36:21 -0700 762) 	kfree(strbuf);
017f8da43e92d (Hin-Tak Leung       2014-06-06 14:36:21 -0700 763) out:
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 764) 	hfs_find_exit(&fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 765) 	return res;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 766) }
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 767) 
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800 768) static int hfsplus_removexattr(struct inode *inode, const char *name)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 769) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 770) 	int err = 0;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 771) 	struct hfs_find_data cat_fd;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 772) 	u16 flags;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 773) 	u16 cat_entry_type;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 774) 	int is_xattr_acl_deleted = 0;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 775) 	int is_all_xattrs_deleted = 0;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 776) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 777) 	if (!HFSPLUS_SB(inode->i_sb)->attr_tree)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 778) 		return -EOPNOTSUPP;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 779) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 780) 	if (!strcmp_xattr_finder_info(name))
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 781) 		return -EOPNOTSUPP;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 782) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 783) 	err = hfs_find_init(HFSPLUS_SB(inode->i_sb)->cat_tree, &cat_fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 784) 	if (err) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 785) 		pr_err("can't init xattr find struct\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 786) 		return err;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 787) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 788) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 789) 	err = hfsplus_find_cat(inode->i_sb, inode->i_ino, &cat_fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 790) 	if (err) {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 791) 		pr_err("catalog searching failed\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 792) 		goto end_removexattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 793) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 794) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 795) 	err = hfsplus_delete_attr(inode, name);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 796) 	if (err)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 797) 		goto end_removexattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 798) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 799) 	is_xattr_acl_deleted = !strcmp_xattr_acl(name);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 800) 	is_all_xattrs_deleted = !hfsplus_attr_exists(inode, NULL);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 801) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 802) 	if (!is_xattr_acl_deleted && !is_all_xattrs_deleted)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 803) 		goto end_removexattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 804) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 805) 	cat_entry_type = hfs_bnode_read_u16(cat_fd.bnode, cat_fd.entryoffset);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 806) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 807) 	if (cat_entry_type == HFSPLUS_FOLDER) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 808) 		flags = hfs_bnode_read_u16(cat_fd.bnode, cat_fd.entryoffset +
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 809) 				offsetof(struct hfsplus_cat_folder, flags));
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 810) 		if (is_xattr_acl_deleted)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 811) 			flags &= ~HFSPLUS_ACL_EXISTS;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 812) 		if (is_all_xattrs_deleted)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 813) 			flags &= ~HFSPLUS_XATTR_EXISTS;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 814) 		hfs_bnode_write_u16(cat_fd.bnode, cat_fd.entryoffset +
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 815) 				offsetof(struct hfsplus_cat_folder, flags),
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 816) 				flags);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 817) 		hfsplus_mark_inode_dirty(inode, HFSPLUS_I_CAT_DIRTY);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 818) 	} else if (cat_entry_type == HFSPLUS_FILE) {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 819) 		flags = hfs_bnode_read_u16(cat_fd.bnode, cat_fd.entryoffset +
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 820) 				offsetof(struct hfsplus_cat_file, flags));
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 821) 		if (is_xattr_acl_deleted)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 822) 			flags &= ~HFSPLUS_ACL_EXISTS;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 823) 		if (is_all_xattrs_deleted)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 824) 			flags &= ~HFSPLUS_XATTR_EXISTS;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 825) 		hfs_bnode_write_u16(cat_fd.bnode, cat_fd.entryoffset +
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 826) 				offsetof(struct hfsplus_cat_file, flags),
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 827) 				flags);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 828) 		hfsplus_mark_inode_dirty(inode, HFSPLUS_I_CAT_DIRTY);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 829) 	} else {
d614267329f2b (Joe Perches         2013-04-30 15:27:55 -0700 830) 		pr_err("invalid catalog entry type\n");
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 831) 		err = -EIO;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 832) 		goto end_removexattr;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 833) 	}
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 834) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 835) end_removexattr:
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 836) 	hfs_find_exit(&cat_fd);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 837) 	return err;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 838) }
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 839) 
d9a82a04033f8 (Andreas Gruenbacher 2015-10-04 19:18:51 +0200 840) static int hfsplus_osx_getxattr(const struct xattr_handler *handler,
b296821a7c42f (Al Viro             2016-04-10 20:48:24 -0400 841) 				struct dentry *unused, struct inode *inode,
b296821a7c42f (Al Viro             2016-04-10 20:48:24 -0400 842) 				const char *name, void *buffer, size_t size)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 843) {
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800 844) 	/*
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800 845) 	 * Don't allow retrieving properly prefixed attributes
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800 846) 	 * by prepending them with "osx."
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800 847) 	 */
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800 848) 	if (is_known_namespace(name))
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800 849) 		return -EOPNOTSUPP;
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 850) 
db579e76f06e7 (Thomas Hebb         2015-04-16 12:47:18 -0700 851) 	/*
db579e76f06e7 (Thomas Hebb         2015-04-16 12:47:18 -0700 852) 	 * osx is the namespace we use to indicate an unprefixed
db579e76f06e7 (Thomas Hebb         2015-04-16 12:47:18 -0700 853) 	 * attribute on the filesystem (like the ones that OS X
db579e76f06e7 (Thomas Hebb         2015-04-16 12:47:18 -0700 854) 	 * creates), so we pass the name through unmodified (after
db579e76f06e7 (Thomas Hebb         2015-04-16 12:47:18 -0700 855) 	 * ensuring it doesn't conflict with another namespace).
db579e76f06e7 (Thomas Hebb         2015-04-16 12:47:18 -0700 856) 	 */
b296821a7c42f (Al Viro             2016-04-10 20:48:24 -0400 857) 	return __hfsplus_getxattr(inode, name, buffer, size);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 858) }
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 859) 
d9a82a04033f8 (Andreas Gruenbacher 2015-10-04 19:18:51 +0200 860) static int hfsplus_osx_setxattr(const struct xattr_handler *handler,
e65ce2a50cf6a (Christian Brauner   2021-01-21 14:19:27 +0100 861) 				struct user_namespace *mnt_userns,
5930122683dff (Al Viro             2016-05-27 10:19:30 -0400 862) 				struct dentry *unused, struct inode *inode,
5930122683dff (Al Viro             2016-05-27 10:19:30 -0400 863) 				const char *name, const void *buffer,
5930122683dff (Al Viro             2016-05-27 10:19:30 -0400 864) 				size_t size, int flags)
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 865) {
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800 866) 	/*
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800 867) 	 * Don't allow setting properly prefixed attributes
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800 868) 	 * by prepending them with "osx."
b168fff72109a (Christoph Hellwig   2014-01-29 23:59:19 -0800 869) 	 */
2796e4cec525a (Christoph Hellwig   2013-12-20 05:16:56 -0800 870) 	if (is_known_namespace(name))
2796e4cec525a (Christoph Hellwig   2013-12-20 05:16:56 -0800 871) 		return -EOPNOTSUPP;
2796e4cec525a (Christoph Hellwig   2013-12-20 05:16:56 -0800 872) 
db579e76f06e7 (Thomas Hebb         2015-04-16 12:47:18 -0700 873) 	/*
db579e76f06e7 (Thomas Hebb         2015-04-16 12:47:18 -0700 874) 	 * osx is the namespace we use to indicate an unprefixed
db579e76f06e7 (Thomas Hebb         2015-04-16 12:47:18 -0700 875) 	 * attribute on the filesystem (like the ones that OS X
db579e76f06e7 (Thomas Hebb         2015-04-16 12:47:18 -0700 876) 	 * creates), so we pass the name through unmodified (after
db579e76f06e7 (Thomas Hebb         2015-04-16 12:47:18 -0700 877) 	 * ensuring it doesn't conflict with another namespace).
db579e76f06e7 (Thomas Hebb         2015-04-16 12:47:18 -0700 878) 	 */
5930122683dff (Al Viro             2016-05-27 10:19:30 -0400 879) 	return __hfsplus_setxattr(inode, name, buffer, size, flags);
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 880) }
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 881) 
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 882) const struct xattr_handler hfsplus_xattr_osx_handler = {
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 883) 	.prefix	= XATTR_MAC_OSX_PREFIX,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 884) 	.get	= hfsplus_osx_getxattr,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 885) 	.set	= hfsplus_osx_setxattr,
127e5f5ae51ef (Vyacheslav Dubeyko  2013-02-27 17:03:03 -0800 886) };