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