~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/hfsplus/xattr.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/hfsplus/xattr.c (Version linux-6.12-rc7) and /fs/hfsplus/xattr.c (Version linux-4.12.14)


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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php