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