blob: 2903faf6a26a7ba6b5528ba818f4860ce82acbf8 [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 Hellwiga3da7892008-03-06 13:46:12 +1100370 struct inode *inode; /* inode of guy being linked to */
Barry Naujok556b8b12008-04-10 12:22:07 +1000371 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 int error;
373
Christoph Hellwiga3da7892008-03-06 13:46:12 +1100374 inode = old_dentry->d_inode;
Barry Naujok556b8b12008-04-10 12:22:07 +1000375 xfs_dentry_to_name(&name, dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Christoph Hellwiga3da7892008-03-06 13:46:12 +1100377 igrab(inode);
Barry Naujok556b8b12008-04-10 12:22:07 +1000378 error = xfs_link(XFS_I(dir), XFS_I(inode), &name);
Nathan Scott97dfd702006-06-27 16:13:46 +1000379 if (unlikely(error)) {
Christoph Hellwiga3da7892008-03-06 13:46:12 +1100380 iput(inode);
381 return -error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 }
Christoph Hellwiga3da7892008-03-06 13:46:12 +1100383
384 xfs_iflags_set(XFS_I(dir), XFS_IMODIFIED);
Christoph Hellwiga3da7892008-03-06 13:46:12 +1100385 d_instantiate(dentry, inode);
386 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387}
388
389STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100390xfs_vn_unlink(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 struct inode *dir,
392 struct dentry *dentry)
393{
Barry Naujok556b8b12008-04-10 12:22:07 +1000394 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 int error;
396
Barry Naujok556b8b12008-04-10 12:22:07 +1000397 xfs_dentry_to_name(&name, dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Christoph Hellwige5700702008-06-23 13:25:25 +1000399 error = -xfs_remove(XFS_I(dir), &name, XFS_I(dentry->d_inode));
400 if (error)
401 return error;
402
403 /*
404 * With unlink, the VFS makes the dentry "negative": no inode,
405 * but still hashed. This is incompatible with case-insensitive
406 * mode, so invalidate (unhash) the dentry in CI-mode.
407 */
408 if (xfs_sb_version_hasasciici(&XFS_M(dir->i_sb)->m_sb))
409 d_invalidate(dentry);
410 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
412
413STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100414xfs_vn_symlink(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 struct inode *dir,
416 struct dentry *dentry,
417 const char *symname)
418{
Christoph Hellwig3937be52008-03-06 13:46:19 +1100419 struct inode *inode;
420 struct xfs_inode *cip = NULL;
Barry Naujok556b8b12008-04-10 12:22:07 +1000421 struct xfs_name name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 int error;
Christoph Hellwig3e5daf02007-10-11 18:09:12 +1000423 mode_t mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Christoph Hellwig3e5daf02007-10-11 18:09:12 +1000425 mode = S_IFLNK |
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000426 (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO);
Barry Naujok556b8b12008-04-10 12:22:07 +1000427 xfs_dentry_to_name(&name, dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Barry Naujok556b8b12008-04-10 12:22:07 +1000429 error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip, NULL);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100430 if (unlikely(error))
431 goto out;
432
David Chinner01651642008-08-13 15:45:15 +1000433 inode = VFS_I(cip);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100434
435 error = xfs_init_security(inode, dir);
436 if (unlikely(error))
437 goto out_cleanup_inode;
438
439 d_instantiate(dentry, inode);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100440 return 0;
441
442 out_cleanup_inode:
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000443 xfs_cleanup_inode(dir, inode, dentry);
Christoph Hellwig3937be52008-03-06 13:46:19 +1100444 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 return -error;
446}
447
448STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100449xfs_vn_rename(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 struct inode *odir,
451 struct dentry *odentry,
452 struct inode *ndir,
453 struct dentry *ndentry)
454{
455 struct inode *new_inode = ndentry->d_inode;
Barry Naujok556b8b12008-04-10 12:22:07 +1000456 struct xfs_name oname;
457 struct xfs_name nname;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Barry Naujok556b8b12008-04-10 12:22:07 +1000459 xfs_dentry_to_name(&oname, odentry);
460 xfs_dentry_to_name(&nname, ndentry);
461
Christoph Hellwige5700702008-06-23 13:25:25 +1000462 return -xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode),
Christoph Hellwigcfa853e2008-04-22 17:34:06 +1000463 XFS_I(ndir), &nname, new_inode ?
464 XFS_I(new_inode) : NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465}
466
467/*
468 * careful here - this function can get called recursively, so
469 * we need to be very careful about how much stack we use.
470 * uio is kmalloced for this reason...
471 */
Al Viro008b1502005-08-20 00:17:39 +0100472STATIC void *
Nathan Scott416c6d52006-03-14 14:00:51 +1100473xfs_vn_follow_link(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 struct dentry *dentry,
475 struct nameidata *nd)
476{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 char *link;
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000478 int error = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Panagiotis Issarisf52720c2006-09-27 01:49:39 -0700480 link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000481 if (!link)
482 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000484 error = -xfs_readlink(XFS_I(dentry->d_inode), link);
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000485 if (unlikely(error))
486 goto out_kfree;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 nd_set_link(nd, link);
Al Viro008b1502005-08-20 00:17:39 +0100489 return NULL;
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000490
491 out_kfree:
492 kfree(link);
493 out_err:
494 nd_set_link(nd, ERR_PTR(error));
495 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496}
497
Nathan Scottcde410a2005-09-05 11:47:01 +1000498STATIC void
Nathan Scott416c6d52006-03-14 14:00:51 +1100499xfs_vn_put_link(
Nathan Scottcde410a2005-09-05 11:47:01 +1000500 struct dentry *dentry,
501 struct nameidata *nd,
502 void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
Nathan Scottcde410a2005-09-05 11:47:01 +1000504 char *s = nd_get_link(nd);
505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 if (!IS_ERR(s))
507 kfree(s);
508}
509
510#ifdef CONFIG_XFS_POSIX_ACL
511STATIC int
Christoph Hellwig45767582008-02-05 12:13:24 +1100512xfs_check_acl(
513 struct inode *inode,
514 int mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
Christoph Hellwig45767582008-02-05 12:13:24 +1100516 struct xfs_inode *ip = XFS_I(inode);
517 int error;
518
519 xfs_itrace_entry(ip);
520
521 if (XFS_IFORK_Q(ip)) {
522 error = xfs_acl_iaccess(ip, mask, NULL);
523 if (error != -1)
524 return -error;
525 }
526
527 return -EAGAIN;
528}
529
530STATIC int
531xfs_vn_permission(
532 struct inode *inode,
Al Viroe6305c42008-07-15 21:03:57 -0400533 int mask)
Christoph Hellwig45767582008-02-05 12:13:24 +1100534{
535 return generic_permission(inode, mask, xfs_check_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536}
537#else
Nathan Scott416c6d52006-03-14 14:00:51 +1100538#define xfs_vn_permission NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539#endif
540
541STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100542xfs_vn_getattr(
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000543 struct vfsmount *mnt,
544 struct dentry *dentry,
545 struct kstat *stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546{
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000547 struct inode *inode = dentry->d_inode;
548 struct xfs_inode *ip = XFS_I(inode);
549 struct xfs_mount *mp = ip->i_mount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000551 xfs_itrace_entry(ip);
552
553 if (XFS_FORCED_SHUTDOWN(mp))
554 return XFS_ERROR(EIO);
555
556 stat->size = XFS_ISIZE(ip);
557 stat->dev = inode->i_sb->s_dev;
558 stat->mode = ip->i_d.di_mode;
559 stat->nlink = ip->i_d.di_nlink;
560 stat->uid = ip->i_d.di_uid;
561 stat->gid = ip->i_d.di_gid;
562 stat->ino = ip->i_ino;
563#if XFS_BIG_INUMS
564 stat->ino += mp->m_inoadd;
565#endif
566 stat->atime = inode->i_atime;
567 stat->mtime.tv_sec = ip->i_d.di_mtime.t_sec;
568 stat->mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
569 stat->ctime.tv_sec = ip->i_d.di_ctime.t_sec;
570 stat->ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
571 stat->blocks =
572 XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
573
574
575 switch (inode->i_mode & S_IFMT) {
576 case S_IFBLK:
577 case S_IFCHR:
578 stat->blksize = BLKDEV_IOSIZE;
579 stat->rdev = MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
580 sysv_minor(ip->i_df.if_u2.if_rdev));
581 break;
582 default:
Eric Sandeen71ddabb2007-11-23 16:29:42 +1100583 if (XFS_IS_REALTIME_INODE(ip)) {
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000584 /*
585 * If the file blocks are being allocated from a
586 * realtime volume, then return the inode's realtime
587 * extent size or the realtime volume's extent size.
588 */
589 stat->blksize =
590 xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
591 } else
592 stat->blksize = xfs_preferred_iosize(mp);
593 stat->rdev = 0;
594 break;
Nathan Scott69e23b92006-09-28 11:01:22 +1000595 }
Christoph Hellwigc43f4082007-10-11 17:46:39 +1000596
597 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598}
599
600STATIC int
Nathan Scott416c6d52006-03-14 14:00:51 +1100601xfs_vn_setattr(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 struct dentry *dentry,
Christoph Hellwig0f285c82008-07-18 17:13:28 +1000603 struct iattr *iattr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
Christoph Hellwigea5a3dc82008-10-30 18:27:48 +1100605 return -xfs_setattr(XFS_I(dentry->d_inode), iattr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606}
607
David Chinnerd87dd632008-04-10 12:21:46 +1000608/*
609 * block_truncate_page can return an error, but we can't propagate it
610 * at all here. Leave a complaint + stack trace in the syslog because
611 * this could be bad. If it is bad, we need to propagate the error further.
612 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613STATIC void
Nathan Scott416c6d52006-03-14 14:00:51 +1100614xfs_vn_truncate(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 struct inode *inode)
616{
David Chinnerd87dd632008-04-10 12:21:46 +1000617 int error;
618 error = block_truncate_page(inode->i_mapping, inode->i_size,
619 xfs_get_blocks);
620 WARN_ON(error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621}
622
David Chinner3ed65262007-11-23 16:29:25 +1100623STATIC long
624xfs_vn_fallocate(
625 struct inode *inode,
626 int mode,
627 loff_t offset,
628 loff_t len)
629{
630 long error;
631 loff_t new_size = 0;
632 xfs_flock64_t bf;
633 xfs_inode_t *ip = XFS_I(inode);
634
635 /* preallocation on directories not yet supported */
636 error = -ENODEV;
637 if (S_ISDIR(inode->i_mode))
638 goto out_error;
639
640 bf.l_whence = 0;
641 bf.l_start = offset;
642 bf.l_len = len;
643
644 xfs_ilock(ip, XFS_IOLOCK_EXCL);
645 error = xfs_change_file_space(ip, XFS_IOC_RESVSP, &bf,
Christoph Hellwigea5a3dc82008-10-30 18:27:48 +1100646 0, XFS_ATTR_NOLOCK);
David Chinner3ed65262007-11-23 16:29:25 +1100647 if (!error && !(mode & FALLOC_FL_KEEP_SIZE) &&
648 offset + len > i_size_read(inode))
649 new_size = offset + len;
650
651 /* Change file size if needed */
652 if (new_size) {
Christoph Hellwig0f285c82008-07-18 17:13:28 +1000653 struct iattr iattr;
David Chinner3ed65262007-11-23 16:29:25 +1100654
Christoph Hellwig0f285c82008-07-18 17:13:28 +1000655 iattr.ia_valid = ATTR_SIZE;
656 iattr.ia_size = new_size;
Christoph Hellwigea5a3dc82008-10-30 18:27:48 +1100657 error = xfs_setattr(ip, &iattr, XFS_ATTR_NOLOCK);
David Chinner3ed65262007-11-23 16:29:25 +1100658 }
659
660 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
661out_error:
662 return error;
663}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Eric Sandeenf35642e2008-11-28 14:23:35 +1100665#define XFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR)
666
667/*
668 * Call fiemap helper to fill in user data.
669 * Returns positive errors to xfs_getbmap.
670 */
671STATIC int
672xfs_fiemap_format(
673 void **arg,
674 struct getbmapx *bmv,
675 int *full)
676{
677 int error;
678 struct fiemap_extent_info *fieinfo = *arg;
679 u32 fiemap_flags = 0;
680 u64 logical, physical, length;
681
682 /* Do nothing for a hole */
683 if (bmv->bmv_block == -1LL)
684 return 0;
685
686 logical = BBTOB(bmv->bmv_offset);
687 physical = BBTOB(bmv->bmv_block);
688 length = BBTOB(bmv->bmv_length);
689
690 if (bmv->bmv_oflags & BMV_OF_PREALLOC)
691 fiemap_flags |= FIEMAP_EXTENT_UNWRITTEN;
692 else if (bmv->bmv_oflags & BMV_OF_DELALLOC) {
693 fiemap_flags |= FIEMAP_EXTENT_DELALLOC;
694 physical = 0; /* no block yet */
695 }
696 if (bmv->bmv_oflags & BMV_OF_LAST)
697 fiemap_flags |= FIEMAP_EXTENT_LAST;
698
699 error = fiemap_fill_next_extent(fieinfo, logical, physical,
700 length, fiemap_flags);
701 if (error > 0) {
702 error = 0;
703 *full = 1; /* user array now full */
704 }
705
706 return -error;
707}
708
709STATIC int
710xfs_vn_fiemap(
711 struct inode *inode,
712 struct fiemap_extent_info *fieinfo,
713 u64 start,
714 u64 length)
715{
716 xfs_inode_t *ip = XFS_I(inode);
717 struct getbmapx bm;
718 int error;
719
720 error = fiemap_check_flags(fieinfo, XFS_FIEMAP_FLAGS);
721 if (error)
722 return error;
723
724 /* Set up bmap header for xfs internal routine */
725 bm.bmv_offset = BTOBB(start);
726 /* Special case for whole file */
727 if (length == FIEMAP_MAX_OFFSET)
728 bm.bmv_length = -1LL;
729 else
730 bm.bmv_length = BTOBB(length);
731
732 /* our formatter will tell xfs_getbmap when to stop. */
733 bm.bmv_count = MAXEXTNUM;
734 bm.bmv_iflags = BMV_IF_PREALLOC;
735 if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR)
736 bm.bmv_iflags |= BMV_IF_ATTRFORK;
737 if (!(fieinfo->fi_flags & FIEMAP_FLAG_SYNC))
738 bm.bmv_iflags |= BMV_IF_DELALLOC;
739
740 error = xfs_getbmap(ip, &bm, xfs_fiemap_format, fieinfo);
741 if (error)
742 return -error;
743
744 return 0;
745}
746
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000747static const struct inode_operations xfs_inode_operations = {
Nathan Scott416c6d52006-03-14 14:00:51 +1100748 .permission = xfs_vn_permission,
749 .truncate = xfs_vn_truncate,
750 .getattr = xfs_vn_getattr,
751 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +1000752 .setxattr = generic_setxattr,
753 .getxattr = generic_getxattr,
754 .removexattr = generic_removexattr,
Nathan Scott416c6d52006-03-14 14:00:51 +1100755 .listxattr = xfs_vn_listxattr,
David Chinner3ed65262007-11-23 16:29:25 +1100756 .fallocate = xfs_vn_fallocate,
Eric Sandeenf35642e2008-11-28 14:23:35 +1100757 .fiemap = xfs_vn_fiemap,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758};
759
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000760static const struct inode_operations xfs_dir_inode_operations = {
Nathan Scott416c6d52006-03-14 14:00:51 +1100761 .create = xfs_vn_create,
762 .lookup = xfs_vn_lookup,
763 .link = xfs_vn_link,
764 .unlink = xfs_vn_unlink,
765 .symlink = xfs_vn_symlink,
766 .mkdir = xfs_vn_mkdir,
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000767 /*
768 * Yes, XFS uses the same method for rmdir and unlink.
769 *
770 * There are some subtile differences deeper in the code,
771 * but we use S_ISDIR to check for those.
772 */
773 .rmdir = xfs_vn_unlink,
Nathan Scott416c6d52006-03-14 14:00:51 +1100774 .mknod = xfs_vn_mknod,
775 .rename = xfs_vn_rename,
776 .permission = xfs_vn_permission,
777 .getattr = xfs_vn_getattr,
778 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +1000779 .setxattr = generic_setxattr,
780 .getxattr = generic_getxattr,
781 .removexattr = generic_removexattr,
Nathan Scott416c6d52006-03-14 14:00:51 +1100782 .listxattr = xfs_vn_listxattr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783};
784
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000785static const struct inode_operations xfs_dir_ci_inode_operations = {
Barry Naujok384f3ce2008-05-21 16:58:22 +1000786 .create = xfs_vn_create,
787 .lookup = xfs_vn_ci_lookup,
788 .link = xfs_vn_link,
789 .unlink = xfs_vn_unlink,
790 .symlink = xfs_vn_symlink,
791 .mkdir = xfs_vn_mkdir,
Christoph Hellwig8f112e32008-06-23 13:25:17 +1000792 /*
793 * Yes, XFS uses the same method for rmdir and unlink.
794 *
795 * There are some subtile differences deeper in the code,
796 * but we use S_ISDIR to check for those.
797 */
798 .rmdir = xfs_vn_unlink,
Barry Naujok384f3ce2008-05-21 16:58:22 +1000799 .mknod = xfs_vn_mknod,
800 .rename = xfs_vn_rename,
801 .permission = xfs_vn_permission,
802 .getattr = xfs_vn_getattr,
803 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +1000804 .setxattr = generic_setxattr,
805 .getxattr = generic_getxattr,
806 .removexattr = generic_removexattr,
Barry Naujok384f3ce2008-05-21 16:58:22 +1000807 .listxattr = xfs_vn_listxattr,
Barry Naujok384f3ce2008-05-21 16:58:22 +1000808};
809
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000810static const struct inode_operations xfs_symlink_inode_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 .readlink = generic_readlink,
Nathan Scott416c6d52006-03-14 14:00:51 +1100812 .follow_link = xfs_vn_follow_link,
813 .put_link = xfs_vn_put_link,
814 .permission = xfs_vn_permission,
815 .getattr = xfs_vn_getattr,
816 .setattr = xfs_vn_setattr,
Lachlan McIlroy0ec58512008-06-23 13:23:01 +1000817 .setxattr = generic_setxattr,
818 .getxattr = generic_getxattr,
819 .removexattr = generic_removexattr,
Nathan Scott416c6d52006-03-14 14:00:51 +1100820 .listxattr = xfs_vn_listxattr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821};
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000822
823STATIC void
824xfs_diflags_to_iflags(
825 struct inode *inode,
826 struct xfs_inode *ip)
827{
828 if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
829 inode->i_flags |= S_IMMUTABLE;
830 else
831 inode->i_flags &= ~S_IMMUTABLE;
832 if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
833 inode->i_flags |= S_APPEND;
834 else
835 inode->i_flags &= ~S_APPEND;
836 if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
837 inode->i_flags |= S_SYNC;
838 else
839 inode->i_flags &= ~S_SYNC;
840 if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
841 inode->i_flags |= S_NOATIME;
842 else
843 inode->i_flags &= ~S_NOATIME;
844}
845
846/*
847 * Initialize the Linux inode, set up the operation vectors and
848 * unlock the inode.
849 *
850 * When reading existing inodes from disk this is called directly
851 * from xfs_iget, when creating a new inode it is called from
852 * xfs_ialloc after setting up the inode.
David Chinnerbf904242008-10-30 17:36:14 +1100853 *
854 * We are always called with an uninitialised linux inode here.
855 * We need to initialise the necessary fields and take a reference
856 * on it.
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000857 */
858void
859xfs_setup_inode(
860 struct xfs_inode *ip)
861{
David Chinnerbf904242008-10-30 17:36:14 +1100862 struct inode *inode = &ip->i_vnode;
863
864 inode->i_ino = ip->i_ino;
865 inode->i_state = I_NEW|I_LOCK;
866 inode_add_to_lists(ip->i_mount->m_super, inode);
Christoph Hellwig41be8be2008-08-13 16:23:13 +1000867
868 inode->i_mode = ip->i_d.di_mode;
869 inode->i_nlink = ip->i_d.di_nlink;
870 inode->i_uid = ip->i_d.di_uid;
871 inode->i_gid = ip->i_d.di_gid;
872
873 switch (inode->i_mode & S_IFMT) {
874 case S_IFBLK:
875 case S_IFCHR:
876 inode->i_rdev =
877 MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
878 sysv_minor(ip->i_df.if_u2.if_rdev));
879 break;
880 default:
881 inode->i_rdev = 0;
882 break;
883 }
884
885 inode->i_generation = ip->i_d.di_gen;
886 i_size_write(inode, ip->i_d.di_size);
887 inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
888 inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
889 inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
890 inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
891 inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
892 inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
893 xfs_diflags_to_iflags(inode, ip);
894 xfs_iflags_clear(ip, XFS_IMODIFIED);
895
896 switch (inode->i_mode & S_IFMT) {
897 case S_IFREG:
898 inode->i_op = &xfs_inode_operations;
899 inode->i_fop = &xfs_file_operations;
900 inode->i_mapping->a_ops = &xfs_address_space_operations;
901 break;
902 case S_IFDIR:
903 if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
904 inode->i_op = &xfs_dir_ci_inode_operations;
905 else
906 inode->i_op = &xfs_dir_inode_operations;
907 inode->i_fop = &xfs_dir_file_operations;
908 break;
909 case S_IFLNK:
910 inode->i_op = &xfs_symlink_inode_operations;
911 if (!(ip->i_df.if_flags & XFS_IFINLINE))
912 inode->i_mapping->a_ops = &xfs_address_space_operations;
913 break;
914 default:
915 inode->i_op = &xfs_inode_operations;
916 init_special_inode(inode, inode->i_mode, inode->i_rdev);
917 break;
918 }
919
920 xfs_iflags_clear(ip, XFS_INEW);
921 barrier();
922
923 unlock_new_inode(inode);
924}