Merge branch 'for-linus' of git://oss.sgi.com:8090/xfs/xfs-2.6
[safe/jmp/linux-2.6] / fs / xfs / linux-2.6 / xfs_iops.c
1 /*
2  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18 #include "xfs.h"
19 #include "xfs_fs.h"
20 #include "xfs_bit.h"
21 #include "xfs_log.h"
22 #include "xfs_inum.h"
23 #include "xfs_trans.h"
24 #include "xfs_sb.h"
25 #include "xfs_ag.h"
26 #include "xfs_dir2.h"
27 #include "xfs_alloc.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_quota.h"
30 #include "xfs_mount.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_alloc_btree.h"
33 #include "xfs_ialloc_btree.h"
34 #include "xfs_dir2_sf.h"
35 #include "xfs_attr_sf.h"
36 #include "xfs_dinode.h"
37 #include "xfs_inode.h"
38 #include "xfs_bmap.h"
39 #include "xfs_btree.h"
40 #include "xfs_ialloc.h"
41 #include "xfs_rtalloc.h"
42 #include "xfs_error.h"
43 #include "xfs_itable.h"
44 #include "xfs_rw.h"
45 #include "xfs_acl.h"
46 #include "xfs_attr.h"
47 #include "xfs_buf_item.h"
48 #include "xfs_utils.h"
49 #include "xfs_vnodeops.h"
50
51 #include <linux/capability.h>
52 #include <linux/xattr.h>
53 #include <linux/namei.h>
54 #include <linux/security.h>
55
56 /*
57  * Bring the atime in the XFS inode uptodate.
58  * Used before logging the inode to disk or when the Linux inode goes away.
59  */
60 void
61 xfs_synchronize_atime(
62         xfs_inode_t     *ip)
63 {
64         bhv_vnode_t     *vp;
65
66         vp = XFS_ITOV_NULL(ip);
67         if (vp) {
68                 ip->i_d.di_atime.t_sec = (__int32_t)vp->i_atime.tv_sec;
69                 ip->i_d.di_atime.t_nsec = (__int32_t)vp->i_atime.tv_nsec;
70         }
71 }
72
73 /*
74  * Change the requested timestamp in the given inode.
75  * We don't lock across timestamp updates, and we don't log them but
76  * we do record the fact that there is dirty information in core.
77  *
78  * NOTE -- callers MUST combine XFS_ICHGTIME_MOD or XFS_ICHGTIME_CHG
79  *              with XFS_ICHGTIME_ACC to be sure that access time
80  *              update will take.  Calling first with XFS_ICHGTIME_ACC
81  *              and then XFS_ICHGTIME_MOD may fail to modify the access
82  *              timestamp if the filesystem is mounted noacctm.
83  */
84 void
85 xfs_ichgtime(
86         xfs_inode_t     *ip,
87         int             flags)
88 {
89         struct inode    *inode = vn_to_inode(XFS_ITOV(ip));
90         timespec_t      tv;
91
92         nanotime(&tv);
93         if (flags & XFS_ICHGTIME_MOD) {
94                 inode->i_mtime = tv;
95                 ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec;
96                 ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec;
97         }
98         if (flags & XFS_ICHGTIME_ACC) {
99                 inode->i_atime = tv;
100                 ip->i_d.di_atime.t_sec = (__int32_t)tv.tv_sec;
101                 ip->i_d.di_atime.t_nsec = (__int32_t)tv.tv_nsec;
102         }
103         if (flags & XFS_ICHGTIME_CHG) {
104                 inode->i_ctime = tv;
105                 ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec;
106                 ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec;
107         }
108
109         /*
110          * We update the i_update_core field _after_ changing
111          * the timestamps in order to coordinate properly with
112          * xfs_iflush() so that we don't lose timestamp updates.
113          * This keeps us from having to hold the inode lock
114          * while doing this.  We use the SYNCHRONIZE macro to
115          * ensure that the compiler does not reorder the update
116          * of i_update_core above the timestamp updates above.
117          */
118         SYNCHRONIZE();
119         ip->i_update_core = 1;
120         if (!(inode->i_state & I_SYNC))
121                 mark_inode_dirty_sync(inode);
122 }
123
124 /*
125  * Variant on the above which avoids querying the system clock
126  * in situations where we know the Linux inode timestamps have
127  * just been updated (and so we can update our inode cheaply).
128  */
129 void
130 xfs_ichgtime_fast(
131         xfs_inode_t     *ip,
132         struct inode    *inode,
133         int             flags)
134 {
135         timespec_t      *tvp;
136
137         /*
138          * Atime updates for read() & friends are handled lazily now, and
139          * explicit updates must go through xfs_ichgtime()
140          */
141         ASSERT((flags & XFS_ICHGTIME_ACC) == 0);
142
143         /*
144          * We're not supposed to change timestamps in readonly-mounted
145          * filesystems.  Throw it away if anyone asks us.
146          */
147         if (unlikely(IS_RDONLY(inode)))
148                 return;
149
150         if (flags & XFS_ICHGTIME_MOD) {
151                 tvp = &inode->i_mtime;
152                 ip->i_d.di_mtime.t_sec = (__int32_t)tvp->tv_sec;
153                 ip->i_d.di_mtime.t_nsec = (__int32_t)tvp->tv_nsec;
154         }
155         if (flags & XFS_ICHGTIME_CHG) {
156                 tvp = &inode->i_ctime;
157                 ip->i_d.di_ctime.t_sec = (__int32_t)tvp->tv_sec;
158                 ip->i_d.di_ctime.t_nsec = (__int32_t)tvp->tv_nsec;
159         }
160
161         /*
162          * We update the i_update_core field _after_ changing
163          * the timestamps in order to coordinate properly with
164          * xfs_iflush() so that we don't lose timestamp updates.
165          * This keeps us from having to hold the inode lock
166          * while doing this.  We use the SYNCHRONIZE macro to
167          * ensure that the compiler does not reorder the update
168          * of i_update_core above the timestamp updates above.
169          */
170         SYNCHRONIZE();
171         ip->i_update_core = 1;
172         if (!(inode->i_state & I_SYNC))
173                 mark_inode_dirty_sync(inode);
174 }
175
176
177 /*
178  * Pull the link count and size up from the xfs inode to the linux inode
179  */
180 STATIC void
181 xfs_validate_fields(
182         struct inode            *inode)
183 {
184         struct xfs_inode        *ip = XFS_I(inode);
185         loff_t size;
186
187         inode->i_nlink = ip->i_d.di_nlink;
188         inode->i_blocks =
189                 XFS_FSB_TO_BB(ip->i_mount, ip->i_d.di_nblocks +
190                                            ip->i_delayed_blks);
191         /* we're under i_sem so i_size can't change under us */
192         size = XFS_ISIZE(ip);
193         if (i_size_read(inode) != size)
194                 i_size_write(inode, size);
195 }
196
197 /*
198  * Hook in SELinux.  This is not quite correct yet, what we really need
199  * here (as we do for default ACLs) is a mechanism by which creation of
200  * these attrs can be journalled at inode creation time (along with the
201  * inode, of course, such that log replay can't cause these to be lost).
202  */
203 STATIC int
204 xfs_init_security(
205         bhv_vnode_t     *vp,
206         struct inode    *dir)
207 {
208         struct inode    *ip = vn_to_inode(vp);
209         size_t          length;
210         void            *value;
211         char            *name;
212         int             error;
213
214         error = security_inode_init_security(ip, dir, &name, &value, &length);
215         if (error) {
216                 if (error == -EOPNOTSUPP)
217                         return 0;
218                 return -error;
219         }
220
221         error = xfs_attr_set(XFS_I(ip), name, value,
222                         length, ATTR_SECURE);
223         if (!error)
224                 xfs_iflags_set(XFS_I(ip), XFS_IMODIFIED);
225
226         kfree(name);
227         kfree(value);
228         return error;
229 }
230
231 /*
232  * Determine whether a process has a valid fs_struct (kernel daemons
233  * like knfsd don't have an fs_struct).
234  *
235  * XXX(hch):  nfsd is broken, better fix it instead.
236  */
237 STATIC_INLINE int
238 xfs_has_fs_struct(struct task_struct *task)
239 {
240         return (task->fs != init_task.fs);
241 }
242
243 STATIC void
244 xfs_cleanup_inode(
245         struct inode    *dir,
246         bhv_vnode_t     *vp,
247         struct dentry   *dentry,
248         int             mode)
249 {
250         struct dentry   teardown = {};
251
252         /* Oh, the horror.
253          * If we can't add the ACL or we fail in
254          * xfs_init_security we must back out.
255          * ENOSPC can hit here, among other things.
256          */
257         teardown.d_inode = vn_to_inode(vp);
258         teardown.d_name = dentry->d_name;
259
260         if (S_ISDIR(mode))
261                 xfs_rmdir(XFS_I(dir), &teardown);
262         else
263                 xfs_remove(XFS_I(dir), &teardown);
264         VN_RELE(vp);
265 }
266
267 STATIC int
268 xfs_vn_mknod(
269         struct inode    *dir,
270         struct dentry   *dentry,
271         int             mode,
272         dev_t           rdev)
273 {
274         struct inode    *ip;
275         bhv_vnode_t     *vp = NULL, *dvp = vn_from_inode(dir);
276         xfs_acl_t       *default_acl = NULL;
277         attrexists_t    test_default_acl = _ACL_DEFAULT_EXISTS;
278         int             error;
279
280         /*
281          * Irix uses Missed'em'V split, but doesn't want to see
282          * the upper 5 bits of (14bit) major.
283          */
284         if (unlikely(!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff))
285                 return -EINVAL;
286
287         if (unlikely(test_default_acl && test_default_acl(dvp))) {
288                 if (!_ACL_ALLOC(default_acl)) {
289                         return -ENOMEM;
290                 }
291                 if (!_ACL_GET_DEFAULT(dvp, default_acl)) {
292                         _ACL_FREE(default_acl);
293                         default_acl = NULL;
294                 }
295         }
296
297         if (IS_POSIXACL(dir) && !default_acl && xfs_has_fs_struct(current))
298                 mode &= ~current->fs->umask;
299
300         switch (mode & S_IFMT) {
301         case S_IFCHR: case S_IFBLK: case S_IFIFO: case S_IFSOCK:
302                 rdev = sysv_encode_dev(rdev);
303         case S_IFREG:
304                 error = xfs_create(XFS_I(dir), dentry, mode, rdev, &vp, NULL);
305                 break;
306         case S_IFDIR:
307                 error = xfs_mkdir(XFS_I(dir), dentry, mode, &vp, NULL);
308                 break;
309         default:
310                 error = EINVAL;
311                 break;
312         }
313
314         if (unlikely(!error)) {
315                 error = xfs_init_security(vp, dir);
316                 if (error)
317                         xfs_cleanup_inode(dir, vp, dentry, mode);
318         }
319
320         if (unlikely(default_acl)) {
321                 if (!error) {
322                         error = _ACL_INHERIT(vp, mode, default_acl);
323                         if (!error)
324                                 xfs_iflags_set(XFS_I(vp), XFS_IMODIFIED);
325                         else
326                                 xfs_cleanup_inode(dir, vp, dentry, mode);
327                 }
328                 _ACL_FREE(default_acl);
329         }
330
331         if (likely(!error)) {
332                 ASSERT(vp);
333                 ip = vn_to_inode(vp);
334
335                 if (S_ISCHR(mode) || S_ISBLK(mode))
336                         ip->i_rdev = rdev;
337                 else if (S_ISDIR(mode))
338                         xfs_validate_fields(ip);
339                 d_instantiate(dentry, ip);
340                 xfs_validate_fields(dir);
341         }
342         return -error;
343 }
344
345 STATIC int
346 xfs_vn_create(
347         struct inode    *dir,
348         struct dentry   *dentry,
349         int             mode,
350         struct nameidata *nd)
351 {
352         return xfs_vn_mknod(dir, dentry, mode, 0);
353 }
354
355 STATIC int
356 xfs_vn_mkdir(
357         struct inode    *dir,
358         struct dentry   *dentry,
359         int             mode)
360 {
361         return xfs_vn_mknod(dir, dentry, mode|S_IFDIR, 0);
362 }
363
364 STATIC struct dentry *
365 xfs_vn_lookup(
366         struct inode    *dir,
367         struct dentry   *dentry,
368         struct nameidata *nd)
369 {
370         bhv_vnode_t     *cvp;
371         int             error;
372
373         if (dentry->d_name.len >= MAXNAMELEN)
374                 return ERR_PTR(-ENAMETOOLONG);
375
376         error = xfs_lookup(XFS_I(dir), dentry, &cvp);
377         if (unlikely(error)) {
378                 if (unlikely(error != ENOENT))
379                         return ERR_PTR(-error);
380                 d_add(dentry, NULL);
381                 return NULL;
382         }
383
384         return d_splice_alias(vn_to_inode(cvp), dentry);
385 }
386
387 STATIC int
388 xfs_vn_link(
389         struct dentry   *old_dentry,
390         struct inode    *dir,
391         struct dentry   *dentry)
392 {
393         struct inode    *ip;    /* inode of guy being linked to */
394         bhv_vnode_t     *vp;    /* vp of name being linked */
395         int             error;
396
397         ip = old_dentry->d_inode;       /* inode being linked to */
398         vp = vn_from_inode(ip);
399
400         VN_HOLD(vp);
401         error = xfs_link(XFS_I(dir), vp, dentry);
402         if (unlikely(error)) {
403                 VN_RELE(vp);
404         } else {
405                 xfs_iflags_set(XFS_I(dir), XFS_IMODIFIED);
406                 xfs_validate_fields(ip);
407                 d_instantiate(dentry, ip);
408         }
409         return -error;
410 }
411
412 STATIC int
413 xfs_vn_unlink(
414         struct inode    *dir,
415         struct dentry   *dentry)
416 {
417         struct inode    *inode;
418         int             error;
419
420         inode = dentry->d_inode;
421
422         error = xfs_remove(XFS_I(dir), dentry);
423         if (likely(!error)) {
424                 xfs_validate_fields(dir);       /* size needs update */
425                 xfs_validate_fields(inode);
426         }
427         return -error;
428 }
429
430 STATIC int
431 xfs_vn_symlink(
432         struct inode    *dir,
433         struct dentry   *dentry,
434         const char      *symname)
435 {
436         struct inode    *ip;
437         bhv_vnode_t     *cvp;   /* used to lookup symlink to put in dentry */
438         int             error;
439         mode_t          mode;
440
441         cvp = NULL;
442
443         mode = S_IFLNK |
444                 (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO);
445
446         error = xfs_symlink(XFS_I(dir), dentry, (char *)symname, mode,
447                             &cvp, NULL);
448         if (likely(!error && cvp)) {
449                 error = xfs_init_security(cvp, dir);
450                 if (likely(!error)) {
451                         ip = vn_to_inode(cvp);
452                         d_instantiate(dentry, ip);
453                         xfs_validate_fields(dir);
454                         xfs_validate_fields(ip);
455                 } else {
456                         xfs_cleanup_inode(dir, cvp, dentry, 0);
457                 }
458         }
459         return -error;
460 }
461
462 STATIC int
463 xfs_vn_rmdir(
464         struct inode    *dir,
465         struct dentry   *dentry)
466 {
467         struct inode    *inode = dentry->d_inode;
468         int             error;
469
470         error = xfs_rmdir(XFS_I(dir), dentry);
471         if (likely(!error)) {
472                 xfs_validate_fields(inode);
473                 xfs_validate_fields(dir);
474         }
475         return -error;
476 }
477
478 STATIC int
479 xfs_vn_rename(
480         struct inode    *odir,
481         struct dentry   *odentry,
482         struct inode    *ndir,
483         struct dentry   *ndentry)
484 {
485         struct inode    *new_inode = ndentry->d_inode;
486         bhv_vnode_t     *tvp;   /* target directory */
487         int             error;
488
489         tvp = vn_from_inode(ndir);
490
491         error = xfs_rename(XFS_I(odir), odentry, tvp, ndentry);
492         if (likely(!error)) {
493                 if (new_inode)
494                         xfs_validate_fields(new_inode);
495                 xfs_validate_fields(odir);
496                 if (ndir != odir)
497                         xfs_validate_fields(ndir);
498         }
499         return -error;
500 }
501
502 /*
503  * careful here - this function can get called recursively, so
504  * we need to be very careful about how much stack we use.
505  * uio is kmalloced for this reason...
506  */
507 STATIC void *
508 xfs_vn_follow_link(
509         struct dentry           *dentry,
510         struct nameidata        *nd)
511 {
512         char                    *link;
513         int                     error = -ENOMEM;
514
515         link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
516         if (!link)
517                 goto out_err;
518
519         error = -xfs_readlink(XFS_I(dentry->d_inode), link);
520         if (unlikely(error))
521                 goto out_kfree;
522
523         nd_set_link(nd, link);
524         return NULL;
525
526  out_kfree:
527         kfree(link);
528  out_err:
529         nd_set_link(nd, ERR_PTR(error));
530         return NULL;
531 }
532
533 STATIC void
534 xfs_vn_put_link(
535         struct dentry   *dentry,
536         struct nameidata *nd,
537         void            *p)
538 {
539         char            *s = nd_get_link(nd);
540
541         if (!IS_ERR(s))
542                 kfree(s);
543 }
544
545 #ifdef CONFIG_XFS_POSIX_ACL
546 STATIC int
547 xfs_vn_permission(
548         struct inode    *inode,
549         int             mode,
550         struct nameidata *nd)
551 {
552         return -xfs_access(XFS_I(inode), mode << 6, NULL);
553 }
554 #else
555 #define xfs_vn_permission NULL
556 #endif
557
558 STATIC int
559 xfs_vn_getattr(
560         struct vfsmount *mnt,
561         struct dentry   *dentry,
562         struct kstat    *stat)
563 {
564         struct inode    *inode = dentry->d_inode;
565         bhv_vattr_t     vattr = { .va_mask = XFS_AT_STAT };
566         int             error;
567
568         error = xfs_getattr(XFS_I(inode), &vattr, ATTR_LAZY);
569         if (likely(!error)) {
570                 stat->size = i_size_read(inode);
571                 stat->dev = inode->i_sb->s_dev;
572                 stat->rdev = (vattr.va_rdev == 0) ? 0 :
573                                 MKDEV(sysv_major(vattr.va_rdev) & 0x1ff,
574                                       sysv_minor(vattr.va_rdev));
575                 stat->mode = vattr.va_mode;
576                 stat->nlink = vattr.va_nlink;
577                 stat->uid = vattr.va_uid;
578                 stat->gid = vattr.va_gid;
579                 stat->ino = vattr.va_nodeid;
580                 stat->atime = vattr.va_atime;
581                 stat->mtime = vattr.va_mtime;
582                 stat->ctime = vattr.va_ctime;
583                 stat->blocks = vattr.va_nblocks;
584                 stat->blksize = vattr.va_blocksize;
585         }
586         return -error;
587 }
588
589 STATIC int
590 xfs_vn_setattr(
591         struct dentry   *dentry,
592         struct iattr    *attr)
593 {
594         struct inode    *inode = dentry->d_inode;
595         unsigned int    ia_valid = attr->ia_valid;
596         bhv_vattr_t     vattr = { 0 };
597         int             flags = 0;
598         int             error;
599
600         if (ia_valid & ATTR_UID) {
601                 vattr.va_mask |= XFS_AT_UID;
602                 vattr.va_uid = attr->ia_uid;
603         }
604         if (ia_valid & ATTR_GID) {
605                 vattr.va_mask |= XFS_AT_GID;
606                 vattr.va_gid = attr->ia_gid;
607         }
608         if (ia_valid & ATTR_SIZE) {
609                 vattr.va_mask |= XFS_AT_SIZE;
610                 vattr.va_size = attr->ia_size;
611         }
612         if (ia_valid & ATTR_ATIME) {
613                 vattr.va_mask |= XFS_AT_ATIME;
614                 vattr.va_atime = attr->ia_atime;
615                 inode->i_atime = attr->ia_atime;
616         }
617         if (ia_valid & ATTR_MTIME) {
618                 vattr.va_mask |= XFS_AT_MTIME;
619                 vattr.va_mtime = attr->ia_mtime;
620         }
621         if (ia_valid & ATTR_CTIME) {
622                 vattr.va_mask |= XFS_AT_CTIME;
623                 vattr.va_ctime = attr->ia_ctime;
624         }
625         if (ia_valid & ATTR_MODE) {
626                 vattr.va_mask |= XFS_AT_MODE;
627                 vattr.va_mode = attr->ia_mode;
628                 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
629                         inode->i_mode &= ~S_ISGID;
630         }
631
632         if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))
633                 flags |= ATTR_UTIME;
634 #ifdef ATTR_NO_BLOCK
635         if ((ia_valid & ATTR_NO_BLOCK))
636                 flags |= ATTR_NONBLOCK;
637 #endif
638
639         error = xfs_setattr(XFS_I(inode), &vattr, flags, NULL);
640         if (likely(!error))
641                 __vn_revalidate(vn_from_inode(inode), &vattr);
642         return -error;
643 }
644
645 STATIC void
646 xfs_vn_truncate(
647         struct inode    *inode)
648 {
649         block_truncate_page(inode->i_mapping, inode->i_size, xfs_get_blocks);
650 }
651
652 STATIC int
653 xfs_vn_setxattr(
654         struct dentry   *dentry,
655         const char      *name,
656         const void      *data,
657         size_t          size,
658         int             flags)
659 {
660         bhv_vnode_t     *vp = vn_from_inode(dentry->d_inode);
661         char            *attr = (char *)name;
662         attrnames_t     *namesp;
663         int             xflags = 0;
664         int             error;
665
666         namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
667         if (!namesp)
668                 return -EOPNOTSUPP;
669         attr += namesp->attr_namelen;
670         error = namesp->attr_capable(vp, NULL);
671         if (error)
672                 return error;
673
674         /* Convert Linux syscall to XFS internal ATTR flags */
675         if (flags & XATTR_CREATE)
676                 xflags |= ATTR_CREATE;
677         if (flags & XATTR_REPLACE)
678                 xflags |= ATTR_REPLACE;
679         xflags |= namesp->attr_flag;
680         return namesp->attr_set(vp, attr, (void *)data, size, xflags);
681 }
682
683 STATIC ssize_t
684 xfs_vn_getxattr(
685         struct dentry   *dentry,
686         const char      *name,
687         void            *data,
688         size_t          size)
689 {
690         bhv_vnode_t     *vp = vn_from_inode(dentry->d_inode);
691         char            *attr = (char *)name;
692         attrnames_t     *namesp;
693         int             xflags = 0;
694         ssize_t         error;
695
696         namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
697         if (!namesp)
698                 return -EOPNOTSUPP;
699         attr += namesp->attr_namelen;
700         error = namesp->attr_capable(vp, NULL);
701         if (error)
702                 return error;
703
704         /* Convert Linux syscall to XFS internal ATTR flags */
705         if (!size) {
706                 xflags |= ATTR_KERNOVAL;
707                 data = NULL;
708         }
709         xflags |= namesp->attr_flag;
710         return namesp->attr_get(vp, attr, (void *)data, size, xflags);
711 }
712
713 STATIC ssize_t
714 xfs_vn_listxattr(
715         struct dentry           *dentry,
716         char                    *data,
717         size_t                  size)
718 {
719         bhv_vnode_t             *vp = vn_from_inode(dentry->d_inode);
720         int                     error, xflags = ATTR_KERNAMELS;
721         ssize_t                 result;
722
723         if (!size)
724                 xflags |= ATTR_KERNOVAL;
725         xflags |= capable(CAP_SYS_ADMIN) ? ATTR_KERNFULLS : ATTR_KERNORMALS;
726
727         error = attr_generic_list(vp, data, size, xflags, &result);
728         if (error < 0)
729                 return error;
730         return result;
731 }
732
733 STATIC int
734 xfs_vn_removexattr(
735         struct dentry   *dentry,
736         const char      *name)
737 {
738         bhv_vnode_t     *vp = vn_from_inode(dentry->d_inode);
739         char            *attr = (char *)name;
740         attrnames_t     *namesp;
741         int             xflags = 0;
742         int             error;
743
744         namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
745         if (!namesp)
746                 return -EOPNOTSUPP;
747         attr += namesp->attr_namelen;
748         error = namesp->attr_capable(vp, NULL);
749         if (error)
750                 return error;
751         xflags |= namesp->attr_flag;
752         return namesp->attr_remove(vp, attr, xflags);
753 }
754
755
756 const struct inode_operations xfs_inode_operations = {
757         .permission             = xfs_vn_permission,
758         .truncate               = xfs_vn_truncate,
759         .getattr                = xfs_vn_getattr,
760         .setattr                = xfs_vn_setattr,
761         .setxattr               = xfs_vn_setxattr,
762         .getxattr               = xfs_vn_getxattr,
763         .listxattr              = xfs_vn_listxattr,
764         .removexattr            = xfs_vn_removexattr,
765 };
766
767 const struct inode_operations xfs_dir_inode_operations = {
768         .create                 = xfs_vn_create,
769         .lookup                 = xfs_vn_lookup,
770         .link                   = xfs_vn_link,
771         .unlink                 = xfs_vn_unlink,
772         .symlink                = xfs_vn_symlink,
773         .mkdir                  = xfs_vn_mkdir,
774         .rmdir                  = xfs_vn_rmdir,
775         .mknod                  = xfs_vn_mknod,
776         .rename                 = xfs_vn_rename,
777         .permission             = xfs_vn_permission,
778         .getattr                = xfs_vn_getattr,
779         .setattr                = xfs_vn_setattr,
780         .setxattr               = xfs_vn_setxattr,
781         .getxattr               = xfs_vn_getxattr,
782         .listxattr              = xfs_vn_listxattr,
783         .removexattr            = xfs_vn_removexattr,
784 };
785
786 const struct inode_operations xfs_symlink_inode_operations = {
787         .readlink               = generic_readlink,
788         .follow_link            = xfs_vn_follow_link,
789         .put_link               = xfs_vn_put_link,
790         .permission             = xfs_vn_permission,
791         .getattr                = xfs_vn_getattr,
792         .setattr                = xfs_vn_setattr,
793         .setxattr               = xfs_vn_setxattr,
794         .getxattr               = xfs_vn_getxattr,
795         .listxattr              = xfs_vn_listxattr,
796         .removexattr            = xfs_vn_removexattr,
797 };