]> err.no Git - linux-2.6/blob - fs/xfs/linux-2.6/xfs_iops.c
[XFS] Fix symlink creation too, with respect to initialising SELinux
[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_dir.h"
27 #include "xfs_dir2.h"
28 #include "xfs_alloc.h"
29 #include "xfs_dmapi.h"
30 #include "xfs_quota.h"
31 #include "xfs_mount.h"
32 #include "xfs_bmap_btree.h"
33 #include "xfs_alloc_btree.h"
34 #include "xfs_ialloc_btree.h"
35 #include "xfs_dir_sf.h"
36 #include "xfs_dir2_sf.h"
37 #include "xfs_attr_sf.h"
38 #include "xfs_dinode.h"
39 #include "xfs_inode.h"
40 #include "xfs_bmap.h"
41 #include "xfs_btree.h"
42 #include "xfs_ialloc.h"
43 #include "xfs_rtalloc.h"
44 #include "xfs_error.h"
45 #include "xfs_itable.h"
46 #include "xfs_rw.h"
47 #include "xfs_acl.h"
48 #include "xfs_cap.h"
49 #include "xfs_mac.h"
50 #include "xfs_attr.h"
51 #include "xfs_buf_item.h"
52 #include "xfs_utils.h"
53
54 #include <linux/capability.h>
55 #include <linux/xattr.h>
56 #include <linux/namei.h>
57 #include <linux/security.h>
58
59 #define IS_NOATIME(inode) ((inode->i_sb->s_flags & MS_NOATIME) ||       \
60         (S_ISDIR(inode->i_mode) && inode->i_sb->s_flags & MS_NODIRATIME))
61
62 /*
63  * Get a XFS inode from a given vnode.
64  */
65 xfs_inode_t *
66 xfs_vtoi(
67         struct vnode    *vp)
68 {
69         bhv_desc_t      *bdp;
70
71         bdp = bhv_lookup_range(VN_BHV_HEAD(vp),
72                         VNODE_POSITION_XFS, VNODE_POSITION_XFS);
73         if (unlikely(bdp == NULL))
74                 return NULL;
75         return XFS_BHVTOI(bdp);
76 }
77
78 /*
79  * Bring the atime in the XFS inode uptodate.
80  * Used before logging the inode to disk or when the Linux inode goes away.
81  */
82 void
83 xfs_synchronize_atime(
84         xfs_inode_t     *ip)
85 {
86         vnode_t         *vp;
87
88         vp = XFS_ITOV_NULL(ip);
89         if (vp) {
90                 struct inode *inode = &vp->v_inode;
91                 ip->i_d.di_atime.t_sec = (__int32_t)inode->i_atime.tv_sec;
92                 ip->i_d.di_atime.t_nsec = (__int32_t)inode->i_atime.tv_nsec;
93         }
94 }
95
96 /*
97  * Change the requested timestamp in the given inode.
98  * We don't lock across timestamp updates, and we don't log them but
99  * we do record the fact that there is dirty information in core.
100  *
101  * NOTE -- callers MUST combine XFS_ICHGTIME_MOD or XFS_ICHGTIME_CHG
102  *              with XFS_ICHGTIME_ACC to be sure that access time
103  *              update will take.  Calling first with XFS_ICHGTIME_ACC
104  *              and then XFS_ICHGTIME_MOD may fail to modify the access
105  *              timestamp if the filesystem is mounted noacctm.
106  */
107 void
108 xfs_ichgtime(
109         xfs_inode_t     *ip,
110         int             flags)
111 {
112         struct inode    *inode = LINVFS_GET_IP(XFS_ITOV(ip));
113         timespec_t      tv;
114
115         nanotime(&tv);
116         if (flags & XFS_ICHGTIME_MOD) {
117                 inode->i_mtime = tv;
118                 ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec;
119                 ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec;
120         }
121         if (flags & XFS_ICHGTIME_ACC) {
122                 inode->i_atime = tv;
123                 ip->i_d.di_atime.t_sec = (__int32_t)tv.tv_sec;
124                 ip->i_d.di_atime.t_nsec = (__int32_t)tv.tv_nsec;
125         }
126         if (flags & XFS_ICHGTIME_CHG) {
127                 inode->i_ctime = tv;
128                 ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec;
129                 ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec;
130         }
131
132         /*
133          * We update the i_update_core field _after_ changing
134          * the timestamps in order to coordinate properly with
135          * xfs_iflush() so that we don't lose timestamp updates.
136          * This keeps us from having to hold the inode lock
137          * while doing this.  We use the SYNCHRONIZE macro to
138          * ensure that the compiler does not reorder the update
139          * of i_update_core above the timestamp updates above.
140          */
141         SYNCHRONIZE();
142         ip->i_update_core = 1;
143         if (!(inode->i_state & I_LOCK))
144                 mark_inode_dirty_sync(inode);
145 }
146
147 /*
148  * Variant on the above which avoids querying the system clock
149  * in situations where we know the Linux inode timestamps have
150  * just been updated (and so we can update our inode cheaply).
151  */
152 void
153 xfs_ichgtime_fast(
154         xfs_inode_t     *ip,
155         struct inode    *inode,
156         int             flags)
157 {
158         timespec_t      *tvp;
159
160         /*
161          * Atime updates for read() & friends are handled lazily now, and
162          * explicit updates must go through xfs_ichgtime()
163          */
164         ASSERT((flags & XFS_ICHGTIME_ACC) == 0);
165
166         /*
167          * We're not supposed to change timestamps in readonly-mounted
168          * filesystems.  Throw it away if anyone asks us.
169          */
170         if (unlikely(IS_RDONLY(inode)))
171                 return;
172
173         if (flags & XFS_ICHGTIME_MOD) {
174                 tvp = &inode->i_mtime;
175                 ip->i_d.di_mtime.t_sec = (__int32_t)tvp->tv_sec;
176                 ip->i_d.di_mtime.t_nsec = (__int32_t)tvp->tv_nsec;
177         }
178         if (flags & XFS_ICHGTIME_CHG) {
179                 tvp = &inode->i_ctime;
180                 ip->i_d.di_ctime.t_sec = (__int32_t)tvp->tv_sec;
181                 ip->i_d.di_ctime.t_nsec = (__int32_t)tvp->tv_nsec;
182         }
183
184         /*
185          * We update the i_update_core field _after_ changing
186          * the timestamps in order to coordinate properly with
187          * xfs_iflush() so that we don't lose timestamp updates.
188          * This keeps us from having to hold the inode lock
189          * while doing this.  We use the SYNCHRONIZE macro to
190          * ensure that the compiler does not reorder the update
191          * of i_update_core above the timestamp updates above.
192          */
193         SYNCHRONIZE();
194         ip->i_update_core = 1;
195         if (!(inode->i_state & I_LOCK))
196                 mark_inode_dirty_sync(inode);
197 }
198
199
200 /*
201  * Pull the link count and size up from the xfs inode to the linux inode
202  */
203 STATIC void
204 validate_fields(
205         struct inode    *ip)
206 {
207         vnode_t         *vp = LINVFS_GET_VP(ip);
208         vattr_t         va;
209         int             error;
210
211         va.va_mask = XFS_AT_NLINK|XFS_AT_SIZE|XFS_AT_NBLOCKS;
212         VOP_GETATTR(vp, &va, ATTR_LAZY, NULL, error);
213         if (likely(!error)) {
214                 ip->i_nlink = va.va_nlink;
215                 ip->i_blocks = va.va_nblocks;
216
217                 /* we're under i_mutex so i_size can't change under us */
218                 if (i_size_read(ip) != va.va_size)
219                         i_size_write(ip, va.va_size);
220         }
221 }
222
223 /*
224  * Hook in SELinux.  This is not quite correct yet, what we really need
225  * here (as we do for default ACLs) is a mechanism by which creation of
226  * these attrs can be journalled at inode creation time (along with the
227  * inode, of course, such that log replay can't cause these to be lost).
228  */
229 STATIC int
230 linvfs_init_security(
231         struct vnode    *vp,
232         struct inode    *dir)
233 {
234         struct inode    *ip = LINVFS_GET_IP(vp);
235         size_t          length;
236         void            *value;
237         char            *name;
238         int             error;
239
240         error = security_inode_init_security(ip, dir, &name, &value, &length);
241         if (error) {
242                 if (error == -EOPNOTSUPP)
243                         return 0;
244                 return -error;
245         }
246
247         VOP_ATTR_SET(vp, name, value, length, ATTR_SECURE, NULL, error);
248         if (!error)
249                 VMODIFY(vp);
250
251         kfree(name);
252         kfree(value);
253         return error;
254 }
255
256 /*
257  * Determine whether a process has a valid fs_struct (kernel daemons
258  * like knfsd don't have an fs_struct).
259  *
260  * XXX(hch):  nfsd is broken, better fix it instead.
261  */
262 STATIC inline int
263 has_fs_struct(struct task_struct *task)
264 {
265         return (task->fs != init_task.fs);
266 }
267
268 STATIC int
269 linvfs_mknod(
270         struct inode    *dir,
271         struct dentry   *dentry,
272         int             mode,
273         dev_t           rdev)
274 {
275         struct inode    *ip;
276         vattr_t         va;
277         vnode_t         *vp = NULL, *dvp = LINVFS_GET_VP(dir);
278         xfs_acl_t       *default_acl = NULL;
279         attrexists_t    test_default_acl = _ACL_DEFAULT_EXISTS;
280         int             error;
281
282         /*
283          * Irix uses Missed'em'V split, but doesn't want to see
284          * the upper 5 bits of (14bit) major.
285          */
286         if (!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff)
287                 return -EINVAL;
288
289         if (test_default_acl && test_default_acl(dvp)) {
290                 if (!_ACL_ALLOC(default_acl))
291                         return -ENOMEM;
292                 if (!_ACL_GET_DEFAULT(dvp, default_acl)) {
293                         _ACL_FREE(default_acl);
294                         default_acl = NULL;
295                 }
296         }
297
298         if (IS_POSIXACL(dir) && !default_acl && has_fs_struct(current))
299                 mode &= ~current->fs->umask;
300
301         memset(&va, 0, sizeof(va));
302         va.va_mask = XFS_AT_TYPE|XFS_AT_MODE;
303         va.va_mode = mode;
304
305         switch (mode & S_IFMT) {
306         case S_IFCHR: case S_IFBLK: case S_IFIFO: case S_IFSOCK:
307                 va.va_rdev = sysv_encode_dev(rdev);
308                 va.va_mask |= XFS_AT_RDEV;
309                 /*FALLTHROUGH*/
310         case S_IFREG:
311                 VOP_CREATE(dvp, dentry, &va, &vp, NULL, error);
312                 break;
313         case S_IFDIR:
314                 VOP_MKDIR(dvp, dentry, &va, &vp, NULL, error);
315                 break;
316         default:
317                 error = EINVAL;
318                 break;
319         }
320
321         if (!error)
322                 error = linvfs_init_security(vp, dir);
323
324         if (default_acl) {
325                 if (!error) {
326                         error = _ACL_INHERIT(vp, &va, default_acl);
327                         if (!error) {
328                                 VMODIFY(vp);
329                         } else {
330                                 struct dentry   teardown = {};
331                                 int             err2;
332
333                                 /* Oh, the horror.
334                                  * If we can't add the ACL we must back out.
335                                  * ENOSPC can hit here, among other things.
336                                  */
337                                 teardown.d_inode = ip = LINVFS_GET_IP(vp);
338                                 teardown.d_name = dentry->d_name;
339
340                                 if (S_ISDIR(mode))
341                                         VOP_RMDIR(dvp, &teardown, NULL, err2);
342                                 else
343                                         VOP_REMOVE(dvp, &teardown, NULL, err2);
344                                 VN_RELE(vp);
345                         }
346                 }
347                 _ACL_FREE(default_acl);
348         }
349
350         if (!error) {
351                 ASSERT(vp);
352                 ip = LINVFS_GET_IP(vp);
353
354                 if (S_ISCHR(mode) || S_ISBLK(mode))
355                         ip->i_rdev = rdev;
356                 else if (S_ISDIR(mode))
357                         validate_fields(ip);
358                 d_instantiate(dentry, ip);
359                 validate_fields(dir);
360         }
361         return -error;
362 }
363
364 STATIC int
365 linvfs_create(
366         struct inode    *dir,
367         struct dentry   *dentry,
368         int             mode,
369         struct nameidata *nd)
370 {
371         return linvfs_mknod(dir, dentry, mode, 0);
372 }
373
374 STATIC int
375 linvfs_mkdir(
376         struct inode    *dir,
377         struct dentry   *dentry,
378         int             mode)
379 {
380         return linvfs_mknod(dir, dentry, mode|S_IFDIR, 0);
381 }
382
383 STATIC struct dentry *
384 linvfs_lookup(
385         struct inode    *dir,
386         struct dentry   *dentry,
387         struct nameidata *nd)
388 {
389         struct vnode    *vp = LINVFS_GET_VP(dir), *cvp;
390         int             error;
391
392         if (dentry->d_name.len >= MAXNAMELEN)
393                 return ERR_PTR(-ENAMETOOLONG);
394
395         VOP_LOOKUP(vp, dentry, &cvp, 0, NULL, NULL, error);
396         if (error) {
397                 if (unlikely(error != ENOENT))
398                         return ERR_PTR(-error);
399                 d_add(dentry, NULL);
400                 return NULL;
401         }
402
403         return d_splice_alias(LINVFS_GET_IP(cvp), dentry);
404 }
405
406 STATIC int
407 linvfs_link(
408         struct dentry   *old_dentry,
409         struct inode    *dir,
410         struct dentry   *dentry)
411 {
412         struct inode    *ip;    /* inode of guy being linked to */
413         vnode_t         *tdvp;  /* target directory for new name/link */
414         vnode_t         *vp;    /* vp of name being linked */
415         int             error;
416
417         ip = old_dentry->d_inode;       /* inode being linked to */
418         if (S_ISDIR(ip->i_mode))
419                 return -EPERM;
420
421         tdvp = LINVFS_GET_VP(dir);
422         vp = LINVFS_GET_VP(ip);
423
424         VOP_LINK(tdvp, vp, dentry, NULL, error);
425         if (!error) {
426                 VMODIFY(tdvp);
427                 VN_HOLD(vp);
428                 validate_fields(ip);
429                 d_instantiate(dentry, ip);
430         }
431         return -error;
432 }
433
434 STATIC int
435 linvfs_unlink(
436         struct inode    *dir,
437         struct dentry   *dentry)
438 {
439         struct inode    *inode;
440         vnode_t         *dvp;   /* directory containing name to remove */
441         int             error;
442
443         inode = dentry->d_inode;
444         dvp = LINVFS_GET_VP(dir);
445
446         VOP_REMOVE(dvp, dentry, NULL, error);
447         if (!error) {
448                 validate_fields(dir);   /* For size only */
449                 validate_fields(inode);
450         }
451
452         return -error;
453 }
454
455 STATIC int
456 linvfs_symlink(
457         struct inode    *dir,
458         struct dentry   *dentry,
459         const char      *symname)
460 {
461         struct inode    *ip;
462         vattr_t         va;
463         vnode_t         *dvp;   /* directory containing name of symlink */
464         vnode_t         *cvp;   /* used to lookup symlink to put in dentry */
465         int             error;
466
467         dvp = LINVFS_GET_VP(dir);
468         cvp = NULL;
469
470         memset(&va, 0, sizeof(va));
471         va.va_mode = S_IFLNK |
472                 (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO);
473         va.va_mask = XFS_AT_TYPE|XFS_AT_MODE;
474
475         error = 0;
476         VOP_SYMLINK(dvp, dentry, &va, (char *)symname, &cvp, NULL, error);
477         if (likely(!error && cvp)) {
478                 error = linvfs_init_security(cvp, dir);
479                 if (likely(!error)) {
480                         ip = LINVFS_GET_IP(cvp);
481                         d_instantiate(dentry, ip);
482                         validate_fields(dir);
483                         validate_fields(ip);
484                 }
485         }
486         return -error;
487 }
488
489 STATIC int
490 linvfs_rmdir(
491         struct inode    *dir,
492         struct dentry   *dentry)
493 {
494         struct inode    *inode = dentry->d_inode;
495         vnode_t         *dvp = LINVFS_GET_VP(dir);
496         int             error;
497
498         VOP_RMDIR(dvp, dentry, NULL, error);
499         if (!error) {
500                 validate_fields(inode);
501                 validate_fields(dir);
502         }
503         return -error;
504 }
505
506 STATIC int
507 linvfs_rename(
508         struct inode    *odir,
509         struct dentry   *odentry,
510         struct inode    *ndir,
511         struct dentry   *ndentry)
512 {
513         struct inode    *new_inode = ndentry->d_inode;
514         vnode_t         *fvp;   /* from directory */
515         vnode_t         *tvp;   /* target directory */
516         int             error;
517
518         fvp = LINVFS_GET_VP(odir);
519         tvp = LINVFS_GET_VP(ndir);
520
521         VOP_RENAME(fvp, odentry, tvp, ndentry, NULL, error);
522         if (error)
523                 return -error;
524
525         if (new_inode)
526                 validate_fields(new_inode);
527
528         validate_fields(odir);
529         if (ndir != odir)
530                 validate_fields(ndir);
531         return 0;
532 }
533
534 /*
535  * careful here - this function can get called recursively, so
536  * we need to be very careful about how much stack we use.
537  * uio is kmalloced for this reason...
538  */
539 STATIC void *
540 linvfs_follow_link(
541         struct dentry           *dentry,
542         struct nameidata        *nd)
543 {
544         vnode_t                 *vp;
545         uio_t                   *uio;
546         iovec_t                 iov;
547         int                     error;
548         char                    *link;
549
550         ASSERT(dentry);
551         ASSERT(nd);
552
553         link = (char *)kmalloc(MAXPATHLEN+1, GFP_KERNEL);
554         if (!link) {
555                 nd_set_link(nd, ERR_PTR(-ENOMEM));
556                 return NULL;
557         }
558
559         uio = (uio_t *)kmalloc(sizeof(uio_t), GFP_KERNEL);
560         if (!uio) {
561                 kfree(link);
562                 nd_set_link(nd, ERR_PTR(-ENOMEM));
563                 return NULL;
564         }
565
566         vp = LINVFS_GET_VP(dentry->d_inode);
567
568         iov.iov_base = link;
569         iov.iov_len = MAXPATHLEN;
570
571         uio->uio_iov = &iov;
572         uio->uio_offset = 0;
573         uio->uio_segflg = UIO_SYSSPACE;
574         uio->uio_resid = MAXPATHLEN;
575         uio->uio_iovcnt = 1;
576
577         VOP_READLINK(vp, uio, 0, NULL, error);
578         if (error) {
579                 kfree(link);
580                 link = ERR_PTR(-error);
581         } else {
582                 link[MAXPATHLEN - uio->uio_resid] = '\0';
583         }
584         kfree(uio);
585
586         nd_set_link(nd, link);
587         return NULL;
588 }
589
590 STATIC void
591 linvfs_put_link(
592         struct dentry   *dentry,
593         struct nameidata *nd,
594         void            *p)
595 {
596         char            *s = nd_get_link(nd);
597
598         if (!IS_ERR(s))
599                 kfree(s);
600 }
601
602 #ifdef CONFIG_XFS_POSIX_ACL
603 STATIC int
604 linvfs_permission(
605         struct inode    *inode,
606         int             mode,
607         struct nameidata *nd)
608 {
609         vnode_t         *vp = LINVFS_GET_VP(inode);
610         int             error;
611
612         mode <<= 6;             /* convert from linux to vnode access bits */
613         VOP_ACCESS(vp, mode, NULL, error);
614         return -error;
615 }
616 #else
617 #define linvfs_permission NULL
618 #endif
619
620 STATIC int
621 linvfs_getattr(
622         struct vfsmount *mnt,
623         struct dentry   *dentry,
624         struct kstat    *stat)
625 {
626         struct inode    *inode = dentry->d_inode;
627         vnode_t         *vp = LINVFS_GET_VP(inode);
628         int             error = 0;
629
630         if (unlikely(vp->v_flag & VMODIFIED))
631                 error = vn_revalidate(vp);
632         if (!error)
633                 generic_fillattr(inode, stat);
634         return 0;
635 }
636
637 STATIC int
638 linvfs_setattr(
639         struct dentry   *dentry,
640         struct iattr    *attr)
641 {
642         struct inode    *inode = dentry->d_inode;
643         unsigned int    ia_valid = attr->ia_valid;
644         vnode_t         *vp = LINVFS_GET_VP(inode);
645         vattr_t         vattr;
646         int             flags = 0;
647         int             error;
648
649         memset(&vattr, 0, sizeof(vattr_t));
650         if (ia_valid & ATTR_UID) {
651                 vattr.va_mask |= XFS_AT_UID;
652                 vattr.va_uid = attr->ia_uid;
653         }
654         if (ia_valid & ATTR_GID) {
655                 vattr.va_mask |= XFS_AT_GID;
656                 vattr.va_gid = attr->ia_gid;
657         }
658         if (ia_valid & ATTR_SIZE) {
659                 vattr.va_mask |= XFS_AT_SIZE;
660                 vattr.va_size = attr->ia_size;
661         }
662         if (ia_valid & ATTR_ATIME) {
663                 vattr.va_mask |= XFS_AT_ATIME;
664                 vattr.va_atime = attr->ia_atime;
665         }
666         if (ia_valid & ATTR_MTIME) {
667                 vattr.va_mask |= XFS_AT_MTIME;
668                 vattr.va_mtime = attr->ia_mtime;
669         }
670         if (ia_valid & ATTR_CTIME) {
671                 vattr.va_mask |= XFS_AT_CTIME;
672                 vattr.va_ctime = attr->ia_ctime;
673         }
674         if (ia_valid & ATTR_MODE) {
675                 vattr.va_mask |= XFS_AT_MODE;
676                 vattr.va_mode = attr->ia_mode;
677                 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
678                         inode->i_mode &= ~S_ISGID;
679         }
680
681         if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))
682                 flags |= ATTR_UTIME;
683 #ifdef ATTR_NO_BLOCK
684         if ((ia_valid & ATTR_NO_BLOCK))
685                 flags |= ATTR_NONBLOCK;
686 #endif
687
688         VOP_SETATTR(vp, &vattr, flags, NULL, error);
689         if (error)
690                 return -error;
691         vn_revalidate(vp);
692         return error;
693 }
694
695 STATIC void
696 linvfs_truncate(
697         struct inode    *inode)
698 {
699         block_truncate_page(inode->i_mapping, inode->i_size, linvfs_get_block);
700 }
701
702 STATIC int
703 linvfs_setxattr(
704         struct dentry   *dentry,
705         const char      *name,
706         const void      *data,
707         size_t          size,
708         int             flags)
709 {
710         vnode_t         *vp = LINVFS_GET_VP(dentry->d_inode);
711         char            *attr = (char *)name;
712         attrnames_t     *namesp;
713         int             xflags = 0;
714         int             error;
715
716         namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
717         if (!namesp)
718                 return -EOPNOTSUPP;
719         attr += namesp->attr_namelen;
720         error = namesp->attr_capable(vp, NULL);
721         if (error)
722                 return error;
723
724         /* Convert Linux syscall to XFS internal ATTR flags */
725         if (flags & XATTR_CREATE)
726                 xflags |= ATTR_CREATE;
727         if (flags & XATTR_REPLACE)
728                 xflags |= ATTR_REPLACE;
729         xflags |= namesp->attr_flag;
730         return namesp->attr_set(vp, attr, (void *)data, size, xflags);
731 }
732
733 STATIC ssize_t
734 linvfs_getxattr(
735         struct dentry   *dentry,
736         const char      *name,
737         void            *data,
738         size_t          size)
739 {
740         vnode_t         *vp = LINVFS_GET_VP(dentry->d_inode);
741         char            *attr = (char *)name;
742         attrnames_t     *namesp;
743         int             xflags = 0;
744         ssize_t         error;
745
746         namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
747         if (!namesp)
748                 return -EOPNOTSUPP;
749         attr += namesp->attr_namelen;
750         error = namesp->attr_capable(vp, NULL);
751         if (error)
752                 return error;
753
754         /* Convert Linux syscall to XFS internal ATTR flags */
755         if (!size) {
756                 xflags |= ATTR_KERNOVAL;
757                 data = NULL;
758         }
759         xflags |= namesp->attr_flag;
760         return namesp->attr_get(vp, attr, (void *)data, size, xflags);
761 }
762
763 STATIC ssize_t
764 linvfs_listxattr(
765         struct dentry           *dentry,
766         char                    *data,
767         size_t                  size)
768 {
769         vnode_t                 *vp = LINVFS_GET_VP(dentry->d_inode);
770         int                     error, xflags = ATTR_KERNAMELS;
771         ssize_t                 result;
772
773         if (!size)
774                 xflags |= ATTR_KERNOVAL;
775         xflags |= capable(CAP_SYS_ADMIN) ? ATTR_KERNFULLS : ATTR_KERNORMALS;
776
777         error = attr_generic_list(vp, data, size, xflags, &result);
778         if (error < 0)
779                 return error;
780         return result;
781 }
782
783 STATIC int
784 linvfs_removexattr(
785         struct dentry   *dentry,
786         const char      *name)
787 {
788         vnode_t         *vp = LINVFS_GET_VP(dentry->d_inode);
789         char            *attr = (char *)name;
790         attrnames_t     *namesp;
791         int             xflags = 0;
792         int             error;
793
794         namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
795         if (!namesp)
796                 return -EOPNOTSUPP;
797         attr += namesp->attr_namelen;
798         error = namesp->attr_capable(vp, NULL);
799         if (error)
800                 return error;
801         xflags |= namesp->attr_flag;
802         return namesp->attr_remove(vp, attr, xflags);
803 }
804
805
806 struct inode_operations linvfs_file_inode_operations = {
807         .permission             = linvfs_permission,
808         .truncate               = linvfs_truncate,
809         .getattr                = linvfs_getattr,
810         .setattr                = linvfs_setattr,
811         .setxattr               = linvfs_setxattr,
812         .getxattr               = linvfs_getxattr,
813         .listxattr              = linvfs_listxattr,
814         .removexattr            = linvfs_removexattr,
815 };
816
817 struct inode_operations linvfs_dir_inode_operations = {
818         .create                 = linvfs_create,
819         .lookup                 = linvfs_lookup,
820         .link                   = linvfs_link,
821         .unlink                 = linvfs_unlink,
822         .symlink                = linvfs_symlink,
823         .mkdir                  = linvfs_mkdir,
824         .rmdir                  = linvfs_rmdir,
825         .mknod                  = linvfs_mknod,
826         .rename                 = linvfs_rename,
827         .permission             = linvfs_permission,
828         .getattr                = linvfs_getattr,
829         .setattr                = linvfs_setattr,
830         .setxattr               = linvfs_setxattr,
831         .getxattr               = linvfs_getxattr,
832         .listxattr              = linvfs_listxattr,
833         .removexattr            = linvfs_removexattr,
834 };
835
836 struct inode_operations linvfs_symlink_inode_operations = {
837         .readlink               = generic_readlink,
838         .follow_link            = linvfs_follow_link,
839         .put_link               = linvfs_put_link,
840         .permission             = linvfs_permission,
841         .getattr                = linvfs_getattr,
842         .setattr                = linvfs_setattr,
843         .setxattr               = linvfs_setxattr,
844         .getxattr               = linvfs_getxattr,
845         .listxattr              = linvfs_listxattr,
846         .removexattr            = linvfs_removexattr,
847 };