| 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" | 
| Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 20 | #include "xfs_acl.h" | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 21 | #include "xfs_bit.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include "xfs_log.h" | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 23 | #include "xfs_inum.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include "xfs_trans.h" | 
|  | 25 | #include "xfs_sb.h" | 
|  | 26 | #include "xfs_ag.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include "xfs_alloc.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include "xfs_quota.h" | 
|  | 29 | #include "xfs_mount.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "xfs_bmap_btree.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include "xfs_dinode.h" | 
|  | 32 | #include "xfs_inode.h" | 
|  | 33 | #include "xfs_bmap.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include "xfs_rtalloc.h" | 
|  | 35 | #include "xfs_error.h" | 
|  | 36 | #include "xfs_itable.h" | 
|  | 37 | #include "xfs_rw.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include "xfs_attr.h" | 
|  | 39 | #include "xfs_buf_item.h" | 
|  | 40 | #include "xfs_utils.h" | 
| Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 41 | #include "xfs_vnodeops.h" | 
| Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 42 | #include "xfs_trace.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 |  | 
| Randy Dunlap | 16f7e0f | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 44 | #include <linux/capability.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/xattr.h> | 
|  | 46 | #include <linux/namei.h> | 
| Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 47 | #include <linux/posix_acl.h> | 
| Nathan Scott | 446ada4 | 2006-01-11 15:35:44 +1100 | [diff] [blame] | 48 | #include <linux/security.h> | 
| Eric Sandeen | f35642e | 2008-11-28 14:23:35 +1100 | [diff] [blame] | 49 | #include <linux/fiemap.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 50 | #include <linux/slab.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 |  | 
| Nathan Scott | 4aeb664 | 2005-11-02 11:43:58 +1100 | [diff] [blame] | 52 | /* | 
| Christoph Hellwig | f9581b1 | 2009-10-06 20:29:26 +0000 | [diff] [blame] | 53 | * Bring the timestamps in the XFS inode uptodate. | 
|  | 54 | * | 
|  | 55 | * Used before writing the inode to disk. | 
| Christoph Hellwig | 42fe2b1 | 2006-01-11 15:35:17 +1100 | [diff] [blame] | 56 | */ | 
|  | 57 | void | 
| Christoph Hellwig | f9581b1 | 2009-10-06 20:29:26 +0000 | [diff] [blame] | 58 | xfs_synchronize_times( | 
| Christoph Hellwig | 42fe2b1 | 2006-01-11 15:35:17 +1100 | [diff] [blame] | 59 | xfs_inode_t	*ip) | 
|  | 60 | { | 
| David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 61 | struct inode	*inode = VFS_I(ip); | 
| Christoph Hellwig | 42fe2b1 | 2006-01-11 15:35:17 +1100 | [diff] [blame] | 62 |  | 
| Christoph Hellwig | f9581b1 | 2009-10-06 20:29:26 +0000 | [diff] [blame] | 63 | ip->i_d.di_atime.t_sec = (__int32_t)inode->i_atime.tv_sec; | 
|  | 64 | ip->i_d.di_atime.t_nsec = (__int32_t)inode->i_atime.tv_nsec; | 
|  | 65 | ip->i_d.di_ctime.t_sec = (__int32_t)inode->i_ctime.tv_sec; | 
|  | 66 | ip->i_d.di_ctime.t_nsec = (__int32_t)inode->i_ctime.tv_nsec; | 
|  | 67 | ip->i_d.di_mtime.t_sec = (__int32_t)inode->i_mtime.tv_sec; | 
|  | 68 | ip->i_d.di_mtime.t_nsec = (__int32_t)inode->i_mtime.tv_nsec; | 
| Christoph Hellwig | 42fe2b1 | 2006-01-11 15:35:17 +1100 | [diff] [blame] | 69 | } | 
|  | 70 |  | 
|  | 71 | /* | 
| David Chinner | bf90424 | 2008-10-30 17:36:14 +1100 | [diff] [blame] | 72 | * If the linux inode is valid, mark it dirty. | 
| David Chinner | 5d51eff | 2007-11-23 16:29:18 +1100 | [diff] [blame] | 73 | * Used when commiting a dirty inode into a transaction so that | 
|  | 74 | * the inode will get written back by the linux code | 
|  | 75 | */ | 
|  | 76 | void | 
|  | 77 | xfs_mark_inode_dirty_sync( | 
|  | 78 | xfs_inode_t	*ip) | 
|  | 79 | { | 
| David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 80 | struct inode	*inode = VFS_I(ip); | 
| David Chinner | 5d51eff | 2007-11-23 16:29:18 +1100 | [diff] [blame] | 81 |  | 
| Al Viro | a4ffdde | 2010-06-02 17:38:30 -0400 | [diff] [blame] | 82 | if (!(inode->i_state & (I_WILL_FREE|I_FREEING))) | 
| Christoph Hellwig | af04819 | 2008-03-06 13:46:43 +1100 | [diff] [blame] | 83 | mark_inode_dirty_sync(inode); | 
| David Chinner | 5d51eff | 2007-11-23 16:29:18 +1100 | [diff] [blame] | 84 | } | 
|  | 85 |  | 
| Christoph Hellwig | 66d834e | 2010-02-15 09:44:49 +0000 | [diff] [blame] | 86 | void | 
|  | 87 | xfs_mark_inode_dirty( | 
|  | 88 | xfs_inode_t	*ip) | 
|  | 89 | { | 
|  | 90 | struct inode	*inode = VFS_I(ip); | 
|  | 91 |  | 
| Al Viro | a4ffdde | 2010-06-02 17:38:30 -0400 | [diff] [blame] | 92 | if (!(inode->i_state & (I_WILL_FREE|I_FREEING))) | 
| Christoph Hellwig | 66d834e | 2010-02-15 09:44:49 +0000 | [diff] [blame] | 93 | mark_inode_dirty(inode); | 
|  | 94 | } | 
|  | 95 |  | 
| David Chinner | 5d51eff | 2007-11-23 16:29:18 +1100 | [diff] [blame] | 96 | /* | 
| Nathan Scott | 446ada4 | 2006-01-11 15:35:44 +1100 | [diff] [blame] | 97 | * Hook in SELinux.  This is not quite correct yet, what we really need | 
|  | 98 | * here (as we do for default ACLs) is a mechanism by which creation of | 
|  | 99 | * these attrs can be journalled at inode creation time (along with the | 
|  | 100 | * inode, of course, such that log replay can't cause these to be lost). | 
|  | 101 | */ | 
|  | 102 | STATIC int | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 103 | xfs_init_security( | 
| Christoph Hellwig | af04819 | 2008-03-06 13:46:43 +1100 | [diff] [blame] | 104 | struct inode	*inode, | 
| Nathan Scott | 446ada4 | 2006-01-11 15:35:44 +1100 | [diff] [blame] | 105 | struct inode	*dir) | 
|  | 106 | { | 
| Christoph Hellwig | af04819 | 2008-03-06 13:46:43 +1100 | [diff] [blame] | 107 | struct xfs_inode *ip = XFS_I(inode); | 
| Nathan Scott | 446ada4 | 2006-01-11 15:35:44 +1100 | [diff] [blame] | 108 | size_t		length; | 
|  | 109 | void		*value; | 
| Dave Chinner | a9273ca | 2010-01-20 10:47:48 +1100 | [diff] [blame] | 110 | unsigned char	*name; | 
| Nathan Scott | 446ada4 | 2006-01-11 15:35:44 +1100 | [diff] [blame] | 111 | int		error; | 
|  | 112 |  | 
| Dave Chinner | a9273ca | 2010-01-20 10:47:48 +1100 | [diff] [blame] | 113 | error = security_inode_init_security(inode, dir, (char **)&name, | 
| Christoph Hellwig | af04819 | 2008-03-06 13:46:43 +1100 | [diff] [blame] | 114 | &value, &length); | 
| Nathan Scott | 446ada4 | 2006-01-11 15:35:44 +1100 | [diff] [blame] | 115 | if (error) { | 
|  | 116 | if (error == -EOPNOTSUPP) | 
|  | 117 | return 0; | 
|  | 118 | return -error; | 
|  | 119 | } | 
|  | 120 |  | 
| Christoph Hellwig | af04819 | 2008-03-06 13:46:43 +1100 | [diff] [blame] | 121 | error = xfs_attr_set(ip, name, value, length, ATTR_SECURE); | 
| Nathan Scott | 446ada4 | 2006-01-11 15:35:44 +1100 | [diff] [blame] | 122 |  | 
|  | 123 | kfree(name); | 
|  | 124 | kfree(value); | 
|  | 125 | return error; | 
|  | 126 | } | 
|  | 127 |  | 
| Barry Naujok | 556b8b1 | 2008-04-10 12:22:07 +1000 | [diff] [blame] | 128 | static void | 
|  | 129 | xfs_dentry_to_name( | 
|  | 130 | struct xfs_name	*namep, | 
|  | 131 | struct dentry	*dentry) | 
|  | 132 | { | 
|  | 133 | namep->name = dentry->d_name.name; | 
|  | 134 | namep->len = dentry->d_name.len; | 
|  | 135 | } | 
|  | 136 |  | 
| David Chinner | 7989cb8 | 2007-02-10 18:34:56 +1100 | [diff] [blame] | 137 | STATIC void | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 138 | xfs_cleanup_inode( | 
| Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 139 | struct inode	*dir, | 
| Christoph Hellwig | af04819 | 2008-03-06 13:46:43 +1100 | [diff] [blame] | 140 | struct inode	*inode, | 
| Christoph Hellwig | 8f112e3 | 2008-06-23 13:25:17 +1000 | [diff] [blame] | 141 | struct dentry	*dentry) | 
| Yingping Lu | 3a69c7d | 2006-02-01 12:14:34 +1100 | [diff] [blame] | 142 | { | 
| Barry Naujok | 556b8b1 | 2008-04-10 12:22:07 +1000 | [diff] [blame] | 143 | struct xfs_name	teardown; | 
| Yingping Lu | 3a69c7d | 2006-02-01 12:14:34 +1100 | [diff] [blame] | 144 |  | 
|  | 145 | /* Oh, the horror. | 
| Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 146 | * If we can't add the ACL or we fail in | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 147 | * xfs_init_security we must back out. | 
| Yingping Lu | 3a69c7d | 2006-02-01 12:14:34 +1100 | [diff] [blame] | 148 | * ENOSPC can hit here, among other things. | 
|  | 149 | */ | 
| Barry Naujok | 556b8b1 | 2008-04-10 12:22:07 +1000 | [diff] [blame] | 150 | xfs_dentry_to_name(&teardown, dentry); | 
| Yingping Lu | 3a69c7d | 2006-02-01 12:14:34 +1100 | [diff] [blame] | 151 |  | 
| Christoph Hellwig | 8f112e3 | 2008-06-23 13:25:17 +1000 | [diff] [blame] | 152 | xfs_remove(XFS_I(dir), &teardown, XFS_I(inode)); | 
| Christoph Hellwig | af04819 | 2008-03-06 13:46:43 +1100 | [diff] [blame] | 153 | iput(inode); | 
| Yingping Lu | 3a69c7d | 2006-02-01 12:14:34 +1100 | [diff] [blame] | 154 | } | 
|  | 155 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | STATIC int | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 157 | xfs_vn_mknod( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | struct inode	*dir, | 
|  | 159 | struct dentry	*dentry, | 
|  | 160 | int		mode, | 
|  | 161 | dev_t		rdev) | 
|  | 162 | { | 
| Christoph Hellwig | db0bb7b | 2008-03-06 13:44:35 +1100 | [diff] [blame] | 163 | struct inode	*inode; | 
| Christoph Hellwig | 979ebab | 2008-03-06 13:46:05 +1100 | [diff] [blame] | 164 | struct xfs_inode *ip = NULL; | 
| Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 165 | struct posix_acl *default_acl = NULL; | 
| Barry Naujok | 556b8b1 | 2008-04-10 12:22:07 +1000 | [diff] [blame] | 166 | struct xfs_name	name; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | int		error; | 
|  | 168 |  | 
|  | 169 | /* | 
|  | 170 | * Irix uses Missed'em'V split, but doesn't want to see | 
|  | 171 | * the upper 5 bits of (14bit) major. | 
|  | 172 | */ | 
| Christoph Hellwig | 517b5e8 | 2009-02-09 08:38:02 +0100 | [diff] [blame] | 173 | if (S_ISCHR(mode) || S_ISBLK(mode)) { | 
|  | 174 | if (unlikely(!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff)) | 
|  | 175 | return -EINVAL; | 
|  | 176 | rdev = sysv_encode_dev(rdev); | 
|  | 177 | } else { | 
|  | 178 | rdev = 0; | 
|  | 179 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 |  | 
| Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 181 | if (IS_POSIXACL(dir)) { | 
|  | 182 | default_acl = xfs_get_acl(dir, ACL_TYPE_DEFAULT); | 
|  | 183 | if (IS_ERR(default_acl)) | 
|  | 184 | return -PTR_ERR(default_acl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 |  | 
| Christoph Hellwig | e83f1eb | 2009-06-12 11:19:11 -0400 | [diff] [blame] | 186 | if (!default_acl) | 
|  | 187 | mode &= ~current_umask(); | 
| Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 188 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 |  | 
| Christoph Hellwig | 517b5e8 | 2009-02-09 08:38:02 +0100 | [diff] [blame] | 190 | xfs_dentry_to_name(&name, dentry); | 
| Christoph Hellwig | 6c77b0e | 2010-10-06 18:41:17 +0000 | [diff] [blame] | 191 | error = xfs_create(XFS_I(dir), &name, mode, rdev, &ip); | 
| Christoph Hellwig | db0bb7b | 2008-03-06 13:44:35 +1100 | [diff] [blame] | 192 | if (unlikely(error)) | 
|  | 193 | goto out_free_acl; | 
| Nathan Scott | 446ada4 | 2006-01-11 15:35:44 +1100 | [diff] [blame] | 194 |  | 
| David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 195 | inode = VFS_I(ip); | 
| Christoph Hellwig | 979ebab | 2008-03-06 13:46:05 +1100 | [diff] [blame] | 196 |  | 
|  | 197 | error = xfs_init_security(inode, dir); | 
| Christoph Hellwig | db0bb7b | 2008-03-06 13:44:35 +1100 | [diff] [blame] | 198 | if (unlikely(error)) | 
|  | 199 | goto out_cleanup_inode; | 
|  | 200 |  | 
|  | 201 | if (default_acl) { | 
| Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 202 | error = -xfs_inherit_acl(inode, default_acl); | 
| Christoph Hellwig | db0bb7b | 2008-03-06 13:44:35 +1100 | [diff] [blame] | 203 | if (unlikely(error)) | 
|  | 204 | goto out_cleanup_inode; | 
| Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 205 | posix_acl_release(default_acl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } | 
|  | 207 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 |  | 
| Christoph Hellwig | db0bb7b | 2008-03-06 13:44:35 +1100 | [diff] [blame] | 209 | d_instantiate(dentry, inode); | 
| Christoph Hellwig | db0bb7b | 2008-03-06 13:44:35 +1100 | [diff] [blame] | 210 | return -error; | 
|  | 211 |  | 
|  | 212 | out_cleanup_inode: | 
| Christoph Hellwig | 8f112e3 | 2008-06-23 13:25:17 +1000 | [diff] [blame] | 213 | xfs_cleanup_inode(dir, inode, dentry); | 
| Christoph Hellwig | db0bb7b | 2008-03-06 13:44:35 +1100 | [diff] [blame] | 214 | out_free_acl: | 
| Christoph Hellwig | ef14f0c | 2009-06-10 17:07:47 +0200 | [diff] [blame] | 215 | posix_acl_release(default_acl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | return -error; | 
|  | 217 | } | 
|  | 218 |  | 
|  | 219 | STATIC int | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 220 | xfs_vn_create( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | struct inode	*dir, | 
|  | 222 | struct dentry	*dentry, | 
|  | 223 | int		mode, | 
|  | 224 | struct nameidata *nd) | 
|  | 225 | { | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 226 | return xfs_vn_mknod(dir, dentry, mode, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } | 
|  | 228 |  | 
|  | 229 | STATIC int | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 230 | xfs_vn_mkdir( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | struct inode	*dir, | 
|  | 232 | struct dentry	*dentry, | 
|  | 233 | int		mode) | 
|  | 234 | { | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 235 | return xfs_vn_mknod(dir, dentry, mode|S_IFDIR, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } | 
|  | 237 |  | 
|  | 238 | STATIC struct dentry * | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 239 | xfs_vn_lookup( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | struct inode	*dir, | 
|  | 241 | struct dentry	*dentry, | 
|  | 242 | struct nameidata *nd) | 
|  | 243 | { | 
| Christoph Hellwig | ef1f5e7 | 2008-03-06 13:46:25 +1100 | [diff] [blame] | 244 | struct xfs_inode *cip; | 
| Barry Naujok | 556b8b1 | 2008-04-10 12:22:07 +1000 | [diff] [blame] | 245 | struct xfs_name	name; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | int		error; | 
|  | 247 |  | 
|  | 248 | if (dentry->d_name.len >= MAXNAMELEN) | 
|  | 249 | return ERR_PTR(-ENAMETOOLONG); | 
|  | 250 |  | 
| Barry Naujok | 556b8b1 | 2008-04-10 12:22:07 +1000 | [diff] [blame] | 251 | xfs_dentry_to_name(&name, dentry); | 
| Barry Naujok | 384f3ce | 2008-05-21 16:58:22 +1000 | [diff] [blame] | 252 | error = xfs_lookup(XFS_I(dir), &name, &cip, NULL); | 
| Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 253 | if (unlikely(error)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | if (unlikely(error != ENOENT)) | 
|  | 255 | return ERR_PTR(-error); | 
|  | 256 | d_add(dentry, NULL); | 
|  | 257 | return NULL; | 
|  | 258 | } | 
|  | 259 |  | 
| David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 260 | return d_splice_alias(VFS_I(cip), dentry); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } | 
|  | 262 |  | 
| Barry Naujok | 384f3ce | 2008-05-21 16:58:22 +1000 | [diff] [blame] | 263 | STATIC struct dentry * | 
|  | 264 | xfs_vn_ci_lookup( | 
|  | 265 | struct inode	*dir, | 
|  | 266 | struct dentry	*dentry, | 
|  | 267 | struct nameidata *nd) | 
|  | 268 | { | 
|  | 269 | struct xfs_inode *ip; | 
|  | 270 | struct xfs_name	xname; | 
|  | 271 | struct xfs_name ci_name; | 
|  | 272 | struct qstr	dname; | 
|  | 273 | int		error; | 
|  | 274 |  | 
|  | 275 | if (dentry->d_name.len >= MAXNAMELEN) | 
|  | 276 | return ERR_PTR(-ENAMETOOLONG); | 
|  | 277 |  | 
|  | 278 | xfs_dentry_to_name(&xname, dentry); | 
|  | 279 | error = xfs_lookup(XFS_I(dir), &xname, &ip, &ci_name); | 
|  | 280 | if (unlikely(error)) { | 
|  | 281 | if (unlikely(error != ENOENT)) | 
|  | 282 | return ERR_PTR(-error); | 
| Barry Naujok | 866d5dc | 2008-05-22 17:21:40 +1000 | [diff] [blame] | 283 | /* | 
|  | 284 | * call d_add(dentry, NULL) here when d_drop_negative_children | 
|  | 285 | * is called in xfs_vn_mknod (ie. allow negative dentries | 
|  | 286 | * with CI filesystems). | 
|  | 287 | */ | 
| Barry Naujok | 384f3ce | 2008-05-21 16:58:22 +1000 | [diff] [blame] | 288 | return NULL; | 
|  | 289 | } | 
|  | 290 |  | 
|  | 291 | /* if exact match, just splice and exit */ | 
|  | 292 | if (!ci_name.name) | 
| David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 293 | return d_splice_alias(VFS_I(ip), dentry); | 
| Barry Naujok | 384f3ce | 2008-05-21 16:58:22 +1000 | [diff] [blame] | 294 |  | 
|  | 295 | /* else case-insensitive match... */ | 
|  | 296 | dname.name = ci_name.name; | 
|  | 297 | dname.len = ci_name.len; | 
| Christoph Hellwig | e45b590 | 2008-08-07 23:49:07 +0200 | [diff] [blame] | 298 | dentry = d_add_ci(dentry, VFS_I(ip), &dname); | 
| Barry Naujok | 384f3ce | 2008-05-21 16:58:22 +1000 | [diff] [blame] | 299 | kmem_free(ci_name.name); | 
|  | 300 | return dentry; | 
|  | 301 | } | 
|  | 302 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | STATIC int | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 304 | xfs_vn_link( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | struct dentry	*old_dentry, | 
|  | 306 | struct inode	*dir, | 
|  | 307 | struct dentry	*dentry) | 
|  | 308 | { | 
| Christoph Hellwig | d9424b3 | 2008-12-03 12:20:27 +0100 | [diff] [blame] | 309 | struct inode	*inode = old_dentry->d_inode; | 
| Barry Naujok | 556b8b1 | 2008-04-10 12:22:07 +1000 | [diff] [blame] | 310 | struct xfs_name	name; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | int		error; | 
|  | 312 |  | 
| Barry Naujok | 556b8b1 | 2008-04-10 12:22:07 +1000 | [diff] [blame] | 313 | xfs_dentry_to_name(&name, dentry); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 |  | 
| Barry Naujok | 556b8b1 | 2008-04-10 12:22:07 +1000 | [diff] [blame] | 315 | error = xfs_link(XFS_I(dir), XFS_I(inode), &name); | 
| Christoph Hellwig | d9424b3 | 2008-12-03 12:20:27 +0100 | [diff] [blame] | 316 | if (unlikely(error)) | 
| Christoph Hellwig | a3da789 | 2008-03-06 13:46:12 +1100 | [diff] [blame] | 317 | return -error; | 
| Christoph Hellwig | a3da789 | 2008-03-06 13:46:12 +1100 | [diff] [blame] | 318 |  | 
| Al Viro | 7de9c6e | 2010-10-23 11:11:40 -0400 | [diff] [blame] | 319 | ihold(inode); | 
| Christoph Hellwig | a3da789 | 2008-03-06 13:46:12 +1100 | [diff] [blame] | 320 | d_instantiate(dentry, inode); | 
|  | 321 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } | 
|  | 323 |  | 
|  | 324 | STATIC int | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 325 | xfs_vn_unlink( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | struct inode	*dir, | 
|  | 327 | struct dentry	*dentry) | 
|  | 328 | { | 
| Barry Naujok | 556b8b1 | 2008-04-10 12:22:07 +1000 | [diff] [blame] | 329 | struct xfs_name	name; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | int		error; | 
|  | 331 |  | 
| Barry Naujok | 556b8b1 | 2008-04-10 12:22:07 +1000 | [diff] [blame] | 332 | xfs_dentry_to_name(&name, dentry); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 |  | 
| Christoph Hellwig | e570070 | 2008-06-23 13:25:25 +1000 | [diff] [blame] | 334 | error = -xfs_remove(XFS_I(dir), &name, XFS_I(dentry->d_inode)); | 
|  | 335 | if (error) | 
|  | 336 | return error; | 
|  | 337 |  | 
|  | 338 | /* | 
|  | 339 | * With unlink, the VFS makes the dentry "negative": no inode, | 
|  | 340 | * but still hashed. This is incompatible with case-insensitive | 
|  | 341 | * mode, so invalidate (unhash) the dentry in CI-mode. | 
|  | 342 | */ | 
|  | 343 | if (xfs_sb_version_hasasciici(&XFS_M(dir->i_sb)->m_sb)) | 
|  | 344 | d_invalidate(dentry); | 
|  | 345 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } | 
|  | 347 |  | 
|  | 348 | STATIC int | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 349 | xfs_vn_symlink( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | struct inode	*dir, | 
|  | 351 | struct dentry	*dentry, | 
|  | 352 | const char	*symname) | 
|  | 353 | { | 
| Christoph Hellwig | 3937be5 | 2008-03-06 13:46:19 +1100 | [diff] [blame] | 354 | struct inode	*inode; | 
|  | 355 | struct xfs_inode *cip = NULL; | 
| Barry Naujok | 556b8b1 | 2008-04-10 12:22:07 +1000 | [diff] [blame] | 356 | struct xfs_name	name; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | int		error; | 
| Christoph Hellwig | 3e5daf0 | 2007-10-11 18:09:12 +1000 | [diff] [blame] | 358 | mode_t		mode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 |  | 
| Christoph Hellwig | 3e5daf0 | 2007-10-11 18:09:12 +1000 | [diff] [blame] | 360 | mode = S_IFLNK | | 
| Al Viro | ce3b0f8 | 2009-03-29 19:08:22 -0400 | [diff] [blame] | 361 | (irix_symlink_mode ? 0777 & ~current_umask() : S_IRWXUGO); | 
| Barry Naujok | 556b8b1 | 2008-04-10 12:22:07 +1000 | [diff] [blame] | 362 | xfs_dentry_to_name(&name, dentry); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 |  | 
| Christoph Hellwig | 6c77b0e | 2010-10-06 18:41:17 +0000 | [diff] [blame] | 364 | error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip); | 
| Christoph Hellwig | 3937be5 | 2008-03-06 13:46:19 +1100 | [diff] [blame] | 365 | if (unlikely(error)) | 
|  | 366 | goto out; | 
|  | 367 |  | 
| David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 368 | inode = VFS_I(cip); | 
| Christoph Hellwig | 3937be5 | 2008-03-06 13:46:19 +1100 | [diff] [blame] | 369 |  | 
|  | 370 | error = xfs_init_security(inode, dir); | 
|  | 371 | if (unlikely(error)) | 
|  | 372 | goto out_cleanup_inode; | 
|  | 373 |  | 
|  | 374 | d_instantiate(dentry, inode); | 
| Christoph Hellwig | 3937be5 | 2008-03-06 13:46:19 +1100 | [diff] [blame] | 375 | return 0; | 
|  | 376 |  | 
|  | 377 | out_cleanup_inode: | 
| Christoph Hellwig | 8f112e3 | 2008-06-23 13:25:17 +1000 | [diff] [blame] | 378 | xfs_cleanup_inode(dir, inode, dentry); | 
| Christoph Hellwig | 3937be5 | 2008-03-06 13:46:19 +1100 | [diff] [blame] | 379 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | return -error; | 
|  | 381 | } | 
|  | 382 |  | 
|  | 383 | STATIC int | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 384 | xfs_vn_rename( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | struct inode	*odir, | 
|  | 386 | struct dentry	*odentry, | 
|  | 387 | struct inode	*ndir, | 
|  | 388 | struct dentry	*ndentry) | 
|  | 389 | { | 
|  | 390 | struct inode	*new_inode = ndentry->d_inode; | 
| Barry Naujok | 556b8b1 | 2008-04-10 12:22:07 +1000 | [diff] [blame] | 391 | struct xfs_name	oname; | 
|  | 392 | struct xfs_name	nname; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 |  | 
| Barry Naujok | 556b8b1 | 2008-04-10 12:22:07 +1000 | [diff] [blame] | 394 | xfs_dentry_to_name(&oname, odentry); | 
|  | 395 | xfs_dentry_to_name(&nname, ndentry); | 
|  | 396 |  | 
| Christoph Hellwig | e570070 | 2008-06-23 13:25:25 +1000 | [diff] [blame] | 397 | return -xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode), | 
| Christoph Hellwig | cfa853e | 2008-04-22 17:34:06 +1000 | [diff] [blame] | 398 | XFS_I(ndir), &nname, new_inode ? | 
|  | 399 | XFS_I(new_inode) : NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } | 
|  | 401 |  | 
|  | 402 | /* | 
|  | 403 | * careful here - this function can get called recursively, so | 
|  | 404 | * we need to be very careful about how much stack we use. | 
|  | 405 | * uio is kmalloced for this reason... | 
|  | 406 | */ | 
| Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 407 | STATIC void * | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 408 | xfs_vn_follow_link( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | struct dentry		*dentry, | 
|  | 410 | struct nameidata	*nd) | 
|  | 411 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | char			*link; | 
| Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 413 | int			error = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 |  | 
| Panagiotis Issaris | f52720c | 2006-09-27 01:49:39 -0700 | [diff] [blame] | 415 | link = kmalloc(MAXPATHLEN+1, GFP_KERNEL); | 
| Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 416 | if (!link) | 
|  | 417 | goto out_err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 |  | 
| Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 419 | error = -xfs_readlink(XFS_I(dentry->d_inode), link); | 
| Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 420 | if (unlikely(error)) | 
|  | 421 | goto out_kfree; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 |  | 
|  | 423 | nd_set_link(nd, link); | 
| Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 424 | return NULL; | 
| Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 425 |  | 
|  | 426 | out_kfree: | 
|  | 427 | kfree(link); | 
|  | 428 | out_err: | 
|  | 429 | nd_set_link(nd, ERR_PTR(error)); | 
|  | 430 | return NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | } | 
|  | 432 |  | 
| Nathan Scott | cde410a | 2005-09-05 11:47:01 +1000 | [diff] [blame] | 433 | STATIC void | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 434 | xfs_vn_put_link( | 
| Nathan Scott | cde410a | 2005-09-05 11:47:01 +1000 | [diff] [blame] | 435 | struct dentry	*dentry, | 
|  | 436 | struct nameidata *nd, | 
|  | 437 | void		*p) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | { | 
| Nathan Scott | cde410a | 2005-09-05 11:47:01 +1000 | [diff] [blame] | 439 | char		*s = nd_get_link(nd); | 
|  | 440 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | if (!IS_ERR(s)) | 
|  | 442 | kfree(s); | 
|  | 443 | } | 
|  | 444 |  | 
| Christoph Hellwig | 4576758 | 2008-02-05 12:13:24 +1100 | [diff] [blame] | 445 | STATIC int | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 446 | xfs_vn_getattr( | 
| Christoph Hellwig | c43f408 | 2007-10-11 17:46:39 +1000 | [diff] [blame] | 447 | struct vfsmount		*mnt, | 
|  | 448 | struct dentry		*dentry, | 
|  | 449 | struct kstat		*stat) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | { | 
| Christoph Hellwig | c43f408 | 2007-10-11 17:46:39 +1000 | [diff] [blame] | 451 | struct inode		*inode = dentry->d_inode; | 
|  | 452 | struct xfs_inode	*ip = XFS_I(inode); | 
|  | 453 | struct xfs_mount	*mp = ip->i_mount; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 |  | 
| Christoph Hellwig | cca28fb | 2010-06-24 11:57:09 +1000 | [diff] [blame] | 455 | trace_xfs_getattr(ip); | 
| Christoph Hellwig | c43f408 | 2007-10-11 17:46:39 +1000 | [diff] [blame] | 456 |  | 
|  | 457 | if (XFS_FORCED_SHUTDOWN(mp)) | 
|  | 458 | return XFS_ERROR(EIO); | 
|  | 459 |  | 
|  | 460 | stat->size = XFS_ISIZE(ip); | 
|  | 461 | stat->dev = inode->i_sb->s_dev; | 
|  | 462 | stat->mode = ip->i_d.di_mode; | 
|  | 463 | stat->nlink = ip->i_d.di_nlink; | 
|  | 464 | stat->uid = ip->i_d.di_uid; | 
|  | 465 | stat->gid = ip->i_d.di_gid; | 
|  | 466 | stat->ino = ip->i_ino; | 
| Christoph Hellwig | c43f408 | 2007-10-11 17:46:39 +1000 | [diff] [blame] | 467 | stat->atime = inode->i_atime; | 
| Christoph Hellwig | f9581b1 | 2009-10-06 20:29:26 +0000 | [diff] [blame] | 468 | stat->mtime = inode->i_mtime; | 
|  | 469 | stat->ctime = inode->i_ctime; | 
| Christoph Hellwig | c43f408 | 2007-10-11 17:46:39 +1000 | [diff] [blame] | 470 | stat->blocks = | 
|  | 471 | XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks); | 
|  | 472 |  | 
|  | 473 |  | 
|  | 474 | switch (inode->i_mode & S_IFMT) { | 
|  | 475 | case S_IFBLK: | 
|  | 476 | case S_IFCHR: | 
|  | 477 | stat->blksize = BLKDEV_IOSIZE; | 
|  | 478 | stat->rdev = MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff, | 
|  | 479 | sysv_minor(ip->i_df.if_u2.if_rdev)); | 
|  | 480 | break; | 
|  | 481 | default: | 
| Eric Sandeen | 71ddabb | 2007-11-23 16:29:42 +1100 | [diff] [blame] | 482 | if (XFS_IS_REALTIME_INODE(ip)) { | 
| Christoph Hellwig | c43f408 | 2007-10-11 17:46:39 +1000 | [diff] [blame] | 483 | /* | 
|  | 484 | * If the file blocks are being allocated from a | 
|  | 485 | * realtime volume, then return the inode's realtime | 
|  | 486 | * extent size or the realtime volume's extent size. | 
|  | 487 | */ | 
|  | 488 | stat->blksize = | 
|  | 489 | xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog; | 
|  | 490 | } else | 
|  | 491 | stat->blksize = xfs_preferred_iosize(mp); | 
|  | 492 | stat->rdev = 0; | 
|  | 493 | break; | 
| Nathan Scott | 69e23b9 | 2006-09-28 11:01:22 +1000 | [diff] [blame] | 494 | } | 
| Christoph Hellwig | c43f408 | 2007-10-11 17:46:39 +1000 | [diff] [blame] | 495 |  | 
|  | 496 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | } | 
|  | 498 |  | 
|  | 499 | STATIC int | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 500 | xfs_vn_setattr( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | struct dentry	*dentry, | 
| Christoph Hellwig | 0f285c8 | 2008-07-18 17:13:28 +1000 | [diff] [blame] | 502 | struct iattr	*iattr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { | 
| Christoph Hellwig | ea5a3dc8 | 2008-10-30 18:27:48 +1100 | [diff] [blame] | 504 | return -xfs_setattr(XFS_I(dentry->d_inode), iattr, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } | 
|  | 506 |  | 
| Eric Sandeen | f35642e | 2008-11-28 14:23:35 +1100 | [diff] [blame] | 507 | #define XFS_FIEMAP_FLAGS	(FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR) | 
|  | 508 |  | 
|  | 509 | /* | 
|  | 510 | * Call fiemap helper to fill in user data. | 
|  | 511 | * Returns positive errors to xfs_getbmap. | 
|  | 512 | */ | 
|  | 513 | STATIC int | 
|  | 514 | xfs_fiemap_format( | 
|  | 515 | void			**arg, | 
|  | 516 | struct getbmapx		*bmv, | 
|  | 517 | int			*full) | 
|  | 518 | { | 
|  | 519 | int			error; | 
|  | 520 | struct fiemap_extent_info *fieinfo = *arg; | 
|  | 521 | u32			fiemap_flags = 0; | 
|  | 522 | u64			logical, physical, length; | 
|  | 523 |  | 
|  | 524 | /* Do nothing for a hole */ | 
|  | 525 | if (bmv->bmv_block == -1LL) | 
|  | 526 | return 0; | 
|  | 527 |  | 
|  | 528 | logical = BBTOB(bmv->bmv_offset); | 
|  | 529 | physical = BBTOB(bmv->bmv_block); | 
|  | 530 | length = BBTOB(bmv->bmv_length); | 
|  | 531 |  | 
|  | 532 | if (bmv->bmv_oflags & BMV_OF_PREALLOC) | 
|  | 533 | fiemap_flags |= FIEMAP_EXTENT_UNWRITTEN; | 
|  | 534 | else if (bmv->bmv_oflags & BMV_OF_DELALLOC) { | 
|  | 535 | fiemap_flags |= FIEMAP_EXTENT_DELALLOC; | 
|  | 536 | physical = 0;   /* no block yet */ | 
|  | 537 | } | 
|  | 538 | if (bmv->bmv_oflags & BMV_OF_LAST) | 
|  | 539 | fiemap_flags |= FIEMAP_EXTENT_LAST; | 
|  | 540 |  | 
|  | 541 | error = fiemap_fill_next_extent(fieinfo, logical, physical, | 
|  | 542 | length, fiemap_flags); | 
|  | 543 | if (error > 0) { | 
|  | 544 | error = 0; | 
|  | 545 | *full = 1;	/* user array now full */ | 
|  | 546 | } | 
|  | 547 |  | 
|  | 548 | return -error; | 
|  | 549 | } | 
|  | 550 |  | 
|  | 551 | STATIC int | 
|  | 552 | xfs_vn_fiemap( | 
|  | 553 | struct inode		*inode, | 
|  | 554 | struct fiemap_extent_info *fieinfo, | 
|  | 555 | u64			start, | 
|  | 556 | u64			length) | 
|  | 557 | { | 
|  | 558 | xfs_inode_t		*ip = XFS_I(inode); | 
|  | 559 | struct getbmapx		bm; | 
|  | 560 | int			error; | 
|  | 561 |  | 
|  | 562 | error = fiemap_check_flags(fieinfo, XFS_FIEMAP_FLAGS); | 
|  | 563 | if (error) | 
|  | 564 | return error; | 
|  | 565 |  | 
|  | 566 | /* Set up bmap header for xfs internal routine */ | 
|  | 567 | bm.bmv_offset = BTOBB(start); | 
|  | 568 | /* Special case for whole file */ | 
|  | 569 | if (length == FIEMAP_MAX_OFFSET) | 
|  | 570 | bm.bmv_length = -1LL; | 
|  | 571 | else | 
|  | 572 | bm.bmv_length = BTOBB(length); | 
|  | 573 |  | 
| Eric Sandeen | 97db39a | 2009-07-26 21:52:01 -0500 | [diff] [blame] | 574 | /* We add one because in getbmap world count includes the header */ | 
| Tao Ma | 2d1ff3c | 2010-04-29 15:13:56 +1000 | [diff] [blame] | 575 | bm.bmv_count = !fieinfo->fi_extents_max ? MAXEXTNUM : | 
|  | 576 | fieinfo->fi_extents_max + 1; | 
|  | 577 | bm.bmv_count = min_t(__s32, bm.bmv_count, | 
|  | 578 | (PAGE_SIZE * 16 / sizeof(struct getbmapx))); | 
| Tao Ma | 9af2546 | 2010-08-30 02:44:03 +0000 | [diff] [blame] | 579 | bm.bmv_iflags = BMV_IF_PREALLOC | BMV_IF_NO_HOLES; | 
| Eric Sandeen | f35642e | 2008-11-28 14:23:35 +1100 | [diff] [blame] | 580 | if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) | 
|  | 581 | bm.bmv_iflags |= BMV_IF_ATTRFORK; | 
|  | 582 | if (!(fieinfo->fi_flags & FIEMAP_FLAG_SYNC)) | 
|  | 583 | bm.bmv_iflags |= BMV_IF_DELALLOC; | 
|  | 584 |  | 
|  | 585 | error = xfs_getbmap(ip, &bm, xfs_fiemap_format, fieinfo); | 
|  | 586 | if (error) | 
|  | 587 | return -error; | 
|  | 588 |  | 
|  | 589 | return 0; | 
|  | 590 | } | 
|  | 591 |  | 
| Christoph Hellwig | 41be8be | 2008-08-13 16:23:13 +1000 | [diff] [blame] | 592 | static const struct inode_operations xfs_inode_operations = { | 
| Linus Torvalds | 18f4c64 | 2009-08-28 12:29:03 -0700 | [diff] [blame] | 593 | .check_acl		= xfs_check_acl, | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 594 | .getattr		= xfs_vn_getattr, | 
|  | 595 | .setattr		= xfs_vn_setattr, | 
| Lachlan McIlroy | 0ec5851 | 2008-06-23 13:23:01 +1000 | [diff] [blame] | 596 | .setxattr		= generic_setxattr, | 
|  | 597 | .getxattr		= generic_getxattr, | 
|  | 598 | .removexattr		= generic_removexattr, | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 599 | .listxattr		= xfs_vn_listxattr, | 
| Eric Sandeen | f35642e | 2008-11-28 14:23:35 +1100 | [diff] [blame] | 600 | .fiemap			= xfs_vn_fiemap, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | }; | 
|  | 602 |  | 
| Christoph Hellwig | 41be8be | 2008-08-13 16:23:13 +1000 | [diff] [blame] | 603 | static const struct inode_operations xfs_dir_inode_operations = { | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 604 | .create			= xfs_vn_create, | 
|  | 605 | .lookup			= xfs_vn_lookup, | 
|  | 606 | .link			= xfs_vn_link, | 
|  | 607 | .unlink			= xfs_vn_unlink, | 
|  | 608 | .symlink		= xfs_vn_symlink, | 
|  | 609 | .mkdir			= xfs_vn_mkdir, | 
| Christoph Hellwig | 8f112e3 | 2008-06-23 13:25:17 +1000 | [diff] [blame] | 610 | /* | 
|  | 611 | * Yes, XFS uses the same method for rmdir and unlink. | 
|  | 612 | * | 
|  | 613 | * There are some subtile differences deeper in the code, | 
|  | 614 | * but we use S_ISDIR to check for those. | 
|  | 615 | */ | 
|  | 616 | .rmdir			= xfs_vn_unlink, | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 617 | .mknod			= xfs_vn_mknod, | 
|  | 618 | .rename			= xfs_vn_rename, | 
| Linus Torvalds | 18f4c64 | 2009-08-28 12:29:03 -0700 | [diff] [blame] | 619 | .check_acl		= xfs_check_acl, | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 620 | .getattr		= xfs_vn_getattr, | 
|  | 621 | .setattr		= xfs_vn_setattr, | 
| Lachlan McIlroy | 0ec5851 | 2008-06-23 13:23:01 +1000 | [diff] [blame] | 622 | .setxattr		= generic_setxattr, | 
|  | 623 | .getxattr		= generic_getxattr, | 
|  | 624 | .removexattr		= generic_removexattr, | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 625 | .listxattr		= xfs_vn_listxattr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | }; | 
|  | 627 |  | 
| Christoph Hellwig | 41be8be | 2008-08-13 16:23:13 +1000 | [diff] [blame] | 628 | static const struct inode_operations xfs_dir_ci_inode_operations = { | 
| Barry Naujok | 384f3ce | 2008-05-21 16:58:22 +1000 | [diff] [blame] | 629 | .create			= xfs_vn_create, | 
|  | 630 | .lookup			= xfs_vn_ci_lookup, | 
|  | 631 | .link			= xfs_vn_link, | 
|  | 632 | .unlink			= xfs_vn_unlink, | 
|  | 633 | .symlink		= xfs_vn_symlink, | 
|  | 634 | .mkdir			= xfs_vn_mkdir, | 
| Christoph Hellwig | 8f112e3 | 2008-06-23 13:25:17 +1000 | [diff] [blame] | 635 | /* | 
|  | 636 | * Yes, XFS uses the same method for rmdir and unlink. | 
|  | 637 | * | 
|  | 638 | * There are some subtile differences deeper in the code, | 
|  | 639 | * but we use S_ISDIR to check for those. | 
|  | 640 | */ | 
|  | 641 | .rmdir			= xfs_vn_unlink, | 
| Barry Naujok | 384f3ce | 2008-05-21 16:58:22 +1000 | [diff] [blame] | 642 | .mknod			= xfs_vn_mknod, | 
|  | 643 | .rename			= xfs_vn_rename, | 
| Linus Torvalds | 18f4c64 | 2009-08-28 12:29:03 -0700 | [diff] [blame] | 644 | .check_acl		= xfs_check_acl, | 
| Barry Naujok | 384f3ce | 2008-05-21 16:58:22 +1000 | [diff] [blame] | 645 | .getattr		= xfs_vn_getattr, | 
|  | 646 | .setattr		= xfs_vn_setattr, | 
| Lachlan McIlroy | 0ec5851 | 2008-06-23 13:23:01 +1000 | [diff] [blame] | 647 | .setxattr		= generic_setxattr, | 
|  | 648 | .getxattr		= generic_getxattr, | 
|  | 649 | .removexattr		= generic_removexattr, | 
| Barry Naujok | 384f3ce | 2008-05-21 16:58:22 +1000 | [diff] [blame] | 650 | .listxattr		= xfs_vn_listxattr, | 
| Barry Naujok | 384f3ce | 2008-05-21 16:58:22 +1000 | [diff] [blame] | 651 | }; | 
|  | 652 |  | 
| Christoph Hellwig | 41be8be | 2008-08-13 16:23:13 +1000 | [diff] [blame] | 653 | static const struct inode_operations xfs_symlink_inode_operations = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | .readlink		= generic_readlink, | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 655 | .follow_link		= xfs_vn_follow_link, | 
|  | 656 | .put_link		= xfs_vn_put_link, | 
| Linus Torvalds | 18f4c64 | 2009-08-28 12:29:03 -0700 | [diff] [blame] | 657 | .check_acl		= xfs_check_acl, | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 658 | .getattr		= xfs_vn_getattr, | 
|  | 659 | .setattr		= xfs_vn_setattr, | 
| Lachlan McIlroy | 0ec5851 | 2008-06-23 13:23:01 +1000 | [diff] [blame] | 660 | .setxattr		= generic_setxattr, | 
|  | 661 | .getxattr		= generic_getxattr, | 
|  | 662 | .removexattr		= generic_removexattr, | 
| Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 663 | .listxattr		= xfs_vn_listxattr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | }; | 
| Christoph Hellwig | 41be8be | 2008-08-13 16:23:13 +1000 | [diff] [blame] | 665 |  | 
|  | 666 | STATIC void | 
|  | 667 | xfs_diflags_to_iflags( | 
|  | 668 | struct inode		*inode, | 
|  | 669 | struct xfs_inode	*ip) | 
|  | 670 | { | 
|  | 671 | if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE) | 
|  | 672 | inode->i_flags |= S_IMMUTABLE; | 
|  | 673 | else | 
|  | 674 | inode->i_flags &= ~S_IMMUTABLE; | 
|  | 675 | if (ip->i_d.di_flags & XFS_DIFLAG_APPEND) | 
|  | 676 | inode->i_flags |= S_APPEND; | 
|  | 677 | else | 
|  | 678 | inode->i_flags &= ~S_APPEND; | 
|  | 679 | if (ip->i_d.di_flags & XFS_DIFLAG_SYNC) | 
|  | 680 | inode->i_flags |= S_SYNC; | 
|  | 681 | else | 
|  | 682 | inode->i_flags &= ~S_SYNC; | 
|  | 683 | if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME) | 
|  | 684 | inode->i_flags |= S_NOATIME; | 
|  | 685 | else | 
|  | 686 | inode->i_flags &= ~S_NOATIME; | 
|  | 687 | } | 
|  | 688 |  | 
|  | 689 | /* | 
|  | 690 | * Initialize the Linux inode, set up the operation vectors and | 
|  | 691 | * unlock the inode. | 
|  | 692 | * | 
|  | 693 | * When reading existing inodes from disk this is called directly | 
|  | 694 | * from xfs_iget, when creating a new inode it is called from | 
|  | 695 | * xfs_ialloc after setting up the inode. | 
| David Chinner | bf90424 | 2008-10-30 17:36:14 +1100 | [diff] [blame] | 696 | * | 
|  | 697 | * We are always called with an uninitialised linux inode here. | 
|  | 698 | * We need to initialise the necessary fields and take a reference | 
|  | 699 | * on it. | 
| Christoph Hellwig | 41be8be | 2008-08-13 16:23:13 +1000 | [diff] [blame] | 700 | */ | 
|  | 701 | void | 
|  | 702 | xfs_setup_inode( | 
|  | 703 | struct xfs_inode	*ip) | 
|  | 704 | { | 
| David Chinner | bf90424 | 2008-10-30 17:36:14 +1100 | [diff] [blame] | 705 | struct inode		*inode = &ip->i_vnode; | 
|  | 706 |  | 
|  | 707 | inode->i_ino = ip->i_ino; | 
| Christoph Hellwig | eaff807 | 2009-12-17 14:25:01 +0100 | [diff] [blame] | 708 | inode->i_state = I_NEW; | 
| Christoph Hellwig | 646ec46 | 2010-10-23 07:15:32 -0400 | [diff] [blame] | 709 |  | 
|  | 710 | inode_sb_list_add(inode); | 
| Christoph Hellwig | c6f6cd0 | 2010-11-06 11:43:08 +0000 | [diff] [blame] | 711 | /* make the inode look hashed for the writeback code */ | 
|  | 712 | hlist_add_fake(&inode->i_hash); | 
| Christoph Hellwig | 41be8be | 2008-08-13 16:23:13 +1000 | [diff] [blame] | 713 |  | 
|  | 714 | inode->i_mode	= ip->i_d.di_mode; | 
|  | 715 | inode->i_nlink	= ip->i_d.di_nlink; | 
|  | 716 | inode->i_uid	= ip->i_d.di_uid; | 
|  | 717 | inode->i_gid	= ip->i_d.di_gid; | 
|  | 718 |  | 
|  | 719 | switch (inode->i_mode & S_IFMT) { | 
|  | 720 | case S_IFBLK: | 
|  | 721 | case S_IFCHR: | 
|  | 722 | inode->i_rdev = | 
|  | 723 | MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff, | 
|  | 724 | sysv_minor(ip->i_df.if_u2.if_rdev)); | 
|  | 725 | break; | 
|  | 726 | default: | 
|  | 727 | inode->i_rdev = 0; | 
|  | 728 | break; | 
|  | 729 | } | 
|  | 730 |  | 
|  | 731 | inode->i_generation = ip->i_d.di_gen; | 
|  | 732 | i_size_write(inode, ip->i_d.di_size); | 
|  | 733 | inode->i_atime.tv_sec	= ip->i_d.di_atime.t_sec; | 
|  | 734 | inode->i_atime.tv_nsec	= ip->i_d.di_atime.t_nsec; | 
|  | 735 | inode->i_mtime.tv_sec	= ip->i_d.di_mtime.t_sec; | 
|  | 736 | inode->i_mtime.tv_nsec	= ip->i_d.di_mtime.t_nsec; | 
|  | 737 | inode->i_ctime.tv_sec	= ip->i_d.di_ctime.t_sec; | 
|  | 738 | inode->i_ctime.tv_nsec	= ip->i_d.di_ctime.t_nsec; | 
|  | 739 | xfs_diflags_to_iflags(inode, ip); | 
| Christoph Hellwig | 41be8be | 2008-08-13 16:23:13 +1000 | [diff] [blame] | 740 |  | 
|  | 741 | switch (inode->i_mode & S_IFMT) { | 
|  | 742 | case S_IFREG: | 
|  | 743 | inode->i_op = &xfs_inode_operations; | 
|  | 744 | inode->i_fop = &xfs_file_operations; | 
|  | 745 | inode->i_mapping->a_ops = &xfs_address_space_operations; | 
|  | 746 | break; | 
|  | 747 | case S_IFDIR: | 
|  | 748 | if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb)) | 
|  | 749 | inode->i_op = &xfs_dir_ci_inode_operations; | 
|  | 750 | else | 
|  | 751 | inode->i_op = &xfs_dir_inode_operations; | 
|  | 752 | inode->i_fop = &xfs_dir_file_operations; | 
|  | 753 | break; | 
|  | 754 | case S_IFLNK: | 
|  | 755 | inode->i_op = &xfs_symlink_inode_operations; | 
|  | 756 | if (!(ip->i_df.if_flags & XFS_IFINLINE)) | 
|  | 757 | inode->i_mapping->a_ops = &xfs_address_space_operations; | 
|  | 758 | break; | 
|  | 759 | default: | 
|  | 760 | inode->i_op = &xfs_inode_operations; | 
|  | 761 | init_special_inode(inode, inode->i_mode, inode->i_rdev); | 
|  | 762 | break; | 
|  | 763 | } | 
|  | 764 |  | 
|  | 765 | xfs_iflags_clear(ip, XFS_INEW); | 
|  | 766 | barrier(); | 
|  | 767 |  | 
|  | 768 | unlock_new_inode(inode); | 
|  | 769 | } |