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