1 --------------------------------------------------------------------
2 This patch adds extended attribute support for JFS 1.1.2.
4 This patch was built against linux-2.4.20 + ea+acl+nfsacl-2.4.20-0.8.57 +
5 JFS 1.1.2 (remove fs/jfs/xattr.c & fs/jfs/jfs_xattr.h before applying patch)
7 ea+acl+nfsacl-2.4.20-08.57 is available from http://acl.bestbits.at/
8 --------------------------------------------------------------------
9 diff -Nur linux-2.4.20/fs/jfs/Makefile linux-ea/fs/jfs/Makefile
10 --- linux-2.4.20/fs/jfs/Makefile 2003-05-08 14:10:45.000000000 -0500
11 +++ linux-ea/fs/jfs/Makefile 2003-05-08 14:13:00.000000000 -0500
13 jfs_xtree.o jfs_imap.o jfs_debug.o jfs_dmap.o \
14 jfs_unicode.o jfs_dtree.o jfs_inode.o \
15 jfs_extent.o symlink.o jfs_metapage.o \
16 - jfs_logmgr.o jfs_txnmgr.o jfs_uniupr.o resize.o
17 + jfs_logmgr.o jfs_txnmgr.o jfs_uniupr.o resize.o xattr.o
20 EXTRA_CFLAGS += -D_JFS_4K
21 diff -Nur linux-2.4.20/fs/jfs/file.c linux-ea/fs/jfs/file.c
22 --- linux-2.4.20/fs/jfs/file.c 2003-05-08 14:10:45.000000000 -0500
23 +++ linux-ea/fs/jfs/file.c 2003-05-08 14:13:00.000000000 -0500
25 #include "jfs_incore.h"
27 #include "jfs_txnmgr.h"
28 +#include "jfs_xattr.h"
29 #include "jfs_debug.h"
34 struct inode_operations jfs_file_inode_operations = {
35 .truncate = jfs_truncate,
36 + .setxattr = jfs_setxattr,
37 + .getxattr = jfs_getxattr,
38 + .listxattr = jfs_listxattr,
39 + .removexattr = jfs_removexattr,
42 struct file_operations jfs_file_operations = {
45 .release = jfs_release,
48 +struct inode_operations jfs_special_inode_operations = {
49 + .setxattr = jfs_setxattr,
50 + .getxattr = jfs_getxattr,
51 + .listxattr = jfs_listxattr,
52 + .removexattr = jfs_removexattr,
55 diff -Nur linux-2.4.20/fs/jfs/inode.c linux-ea/fs/jfs/inode.c
56 --- linux-2.4.20/fs/jfs/inode.c 2003-05-08 14:10:45.000000000 -0500
57 +++ linux-ea/fs/jfs/inode.c 2003-05-08 14:13:00.000000000 -0500
59 extern struct inode_operations jfs_dir_inode_operations;
60 extern struct inode_operations jfs_file_inode_operations;
61 extern struct inode_operations jfs_symlink_inode_operations;
62 +extern struct inode_operations jfs_special_inode_operations;
63 extern struct file_operations jfs_dir_operations;
64 extern struct file_operations jfs_file_operations;
65 struct address_space_operations jfs_aops;
68 inode->i_op = &jfs_symlink_inode_operations;
70 + inode->i_op = &jfs_special_inode_operations;
71 init_special_inode(inode, inode->i_mode,
72 kdev_t_to_nr(inode->i_rdev));
74 diff -Nur linux-2.4.20/fs/jfs/jfs_imap.c linux-ea/fs/jfs/jfs_imap.c
75 --- linux-2.4.20/fs/jfs/jfs_imap.c 2003-05-08 14:10:45.000000000 -0500
76 +++ linux-ea/fs/jfs/jfs_imap.c 2003-05-08 14:13:00.000000000 -0500
78 memcpy(&dp->di_fastsymlink, jfs_ip->i_inline, IDATASIZE);
81 -#ifdef _STILL_TO_PORT
83 * copy inline data from in-memory inode to on-disk inode:
84 * 128 byte slot granularity
86 - if (test_cflag(COMMIT_Inlineea, ip))
87 + if (test_cflag(COMMIT_Inlineea, ip)) {
88 lv = & dilinelock->lv[dilinelock->index];
89 lv->offset = (dioffset + 3 * 128) >> L2INODESLOTSIZE;
91 - memcpy(&dp->di_inlineea, &ip->i_inlineea, INODESLOTSIZE);
92 + memcpy(&dp->di_inlineea, &jfs_ip->i_inline_ea, INODESLOTSIZE);
95 clear_cflag(COMMIT_Inlineea, ip);
97 -#endif /* _STILL_TO_PORT */
100 * lock/copy inode base: 128 byte slot granularity
101 @@ -3046,16 +3044,17 @@
102 jfs_ip->next_index = le32_to_cpu(dip->di_next_index);
103 jfs_ip->otime = le32_to_cpu(dip->di_otime.tv_sec);
104 jfs_ip->acltype = le32_to_cpu(dip->di_acltype);
106 - * We may only need to do this for "special" inodes (dmap, imap)
109 if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode))
110 ip->i_rdev = to_kdev_t(le32_to_cpu(dip->di_rdev));
111 - else if (S_ISDIR(ip->i_mode)) {
113 + if (S_ISDIR(ip->i_mode)) {
114 memcpy(&jfs_ip->i_dirtable, &dip->di_dirtable, 384);
115 - } else if (!S_ISFIFO(ip->i_mode)) {
116 + } else if (S_ISREG(ip->i_mode) || S_ISLNK(ip->i_mode)) {
117 memcpy(&jfs_ip->i_xtroot, &dip->di_xtroot, 288);
120 + memcpy(&jfs_ip->i_inline_ea, &dip->di_inlineea, 128);
122 /* Zero the in-memory-only stuff */
125 diff -Nur linux-2.4.20/fs/jfs/jfs_incore.h linux-ea/fs/jfs/jfs_incore.h
126 --- linux-2.4.20/fs/jfs/jfs_incore.h 2003-05-08 14:10:45.000000000 -0500
127 +++ linux-ea/fs/jfs/jfs_incore.h 2003-05-08 14:13:01.000000000 -0500
129 unchar _unused[16]; /* 16: */
130 dxd_t _dxd; /* 16: */
131 unchar _inline[128]; /* 128: inline symlink */
132 + /* _inline_ea may overlay the last part of
133 + * file._xtroot if maxentry = XTROOTINITSLOT
135 + unchar _inline_ea[128]; /* 128: inline extended attr */
140 #define i_dirtable u.dir._table
141 #define i_dtroot u.dir._dtroot
142 #define i_inline u.link._inline
143 +#define i_inline_ea u.link._inline_ea
146 #define IREAD_LOCK(ip) down_read(&JFS_IP(ip)->rdwrlock)
147 diff -Nur linux-2.4.20/fs/jfs/jfs_metapage.h linux-ea/fs/jfs/jfs_metapage.h
148 --- linux-2.4.20/fs/jfs/jfs_metapage.h 2003-05-08 14:10:45.000000000 -0500
149 +++ linux-ea/fs/jfs/jfs_metapage.h 2003-05-08 14:13:01.000000000 -0500
154 - * This routines invalidate all pages for an extent.
155 + * These routines invalidate all pages for an extent.
157 extern void __invalidate_metapages(struct inode *, s64, int);
158 #define invalidate_pxd_metapages(ip, pxd) \
159 diff -Nur linux-2.4.20/fs/jfs/jfs_types.h linux-ea/fs/jfs/jfs_types.h
160 --- linux-2.4.20/fs/jfs/jfs_types.h 2003-05-08 14:10:45.000000000 -0500
161 +++ linux-ea/fs/jfs/jfs_types.h 2003-05-08 14:13:01.000000000 -0500
163 #define DXDaddress PXDaddress
164 #define lengthDXD lengthPXD
165 #define addressDXD addressPXD
166 +#define DXDsize(dxd, size32) ((dxd)->size = cpu_to_le32(size32))
167 +#define sizeDXD(dxd) le32_to_cpu((dxd)->size)
170 * directory entry argument
171 diff -Nur linux-2.4.20/fs/jfs/jfs_xattr.h linux-ea/fs/jfs/jfs_xattr.h
172 --- linux-2.4.20/fs/jfs/jfs_xattr.h 1969-12-31 18:00:00.000000000 -0600
173 +++ linux-ea/fs/jfs/jfs_xattr.h 2003-05-08 14:28:35.000000000 -0500
176 + * Copyright (c) International Business Machines Corp., 2000-2002
178 + * This program is free software; you can redistribute it and/or modify
179 + * it under the terms of the GNU General Public License as published by
180 + * the Free Software Foundation; either version 2 of the License, or
181 + * (at your option) any later version.
183 + * This program is distributed in the hope that it will be useful,
184 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
185 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
186 + * the GNU General Public License for more details.
188 + * You should have received a copy of the GNU General Public License
189 + * along with this program; if not, write to the Free Software
190 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
197 + * jfs_ea_list describe the on-disk format of the extended attributes.
198 + * I know the null-terminator is redundant since namelen is stored, but
199 + * I am maintaining compatibility with OS/2 where possible.
202 + u8 flag; /* Unused? */
203 + u8 namelen; /* Length of name */
204 + u16 valuelen; /* Length of value */
205 + char name[0]; /* Attribute name (includes null-terminator) */
206 +}; /* Value immediately follows name */
208 +struct jfs_ea_list {
209 + u32 size; /* overall size */
210 + struct jfs_ea ea[0]; /* Variable length list */
213 +/* Macros for defining maxiumum number of bytes supported for EAs */
214 +#define MAXEASIZE 65535
215 +#define MAXEALISTSIZE MAXEASIZE
218 + * some macros for dealing with variable length EA lists.
220 +#define EA_SIZE(ea) \
221 + (sizeof (struct jfs_ea) + (ea)->namelen + 1 + \
222 + le16_to_cpu((ea)->valuelen))
223 +#define NEXT_EA(ea) ((struct jfs_ea *) (((char *) (ea)) + (EA_SIZE (ea))))
224 +#define FIRST_EA(ealist) ((ealist)->ea)
225 +#define EALIST_SIZE(ealist) le32_to_cpu((ealist)->size)
226 +#define END_EALIST(ealist) \
227 + ((struct jfs_ea *) (((char *) (ealist)) + EALIST_SIZE(ealist)))
229 +extern int __jfs_setxattr(struct inode *, const char *, const void *, size_t,
231 +extern int jfs_setxattr(struct dentry *, const char *, const void *, size_t,
233 +extern ssize_t __jfs_getxattr(struct inode *, const char *, void *, size_t);
234 +extern ssize_t jfs_getxattr(struct dentry *, const char *, void *, size_t);
235 +extern ssize_t jfs_listxattr(struct dentry *, char *, size_t);
236 +extern int jfs_removexattr(struct dentry *, const char *);
238 +#endif /* H_JFS_XATTR */
239 diff -Nur linux-2.4.20/fs/jfs/namei.c linux-ea/fs/jfs/namei.c
240 --- linux-2.4.20/fs/jfs/namei.c 2003-05-08 14:10:45.000000000 -0500
241 +++ linux-ea/fs/jfs/namei.c 2003-05-08 14:13:01.000000000 -0500
243 #include "jfs_dmap.h"
244 #include "jfs_unicode.h"
245 #include "jfs_metapage.h"
246 +#include "jfs_xattr.h"
247 #include "jfs_debug.h"
249 extern struct inode_operations jfs_file_inode_operations;
250 extern struct inode_operations jfs_symlink_inode_operations;
251 +extern struct inode_operations jfs_special_inode_operations;
252 extern struct file_operations jfs_file_operations;
253 extern struct address_space_operations jfs_aops;
255 @@ -1316,6 +1318,7 @@
256 if ((rc = dtInsert(tid, dir, &dname, &ino, &btstack)))
259 + ip->i_op = &jfs_special_inode_operations;
260 init_special_inode(ip, ip->i_mode, rdev);
262 insert_inode_hash(ip);
263 @@ -1400,6 +1403,10 @@
266 .rename = jfs_rename,
267 + .setxattr = jfs_setxattr,
268 + .getxattr = jfs_getxattr,
269 + .listxattr = jfs_listxattr,
270 + .removexattr = jfs_removexattr,
273 struct file_operations jfs_dir_operations = {
274 diff -Nur linux-2.4.20/fs/jfs/symlink.c linux-ea/fs/jfs/symlink.c
275 --- linux-2.4.20/fs/jfs/symlink.c 2003-05-08 14:10:45.000000000 -0500
276 +++ linux-ea/fs/jfs/symlink.c 2003-05-08 14:13:01.000000000 -0500
279 #include <linux/fs.h>
280 #include "jfs_incore.h"
281 +#include "jfs_xattr.h"
283 static int jfs_follow_link(struct dentry *dentry, struct nameidata *nd)
286 struct inode_operations jfs_symlink_inode_operations = {
287 .readlink = jfs_readlink,
288 .follow_link = jfs_follow_link,
289 + .setxattr = jfs_setxattr,
290 + .getxattr = jfs_getxattr,
291 + .listxattr = jfs_listxattr,
292 + .removexattr = jfs_removexattr,
295 diff -Nur linux-2.4.20/fs/jfs/xattr.c linux-ea/fs/jfs/xattr.c
296 --- linux-2.4.20/fs/jfs/xattr.c 1969-12-31 18:00:00.000000000 -0600
297 +++ linux-ea/fs/jfs/xattr.c 2003-05-08 14:30:04.000000000 -0500
300 + * Copyright (c) International Business Machines Corp., 2000-2002
301 + * Copyright (c) Christoph Hellwig, 2002
303 + * This program is free software; you can redistribute it and/or modify
304 + * it under the terms of the GNU General Public License as published by
305 + * the Free Software Foundation; either version 2 of the License, or
306 + * (at your option) any later version.
308 + * This program is distributed in the hope that it will be useful,
309 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
310 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
311 + * the GNU General Public License for more details.
313 + * You should have received a copy of the GNU General Public License
314 + * along with this program; if not, write to the Free Software
315 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
318 +#include <linux/fs.h>
319 +#include <linux/xattr.h>
320 +#include <linux/errno.h>
321 +#include "jfs_incore.h"
322 +#include "jfs_dmap.h"
323 +#include "jfs_debug.h"
324 +#include "jfs_dinode.h"
325 +#include "jfs_extent.h"
326 +#include "jfs_metapage.h"
327 +#include "jfs_xattr.h"
330 + * jfs_xattr.c: extended attribute service
332 + * Overall design --
336 + * Extended attribute lists (jfs_ea_list) consist of an overall size (32 bit
337 + * value) and a variable (0 or more) number of extended attribute
338 + * entries. Each extended attribute entry (jfs_ea) is a <name,value> double
339 + * where <name> is constructed from a null-terminated ascii string
340 + * (1 ... 255 bytes in the name) and <value> is arbitrary 8 bit data
341 + * (1 ... 65535 bytes). The in-memory format is
343 + * 0 1 2 4 4 + namelen + 1
344 + * +-------+--------+--------+----------------+-------------------+
345 + * | Flags | Name | Value | Name String \0 | Data . . . . |
346 + * | | Length | Length | | |
347 + * +-------+--------+--------+----------------+-------------------+
349 + * A jfs_ea_list then is structured as
351 + * 0 4 4 + EA_SIZE(ea1)
352 + * +------------+-------------------+--------------------+-----
353 + * | Overall EA | First FEA Element | Second FEA Element | .....
354 + * | List Size | | |
355 + * +------------+-------------------+--------------------+-----
359 + * FEALISTs are stored on disk using blocks allocated by dbAlloc() and
360 + * written directly. An EA list may be in-lined in the inode if there is
361 + * sufficient room available.
365 + int flag; /* Indicates what storage xattr points to */
366 + int max_size; /* largest xattr that fits in current buffer */
367 + dxd_t new_ea; /* dxd to replace ea when modifying xattr */
368 + struct metapage *mp; /* metapage containing ea list */
369 + struct jfs_ea_list *xattr; /* buffer containing ea list */
373 + * ea_buffer.flag values
375 +#define EA_INLINE 0x0001
376 +#define EA_EXTENT 0x0002
377 +#define EA_NEW 0x0004
378 +#define EA_MALLOC 0x0008
381 +#define XATTR_SYSTEM_PREFIX "system."
382 +#define XATTR_SYSTEM_PREFIX_LEN (sizeof (XATTR_SYSTEM_PREFIX) - 1)
384 +#define XATTR_USER_PREFIX "user."
385 +#define XATTR_USER_PREFIX_LEN (sizeof (XATTR_USER_PREFIX) - 1)
387 +#define XATTR_OS2_PREFIX "os2."
388 +#define XATTR_OS2_PREFIX_LEN (sizeof (XATTR_OS2_PREFIX) - 1)
391 + * These three routines are used to recognize on-disk extended attributes
392 + * that are in a recognized namespace. If the attribute is not recognized,
393 + * "os2." is prepended to the name
395 +static inline int is_os2_xattr(struct jfs_ea *ea)
398 + * Check for "system."
400 + if ((ea->namelen >= XATTR_SYSTEM_PREFIX_LEN) &&
401 + !strncmp(ea->name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
404 + * Check for "user."
406 + if ((ea->namelen >= XATTR_USER_PREFIX_LEN) &&
407 + !strncmp(ea->name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN))
410 + * Add any other valid namespace prefixes here
414 + * We assume it's OS/2's flat namespace
419 +static inline int name_size(struct jfs_ea *ea)
421 + if (is_os2_xattr(ea))
422 + return ea->namelen + XATTR_OS2_PREFIX_LEN;
424 + return ea->namelen;
427 +static inline int copy_name(char *buffer, struct jfs_ea *ea)
429 + int len = ea->namelen;
431 + if (is_os2_xattr(ea)) {
432 + memcpy(buffer, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN);
433 + buffer += XATTR_OS2_PREFIX_LEN;
434 + len += XATTR_OS2_PREFIX_LEN;
436 + memcpy(buffer, ea->name, ea->namelen);
437 + buffer[ea->namelen] = 0;
442 +/* Forward references */
443 +static void ea_release(struct inode *inode, struct ea_buffer *ea_buf);
446 + * NAME: ea_write_inline
448 + * FUNCTION: Attempt to write an EA inline if area is available
451 + * Already verified that the specified EA is small enough to fit inline
454 + * ip - Inode pointer
455 + * ealist - EA list pointer
456 + * size - size of ealist in bytes
457 + * ea - dxd_t structure to be filled in with necessary EA information
458 + * if we successfully copy the EA inline
461 + * Checks if the inode's inline area is available. If so, copies EA inline
462 + * and sets <ea> fields appropriately. Otherwise, returns failure, EA will
463 + * have to be put into an extent.
465 + * RETURNS: 0 for successful copy to inline area; -1 if area not available
467 +static int ea_write_inline(struct inode *ip, struct jfs_ea_list *ealist,
468 + int size, dxd_t * ea)
470 + struct jfs_inode_info *ji = JFS_IP(ip);
473 + * Make sure we have an EA -- the NULL EA list is valid, but you
476 + if (ealist && size > sizeof (struct jfs_ea_list)) {
477 + assert(size <= sizeof (ji->i_inline_ea));
480 + * See if the space is available or if it is already being
481 + * used for an inline EA.
483 + if (!(ji->mode2 & INLINEEA) && !(ji->ea.flag & DXD_INLINE))
489 + memcpy(ji->i_inline_ea, ealist, size);
490 + ea->flag = DXD_INLINE;
491 + ji->mode2 &= ~INLINEEA;
498 + /* Free up INLINE area */
499 + if (ji->ea.flag & DXD_INLINE)
500 + ji->mode2 |= INLINEEA;
503 + mark_inode_dirty(ip);
510 + * FUNCTION: Write an EA for an inode
512 + * PRE CONDITIONS: EA has been verified
515 + * ip - Inode pointer
516 + * ealist - EA list pointer
517 + * size - size of ealist in bytes
518 + * ea - dxd_t structure to be filled in appropriately with where the
521 + * NOTES: Will write EA inline if able to, otherwise allocates blocks for an
522 + * extent and synchronously writes it to those blocks.
524 + * RETURNS: 0 for success; Anything else indicates failure
526 +static int ea_write(struct inode *ip, struct jfs_ea_list *ealist, int size,
529 + struct super_block *sb = ip->i_sb;
530 + struct jfs_inode_info *ji = JFS_IP(ip);
531 + struct jfs_sb_info *sbi = JFS_SBI(sb);
537 + s32 bytes_to_write;
538 + struct metapage *mp;
541 + * Quick check to see if this is an in-linable EA. Short EAs
542 + * and empty EAs are all in-linable, provided the space exists.
544 + if (!ealist || size <= sizeof (ji->i_inline_ea)) {
545 + if (!ea_write_inline(ip, ealist, size, ea))
549 + /* figure out how many blocks we need */
550 + nblocks = (size + (sb->s_blocksize - 1)) >> sb->s_blocksize_bits;
552 + rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
557 + * Now have nblocks worth of storage to stuff into the FEALIST.
558 + * loop over the FEALIST copying data into the buffer one page at
561 + cp = (char *) ealist;
563 + for (i = 0; i < nblocks; i += sbi->nbperpage) {
565 + * Determine how many bytes for this request, and round up to
566 + * the nearest aggregate block size
568 + nb = min(PSIZE, nbytes);
570 + ((((nb + sb->s_blocksize - 1)) >> sb->s_blocksize_bits))
571 + << sb->s_blocksize_bits;
573 + if (!(mp = get_metapage(ip, blkno + i, bytes_to_write, 1))) {
578 + memcpy(mp->data, cp, nb);
581 + * We really need a way to propagate errors for
582 + * forced writes like this one. --hch
584 + * (__write_metapage => release_metapage => flush_metapage)
587 + if ((rc = flush_metapage(mp))) {
589 + * the write failed -- this means that the buffer
590 + * is still assigned and the blocks are not being
591 + * used. this seems like the best error recovery
597 + flush_metapage(mp);
604 + ea->flag = DXD_EXTENT;
605 + DXDsize(ea, le32_to_cpu(ealist->size));
606 + DXDlength(ea, nblocks);
607 + DXDaddress(ea, blkno);
609 + /* Free up INLINE area */
610 + if (ji->ea.flag & DXD_INLINE)
611 + ji->mode2 |= INLINEEA;
616 + dbFree(ip, blkno, nblocks);
621 + * NAME: ea_read_inline
623 + * FUNCTION: Read an inlined EA into user's buffer
626 + * ip - Inode pointer
627 + * ealist - Pointer to buffer to fill in with EA
631 +static int ea_read_inline(struct inode *ip, struct jfs_ea_list *ealist)
633 + struct jfs_inode_info *ji = JFS_IP(ip);
634 + int ea_size = sizeDXD(&ji->ea);
636 + if (ea_size == 0) {
642 + if ((sizeDXD(&ji->ea) > sizeof (ji->i_inline_ea)))
644 + if (le32_to_cpu(((struct jfs_ea_list *) &ji->i_inline_ea)->size)
648 + memcpy(ealist, ji->i_inline_ea, ea_size);
655 + * FUNCTION: copy EA data into user's buffer
658 + * ip - Inode pointer
659 + * ealist - Pointer to buffer to fill in with EA
661 + * NOTES: If EA is inline calls ea_read_inline() to copy EA.
663 + * RETURNS: 0 for success; other indicates failure
665 +static int ea_read(struct inode *ip, struct jfs_ea_list *ealist)
667 + struct super_block *sb = ip->i_sb;
668 + struct jfs_inode_info *ji = JFS_IP(ip);
669 + struct jfs_sb_info *sbi = JFS_SBI(sb);
672 + char *cp = (char *) ealist;
676 + struct metapage *mp;
678 + /* quick check for in-line EA */
679 + if (ji->ea.flag & DXD_INLINE)
680 + return ea_read_inline(ip, ealist);
682 + nbytes = sizeDXD(&ji->ea);
686 + * Figure out how many blocks were allocated when this EA list was
687 + * originally written to disk.
689 + nblocks = lengthDXD(&ji->ea) << sbi->l2nbperpage;
690 + blkno = addressDXD(&ji->ea) << sbi->l2nbperpage;
693 + * I have found the disk blocks which were originally used to store
694 + * the FEALIST. now i loop over each contiguous block copying the
695 + * data into the buffer.
697 + for (i = 0; i < nblocks; i += sbi->nbperpage) {
699 + * Determine how many bytes for this request, and round up to
700 + * the nearest aggregate block size
702 + nb = min(PSIZE, nbytes);
704 + ((((nb + sb->s_blocksize - 1)) >> sb->s_blocksize_bits))
705 + << sb->s_blocksize_bits;
707 + if (!(mp = read_metapage(ip, blkno + i, bytes_to_read, 1)))
710 + memcpy(cp, mp->data, nb);
711 + release_metapage(mp);
723 + * FUNCTION: Returns buffer containing existing extended attributes.
724 + * The size of the buffer will be the larger of the existing
725 + * attributes size, or min_size.
727 + * The buffer, which may be inlined in the inode or in the
728 + * page cache must be release by calling ea_release or ea_put
731 + * inode - Inode pointer
732 + * ea_buf - Structure to be populated with ealist and its metadata
733 + * min_size- minimum size of buffer to be returned
735 + * RETURNS: 0 for success; Other indicates failure
737 +static int ea_get(struct inode *inode, struct ea_buffer *ea_buf, int min_size)
739 + struct jfs_inode_info *ji = JFS_IP(inode);
740 + struct super_block *sb = inode->i_sb;
742 + int ea_size = sizeDXD(&ji->ea);
743 + int blocks_needed, current_blocks;
747 + /* When fsck.jfs clears a bad ea, it doesn't clear the size */
748 + if (ji->ea.flag == 0)
751 + if (ea_size == 0) {
752 + if (min_size == 0) {
754 + ea_buf->max_size = 0;
755 + ea_buf->xattr = NULL;
758 + if ((min_size <= sizeof (ji->i_inline_ea)) &&
759 + (ji->mode2 & INLINEEA)) {
760 + ea_buf->flag = EA_INLINE | EA_NEW;
761 + ea_buf->max_size = sizeof (ji->i_inline_ea);
762 + ea_buf->xattr = (struct jfs_ea_list *) ji->i_inline_ea;
763 + DXDlength(&ea_buf->new_ea, 0);
764 + DXDaddress(&ea_buf->new_ea, 0);
765 + ea_buf->new_ea.flag = DXD_INLINE;
766 + DXDsize(&ea_buf->new_ea, min_size);
769 + current_blocks = 0;
770 + } else if (ji->ea.flag & DXD_INLINE) {
771 + if (min_size <= sizeof (ji->i_inline_ea)) {
772 + ea_buf->flag = EA_INLINE;
773 + ea_buf->max_size = sizeof (ji->i_inline_ea);
774 + ea_buf->xattr = (struct jfs_ea_list *) ji->i_inline_ea;
777 + current_blocks = 0;
779 + assert(ji->ea.flag & DXD_EXTENT);
780 + current_blocks = (ea_size + sb->s_blocksize - 1) >>
781 + sb->s_blocksize_bits;
783 + size = max(min_size, ea_size);
785 + if (size > PSIZE) {
787 + * To keep the rest of the code simple. Allocate a
788 + * contiguous buffer to work with
790 + ea_buf->xattr = kmalloc(size, GFP_KERNEL);
791 + if (ea_buf->xattr == NULL)
794 + ea_buf->flag |= EA_MALLOC;
795 + ea_buf->max_size = (size + sb->s_blocksize - 1) &
796 + ~(sb->s_blocksize - 1);
801 + if ((rc = ea_read(inode, ea_buf->xattr))) {
802 + kfree(ea_buf->xattr);
803 + ea_buf->xattr = NULL;
808 + blocks_needed = (min_size + sb->s_blocksize - 1) >>
809 + sb->s_blocksize_bits;
811 + if (blocks_needed > current_blocks) {
812 + rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
817 + DXDlength(&ea_buf->new_ea, blocks_needed);
818 + DXDaddress(&ea_buf->new_ea, blkno);
819 + ea_buf->new_ea.flag = DXD_EXTENT;
820 + DXDsize(&ea_buf->new_ea, min_size);
822 + ea_buf->flag = EA_EXTENT | EA_NEW;
824 + ea_buf->mp = get_metapage(inode, blkno,
825 + blocks_needed << sb->s_blocksize_bits,
827 + if (ea_buf->mp == NULL) {
828 + dbFree(inode, blkno, (s64) blocks_needed);
831 + ea_buf->xattr = ea_buf->mp->data;
832 + ea_buf->max_size = (min_size + sb->s_blocksize - 1) &
833 + ~(sb->s_blocksize - 1);
836 + if ((rc = ea_read(inode, ea_buf->xattr))) {
837 + discard_metapage(ea_buf->mp);
838 + dbFree(inode, blkno, (s64) blocks_needed);
843 + ea_buf->flag = EA_EXTENT;
844 + ea_buf->mp = read_metapage(inode, addressDXD(&ji->ea),
845 + lengthDXD(&ji->ea), 1);
846 + if (ea_buf->mp == NULL)
848 + ea_buf->xattr = ea_buf->mp->data;
849 + ea_buf->max_size = (ea_size + sb->s_blocksize - 1) &
850 + ~(sb->s_blocksize - 1);
853 + if (EALIST_SIZE(ea_buf->xattr) != ea_size) {
854 + printk(KERN_ERR "ea_get: invalid extended attribute\n");
855 + dump_mem("xattr", ea_buf->xattr, ea_size);
856 + ea_release(inode, ea_buf);
863 +static void ea_release(struct inode *inode, struct ea_buffer *ea_buf)
865 + if (ea_buf->flag & EA_MALLOC)
866 + kfree(ea_buf->xattr);
867 + else if (ea_buf->flag & EA_EXTENT) {
868 + assert(ea_buf->mp);
869 + release_metapage(ea_buf->mp);
871 + if (ea_buf->flag & EA_NEW)
872 + dbFree(inode, addressDXD(&ea_buf->new_ea),
873 + lengthDXD(&ea_buf->new_ea));
877 +static int ea_put(struct inode *inode, struct ea_buffer *ea_buf, int new_size)
879 + struct jfs_inode_info *ji = JFS_IP(inode);
880 + unsigned long old_blocks, new_blocks;
884 + if (new_size == 0) {
885 + ea_release(inode, ea_buf);
887 + } else if (ea_buf->flag & EA_INLINE) {
888 + assert(new_size <= sizeof (ji->i_inline_ea));
889 + ji->mode2 &= ~INLINEEA;
890 + ea_buf->new_ea.flag = DXD_INLINE;
891 + DXDsize(&ea_buf->new_ea, new_size);
892 + DXDaddress(&ea_buf->new_ea, 0);
893 + DXDlength(&ea_buf->new_ea, 0);
894 + } else if (ea_buf->flag & EA_MALLOC) {
895 + rc = ea_write(inode, ea_buf->xattr, new_size, &ea_buf->new_ea);
896 + kfree(ea_buf->xattr);
897 + } else if (ea_buf->flag & EA_NEW) {
898 + /* We have already allocated a new dxd */
899 + flush_metapage(ea_buf->mp);
901 + /* ->xattr must point to original ea's metapage */
902 + rc = ea_write(inode, ea_buf->xattr, new_size, &ea_buf->new_ea);
903 + discard_metapage(ea_buf->mp);
908 + tid = txBegin(inode->i_sb, 0);
909 + down(&ji->commit_sem);
911 + old_blocks = new_blocks = 0;
913 + if (ji->ea.flag & DXD_EXTENT) {
914 + invalidate_dxd_metapages(inode, ji->ea);
915 + old_blocks = lengthDXD(&ji->ea);
919 + txEA(tid, inode, &ji->ea, &ea_buf->new_ea);
920 + if (ea_buf->new_ea.flag & DXD_EXTENT) {
921 + new_blocks = lengthDXD(&ea_buf->new_ea);
922 + if (ji->ea.flag & DXD_INLINE)
923 + ji->mode2 |= INLINEEA;
925 + ji->ea = ea_buf->new_ea;
927 + txEA(tid, inode, &ji->ea, 0);
928 + if (ji->ea.flag & DXD_INLINE)
929 + ji->mode2 |= INLINEEA;
934 + inode->i_blocks += LBLK2PBLK(inode->i_sb, new_blocks - old_blocks);
935 + rc = txCommit(tid, 1, &inode, 0);
937 + up(&ji->commit_sem);
942 +static int can_set_xattr(struct inode *inode, const char *name,
943 + const void *value, size_t value_len)
945 + if (IS_RDONLY(inode))
948 + if (IS_IMMUTABLE(inode) || IS_APPEND(inode) || S_ISLNK(inode->i_mode))
951 + if((strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) != 0) &&
952 + (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) != 0))
953 + return -EOPNOTSUPP;
955 + if (!S_ISREG(inode->i_mode) &&
956 + (!S_ISDIR(inode->i_mode) || inode->i_mode &S_ISVTX))
959 + return permission(inode, MAY_WRITE);
962 +int __jfs_setxattr(struct inode *inode, const char *name, const void *value,
963 + size_t value_len, int flags)
965 + struct jfs_ea_list *ealist;
966 + struct jfs_ea *ea, *old_ea = NULL, *next_ea = NULL;
967 + struct ea_buffer ea_buf;
968 + int old_ea_size = 0;
971 + int namelen = strlen(name);
972 + char *os2name = NULL;
977 + if ((rc = can_set_xattr(inode, name, value, value_len)))
980 + if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
981 + os2name = kmalloc(namelen - XATTR_OS2_PREFIX_LEN + 1,
985 + strcpy(os2name, name + XATTR_OS2_PREFIX_LEN);
987 + namelen -= XATTR_OS2_PREFIX_LEN;
990 + xattr_size = ea_get(inode, &ea_buf, 0);
991 + if (xattr_size < 0) {
997 + ealist = (struct jfs_ea_list *) ea_buf.xattr;
998 + new_size = sizeof (struct jfs_ea_list);
1001 + for (ea = FIRST_EA(ealist); ea < END_EALIST(ealist);
1002 + ea = NEXT_EA(ea)) {
1003 + if ((namelen == ea->namelen) &&
1004 + (memcmp(name, ea->name, namelen) == 0)) {
1006 + if (flags & XATTR_CREATE) {
1011 + old_ea_size = EA_SIZE(ea);
1012 + next_ea = NEXT_EA(ea);
1014 + new_size += EA_SIZE(ea);
1019 + if (flags & XATTR_REPLACE) {
1023 + if (value == NULL) {
1029 + new_size += sizeof (struct jfs_ea) + namelen + 1 + value_len;
1031 + if (new_size > ea_buf.max_size) {
1033 + * We need to allocate more space for merged ea list.
1034 + * We should only have loop to again: once.
1036 + ea_release(inode, &ea_buf);
1037 + xattr_size = ea_get(inode, &ea_buf, new_size);
1038 + if (xattr_size < 0) {
1045 + /* Remove old ea of the same name */
1047 + /* number of bytes following target EA */
1048 + length = (char *) END_EALIST(ealist) - (char *) next_ea;
1050 + memmove(old_ea, next_ea, length);
1051 + xattr_size -= old_ea_size;
1054 + /* Add new entry to the end */
1056 + if (xattr_size == 0)
1057 + /* Completely new ea list */
1058 + xattr_size = sizeof (struct jfs_ea_list);
1060 + ea = (struct jfs_ea *) ((char *) ealist + xattr_size);
1062 + ea->namelen = namelen;
1063 + ea->valuelen = (cpu_to_le16(value_len));
1064 + memcpy(ea->name, name, namelen);
1065 + ea->name[namelen] = 0;
1067 + memcpy(&ea->name[namelen + 1], value, value_len);
1068 + xattr_size += EA_SIZE(ea);
1071 + /* DEBUG - If we did this right, these number match */
1072 + if (xattr_size != new_size) {
1074 + "jfs_xsetattr: xattr_size = %d, new_size = %d\n",
1075 + xattr_size, new_size);
1082 + * If we're left with an empty list, there's no ea
1084 + if (new_size == sizeof (struct jfs_ea_list))
1087 + ealist->size = cpu_to_le32(new_size);
1089 + rc = ea_put(inode, &ea_buf, new_size);
1093 + ea_release(inode, &ea_buf);
1101 +int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
1102 + size_t value_len, int flags)
1104 + if (value == NULL) { /* empty EA, do not remove */
1109 + return __jfs_setxattr(dentry->d_inode, name, value, value_len, flags);
1112 +static inline int can_get_xattr(struct inode *inode, const char *name)
1114 + return permission(inode, MAY_READ);
1117 +ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data,
1120 + struct jfs_ea_list *ealist;
1121 + struct jfs_ea *ea;
1122 + struct ea_buffer ea_buf;
1125 + int namelen = strlen(name);
1126 + char *os2name = NULL;
1130 + if ((rc = can_get_xattr(inode, name)))
1133 + if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
1134 + os2name = kmalloc(namelen - XATTR_OS2_PREFIX_LEN + 1,
1138 + strcpy(os2name, name + XATTR_OS2_PREFIX_LEN);
1140 + namelen -= XATTR_OS2_PREFIX_LEN;
1143 + xattr_size = ea_get(inode, &ea_buf, 0);
1144 + if (xattr_size < 0) {
1145 + size = xattr_size;
1149 + if (xattr_size == 0)
1152 + ealist = (struct jfs_ea_list *) ea_buf.xattr;
1154 + /* Find the named attribute */
1155 + for (ea = FIRST_EA(ealist); ea < END_EALIST(ealist); ea = NEXT_EA(ea))
1156 + if ((namelen == ea->namelen) &&
1157 + memcmp(name, ea->name, namelen) == 0) {
1159 + size = le16_to_cpu(ea->valuelen);
1162 + else if (size > buf_size) {
1166 + value = ((char *) &ea->name) + ea->namelen + 1;
1167 + memcpy(data, value, size);
1173 + ea_release(inode, &ea_buf);
1181 +ssize_t jfs_getxattr(struct dentry *dentry, const char *name, void *data,
1184 + return __jfs_getxattr(dentry->d_inode, name, data, buf_size);
1187 +ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size)
1189 + struct inode *inode = dentry->d_inode;
1193 + struct jfs_ea_list *ealist;
1194 + struct jfs_ea *ea;
1195 + struct ea_buffer ea_buf;
1197 + xattr_size = ea_get(inode, &ea_buf, 0);
1198 + if (xattr_size < 0) {
1199 + size = xattr_size;
1203 + if (xattr_size == 0)
1206 + ealist = (struct jfs_ea_list *) ea_buf.xattr;
1208 + /* compute required size of list */
1209 + for (ea = FIRST_EA(ealist); ea < END_EALIST(ealist); ea = NEXT_EA(ea))
1210 + size += name_size(ea) + 1;
1215 + if (size > buf_size) {
1220 + /* Copy attribute names to buffer */
1222 + for (ea = FIRST_EA(ealist); ea < END_EALIST(ealist); ea = NEXT_EA(ea)) {
1223 + int namelen = copy_name(buffer, ea);
1224 + buffer += namelen + 1;
1228 + ea_release(inode, &ea_buf);
1233 +int jfs_removexattr(struct dentry *dentry, const char *name)
1235 + return __jfs_setxattr(dentry->d_inode, name, 0, 0, XATTR_REPLACE);