2 * Copyright (C) International Business Machines Corp., 2000-2004
3 * Copyright (C) Christoph Hellwig, 2002
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/capability.h>
22 #include <linux/xattr.h>
23 #include <linux/posix_acl_xattr.h>
24 #include <linux/slab.h>
25 #include <linux/quotaops.h>
26 #include <linux/security.h>
27 #include "jfs_incore.h"
28 #include "jfs_superblock.h"
30 #include "jfs_debug.h"
31 #include "jfs_dinode.h"
32 #include "jfs_extent.h"
33 #include "jfs_metapage.h"
34 #include "jfs_xattr.h"
38 * jfs_xattr.c: extended attribute service
44 * Extended attribute lists (jfs_ea_list) consist of an overall size (32 bit
45 * value) and a variable (0 or more) number of extended attribute
46 * entries. Each extended attribute entry (jfs_ea) is a <name,value> double
47 * where <name> is constructed from a null-terminated ascii string
48 * (1 ... 255 bytes in the name) and <value> is arbitrary 8 bit data
49 * (1 ... 65535 bytes). The in-memory format is
51 * 0 1 2 4 4 + namelen + 1
52 * +-------+--------+--------+----------------+-------------------+
53 * | Flags | Name | Value | Name String \0 | Data . . . . |
54 * | | Length | Length | | |
55 * +-------+--------+--------+----------------+-------------------+
57 * A jfs_ea_list then is structured as
59 * 0 4 4 + EA_SIZE(ea1)
60 * +------------+-------------------+--------------------+-----
61 * | Overall EA | First FEA Element | Second FEA Element | .....
63 * +------------+-------------------+--------------------+-----
67 * FEALISTs are stored on disk using blocks allocated by dbAlloc() and
68 * written directly. An EA list may be in-lined in the inode if there is
69 * sufficient room available.
73 int flag
; /* Indicates what storage xattr points to */
74 int max_size
; /* largest xattr that fits in current buffer */
75 dxd_t new_ea
; /* dxd to replace ea when modifying xattr */
76 struct metapage
*mp
; /* metapage containing ea list */
77 struct jfs_ea_list
*xattr
; /* buffer containing ea list */
81 * ea_buffer.flag values
83 #define EA_INLINE 0x0001
84 #define EA_EXTENT 0x0002
86 #define EA_MALLOC 0x0008
90 * Mapping of on-disk attribute names: for on-disk attribute names with an
91 * unknown prefix (not "system.", "user.", "security.", or "trusted."), the
92 * prefix "os2." is prepended. On the way back to disk, "os2." prefixes are
93 * stripped and we make sure that the remaining name does not start with one
94 * of the know prefixes.
97 static int is_known_namespace(const char *name
)
99 if (strncmp(name
, XATTR_SYSTEM_PREFIX
, XATTR_SYSTEM_PREFIX_LEN
) &&
100 strncmp(name
, XATTR_USER_PREFIX
, XATTR_USER_PREFIX_LEN
) &&
101 strncmp(name
, XATTR_SECURITY_PREFIX
, XATTR_SECURITY_PREFIX_LEN
) &&
102 strncmp(name
, XATTR_TRUSTED_PREFIX
, XATTR_TRUSTED_PREFIX_LEN
))
108 static inline int name_size(struct jfs_ea
*ea
)
110 if (is_known_namespace(ea
->name
))
113 return ea
->namelen
+ XATTR_OS2_PREFIX_LEN
;
116 static inline int copy_name(char *buffer
, struct jfs_ea
*ea
)
118 int len
= ea
->namelen
;
120 if (!is_known_namespace(ea
->name
)) {
121 memcpy(buffer
, XATTR_OS2_PREFIX
, XATTR_OS2_PREFIX_LEN
);
122 buffer
+= XATTR_OS2_PREFIX_LEN
;
123 len
+= XATTR_OS2_PREFIX_LEN
;
125 memcpy(buffer
, ea
->name
, ea
->namelen
);
126 buffer
[ea
->namelen
] = 0;
131 /* Forward references */
132 static void ea_release(struct inode
*inode
, struct ea_buffer
*ea_buf
);
135 * NAME: ea_write_inline
137 * FUNCTION: Attempt to write an EA inline if area is available
140 * Already verified that the specified EA is small enough to fit inline
144 * ealist - EA list pointer
145 * size - size of ealist in bytes
146 * ea - dxd_t structure to be filled in with necessary EA information
147 * if we successfully copy the EA inline
150 * Checks if the inode's inline area is available. If so, copies EA inline
151 * and sets <ea> fields appropriately. Otherwise, returns failure, EA will
152 * have to be put into an extent.
154 * RETURNS: 0 for successful copy to inline area; -1 if area not available
156 static int ea_write_inline(struct inode
*ip
, struct jfs_ea_list
*ealist
,
157 int size
, dxd_t
* ea
)
159 struct jfs_inode_info
*ji
= JFS_IP(ip
);
162 * Make sure we have an EA -- the NULL EA list is valid, but you
165 if (ealist
&& size
> sizeof (struct jfs_ea_list
)) {
166 assert(size
<= sizeof (ji
->i_inline_ea
));
169 * See if the space is available or if it is already being
170 * used for an inline EA.
172 if (!(ji
->mode2
& INLINEEA
) && !(ji
->ea
.flag
& DXD_INLINE
))
178 memcpy(ji
->i_inline_ea
, ealist
, size
);
179 ea
->flag
= DXD_INLINE
;
180 ji
->mode2
&= ~INLINEEA
;
187 /* Free up INLINE area */
188 if (ji
->ea
.flag
& DXD_INLINE
)
189 ji
->mode2
|= INLINEEA
;
198 * FUNCTION: Write an EA for an inode
200 * PRE CONDITIONS: EA has been verified
204 * ealist - EA list pointer
205 * size - size of ealist in bytes
206 * ea - dxd_t structure to be filled in appropriately with where the
209 * NOTES: Will write EA inline if able to, otherwise allocates blocks for an
210 * extent and synchronously writes it to those blocks.
212 * RETURNS: 0 for success; Anything else indicates failure
214 static int ea_write(struct inode
*ip
, struct jfs_ea_list
*ealist
, int size
,
217 struct super_block
*sb
= ip
->i_sb
;
218 struct jfs_inode_info
*ji
= JFS_IP(ip
);
219 struct jfs_sb_info
*sbi
= JFS_SBI(sb
);
229 * Quick check to see if this is an in-linable EA. Short EAs
230 * and empty EAs are all in-linable, provided the space exists.
232 if (!ealist
|| size
<= sizeof (ji
->i_inline_ea
)) {
233 if (!ea_write_inline(ip
, ealist
, size
, ea
))
237 /* figure out how many blocks we need */
238 nblocks
= (size
+ (sb
->s_blocksize
- 1)) >> sb
->s_blocksize_bits
;
240 /* Allocate new blocks to quota. */
241 rc
= dquot_alloc_block(ip
, nblocks
);
245 rc
= dbAlloc(ip
, INOHINT(ip
), nblocks
, &blkno
);
247 /*Rollback quota allocation. */
248 dquot_free_block(ip
, nblocks
);
253 * Now have nblocks worth of storage to stuff into the FEALIST.
254 * loop over the FEALIST copying data into the buffer one page at
257 cp
= (char *) ealist
;
259 for (i
= 0; i
< nblocks
; i
+= sbi
->nbperpage
) {
261 * Determine how many bytes for this request, and round up to
262 * the nearest aggregate block size
264 nb
= min(PSIZE
, nbytes
);
266 ((((nb
+ sb
->s_blocksize
- 1)) >> sb
->s_blocksize_bits
))
267 << sb
->s_blocksize_bits
;
269 if (!(mp
= get_metapage(ip
, blkno
+ i
, bytes_to_write
, 1))) {
274 memcpy(mp
->data
, cp
, nb
);
277 * We really need a way to propagate errors for
278 * forced writes like this one. --hch
280 * (__write_metapage => release_metapage => flush_metapage)
283 if ((rc
= flush_metapage(mp
))) {
285 * the write failed -- this means that the buffer
286 * is still assigned and the blocks are not being
287 * used. this seems like the best error recovery
300 ea
->flag
= DXD_EXTENT
;
301 DXDsize(ea
, le32_to_cpu(ealist
->size
));
302 DXDlength(ea
, nblocks
);
303 DXDaddress(ea
, blkno
);
305 /* Free up INLINE area */
306 if (ji
->ea
.flag
& DXD_INLINE
)
307 ji
->mode2
|= INLINEEA
;
312 /* Rollback quota allocation. */
313 dquot_free_block(ip
, nblocks
);
315 dbFree(ip
, blkno
, nblocks
);
320 * NAME: ea_read_inline
322 * FUNCTION: Read an inlined EA into user's buffer
326 * ealist - Pointer to buffer to fill in with EA
330 static int ea_read_inline(struct inode
*ip
, struct jfs_ea_list
*ealist
)
332 struct jfs_inode_info
*ji
= JFS_IP(ip
);
333 int ea_size
= sizeDXD(&ji
->ea
);
341 if ((sizeDXD(&ji
->ea
) > sizeof (ji
->i_inline_ea
)))
343 if (le32_to_cpu(((struct jfs_ea_list
*) &ji
->i_inline_ea
)->size
)
347 memcpy(ealist
, ji
->i_inline_ea
, ea_size
);
354 * FUNCTION: copy EA data into user's buffer
358 * ealist - Pointer to buffer to fill in with EA
360 * NOTES: If EA is inline calls ea_read_inline() to copy EA.
362 * RETURNS: 0 for success; other indicates failure
364 static int ea_read(struct inode
*ip
, struct jfs_ea_list
*ealist
)
366 struct super_block
*sb
= ip
->i_sb
;
367 struct jfs_inode_info
*ji
= JFS_IP(ip
);
368 struct jfs_sb_info
*sbi
= JFS_SBI(sb
);
371 char *cp
= (char *) ealist
;
377 /* quick check for in-line EA */
378 if (ji
->ea
.flag
& DXD_INLINE
)
379 return ea_read_inline(ip
, ealist
);
381 nbytes
= sizeDXD(&ji
->ea
);
383 jfs_error(sb
, "nbytes is 0\n");
388 * Figure out how many blocks were allocated when this EA list was
389 * originally written to disk.
391 nblocks
= lengthDXD(&ji
->ea
) << sbi
->l2nbperpage
;
392 blkno
= addressDXD(&ji
->ea
) << sbi
->l2nbperpage
;
395 * I have found the disk blocks which were originally used to store
396 * the FEALIST. now i loop over each contiguous block copying the
397 * data into the buffer.
399 for (i
= 0; i
< nblocks
; i
+= sbi
->nbperpage
) {
401 * Determine how many bytes for this request, and round up to
402 * the nearest aggregate block size
404 nb
= min(PSIZE
, nbytes
);
406 ((((nb
+ sb
->s_blocksize
- 1)) >> sb
->s_blocksize_bits
))
407 << sb
->s_blocksize_bits
;
409 if (!(mp
= read_metapage(ip
, blkno
+ i
, bytes_to_read
, 1)))
412 memcpy(cp
, mp
->data
, nb
);
413 release_metapage(mp
);
425 * FUNCTION: Returns buffer containing existing extended attributes.
426 * The size of the buffer will be the larger of the existing
427 * attributes size, or min_size.
429 * The buffer, which may be inlined in the inode or in the
430 * page cache must be release by calling ea_release or ea_put
433 * inode - Inode pointer
434 * ea_buf - Structure to be populated with ealist and its metadata
435 * min_size- minimum size of buffer to be returned
437 * RETURNS: 0 for success; Other indicates failure
439 static int ea_get(struct inode
*inode
, struct ea_buffer
*ea_buf
, int min_size
)
441 struct jfs_inode_info
*ji
= JFS_IP(inode
);
442 struct super_block
*sb
= inode
->i_sb
;
444 int ea_size
= sizeDXD(&ji
->ea
);
445 int blocks_needed
, current_blocks
;
448 int quota_allocation
= 0;
450 /* When fsck.jfs clears a bad ea, it doesn't clear the size */
451 if (ji
->ea
.flag
== 0)
457 ea_buf
->max_size
= 0;
458 ea_buf
->xattr
= NULL
;
461 if ((min_size
<= sizeof (ji
->i_inline_ea
)) &&
462 (ji
->mode2
& INLINEEA
)) {
463 ea_buf
->flag
= EA_INLINE
| EA_NEW
;
464 ea_buf
->max_size
= sizeof (ji
->i_inline_ea
);
465 ea_buf
->xattr
= (struct jfs_ea_list
*) ji
->i_inline_ea
;
466 DXDlength(&ea_buf
->new_ea
, 0);
467 DXDaddress(&ea_buf
->new_ea
, 0);
468 ea_buf
->new_ea
.flag
= DXD_INLINE
;
469 DXDsize(&ea_buf
->new_ea
, min_size
);
473 } else if (ji
->ea
.flag
& DXD_INLINE
) {
474 if (min_size
<= sizeof (ji
->i_inline_ea
)) {
475 ea_buf
->flag
= EA_INLINE
;
476 ea_buf
->max_size
= sizeof (ji
->i_inline_ea
);
477 ea_buf
->xattr
= (struct jfs_ea_list
*) ji
->i_inline_ea
;
482 if (!(ji
->ea
.flag
& DXD_EXTENT
)) {
483 jfs_error(sb
, "invalid ea.flag\n");
486 current_blocks
= (ea_size
+ sb
->s_blocksize
- 1) >>
487 sb
->s_blocksize_bits
;
489 size
= max(min_size
, ea_size
);
493 * To keep the rest of the code simple. Allocate a
494 * contiguous buffer to work with
496 ea_buf
->xattr
= kmalloc(size
, GFP_KERNEL
);
497 if (ea_buf
->xattr
== NULL
)
500 ea_buf
->flag
= EA_MALLOC
;
501 ea_buf
->max_size
= (size
+ sb
->s_blocksize
- 1) &
502 ~(sb
->s_blocksize
- 1);
507 if ((rc
= ea_read(inode
, ea_buf
->xattr
))) {
508 kfree(ea_buf
->xattr
);
509 ea_buf
->xattr
= NULL
;
514 blocks_needed
= (min_size
+ sb
->s_blocksize
- 1) >>
515 sb
->s_blocksize_bits
;
517 if (blocks_needed
> current_blocks
) {
518 /* Allocate new blocks to quota. */
519 rc
= dquot_alloc_block(inode
, blocks_needed
);
523 quota_allocation
= blocks_needed
;
525 rc
= dbAlloc(inode
, INOHINT(inode
), (s64
) blocks_needed
,
530 DXDlength(&ea_buf
->new_ea
, blocks_needed
);
531 DXDaddress(&ea_buf
->new_ea
, blkno
);
532 ea_buf
->new_ea
.flag
= DXD_EXTENT
;
533 DXDsize(&ea_buf
->new_ea
, min_size
);
535 ea_buf
->flag
= EA_EXTENT
| EA_NEW
;
537 ea_buf
->mp
= get_metapage(inode
, blkno
,
538 blocks_needed
<< sb
->s_blocksize_bits
,
540 if (ea_buf
->mp
== NULL
) {
541 dbFree(inode
, blkno
, (s64
) blocks_needed
);
545 ea_buf
->xattr
= ea_buf
->mp
->data
;
546 ea_buf
->max_size
= (min_size
+ sb
->s_blocksize
- 1) &
547 ~(sb
->s_blocksize
- 1);
550 if ((rc
= ea_read(inode
, ea_buf
->xattr
))) {
551 discard_metapage(ea_buf
->mp
);
552 dbFree(inode
, blkno
, (s64
) blocks_needed
);
557 ea_buf
->flag
= EA_EXTENT
;
558 ea_buf
->mp
= read_metapage(inode
, addressDXD(&ji
->ea
),
559 lengthDXD(&ji
->ea
) << sb
->s_blocksize_bits
,
561 if (ea_buf
->mp
== NULL
) {
565 ea_buf
->xattr
= ea_buf
->mp
->data
;
566 ea_buf
->max_size
= (ea_size
+ sb
->s_blocksize
- 1) &
567 ~(sb
->s_blocksize
- 1);
570 if (EALIST_SIZE(ea_buf
->xattr
) != ea_size
) {
571 printk(KERN_ERR
"ea_get: invalid extended attribute\n");
572 print_hex_dump(KERN_ERR
, "", DUMP_PREFIX_ADDRESS
, 16, 1,
573 ea_buf
->xattr
, ea_size
, 1);
574 ea_release(inode
, ea_buf
);
582 /* Rollback quota allocation */
583 if (quota_allocation
)
584 dquot_free_block(inode
, quota_allocation
);
589 static void ea_release(struct inode
*inode
, struct ea_buffer
*ea_buf
)
591 if (ea_buf
->flag
& EA_MALLOC
)
592 kfree(ea_buf
->xattr
);
593 else if (ea_buf
->flag
& EA_EXTENT
) {
595 release_metapage(ea_buf
->mp
);
597 if (ea_buf
->flag
& EA_NEW
)
598 dbFree(inode
, addressDXD(&ea_buf
->new_ea
),
599 lengthDXD(&ea_buf
->new_ea
));
603 static int ea_put(tid_t tid
, struct inode
*inode
, struct ea_buffer
*ea_buf
,
606 struct jfs_inode_info
*ji
= JFS_IP(inode
);
607 unsigned long old_blocks
, new_blocks
;
611 ea_release(inode
, ea_buf
);
613 } else if (ea_buf
->flag
& EA_INLINE
) {
614 assert(new_size
<= sizeof (ji
->i_inline_ea
));
615 ji
->mode2
&= ~INLINEEA
;
616 ea_buf
->new_ea
.flag
= DXD_INLINE
;
617 DXDsize(&ea_buf
->new_ea
, new_size
);
618 DXDaddress(&ea_buf
->new_ea
, 0);
619 DXDlength(&ea_buf
->new_ea
, 0);
620 } else if (ea_buf
->flag
& EA_MALLOC
) {
621 rc
= ea_write(inode
, ea_buf
->xattr
, new_size
, &ea_buf
->new_ea
);
622 kfree(ea_buf
->xattr
);
623 } else if (ea_buf
->flag
& EA_NEW
) {
624 /* We have already allocated a new dxd */
625 flush_metapage(ea_buf
->mp
);
627 /* ->xattr must point to original ea's metapage */
628 rc
= ea_write(inode
, ea_buf
->xattr
, new_size
, &ea_buf
->new_ea
);
629 discard_metapage(ea_buf
->mp
);
634 old_blocks
= new_blocks
= 0;
636 if (ji
->ea
.flag
& DXD_EXTENT
) {
637 invalidate_dxd_metapages(inode
, ji
->ea
);
638 old_blocks
= lengthDXD(&ji
->ea
);
642 txEA(tid
, inode
, &ji
->ea
, &ea_buf
->new_ea
);
643 if (ea_buf
->new_ea
.flag
& DXD_EXTENT
) {
644 new_blocks
= lengthDXD(&ea_buf
->new_ea
);
645 if (ji
->ea
.flag
& DXD_INLINE
)
646 ji
->mode2
|= INLINEEA
;
648 ji
->ea
= ea_buf
->new_ea
;
650 txEA(tid
, inode
, &ji
->ea
, NULL
);
651 if (ji
->ea
.flag
& DXD_INLINE
)
652 ji
->mode2
|= INLINEEA
;
657 /* If old blocks exist, they must be removed from quota allocation. */
659 dquot_free_block(inode
, old_blocks
);
661 inode
->i_ctime
= CURRENT_TIME
;
666 int __jfs_setxattr(tid_t tid
, struct inode
*inode
, const char *name
,
667 const void *value
, size_t value_len
, int flags
)
669 struct jfs_ea_list
*ealist
;
670 struct jfs_ea
*ea
, *old_ea
= NULL
, *next_ea
= NULL
;
671 struct ea_buffer ea_buf
;
675 int namelen
= strlen(name
);
680 down_write(&JFS_IP(inode
)->xattr_sem
);
682 xattr_size
= ea_get(inode
, &ea_buf
, 0);
683 if (xattr_size
< 0) {
689 ealist
= (struct jfs_ea_list
*) ea_buf
.xattr
;
690 new_size
= sizeof (struct jfs_ea_list
);
693 for (ea
= FIRST_EA(ealist
); ea
< END_EALIST(ealist
);
695 if ((namelen
== ea
->namelen
) &&
696 (memcmp(name
, ea
->name
, namelen
) == 0)) {
698 if (flags
& XATTR_CREATE
) {
703 old_ea_size
= EA_SIZE(ea
);
704 next_ea
= NEXT_EA(ea
);
706 new_size
+= EA_SIZE(ea
);
711 if (flags
& XATTR_REPLACE
) {
721 new_size
+= sizeof (struct jfs_ea
) + namelen
+ 1 + value_len
;
723 if (new_size
> ea_buf
.max_size
) {
725 * We need to allocate more space for merged ea list.
726 * We should only have loop to again: once.
728 ea_release(inode
, &ea_buf
);
729 xattr_size
= ea_get(inode
, &ea_buf
, new_size
);
730 if (xattr_size
< 0) {
737 /* Remove old ea of the same name */
739 /* number of bytes following target EA */
740 length
= (char *) END_EALIST(ealist
) - (char *) next_ea
;
742 memmove(old_ea
, next_ea
, length
);
743 xattr_size
-= old_ea_size
;
746 /* Add new entry to the end */
749 /* Completely new ea list */
750 xattr_size
= sizeof (struct jfs_ea_list
);
753 * The size of EA value is limitted by on-disk format up to
754 * __le16, there would be an overflow if the size is equal
755 * to XATTR_SIZE_MAX (65536). In order to avoid this issue,
756 * we can pre-checkup the value size against USHRT_MAX, and
757 * return -E2BIG in this case, which is consistent with the
758 * VFS setxattr interface.
760 if (value_len
>= USHRT_MAX
) {
765 ea
= (struct jfs_ea
*) ((char *) ealist
+ xattr_size
);
767 ea
->namelen
= namelen
;
768 ea
->valuelen
= (cpu_to_le16(value_len
));
769 memcpy(ea
->name
, name
, namelen
);
770 ea
->name
[namelen
] = 0;
772 memcpy(&ea
->name
[namelen
+ 1], value
, value_len
);
773 xattr_size
+= EA_SIZE(ea
);
776 /* DEBUG - If we did this right, these number match */
777 if (xattr_size
!= new_size
) {
779 "__jfs_setxattr: xattr_size = %d, new_size = %d\n",
780 xattr_size
, new_size
);
787 * If we're left with an empty list, there's no ea
789 if (new_size
== sizeof (struct jfs_ea_list
))
792 ealist
->size
= cpu_to_le32(new_size
);
794 rc
= ea_put(tid
, inode
, &ea_buf
, new_size
);
798 ea_release(inode
, &ea_buf
);
800 up_write(&JFS_IP(inode
)->xattr_sem
);
805 ssize_t
__jfs_getxattr(struct inode
*inode
, const char *name
, void *data
,
808 struct jfs_ea_list
*ealist
;
810 struct ea_buffer ea_buf
;
813 int namelen
= strlen(name
);
816 down_read(&JFS_IP(inode
)->xattr_sem
);
818 xattr_size
= ea_get(inode
, &ea_buf
, 0);
820 if (xattr_size
< 0) {
828 ealist
= (struct jfs_ea_list
*) ea_buf
.xattr
;
830 /* Find the named attribute */
831 for (ea
= FIRST_EA(ealist
); ea
< END_EALIST(ealist
); ea
= NEXT_EA(ea
))
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
);
849 ea_release(inode
, &ea_buf
);
851 up_read(&JFS_IP(inode
)->xattr_sem
);
857 * No special permissions are needed to list attributes except for trusted.*
859 static inline int can_list(struct jfs_ea
*ea
)
861 return (strncmp(ea
->name
, XATTR_TRUSTED_PREFIX
,
862 XATTR_TRUSTED_PREFIX_LEN
) ||
863 capable(CAP_SYS_ADMIN
));
866 ssize_t
jfs_listxattr(struct dentry
* dentry
, char *data
, size_t buf_size
)
868 struct inode
*inode
= d_inode(dentry
);
872 struct jfs_ea_list
*ealist
;
874 struct ea_buffer ea_buf
;
876 down_read(&JFS_IP(inode
)->xattr_sem
);
878 xattr_size
= ea_get(inode
, &ea_buf
, 0);
879 if (xattr_size
< 0) {
887 ealist
= (struct jfs_ea_list
*) ea_buf
.xattr
;
889 /* compute required size of list */
890 for (ea
= FIRST_EA(ealist
); ea
< END_EALIST(ealist
); ea
= NEXT_EA(ea
)) {
892 size
+= name_size(ea
) + 1;
898 if (size
> buf_size
) {
903 /* Copy attribute names to buffer */
905 for (ea
= FIRST_EA(ealist
); ea
< END_EALIST(ealist
); ea
= NEXT_EA(ea
)) {
907 int namelen
= copy_name(buffer
, ea
);
908 buffer
+= namelen
+ 1;
913 ea_release(inode
, &ea_buf
);
915 up_read(&JFS_IP(inode
)->xattr_sem
);
919 static int __jfs_xattr_set(struct inode
*inode
, const char *name
,
920 const void *value
, size_t size
, int flags
)
922 struct jfs_inode_info
*ji
= JFS_IP(inode
);
926 tid
= txBegin(inode
->i_sb
, 0);
927 mutex_lock(&ji
->commit_mutex
);
928 rc
= __jfs_setxattr(tid
, inode
, name
, value
, size
, flags
);
930 rc
= txCommit(tid
, 1, &inode
, 0);
932 mutex_unlock(&ji
->commit_mutex
);
937 static int jfs_xattr_get(const struct xattr_handler
*handler
,
938 struct dentry
*unused
, struct inode
*inode
,
939 const char *name
, void *value
, size_t size
)
941 name
= xattr_full_name(handler
, name
);
942 return __jfs_getxattr(inode
, name
, value
, size
);
945 static int jfs_xattr_set(const struct xattr_handler
*handler
,
946 struct dentry
*unused
, struct inode
*inode
,
947 const char *name
, const void *value
,
948 size_t size
, int flags
)
950 name
= xattr_full_name(handler
, name
);
951 return __jfs_xattr_set(inode
, name
, value
, size
, flags
);
954 static int jfs_xattr_get_os2(const struct xattr_handler
*handler
,
955 struct dentry
*unused
, struct inode
*inode
,
956 const char *name
, void *value
, size_t size
)
958 if (is_known_namespace(name
))
960 return __jfs_getxattr(inode
, name
, value
, size
);
963 static int jfs_xattr_set_os2(const struct xattr_handler
*handler
,
964 struct dentry
*unused
, struct inode
*inode
,
965 const char *name
, const void *value
,
966 size_t size
, int flags
)
968 if (is_known_namespace(name
))
970 return __jfs_xattr_set(inode
, name
, value
, size
, flags
);
973 static const struct xattr_handler jfs_user_xattr_handler
= {
974 .prefix
= XATTR_USER_PREFIX
,
975 .get
= jfs_xattr_get
,
976 .set
= jfs_xattr_set
,
979 static const struct xattr_handler jfs_os2_xattr_handler
= {
980 .prefix
= XATTR_OS2_PREFIX
,
981 .get
= jfs_xattr_get_os2
,
982 .set
= jfs_xattr_set_os2
,
985 static const struct xattr_handler jfs_security_xattr_handler
= {
986 .prefix
= XATTR_SECURITY_PREFIX
,
987 .get
= jfs_xattr_get
,
988 .set
= jfs_xattr_set
,
991 static const struct xattr_handler jfs_trusted_xattr_handler
= {
992 .prefix
= XATTR_TRUSTED_PREFIX
,
993 .get
= jfs_xattr_get
,
994 .set
= jfs_xattr_set
,
997 const struct xattr_handler
*jfs_xattr_handlers
[] = {
998 #ifdef CONFIG_JFS_POSIX_ACL
999 &posix_acl_access_xattr_handler
,
1000 &posix_acl_default_xattr_handler
,
1002 &jfs_os2_xattr_handler
,
1003 &jfs_user_xattr_handler
,
1004 &jfs_security_xattr_handler
,
1005 &jfs_trusted_xattr_handler
,
1010 #ifdef CONFIG_JFS_SECURITY
1011 static int jfs_initxattrs(struct inode
*inode
, const struct xattr
*xattr_array
,
1014 const struct xattr
*xattr
;
1015 tid_t
*tid
= fs_info
;
1019 for (xattr
= xattr_array
; xattr
->name
!= NULL
; xattr
++) {
1020 name
= kmalloc(XATTR_SECURITY_PREFIX_LEN
+
1021 strlen(xattr
->name
) + 1, GFP_NOFS
);
1026 strcpy(name
, XATTR_SECURITY_PREFIX
);
1027 strcpy(name
+ XATTR_SECURITY_PREFIX_LEN
, xattr
->name
);
1029 err
= __jfs_setxattr(*tid
, inode
, name
,
1030 xattr
->value
, xattr
->value_len
, 0);
1038 int jfs_init_security(tid_t tid
, struct inode
*inode
, struct inode
*dir
,
1039 const struct qstr
*qstr
)
1041 return security_inode_init_security(inode
, dir
, qstr
,
1042 &jfs_initxattrs
, &tid
);