]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - fs/xfs/linux-2.6/xfs_iops.c
d6947f818f290f7deae6fbe8d2d652c2d9eef955
[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_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 #include <linux/falloc.h>
56
57 /*
58  * Bring the atime in the XFS inode uptodate.
59  * Used before logging the inode to disk or when the Linux inode goes away.
60  */
61 void
62 xfs_synchronize_atime(
63         xfs_inode_t     *ip)
64 {
65         struct inode    *inode = VFS_I(ip);
66
67         if (inode) {
68                 ip->i_d.di_atime.t_sec = (__int32_t)inode->i_atime.tv_sec;
69                 ip->i_d.di_atime.t_nsec = (__int32_t)inode->i_atime.tv_nsec;
70         }
71 }
72
73 /*
74  * If the linux inode exists, mark it dirty.
75  * Used when commiting a dirty inode into a transaction so that
76  * the inode will get written back by the linux code
77  */
78 void
79 xfs_mark_inode_dirty_sync(
80         xfs_inode_t     *ip)
81 {
82         struct inode    *inode = VFS_I(ip);
83
84         if (inode)
85                 mark_inode_dirty_sync(inode);
86 }
87
88 /*
89  * Change the requested timestamp in the given inode.
90  * We don't lock across timestamp updates, and we don't log them but
91  * we do record the fact that there is dirty information in core.
92  */
93 void
94 xfs_ichgtime(
95         xfs_inode_t     *ip,
96         int             flags)
97 {
98         struct inode    *inode = VFS_I(ip);
99         timespec_t      tv;
100
101         nanotime(&tv);
102         if (flags & XFS_ICHGTIME_MOD) {
103                 inode->i_mtime = tv;
104                 ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec;
105                 ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec;
106         }
107         if (flags & XFS_ICHGTIME_CHG) {
108                 inode->i_ctime = tv;
109                 ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec;
110                 ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec;
111         }
112
113         /*
114          * We update the i_update_core field _after_ changing
115          * the timestamps in order to coordinate properly with
116          * xfs_iflush() so that we don't lose timestamp updates.
117          * This keeps us from having to hold the inode lock
118          * while doing this.  We use the SYNCHRONIZE macro to
119          * ensure that the compiler does not reorder the update
120          * of i_update_core above the timestamp updates above.
121          */
122         SYNCHRONIZE();
123         ip->i_update_core = 1;
124         if (!(inode->i_state & I_NEW))
125                 mark_inode_dirty_sync(inode);
126 }
127
128 /*
129  * Variant on the above which avoids querying the system clock
130  * in situations where we know the Linux inode timestamps have
131  * just been updated (and so we can update our inode cheaply).
132  */
133 void
134 xfs_ichgtime_fast(
135         xfs_inode_t     *ip,
136         struct inode    *inode,
137         int             flags)
138 {
139         timespec_t      *tvp;
140
141         if (flags & XFS_ICHGTIME_MOD) {
142                 tvp = &inode->i_mtime;
143                 ip->i_d.di_mtime.t_sec = (__int32_t)tvp->tv_sec;
144                 ip->i_d.di_mtime.t_nsec = (__int32_t)tvp->tv_nsec;
145         }
146         if (flags & XFS_ICHGTIME_CHG) {
147                 tvp = &inode->i_ctime;
148                 ip->i_d.di_ctime.t_sec = (__int32_t)tvp->tv_sec;
149                 ip->i_d.di_ctime.t_nsec = (__int32_t)tvp->tv_nsec;
150         }
151
152         /*
153          * We update the i_update_core field _after_ changing
154          * the timestamps in order to coordinate properly with
155          * xfs_iflush() so that we don't lose timestamp updates.
156          * This keeps us from having to hold the inode lock
157          * while doing this.  We use the SYNCHRONIZE macro to
158          * ensure that the compiler does not reorder the update
159          * of i_update_core above the timestamp updates above.
160          */
161         SYNCHRONIZE();
162         ip->i_update_core = 1;
163         if (!(inode->i_state & I_NEW))
164                 mark_inode_dirty_sync(inode);
165 }
166
167 /*
168  * Hook in SELinux.  This is not quite correct yet, what we really need
169  * here (as we do for default ACLs) is a mechanism by which creation of
170  * these attrs can be journalled at inode creation time (along with the
171  * inode, of course, such that log replay can't cause these to be lost).
172  */
173 STATIC int
174 xfs_init_security(
175         struct inode    *inode,
176         struct inode    *dir)
177 {
178         struct xfs_inode *ip = XFS_I(inode);
179         size_t          length;
180         void            *value;
181         char            *name;
182         int             error;
183
184         error = security_inode_init_security(inode, dir, &name,
185                                              &value, &length);
186         if (error) {
187                 if (error == -EOPNOTSUPP)
188                         return 0;
189                 return -error;
190         }
191
192         error = xfs_attr_set(ip, name, value, length, ATTR_SECURE);
193         if (!error)
194                 xfs_iflags_set(ip, XFS_IMODIFIED);
195
196         kfree(name);
197         kfree(value);
198         return error;
199 }
200
201 static void
202 xfs_dentry_to_name(
203         struct xfs_name *namep,
204         struct dentry   *dentry)
205 {
206         namep->name = dentry->d_name.name;
207         namep->len = dentry->d_name.len;
208 }
209
210 STATIC void
211 xfs_cleanup_inode(
212         struct inode    *dir,
213         struct inode    *inode,
214         struct dentry   *dentry)
215 {
216         struct xfs_name teardown;
217
218         /* Oh, the horror.
219          * If we can't add the ACL or we fail in
220          * xfs_init_security we must back out.
221          * ENOSPC can hit here, among other things.
222          */
223         xfs_dentry_to_name(&teardown, dentry);
224
225         xfs_remove(XFS_I(dir), &teardown, XFS_I(inode));
226         iput(inode);
227 }
228
229 STATIC int
230 xfs_vn_mknod(
231         struct inode    *dir,
232         struct dentry   *dentry,
233         int             mode,
234         dev_t           rdev)
235 {
236         struct inode    *inode;
237         struct xfs_inode *ip = NULL;
238         xfs_acl_t       *default_acl = NULL;
239         struct xfs_name name;
240         int (*test_default_acl)(struct inode *) = _ACL_DEFAULT_EXISTS;
241         int             error;
242
243         /*
244          * Irix uses Missed'em'V split, but doesn't want to see
245          * the upper 5 bits of (14bit) major.
246          */
247         if (unlikely(!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff))
248                 return -EINVAL;
249
250         if (test_default_acl && test_default_acl(dir)) {
251                 if (!_ACL_ALLOC(default_acl)) {
252                         return -ENOMEM;
253                 }
254                 if (!_ACL_GET_DEFAULT(dir, default_acl)) {
255                         _ACL_FREE(default_acl);
256                         default_acl = NULL;
257                 }
258         }
259
260         xfs_dentry_to_name(&name, dentry);
261
262         if (IS_POSIXACL(dir) && !default_acl)
263                 mode &= ~current->fs->umask;
264
265         switch (mode & S_IFMT) {
266         case S_IFCHR:
267         case S_IFBLK:
268         case S_IFIFO:
269         case S_IFSOCK:
270                 rdev = sysv_encode_dev(rdev);
271         case S_IFREG:
272                 error = xfs_create(XFS_I(dir), &name, mode, rdev, &ip, NULL);
273                 break;
274         case S_IFDIR:
275                 error = xfs_mkdir(XFS_I(dir), &name, mode, &ip, NULL);
276                 break;
277         default:
278                 error = EINVAL;
279                 break;
280         }
281
282         if (unlikely(error))
283                 goto out_free_acl;
284
285         inode = VFS_I(ip);
286
287         error = xfs_init_security(inode, dir);
288         if (unlikely(error))
289                 goto out_cleanup_inode;
290
291         if (default_acl) {
292                 error = _ACL_INHERIT(inode, mode, default_acl);
293                 if (unlikely(error))
294                         goto out_cleanup_inode;
295                 xfs_iflags_set(ip, XFS_IMODIFIED);
296                 _ACL_FREE(default_acl);
297         }
298
299
300         d_instantiate(dentry, inode);
301         return -error;
302
303  out_cleanup_inode:
304         xfs_cleanup_inode(dir, inode, dentry);
305  out_free_acl:
306         if (default_acl)
307                 _ACL_FREE(default_acl);
308         return -error;
309 }
310
311 STATIC int
312 xfs_vn_create(
313         struct inode    *dir,
314         struct dentry   *dentry,
315         int             mode,
316         struct nameidata *nd)
317 {
318         return xfs_vn_mknod(dir, dentry, mode, 0);
319 }
320
321 STATIC int
322 xfs_vn_mkdir(
323         struct inode    *dir,
324         struct dentry   *dentry,
325         int             mode)
326 {
327         return xfs_vn_mknod(dir, dentry, mode|S_IFDIR, 0);
328 }
329
330 STATIC struct dentry *
331 xfs_vn_lookup(
332         struct inode    *dir,
333         struct dentry   *dentry,
334         struct nameidata *nd)
335 {
336         struct xfs_inode *cip;
337         struct xfs_name name;
338         int             error;
339
340         if (dentry->d_name.len >= MAXNAMELEN)
341                 return ERR_PTR(-ENAMETOOLONG);
342
343         xfs_dentry_to_name(&name, dentry);
344         error = xfs_lookup(XFS_I(dir), &name, &cip, NULL);
345         if (unlikely(error)) {
346                 if (unlikely(error != ENOENT))
347                         return ERR_PTR(-error);
348                 d_add(dentry, NULL);
349                 return NULL;
350         }
351
352         return d_splice_alias(VFS_I(cip), dentry);
353 }
354
355 STATIC struct dentry *
356 xfs_vn_ci_lookup(
357         struct inode    *dir,
358         struct dentry   *dentry,
359         struct nameidata *nd)
360 {
361         struct xfs_inode *ip;
362         struct xfs_name xname;
363         struct xfs_name ci_name;
364         struct qstr     dname;
365         int             error;
366
367         if (dentry->d_name.len >= MAXNAMELEN)
368                 return ERR_PTR(-ENAMETOOLONG);
369
370         xfs_dentry_to_name(&xname, dentry);
371         error = xfs_lookup(XFS_I(dir), &xname, &ip, &ci_name);
372         if (unlikely(error)) {
373                 if (unlikely(error != ENOENT))
374                         return ERR_PTR(-error);
375                 /*
376                  * call d_add(dentry, NULL) here when d_drop_negative_children
377                  * is called in xfs_vn_mknod (ie. allow negative dentries
378                  * with CI filesystems).
379                  */
380                 return NULL;
381         }
382
383         /* if exact match, just splice and exit */
384         if (!ci_name.name)
385                 return d_splice_alias(VFS_I(ip), dentry);
386
387         /* else case-insensitive match... */
388         dname.name = ci_name.name;
389         dname.len = ci_name.len;
390         dentry = d_add_ci(VFS_I(ip), dentry, &dname);
391         kmem_free(ci_name.name);
392         return dentry;
393 }
394
395 STATIC int
396 xfs_vn_link(
397         struct dentry   *old_dentry,
398         struct inode    *dir,
399         struct dentry   *dentry)
400 {
401         struct inode    *inode; /* inode of guy being linked to */
402         struct xfs_name name;
403         int             error;
404
405         inode = old_dentry->d_inode;
406         xfs_dentry_to_name(&name, dentry);
407
408         igrab(inode);
409         error = xfs_link(XFS_I(dir), XFS_I(inode), &name);
410         if (unlikely(error)) {
411                 iput(inode);
412                 return -error;
413         }
414
415         xfs_iflags_set(XFS_I(dir), XFS_IMODIFIED);
416         d_instantiate(dentry, inode);
417         return 0;
418 }
419
420 STATIC int
421 xfs_vn_unlink(
422         struct inode    *dir,
423         struct dentry   *dentry)
424 {
425         struct xfs_name name;
426         int             error;
427
428         xfs_dentry_to_name(&name, dentry);
429
430         error = -xfs_remove(XFS_I(dir), &name, XFS_I(dentry->d_inode));
431         if (error)
432                 return error;
433
434         /*
435          * With unlink, the VFS makes the dentry "negative": no inode,
436          * but still hashed. This is incompatible with case-insensitive
437          * mode, so invalidate (unhash) the dentry in CI-mode.
438          */
439         if (xfs_sb_version_hasasciici(&XFS_M(dir->i_sb)->m_sb))
440                 d_invalidate(dentry);
441         return 0;
442 }
443
444 STATIC int
445 xfs_vn_symlink(
446         struct inode    *dir,
447         struct dentry   *dentry,
448         const char      *symname)
449 {
450         struct inode    *inode;
451         struct xfs_inode *cip = NULL;
452         struct xfs_name name;
453         int             error;
454         mode_t          mode;
455
456         mode = S_IFLNK |
457                 (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO);
458         xfs_dentry_to_name(&name, dentry);
459
460         error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip, NULL);
461         if (unlikely(error))
462                 goto out;
463
464         inode = VFS_I(cip);
465
466         error = xfs_init_security(inode, dir);
467         if (unlikely(error))
468                 goto out_cleanup_inode;
469
470         d_instantiate(dentry, inode);
471         return 0;
472
473  out_cleanup_inode:
474         xfs_cleanup_inode(dir, inode, dentry);
475  out:
476         return -error;
477 }
478
479 STATIC int
480 xfs_vn_rename(
481         struct inode    *odir,
482         struct dentry   *odentry,
483         struct inode    *ndir,
484         struct dentry   *ndentry)
485 {
486         struct inode    *new_inode = ndentry->d_inode;
487         struct xfs_name oname;
488         struct xfs_name nname;
489
490         xfs_dentry_to_name(&oname, odentry);
491         xfs_dentry_to_name(&nname, ndentry);
492
493         return -xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode),
494                            XFS_I(ndir), &nname, new_inode ?
495                                                 XFS_I(new_inode) : NULL);
496 }
497
498 /*
499  * careful here - this function can get called recursively, so
500  * we need to be very careful about how much stack we use.
501  * uio is kmalloced for this reason...
502  */
503 STATIC void *
504 xfs_vn_follow_link(
505         struct dentry           *dentry,
506         struct nameidata        *nd)
507 {
508         char                    *link;
509         int                     error = -ENOMEM;
510
511         link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
512         if (!link)
513                 goto out_err;
514
515         error = -xfs_readlink(XFS_I(dentry->d_inode), link);
516         if (unlikely(error))
517                 goto out_kfree;
518
519         nd_set_link(nd, link);
520         return NULL;
521
522  out_kfree:
523         kfree(link);
524  out_err:
525         nd_set_link(nd, ERR_PTR(error));
526         return NULL;
527 }
528
529 STATIC void
530 xfs_vn_put_link(
531         struct dentry   *dentry,
532         struct nameidata *nd,
533         void            *p)
534 {
535         char            *s = nd_get_link(nd);
536
537         if (!IS_ERR(s))
538                 kfree(s);
539 }
540
541 #ifdef CONFIG_XFS_POSIX_ACL
542 STATIC int
543 xfs_check_acl(
544         struct inode            *inode,
545         int                     mask)
546 {
547         struct xfs_inode        *ip = XFS_I(inode);
548         int                     error;
549
550         xfs_itrace_entry(ip);
551
552         if (XFS_IFORK_Q(ip)) {
553                 error = xfs_acl_iaccess(ip, mask, NULL);
554                 if (error != -1)
555                         return -error;
556         }
557
558         return -EAGAIN;
559 }
560
561 STATIC int
562 xfs_vn_permission(
563         struct inode            *inode,
564         int                     mask)
565 {
566         return generic_permission(inode, mask, xfs_check_acl);
567 }
568 #else
569 #define xfs_vn_permission NULL
570 #endif
571
572 STATIC int
573 xfs_vn_getattr(
574         struct vfsmount         *mnt,
575         struct dentry           *dentry,
576         struct kstat            *stat)
577 {
578         struct inode            *inode = dentry->d_inode;
579         struct xfs_inode        *ip = XFS_I(inode);
580         struct xfs_mount        *mp = ip->i_mount;
581
582         xfs_itrace_entry(ip);
583
584         if (XFS_FORCED_SHUTDOWN(mp))
585                 return XFS_ERROR(EIO);
586
587         stat->size = XFS_ISIZE(ip);
588         stat->dev = inode->i_sb->s_dev;
589         stat->mode = ip->i_d.di_mode;
590         stat->nlink = ip->i_d.di_nlink;
591         stat->uid = ip->i_d.di_uid;
592         stat->gid = ip->i_d.di_gid;
593         stat->ino = ip->i_ino;
594 #if XFS_BIG_INUMS
595         stat->ino += mp->m_inoadd;
596 #endif
597         stat->atime = inode->i_atime;
598         stat->mtime.tv_sec = ip->i_d.di_mtime.t_sec;
599         stat->mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
600         stat->ctime.tv_sec = ip->i_d.di_ctime.t_sec;
601         stat->ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
602         stat->blocks =
603                 XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
604
605
606         switch (inode->i_mode & S_IFMT) {
607         case S_IFBLK:
608         case S_IFCHR:
609                 stat->blksize = BLKDEV_IOSIZE;
610                 stat->rdev = MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
611                                    sysv_minor(ip->i_df.if_u2.if_rdev));
612                 break;
613         default:
614                 if (XFS_IS_REALTIME_INODE(ip)) {
615                         /*
616                          * If the file blocks are being allocated from a
617                          * realtime volume, then return the inode's realtime
618                          * extent size or the realtime volume's extent size.
619                          */
620                         stat->blksize =
621                                 xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
622                 } else
623                         stat->blksize = xfs_preferred_iosize(mp);
624                 stat->rdev = 0;
625                 break;
626         }
627
628         return 0;
629 }
630
631 STATIC int
632 xfs_vn_setattr(
633         struct dentry   *dentry,
634         struct iattr    *iattr)
635 {
636         return -xfs_setattr(XFS_I(dentry->d_inode), iattr, 0, NULL);
637 }
638
639 /*
640  * block_truncate_page can return an error, but we can't propagate it
641  * at all here. Leave a complaint + stack trace in the syslog because
642  * this could be bad. If it is bad, we need to propagate the error further.
643  */
644 STATIC void
645 xfs_vn_truncate(
646         struct inode    *inode)
647 {
648         int     error;
649         error = block_truncate_page(inode->i_mapping, inode->i_size,
650                                                         xfs_get_blocks);
651         WARN_ON(error);
652 }
653
654 STATIC long
655 xfs_vn_fallocate(
656         struct inode    *inode,
657         int             mode,
658         loff_t          offset,
659         loff_t          len)
660 {
661         long            error;
662         loff_t          new_size = 0;
663         xfs_flock64_t   bf;
664         xfs_inode_t     *ip = XFS_I(inode);
665
666         /* preallocation on directories not yet supported */
667         error = -ENODEV;
668         if (S_ISDIR(inode->i_mode))
669                 goto out_error;
670
671         bf.l_whence = 0;
672         bf.l_start = offset;
673         bf.l_len = len;
674
675         xfs_ilock(ip, XFS_IOLOCK_EXCL);
676         error = xfs_change_file_space(ip, XFS_IOC_RESVSP, &bf,
677                                       0, NULL, XFS_ATTR_NOLOCK);
678         if (!error && !(mode & FALLOC_FL_KEEP_SIZE) &&
679             offset + len > i_size_read(inode))
680                 new_size = offset + len;
681
682         /* Change file size if needed */
683         if (new_size) {
684                 struct iattr iattr;
685
686                 iattr.ia_valid = ATTR_SIZE;
687                 iattr.ia_size = new_size;
688                 error = xfs_setattr(ip, &iattr, XFS_ATTR_NOLOCK, NULL);
689         }
690
691         xfs_iunlock(ip, XFS_IOLOCK_EXCL);
692 out_error:
693         return error;
694 }
695
696 static const struct inode_operations xfs_inode_operations = {
697         .permission             = xfs_vn_permission,
698         .truncate               = xfs_vn_truncate,
699         .getattr                = xfs_vn_getattr,
700         .setattr                = xfs_vn_setattr,
701         .setxattr               = generic_setxattr,
702         .getxattr               = generic_getxattr,
703         .removexattr            = generic_removexattr,
704         .listxattr              = xfs_vn_listxattr,
705         .fallocate              = xfs_vn_fallocate,
706 };
707
708 static const struct inode_operations xfs_dir_inode_operations = {
709         .create                 = xfs_vn_create,
710         .lookup                 = xfs_vn_lookup,
711         .link                   = xfs_vn_link,
712         .unlink                 = xfs_vn_unlink,
713         .symlink                = xfs_vn_symlink,
714         .mkdir                  = xfs_vn_mkdir,
715         /*
716          * Yes, XFS uses the same method for rmdir and unlink.
717          *
718          * There are some subtile differences deeper in the code,
719          * but we use S_ISDIR to check for those.
720          */
721         .rmdir                  = xfs_vn_unlink,
722         .mknod                  = xfs_vn_mknod,
723         .rename                 = xfs_vn_rename,
724         .permission             = xfs_vn_permission,
725         .getattr                = xfs_vn_getattr,
726         .setattr                = xfs_vn_setattr,
727         .setxattr               = generic_setxattr,
728         .getxattr               = generic_getxattr,
729         .removexattr            = generic_removexattr,
730         .listxattr              = xfs_vn_listxattr,
731 };
732
733 static const struct inode_operations xfs_dir_ci_inode_operations = {
734         .create                 = xfs_vn_create,
735         .lookup                 = xfs_vn_ci_lookup,
736         .link                   = xfs_vn_link,
737         .unlink                 = xfs_vn_unlink,
738         .symlink                = xfs_vn_symlink,
739         .mkdir                  = xfs_vn_mkdir,
740         /*
741          * Yes, XFS uses the same method for rmdir and unlink.
742          *
743          * There are some subtile differences deeper in the code,
744          * but we use S_ISDIR to check for those.
745          */
746         .rmdir                  = xfs_vn_unlink,
747         .mknod                  = xfs_vn_mknod,
748         .rename                 = xfs_vn_rename,
749         .permission             = xfs_vn_permission,
750         .getattr                = xfs_vn_getattr,
751         .setattr                = xfs_vn_setattr,
752         .setxattr               = generic_setxattr,
753         .getxattr               = generic_getxattr,
754         .removexattr            = generic_removexattr,
755         .listxattr              = xfs_vn_listxattr,
756 };
757
758 static const struct inode_operations xfs_symlink_inode_operations = {
759         .readlink               = generic_readlink,
760         .follow_link            = xfs_vn_follow_link,
761         .put_link               = xfs_vn_put_link,
762         .permission             = xfs_vn_permission,
763         .getattr                = xfs_vn_getattr,
764         .setattr                = xfs_vn_setattr,
765         .setxattr               = generic_setxattr,
766         .getxattr               = generic_getxattr,
767         .removexattr            = generic_removexattr,
768         .listxattr              = xfs_vn_listxattr,
769 };
770
771 STATIC void
772 xfs_diflags_to_iflags(
773         struct inode            *inode,
774         struct xfs_inode        *ip)
775 {
776         if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
777                 inode->i_flags |= S_IMMUTABLE;
778         else
779                 inode->i_flags &= ~S_IMMUTABLE;
780         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
781                 inode->i_flags |= S_APPEND;
782         else
783                 inode->i_flags &= ~S_APPEND;
784         if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
785                 inode->i_flags |= S_SYNC;
786         else
787                 inode->i_flags &= ~S_SYNC;
788         if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
789                 inode->i_flags |= S_NOATIME;
790         else
791                 inode->i_flags &= ~S_NOATIME;
792 }
793
794 /*
795  * Initialize the Linux inode, set up the operation vectors and
796  * unlock the inode.
797  *
798  * When reading existing inodes from disk this is called directly
799  * from xfs_iget, when creating a new inode it is called from
800  * xfs_ialloc after setting up the inode.
801  */
802 void
803 xfs_setup_inode(
804         struct xfs_inode        *ip)
805 {
806         struct inode            *inode = ip->i_vnode;
807
808         inode->i_mode   = ip->i_d.di_mode;
809         inode->i_nlink  = ip->i_d.di_nlink;
810         inode->i_uid    = ip->i_d.di_uid;
811         inode->i_gid    = ip->i_d.di_gid;
812
813         switch (inode->i_mode & S_IFMT) {
814         case S_IFBLK:
815         case S_IFCHR:
816                 inode->i_rdev =
817                         MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
818                               sysv_minor(ip->i_df.if_u2.if_rdev));
819                 break;
820         default:
821                 inode->i_rdev = 0;
822                 break;
823         }
824
825         inode->i_generation = ip->i_d.di_gen;
826         i_size_write(inode, ip->i_d.di_size);
827         inode->i_atime.tv_sec   = ip->i_d.di_atime.t_sec;
828         inode->i_atime.tv_nsec  = ip->i_d.di_atime.t_nsec;
829         inode->i_mtime.tv_sec   = ip->i_d.di_mtime.t_sec;
830         inode->i_mtime.tv_nsec  = ip->i_d.di_mtime.t_nsec;
831         inode->i_ctime.tv_sec   = ip->i_d.di_ctime.t_sec;
832         inode->i_ctime.tv_nsec  = ip->i_d.di_ctime.t_nsec;
833         xfs_diflags_to_iflags(inode, ip);
834         xfs_iflags_clear(ip, XFS_IMODIFIED);
835
836         switch (inode->i_mode & S_IFMT) {
837         case S_IFREG:
838                 inode->i_op = &xfs_inode_operations;
839                 inode->i_fop = &xfs_file_operations;
840                 inode->i_mapping->a_ops = &xfs_address_space_operations;
841                 break;
842         case S_IFDIR:
843                 if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
844                         inode->i_op = &xfs_dir_ci_inode_operations;
845                 else
846                         inode->i_op = &xfs_dir_inode_operations;
847                 inode->i_fop = &xfs_dir_file_operations;
848                 break;
849         case S_IFLNK:
850                 inode->i_op = &xfs_symlink_inode_operations;
851                 if (!(ip->i_df.if_flags & XFS_IFINLINE))
852                         inode->i_mapping->a_ops = &xfs_address_space_operations;
853                 break;
854         default:
855                 inode->i_op = &xfs_inode_operations;
856                 init_special_inode(inode, inode->i_mode, inode->i_rdev);
857                 break;
858         }
859
860         xfs_iflags_clear(ip, XFS_INEW);
861         barrier();
862
863         unlock_new_inode(inode);
864 }