]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.4.21-jfs-xattr.patch
- added description of djurban's branch
[packages/kernel.git] / linux-2.4.21-jfs-xattr.patch
1 --------------------------------------------------------------------
2 This patch adds extended attribute support for JFS 1.1.2.
3
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)
6
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
12 @@ -12,7 +12,7 @@
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
18  obj-m   := $(O_TARGET)
19  
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
24 @@ -22,6 +22,7 @@
25  #include "jfs_incore.h"
26  #include "jfs_dmap.h"
27  #include "jfs_txnmgr.h"
28 +#include "jfs_xattr.h"
29  #include "jfs_debug.h"
30  
31  
32 @@ -91,6 +92,10 @@
33  
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,
40  };
41  
42  struct file_operations jfs_file_operations = {
43 @@ -102,3 +107,11 @@
44         .fsync          = jfs_fsync,
45         .release        = jfs_release,
46  };
47 +
48 +struct inode_operations jfs_special_inode_operations = {
49 +       .setxattr       = jfs_setxattr,
50 +       .getxattr       = jfs_getxattr,
51 +       .listxattr      = jfs_listxattr,
52 +       .removexattr    = jfs_removexattr,
53 +};
54 +
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
58 @@ -31,6 +31,7 @@
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;
66 @@ -96,6 +97,7 @@
67                 } else
68                         inode->i_op = &jfs_symlink_inode_operations;
69         } else {
70 +               inode->i_op = &jfs_special_inode_operations;
71                 init_special_inode(inode, inode->i_mode,
72                                    kdev_t_to_nr(inode->i_rdev));
73         }
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
77 @@ -806,21 +806,19 @@
78                 memcpy(&dp->di_fastsymlink, jfs_ip->i_inline, IDATASIZE);
79                 dilinelock->index++;
80         }
81 -#ifdef _STILL_TO_PORT
82         /*
83          * copy inline data from in-memory inode to on-disk inode:
84          * 128 byte slot granularity
85          */
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;
90                 lv->length = 1;
91 -               memcpy(&dp->di_inlineea, &ip->i_inlineea, INODESLOTSIZE);
92 +               memcpy(&dp->di_inlineea, &jfs_ip->i_inline_ea, INODESLOTSIZE);
93                 dilinelock->index++;
94  
95                 clear_cflag(COMMIT_Inlineea, ip);
96         }
97 -#endif                         /* _STILL_TO_PORT */
98  
99         /*
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);
105 -       /*
106 -        * We may only need to do this for "special" inodes (dmap, imap)
107 -        */
108 +
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)) {
112 +
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);
118 -       }
119 +       } else
120 +               memcpy(&jfs_ip->i_inline_ea, &dip->di_inlineea, 128);
121 +
122         /* Zero the in-memory-only stuff */
123         jfs_ip->cflag = 0;
124         jfs_ip->btindex = 0;
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
128 @@ -82,6 +82,10 @@
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
134 +                        */
135 +                       unchar _inline_ea[128]; /* 128: inline extended attr */
136                 } link;
137         } u;
138  };
139 @@ -90,6 +94,7 @@
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
144  
145  
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
150 @@ -106,7 +106,7 @@
151  }
152  
153  /*
154 - * This routines invalidate all pages for an extent.
155 + * These routines invalidate all pages for an extent.
156   */
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
162 @@ -144,6 +144,8 @@
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)
168  
169  /*
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
174 @@ -0,0 +1,64 @@
175 +/*
176 + *   Copyright (c) International Business Machines Corp., 2000-2002
177 + *
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.
182 + *
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.
187 + *
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
191 + */
192 +
193 +#ifndef H_JFS_XATTR
194 +#define H_JFS_XATTR
195 +
196 +/*
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.
200 + */
201 +struct jfs_ea {
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 */
207 +
208 +struct jfs_ea_list {
209 +       u32 size;               /* overall size */
210 +       struct jfs_ea ea[0];    /* Variable length list */
211 +};
212 +
213 +/* Macros for defining maxiumum number of bytes supported for EAs */
214 +#define MAXEASIZE      65535
215 +#define MAXEALISTSIZE  MAXEASIZE
216 +
217 +/*
218 + * some macros for dealing with variable length EA lists.
219 + */
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)))
228 +
229 +extern int __jfs_setxattr(struct inode *, const char *, const void *, size_t,
230 +                       int);
231 +extern int jfs_setxattr(struct dentry *, const char *, const void *, size_t,
232 +                       int);
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 *);
237 +
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
242 @@ -24,10 +24,12 @@
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"
248  
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;
254  
255 @@ -1316,6 +1318,7 @@
256         if ((rc = dtInsert(tid, dir, &dname, &ino, &btstack)))
257                 goto out3;
258  
259 +       ip->i_op = &jfs_special_inode_operations;
260         init_special_inode(ip, ip->i_mode, rdev);
261  
262         insert_inode_hash(ip);
263 @@ -1400,6 +1403,10 @@
264         .rmdir          = jfs_rmdir,
265         .mknod          = jfs_mknod,
266         .rename         = jfs_rename,
267 +       .setxattr       = jfs_setxattr,
268 +       .getxattr       = jfs_getxattr,
269 +       .listxattr      = jfs_listxattr,
270 +       .removexattr    = jfs_removexattr,
271  };
272  
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
277 @@ -18,6 +18,7 @@
278  
279  #include <linux/fs.h>
280  #include "jfs_incore.h"
281 +#include "jfs_xattr.h"
282  
283  static int jfs_follow_link(struct dentry *dentry, struct nameidata *nd)
284  {
285 @@ -34,5 +35,9 @@
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,
293  };
294  
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
298 @@ -0,0 +1,938 @@
299 +/*
300 + *   Copyright (c) International Business Machines  Corp., 2000-2002
301 + *   Copyright (c) Christoph Hellwig, 2002
302 + *
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.
307 + * 
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.
312 + *
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
316 + */
317 +
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"
328 +
329 +/*
330 + *     jfs_xattr.c: extended attribute service
331 + *
332 + * Overall design --
333 + *
334 + * Format:
335 + *
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
342 + *
343 + *   0       1        2        4                4 + namelen + 1
344 + *   +-------+--------+--------+----------------+-------------------+
345 + *   | Flags | Name   | Value  | Name String \0 | Data . . . .      |
346 + *   |       | Length | Length |                |                   |
347 + *   +-------+--------+--------+----------------+-------------------+
348 + *
349 + *   A jfs_ea_list then is structured as
350 + *
351 + *   0            4                   4 + EA_SIZE(ea1)
352 + *   +------------+-------------------+--------------------+-----
353 + *   | Overall EA | First FEA Element | Second FEA Element | ..... 
354 + *   | List Size  |                   |                    |
355 + *   +------------+-------------------+--------------------+-----
356 + *
357 + *   On-disk:
358 + *
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.
362 + */
363 +
364 +struct ea_buffer {
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 */
370 +};
371 +
372 +/*
373 + * ea_buffer.flag values
374 + */
375 +#define EA_INLINE      0x0001
376 +#define EA_EXTENT      0x0002
377 +#define EA_NEW         0x0004
378 +#define EA_MALLOC      0x0008
379 +
380 +/* Namespaces */
381 +#define XATTR_SYSTEM_PREFIX "system."
382 +#define XATTR_SYSTEM_PREFIX_LEN (sizeof (XATTR_SYSTEM_PREFIX) - 1)
383 +
384 +#define XATTR_USER_PREFIX "user."
385 +#define XATTR_USER_PREFIX_LEN (sizeof (XATTR_USER_PREFIX) - 1)
386 +
387 +#define XATTR_OS2_PREFIX "os2."
388 +#define XATTR_OS2_PREFIX_LEN (sizeof (XATTR_OS2_PREFIX) - 1)
389 +
390 +/*
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
394 + */
395 +static inline int is_os2_xattr(struct jfs_ea *ea)
396 +{
397 +       /*
398 +        * Check for "system."
399 +        */
400 +       if ((ea->namelen >= XATTR_SYSTEM_PREFIX_LEN) &&
401 +           !strncmp(ea->name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
402 +               return FALSE;
403 +       /*
404 +        * Check for "user."
405 +        */
406 +       if ((ea->namelen >= XATTR_USER_PREFIX_LEN) &&
407 +           !strncmp(ea->name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN))
408 +               return FALSE;
409 +       /*
410 +        * Add any other valid namespace prefixes here
411 +        */
412 +
413 +       /*
414 +        * We assume it's OS/2's flat namespace
415 +        */
416 +       return TRUE;
417 +}
418 +
419 +static inline int name_size(struct jfs_ea *ea)
420 +{
421 +       if (is_os2_xattr(ea))
422 +               return ea->namelen + XATTR_OS2_PREFIX_LEN;
423 +       else
424 +               return ea->namelen;
425 +}
426 +
427 +static inline int copy_name(char *buffer, struct jfs_ea *ea)
428 +{
429 +       int len = ea->namelen;
430 +
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;
435 +       }
436 +       memcpy(buffer, ea->name, ea->namelen);
437 +       buffer[ea->namelen] = 0;
438 +
439 +       return len;
440 +}
441 +
442 +/* Forward references */
443 +static void ea_release(struct inode *inode, struct ea_buffer *ea_buf);
444 +
445 +/*
446 + * NAME: ea_write_inline
447 + *                                                                    
448 + * FUNCTION: Attempt to write an EA inline if area is available
449 + *                                                                    
450 + * PRE CONDITIONS:
451 + *     Already verified that the specified EA is small enough to fit inline
452 + *
453 + * PARAMETERS:
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
459 + *
460 + * NOTES:
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.
464 + *
465 + * RETURNS: 0 for successful copy to inline area; -1 if area not available
466 + */
467 +static int ea_write_inline(struct inode *ip, struct jfs_ea_list *ealist,
468 +                          int size, dxd_t * ea)
469 +{
470 +       struct jfs_inode_info *ji = JFS_IP(ip);
471 +
472 +       /*
473 +        * Make sure we have an EA -- the NULL EA list is valid, but you
474 +        * can't copy it!
475 +        */
476 +       if (ealist && size > sizeof (struct jfs_ea_list)) {
477 +               assert(size <= sizeof (ji->i_inline_ea));
478 +
479 +               /*
480 +                * See if the space is available or if it is already being
481 +                * used for an inline EA.
482 +                */
483 +               if (!(ji->mode2 & INLINEEA) && !(ji->ea.flag & DXD_INLINE))
484 +                       return -1;
485 +
486 +               DXDsize(ea, size);
487 +               DXDlength(ea, 0);
488 +               DXDaddress(ea, 0);
489 +               memcpy(ji->i_inline_ea, ealist, size);
490 +               ea->flag = DXD_INLINE;
491 +               ji->mode2 &= ~INLINEEA;
492 +       } else {
493 +               ea->flag = 0;
494 +               DXDsize(ea, 0);
495 +               DXDlength(ea, 0);
496 +               DXDaddress(ea, 0);
497 +
498 +               /* Free up INLINE area */
499 +               if (ji->ea.flag & DXD_INLINE)
500 +                       ji->mode2 |= INLINEEA;
501 +       }
502 +
503 +       mark_inode_dirty(ip);
504 +       return 0;
505 +}
506 +
507 +/*
508 + * NAME: ea_write
509 + *                                                                    
510 + * FUNCTION: Write an EA for an inode
511 + *                                                                    
512 + * PRE CONDITIONS: EA has been verified 
513 + *
514 + * PARAMETERS:
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
519 + *               EA was copied
520 + *
521 + * NOTES: Will write EA inline if able to, otherwise allocates blocks for an
522 + *     extent and synchronously writes it to those blocks.
523 + *
524 + * RETURNS: 0 for success; Anything else indicates failure
525 + */
526 +static int ea_write(struct inode *ip, struct jfs_ea_list *ealist, int size,
527 +                      dxd_t * ea)
528 +{
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);
532 +       int nblocks;
533 +       s64 blkno;
534 +       int rc = 0, i;
535 +       char *cp;
536 +       s32 nbytes, nb;
537 +       s32 bytes_to_write;
538 +       struct metapage *mp;
539 +
540 +       /*
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.
543 +        */
544 +       if (!ealist || size <= sizeof (ji->i_inline_ea)) {
545 +               if (!ea_write_inline(ip, ealist, size, ea))
546 +                       return 0;
547 +       }
548 +
549 +       /* figure out how many blocks we need */
550 +       nblocks = (size + (sb->s_blocksize - 1)) >> sb->s_blocksize_bits;
551 +
552 +       rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
553 +       if (rc)
554 +               return -rc;
555 +
556 +       /*
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
559 +        * a time.
560 +        */
561 +       cp = (char *) ealist;
562 +       nbytes = size;
563 +       for (i = 0; i < nblocks; i += sbi->nbperpage) {
564 +               /*
565 +                * Determine how many bytes for this request, and round up to
566 +                * the nearest aggregate block size
567 +                */
568 +               nb = min(PSIZE, nbytes);
569 +               bytes_to_write =
570 +                   ((((nb + sb->s_blocksize - 1)) >> sb->s_blocksize_bits))
571 +                   << sb->s_blocksize_bits;
572 +
573 +               if (!(mp = get_metapage(ip, blkno + i, bytes_to_write, 1))) {
574 +                       rc = -EIO;
575 +                       goto failed;
576 +               }
577 +
578 +               memcpy(mp->data, cp, nb);
579 +
580 +               /*
581 +                * We really need a way to propagate errors for
582 +                * forced writes like this one.  --hch
583 +                *
584 +                * (__write_metapage => release_metapage => flush_metapage)
585 +                */
586 +#ifdef _JFS_FIXME
587 +               if ((rc = flush_metapage(mp))) {
588 +                       /*
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
592 +                        * we can get ...
593 +                        */
594 +                       goto failed;
595 +               }
596 +#else
597 +               flush_metapage(mp);
598 +#endif
599 +
600 +               cp += PSIZE;
601 +               nbytes -= nb;
602 +       }
603 +
604 +       ea->flag = DXD_EXTENT;
605 +       DXDsize(ea, le32_to_cpu(ealist->size));
606 +       DXDlength(ea, nblocks);
607 +       DXDaddress(ea, blkno);
608 +
609 +       /* Free up INLINE area */
610 +       if (ji->ea.flag & DXD_INLINE)
611 +               ji->mode2 |= INLINEEA;
612 +
613 +       return 0;
614 +
615 +      failed:
616 +       dbFree(ip, blkno, nblocks);
617 +       return rc;
618 +}
619 +
620 +/*
621 + * NAME: ea_read_inline
622 + *                                                                    
623 + * FUNCTION: Read an inlined EA into user's buffer
624 + *                                                                    
625 + * PARAMETERS:
626 + *     ip      - Inode pointer
627 + *     ealist  - Pointer to buffer to fill in with EA
628 + *
629 + * RETURNS: 0
630 + */
631 +static int ea_read_inline(struct inode *ip, struct jfs_ea_list *ealist)
632 +{
633 +       struct jfs_inode_info *ji = JFS_IP(ip);
634 +       int ea_size = sizeDXD(&ji->ea);
635 +
636 +       if (ea_size == 0) {
637 +               ealist->size = 0;
638 +               return 0;
639 +       }
640 +
641 +       /* Sanity Check */
642 +       if ((sizeDXD(&ji->ea) > sizeof (ji->i_inline_ea)))
643 +               return -EIO;
644 +       if (le32_to_cpu(((struct jfs_ea_list *) &ji->i_inline_ea)->size)
645 +           != ea_size)
646 +               return -EIO;
647 +
648 +       memcpy(ealist, ji->i_inline_ea, ea_size);
649 +       return 0;
650 +}
651 +
652 +/*
653 + * NAME: ea_read
654 + *                                                                    
655 + * FUNCTION: copy EA data into user's buffer
656 + *                                                                    
657 + * PARAMETERS:
658 + *     ip      - Inode pointer
659 + *     ealist  - Pointer to buffer to fill in with EA
660 + *
661 + * NOTES:  If EA is inline calls ea_read_inline() to copy EA.
662 + *
663 + * RETURNS: 0 for success; other indicates failure
664 + */
665 +static int ea_read(struct inode *ip, struct jfs_ea_list *ealist)
666 +{
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);
670 +       int nblocks;
671 +       s64 blkno;
672 +       char *cp = (char *) ealist;
673 +       int i;
674 +       int nbytes, nb;
675 +       s32 bytes_to_read;
676 +       struct metapage *mp;
677 +
678 +       /* quick check for in-line EA */
679 +       if (ji->ea.flag & DXD_INLINE)
680 +               return ea_read_inline(ip, ealist);
681 +
682 +       nbytes = sizeDXD(&ji->ea);
683 +       assert(nbytes);
684 +
685 +       /* 
686 +        * Figure out how many blocks were allocated when this EA list was
687 +        * originally written to disk.
688 +        */
689 +       nblocks = lengthDXD(&ji->ea) << sbi->l2nbperpage;
690 +       blkno = addressDXD(&ji->ea) << sbi->l2nbperpage;
691 +
692 +       /*
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.
696 +        */
697 +       for (i = 0; i < nblocks; i += sbi->nbperpage) {
698 +               /*
699 +                * Determine how many bytes for this request, and round up to
700 +                * the nearest aggregate block size
701 +                */
702 +               nb = min(PSIZE, nbytes);
703 +               bytes_to_read =
704 +                   ((((nb + sb->s_blocksize - 1)) >> sb->s_blocksize_bits))
705 +                   << sb->s_blocksize_bits;
706 +
707 +               if (!(mp = read_metapage(ip, blkno + i, bytes_to_read, 1)))
708 +                       return -EIO;
709 +
710 +               memcpy(cp, mp->data, nb);
711 +               release_metapage(mp);
712 +
713 +               cp += PSIZE;
714 +               nbytes -= nb;
715 +       }
716 +
717 +       return 0;
718 +}
719 +
720 +/*
721 + * NAME: ea_get
722 + *                                                                    
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.
726 + *
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
729 + *                                                                    
730 + * PARAMETERS:
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
734 + *
735 + * RETURNS: 0 for success; Other indicates failure
736 + */
737 +static int ea_get(struct inode *inode, struct ea_buffer *ea_buf, int min_size)
738 +{
739 +       struct jfs_inode_info *ji = JFS_IP(inode);
740 +       struct super_block *sb = inode->i_sb;
741 +       int size;
742 +       int ea_size = sizeDXD(&ji->ea);
743 +       int blocks_needed, current_blocks;
744 +       s64 blkno;
745 +       int rc;
746 +
747 +       /* When fsck.jfs clears a bad ea, it doesn't clear the size */
748 +       if (ji->ea.flag == 0)
749 +               ea_size = 0;
750 +
751 +       if (ea_size == 0) {
752 +               if (min_size == 0) {
753 +                       ea_buf->flag = 0;
754 +                       ea_buf->max_size = 0;
755 +                       ea_buf->xattr = NULL;
756 +                       return 0;
757 +               }
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);
767 +                       return 0;
768 +               }
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;
775 +                       goto size_check;
776 +               }
777 +               current_blocks = 0;
778 +       } else {
779 +               assert(ji->ea.flag & DXD_EXTENT);
780 +               current_blocks = (ea_size + sb->s_blocksize - 1) >>
781 +                   sb->s_blocksize_bits;
782 +       }
783 +       size = max(min_size, ea_size);
784 +
785 +       if (size > PSIZE) {
786 +               /*
787 +                * To keep the rest of the code simple.  Allocate a
788 +                * contiguous buffer to work with
789 +                */
790 +               ea_buf->xattr = kmalloc(size, GFP_KERNEL);
791 +               if (ea_buf->xattr == NULL)
792 +                       return -ENOMEM;
793 +
794 +               ea_buf->flag |= EA_MALLOC;
795 +               ea_buf->max_size = (size + sb->s_blocksize - 1) &
796 +                   ~(sb->s_blocksize - 1);
797 +
798 +               if (ea_size == 0)
799 +                       return 0;
800 +
801 +               if ((rc = ea_read(inode, ea_buf->xattr))) {
802 +                       kfree(ea_buf->xattr);
803 +                       ea_buf->xattr = NULL;
804 +                       return rc;
805 +               }
806 +               goto size_check;
807 +       }
808 +       blocks_needed = (min_size + sb->s_blocksize - 1) >>
809 +           sb->s_blocksize_bits;
810 +
811 +       if (blocks_needed > current_blocks) {
812 +               rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
813 +                            &blkno);
814 +               if (rc)
815 +                       return -rc;
816 +
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);
821 +
822 +               ea_buf->flag = EA_EXTENT | EA_NEW;
823 +
824 +               ea_buf->mp = get_metapage(inode, blkno,
825 +                                         blocks_needed << sb->s_blocksize_bits,
826 +                                         1);
827 +               if (ea_buf->mp == NULL) {
828 +                       dbFree(inode, blkno, (s64) blocks_needed);
829 +                       return -EIO;
830 +               }
831 +               ea_buf->xattr = ea_buf->mp->data;
832 +               ea_buf->max_size = (min_size + sb->s_blocksize - 1) &
833 +                   ~(sb->s_blocksize - 1);
834 +               if (ea_size == 0)
835 +                       return 0;
836 +               if ((rc = ea_read(inode, ea_buf->xattr))) {
837 +                       discard_metapage(ea_buf->mp);
838 +                       dbFree(inode, blkno, (s64) blocks_needed);
839 +                       return rc;
840 +               }
841 +               goto size_check;
842 +       }
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)
847 +               return -EIO;
848 +       ea_buf->xattr = ea_buf->mp->data;
849 +       ea_buf->max_size = (ea_size + sb->s_blocksize - 1) &
850 +           ~(sb->s_blocksize - 1);
851 +
852 +      size_check:
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);
857 +               return -EIO;
858 +       }
859 +
860 +       return ea_size;
861 +}
862 +
863 +static void ea_release(struct inode *inode, struct ea_buffer *ea_buf)
864 +{
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);
870 +
871 +               if (ea_buf->flag & EA_NEW)
872 +                       dbFree(inode, addressDXD(&ea_buf->new_ea),
873 +                              lengthDXD(&ea_buf->new_ea));
874 +       }
875 +}
876 +
877 +static int ea_put(struct inode *inode, struct ea_buffer *ea_buf, int new_size)
878 +{
879 +       struct jfs_inode_info *ji = JFS_IP(inode);
880 +       unsigned long old_blocks, new_blocks;
881 +       int rc = 0;
882 +       tid_t tid;
883 +
884 +       if (new_size == 0) {
885 +               ea_release(inode, ea_buf);
886 +               ea_buf = 0;
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);
900 +       } else {
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);
904 +       }
905 +       if (rc)
906 +               return rc;
907 +
908 +       tid = txBegin(inode->i_sb, 0);
909 +       down(&ji->commit_sem);
910 +
911 +       old_blocks = new_blocks = 0;
912 +
913 +       if (ji->ea.flag & DXD_EXTENT) {
914 +               invalidate_dxd_metapages(inode, ji->ea);
915 +               old_blocks = lengthDXD(&ji->ea);
916 +       }
917 +
918 +       if (ea_buf) {
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;
924 +               }
925 +               ji->ea = ea_buf->new_ea;
926 +       } else {
927 +               txEA(tid, inode, &ji->ea, 0);
928 +               if (ji->ea.flag & DXD_INLINE)
929 +                       ji->mode2 |= INLINEEA;
930 +               ji->ea.flag = 0;
931 +               ji->ea.size = 0;
932 +       }
933 +
934 +       inode->i_blocks += LBLK2PBLK(inode->i_sb, new_blocks - old_blocks);
935 +       rc = txCommit(tid, 1, &inode, 0);
936 +       txEnd(tid);
937 +       up(&ji->commit_sem);
938 +
939 +       return rc;
940 +}
941 +
942 +static int can_set_xattr(struct inode *inode, const char *name,
943 +                        const void *value, size_t value_len)
944 +{
945 +       if (IS_RDONLY(inode))
946 +               return -EROFS;
947 +
948 +       if (IS_IMMUTABLE(inode) || IS_APPEND(inode) || S_ISLNK(inode->i_mode))
949 +               return -EPERM;
950 +
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;
954 +
955 +       if (!S_ISREG(inode->i_mode) &&
956 +           (!S_ISDIR(inode->i_mode) || inode->i_mode &S_ISVTX))
957 +               return -EPERM;
958 +
959 +       return permission(inode, MAY_WRITE);
960 +}
961 +
962 +int __jfs_setxattr(struct inode *inode, const char *name, const void *value,
963 +                  size_t value_len, int flags)
964 +{
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;
969 +       int xattr_size;
970 +       int new_size;
971 +       int namelen = strlen(name);
972 +       char *os2name = NULL;
973 +       int found = 0;
974 +       int rc;
975 +       int length;
976 +
977 +       if ((rc = can_set_xattr(inode, name, value, value_len)))
978 +               return rc;
979 +
980 +       if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
981 +               os2name = kmalloc(namelen - XATTR_OS2_PREFIX_LEN + 1,
982 +                                 GFP_KERNEL);
983 +               if (!os2name)
984 +                       return -ENOMEM;
985 +               strcpy(os2name, name + XATTR_OS2_PREFIX_LEN);
986 +               name = os2name;
987 +               namelen -= XATTR_OS2_PREFIX_LEN;
988 +       }
989 +
990 +       xattr_size = ea_get(inode, &ea_buf, 0);
991 +       if (xattr_size < 0) {
992 +               rc = xattr_size;
993 +               goto out;
994 +       }
995 +
996 +      again:
997 +       ealist = (struct jfs_ea_list *) ea_buf.xattr;
998 +       new_size = sizeof (struct jfs_ea_list);
999 +
1000 +       if (xattr_size) {
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)) {
1005 +                               found = 1;
1006 +                               if (flags & XATTR_CREATE) {
1007 +                                       rc = -EEXIST;
1008 +                                       goto release;
1009 +                               }
1010 +                               old_ea = ea;
1011 +                               old_ea_size = EA_SIZE(ea);
1012 +                               next_ea = NEXT_EA(ea);
1013 +                       } else
1014 +                               new_size += EA_SIZE(ea);
1015 +               }
1016 +       }
1017 +
1018 +       if (!found) {
1019 +               if (flags & XATTR_REPLACE) {
1020 +                       rc = -ENODATA;
1021 +                       goto release;
1022 +               }
1023 +               if (value == NULL) {
1024 +                       rc = 0;
1025 +                       goto release;
1026 +               }
1027 +       }
1028 +       if (value)
1029 +               new_size += sizeof (struct jfs_ea) + namelen + 1 + value_len;
1030 +
1031 +       if (new_size > ea_buf.max_size) {
1032 +               /*
1033 +                * We need to allocate more space for merged ea list.
1034 +                * We should only have loop to again: once.
1035 +                */
1036 +               ea_release(inode, &ea_buf);
1037 +               xattr_size = ea_get(inode, &ea_buf, new_size);
1038 +               if (xattr_size < 0) {
1039 +                       rc = xattr_size;
1040 +                       goto out;
1041 +               }
1042 +               goto again;
1043 +       }
1044 +
1045 +       /* Remove old ea of the same name */
1046 +       if (found) {
1047 +               /* number of bytes following target EA */
1048 +               length = (char *) END_EALIST(ealist) - (char *) next_ea;
1049 +               if (length > 0)
1050 +                       memmove(old_ea, next_ea, length);
1051 +               xattr_size -= old_ea_size;
1052 +       }
1053 +
1054 +       /* Add new entry to the end */
1055 +       if (value) {
1056 +               if (xattr_size == 0)
1057 +                       /* Completely new ea list */
1058 +                       xattr_size = sizeof (struct jfs_ea_list);
1059 +
1060 +               ea = (struct jfs_ea *) ((char *) ealist + xattr_size);
1061 +               ea->flag = 0;
1062 +               ea->namelen = namelen;
1063 +               ea->valuelen = (cpu_to_le16(value_len));
1064 +               memcpy(ea->name, name, namelen);
1065 +               ea->name[namelen] = 0;
1066 +               if (value_len)
1067 +                       memcpy(&ea->name[namelen + 1], value, value_len);
1068 +               xattr_size += EA_SIZE(ea);
1069 +       }
1070 +
1071 +       /* DEBUG - If we did this right, these number match */
1072 +       if (xattr_size != new_size) {
1073 +               printk(KERN_ERR
1074 +                      "jfs_xsetattr: xattr_size = %d, new_size = %d\n",
1075 +                      xattr_size, new_size);
1076 +
1077 +               rc = -EINVAL;
1078 +               goto release;
1079 +       }
1080 +
1081 +       /*
1082 +        * If we're left with an empty list, there's no ea
1083 +        */
1084 +       if (new_size == sizeof (struct jfs_ea_list))
1085 +               new_size = 0;
1086 +
1087 +       ealist->size = cpu_to_le32(new_size);
1088 +
1089 +       rc = ea_put(inode, &ea_buf, new_size);
1090 +
1091 +       goto out;
1092 +      release:
1093 +       ea_release(inode, &ea_buf);
1094 +      out:
1095 +       if (os2name)
1096 +               kfree(os2name);
1097 +
1098 +       return rc;
1099 +}
1100 +
1101 +int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
1102 +                size_t value_len, int flags)
1103 +{
1104 +       if (value == NULL) {    /* empty EA, do not remove */
1105 +               value = "";
1106 +               value_len = 0;
1107 +       }
1108 +
1109 +       return __jfs_setxattr(dentry->d_inode, name, value, value_len, flags);
1110 +}
1111 +
1112 +static inline int can_get_xattr(struct inode *inode, const char *name)
1113 +{
1114 +       return permission(inode, MAY_READ);
1115 +}
1116 +
1117 +ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data,
1118 +                      size_t buf_size)
1119 +{
1120 +       struct jfs_ea_list *ealist;
1121 +       struct jfs_ea *ea;
1122 +       struct ea_buffer ea_buf;
1123 +       int xattr_size;
1124 +       ssize_t size;
1125 +       int namelen = strlen(name);
1126 +       char *os2name = NULL;
1127 +       int rc;
1128 +       char *value;
1129 +
1130 +       if ((rc = can_get_xattr(inode, name)))
1131 +               return rc;
1132 +
1133 +       if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
1134 +               os2name = kmalloc(namelen - XATTR_OS2_PREFIX_LEN + 1,
1135 +                                 GFP_KERNEL);
1136 +               if (!os2name)
1137 +                       return -ENOMEM;
1138 +               strcpy(os2name, name + XATTR_OS2_PREFIX_LEN);
1139 +               name = os2name;
1140 +               namelen -= XATTR_OS2_PREFIX_LEN;
1141 +       }
1142 +
1143 +       xattr_size = ea_get(inode, &ea_buf, 0);
1144 +       if (xattr_size < 0) {
1145 +               size = xattr_size;
1146 +               goto out;
1147 +       }
1148 +
1149 +       if (xattr_size == 0)
1150 +               goto not_found;
1151 +
1152 +       ealist = (struct jfs_ea_list *) ea_buf.xattr;
1153 +
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) {
1158 +                       /* Found it */
1159 +                       size = le16_to_cpu(ea->valuelen);
1160 +                       if (!data)
1161 +                               goto release;
1162 +                       else if (size > buf_size) {
1163 +                               size = -ERANGE;
1164 +                               goto release;
1165 +                       }
1166 +                       value = ((char *) &ea->name) + ea->namelen + 1;
1167 +                       memcpy(data, value, size);
1168 +                       goto release;
1169 +               }
1170 +      not_found:
1171 +       size = -ENODATA;
1172 +      release:
1173 +       ea_release(inode, &ea_buf);
1174 +      out:
1175 +       if (os2name)
1176 +               kfree(os2name);
1177 +
1178 +       return size;
1179 +}
1180 +
1181 +ssize_t jfs_getxattr(struct dentry *dentry, const char *name, void *data,
1182 +                    size_t buf_size)
1183 +{
1184 +       return __jfs_getxattr(dentry->d_inode, name, data, buf_size);
1185 +}
1186 +
1187 +ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size)
1188 +{
1189 +       struct inode *inode = dentry->d_inode;
1190 +       char *buffer;
1191 +       ssize_t size = 0;
1192 +       int xattr_size;
1193 +       struct jfs_ea_list *ealist;
1194 +       struct jfs_ea *ea;
1195 +       struct ea_buffer ea_buf;
1196 +
1197 +       xattr_size = ea_get(inode, &ea_buf, 0);
1198 +       if (xattr_size < 0) {
1199 +               size = xattr_size;
1200 +               goto out;
1201 +       }
1202 +
1203 +       if (xattr_size == 0)
1204 +               goto release;
1205 +
1206 +       ealist = (struct jfs_ea_list *) ea_buf.xattr;
1207 +
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;
1211 +
1212 +       if (!data)
1213 +               goto release;
1214 +
1215 +       if (size > buf_size) {
1216 +               size = -ERANGE;
1217 +               goto release;
1218 +       }
1219 +
1220 +       /* Copy attribute names to buffer */
1221 +       buffer = data;
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;
1225 +       }
1226 +
1227 +      release:
1228 +       ea_release(inode, &ea_buf);
1229 +      out:
1230 +       return size;
1231 +}
1232 +
1233 +int jfs_removexattr(struct dentry *dentry, const char *name)
1234 +{
1235 +       return __jfs_setxattr(dentry->d_inode, name, 0, 0, XATTR_REPLACE);
1236 +}
This page took 1.855446 seconds and 3 git commands to generate.