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