Merge branch 'next' into for-linus
[pandora-kernel.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_acl.h"
21 #include "xfs_bit.h"
22 #include "xfs_log.h"
23 #include "xfs_inum.h"
24 #include "xfs_trans.h"
25 #include "xfs_sb.h"
26 #include "xfs_ag.h"
27 #include "xfs_alloc.h"
28 #include "xfs_quota.h"
29 #include "xfs_mount.h"
30 #include "xfs_bmap_btree.h"
31 #include "xfs_dinode.h"
32 #include "xfs_inode.h"
33 #include "xfs_bmap.h"
34 #include "xfs_rtalloc.h"
35 #include "xfs_error.h"
36 #include "xfs_itable.h"
37 #include "xfs_rw.h"
38 #include "xfs_attr.h"
39 #include "xfs_buf_item.h"
40 #include "xfs_utils.h"
41 #include "xfs_vnodeops.h"
42 #include "xfs_trace.h"
43
44 #include <linux/capability.h>
45 #include <linux/xattr.h>
46 #include <linux/namei.h>
47 #include <linux/posix_acl.h>
48 #include <linux/security.h>
49 #include <linux/fiemap.h>
50 #include <linux/slab.h>
51
52 /*
53  * Bring the timestamps in the XFS inode uptodate.
54  *
55  * Used before writing the inode to disk.
56  */
57 void
58 xfs_synchronize_times(
59         xfs_inode_t     *ip)
60 {
61         struct inode    *inode = VFS_I(ip);
62
63         ip->i_d.di_atime.t_sec = (__int32_t)inode->i_atime.tv_sec;
64         ip->i_d.di_atime.t_nsec = (__int32_t)inode->i_atime.tv_nsec;
65         ip->i_d.di_ctime.t_sec = (__int32_t)inode->i_ctime.tv_sec;
66         ip->i_d.di_ctime.t_nsec = (__int32_t)inode->i_ctime.tv_nsec;
67         ip->i_d.di_mtime.t_sec = (__int32_t)inode->i_mtime.tv_sec;
68         ip->i_d.di_mtime.t_nsec = (__int32_t)inode->i_mtime.tv_nsec;
69 }
70
71 /*
72  * If the linux inode is valid, mark it dirty.
73  * Used when commiting a dirty inode into a transaction so that
74  * the inode will get written back by the linux code
75  */
76 void
77 xfs_mark_inode_dirty_sync(
78         xfs_inode_t     *ip)
79 {
80         struct inode    *inode = VFS_I(ip);
81
82         if (!(inode->i_state & (I_WILL_FREE|I_FREEING)))
83                 mark_inode_dirty_sync(inode);
84 }
85
86 void
87 xfs_mark_inode_dirty(
88         xfs_inode_t     *ip)
89 {
90         struct inode    *inode = VFS_I(ip);
91
92         if (!(inode->i_state & (I_WILL_FREE|I_FREEING)))
93                 mark_inode_dirty(inode);
94 }
95
96 /*
97  * Hook in SELinux.  This is not quite correct yet, what we really need
98  * here (as we do for default ACLs) is a mechanism by which creation of
99  * these attrs can be journalled at inode creation time (along with the
100  * inode, of course, such that log replay can't cause these to be lost).
101  */
102 STATIC int
103 xfs_init_security(
104         struct inode    *inode,
105         struct inode    *dir)
106 {
107         struct xfs_inode *ip = XFS_I(inode);
108         size_t          length;
109         void            *value;
110         unsigned char   *name;
111         int             error;
112
113         error = security_inode_init_security(inode, dir, (char **)&name,
114                                              &value, &length);
115         if (error) {
116                 if (error == -EOPNOTSUPP)
117                         return 0;
118                 return -error;
119         }
120
121         error = xfs_attr_set(ip, name, value, length, ATTR_SECURE);
122
123         kfree(name);
124         kfree(value);
125         return error;
126 }
127
128 static void
129 xfs_dentry_to_name(
130         struct xfs_name *namep,
131         struct dentry   *dentry)
132 {
133         namep->name = dentry->d_name.name;
134         namep->len = dentry->d_name.len;
135 }
136
137 STATIC void
138 xfs_cleanup_inode(
139         struct inode    *dir,
140         struct inode    *inode,
141         struct dentry   *dentry)
142 {
143         struct xfs_name teardown;
144
145         /* Oh, the horror.
146          * If we can't add the ACL or we fail in
147          * xfs_init_security we must back out.
148          * ENOSPC can hit here, among other things.
149          */
150         xfs_dentry_to_name(&teardown, dentry);
151
152         xfs_remove(XFS_I(dir), &teardown, XFS_I(inode));
153         iput(inode);
154 }
155
156 STATIC int
157 xfs_vn_mknod(
158         struct inode    *dir,
159         struct dentry   *dentry,
160         int             mode,
161         dev_t           rdev)
162 {
163         struct inode    *inode;
164         struct xfs_inode *ip = NULL;
165         struct posix_acl *default_acl = NULL;
166         struct xfs_name name;
167         int             error;
168
169         /*
170          * Irix uses Missed'em'V split, but doesn't want to see
171          * the upper 5 bits of (14bit) major.
172          */
173         if (S_ISCHR(mode) || S_ISBLK(mode)) {
174                 if (unlikely(!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff))
175                         return -EINVAL;
176                 rdev = sysv_encode_dev(rdev);
177         } else {
178                 rdev = 0;
179         }
180
181         if (IS_POSIXACL(dir)) {
182                 default_acl = xfs_get_acl(dir, ACL_TYPE_DEFAULT);
183                 if (IS_ERR(default_acl))
184                         return -PTR_ERR(default_acl);
185
186                 if (!default_acl)
187                         mode &= ~current_umask();
188         }
189
190         xfs_dentry_to_name(&name, dentry);
191         error = xfs_create(XFS_I(dir), &name, mode, rdev, &ip);
192         if (unlikely(error))
193                 goto out_free_acl;
194
195         inode = VFS_I(ip);
196
197         error = xfs_init_security(inode, dir);
198         if (unlikely(error))
199                 goto out_cleanup_inode;
200
201         if (default_acl) {
202                 error = -xfs_inherit_acl(inode, default_acl);
203                 if (unlikely(error))
204                         goto out_cleanup_inode;
205                 posix_acl_release(default_acl);
206         }
207
208
209         d_instantiate(dentry, inode);
210         return -error;
211
212  out_cleanup_inode:
213         xfs_cleanup_inode(dir, inode, dentry);
214  out_free_acl:
215         posix_acl_release(default_acl);
216         return -error;
217 }
218
219 STATIC int
220 xfs_vn_create(
221         struct inode    *dir,
222         struct dentry   *dentry,
223         int             mode,
224         struct nameidata *nd)
225 {
226         return xfs_vn_mknod(dir, dentry, mode, 0);
227 }
228
229 STATIC int
230 xfs_vn_mkdir(
231         struct inode    *dir,
232         struct dentry   *dentry,
233         int             mode)
234 {
235         return xfs_vn_mknod(dir, dentry, mode|S_IFDIR, 0);
236 }
237
238 STATIC struct dentry *
239 xfs_vn_lookup(
240         struct inode    *dir,
241         struct dentry   *dentry,
242         struct nameidata *nd)
243 {
244         struct xfs_inode *cip;
245         struct xfs_name name;
246         int             error;
247
248         if (dentry->d_name.len >= MAXNAMELEN)
249                 return ERR_PTR(-ENAMETOOLONG);
250
251         xfs_dentry_to_name(&name, dentry);
252         error = xfs_lookup(XFS_I(dir), &name, &cip, NULL);
253         if (unlikely(error)) {
254                 if (unlikely(error != ENOENT))
255                         return ERR_PTR(-error);
256                 d_add(dentry, NULL);
257                 return NULL;
258         }
259
260         return d_splice_alias(VFS_I(cip), dentry);
261 }
262
263 STATIC struct dentry *
264 xfs_vn_ci_lookup(
265         struct inode    *dir,
266         struct dentry   *dentry,
267         struct nameidata *nd)
268 {
269         struct xfs_inode *ip;
270         struct xfs_name xname;
271         struct xfs_name ci_name;
272         struct qstr     dname;
273         int             error;
274
275         if (dentry->d_name.len >= MAXNAMELEN)
276                 return ERR_PTR(-ENAMETOOLONG);
277
278         xfs_dentry_to_name(&xname, dentry);
279         error = xfs_lookup(XFS_I(dir), &xname, &ip, &ci_name);
280         if (unlikely(error)) {
281                 if (unlikely(error != ENOENT))
282                         return ERR_PTR(-error);
283                 /*
284                  * call d_add(dentry, NULL) here when d_drop_negative_children
285                  * is called in xfs_vn_mknod (ie. allow negative dentries
286                  * with CI filesystems).
287                  */
288                 return NULL;
289         }
290
291         /* if exact match, just splice and exit */
292         if (!ci_name.name)
293                 return d_splice_alias(VFS_I(ip), dentry);
294
295         /* else case-insensitive match... */
296         dname.name = ci_name.name;
297         dname.len = ci_name.len;
298         dentry = d_add_ci(dentry, VFS_I(ip), &dname);
299         kmem_free(ci_name.name);
300         return dentry;
301 }
302
303 STATIC int
304 xfs_vn_link(
305         struct dentry   *old_dentry,
306         struct inode    *dir,
307         struct dentry   *dentry)
308 {
309         struct inode    *inode = old_dentry->d_inode;
310         struct xfs_name name;
311         int             error;
312
313         xfs_dentry_to_name(&name, dentry);
314
315         error = xfs_link(XFS_I(dir), XFS_I(inode), &name);
316         if (unlikely(error))
317                 return -error;
318
319         ihold(inode);
320         d_instantiate(dentry, inode);
321         return 0;
322 }
323
324 STATIC int
325 xfs_vn_unlink(
326         struct inode    *dir,
327         struct dentry   *dentry)
328 {
329         struct xfs_name name;
330         int             error;
331
332         xfs_dentry_to_name(&name, dentry);
333
334         error = -xfs_remove(XFS_I(dir), &name, XFS_I(dentry->d_inode));
335         if (error)
336                 return error;
337
338         /*
339          * With unlink, the VFS makes the dentry "negative": no inode,
340          * but still hashed. This is incompatible with case-insensitive
341          * mode, so invalidate (unhash) the dentry in CI-mode.
342          */
343         if (xfs_sb_version_hasasciici(&XFS_M(dir->i_sb)->m_sb))
344                 d_invalidate(dentry);
345         return 0;
346 }
347
348 STATIC int
349 xfs_vn_symlink(
350         struct inode    *dir,
351         struct dentry   *dentry,
352         const char      *symname)
353 {
354         struct inode    *inode;
355         struct xfs_inode *cip = NULL;
356         struct xfs_name name;
357         int             error;
358         mode_t          mode;
359
360         mode = S_IFLNK |
361                 (irix_symlink_mode ? 0777 & ~current_umask() : S_IRWXUGO);
362         xfs_dentry_to_name(&name, dentry);
363
364         error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip);
365         if (unlikely(error))
366                 goto out;
367
368         inode = VFS_I(cip);
369
370         error = xfs_init_security(inode, dir);
371         if (unlikely(error))
372                 goto out_cleanup_inode;
373
374         d_instantiate(dentry, inode);
375         return 0;
376
377  out_cleanup_inode:
378         xfs_cleanup_inode(dir, inode, dentry);
379  out:
380         return -error;
381 }
382
383 STATIC int
384 xfs_vn_rename(
385         struct inode    *odir,
386         struct dentry   *odentry,
387         struct inode    *ndir,
388         struct dentry   *ndentry)
389 {
390         struct inode    *new_inode = ndentry->d_inode;
391         struct xfs_name oname;
392         struct xfs_name nname;
393
394         xfs_dentry_to_name(&oname, odentry);
395         xfs_dentry_to_name(&nname, ndentry);
396
397         return -xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode),
398                            XFS_I(ndir), &nname, new_inode ?
399                                                 XFS_I(new_inode) : NULL);
400 }
401
402 /*
403  * careful here - this function can get called recursively, so
404  * we need to be very careful about how much stack we use.
405  * uio is kmalloced for this reason...
406  */
407 STATIC void *
408 xfs_vn_follow_link(
409         struct dentry           *dentry,
410         struct nameidata        *nd)
411 {
412         char                    *link;
413         int                     error = -ENOMEM;
414
415         link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
416         if (!link)
417                 goto out_err;
418
419         error = -xfs_readlink(XFS_I(dentry->d_inode), link);
420         if (unlikely(error))
421                 goto out_kfree;
422
423         nd_set_link(nd, link);
424         return NULL;
425
426  out_kfree:
427         kfree(link);
428  out_err:
429         nd_set_link(nd, ERR_PTR(error));
430         return NULL;
431 }
432
433 STATIC void
434 xfs_vn_put_link(
435         struct dentry   *dentry,
436         struct nameidata *nd,
437         void            *p)
438 {
439         char            *s = nd_get_link(nd);
440
441         if (!IS_ERR(s))
442                 kfree(s);
443 }
444
445 STATIC int
446 xfs_vn_getattr(
447         struct vfsmount         *mnt,
448         struct dentry           *dentry,
449         struct kstat            *stat)
450 {
451         struct inode            *inode = dentry->d_inode;
452         struct xfs_inode        *ip = XFS_I(inode);
453         struct xfs_mount        *mp = ip->i_mount;
454
455         trace_xfs_getattr(ip);
456
457         if (XFS_FORCED_SHUTDOWN(mp))
458                 return XFS_ERROR(EIO);
459
460         stat->size = XFS_ISIZE(ip);
461         stat->dev = inode->i_sb->s_dev;
462         stat->mode = ip->i_d.di_mode;
463         stat->nlink = ip->i_d.di_nlink;
464         stat->uid = ip->i_d.di_uid;
465         stat->gid = ip->i_d.di_gid;
466         stat->ino = ip->i_ino;
467         stat->atime = inode->i_atime;
468         stat->mtime = inode->i_mtime;
469         stat->ctime = inode->i_ctime;
470         stat->blocks =
471                 XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
472
473
474         switch (inode->i_mode & S_IFMT) {
475         case S_IFBLK:
476         case S_IFCHR:
477                 stat->blksize = BLKDEV_IOSIZE;
478                 stat->rdev = MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
479                                    sysv_minor(ip->i_df.if_u2.if_rdev));
480                 break;
481         default:
482                 if (XFS_IS_REALTIME_INODE(ip)) {
483                         /*
484                          * If the file blocks are being allocated from a
485                          * realtime volume, then return the inode's realtime
486                          * extent size or the realtime volume's extent size.
487                          */
488                         stat->blksize =
489                                 xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
490                 } else
491                         stat->blksize = xfs_preferred_iosize(mp);
492                 stat->rdev = 0;
493                 break;
494         }
495
496         return 0;
497 }
498
499 STATIC int
500 xfs_vn_setattr(
501         struct dentry   *dentry,
502         struct iattr    *iattr)
503 {
504         return -xfs_setattr(XFS_I(dentry->d_inode), iattr, 0);
505 }
506
507 #define XFS_FIEMAP_FLAGS        (FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR)
508
509 /*
510  * Call fiemap helper to fill in user data.
511  * Returns positive errors to xfs_getbmap.
512  */
513 STATIC int
514 xfs_fiemap_format(
515         void                    **arg,
516         struct getbmapx         *bmv,
517         int                     *full)
518 {
519         int                     error;
520         struct fiemap_extent_info *fieinfo = *arg;
521         u32                     fiemap_flags = 0;
522         u64                     logical, physical, length;
523
524         /* Do nothing for a hole */
525         if (bmv->bmv_block == -1LL)
526                 return 0;
527
528         logical = BBTOB(bmv->bmv_offset);
529         physical = BBTOB(bmv->bmv_block);
530         length = BBTOB(bmv->bmv_length);
531
532         if (bmv->bmv_oflags & BMV_OF_PREALLOC)
533                 fiemap_flags |= FIEMAP_EXTENT_UNWRITTEN;
534         else if (bmv->bmv_oflags & BMV_OF_DELALLOC) {
535                 fiemap_flags |= FIEMAP_EXTENT_DELALLOC;
536                 physical = 0;   /* no block yet */
537         }
538         if (bmv->bmv_oflags & BMV_OF_LAST)
539                 fiemap_flags |= FIEMAP_EXTENT_LAST;
540
541         error = fiemap_fill_next_extent(fieinfo, logical, physical,
542                                         length, fiemap_flags);
543         if (error > 0) {
544                 error = 0;
545                 *full = 1;      /* user array now full */
546         }
547
548         return -error;
549 }
550
551 STATIC int
552 xfs_vn_fiemap(
553         struct inode            *inode,
554         struct fiemap_extent_info *fieinfo,
555         u64                     start,
556         u64                     length)
557 {
558         xfs_inode_t             *ip = XFS_I(inode);
559         struct getbmapx         bm;
560         int                     error;
561
562         error = fiemap_check_flags(fieinfo, XFS_FIEMAP_FLAGS);
563         if (error)
564                 return error;
565
566         /* Set up bmap header for xfs internal routine */
567         bm.bmv_offset = BTOBB(start);
568         /* Special case for whole file */
569         if (length == FIEMAP_MAX_OFFSET)
570                 bm.bmv_length = -1LL;
571         else
572                 bm.bmv_length = BTOBB(length);
573
574         /* We add one because in getbmap world count includes the header */
575         bm.bmv_count = !fieinfo->fi_extents_max ? MAXEXTNUM :
576                                         fieinfo->fi_extents_max + 1;
577         bm.bmv_count = min_t(__s32, bm.bmv_count,
578                              (PAGE_SIZE * 16 / sizeof(struct getbmapx)));
579         bm.bmv_iflags = BMV_IF_PREALLOC | BMV_IF_NO_HOLES;
580         if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR)
581                 bm.bmv_iflags |= BMV_IF_ATTRFORK;
582         if (!(fieinfo->fi_flags & FIEMAP_FLAG_SYNC))
583                 bm.bmv_iflags |= BMV_IF_DELALLOC;
584
585         error = xfs_getbmap(ip, &bm, xfs_fiemap_format, fieinfo);
586         if (error)
587                 return -error;
588
589         return 0;
590 }
591
592 static const struct inode_operations xfs_inode_operations = {
593         .check_acl              = xfs_check_acl,
594         .getattr                = xfs_vn_getattr,
595         .setattr                = xfs_vn_setattr,
596         .setxattr               = generic_setxattr,
597         .getxattr               = generic_getxattr,
598         .removexattr            = generic_removexattr,
599         .listxattr              = xfs_vn_listxattr,
600         .fiemap                 = xfs_vn_fiemap,
601 };
602
603 static const struct inode_operations xfs_dir_inode_operations = {
604         .create                 = xfs_vn_create,
605         .lookup                 = xfs_vn_lookup,
606         .link                   = xfs_vn_link,
607         .unlink                 = xfs_vn_unlink,
608         .symlink                = xfs_vn_symlink,
609         .mkdir                  = xfs_vn_mkdir,
610         /*
611          * Yes, XFS uses the same method for rmdir and unlink.
612          *
613          * There are some subtile differences deeper in the code,
614          * but we use S_ISDIR to check for those.
615          */
616         .rmdir                  = xfs_vn_unlink,
617         .mknod                  = xfs_vn_mknod,
618         .rename                 = xfs_vn_rename,
619         .check_acl              = xfs_check_acl,
620         .getattr                = xfs_vn_getattr,
621         .setattr                = xfs_vn_setattr,
622         .setxattr               = generic_setxattr,
623         .getxattr               = generic_getxattr,
624         .removexattr            = generic_removexattr,
625         .listxattr              = xfs_vn_listxattr,
626 };
627
628 static const struct inode_operations xfs_dir_ci_inode_operations = {
629         .create                 = xfs_vn_create,
630         .lookup                 = xfs_vn_ci_lookup,
631         .link                   = xfs_vn_link,
632         .unlink                 = xfs_vn_unlink,
633         .symlink                = xfs_vn_symlink,
634         .mkdir                  = xfs_vn_mkdir,
635         /*
636          * Yes, XFS uses the same method for rmdir and unlink.
637          *
638          * There are some subtile differences deeper in the code,
639          * but we use S_ISDIR to check for those.
640          */
641         .rmdir                  = xfs_vn_unlink,
642         .mknod                  = xfs_vn_mknod,
643         .rename                 = xfs_vn_rename,
644         .check_acl              = xfs_check_acl,
645         .getattr                = xfs_vn_getattr,
646         .setattr                = xfs_vn_setattr,
647         .setxattr               = generic_setxattr,
648         .getxattr               = generic_getxattr,
649         .removexattr            = generic_removexattr,
650         .listxattr              = xfs_vn_listxattr,
651 };
652
653 static const struct inode_operations xfs_symlink_inode_operations = {
654         .readlink               = generic_readlink,
655         .follow_link            = xfs_vn_follow_link,
656         .put_link               = xfs_vn_put_link,
657         .check_acl              = xfs_check_acl,
658         .getattr                = xfs_vn_getattr,
659         .setattr                = xfs_vn_setattr,
660         .setxattr               = generic_setxattr,
661         .getxattr               = generic_getxattr,
662         .removexattr            = generic_removexattr,
663         .listxattr              = xfs_vn_listxattr,
664 };
665
666 STATIC void
667 xfs_diflags_to_iflags(
668         struct inode            *inode,
669         struct xfs_inode        *ip)
670 {
671         if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
672                 inode->i_flags |= S_IMMUTABLE;
673         else
674                 inode->i_flags &= ~S_IMMUTABLE;
675         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
676                 inode->i_flags |= S_APPEND;
677         else
678                 inode->i_flags &= ~S_APPEND;
679         if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
680                 inode->i_flags |= S_SYNC;
681         else
682                 inode->i_flags &= ~S_SYNC;
683         if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
684                 inode->i_flags |= S_NOATIME;
685         else
686                 inode->i_flags &= ~S_NOATIME;
687 }
688
689 /*
690  * Initialize the Linux inode, set up the operation vectors and
691  * unlock the inode.
692  *
693  * When reading existing inodes from disk this is called directly
694  * from xfs_iget, when creating a new inode it is called from
695  * xfs_ialloc after setting up the inode.
696  *
697  * We are always called with an uninitialised linux inode here.
698  * We need to initialise the necessary fields and take a reference
699  * on it.
700  */
701 void
702 xfs_setup_inode(
703         struct xfs_inode        *ip)
704 {
705         struct inode            *inode = &ip->i_vnode;
706
707         inode->i_ino = ip->i_ino;
708         inode->i_state = I_NEW;
709
710         inode_sb_list_add(inode);
711         /* make the inode look hashed for the writeback code */
712         hlist_add_fake(&inode->i_hash);
713
714         inode->i_mode   = ip->i_d.di_mode;
715         inode->i_nlink  = ip->i_d.di_nlink;
716         inode->i_uid    = ip->i_d.di_uid;
717         inode->i_gid    = ip->i_d.di_gid;
718
719         switch (inode->i_mode & S_IFMT) {
720         case S_IFBLK:
721         case S_IFCHR:
722                 inode->i_rdev =
723                         MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
724                               sysv_minor(ip->i_df.if_u2.if_rdev));
725                 break;
726         default:
727                 inode->i_rdev = 0;
728                 break;
729         }
730
731         inode->i_generation = ip->i_d.di_gen;
732         i_size_write(inode, ip->i_d.di_size);
733         inode->i_atime.tv_sec   = ip->i_d.di_atime.t_sec;
734         inode->i_atime.tv_nsec  = ip->i_d.di_atime.t_nsec;
735         inode->i_mtime.tv_sec   = ip->i_d.di_mtime.t_sec;
736         inode->i_mtime.tv_nsec  = ip->i_d.di_mtime.t_nsec;
737         inode->i_ctime.tv_sec   = ip->i_d.di_ctime.t_sec;
738         inode->i_ctime.tv_nsec  = ip->i_d.di_ctime.t_nsec;
739         xfs_diflags_to_iflags(inode, ip);
740
741         switch (inode->i_mode & S_IFMT) {
742         case S_IFREG:
743                 inode->i_op = &xfs_inode_operations;
744                 inode->i_fop = &xfs_file_operations;
745                 inode->i_mapping->a_ops = &xfs_address_space_operations;
746                 break;
747         case S_IFDIR:
748                 if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
749                         inode->i_op = &xfs_dir_ci_inode_operations;
750                 else
751                         inode->i_op = &xfs_dir_inode_operations;
752                 inode->i_fop = &xfs_dir_file_operations;
753                 break;
754         case S_IFLNK:
755                 inode->i_op = &xfs_symlink_inode_operations;
756                 if (!(ip->i_df.if_flags & XFS_IFINLINE))
757                         inode->i_mapping->a_ops = &xfs_address_space_operations;
758                 break;
759         default:
760                 inode->i_op = &xfs_inode_operations;
761                 init_special_inode(inode, inode->i_mode, inode->i_rdev);
762                 break;
763         }
764
765         xfs_iflags_clear(ip, XFS_INEW);
766         barrier();
767
768         unlock_new_inode(inode);
769 }