2 * Copyright (C) International Business Machines Corp., 2000-2003
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
21 #include <linux/xattr.h>
22 #include "jfs_incore.h"
23 #include "jfs_superblock.h"
25 #include "jfs_debug.h"
26 #include "jfs_dinode.h"
27 #include "jfs_extent.h"
28 #include "jfs_metapage.h"
29 #include "jfs_xattr.h"
33 * jfs_xattr.c: extended attribute service
39 * Extended attribute lists (jfs_ea_list) consist of an overall size (32 bit
40 * value) and a variable (0 or more) number of extended attribute
41 * entries. Each extended attribute entry (jfs_ea) is a <name,value> double
42 * where <name> is constructed from a null-terminated ascii string
43 * (1 ... 255 bytes in the name) and <value> is arbitrary 8 bit data
44 * (1 ... 65535 bytes). The in-memory format is
46 * 0 1 2 4 4 + namelen + 1
47 * +-------+--------+--------+----------------+-------------------+
48 * | Flags | Name | Value | Name String \0 | Data . . . . |
49 * | | Length | Length | | |
50 * +-------+--------+--------+----------------+-------------------+
52 * A jfs_ea_list then is structured as
54 * 0 4 4 + EA_SIZE(ea1)
55 * +------------+-------------------+--------------------+-----
56 * | Overall EA | First FEA Element | Second FEA Element | .....
58 * +------------+-------------------+--------------------+-----
62 * FEALISTs are stored on disk using blocks allocated by dbAlloc() and
63 * written directly. An EA list may be in-lined in the inode if there is
64 * sufficient room available.
68 int flag; /* Indicates what storage xattr points to */
69 int max_size; /* largest xattr that fits in current buffer */
70 dxd_t new_ea; /* dxd to replace ea when modifying xattr */
71 struct metapage *mp; /* metapage containing ea list */
72 struct jfs_ea_list *xattr; /* buffer containing ea list */
76 * ea_buffer.flag values
78 #define EA_INLINE 0x0001
79 #define EA_EXTENT 0x0002
81 #define EA_MALLOC 0x0008
84 #define XATTR_SYSTEM_PREFIX "system."
85 #define XATTR_SYSTEM_PREFIX_LEN (sizeof (XATTR_SYSTEM_PREFIX) - 1)
87 #define XATTR_USER_PREFIX "user."
88 #define XATTR_USER_PREFIX_LEN (sizeof (XATTR_USER_PREFIX) - 1)
90 #define XATTR_OS2_PREFIX "os2."
91 #define XATTR_OS2_PREFIX_LEN (sizeof (XATTR_OS2_PREFIX) - 1)
94 * These three routines are used to recognize on-disk extended attributes
95 * that are in a recognized namespace. If the attribute is not recognized,
96 * "os2." is prepended to the name
98 static inline int is_os2_xattr(struct jfs_ea *ea)
101 * Check for "system."
103 if ((ea->namelen >= XATTR_SYSTEM_PREFIX_LEN) &&
104 !strncmp(ea->name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
109 if ((ea->namelen >= XATTR_USER_PREFIX_LEN) &&
110 !strncmp(ea->name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN))
113 * Add any other valid namespace prefixes here
117 * We assume it's OS/2's flat namespace
122 static inline int name_size(struct jfs_ea *ea)
124 if (is_os2_xattr(ea))
125 return ea->namelen + XATTR_OS2_PREFIX_LEN;
130 static inline int copy_name(char *buffer, struct jfs_ea *ea)
132 int len = ea->namelen;
134 if (is_os2_xattr(ea)) {
135 memcpy(buffer, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN);
136 buffer += XATTR_OS2_PREFIX_LEN;
137 len += XATTR_OS2_PREFIX_LEN;
139 memcpy(buffer, ea->name, ea->namelen);
140 buffer[ea->namelen] = 0;
145 /* Forward references */
146 static void ea_release(struct inode *inode, struct ea_buffer *ea_buf);
149 * NAME: ea_write_inline
151 * FUNCTION: Attempt to write an EA inline if area is available
154 * Already verified that the specified EA is small enough to fit inline
158 * ealist - EA list pointer
159 * size - size of ealist in bytes
160 * ea - dxd_t structure to be filled in with necessary EA information
161 * if we successfully copy the EA inline
164 * Checks if the inode's inline area is available. If so, copies EA inline
165 * and sets <ea> fields appropriately. Otherwise, returns failure, EA will
166 * have to be put into an extent.
168 * RETURNS: 0 for successful copy to inline area; -1 if area not available
170 static int ea_write_inline(struct inode *ip, struct jfs_ea_list *ealist,
171 int size, dxd_t * ea)
173 struct jfs_inode_info *ji = JFS_IP(ip);
176 * Make sure we have an EA -- the NULL EA list is valid, but you
179 if (ealist && size > sizeof (struct jfs_ea_list)) {
180 assert(size <= sizeof (ji->i_inline_ea));
183 * See if the space is available or if it is already being
184 * used for an inline EA.
186 if (!(ji->mode2 & INLINEEA) && !(ji->ea.flag & DXD_INLINE))
192 memcpy(ji->i_inline_ea, ealist, size);
193 ea->flag = DXD_INLINE;
194 ji->mode2 &= ~INLINEEA;
201 /* Free up INLINE area */
202 if (ji->ea.flag & DXD_INLINE)
203 ji->mode2 |= INLINEEA;
212 * FUNCTION: Write an EA for an inode
214 * PRE CONDITIONS: EA has been verified
218 * ealist - EA list pointer
219 * size - size of ealist in bytes
220 * ea - dxd_t structure to be filled in appropriately with where the
223 * NOTES: Will write EA inline if able to, otherwise allocates blocks for an
224 * extent and synchronously writes it to those blocks.
226 * RETURNS: 0 for success; Anything else indicates failure
228 static int ea_write(struct inode *ip, struct jfs_ea_list *ealist, int size,
231 struct super_block *sb = ip->i_sb;
232 struct jfs_inode_info *ji = JFS_IP(ip);
233 struct jfs_sb_info *sbi = JFS_SBI(sb);
243 * Quick check to see if this is an in-linable EA. Short EAs
244 * and empty EAs are all in-linable, provided the space exists.
246 if (!ealist || size <= sizeof (ji->i_inline_ea)) {
247 if (!ea_write_inline(ip, ealist, size, ea))
251 /* figure out how many blocks we need */
252 nblocks = (size + (sb->s_blocksize - 1)) >> sb->s_blocksize_bits;
254 rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
259 * Now have nblocks worth of storage to stuff into the FEALIST.
260 * loop over the FEALIST copying data into the buffer one page at
263 cp = (char *) ealist;
265 for (i = 0; i < nblocks; i += sbi->nbperpage) {
267 * Determine how many bytes for this request, and round up to
268 * the nearest aggregate block size
270 nb = min(PSIZE, nbytes);
272 ((((nb + sb->s_blocksize - 1)) >> sb->s_blocksize_bits))
273 << sb->s_blocksize_bits;
275 if (!(mp = get_metapage(ip, blkno + i, bytes_to_write, 1))) {
280 memcpy(mp->data, cp, nb);
283 * We really need a way to propagate errors for
284 * forced writes like this one. --hch
286 * (__write_metapage => release_metapage => flush_metapage)
289 if ((rc = flush_metapage(mp))) {
291 * the write failed -- this means that the buffer
292 * is still assigned and the blocks are not being
293 * used. this seems like the best error recovery
306 ea->flag = DXD_EXTENT;
307 DXDsize(ea, le32_to_cpu(ealist->size));
308 DXDlength(ea, nblocks);
309 DXDaddress(ea, blkno);
311 /* Free up INLINE area */
312 if (ji->ea.flag & DXD_INLINE)
313 ji->mode2 |= INLINEEA;
318 dbFree(ip, blkno, nblocks);
323 * NAME: ea_read_inline
325 * FUNCTION: Read an inlined EA into user's buffer
329 * ealist - Pointer to buffer to fill in with EA
333 static int ea_read_inline(struct inode *ip, struct jfs_ea_list *ealist)
335 struct jfs_inode_info *ji = JFS_IP(ip);
336 int ea_size = sizeDXD(&ji->ea);
344 if ((sizeDXD(&ji->ea) > sizeof (ji->i_inline_ea)))
346 if (le32_to_cpu(((struct jfs_ea_list *) &ji->i_inline_ea)->size)
350 memcpy(ealist, ji->i_inline_ea, ea_size);
357 * FUNCTION: copy EA data into user's buffer
361 * ealist - Pointer to buffer to fill in with EA
363 * NOTES: If EA is inline calls ea_read_inline() to copy EA.
365 * RETURNS: 0 for success; other indicates failure
367 static int ea_read(struct inode *ip, struct jfs_ea_list *ealist)
369 struct super_block *sb = ip->i_sb;
370 struct jfs_inode_info *ji = JFS_IP(ip);
371 struct jfs_sb_info *sbi = JFS_SBI(sb);
374 char *cp = (char *) ealist;
380 /* quick check for in-line EA */
381 if (ji->ea.flag & DXD_INLINE)
382 return ea_read_inline(ip, ealist);
384 nbytes = sizeDXD(&ji->ea);
386 jfs_error(sb, "ea_read: nbytes is 0");
391 * Figure out how many blocks were allocated when this EA list was
392 * originally written to disk.
394 nblocks = lengthDXD(&ji->ea) << sbi->l2nbperpage;
395 blkno = addressDXD(&ji->ea) << sbi->l2nbperpage;
398 * I have found the disk blocks which were originally used to store
399 * the FEALIST. now i loop over each contiguous block copying the
400 * data into the buffer.
402 for (i = 0; i < nblocks; i += sbi->nbperpage) {
404 * Determine how many bytes for this request, and round up to
405 * the nearest aggregate block size
407 nb = min(PSIZE, nbytes);
409 ((((nb + sb->s_blocksize - 1)) >> sb->s_blocksize_bits))
410 << sb->s_blocksize_bits;
412 if (!(mp = read_metapage(ip, blkno + i, bytes_to_read, 1)))
415 memcpy(cp, mp->data, nb);
416 release_metapage(mp);
428 * FUNCTION: Returns buffer containing existing extended attributes.
429 * The size of the buffer will be the larger of the existing
430 * attributes size, or min_size.
432 * The buffer, which may be inlined in the inode or in the
433 * page cache must be release by calling ea_release or ea_put
436 * inode - Inode pointer
437 * ea_buf - Structure to be populated with ealist and its metadata
438 * min_size- minimum size of buffer to be returned
440 * RETURNS: 0 for success; Other indicates failure
442 static int ea_get(struct inode *inode, struct ea_buffer *ea_buf, int min_size)
444 struct jfs_inode_info *ji = JFS_IP(inode);
445 struct super_block *sb = inode->i_sb;
447 int ea_size = sizeDXD(&ji->ea);
448 int blocks_needed, current_blocks;
452 /* When fsck.jfs clears a bad ea, it doesn't clear the size */
453 if (ji->ea.flag == 0)
459 ea_buf->max_size = 0;
460 ea_buf->xattr = NULL;
463 if ((min_size <= sizeof (ji->i_inline_ea)) &&
464 (ji->mode2 & INLINEEA)) {
465 ea_buf->flag = EA_INLINE | EA_NEW;
466 ea_buf->max_size = sizeof (ji->i_inline_ea);
467 ea_buf->xattr = (struct jfs_ea_list *) ji->i_inline_ea;
468 DXDlength(&ea_buf->new_ea, 0);
469 DXDaddress(&ea_buf->new_ea, 0);
470 ea_buf->new_ea.flag = DXD_INLINE;
471 DXDsize(&ea_buf->new_ea, min_size);
475 } else if (ji->ea.flag & DXD_INLINE) {
476 if (min_size <= sizeof (ji->i_inline_ea)) {
477 ea_buf->flag = EA_INLINE;
478 ea_buf->max_size = sizeof (ji->i_inline_ea);
479 ea_buf->xattr = (struct jfs_ea_list *) ji->i_inline_ea;
484 if (!(ji->ea.flag & DXD_EXTENT)) {
485 jfs_error(sb, "ea_get: invalid ea.flag)");
488 current_blocks = (ea_size + sb->s_blocksize - 1) >>
489 sb->s_blocksize_bits;
491 size = max(min_size, ea_size);
495 * To keep the rest of the code simple. Allocate a
496 * contiguous buffer to work with
498 ea_buf->xattr = kmalloc(size, GFP_KERNEL);
499 if (ea_buf->xattr == NULL)
502 ea_buf->flag = EA_MALLOC;
503 ea_buf->max_size = (size + sb->s_blocksize - 1) &
504 ~(sb->s_blocksize - 1);
509 if ((rc = ea_read(inode, ea_buf->xattr))) {
510 kfree(ea_buf->xattr);
511 ea_buf->xattr = NULL;
516 blocks_needed = (min_size + sb->s_blocksize - 1) >>
517 sb->s_blocksize_bits;
519 if (blocks_needed > current_blocks) {
520 rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
525 DXDlength(&ea_buf->new_ea, blocks_needed);
526 DXDaddress(&ea_buf->new_ea, blkno);
527 ea_buf->new_ea.flag = DXD_EXTENT;
528 DXDsize(&ea_buf->new_ea, min_size);
530 ea_buf->flag = EA_EXTENT | EA_NEW;
532 ea_buf->mp = get_metapage(inode, blkno,
533 blocks_needed << sb->s_blocksize_bits,
535 if (ea_buf->mp == NULL) {
536 dbFree(inode, blkno, (s64) blocks_needed);
539 ea_buf->xattr = ea_buf->mp->data;
540 ea_buf->max_size = (min_size + sb->s_blocksize - 1) &
541 ~(sb->s_blocksize - 1);
544 if ((rc = ea_read(inode, ea_buf->xattr))) {
545 discard_metapage(ea_buf->mp);
546 dbFree(inode, blkno, (s64) blocks_needed);
551 ea_buf->flag = EA_EXTENT;
552 ea_buf->mp = read_metapage(inode, addressDXD(&ji->ea),
553 lengthDXD(&ji->ea), 1);
554 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 printk(KERN_ERR "ea_get: invalid extended attribute\n");
563 dump_mem("xattr", ea_buf->xattr, ea_size);
564 ea_release(inode, ea_buf);
571 static void ea_release(struct inode *inode, struct ea_buffer *ea_buf)
573 if (ea_buf->flag & EA_MALLOC)
574 kfree(ea_buf->xattr);
575 else if (ea_buf->flag & EA_EXTENT) {
577 release_metapage(ea_buf->mp);
579 if (ea_buf->flag & EA_NEW)
580 dbFree(inode, addressDXD(&ea_buf->new_ea),
581 lengthDXD(&ea_buf->new_ea));
585 static int ea_put(struct inode *inode, struct ea_buffer *ea_buf, int new_size)
587 struct jfs_inode_info *ji = JFS_IP(inode);
588 unsigned long old_blocks, new_blocks;
593 ea_release(inode, ea_buf);
595 } else if (ea_buf->flag & EA_INLINE) {
596 assert(new_size <= sizeof (ji->i_inline_ea));
597 ji->mode2 &= ~INLINEEA;
598 ea_buf->new_ea.flag = DXD_INLINE;
599 DXDsize(&ea_buf->new_ea, new_size);
600 DXDaddress(&ea_buf->new_ea, 0);
601 DXDlength(&ea_buf->new_ea, 0);
602 } else if (ea_buf->flag & EA_MALLOC) {
603 rc = ea_write(inode, ea_buf->xattr, new_size, &ea_buf->new_ea);
604 kfree(ea_buf->xattr);
605 } else if (ea_buf->flag & EA_NEW) {
606 /* We have already allocated a new dxd */
607 flush_metapage(ea_buf->mp);
609 /* ->xattr must point to original ea's metapage */
610 rc = ea_write(inode, ea_buf->xattr, new_size, &ea_buf->new_ea);
611 discard_metapage(ea_buf->mp);
616 tid = txBegin(inode->i_sb, 0);
617 down(&ji->commit_sem);
619 old_blocks = new_blocks = 0;
621 if (ji->ea.flag & DXD_EXTENT) {
622 invalidate_dxd_metapages(inode, ji->ea);
623 old_blocks = lengthDXD(&ji->ea);
627 txEA(tid, inode, &ji->ea, &ea_buf->new_ea);
628 if (ea_buf->new_ea.flag & DXD_EXTENT) {
629 new_blocks = lengthDXD(&ea_buf->new_ea);
630 if (ji->ea.flag & DXD_INLINE)
631 ji->mode2 |= INLINEEA;
633 ji->ea = ea_buf->new_ea;
635 txEA(tid, inode, &ji->ea, 0);
636 if (ji->ea.flag & DXD_INLINE)
637 ji->mode2 |= INLINEEA;
642 inode->i_blocks += LBLK2PBLK(inode->i_sb, new_blocks - old_blocks);
643 inode->i_ctime = CURRENT_TIME;
644 rc = txCommit(tid, 1, &inode, 0);
652 * can_set_system_xattr
654 * This code is specific to the system.* namespace. It contains policy
655 * which doesn't belong in the main xattr codepath.
657 static int can_set_system_xattr(struct inode *inode, const char *name,
658 const void *value, size_t value_len)
660 #ifdef CONFIG_JFS_POSIX_ACL
661 struct posix_acl *acl;
664 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
668 * XATTR_NAME_ACL_ACCESS is tied to i_mode
670 if (strcmp(name, XATTR_NAME_ACL_ACCESS) == 0) {
671 acl = posix_acl_from_xattr(value, value_len);
674 printk(KERN_ERR "posix_acl_from_xattr returned %d\n",
679 mode_t mode = inode->i_mode;
680 rc = posix_acl_equiv_mode(acl, &mode);
681 posix_acl_release(acl);
684 "posix_acl_equiv_mode returned %d\n",
688 inode->i_mode = mode;
689 mark_inode_dirty(inode);
694 * We're changing the ACL. Get rid of the cached one
696 acl =JFS_IP(inode)->i_acl;
697 if (acl && (acl != JFS_ACL_NOT_CACHED))
698 posix_acl_release(acl);
699 JFS_IP(inode)->i_acl = JFS_ACL_NOT_CACHED;
700 } else if (strcmp(name, XATTR_NAME_ACL_DEFAULT) == 0) {
702 * We're changing the default ACL. Get rid of the cached one
704 acl =JFS_IP(inode)->i_default_acl;
705 if (acl && (acl != JFS_ACL_NOT_CACHED))
706 posix_acl_release(acl);
707 JFS_IP(inode)->i_default_acl = JFS_ACL_NOT_CACHED;
709 /* Invalid xattr name */
712 #else /* CONFIG_JFS_POSIX_ACL */
714 #endif /* CONFIG_JFS_POSIX_ACL */
717 static int can_set_xattr(struct inode *inode, const char *name,
718 const void *value, size_t value_len)
720 if (IS_RDONLY(inode))
723 if (IS_IMMUTABLE(inode) || IS_APPEND(inode) || S_ISLNK(inode->i_mode))
726 if(strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) == 0)
730 return can_set_system_xattr(inode, name, value, value_len);
732 if((strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) != 0) &&
733 (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) != 0))
736 if (!S_ISREG(inode->i_mode) &&
737 (!S_ISDIR(inode->i_mode) || inode->i_mode &S_ISVTX))
740 #ifdef CONFIG_JFS_POSIX_ACL
741 return jfs_permission(inode, MAY_WRITE, NULL);
743 return permission(inode, MAY_WRITE, NULL);
747 int __jfs_setxattr(struct inode *inode, const char *name, const void *value,
748 size_t value_len, int flags)
750 struct jfs_ea_list *ealist;
751 struct jfs_ea *ea, *old_ea = NULL, *next_ea = NULL;
752 struct ea_buffer ea_buf;
756 int namelen = strlen(name);
757 char *os2name = NULL;
762 if ((rc = can_set_xattr(inode, name, value, value_len)))
765 if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
766 os2name = kmalloc(namelen - XATTR_OS2_PREFIX_LEN + 1,
770 strcpy(os2name, name + XATTR_OS2_PREFIX_LEN);
772 namelen -= XATTR_OS2_PREFIX_LEN;
775 down_write(&JFS_IP(inode)->xattr_sem);
777 xattr_size = ea_get(inode, &ea_buf, 0);
778 if (xattr_size < 0) {
784 ealist = (struct jfs_ea_list *) ea_buf.xattr;
785 new_size = sizeof (struct jfs_ea_list);
788 for (ea = FIRST_EA(ealist); ea < END_EALIST(ealist);
790 if ((namelen == ea->namelen) &&
791 (memcmp(name, ea->name, namelen) == 0)) {
793 if (flags & XATTR_CREATE) {
798 old_ea_size = EA_SIZE(ea);
799 next_ea = NEXT_EA(ea);
801 new_size += EA_SIZE(ea);
806 if (flags & XATTR_REPLACE) {
816 new_size += sizeof (struct jfs_ea) + namelen + 1 + value_len;
818 if (new_size > ea_buf.max_size) {
820 * We need to allocate more space for merged ea list.
821 * We should only have loop to again: once.
823 ea_release(inode, &ea_buf);
824 xattr_size = ea_get(inode, &ea_buf, new_size);
825 if (xattr_size < 0) {
832 /* Remove old ea of the same name */
834 /* number of bytes following target EA */
835 length = (char *) END_EALIST(ealist) - (char *) next_ea;
837 memmove(old_ea, next_ea, length);
838 xattr_size -= old_ea_size;
841 /* Add new entry to the end */
844 /* Completely new ea list */
845 xattr_size = sizeof (struct jfs_ea_list);
847 ea = (struct jfs_ea *) ((char *) ealist + xattr_size);
849 ea->namelen = namelen;
850 ea->valuelen = (cpu_to_le16(value_len));
851 memcpy(ea->name, name, namelen);
852 ea->name[namelen] = 0;
854 memcpy(&ea->name[namelen + 1], value, value_len);
855 xattr_size += EA_SIZE(ea);
858 /* DEBUG - If we did this right, these number match */
859 if (xattr_size != new_size) {
861 "jfs_xsetattr: xattr_size = %d, new_size = %d\n",
862 xattr_size, new_size);
869 * If we're left with an empty list, there's no ea
871 if (new_size == sizeof (struct jfs_ea_list))
874 ealist->size = cpu_to_le32(new_size);
876 rc = ea_put(inode, &ea_buf, new_size);
880 ea_release(inode, &ea_buf);
882 up_write(&JFS_IP(inode)->xattr_sem);
890 int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
891 size_t value_len, int flags)
893 if (value == NULL) { /* empty EA, do not remove */
898 return __jfs_setxattr(dentry->d_inode, name, value, value_len, flags);
901 static int can_get_xattr(struct inode *inode, const char *name)
903 #ifdef CONFIG_JFS_POSIX_ACL
904 if(strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) == 0)
906 return jfs_permission(inode, MAY_READ, NULL);
908 return permission(inode, MAY_READ, NULL);
912 ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data,
915 struct jfs_ea_list *ealist;
917 struct ea_buffer ea_buf;
920 int namelen = strlen(name);
921 char *os2name = NULL;
925 if ((rc = can_get_xattr(inode, name)))
928 if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
929 os2name = kmalloc(namelen - XATTR_OS2_PREFIX_LEN + 1,
933 strcpy(os2name, name + XATTR_OS2_PREFIX_LEN);
935 namelen -= XATTR_OS2_PREFIX_LEN;
938 down_read(&JFS_IP(inode)->xattr_sem);
940 xattr_size = ea_get(inode, &ea_buf, 0);
942 if (xattr_size < 0) {
950 ealist = (struct jfs_ea_list *) ea_buf.xattr;
952 /* Find the named attribute */
953 for (ea = FIRST_EA(ealist); ea < END_EALIST(ealist); ea = NEXT_EA(ea))
954 if ((namelen == ea->namelen) &&
955 memcmp(name, ea->name, namelen) == 0) {
957 size = le16_to_cpu(ea->valuelen);
960 else if (size > buf_size) {
964 value = ((char *) &ea->name) + ea->namelen + 1;
965 memcpy(data, value, size);
971 ea_release(inode, &ea_buf);
973 up_read(&JFS_IP(inode)->xattr_sem);
981 ssize_t jfs_getxattr(struct dentry *dentry, const char *name, void *data,
986 err = __jfs_getxattr(dentry->d_inode, name, data, buf_size);
991 ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size)
993 struct inode *inode = dentry->d_inode;
997 struct jfs_ea_list *ealist;
999 struct ea_buffer ea_buf;
1001 down_read(&JFS_IP(inode)->xattr_sem);
1003 xattr_size = ea_get(inode, &ea_buf, 0);
1004 if (xattr_size < 0) {
1009 if (xattr_size == 0)
1012 ealist = (struct jfs_ea_list *) ea_buf.xattr;
1014 /* compute required size of list */
1015 for (ea = FIRST_EA(ealist); ea < END_EALIST(ealist); ea = NEXT_EA(ea))
1016 size += name_size(ea) + 1;
1021 if (size > buf_size) {
1026 /* Copy attribute names to buffer */
1028 for (ea = FIRST_EA(ealist); ea < END_EALIST(ealist); ea = NEXT_EA(ea)) {
1029 int namelen = copy_name(buffer, ea);
1030 buffer += namelen + 1;
1034 ea_release(inode, &ea_buf);
1036 up_read(&JFS_IP(inode)->xattr_sem);
1040 int jfs_removexattr(struct dentry *dentry, const char *name)
1042 return __jfs_setxattr(dentry->d_inode, name, 0, 0, XATTR_REPLACE);