1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) International Business Machines Corp., 2000-2004
4 * Copyright (C) Christoph Hellwig, 2002
7 #include <linux/capability.h>
9 #include <linux/xattr.h>
10 #include <linux/posix_acl_xattr.h>
11 #include <linux/slab.h>
12 #include <linux/quotaops.h>
13 #include <linux/security.h>
14 #include "jfs_incore.h"
15 #include "jfs_superblock.h"
17 #include "jfs_debug.h"
18 #include "jfs_dinode.h"
19 #include "jfs_extent.h"
20 #include "jfs_metapage.h"
21 #include "jfs_xattr.h"
25 * jfs_xattr.c: extended attribute service
31 * Extended attribute lists (jfs_ea_list) consist of an overall size (32 bit
32 * value) and a variable (0 or more) number of extended attribute
33 * entries. Each extended attribute entry (jfs_ea) is a <name,value> double
34 * where <name> is constructed from a null-terminated ascii string
35 * (1 ... 255 bytes in the name) and <value> is arbitrary 8 bit data
36 * (1 ... 65535 bytes). The in-memory format is
38 * 0 1 2 4 4 + namelen + 1
39 * +-------+--------+--------+----------------+-------------------+
40 * | Flags | Name | Value | Name String \0 | Data . . . . |
41 * | | Length | Length | | |
42 * +-------+--------+--------+----------------+-------------------+
44 * A jfs_ea_list then is structured as
46 * 0 4 4 + EA_SIZE(ea1)
47 * +------------+-------------------+--------------------+-----
48 * | Overall EA | First FEA Element | Second FEA Element | .....
50 * +------------+-------------------+--------------------+-----
54 * FEALISTs are stored on disk using blocks allocated by dbAlloc() and
55 * written directly. An EA list may be in-lined in the inode if there is
56 * sufficient room available.
60 int flag; /* Indicates what storage xattr points to */
61 int max_size; /* largest xattr that fits in current buffer */
62 dxd_t new_ea; /* dxd to replace ea when modifying xattr */
63 struct metapage *mp; /* metapage containing ea list */
64 struct jfs_ea_list *xattr; /* buffer containing ea list */
68 * ea_buffer.flag values
70 #define EA_INLINE 0x0001
71 #define EA_EXTENT 0x0002
73 #define EA_MALLOC 0x0008
77 * Mapping of on-disk attribute names: for on-disk attribute names with an
78 * unknown prefix (not "system.", "user.", "security.", or "trusted."), the
79 * prefix "os2." is prepended. On the way back to disk, "os2." prefixes are
80 * stripped and we make sure that the remaining name does not start with one
81 * of the know prefixes.
84 static int is_known_namespace(const char *name)
86 if (strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) &&
87 strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) &&
88 strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) &&
89 strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
95 static inline int name_size(struct jfs_ea *ea)
97 if (is_known_namespace(ea->name))
100 return ea->namelen + XATTR_OS2_PREFIX_LEN;
103 static inline int copy_name(char *buffer, struct jfs_ea *ea)
105 int len = ea->namelen;
107 if (!is_known_namespace(ea->name)) {
108 memcpy(buffer, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN);
109 buffer += XATTR_OS2_PREFIX_LEN;
110 len += XATTR_OS2_PREFIX_LEN;
112 memcpy(buffer, ea->name, ea->namelen);
113 buffer[ea->namelen] = 0;
118 /* Forward references */
119 static void ea_release(struct inode *inode, struct ea_buffer *ea_buf);
122 * NAME: ea_write_inline
124 * FUNCTION: Attempt to write an EA inline if area is available
127 * Already verified that the specified EA is small enough to fit inline
131 * ealist - EA list pointer
132 * size - size of ealist in bytes
133 * ea - dxd_t structure to be filled in with necessary EA information
134 * if we successfully copy the EA inline
137 * Checks if the inode's inline area is available. If so, copies EA inline
138 * and sets <ea> fields appropriately. Otherwise, returns failure, EA will
139 * have to be put into an extent.
141 * RETURNS: 0 for successful copy to inline area; -1 if area not available
143 static int ea_write_inline(struct inode *ip, struct jfs_ea_list *ealist,
144 int size, dxd_t * ea)
146 struct jfs_inode_info *ji = JFS_IP(ip);
149 * Make sure we have an EA -- the NULL EA list is valid, but you
152 if (ealist && size > sizeof (struct jfs_ea_list)) {
153 assert(size <= sizeof (ji->i_inline_ea));
156 * See if the space is available or if it is already being
157 * used for an inline EA.
159 if (!(ji->mode2 & INLINEEA) && !(ji->ea.flag & DXD_INLINE))
165 memcpy(ji->i_inline_ea, ealist, size);
166 ea->flag = DXD_INLINE;
167 ji->mode2 &= ~INLINEEA;
174 /* Free up INLINE area */
175 if (ji->ea.flag & DXD_INLINE)
176 ji->mode2 |= INLINEEA;
185 * FUNCTION: Write an EA for an inode
187 * PRE CONDITIONS: EA has been verified
191 * ealist - EA list pointer
192 * size - size of ealist in bytes
193 * ea - dxd_t structure to be filled in appropriately with where the
196 * NOTES: Will write EA inline if able to, otherwise allocates blocks for an
197 * extent and synchronously writes it to those blocks.
199 * RETURNS: 0 for success; Anything else indicates failure
201 static int ea_write(struct inode *ip, struct jfs_ea_list *ealist, int size,
204 struct super_block *sb = ip->i_sb;
205 struct jfs_inode_info *ji = JFS_IP(ip);
206 struct jfs_sb_info *sbi = JFS_SBI(sb);
216 * Quick check to see if this is an in-linable EA. Short EAs
217 * and empty EAs are all in-linable, provided the space exists.
219 if (!ealist || size <= sizeof (ji->i_inline_ea)) {
220 if (!ea_write_inline(ip, ealist, size, ea))
224 /* figure out how many blocks we need */
225 nblocks = (size + (sb->s_blocksize - 1)) >> sb->s_blocksize_bits;
227 /* Allocate new blocks to quota. */
228 rc = dquot_alloc_block(ip, nblocks);
232 rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
234 /*Rollback quota allocation. */
235 dquot_free_block(ip, nblocks);
240 * Now have nblocks worth of storage to stuff into the FEALIST.
241 * loop over the FEALIST copying data into the buffer one page at
244 cp = (char *) ealist;
246 for (i = 0; i < nblocks; i += sbi->nbperpage) {
248 * Determine how many bytes for this request, and round up to
249 * the nearest aggregate block size
251 nb = min(PSIZE, nbytes);
253 ((((nb + sb->s_blocksize - 1)) >> sb->s_blocksize_bits))
254 << sb->s_blocksize_bits;
256 if (!(mp = get_metapage(ip, blkno + i, bytes_to_write, 1))) {
261 memcpy(mp->data, cp, nb);
264 * We really need a way to propagate errors for
265 * forced writes like this one. --hch
267 * (__write_metapage => release_metapage => flush_metapage)
270 if ((rc = flush_metapage(mp))) {
272 * the write failed -- this means that the buffer
273 * is still assigned and the blocks are not being
274 * used. this seems like the best error recovery
287 ea->flag = DXD_EXTENT;
288 DXDsize(ea, le32_to_cpu(ealist->size));
289 DXDlength(ea, nblocks);
290 DXDaddress(ea, blkno);
292 /* Free up INLINE area */
293 if (ji->ea.flag & DXD_INLINE)
294 ji->mode2 |= INLINEEA;
299 /* Rollback quota allocation. */
300 dquot_free_block(ip, nblocks);
302 dbFree(ip, blkno, nblocks);
307 * NAME: ea_read_inline
309 * FUNCTION: Read an inlined EA into user's buffer
313 * ealist - Pointer to buffer to fill in with EA
317 static int ea_read_inline(struct inode *ip, struct jfs_ea_list *ealist)
319 struct jfs_inode_info *ji = JFS_IP(ip);
320 int ea_size = sizeDXD(&ji->ea);
328 if ((sizeDXD(&ji->ea) > sizeof (ji->i_inline_ea)))
330 if (le32_to_cpu(((struct jfs_ea_list *) &ji->i_inline_ea)->size)
334 memcpy(ealist, ji->i_inline_ea, ea_size);
341 * FUNCTION: copy EA data into user's buffer
345 * ealist - Pointer to buffer to fill in with EA
347 * NOTES: If EA is inline calls ea_read_inline() to copy EA.
349 * RETURNS: 0 for success; other indicates failure
351 static int ea_read(struct inode *ip, struct jfs_ea_list *ealist)
353 struct super_block *sb = ip->i_sb;
354 struct jfs_inode_info *ji = JFS_IP(ip);
355 struct jfs_sb_info *sbi = JFS_SBI(sb);
358 char *cp = (char *) ealist;
364 /* quick check for in-line EA */
365 if (ji->ea.flag & DXD_INLINE)
366 return ea_read_inline(ip, ealist);
368 nbytes = sizeDXD(&ji->ea);
370 jfs_error(sb, "nbytes is 0\n");
375 * Figure out how many blocks were allocated when this EA list was
376 * originally written to disk.
378 nblocks = lengthDXD(&ji->ea) << sbi->l2nbperpage;
379 blkno = addressDXD(&ji->ea) << sbi->l2nbperpage;
382 * I have found the disk blocks which were originally used to store
383 * the FEALIST. now i loop over each contiguous block copying the
384 * data into the buffer.
386 for (i = 0; i < nblocks; i += sbi->nbperpage) {
388 * Determine how many bytes for this request, and round up to
389 * the nearest aggregate block size
391 nb = min(PSIZE, nbytes);
393 ((((nb + sb->s_blocksize - 1)) >> sb->s_blocksize_bits))
394 << sb->s_blocksize_bits;
396 if (!(mp = read_metapage(ip, blkno + i, bytes_to_read, 1)))
399 memcpy(cp, mp->data, nb);
400 release_metapage(mp);
412 * FUNCTION: Returns buffer containing existing extended attributes.
413 * The size of the buffer will be the larger of the existing
414 * attributes size, or min_size.
416 * The buffer, which may be inlined in the inode or in the
417 * page cache must be release by calling ea_release or ea_put
420 * inode - Inode pointer
421 * ea_buf - Structure to be populated with ealist and its metadata
422 * min_size- minimum size of buffer to be returned
424 * RETURNS: 0 for success; Other indicates failure
426 static int ea_get(struct inode *inode, struct ea_buffer *ea_buf, int min_size)
428 struct jfs_inode_info *ji = JFS_IP(inode);
429 struct super_block *sb = inode->i_sb;
431 int ea_size = sizeDXD(&ji->ea);
432 int blocks_needed, current_blocks;
435 int quota_allocation = 0;
437 memset(&ea_buf->new_ea, 0, sizeof(ea_buf->new_ea));
439 /* When fsck.jfs clears a bad ea, it doesn't clear the size */
440 if (ji->ea.flag == 0)
446 ea_buf->max_size = 0;
447 ea_buf->xattr = NULL;
450 if ((min_size <= sizeof (ji->i_inline_ea)) &&
451 (ji->mode2 & INLINEEA)) {
452 ea_buf->flag = EA_INLINE | EA_NEW;
453 ea_buf->max_size = sizeof (ji->i_inline_ea);
454 ea_buf->xattr = (struct jfs_ea_list *) ji->i_inline_ea;
455 DXDlength(&ea_buf->new_ea, 0);
456 DXDaddress(&ea_buf->new_ea, 0);
457 ea_buf->new_ea.flag = DXD_INLINE;
458 DXDsize(&ea_buf->new_ea, min_size);
462 } else if (ji->ea.flag & DXD_INLINE) {
463 if (min_size <= sizeof (ji->i_inline_ea)) {
464 ea_buf->flag = EA_INLINE;
465 ea_buf->max_size = sizeof (ji->i_inline_ea);
466 ea_buf->xattr = (struct jfs_ea_list *) ji->i_inline_ea;
471 if (!(ji->ea.flag & DXD_EXTENT)) {
472 jfs_error(sb, "invalid ea.flag\n");
475 current_blocks = (ea_size + sb->s_blocksize - 1) >>
476 sb->s_blocksize_bits;
478 size = max(min_size, ea_size);
482 * To keep the rest of the code simple. Allocate a
483 * contiguous buffer to work with. Make the buffer large
484 * enough to make use of the whole extent.
486 ea_buf->max_size = (size + sb->s_blocksize - 1) &
487 ~(sb->s_blocksize - 1);
489 ea_buf->xattr = kmalloc(ea_buf->max_size, GFP_KERNEL);
490 if (ea_buf->xattr == NULL)
493 ea_buf->flag = EA_MALLOC;
498 if ((rc = ea_read(inode, ea_buf->xattr))) {
499 kfree(ea_buf->xattr);
500 ea_buf->xattr = NULL;
505 blocks_needed = (min_size + sb->s_blocksize - 1) >>
506 sb->s_blocksize_bits;
508 if (blocks_needed > current_blocks) {
509 /* Allocate new blocks to quota. */
510 rc = dquot_alloc_block(inode, blocks_needed);
514 quota_allocation = blocks_needed;
516 rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
521 DXDlength(&ea_buf->new_ea, blocks_needed);
522 DXDaddress(&ea_buf->new_ea, blkno);
523 ea_buf->new_ea.flag = DXD_EXTENT;
524 DXDsize(&ea_buf->new_ea, min_size);
526 ea_buf->flag = EA_EXTENT | EA_NEW;
528 ea_buf->mp = get_metapage(inode, blkno,
529 blocks_needed << sb->s_blocksize_bits,
531 if (ea_buf->mp == NULL) {
532 dbFree(inode, blkno, (s64) blocks_needed);
536 ea_buf->xattr = ea_buf->mp->data;
537 ea_buf->max_size = (min_size + sb->s_blocksize - 1) &
538 ~(sb->s_blocksize - 1);
541 if ((rc = ea_read(inode, ea_buf->xattr))) {
542 discard_metapage(ea_buf->mp);
543 dbFree(inode, blkno, (s64) blocks_needed);
548 ea_buf->flag = EA_EXTENT;
549 ea_buf->mp = read_metapage(inode, addressDXD(&ji->ea),
550 lengthDXD(&ji->ea) << sb->s_blocksize_bits,
552 if (ea_buf->mp == NULL) {
556 ea_buf->xattr = ea_buf->mp->data;
557 ea_buf->max_size = (ea_size + sb->s_blocksize - 1) &
558 ~(sb->s_blocksize - 1);
561 if (EALIST_SIZE(ea_buf->xattr) != ea_size) {
562 int size = min_t(int, EALIST_SIZE(ea_buf->xattr), ea_size);
564 printk(KERN_ERR "ea_get: invalid extended attribute\n");
565 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_ADDRESS, 16, 1,
566 ea_buf->xattr, size, 1);
567 ea_release(inode, ea_buf);
575 /* Rollback quota allocation */
576 if (quota_allocation)
577 dquot_free_block(inode, quota_allocation);
582 static void ea_release(struct inode *inode, struct ea_buffer *ea_buf)
584 if (ea_buf->flag & EA_MALLOC)
585 kfree(ea_buf->xattr);
586 else if (ea_buf->flag & EA_EXTENT) {
588 release_metapage(ea_buf->mp);
590 if (ea_buf->flag & EA_NEW)
591 dbFree(inode, addressDXD(&ea_buf->new_ea),
592 lengthDXD(&ea_buf->new_ea));
596 static int ea_put(tid_t tid, struct inode *inode, struct ea_buffer *ea_buf,
599 struct jfs_inode_info *ji = JFS_IP(inode);
600 unsigned long old_blocks, new_blocks;
604 ea_release(inode, ea_buf);
606 } else if (ea_buf->flag & EA_INLINE) {
607 assert(new_size <= sizeof (ji->i_inline_ea));
608 ji->mode2 &= ~INLINEEA;
609 ea_buf->new_ea.flag = DXD_INLINE;
610 DXDsize(&ea_buf->new_ea, new_size);
611 DXDaddress(&ea_buf->new_ea, 0);
612 DXDlength(&ea_buf->new_ea, 0);
613 } else if (ea_buf->flag & EA_MALLOC) {
614 rc = ea_write(inode, ea_buf->xattr, new_size, &ea_buf->new_ea);
615 kfree(ea_buf->xattr);
616 } else if (ea_buf->flag & EA_NEW) {
617 /* We have already allocated a new dxd */
618 flush_metapage(ea_buf->mp);
620 /* ->xattr must point to original ea's metapage */
621 rc = ea_write(inode, ea_buf->xattr, new_size, &ea_buf->new_ea);
622 discard_metapage(ea_buf->mp);
627 old_blocks = new_blocks = 0;
629 if (ji->ea.flag & DXD_EXTENT) {
630 invalidate_dxd_metapages(inode, ji->ea);
631 old_blocks = lengthDXD(&ji->ea);
635 txEA(tid, inode, &ji->ea, &ea_buf->new_ea);
636 if (ea_buf->new_ea.flag & DXD_EXTENT) {
637 new_blocks = lengthDXD(&ea_buf->new_ea);
638 if (ji->ea.flag & DXD_INLINE)
639 ji->mode2 |= INLINEEA;
641 ji->ea = ea_buf->new_ea;
643 txEA(tid, inode, &ji->ea, NULL);
644 if (ji->ea.flag & DXD_INLINE)
645 ji->mode2 |= INLINEEA;
650 /* If old blocks exist, they must be removed from quota allocation. */
652 dquot_free_block(inode, old_blocks);
654 inode_set_ctime_current(inode);
659 int __jfs_setxattr(tid_t tid, struct inode *inode, const char *name,
660 const void *value, size_t value_len, int flags)
662 struct jfs_ea_list *ealist;
663 struct jfs_ea *ea, *old_ea = NULL, *next_ea = NULL;
664 struct ea_buffer ea_buf;
668 int namelen = strlen(name);
673 down_write(&JFS_IP(inode)->xattr_sem);
675 xattr_size = ea_get(inode, &ea_buf, 0);
676 if (xattr_size < 0) {
682 ealist = (struct jfs_ea_list *) ea_buf.xattr;
683 new_size = sizeof (struct jfs_ea_list);
686 for (ea = FIRST_EA(ealist); ea < END_EALIST(ealist);
688 if ((namelen == ea->namelen) &&
689 (memcmp(name, ea->name, namelen) == 0)) {
691 if (flags & XATTR_CREATE) {
696 old_ea_size = EA_SIZE(ea);
697 next_ea = NEXT_EA(ea);
699 new_size += EA_SIZE(ea);
704 if (flags & XATTR_REPLACE) {
714 new_size += sizeof (struct jfs_ea) + namelen + 1 + value_len;
716 if (new_size > ea_buf.max_size) {
718 * We need to allocate more space for merged ea list.
719 * We should only have loop to again: once.
721 ea_release(inode, &ea_buf);
722 xattr_size = ea_get(inode, &ea_buf, new_size);
723 if (xattr_size < 0) {
730 /* Remove old ea of the same name */
732 /* number of bytes following target EA */
733 length = (char *) END_EALIST(ealist) - (char *) next_ea;
735 memmove(old_ea, next_ea, length);
736 xattr_size -= old_ea_size;
739 /* Add new entry to the end */
742 /* Completely new ea list */
743 xattr_size = sizeof (struct jfs_ea_list);
746 * The size of EA value is limitted by on-disk format up to
747 * __le16, there would be an overflow if the size is equal
748 * to XATTR_SIZE_MAX (65536). In order to avoid this issue,
749 * we can pre-checkup the value size against USHRT_MAX, and
750 * return -E2BIG in this case, which is consistent with the
751 * VFS setxattr interface.
753 if (value_len >= USHRT_MAX) {
758 ea = (struct jfs_ea *) ((char *) ealist + xattr_size);
760 ea->namelen = namelen;
761 ea->valuelen = (cpu_to_le16(value_len));
762 memcpy(ea->name, name, namelen);
763 ea->name[namelen] = 0;
765 memcpy(&ea->name[namelen + 1], value, value_len);
766 xattr_size += EA_SIZE(ea);
769 /* DEBUG - If we did this right, these number match */
770 if (xattr_size != new_size) {
772 "__jfs_setxattr: xattr_size = %d, new_size = %d\n",
773 xattr_size, new_size);
780 * If we're left with an empty list, there's no ea
782 if (new_size == sizeof (struct jfs_ea_list))
785 ealist->size = cpu_to_le32(new_size);
787 rc = ea_put(tid, inode, &ea_buf, new_size);
791 ea_release(inode, &ea_buf);
793 up_write(&JFS_IP(inode)->xattr_sem);
798 ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data,
801 struct jfs_ea_list *ealist;
802 struct jfs_ea *ea, *ealist_end;
803 struct ea_buffer ea_buf;
806 int namelen = strlen(name);
809 down_read(&JFS_IP(inode)->xattr_sem);
811 xattr_size = ea_get(inode, &ea_buf, 0);
813 if (xattr_size < 0) {
821 ealist = (struct jfs_ea_list *) ea_buf.xattr;
822 ealist_end = END_EALIST(ealist);
824 /* Find the named attribute */
825 for (ea = FIRST_EA(ealist); ea < ealist_end; ea = NEXT_EA(ea)) {
826 if (unlikely(ea + 1 > ealist_end) ||
827 unlikely(NEXT_EA(ea) > ealist_end)) {
832 if ((namelen == ea->namelen) &&
833 memcmp(name, ea->name, namelen) == 0) {
835 size = le16_to_cpu(ea->valuelen);
838 else if (size > buf_size) {
842 value = ((char *) &ea->name) + ea->namelen + 1;
843 memcpy(data, value, size);
850 ea_release(inode, &ea_buf);
852 up_read(&JFS_IP(inode)->xattr_sem);
858 * No special permissions are needed to list attributes except for trusted.*
860 static inline int can_list(struct jfs_ea *ea)
862 return (strncmp(ea->name, XATTR_TRUSTED_PREFIX,
863 XATTR_TRUSTED_PREFIX_LEN) ||
864 capable(CAP_SYS_ADMIN));
867 ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size)
869 struct inode *inode = d_inode(dentry);
873 struct jfs_ea_list *ealist;
874 struct jfs_ea *ea, *ealist_end;
875 struct ea_buffer ea_buf;
877 down_read(&JFS_IP(inode)->xattr_sem);
879 xattr_size = ea_get(inode, &ea_buf, 0);
880 if (xattr_size < 0) {
888 ealist = (struct jfs_ea_list *) ea_buf.xattr;
889 ealist_end = END_EALIST(ealist);
891 /* compute required size of list */
892 for (ea = FIRST_EA(ealist); ea < ealist_end; ea = NEXT_EA(ea)) {
893 if (unlikely(ea + 1 > ealist_end) ||
894 unlikely(NEXT_EA(ea) > ealist_end)) {
900 size += name_size(ea) + 1;
906 if (size > buf_size) {
911 /* Copy attribute names to buffer */
913 for (ea = FIRST_EA(ealist); ea < END_EALIST(ealist); ea = NEXT_EA(ea)) {
915 int namelen = copy_name(buffer, ea);
916 buffer += namelen + 1;
921 ea_release(inode, &ea_buf);
923 up_read(&JFS_IP(inode)->xattr_sem);
927 static int __jfs_xattr_set(struct inode *inode, const char *name,
928 const void *value, size_t size, int flags)
930 struct jfs_inode_info *ji = JFS_IP(inode);
934 tid = txBegin(inode->i_sb, 0);
935 mutex_lock(&ji->commit_mutex);
936 rc = __jfs_setxattr(tid, inode, name, value, size, flags);
938 rc = txCommit(tid, 1, &inode, 0);
940 mutex_unlock(&ji->commit_mutex);
945 static int jfs_xattr_get(const struct xattr_handler *handler,
946 struct dentry *unused, struct inode *inode,
947 const char *name, void *value, size_t size)
949 name = xattr_full_name(handler, name);
950 return __jfs_getxattr(inode, name, value, size);
953 static int jfs_xattr_set(const struct xattr_handler *handler,
954 struct mnt_idmap *idmap,
955 struct dentry *unused, struct inode *inode,
956 const char *name, const void *value,
957 size_t size, int flags)
959 name = xattr_full_name(handler, name);
960 return __jfs_xattr_set(inode, name, value, size, flags);
963 static int jfs_xattr_get_os2(const struct xattr_handler *handler,
964 struct dentry *unused, struct inode *inode,
965 const char *name, void *value, size_t size)
967 if (is_known_namespace(name))
969 return __jfs_getxattr(inode, name, value, size);
972 static int jfs_xattr_set_os2(const struct xattr_handler *handler,
973 struct mnt_idmap *idmap,
974 struct dentry *unused, struct inode *inode,
975 const char *name, const void *value,
976 size_t size, int flags)
978 if (is_known_namespace(name))
980 return __jfs_xattr_set(inode, name, value, size, flags);
983 static const struct xattr_handler jfs_user_xattr_handler = {
984 .prefix = XATTR_USER_PREFIX,
985 .get = jfs_xattr_get,
986 .set = jfs_xattr_set,
989 static const struct xattr_handler jfs_os2_xattr_handler = {
990 .prefix = XATTR_OS2_PREFIX,
991 .get = jfs_xattr_get_os2,
992 .set = jfs_xattr_set_os2,
995 static const struct xattr_handler jfs_security_xattr_handler = {
996 .prefix = XATTR_SECURITY_PREFIX,
997 .get = jfs_xattr_get,
998 .set = jfs_xattr_set,
1001 static const struct xattr_handler jfs_trusted_xattr_handler = {
1002 .prefix = XATTR_TRUSTED_PREFIX,
1003 .get = jfs_xattr_get,
1004 .set = jfs_xattr_set,
1007 const struct xattr_handler * const jfs_xattr_handlers[] = {
1008 &jfs_os2_xattr_handler,
1009 &jfs_user_xattr_handler,
1010 &jfs_security_xattr_handler,
1011 &jfs_trusted_xattr_handler,
1016 #ifdef CONFIG_JFS_SECURITY
1017 static int jfs_initxattrs(struct inode *inode, const struct xattr *xattr_array,
1020 const struct xattr *xattr;
1021 tid_t *tid = fs_info;
1025 for (xattr = xattr_array; xattr->name != NULL; xattr++) {
1026 name = kmalloc(XATTR_SECURITY_PREFIX_LEN +
1027 strlen(xattr->name) + 1, GFP_NOFS);
1032 strcpy(name, XATTR_SECURITY_PREFIX);
1033 strcpy(name + XATTR_SECURITY_PREFIX_LEN, xattr->name);
1035 err = __jfs_setxattr(*tid, inode, name,
1036 xattr->value, xattr->value_len, 0);
1044 int jfs_init_security(tid_t tid, struct inode *inode, struct inode *dir,
1045 const struct qstr *qstr)
1047 return security_inode_init_security(inode, dir, qstr,
1048 &jfs_initxattrs, &tid);