blob: 76b570dd1ab26a3127aa0f2b556d21ad9c58bfe8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
19#include "xfs_fs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110020#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110022#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "xfs_trans.h"
24#include "xfs_sb.h"
25#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "xfs_dir2.h"
27#include "xfs_alloc.h"
28#include "xfs_dmapi.h"
29#include "xfs_quota.h"
30#include "xfs_mount.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "xfs_bmap_btree.h"
Nathan Scotta844f452005-11-02 14:38:42 +110032#include "xfs_alloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "xfs_ialloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "xfs_dir2_sf.h"
Nathan Scotta844f452005-11-02 14:38:42 +110035#include "xfs_attr_sf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "xfs_dinode.h"
37#include "xfs_inode.h"
38#include "xfs_bmap.h"
Nathan Scotta844f452005-11-02 14:38:42 +110039#include "xfs_btree.h"
40#include "xfs_ialloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include "xfs_rtalloc.h"
42#include "xfs_error.h"
43#include "xfs_itable.h"
44#include "xfs_rw.h"
45#include "xfs_acl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include "xfs_attr.h"
47#include "xfs_buf_item.h"
48#include "xfs_utils.h"
Christoph Hellwig739bfb22007-08-29 10:58:01 +100049#include "xfs_vnodeops.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Randy Dunlap16f7e0f2006-01-11 12:17:46 -080051#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/xattr.h>
53#include <linux/namei.h>
Nathan Scott446ada42006-01-11 15:35:44 +110054#include <linux/security.h>
David Chinner3ed65262007-11-23 16:29:25 +110055#include <linux/falloc.h>
Eric Sandeenf35642e2008-11-28 14:23:35 +110056#include <linux/fiemap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Nathan Scott4aeb6642005-11-02 11:43:58 +110058/*
Christoph Hellwig42fe2b12006-01-11 15:35:17 +110059 * Bring the atime in the XFS inode uptodate.
60 * Used before logging the inode to disk or when the Linux inode goes away.
61 */
62void
63xfs_synchronize_atime(
64 xfs_inode_t *ip)
65{
David Chinner01651642008-08-13 15:45:15 +100066 struct inode *inode = VFS_I(ip);
Christoph Hellwig42fe2b12006-01-11 15:35:17 +110067
David Chinnerbf904242008-10-30 17:36:14 +110068 if (!(inode->i_state & I_CLEAR)) {
Christoph Hellwigaf048192008-03-06 13:46:43 +110069 ip->i_d.di_atime.t_sec = (__int32_t)inode->i_atime.tv_sec;
70 ip->i_d.di_atime.t_nsec = (__int32_t)inode->i_atime.tv_nsec;
Christoph Hellwig42fe2b12006-01-11 15:35:17 +110071 }
72}
73
74/*
David Chinnerbf904242008-10-30 17:36:14 +110075 * If the linux inode is valid, mark it dirty.
David Chinner5d51eff2007-11-23 16:29:18 +110076 * Used when commiting a dirty inode into a transaction so that
77 * the inode will get written back by the linux code
78 */
79void
80xfs_mark_inode_dirty_sync(
81 xfs_inode_t *ip)
82{
David Chinner01651642008-08-13 15:45:15 +100083 struct inode *inode = VFS_I(ip);
David Chinner5d51eff2007-11-23 16:29:18 +110084
David Chinnerbf904242008-10-30 17:36:14 +110085 if (!(inode->i_state & (I_WILL_FREE|I_FREEING|I_CLEAR)))
Christoph Hellwigaf048192008-03-06 13:46:43 +110086 mark_inode_dirty_sync(inode);
David Chinner5d51eff2007-11-23 16:29:18 +110087}
88
89/*
Nathan Scott4aeb6642005-11-02 11:43:58 +110090 * Change the requested timestamp in the given inode.
91 * We don't lock across timestamp updates, and we don't log them but
92 * we do record the fact that there is dirty information in core.
Nathan Scott4aeb6642005-11-02 11:43:58 +110093 */
94void
95xfs_ichgtime(
96 xfs_inode_t *ip,
97 int flags)
98{
David Chinnere4f75292008-08-13 16:00:45 +100099 struct inode *inode = VFS_I(ip);
Nathan Scott4aeb6642005-11-02 11:43:58 +1100100 timespec_t tv;
Christoph Hellwig8e5975c2008-08-13 16:45:13 +1000101 int sync_it = 0;
Nathan Scott4aeb6642005-11-02 11:43:58 +1100102
Christoph Hellwig8e5975c2008-08-13 16:45:13 +1000103 tv = current_fs_time(inode->i_sb);
104
105 if ((flags & XFS_ICHGTIME_MOD) &&
106 !timespec_equal(&inode->i_mtime, &tv)) {
Nathan Scott4aeb6642005-11-02 11:43:58 +1100107 inode->i_mtime = tv;
108 ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec;
109 ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec;
Christoph Hellwig8e5975c2008-08-13 16:45:13 +1000110 sync_it = 1;
Nathan Scott4aeb6642005-11-02 11:43:58 +1100111 }
Christoph Hellwig8e5975c2008-08-13 16:45:13 +1000112 if ((flags & XFS_ICHGTIME_CHG) &&
113 !timespec_equal(&inode->i_ctime, &tv)) {
Nathan Scott4aeb6642005-11-02 11:43:58 +1100114 inode->i_ctime = tv;
115 ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec;
116 ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec;
Christoph Hellwig8e5975c2008-08-13 16:45:13 +1000117 sync_it = 1;
Nathan Scott4aeb6642005-11-02 11:43:58 +1100118 }
119
120 /*
121 * We update the i_update_core field _after_ changing
122 * the timestamps in order to coordinate properly with
123 * xfs_iflush() so that we don't lose timestamp updates.
124 * This keeps us from having to hold the inode lock
125 * while doing this. We use the SYNCHRONIZE macro to
126 * ensure that the compiler does not reorder the update
127 * of i_update_core above the timestamp updates above.
128 */
Christoph Hellwig8e5975c2008-08-13 16:45:13 +1000129 if (sync_it) {
130 SYNCHRONIZE();
131 ip->i_update_core = 1;
David Chinner94b97e32008-10-30 17:21:30 +1100132 xfs_mark_inode_dirty_sync(ip);
Christoph Hellwig8e5975c2008-08-13 16:45:13 +1000133 }
Nathan Scott4aeb6642005-11-02 11:43:58 +1100134}
135
136/*
Nathan Scott446ada42006-01-11 15:35:44 +1100137 * Hook in SELinux. This is not quite correct yet, what we really need
138 * here (as we do for default ACLs) is a mechanism by which creation of
139 * these attrs can be journalled at inode creation time (along with the
140 * inode, of course, such that log replay can't cause these to be lost).
141 */
142STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100143xfs_init_security(
Christoph Hellwigaf048192008-03-06 13:46:43 +1100144 struct inode *inode,
Nathan Scott446ada42006-01-11 15:35:44 +1100145 struct inode *dir)
146{
Christoph Hellwigaf048192008-03-06 13:46:43 +1100147 struct xfs_inode *ip = XFS_I(inode);
Nathan Scott446ada42006-01-11 15:35:44 +1100148 size_t length;
149 void *value;
150 char *name;
151 int error;
152
Christoph Hellwigaf048192008-03-06 13:46:43 +1100153 error = security_inode_init_security(inode, dir, &name,
154 &value, &length);
Nathan Scott446ada42006-01-11 15:35:44 +1100155 if (error) {
156 if (error == -EOPNOTSUPP)
157 return 0;
158 return -error;
159 }
160
Christoph Hellwigaf048192008-03-06 13:46:43 +1100161 error = xfs_attr_set(ip, name, value, length, ATTR_SECURE);
Nathan Scott446ada42006-01-11 15:35:44 +1100162 if (!error)
Christoph Hellwigaf048192008-03-06 13:46:43 +1100163 xfs_iflags_set(ip, XFS_IMODIFIED);
Nathan Scott446ada42006-01-11 15:35:44 +1100164
165 kfree(name);
166 kfree(value);
167 return error;
168}
169
Barry Naujok556b8b12008-04-10 12:22:07 +1000170static void
171xfs_dentry_to_name(
172 struct xfs_name *namep,
173 struct dentry *dentry)
174{
175 namep->name = dentry->d_name.name;
176 namep->len = dentry->d_name.len;
177}
178
David Chinner7989cb82007-02-10 18:34:56 +1100179STATIC void
Nathan Scott416c6d52006-03-14 14:00:51 +1100180xfs_cleanup_inode(
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000181 struct inode *dir,
Christoph Hellwigaf048192008-03-06 13:46:43 +1100182 struct inode *inode,
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000183 struct dentry *dentry)
Yingping Lu3a69c7d2006-02-01 12:14:34 +1100184{
Barry Naujok556b8b12008-04-10 12:22:07 +1000185 struct xfs_name teardown;
Yingping Lu3a69c7d2006-02-01 12:14:34 +1100186
187 /* Oh, the horror.
Nathan Scott220b5282006-03-14 13:33:36 +1100188 * If we can't add the ACL or we fail in
Nathan Scott416c6d52006-03-14 14:00:51 +1100189 * xfs_init_security we must back out.
Yingping Lu3a69c7d2006-02-01 12:14:34 +1100190 * ENOSPC can hit here, among other things.
191 */
Barry Naujok556b8b12008-04-10 12:22:07 +1000192 xfs_dentry_to_name(&teardown, dentry);
Yingping Lu3a69c7d2006-02-01 12:14:34 +1100193
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000194 xfs_remove(XFS_I(dir), &teardown, XFS_I(inode));
Christoph Hellwigaf048192008-03-06 13:46:43 +1100195 iput(inode);
Yingping Lu3a69c7d2006-02-01 12:14:34 +1100196}
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100199xfs_vn_mknod(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 struct inode *dir,
201 struct dentry *dentry,
202 int mode,
203 dev_t rdev)
204{
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100205 struct inode *inode;
Christoph Hellwig979ebab2008-03-06 13:46:05 +1100206 struct xfs_inode *ip = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 xfs_acl_t *default_acl = NULL;
Barry Naujok556b8b12008-04-10 12:22:07 +1000208 struct xfs_name name;
Lachlan McIlroy0ec58512008-06-23 13:23:01 +1000209 int (*test_default_acl)(struct inode *) = _ACL_DEFAULT_EXISTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 int error;
211
212 /*
213 * Irix uses Missed'em'V split, but doesn't want to see
214 * the upper 5 bits of (14bit) major.
215 */
Nathan Scott220b5282006-03-14 13:33:36 +1100216 if (unlikely(!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 return -EINVAL;
218
Christoph Hellwig979ebab2008-03-06 13:46:05 +1100219 if (test_default_acl && test_default_acl(dir)) {
Nathan Scott220b5282006-03-14 13:33:36 +1100220 if (!_ACL_ALLOC(default_acl)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 return -ENOMEM;
Nathan Scott220b5282006-03-14 13:33:36 +1100222 }
Christoph Hellwig979ebab2008-03-06 13:46:05 +1100223 if (!_ACL_GET_DEFAULT(dir, default_acl)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 _ACL_FREE(default_acl);
225 default_acl = NULL;
226 }
227 }
228
Barry Naujok556b8b12008-04-10 12:22:07 +1000229 xfs_dentry_to_name(&name, dentry);
230
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100231 if (IS_POSIXACL(dir) && !default_acl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 mode &= ~current->fs->umask;
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 switch (mode & S_IFMT) {
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100235 case S_IFCHR:
236 case S_IFBLK:
237 case S_IFIFO:
238 case S_IFSOCK:
Christoph Hellwig3e5daf02007-10-11 18:09:12 +1000239 rdev = sysv_encode_dev(rdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 case S_IFREG:
Barry Naujok556b8b12008-04-10 12:22:07 +1000241 error = xfs_create(XFS_I(dir), &name, mode, rdev, &ip, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 break;
243 case S_IFDIR:
Barry Naujok556b8b12008-04-10 12:22:07 +1000244 error = xfs_mkdir(XFS_I(dir), &name, mode, &ip, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 break;
246 default:
247 error = EINVAL;
248 break;
249 }
250
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100251 if (unlikely(error))
252 goto out_free_acl;
Nathan Scott446ada42006-01-11 15:35:44 +1100253
David Chinner01651642008-08-13 15:45:15 +1000254 inode = VFS_I(ip);
Christoph Hellwig979ebab2008-03-06 13:46:05 +1100255
256 error = xfs_init_security(inode, dir);
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100257 if (unlikely(error))
258 goto out_cleanup_inode;
259
260 if (default_acl) {
Christoph Hellwig979ebab2008-03-06 13:46:05 +1100261 error = _ACL_INHERIT(inode, mode, default_acl);
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100262 if (unlikely(error))
263 goto out_cleanup_inode;
Christoph Hellwig979ebab2008-03-06 13:46:05 +1100264 xfs_iflags_set(ip, XFS_IMODIFIED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 _ACL_FREE(default_acl);
266 }
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100269 d_instantiate(dentry, inode);
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100270 return -error;
271
272 out_cleanup_inode:
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000273 xfs_cleanup_inode(dir, inode, dentry);
Christoph Hellwigdb0bb7b2008-03-06 13:44:35 +1100274 out_free_acl:
275 if (default_acl)
276 _ACL_FREE(default_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 return -error;
278}
279
280STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100281xfs_vn_create(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 struct inode *dir,
283 struct dentry *dentry,
284 int mode,
285 struct nameidata *nd)
286{
Nathan Scott416c6d52006-03-14 14:00:51 +1100287 return xfs_vn_mknod(dir, dentry, mode, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}
289
290STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100291xfs_vn_mkdir(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 struct inode *dir,
293 struct dentry *dentry,
294 int mode)
295{
Nathan Scott416c6d52006-03-14 14:00:51 +1100296 return xfs_vn_mknod(dir, dentry, mode|S_IFDIR, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297}
298
299STATIC struct dentry *
Nathan Scott416c6d52006-03-14 14:00:51 +1100300xfs_vn_lookup(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 struct inode *dir,
302 struct dentry *dentry,
303 struct nameidata *nd)
304{
Christoph Hellwigef1f5e72008-03-06 13:46:25 +1100305 struct xfs_inode *cip;
Barry Naujok556b8b12008-04-10 12:22:07 +1000306 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 int error;
308
309 if (dentry->d_name.len >= MAXNAMELEN)
310 return ERR_PTR(-ENAMETOOLONG);
311
Barry Naujok556b8b12008-04-10 12:22:07 +1000312 xfs_dentry_to_name(&name, dentry);
Barry Naujok384f3ce2008-05-21 16:58:22 +1000313 error = xfs_lookup(XFS_I(dir), &name, &cip, NULL);
Nathan Scott67fcaa72006-06-09 17:00:52 +1000314 if (unlikely(error)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 if (unlikely(error != ENOENT))
316 return ERR_PTR(-error);
317 d_add(dentry, NULL);
318 return NULL;
319 }
320
David Chinner01651642008-08-13 15:45:15 +1000321 return d_splice_alias(VFS_I(cip), dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322}
323
Barry Naujok384f3ce2008-05-21 16:58:22 +1000324STATIC struct dentry *
325xfs_vn_ci_lookup(
326 struct inode *dir,
327 struct dentry *dentry,
328 struct nameidata *nd)
329{
330 struct xfs_inode *ip;
331 struct xfs_name xname;
332 struct xfs_name ci_name;
333 struct qstr dname;
334 int error;
335
336 if (dentry->d_name.len >= MAXNAMELEN)
337 return ERR_PTR(-ENAMETOOLONG);
338
339 xfs_dentry_to_name(&xname, dentry);
340 error = xfs_lookup(XFS_I(dir), &xname, &ip, &ci_name);
341 if (unlikely(error)) {
342 if (unlikely(error != ENOENT))
343 return ERR_PTR(-error);
Barry Naujok866d5dc2008-05-22 17:21:40 +1000344 /*
345 * call d_add(dentry, NULL) here when d_drop_negative_children
346 * is called in xfs_vn_mknod (ie. allow negative dentries
347 * with CI filesystems).
348 */
Barry Naujok384f3ce2008-05-21 16:58:22 +1000349 return NULL;
350 }
351
352 /* if exact match, just splice and exit */
353 if (!ci_name.name)
David Chinner01651642008-08-13 15:45:15 +1000354 return d_splice_alias(VFS_I(ip), dentry);
Barry Naujok384f3ce2008-05-21 16:58:22 +1000355
356 /* else case-insensitive match... */
357 dname.name = ci_name.name;
358 dname.len = ci_name.len;
Christoph Hellwige45b5902008-08-07 23:49:07 +0200359 dentry = d_add_ci(dentry, VFS_I(ip), &dname);
Barry Naujok384f3ce2008-05-21 16:58:22 +1000360 kmem_free(ci_name.name);
361 return dentry;
362}
363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100365xfs_vn_link(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 struct dentry *old_dentry,
367 struct inode *dir,
368 struct dentry *dentry)
369{
Christoph Hellwigd9424b32008-12-03 12:20:27 +0100370 struct inode *inode = old_dentry->d_inode;
Barry Naujok556b8b12008-04-10 12:22:07 +1000371 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 int error;
373
Barry Naujok556b8b12008-04-10 12:22:07 +1000374 xfs_dentry_to_name(&name, dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Barry Naujok556b8b12008-04-10 12:22:07 +1000376 error = xfs_link(XFS_I(dir), XFS_I(inode), &name);
Christoph Hellwigd9424b32008-12-03 12:20:27 +0100377 if (unlikely(error))
Christoph Hellwiga3da7892008-03-06 13:46:12 +1100378 return -error;
Christoph Hellwiga3da7892008-03-06 13:46:12 +1100379
380 xfs_iflags_set(XFS_I(dir), XFS_IMODIFIED);
Christoph Hellwigd9424b32008-12-03 12:20:27 +0100381 atomic_inc(&inode->i_count);
Christoph Hellwiga3da7892008-03-06 13:46:12 +1100382 d_instantiate(dentry, inode);
383 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384}
385
386STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100387xfs_vn_unlink(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 struct inode *dir,
389 struct dentry *dentry)
390{
Barry Naujok556b8b12008-04-10 12:22:07 +1000391 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 int error;
393
Barry Naujok556b8b12008-04-10 12:22:07 +1000394 xfs_dentry_to_name(&name, dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Christoph Hellwige5700702008-06-23 13:25:25 +1000396 error = -xfs_remove(XFS_I(dir), &name, XFS_I(dentry->d_inode));
397 if (error)
398 return error;
399
400 /*
401 * With unlink, the VFS makes the dentry "negative": no inode,
402 * but still hashed. This is incompatible with case-insensitive
403 * mode, so invalidate (unhash) the dentry in CI-mode.
404 */
405 if (xfs_sb_version_hasasciici(&XFS_M(dir->i_sb)->m_sb))
406 d_invalidate(dentry);
407 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
410STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100411xfs_vn_symlink(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 struct inode *dir,
413 struct dentry *dentry,
414 const char *symname)
415{
Christoph Hellwig3937be52008-03-06 13:46:19 +1100416 struct inode *inode;
417 struct xfs_inode *cip = NULL;
Barry Naujok556b8b12008-04-10 12:22:07 +1000418 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 int error;
Christoph Hellwig3e5daf02007-10-11 18:09:12 +1000420 mode_t mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Christoph Hellwig3e5daf02007-10-11 18:09:12 +1000422 mode = S_IFLNK |
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000423 (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO);
Barry Naujok556b8b12008-04-10 12:22:07 +1000424 xfs_dentry_to_name(&name, dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Barry Naujok556b8b12008-04-10 12:22:07 +1000426 error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip, NULL);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100427 if (unlikely(error))
428 goto out;
429
David Chinner01651642008-08-13 15:45:15 +1000430 inode = VFS_I(cip);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100431
432 error = xfs_init_security(inode, dir);
433 if (unlikely(error))
434 goto out_cleanup_inode;
435
436 d_instantiate(dentry, inode);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100437 return 0;
438
439 out_cleanup_inode:
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000440 xfs_cleanup_inode(dir, inode, dentry);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100441 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 return -error;
443}
444
445STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100446xfs_vn_rename(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 struct inode *odir,
448 struct dentry *odentry,
449 struct inode *ndir,
450 struct dentry *ndentry)
451{
452 struct inode *new_inode = ndentry->d_inode;
Barry Naujok556b8b12008-04-10 12:22:07 +1000453 struct xfs_name oname;
454 struct xfs_name nname;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Barry Naujok556b8b12008-04-10 12:22:07 +1000456 xfs_dentry_to_name(&oname, odentry);
457 xfs_dentry_to_name(&nname, ndentry);
458
Christoph Hellwige5700702008-06-23 13:25:25 +1000459 return -xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode),
Christoph Hellwigcfa853e2008-04-22 17:34:06 +1000460 XFS_I(ndir), &nname, new_inode ?
461 XFS_I(new_inode) : NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462}
463
464/*
465 * careful here - this function can get called recursively, so
466 * we need to be very careful about how much stack we use.
467 * uio is kmalloced for this reason...
468 */
Al Viro008b1502005-08-20 00:17:39 +0100469STATIC void *
Nathan Scott416c6d52006-03-14 14:00:51 +1100470xfs_vn_follow_link(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 struct dentry *dentry,
472 struct nameidata *nd)
473{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 char *link;
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000475 int error = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Panagiotis Issarisf52720c2006-09-27 01:49:39 -0700477 link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000478 if (!link)
479 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000481 error = -xfs_readlink(XFS_I(dentry->d_inode), link);
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000482 if (unlikely(error))
483 goto out_kfree;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 nd_set_link(nd, link);
Al Viro008b1502005-08-20 00:17:39 +0100486 return NULL;
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000487
488 out_kfree:
489 kfree(link);
490 out_err:
491 nd_set_link(nd, ERR_PTR(error));
492 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493}
494
Nathan Scottcde410a2005-09-05 11:47:01 +1000495STATIC void
Nathan Scott416c6d52006-03-14 14:00:51 +1100496xfs_vn_put_link(
Nathan Scottcde410a2005-09-05 11:47:01 +1000497 struct dentry *dentry,
498 struct nameidata *nd,
499 void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
Nathan Scottcde410a2005-09-05 11:47:01 +1000501 char *s = nd_get_link(nd);
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 if (!IS_ERR(s))
504 kfree(s);
505}
506
507#ifdef CONFIG_XFS_POSIX_ACL
508STATIC int
Christoph Hellwig45767582008-02-05 12:13:24 +1100509xfs_check_acl(
510 struct inode *inode,
511 int mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512{
Christoph Hellwig45767582008-02-05 12:13:24 +1100513 struct xfs_inode *ip = XFS_I(inode);
514 int error;
515
516 xfs_itrace_entry(ip);
517
518 if (XFS_IFORK_Q(ip)) {
519 error = xfs_acl_iaccess(ip, mask, NULL);
520 if (error != -1)
521 return -error;
522 }
523
524 return -EAGAIN;
525}
526
527STATIC int
528xfs_vn_permission(
529 struct inode *inode,
Al Viroe6305c42008-07-15 21:03:57 -0400530 int mask)
Christoph Hellwig45767582008-02-05 12:13:24 +1100531{
532 return generic_permission(inode, mask, xfs_check_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533}
534#else
Nathan Scott416c6d52006-03-14 14:00:51 +1100535#define xfs_vn_permission NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536#endif
537
538STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100539xfs_vn_getattr(
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000540 struct vfsmount *mnt,
541 struct dentry *dentry,
542 struct kstat *stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000544 struct inode *inode = dentry->d_inode;
545 struct xfs_inode *ip = XFS_I(inode);
546 struct xfs_mount *mp = ip->i_mount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000548 xfs_itrace_entry(ip);
549
550 if (XFS_FORCED_SHUTDOWN(mp))
551 return XFS_ERROR(EIO);
552
553 stat->size = XFS_ISIZE(ip);
554 stat->dev = inode->i_sb->s_dev;
555 stat->mode = ip->i_d.di_mode;
556 stat->nlink = ip->i_d.di_nlink;
557 stat->uid = ip->i_d.di_uid;
558 stat->gid = ip->i_d.di_gid;
559 stat->ino = ip->i_ino;
560#if XFS_BIG_INUMS
561 stat->ino += mp->m_inoadd;
562#endif
563 stat->atime = inode->i_atime;
564 stat->mtime.tv_sec = ip->i_d.di_mtime.t_sec;
565 stat->mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
566 stat->ctime.tv_sec = ip->i_d.di_ctime.t_sec;
567 stat->ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
568 stat->blocks =
569 XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
570
571
572 switch (inode->i_mode & S_IFMT) {
573 case S_IFBLK:
574 case S_IFCHR:
575 stat->blksize = BLKDEV_IOSIZE;
576 stat->rdev = MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
577 sysv_minor(ip->i_df.if_u2.if_rdev));
578 break;
579 default:
Eric Sandeen71ddabb2007-11-23 16:29:42 +1100580 if (XFS_IS_REALTIME_INODE(ip)) {
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000581 /*
582 * If the file blocks are being allocated from a
583 * realtime volume, then return the inode's realtime
584 * extent size or the realtime volume's extent size.
585 */
586 stat->blksize =
587 xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
588 } else
589 stat->blksize = xfs_preferred_iosize(mp);
590 stat->rdev = 0;
591 break;
Nathan Scott69e23b92006-09-28 11:01:22 +1000592 }
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000593
594 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
596
597STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100598xfs_vn_setattr(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 struct dentry *dentry,
Christoph Hellwig0f285c82008-07-18 17:13:28 +1000600 struct iattr *iattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
Christoph Hellwigea5a3dc82008-10-30 18:27:48 +1100602 return -xfs_setattr(XFS_I(dentry->d_inode), iattr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603}
604
David Chinnerd87dd632008-04-10 12:21:46 +1000605/*
606 * block_truncate_page can return an error, but we can't propagate it
607 * at all here. Leave a complaint + stack trace in the syslog because
608 * this could be bad. If it is bad, we need to propagate the error further.
609 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610STATIC void
Nathan Scott416c6d52006-03-14 14:00:51 +1100611xfs_vn_truncate(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 struct inode *inode)
613{
David Chinnerd87dd632008-04-10 12:21:46 +1000614 int error;
615 error = block_truncate_page(inode->i_mapping, inode->i_size,
616 xfs_get_blocks);
617 WARN_ON(error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618}
619
David Chinner3ed65262007-11-23 16:29:25 +1100620STATIC long
621xfs_vn_fallocate(
622 struct inode *inode,
623 int mode,
624 loff_t offset,
625 loff_t len)
626{
627 long error;
628 loff_t new_size = 0;
629 xfs_flock64_t bf;
630 xfs_inode_t *ip = XFS_I(inode);
631
632 /* preallocation on directories not yet supported */
633 error = -ENODEV;
634 if (S_ISDIR(inode->i_mode))
635 goto out_error;
636
637 bf.l_whence = 0;
638 bf.l_start = offset;
639 bf.l_len = len;
640
641 xfs_ilock(ip, XFS_IOLOCK_EXCL);
642 error = xfs_change_file_space(ip, XFS_IOC_RESVSP, &bf,
Christoph Hellwigea5a3dc82008-10-30 18:27:48 +1100643 0, XFS_ATTR_NOLOCK);
David Chinner3ed65262007-11-23 16:29:25 +1100644 if (!error && !(mode & FALLOC_FL_KEEP_SIZE) &&
645 offset + len > i_size_read(inode))
646 new_size = offset + len;
647
648 /* Change file size if needed */
649 if (new_size) {
Christoph Hellwig0f285c82008-07-18 17:13:28 +1000650 struct iattr iattr;
David Chinner3ed65262007-11-23 16:29:25 +1100651
Christoph Hellwig0f285c82008-07-18 17:13:28 +1000652 iattr.ia_valid = ATTR_SIZE;
653 iattr.ia_size = new_size;
Christoph Hellwigea5a3dc82008-10-30 18:27:48 +1100654 error = xfs_setattr(ip, &iattr, XFS_ATTR_NOLOCK);
David Chinner3ed65262007-11-23 16:29:25 +1100655 }
656
657 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
658out_error:
659 return error;
660}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Eric Sandeenf35642e2008-11-28 14:23:35 +1100662#define XFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR)
663
664/*
665 * Call fiemap helper to fill in user data.
666 * Returns positive errors to xfs_getbmap.
667 */
668STATIC int
669xfs_fiemap_format(
670 void **arg,
671 struct getbmapx *bmv,
672 int *full)
673{
674 int error;
675 struct fiemap_extent_info *fieinfo = *arg;
676 u32 fiemap_flags = 0;
677 u64 logical, physical, length;
678
679 /* Do nothing for a hole */
680 if (bmv->bmv_block == -1LL)
681 return 0;
682
683 logical = BBTOB(bmv->bmv_offset);
684 physical = BBTOB(bmv->bmv_block);
685 length = BBTOB(bmv->bmv_length);
686
687 if (bmv->bmv_oflags & BMV_OF_PREALLOC)
688 fiemap_flags |= FIEMAP_EXTENT_UNWRITTEN;
689 else if (bmv->bmv_oflags & BMV_OF_DELALLOC) {
690 fiemap_flags |= FIEMAP_EXTENT_DELALLOC;
691 physical = 0; /* no block yet */
692 }
693 if (bmv->bmv_oflags & BMV_OF_LAST)
694 fiemap_flags |= FIEMAP_EXTENT_LAST;
695
696 error = fiemap_fill_next_extent(fieinfo, logical, physical,
697 length, fiemap_flags);
698 if (error > 0) {
699 error = 0;
700 *full = 1; /* user array now full */
701 }
702
703 return -error;
704}
705
706STATIC int
707xfs_vn_fiemap(
708 struct inode *inode,
709 struct fiemap_extent_info *fieinfo,
710 u64 start,
711 u64 length)
712{
713 xfs_inode_t *ip = XFS_I(inode);
714 struct getbmapx bm;
715 int error;
716
717 error = fiemap_check_flags(fieinfo, XFS_FIEMAP_FLAGS);
718 if (error)
719 return error;
720
721 /* Set up bmap header for xfs internal routine */
722 bm.bmv_offset = BTOBB(start);
723 /* Special case for whole file */
724 if (length == FIEMAP_MAX_OFFSET)
725 bm.bmv_length = -1LL;
726 else
727 bm.bmv_length = BTOBB(length);
728
729 /* our formatter will tell xfs_getbmap when to stop. */
730 bm.bmv_count = MAXEXTNUM;
731 bm.bmv_iflags = BMV_IF_PREALLOC;
732 if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR)
733 bm.bmv_iflags |= BMV_IF_ATTRFORK;
734 if (!(fieinfo->fi_flags & FIEMAP_FLAG_SYNC))
735 bm.bmv_iflags |= BMV_IF_DELALLOC;
736
737 error = xfs_getbmap(ip, &bm, xfs_fiemap_format, fieinfo);
738 if (error)
739 return -error;
740
741 return 0;
742}
743
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000744static const struct inode_operations xfs_inode_operations = {
Nathan Scott416c6d52006-03-14 14:00:51 +1100745 .permission = xfs_vn_permission,
746 .truncate = xfs_vn_truncate,
747 .getattr = xfs_vn_getattr,
748 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +1000749 .setxattr = generic_setxattr,
750 .getxattr = generic_getxattr,
751 .removexattr = generic_removexattr,
Nathan Scott416c6d52006-03-14 14:00:51 +1100752 .listxattr = xfs_vn_listxattr,
David Chinner3ed65262007-11-23 16:29:25 +1100753 .fallocate = xfs_vn_fallocate,
Eric Sandeenf35642e2008-11-28 14:23:35 +1100754 .fiemap = xfs_vn_fiemap,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755};
756
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000757static const struct inode_operations xfs_dir_inode_operations = {
Nathan Scott416c6d52006-03-14 14:00:51 +1100758 .create = xfs_vn_create,
759 .lookup = xfs_vn_lookup,
760 .link = xfs_vn_link,
761 .unlink = xfs_vn_unlink,
762 .symlink = xfs_vn_symlink,
763 .mkdir = xfs_vn_mkdir,
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000764 /*
765 * Yes, XFS uses the same method for rmdir and unlink.
766 *
767 * There are some subtile differences deeper in the code,
768 * but we use S_ISDIR to check for those.
769 */
770 .rmdir = xfs_vn_unlink,
Nathan Scott416c6d52006-03-14 14:00:51 +1100771 .mknod = xfs_vn_mknod,
772 .rename = xfs_vn_rename,
773 .permission = xfs_vn_permission,
774 .getattr = xfs_vn_getattr,
775 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +1000776 .setxattr = generic_setxattr,
777 .getxattr = generic_getxattr,
778 .removexattr = generic_removexattr,
Nathan Scott416c6d52006-03-14 14:00:51 +1100779 .listxattr = xfs_vn_listxattr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780};
781
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000782static const struct inode_operations xfs_dir_ci_inode_operations = {
Barry Naujok384f3ce2008-05-21 16:58:22 +1000783 .create = xfs_vn_create,
784 .lookup = xfs_vn_ci_lookup,
785 .link = xfs_vn_link,
786 .unlink = xfs_vn_unlink,
787 .symlink = xfs_vn_symlink,
788 .mkdir = xfs_vn_mkdir,
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000789 /*
790 * Yes, XFS uses the same method for rmdir and unlink.
791 *
792 * There are some subtile differences deeper in the code,
793 * but we use S_ISDIR to check for those.
794 */
795 .rmdir = xfs_vn_unlink,
Barry Naujok384f3ce2008-05-21 16:58:22 +1000796 .mknod = xfs_vn_mknod,
797 .rename = xfs_vn_rename,
798 .permission = xfs_vn_permission,
799 .getattr = xfs_vn_getattr,
800 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +1000801 .setxattr = generic_setxattr,
802 .getxattr = generic_getxattr,
803 .removexattr = generic_removexattr,
Barry Naujok384f3ce2008-05-21 16:58:22 +1000804 .listxattr = xfs_vn_listxattr,
Barry Naujok384f3ce2008-05-21 16:58:22 +1000805};
806
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000807static const struct inode_operations xfs_symlink_inode_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 .readlink = generic_readlink,
Nathan Scott416c6d52006-03-14 14:00:51 +1100809 .follow_link = xfs_vn_follow_link,
810 .put_link = xfs_vn_put_link,
811 .permission = xfs_vn_permission,
812 .getattr = xfs_vn_getattr,
813 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +1000814 .setxattr = generic_setxattr,
815 .getxattr = generic_getxattr,
816 .removexattr = generic_removexattr,
Nathan Scott416c6d52006-03-14 14:00:51 +1100817 .listxattr = xfs_vn_listxattr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818};
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000819
820STATIC void
821xfs_diflags_to_iflags(
822 struct inode *inode,
823 struct xfs_inode *ip)
824{
825 if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
826 inode->i_flags |= S_IMMUTABLE;
827 else
828 inode->i_flags &= ~S_IMMUTABLE;
829 if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
830 inode->i_flags |= S_APPEND;
831 else
832 inode->i_flags &= ~S_APPEND;
833 if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
834 inode->i_flags |= S_SYNC;
835 else
836 inode->i_flags &= ~S_SYNC;
837 if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
838 inode->i_flags |= S_NOATIME;
839 else
840 inode->i_flags &= ~S_NOATIME;
841}
842
843/*
844 * Initialize the Linux inode, set up the operation vectors and
845 * unlock the inode.
846 *
847 * When reading existing inodes from disk this is called directly
848 * from xfs_iget, when creating a new inode it is called from
849 * xfs_ialloc after setting up the inode.
David Chinnerbf904242008-10-30 17:36:14 +1100850 *
851 * We are always called with an uninitialised linux inode here.
852 * We need to initialise the necessary fields and take a reference
853 * on it.
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000854 */
855void
856xfs_setup_inode(
857 struct xfs_inode *ip)
858{
David Chinnerbf904242008-10-30 17:36:14 +1100859 struct inode *inode = &ip->i_vnode;
860
861 inode->i_ino = ip->i_ino;
862 inode->i_state = I_NEW|I_LOCK;
863 inode_add_to_lists(ip->i_mount->m_super, inode);
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000864
865 inode->i_mode = ip->i_d.di_mode;
866 inode->i_nlink = ip->i_d.di_nlink;
867 inode->i_uid = ip->i_d.di_uid;
868 inode->i_gid = ip->i_d.di_gid;
869
870 switch (inode->i_mode & S_IFMT) {
871 case S_IFBLK:
872 case S_IFCHR:
873 inode->i_rdev =
874 MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
875 sysv_minor(ip->i_df.if_u2.if_rdev));
876 break;
877 default:
878 inode->i_rdev = 0;
879 break;
880 }
881
882 inode->i_generation = ip->i_d.di_gen;
883 i_size_write(inode, ip->i_d.di_size);
884 inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
885 inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
886 inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
887 inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
888 inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
889 inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
890 xfs_diflags_to_iflags(inode, ip);
891 xfs_iflags_clear(ip, XFS_IMODIFIED);
892
893 switch (inode->i_mode & S_IFMT) {
894 case S_IFREG:
895 inode->i_op = &xfs_inode_operations;
896 inode->i_fop = &xfs_file_operations;
897 inode->i_mapping->a_ops = &xfs_address_space_operations;
898 break;
899 case S_IFDIR:
900 if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
901 inode->i_op = &xfs_dir_ci_inode_operations;
902 else
903 inode->i_op = &xfs_dir_inode_operations;
904 inode->i_fop = &xfs_dir_file_operations;
905 break;
906 case S_IFLNK:
907 inode->i_op = &xfs_symlink_inode_operations;
908 if (!(ip->i_df.if_flags & XFS_IFINLINE))
909 inode->i_mapping->a_ops = &xfs_address_space_operations;
910 break;
911 default:
912 inode->i_op = &xfs_inode_operations;
913 init_special_inode(inode, inode->i_mode, inode->i_rdev);
914 break;
915 }
916
917 xfs_iflags_clear(ip, XFS_INEW);
918 barrier();
919
920 unlock_new_inode(inode);
921}