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