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" |
| 49 | |
Randy Dunlap | 16f7e0f | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 50 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/xattr.h> |
| 52 | #include <linux/namei.h> |
Nathan Scott | 446ada4 | 2006-01-11 15:35:44 +1100 | [diff] [blame] | 53 | #include <linux/security.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Nathan Scott | 4aeb664 | 2005-11-02 11:43:58 +1100 | [diff] [blame] | 55 | /* |
Christoph Hellwig | 75e17b3 | 2006-01-11 20:58:44 +1100 | [diff] [blame] | 56 | * Get a XFS inode from a given vnode. |
| 57 | */ |
| 58 | xfs_inode_t * |
| 59 | xfs_vtoi( |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 60 | bhv_vnode_t *vp) |
Christoph Hellwig | 75e17b3 | 2006-01-11 20:58:44 +1100 | [diff] [blame] | 61 | { |
| 62 | bhv_desc_t *bdp; |
| 63 | |
| 64 | bdp = bhv_lookup_range(VN_BHV_HEAD(vp), |
| 65 | VNODE_POSITION_XFS, VNODE_POSITION_XFS); |
| 66 | if (unlikely(bdp == NULL)) |
| 67 | return NULL; |
| 68 | return XFS_BHVTOI(bdp); |
| 69 | } |
| 70 | |
| 71 | /* |
Christoph Hellwig | 42fe2b1 | 2006-01-11 15:35:17 +1100 | [diff] [blame] | 72 | * Bring the atime in the XFS inode uptodate. |
| 73 | * Used before logging the inode to disk or when the Linux inode goes away. |
| 74 | */ |
| 75 | void |
| 76 | xfs_synchronize_atime( |
| 77 | xfs_inode_t *ip) |
| 78 | { |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 79 | bhv_vnode_t *vp; |
Christoph Hellwig | 42fe2b1 | 2006-01-11 15:35:17 +1100 | [diff] [blame] | 80 | |
| 81 | vp = XFS_ITOV_NULL(ip); |
| 82 | if (vp) { |
| 83 | struct inode *inode = &vp->v_inode; |
| 84 | ip->i_d.di_atime.t_sec = (__int32_t)inode->i_atime.tv_sec; |
| 85 | ip->i_d.di_atime.t_nsec = (__int32_t)inode->i_atime.tv_nsec; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | /* |
Nathan Scott | 4aeb664 | 2005-11-02 11:43:58 +1100 | [diff] [blame] | 90 | * 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. |
| 93 | * |
| 94 | * NOTE -- callers MUST combine XFS_ICHGTIME_MOD or XFS_ICHGTIME_CHG |
| 95 | * with XFS_ICHGTIME_ACC to be sure that access time |
| 96 | * update will take. Calling first with XFS_ICHGTIME_ACC |
| 97 | * and then XFS_ICHGTIME_MOD may fail to modify the access |
| 98 | * timestamp if the filesystem is mounted noacctm. |
| 99 | */ |
| 100 | void |
| 101 | xfs_ichgtime( |
| 102 | xfs_inode_t *ip, |
| 103 | int flags) |
| 104 | { |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 105 | struct inode *inode = vn_to_inode(XFS_ITOV(ip)); |
Nathan Scott | 4aeb664 | 2005-11-02 11:43:58 +1100 | [diff] [blame] | 106 | timespec_t tv; |
| 107 | |
Nathan Scott | 4aeb664 | 2005-11-02 11:43:58 +1100 | [diff] [blame] | 108 | nanotime(&tv); |
| 109 | if (flags & XFS_ICHGTIME_MOD) { |
| 110 | inode->i_mtime = tv; |
| 111 | ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec; |
| 112 | ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec; |
| 113 | } |
| 114 | if (flags & XFS_ICHGTIME_ACC) { |
| 115 | inode->i_atime = tv; |
| 116 | ip->i_d.di_atime.t_sec = (__int32_t)tv.tv_sec; |
| 117 | ip->i_d.di_atime.t_nsec = (__int32_t)tv.tv_nsec; |
| 118 | } |
| 119 | if (flags & XFS_ICHGTIME_CHG) { |
| 120 | inode->i_ctime = tv; |
| 121 | ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec; |
| 122 | ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec; |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | * We update the i_update_core field _after_ changing |
| 127 | * the timestamps in order to coordinate properly with |
| 128 | * xfs_iflush() so that we don't lose timestamp updates. |
| 129 | * This keeps us from having to hold the inode lock |
| 130 | * while doing this. We use the SYNCHRONIZE macro to |
| 131 | * ensure that the compiler does not reorder the update |
| 132 | * of i_update_core above the timestamp updates above. |
| 133 | */ |
| 134 | SYNCHRONIZE(); |
| 135 | ip->i_update_core = 1; |
| 136 | if (!(inode->i_state & I_LOCK)) |
| 137 | mark_inode_dirty_sync(inode); |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * Variant on the above which avoids querying the system clock |
| 142 | * in situations where we know the Linux inode timestamps have |
| 143 | * just been updated (and so we can update our inode cheaply). |
Nathan Scott | 4aeb664 | 2005-11-02 11:43:58 +1100 | [diff] [blame] | 144 | */ |
| 145 | void |
| 146 | xfs_ichgtime_fast( |
| 147 | xfs_inode_t *ip, |
| 148 | struct inode *inode, |
| 149 | int flags) |
| 150 | { |
| 151 | timespec_t *tvp; |
| 152 | |
| 153 | /* |
Christoph Hellwig | 42fe2b1 | 2006-01-11 15:35:17 +1100 | [diff] [blame] | 154 | * Atime updates for read() & friends are handled lazily now, and |
| 155 | * explicit updates must go through xfs_ichgtime() |
| 156 | */ |
| 157 | ASSERT((flags & XFS_ICHGTIME_ACC) == 0); |
| 158 | |
| 159 | /* |
Nathan Scott | 4aeb664 | 2005-11-02 11:43:58 +1100 | [diff] [blame] | 160 | * We're not supposed to change timestamps in readonly-mounted |
| 161 | * filesystems. Throw it away if anyone asks us. |
| 162 | */ |
| 163 | if (unlikely(IS_RDONLY(inode))) |
| 164 | return; |
| 165 | |
Nathan Scott | 4aeb664 | 2005-11-02 11:43:58 +1100 | [diff] [blame] | 166 | if (flags & XFS_ICHGTIME_MOD) { |
| 167 | tvp = &inode->i_mtime; |
| 168 | ip->i_d.di_mtime.t_sec = (__int32_t)tvp->tv_sec; |
| 169 | ip->i_d.di_mtime.t_nsec = (__int32_t)tvp->tv_nsec; |
| 170 | } |
Nathan Scott | 4aeb664 | 2005-11-02 11:43:58 +1100 | [diff] [blame] | 171 | if (flags & XFS_ICHGTIME_CHG) { |
| 172 | tvp = &inode->i_ctime; |
| 173 | ip->i_d.di_ctime.t_sec = (__int32_t)tvp->tv_sec; |
| 174 | ip->i_d.di_ctime.t_nsec = (__int32_t)tvp->tv_nsec; |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * We update the i_update_core field _after_ changing |
| 179 | * the timestamps in order to coordinate properly with |
| 180 | * xfs_iflush() so that we don't lose timestamp updates. |
| 181 | * This keeps us from having to hold the inode lock |
| 182 | * while doing this. We use the SYNCHRONIZE macro to |
| 183 | * ensure that the compiler does not reorder the update |
| 184 | * of i_update_core above the timestamp updates above. |
| 185 | */ |
| 186 | SYNCHRONIZE(); |
| 187 | ip->i_update_core = 1; |
| 188 | if (!(inode->i_state & I_LOCK)) |
| 189 | mark_inode_dirty_sync(inode); |
| 190 | } |
| 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | /* |
| 194 | * Pull the link count and size up from the xfs inode to the linux inode |
| 195 | */ |
| 196 | STATIC void |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 197 | xfs_validate_fields( |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 198 | struct inode *ip, |
Nathan Scott | 8285fb5 | 2006-06-09 17:07:12 +1000 | [diff] [blame] | 199 | bhv_vattr_t *vattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | { |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 201 | vattr->va_mask = XFS_AT_NLINK|XFS_AT_SIZE|XFS_AT_NBLOCKS; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 202 | if (!bhv_vop_getattr(vn_from_inode(ip), vattr, ATTR_LAZY, NULL)) { |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 203 | ip->i_nlink = vattr->va_nlink; |
| 204 | ip->i_blocks = vattr->va_nblocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 206 | /* we're under i_sem so i_size can't change under us */ |
| 207 | if (i_size_read(ip) != vattr->va_size) |
| 208 | i_size_write(ip, vattr->va_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
| 212 | /* |
Nathan Scott | 446ada4 | 2006-01-11 15:35:44 +1100 | [diff] [blame] | 213 | * Hook in SELinux. This is not quite correct yet, what we really need |
| 214 | * here (as we do for default ACLs) is a mechanism by which creation of |
| 215 | * these attrs can be journalled at inode creation time (along with the |
| 216 | * inode, of course, such that log replay can't cause these to be lost). |
| 217 | */ |
| 218 | STATIC int |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 219 | xfs_init_security( |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 220 | bhv_vnode_t *vp, |
Nathan Scott | 446ada4 | 2006-01-11 15:35:44 +1100 | [diff] [blame] | 221 | struct inode *dir) |
| 222 | { |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 223 | struct inode *ip = vn_to_inode(vp); |
Nathan Scott | 446ada4 | 2006-01-11 15:35:44 +1100 | [diff] [blame] | 224 | size_t length; |
| 225 | void *value; |
| 226 | char *name; |
| 227 | int error; |
| 228 | |
| 229 | error = security_inode_init_security(ip, dir, &name, &value, &length); |
| 230 | if (error) { |
| 231 | if (error == -EOPNOTSUPP) |
| 232 | return 0; |
| 233 | return -error; |
| 234 | } |
| 235 | |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 236 | error = bhv_vop_attr_set(vp, name, value, length, ATTR_SECURE, NULL); |
Nathan Scott | 446ada4 | 2006-01-11 15:35:44 +1100 | [diff] [blame] | 237 | if (!error) |
| 238 | VMODIFY(vp); |
| 239 | |
| 240 | kfree(name); |
| 241 | kfree(value); |
| 242 | return error; |
| 243 | } |
| 244 | |
| 245 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | * Determine whether a process has a valid fs_struct (kernel daemons |
| 247 | * like knfsd don't have an fs_struct). |
| 248 | * |
| 249 | * XXX(hch): nfsd is broken, better fix it instead. |
| 250 | */ |
David Chinner | 7989cb8 | 2007-02-10 18:34:56 +1100 | [diff] [blame] | 251 | STATIC_INLINE int |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 252 | xfs_has_fs_struct(struct task_struct *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { |
| 254 | return (task->fs != init_task.fs); |
| 255 | } |
| 256 | |
David Chinner | 7989cb8 | 2007-02-10 18:34:56 +1100 | [diff] [blame] | 257 | STATIC void |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 258 | xfs_cleanup_inode( |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 259 | bhv_vnode_t *dvp, |
| 260 | bhv_vnode_t *vp, |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 261 | struct dentry *dentry, |
Yingping Lu | 3a69c7d | 2006-02-01 12:14:34 +1100 | [diff] [blame] | 262 | int mode) |
| 263 | { |
| 264 | struct dentry teardown = {}; |
Yingping Lu | 3a69c7d | 2006-02-01 12:14:34 +1100 | [diff] [blame] | 265 | |
| 266 | /* Oh, the horror. |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 267 | * If we can't add the ACL or we fail in |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 268 | * xfs_init_security we must back out. |
Yingping Lu | 3a69c7d | 2006-02-01 12:14:34 +1100 | [diff] [blame] | 269 | * ENOSPC can hit here, among other things. |
| 270 | */ |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 271 | teardown.d_inode = vn_to_inode(vp); |
Yingping Lu | 3a69c7d | 2006-02-01 12:14:34 +1100 | [diff] [blame] | 272 | teardown.d_name = dentry->d_name; |
| 273 | |
| 274 | if (S_ISDIR(mode)) |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 275 | bhv_vop_rmdir(dvp, &teardown, NULL); |
Yingping Lu | 3a69c7d | 2006-02-01 12:14:34 +1100 | [diff] [blame] | 276 | else |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 277 | bhv_vop_remove(dvp, &teardown, NULL); |
Yingping Lu | 3a69c7d | 2006-02-01 12:14:34 +1100 | [diff] [blame] | 278 | VN_RELE(vp); |
| 279 | } |
| 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | STATIC int |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 282 | xfs_vn_mknod( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | struct inode *dir, |
| 284 | struct dentry *dentry, |
| 285 | int mode, |
| 286 | dev_t rdev) |
| 287 | { |
| 288 | struct inode *ip; |
Nathan Scott | 8285fb5 | 2006-06-09 17:07:12 +1000 | [diff] [blame] | 289 | bhv_vattr_t vattr = { 0 }; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 290 | bhv_vnode_t *vp = NULL, *dvp = vn_from_inode(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | xfs_acl_t *default_acl = NULL; |
| 292 | attrexists_t test_default_acl = _ACL_DEFAULT_EXISTS; |
| 293 | int error; |
| 294 | |
| 295 | /* |
| 296 | * Irix uses Missed'em'V split, but doesn't want to see |
| 297 | * the upper 5 bits of (14bit) major. |
| 298 | */ |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 299 | if (unlikely(!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | return -EINVAL; |
| 301 | |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 302 | if (unlikely(test_default_acl && test_default_acl(dvp))) { |
| 303 | if (!_ACL_ALLOC(default_acl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | return -ENOMEM; |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | if (!_ACL_GET_DEFAULT(dvp, default_acl)) { |
| 307 | _ACL_FREE(default_acl); |
| 308 | default_acl = NULL; |
| 309 | } |
| 310 | } |
| 311 | |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 312 | if (IS_POSIXACL(dir) && !default_acl && xfs_has_fs_struct(current)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | mode &= ~current->fs->umask; |
| 314 | |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 315 | vattr.va_mask = XFS_AT_TYPE|XFS_AT_MODE; |
| 316 | vattr.va_mode = mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
| 318 | switch (mode & S_IFMT) { |
| 319 | case S_IFCHR: case S_IFBLK: case S_IFIFO: case S_IFSOCK: |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 320 | vattr.va_rdev = sysv_encode_dev(rdev); |
| 321 | vattr.va_mask |= XFS_AT_RDEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | /*FALLTHROUGH*/ |
| 323 | case S_IFREG: |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 324 | error = bhv_vop_create(dvp, dentry, &vattr, &vp, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | break; |
| 326 | case S_IFDIR: |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 327 | error = bhv_vop_mkdir(dvp, dentry, &vattr, &vp, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | break; |
| 329 | default: |
| 330 | error = EINVAL; |
| 331 | break; |
| 332 | } |
| 333 | |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 334 | if (unlikely(!error)) { |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 335 | error = xfs_init_security(vp, dir); |
Yingping Lu | 3a69c7d | 2006-02-01 12:14:34 +1100 | [diff] [blame] | 336 | if (error) |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 337 | xfs_cleanup_inode(dvp, vp, dentry, mode); |
Yingping Lu | 3a69c7d | 2006-02-01 12:14:34 +1100 | [diff] [blame] | 338 | } |
Nathan Scott | 446ada4 | 2006-01-11 15:35:44 +1100 | [diff] [blame] | 339 | |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 340 | if (unlikely(default_acl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | if (!error) { |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 342 | error = _ACL_INHERIT(vp, &vattr, default_acl); |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 343 | if (!error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | VMODIFY(vp); |
Yingping Lu | 3a69c7d | 2006-02-01 12:14:34 +1100 | [diff] [blame] | 345 | else |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 346 | xfs_cleanup_inode(dvp, vp, dentry, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | _ACL_FREE(default_acl); |
| 349 | } |
| 350 | |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 351 | if (likely(!error)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | ASSERT(vp); |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 353 | ip = vn_to_inode(vp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | if (S_ISCHR(mode) || S_ISBLK(mode)) |
| 356 | ip->i_rdev = rdev; |
| 357 | else if (S_ISDIR(mode)) |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 358 | xfs_validate_fields(ip, &vattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | d_instantiate(dentry, ip); |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 360 | xfs_validate_fields(dir, &vattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | return -error; |
| 363 | } |
| 364 | |
| 365 | STATIC int |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 366 | xfs_vn_create( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | struct inode *dir, |
| 368 | struct dentry *dentry, |
| 369 | int mode, |
| 370 | struct nameidata *nd) |
| 371 | { |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 372 | return xfs_vn_mknod(dir, dentry, mode, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | STATIC int |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 376 | xfs_vn_mkdir( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | struct inode *dir, |
| 378 | struct dentry *dentry, |
| 379 | int mode) |
| 380 | { |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 381 | return xfs_vn_mknod(dir, dentry, mode|S_IFDIR, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | STATIC struct dentry * |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 385 | xfs_vn_lookup( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | struct inode *dir, |
| 387 | struct dentry *dentry, |
| 388 | struct nameidata *nd) |
| 389 | { |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 390 | bhv_vnode_t *vp = vn_from_inode(dir), *cvp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | int error; |
| 392 | |
| 393 | if (dentry->d_name.len >= MAXNAMELEN) |
| 394 | return ERR_PTR(-ENAMETOOLONG); |
| 395 | |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 396 | error = bhv_vop_lookup(vp, dentry, &cvp, 0, NULL, NULL); |
| 397 | if (unlikely(error)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | if (unlikely(error != ENOENT)) |
| 399 | return ERR_PTR(-error); |
| 400 | d_add(dentry, NULL); |
| 401 | return NULL; |
| 402 | } |
| 403 | |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 404 | return d_splice_alias(vn_to_inode(cvp), dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | STATIC int |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 408 | xfs_vn_link( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | struct dentry *old_dentry, |
| 410 | struct inode *dir, |
| 411 | struct dentry *dentry) |
| 412 | { |
| 413 | struct inode *ip; /* inode of guy being linked to */ |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 414 | bhv_vnode_t *tdvp; /* target directory for new name/link */ |
| 415 | bhv_vnode_t *vp; /* vp of name being linked */ |
Nathan Scott | 8285fb5 | 2006-06-09 17:07:12 +1000 | [diff] [blame] | 416 | bhv_vattr_t vattr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | int error; |
| 418 | |
| 419 | ip = old_dentry->d_inode; /* inode being linked to */ |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 420 | tdvp = vn_from_inode(dir); |
| 421 | vp = vn_from_inode(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Nathan Scott | 97dfd70 | 2006-06-27 16:13:46 +1000 | [diff] [blame] | 423 | VN_HOLD(vp); |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 424 | error = bhv_vop_link(tdvp, vp, dentry, NULL); |
Nathan Scott | 97dfd70 | 2006-06-27 16:13:46 +1000 | [diff] [blame] | 425 | if (unlikely(error)) { |
| 426 | VN_RELE(vp); |
| 427 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | VMODIFY(tdvp); |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 429 | xfs_validate_fields(ip, &vattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | d_instantiate(dentry, ip); |
| 431 | } |
| 432 | return -error; |
| 433 | } |
| 434 | |
| 435 | STATIC int |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 436 | xfs_vn_unlink( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | struct inode *dir, |
| 438 | struct dentry *dentry) |
| 439 | { |
| 440 | struct inode *inode; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 441 | bhv_vnode_t *dvp; /* directory containing name to remove */ |
Nathan Scott | 8285fb5 | 2006-06-09 17:07:12 +1000 | [diff] [blame] | 442 | bhv_vattr_t vattr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | int error; |
| 444 | |
| 445 | inode = dentry->d_inode; |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 446 | dvp = vn_from_inode(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 448 | error = bhv_vop_remove(dvp, dentry, NULL); |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 449 | if (likely(!error)) { |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 450 | xfs_validate_fields(dir, &vattr); /* size needs update */ |
| 451 | xfs_validate_fields(inode, &vattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | return -error; |
| 454 | } |
| 455 | |
| 456 | STATIC int |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 457 | xfs_vn_symlink( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | struct inode *dir, |
| 459 | struct dentry *dentry, |
| 460 | const char *symname) |
| 461 | { |
| 462 | struct inode *ip; |
Nathan Scott | 8285fb5 | 2006-06-09 17:07:12 +1000 | [diff] [blame] | 463 | bhv_vattr_t va = { 0 }; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 464 | bhv_vnode_t *dvp; /* directory containing name of symlink */ |
| 465 | bhv_vnode_t *cvp; /* used to lookup symlink to put in dentry */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | int error; |
| 467 | |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 468 | dvp = vn_from_inode(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | cvp = NULL; |
| 470 | |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 471 | va.va_mode = S_IFLNK | |
Christoph Hellwig | 0432dab | 2005-09-02 16:46:51 +1000 | [diff] [blame] | 472 | (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO); |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 473 | va.va_mask = XFS_AT_TYPE|XFS_AT_MODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 475 | error = bhv_vop_symlink(dvp, dentry, &va, (char *)symname, &cvp, NULL); |
Nathan Scott | 5424570 | 2006-01-16 15:54:05 +1100 | [diff] [blame] | 476 | if (likely(!error && cvp)) { |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 477 | error = xfs_init_security(cvp, dir); |
Nathan Scott | 5424570 | 2006-01-16 15:54:05 +1100 | [diff] [blame] | 478 | if (likely(!error)) { |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 479 | ip = vn_to_inode(cvp); |
Nathan Scott | 5424570 | 2006-01-16 15:54:05 +1100 | [diff] [blame] | 480 | d_instantiate(dentry, ip); |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 481 | xfs_validate_fields(dir, &va); |
| 482 | xfs_validate_fields(ip, &va); |
Nathan Scott | ce9d37c | 2006-03-17 17:26:34 +1100 | [diff] [blame] | 483 | } else { |
| 484 | xfs_cleanup_inode(dvp, cvp, dentry, 0); |
Nathan Scott | 5424570 | 2006-01-16 15:54:05 +1100 | [diff] [blame] | 485 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | } |
| 487 | return -error; |
| 488 | } |
| 489 | |
| 490 | STATIC int |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 491 | xfs_vn_rmdir( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | struct inode *dir, |
| 493 | struct dentry *dentry) |
| 494 | { |
| 495 | struct inode *inode = dentry->d_inode; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 496 | bhv_vnode_t *dvp = vn_from_inode(dir); |
Nathan Scott | 8285fb5 | 2006-06-09 17:07:12 +1000 | [diff] [blame] | 497 | bhv_vattr_t vattr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | int error; |
| 499 | |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 500 | error = bhv_vop_rmdir(dvp, dentry, NULL); |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 501 | if (likely(!error)) { |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 502 | xfs_validate_fields(inode, &vattr); |
| 503 | xfs_validate_fields(dir, &vattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | } |
| 505 | return -error; |
| 506 | } |
| 507 | |
| 508 | STATIC int |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 509 | xfs_vn_rename( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | struct inode *odir, |
| 511 | struct dentry *odentry, |
| 512 | struct inode *ndir, |
| 513 | struct dentry *ndentry) |
| 514 | { |
| 515 | struct inode *new_inode = ndentry->d_inode; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 516 | bhv_vnode_t *fvp; /* from directory */ |
| 517 | bhv_vnode_t *tvp; /* target directory */ |
Nathan Scott | 8285fb5 | 2006-06-09 17:07:12 +1000 | [diff] [blame] | 518 | bhv_vattr_t vattr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | int error; |
| 520 | |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 521 | fvp = vn_from_inode(odir); |
| 522 | tvp = vn_from_inode(ndir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 524 | error = bhv_vop_rename(fvp, odentry, tvp, ndentry, NULL); |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 525 | if (likely(!error)) { |
| 526 | if (new_inode) |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 527 | xfs_validate_fields(new_inode, &vattr); |
| 528 | xfs_validate_fields(odir, &vattr); |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 529 | if (ndir != odir) |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 530 | xfs_validate_fields(ndir, &vattr); |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 531 | } |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 532 | return -error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | /* |
| 536 | * careful here - this function can get called recursively, so |
| 537 | * we need to be very careful about how much stack we use. |
| 538 | * uio is kmalloced for this reason... |
| 539 | */ |
Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 540 | STATIC void * |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 541 | xfs_vn_follow_link( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | struct dentry *dentry, |
| 543 | struct nameidata *nd) |
| 544 | { |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 545 | bhv_vnode_t *vp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | uio_t *uio; |
| 547 | iovec_t iov; |
| 548 | int error; |
| 549 | char *link; |
| 550 | |
| 551 | ASSERT(dentry); |
| 552 | ASSERT(nd); |
| 553 | |
Panagiotis Issaris | f52720c | 2006-09-27 01:49:39 -0700 | [diff] [blame] | 554 | link = kmalloc(MAXPATHLEN+1, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | if (!link) { |
| 556 | nd_set_link(nd, ERR_PTR(-ENOMEM)); |
Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 557 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Panagiotis Issaris | f52720c | 2006-09-27 01:49:39 -0700 | [diff] [blame] | 560 | uio = kmalloc(sizeof(uio_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | if (!uio) { |
| 562 | kfree(link); |
| 563 | nd_set_link(nd, ERR_PTR(-ENOMEM)); |
Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 564 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 567 | vp = vn_from_inode(dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
| 569 | iov.iov_base = link; |
Nathan Scott | 0d1335b | 2006-01-12 10:32:51 +1100 | [diff] [blame] | 570 | iov.iov_len = MAXPATHLEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
| 572 | uio->uio_iov = &iov; |
| 573 | uio->uio_offset = 0; |
| 574 | uio->uio_segflg = UIO_SYSSPACE; |
Nathan Scott | 0d1335b | 2006-01-12 10:32:51 +1100 | [diff] [blame] | 575 | uio->uio_resid = MAXPATHLEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | uio->uio_iovcnt = 1; |
| 577 | |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 578 | error = bhv_vop_readlink(vp, uio, 0, NULL); |
| 579 | if (unlikely(error)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | kfree(link); |
| 581 | link = ERR_PTR(-error); |
| 582 | } else { |
Nathan Scott | 0d1335b | 2006-01-12 10:32:51 +1100 | [diff] [blame] | 583 | link[MAXPATHLEN - uio->uio_resid] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | } |
| 585 | kfree(uio); |
| 586 | |
| 587 | nd_set_link(nd, link); |
Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 588 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Nathan Scott | cde410a | 2005-09-05 11:47:01 +1000 | [diff] [blame] | 591 | STATIC void |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 592 | xfs_vn_put_link( |
Nathan Scott | cde410a | 2005-09-05 11:47:01 +1000 | [diff] [blame] | 593 | struct dentry *dentry, |
| 594 | struct nameidata *nd, |
| 595 | void *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | { |
Nathan Scott | cde410a | 2005-09-05 11:47:01 +1000 | [diff] [blame] | 597 | char *s = nd_get_link(nd); |
| 598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | if (!IS_ERR(s)) |
| 600 | kfree(s); |
| 601 | } |
| 602 | |
| 603 | #ifdef CONFIG_XFS_POSIX_ACL |
| 604 | STATIC int |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 605 | xfs_vn_permission( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | struct inode *inode, |
| 607 | int mode, |
| 608 | struct nameidata *nd) |
| 609 | { |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 610 | return -bhv_vop_access(vn_from_inode(inode), mode << 6, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | } |
| 612 | #else |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 613 | #define xfs_vn_permission NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | #endif |
| 615 | |
| 616 | STATIC int |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 617 | xfs_vn_getattr( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | struct vfsmount *mnt, |
| 619 | struct dentry *dentry, |
| 620 | struct kstat *stat) |
| 621 | { |
| 622 | struct inode *inode = dentry->d_inode; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 623 | bhv_vnode_t *vp = vn_from_inode(inode); |
Nathan Scott | 69e23b9 | 2006-09-28 11:01:22 +1000 | [diff] [blame] | 624 | bhv_vattr_t vattr = { .va_mask = XFS_AT_STAT }; |
| 625 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
Nathan Scott | 69e23b9 | 2006-09-28 11:01:22 +1000 | [diff] [blame] | 627 | error = bhv_vop_getattr(vp, &vattr, ATTR_LAZY, NULL); |
| 628 | if (likely(!error)) { |
| 629 | stat->size = i_size_read(inode); |
| 630 | stat->dev = inode->i_sb->s_dev; |
| 631 | stat->rdev = (vattr.va_rdev == 0) ? 0 : |
| 632 | MKDEV(sysv_major(vattr.va_rdev) & 0x1ff, |
| 633 | sysv_minor(vattr.va_rdev)); |
| 634 | stat->mode = vattr.va_mode; |
| 635 | stat->nlink = vattr.va_nlink; |
| 636 | stat->uid = vattr.va_uid; |
| 637 | stat->gid = vattr.va_gid; |
| 638 | stat->ino = vattr.va_nodeid; |
| 639 | stat->atime = vattr.va_atime; |
| 640 | stat->mtime = vattr.va_mtime; |
| 641 | stat->ctime = vattr.va_ctime; |
| 642 | stat->blocks = vattr.va_nblocks; |
| 643 | stat->blksize = vattr.va_blocksize; |
| 644 | } |
Nathan Scott | b76963f | 2006-06-09 14:58:20 +1000 | [diff] [blame] | 645 | return -error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | STATIC int |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 649 | xfs_vn_setattr( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | struct dentry *dentry, |
| 651 | struct iattr *attr) |
| 652 | { |
| 653 | struct inode *inode = dentry->d_inode; |
| 654 | unsigned int ia_valid = attr->ia_valid; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 655 | bhv_vnode_t *vp = vn_from_inode(inode); |
Nathan Scott | 8285fb5 | 2006-06-09 17:07:12 +1000 | [diff] [blame] | 656 | bhv_vattr_t vattr = { 0 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | int flags = 0; |
| 658 | int error; |
| 659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | if (ia_valid & ATTR_UID) { |
| 661 | vattr.va_mask |= XFS_AT_UID; |
| 662 | vattr.va_uid = attr->ia_uid; |
| 663 | } |
| 664 | if (ia_valid & ATTR_GID) { |
| 665 | vattr.va_mask |= XFS_AT_GID; |
| 666 | vattr.va_gid = attr->ia_gid; |
| 667 | } |
| 668 | if (ia_valid & ATTR_SIZE) { |
| 669 | vattr.va_mask |= XFS_AT_SIZE; |
| 670 | vattr.va_size = attr->ia_size; |
| 671 | } |
| 672 | if (ia_valid & ATTR_ATIME) { |
| 673 | vattr.va_mask |= XFS_AT_ATIME; |
| 674 | vattr.va_atime = attr->ia_atime; |
Nathan Scott | 8c0b511 | 2006-04-11 15:12:45 +1000 | [diff] [blame] | 675 | inode->i_atime = attr->ia_atime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | } |
| 677 | if (ia_valid & ATTR_MTIME) { |
| 678 | vattr.va_mask |= XFS_AT_MTIME; |
| 679 | vattr.va_mtime = attr->ia_mtime; |
| 680 | } |
| 681 | if (ia_valid & ATTR_CTIME) { |
| 682 | vattr.va_mask |= XFS_AT_CTIME; |
| 683 | vattr.va_ctime = attr->ia_ctime; |
| 684 | } |
| 685 | if (ia_valid & ATTR_MODE) { |
| 686 | vattr.va_mask |= XFS_AT_MODE; |
| 687 | vattr.va_mode = attr->ia_mode; |
| 688 | if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID)) |
| 689 | inode->i_mode &= ~S_ISGID; |
| 690 | } |
| 691 | |
| 692 | if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) |
| 693 | flags |= ATTR_UTIME; |
| 694 | #ifdef ATTR_NO_BLOCK |
| 695 | if ((ia_valid & ATTR_NO_BLOCK)) |
| 696 | flags |= ATTR_NONBLOCK; |
| 697 | #endif |
| 698 | |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 699 | error = bhv_vop_setattr(vp, &vattr, flags, NULL); |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 700 | if (likely(!error)) |
| 701 | __vn_revalidate(vp, &vattr); |
| 702 | return -error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | STATIC void |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 706 | xfs_vn_truncate( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | struct inode *inode) |
| 708 | { |
Nathan Scott | c253666 | 2006-03-29 10:44:40 +1000 | [diff] [blame] | 709 | block_truncate_page(inode->i_mapping, inode->i_size, xfs_get_blocks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | STATIC int |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 713 | xfs_vn_setxattr( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | struct dentry *dentry, |
| 715 | const char *name, |
| 716 | const void *data, |
| 717 | size_t size, |
| 718 | int flags) |
| 719 | { |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 720 | bhv_vnode_t *vp = vn_from_inode(dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | char *attr = (char *)name; |
| 722 | attrnames_t *namesp; |
| 723 | int xflags = 0; |
| 724 | int error; |
| 725 | |
| 726 | namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT); |
| 727 | if (!namesp) |
| 728 | return -EOPNOTSUPP; |
| 729 | attr += namesp->attr_namelen; |
| 730 | error = namesp->attr_capable(vp, NULL); |
| 731 | if (error) |
| 732 | return error; |
| 733 | |
| 734 | /* Convert Linux syscall to XFS internal ATTR flags */ |
| 735 | if (flags & XATTR_CREATE) |
| 736 | xflags |= ATTR_CREATE; |
| 737 | if (flags & XATTR_REPLACE) |
| 738 | xflags |= ATTR_REPLACE; |
| 739 | xflags |= namesp->attr_flag; |
| 740 | return namesp->attr_set(vp, attr, (void *)data, size, xflags); |
| 741 | } |
| 742 | |
| 743 | STATIC ssize_t |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 744 | xfs_vn_getxattr( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | struct dentry *dentry, |
| 746 | const char *name, |
| 747 | void *data, |
| 748 | size_t size) |
| 749 | { |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 750 | bhv_vnode_t *vp = vn_from_inode(dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | char *attr = (char *)name; |
| 752 | attrnames_t *namesp; |
| 753 | int xflags = 0; |
| 754 | ssize_t error; |
| 755 | |
| 756 | namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT); |
| 757 | if (!namesp) |
| 758 | return -EOPNOTSUPP; |
| 759 | attr += namesp->attr_namelen; |
| 760 | error = namesp->attr_capable(vp, NULL); |
| 761 | if (error) |
| 762 | return error; |
| 763 | |
| 764 | /* Convert Linux syscall to XFS internal ATTR flags */ |
| 765 | if (!size) { |
| 766 | xflags |= ATTR_KERNOVAL; |
| 767 | data = NULL; |
| 768 | } |
| 769 | xflags |= namesp->attr_flag; |
| 770 | return namesp->attr_get(vp, attr, (void *)data, size, xflags); |
| 771 | } |
| 772 | |
| 773 | STATIC ssize_t |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 774 | xfs_vn_listxattr( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | struct dentry *dentry, |
| 776 | char *data, |
| 777 | size_t size) |
| 778 | { |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 779 | bhv_vnode_t *vp = vn_from_inode(dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | int error, xflags = ATTR_KERNAMELS; |
| 781 | ssize_t result; |
| 782 | |
| 783 | if (!size) |
| 784 | xflags |= ATTR_KERNOVAL; |
| 785 | xflags |= capable(CAP_SYS_ADMIN) ? ATTR_KERNFULLS : ATTR_KERNORMALS; |
| 786 | |
| 787 | error = attr_generic_list(vp, data, size, xflags, &result); |
| 788 | if (error < 0) |
| 789 | return error; |
| 790 | return result; |
| 791 | } |
| 792 | |
| 793 | STATIC int |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 794 | xfs_vn_removexattr( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | struct dentry *dentry, |
| 796 | const char *name) |
| 797 | { |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 798 | bhv_vnode_t *vp = vn_from_inode(dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | char *attr = (char *)name; |
| 800 | attrnames_t *namesp; |
| 801 | int xflags = 0; |
| 802 | int error; |
| 803 | |
| 804 | namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT); |
| 805 | if (!namesp) |
| 806 | return -EOPNOTSUPP; |
| 807 | attr += namesp->attr_namelen; |
| 808 | error = namesp->attr_capable(vp, NULL); |
| 809 | if (error) |
| 810 | return error; |
| 811 | xflags |= namesp->attr_flag; |
| 812 | return namesp->attr_remove(vp, attr, xflags); |
| 813 | } |
| 814 | |
| 815 | |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 816 | const struct inode_operations xfs_inode_operations = { |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 817 | .permission = xfs_vn_permission, |
| 818 | .truncate = xfs_vn_truncate, |
| 819 | .getattr = xfs_vn_getattr, |
| 820 | .setattr = xfs_vn_setattr, |
| 821 | .setxattr = xfs_vn_setxattr, |
| 822 | .getxattr = xfs_vn_getxattr, |
| 823 | .listxattr = xfs_vn_listxattr, |
| 824 | .removexattr = xfs_vn_removexattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | }; |
| 826 | |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 827 | const struct inode_operations xfs_dir_inode_operations = { |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 828 | .create = xfs_vn_create, |
| 829 | .lookup = xfs_vn_lookup, |
| 830 | .link = xfs_vn_link, |
| 831 | .unlink = xfs_vn_unlink, |
| 832 | .symlink = xfs_vn_symlink, |
| 833 | .mkdir = xfs_vn_mkdir, |
| 834 | .rmdir = xfs_vn_rmdir, |
| 835 | .mknod = xfs_vn_mknod, |
| 836 | .rename = xfs_vn_rename, |
| 837 | .permission = xfs_vn_permission, |
| 838 | .getattr = xfs_vn_getattr, |
| 839 | .setattr = xfs_vn_setattr, |
| 840 | .setxattr = xfs_vn_setxattr, |
| 841 | .getxattr = xfs_vn_getxattr, |
| 842 | .listxattr = xfs_vn_listxattr, |
| 843 | .removexattr = xfs_vn_removexattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | }; |
| 845 | |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 846 | const struct inode_operations xfs_symlink_inode_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | .readlink = generic_readlink, |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 848 | .follow_link = xfs_vn_follow_link, |
| 849 | .put_link = xfs_vn_put_link, |
| 850 | .permission = xfs_vn_permission, |
| 851 | .getattr = xfs_vn_getattr, |
| 852 | .setattr = xfs_vn_setattr, |
| 853 | .setxattr = xfs_vn_setxattr, |
| 854 | .getxattr = xfs_vn_getxattr, |
| 855 | .listxattr = xfs_vn_listxattr, |
| 856 | .removexattr = xfs_vn_removexattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | }; |