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