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" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 19 | #include "xfs_bit.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include "xfs_log.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 21 | #include "xfs_inum.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include "xfs_sb.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 23 | #include "xfs_ag.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include "xfs_dir.h" |
| 25 | #include "xfs_dir2.h" |
| 26 | #include "xfs_trans.h" |
| 27 | #include "xfs_dmapi.h" |
| 28 | #include "xfs_mount.h" |
| 29 | #include "xfs_bmap_btree.h" |
| 30 | #include "xfs_alloc_btree.h" |
| 31 | #include "xfs_ialloc_btree.h" |
| 32 | #include "xfs_alloc.h" |
| 33 | #include "xfs_btree.h" |
| 34 | #include "xfs_attr_sf.h" |
| 35 | #include "xfs_dir_sf.h" |
| 36 | #include "xfs_dir2_sf.h" |
| 37 | #include "xfs_dinode.h" |
| 38 | #include "xfs_inode.h" |
| 39 | #include "xfs_error.h" |
| 40 | #include "xfs_rw.h" |
| 41 | #include "xfs_ioctl32.h" |
| 42 | |
| 43 | #include <linux/dcache.h> |
| 44 | #include <linux/smp_lock.h> |
| 45 | |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 46 | static struct vm_operations_struct xfs_file_vm_ops; |
Dean Roehrich | 6fac0cb | 2005-06-21 14:07:45 +1000 | [diff] [blame] | 47 | #ifdef CONFIG_XFS_DMAPI |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 48 | static struct vm_operations_struct xfs_dmapi_file_vm_ops; |
Dean Roehrich | 6fac0cb | 2005-06-21 14:07:45 +1000 | [diff] [blame] | 49 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | STATIC inline ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 52 | __xfs_file_read( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | struct kiocb *iocb, |
| 54 | char __user *buf, |
| 55 | int ioflags, |
| 56 | size_t count, |
| 57 | loff_t pos) |
| 58 | { |
| 59 | struct iovec iov = {buf, count}; |
| 60 | struct file *file = iocb->ki_filp; |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 61 | vnode_t *vp = vn_from_inode(file->f_dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | ssize_t rval; |
| 63 | |
| 64 | BUG_ON(iocb->ki_pos != pos); |
| 65 | |
| 66 | if (unlikely(file->f_flags & O_DIRECT)) |
| 67 | ioflags |= IO_ISDIRECT; |
| 68 | VOP_READ(vp, iocb, &iov, 1, &iocb->ki_pos, ioflags, NULL, rval); |
| 69 | return rval; |
| 70 | } |
| 71 | |
| 72 | |
| 73 | STATIC ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 74 | xfs_file_aio_read( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | struct kiocb *iocb, |
| 76 | char __user *buf, |
| 77 | size_t count, |
| 78 | loff_t pos) |
| 79 | { |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 80 | return __xfs_file_read(iocb, buf, IO_ISAIO, count, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | STATIC ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 84 | xfs_file_aio_read_invis( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | struct kiocb *iocb, |
| 86 | char __user *buf, |
| 87 | size_t count, |
| 88 | loff_t pos) |
| 89 | { |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 90 | return __xfs_file_read(iocb, buf, IO_ISAIO|IO_INVIS, count, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | |
| 94 | STATIC inline ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 95 | __xfs_file_write( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | struct kiocb *iocb, |
| 97 | const char __user *buf, |
| 98 | int ioflags, |
| 99 | size_t count, |
| 100 | loff_t pos) |
| 101 | { |
| 102 | struct iovec iov = {(void __user *)buf, count}; |
| 103 | struct file *file = iocb->ki_filp; |
| 104 | struct inode *inode = file->f_mapping->host; |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 105 | vnode_t *vp = vn_from_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | ssize_t rval; |
| 107 | |
| 108 | BUG_ON(iocb->ki_pos != pos); |
| 109 | if (unlikely(file->f_flags & O_DIRECT)) |
| 110 | ioflags |= IO_ISDIRECT; |
| 111 | |
| 112 | VOP_WRITE(vp, iocb, &iov, 1, &iocb->ki_pos, ioflags, NULL, rval); |
| 113 | return rval; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | STATIC ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 118 | xfs_file_aio_write( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | struct kiocb *iocb, |
| 120 | const char __user *buf, |
| 121 | size_t count, |
| 122 | loff_t pos) |
| 123 | { |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 124 | return __xfs_file_write(iocb, buf, IO_ISAIO, count, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | STATIC ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 128 | xfs_file_aio_write_invis( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | struct kiocb *iocb, |
| 130 | const char __user *buf, |
| 131 | size_t count, |
| 132 | loff_t pos) |
| 133 | { |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 134 | return __xfs_file_write(iocb, buf, IO_ISAIO|IO_INVIS, count, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | |
| 138 | STATIC inline ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 139 | __xfs_file_readv( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | struct file *file, |
| 141 | const struct iovec *iov, |
| 142 | int ioflags, |
| 143 | unsigned long nr_segs, |
| 144 | loff_t *ppos) |
| 145 | { |
| 146 | struct inode *inode = file->f_mapping->host; |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 147 | vnode_t *vp = vn_from_inode(inode); |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 148 | struct kiocb kiocb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | ssize_t rval; |
| 150 | |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 151 | init_sync_kiocb(&kiocb, file); |
| 152 | kiocb.ki_pos = *ppos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | if (unlikely(file->f_flags & O_DIRECT)) |
| 155 | ioflags |= IO_ISDIRECT; |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 156 | VOP_READ(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos, ioflags, NULL, rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 158 | *ppos = kiocb.ki_pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | return rval; |
| 160 | } |
| 161 | |
| 162 | STATIC ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 163 | xfs_file_readv( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | struct file *file, |
| 165 | const struct iovec *iov, |
| 166 | unsigned long nr_segs, |
| 167 | loff_t *ppos) |
| 168 | { |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 169 | return __xfs_file_readv(file, iov, 0, nr_segs, ppos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | STATIC ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 173 | xfs_file_readv_invis( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | struct file *file, |
| 175 | const struct iovec *iov, |
| 176 | unsigned long nr_segs, |
| 177 | loff_t *ppos) |
| 178 | { |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 179 | return __xfs_file_readv(file, iov, IO_INVIS, nr_segs, ppos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | |
| 183 | STATIC inline ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 184 | __xfs_file_writev( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | struct file *file, |
| 186 | const struct iovec *iov, |
| 187 | int ioflags, |
| 188 | unsigned long nr_segs, |
| 189 | loff_t *ppos) |
| 190 | { |
| 191 | struct inode *inode = file->f_mapping->host; |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 192 | vnode_t *vp = vn_from_inode(inode); |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 193 | struct kiocb kiocb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | ssize_t rval; |
| 195 | |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 196 | init_sync_kiocb(&kiocb, file); |
| 197 | kiocb.ki_pos = *ppos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | if (unlikely(file->f_flags & O_DIRECT)) |
| 199 | ioflags |= IO_ISDIRECT; |
| 200 | |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 201 | VOP_WRITE(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos, ioflags, NULL, rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 203 | *ppos = kiocb.ki_pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | return rval; |
| 205 | } |
| 206 | |
| 207 | |
| 208 | STATIC ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 209 | xfs_file_writev( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | struct file *file, |
| 211 | const struct iovec *iov, |
| 212 | unsigned long nr_segs, |
| 213 | loff_t *ppos) |
| 214 | { |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 215 | return __xfs_file_writev(file, iov, 0, nr_segs, ppos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | STATIC ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 219 | xfs_file_writev_invis( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | struct file *file, |
| 221 | const struct iovec *iov, |
| 222 | unsigned long nr_segs, |
| 223 | loff_t *ppos) |
| 224 | { |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 225 | return __xfs_file_writev(file, iov, IO_INVIS, nr_segs, ppos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | STATIC ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 229 | xfs_file_sendfile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | struct file *filp, |
| 231 | loff_t *ppos, |
| 232 | size_t count, |
| 233 | read_actor_t actor, |
| 234 | void *target) |
| 235 | { |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 236 | vnode_t *vp = vn_from_inode(filp->f_dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | ssize_t rval; |
| 238 | |
| 239 | VOP_SENDFILE(vp, filp, ppos, 0, count, actor, target, NULL, rval); |
| 240 | return rval; |
| 241 | } |
| 242 | |
| 243 | |
| 244 | STATIC int |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 245 | xfs_file_open( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | struct inode *inode, |
| 247 | struct file *filp) |
| 248 | { |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 249 | vnode_t *vp = vn_from_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | int error; |
| 251 | |
| 252 | if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS) |
| 253 | return -EFBIG; |
| 254 | |
| 255 | ASSERT(vp); |
| 256 | VOP_OPEN(vp, NULL, error); |
| 257 | return -error; |
| 258 | } |
| 259 | |
| 260 | |
| 261 | STATIC int |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 262 | xfs_file_release( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | struct inode *inode, |
| 264 | struct file *filp) |
| 265 | { |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 266 | vnode_t *vp = vn_from_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | int error = 0; |
| 268 | |
| 269 | if (vp) |
| 270 | VOP_RELEASE(vp, error); |
| 271 | return -error; |
| 272 | } |
| 273 | |
| 274 | |
| 275 | STATIC int |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 276 | xfs_file_fsync( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | struct file *filp, |
| 278 | struct dentry *dentry, |
| 279 | int datasync) |
| 280 | { |
| 281 | struct inode *inode = dentry->d_inode; |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 282 | vnode_t *vp = vn_from_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | int error; |
| 284 | int flags = FSYNC_WAIT; |
| 285 | |
| 286 | if (datasync) |
| 287 | flags |= FSYNC_DATA; |
| 288 | |
| 289 | ASSERT(vp); |
| 290 | VOP_FSYNC(vp, flags, NULL, (xfs_off_t)0, (xfs_off_t)-1, error); |
| 291 | return -error; |
| 292 | } |
| 293 | |
| 294 | /* |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 295 | * xfs_file_readdir maps to VOP_READDIR(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | * We need to build a uio, cred, ... |
| 297 | */ |
| 298 | |
| 299 | #define nextdp(dp) ((struct xfs_dirent *)((char *)(dp) + (dp)->d_reclen)) |
| 300 | |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 301 | #ifdef CONFIG_XFS_DMAPI |
| 302 | |
| 303 | STATIC struct page * |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 304 | xfs_vm_nopage( |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 305 | struct vm_area_struct *area, |
| 306 | unsigned long address, |
| 307 | int *type) |
| 308 | { |
| 309 | struct inode *inode = area->vm_file->f_dentry->d_inode; |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 310 | vnode_t *vp = vn_from_inode(inode); |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 311 | xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp); |
| 312 | int error; |
| 313 | |
| 314 | ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI); |
| 315 | |
| 316 | error = XFS_SEND_MMAP(mp, area, 0); |
| 317 | if (error) |
| 318 | return NULL; |
| 319 | |
| 320 | return filemap_nopage(area, address, type); |
| 321 | } |
| 322 | |
| 323 | #endif /* CONFIG_XFS_DMAPI */ |
| 324 | |
| 325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | STATIC int |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 327 | xfs_file_readdir( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | struct file *filp, |
| 329 | void *dirent, |
| 330 | filldir_t filldir) |
| 331 | { |
| 332 | int error = 0; |
| 333 | vnode_t *vp; |
| 334 | uio_t uio; |
| 335 | iovec_t iov; |
| 336 | int eof = 0; |
| 337 | caddr_t read_buf; |
| 338 | int namelen, size = 0; |
| 339 | size_t rlen = PAGE_CACHE_SIZE; |
| 340 | xfs_off_t start_offset, curr_offset; |
| 341 | xfs_dirent_t *dbp = NULL; |
| 342 | |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 343 | vp = vn_from_inode(filp->f_dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | ASSERT(vp); |
| 345 | |
| 346 | /* Try fairly hard to get memory */ |
| 347 | do { |
| 348 | if ((read_buf = (caddr_t)kmalloc(rlen, GFP_KERNEL))) |
| 349 | break; |
| 350 | rlen >>= 1; |
| 351 | } while (rlen >= 1024); |
| 352 | |
| 353 | if (read_buf == NULL) |
| 354 | return -ENOMEM; |
| 355 | |
| 356 | uio.uio_iov = &iov; |
| 357 | uio.uio_segflg = UIO_SYSSPACE; |
| 358 | curr_offset = filp->f_pos; |
| 359 | if (filp->f_pos != 0x7fffffff) |
| 360 | uio.uio_offset = filp->f_pos; |
| 361 | else |
| 362 | uio.uio_offset = 0xffffffff; |
| 363 | |
| 364 | while (!eof) { |
| 365 | uio.uio_resid = iov.iov_len = rlen; |
| 366 | iov.iov_base = read_buf; |
| 367 | uio.uio_iovcnt = 1; |
| 368 | |
| 369 | start_offset = uio.uio_offset; |
| 370 | |
| 371 | VOP_READDIR(vp, &uio, NULL, &eof, error); |
| 372 | if ((uio.uio_offset == start_offset) || error) { |
| 373 | size = 0; |
| 374 | break; |
| 375 | } |
| 376 | |
| 377 | size = rlen - uio.uio_resid; |
| 378 | dbp = (xfs_dirent_t *)read_buf; |
| 379 | while (size > 0) { |
| 380 | namelen = strlen(dbp->d_name); |
| 381 | |
| 382 | if (filldir(dirent, dbp->d_name, namelen, |
| 383 | (loff_t) curr_offset & 0x7fffffff, |
| 384 | (ino_t) dbp->d_ino, |
| 385 | DT_UNKNOWN)) { |
| 386 | goto done; |
| 387 | } |
| 388 | size -= dbp->d_reclen; |
| 389 | curr_offset = (loff_t)dbp->d_off /* & 0x7fffffff */; |
| 390 | dbp = nextdp(dbp); |
| 391 | } |
| 392 | } |
| 393 | done: |
| 394 | if (!error) { |
| 395 | if (size == 0) |
| 396 | filp->f_pos = uio.uio_offset & 0x7fffffff; |
| 397 | else if (dbp) |
| 398 | filp->f_pos = curr_offset; |
| 399 | } |
| 400 | |
| 401 | kfree(read_buf); |
| 402 | return -error; |
| 403 | } |
| 404 | |
| 405 | |
| 406 | STATIC int |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 407 | xfs_file_mmap( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | struct file *filp, |
| 409 | struct vm_area_struct *vma) |
| 410 | { |
| 411 | struct inode *ip = filp->f_dentry->d_inode; |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 412 | vnode_t *vp = vn_from_inode(ip); |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 413 | vattr_t vattr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | int error; |
| 415 | |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 416 | vma->vm_ops = &xfs_file_vm_ops; |
Dean Roehrich | 6fac0cb | 2005-06-21 14:07:45 +1000 | [diff] [blame] | 417 | |
Dean Roehrich | 6fac0cb | 2005-06-21 14:07:45 +1000 | [diff] [blame] | 418 | #ifdef CONFIG_XFS_DMAPI |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 419 | if (vp->v_vfsp->vfs_flag & VFS_DMI) { |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 420 | vma->vm_ops = &xfs_dmapi_file_vm_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 422 | #endif /* CONFIG_XFS_DMAPI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 424 | vattr.va_mask = XFS_AT_UPDATIME; |
| 425 | VOP_SETATTR(vp, &vattr, XFS_AT_UPDATIME, NULL, error); |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 426 | if (likely(!error)) |
Nathan Scott | 524fbf5 | 2006-03-14 14:07:53 +1100 | [diff] [blame] | 427 | __vn_revalidate(vp, &vattr); /* update flags */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | |
| 432 | STATIC long |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 433 | xfs_file_ioctl( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | struct file *filp, |
| 435 | unsigned int cmd, |
| 436 | unsigned long arg) |
| 437 | { |
| 438 | int error; |
Nathan Scott | 1f6553f | 2006-03-14 13:30:48 +1100 | [diff] [blame] | 439 | struct inode *inode = filp->f_dentry->d_inode; |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 440 | vnode_t *vp = vn_from_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
| 442 | VOP_IOCTL(vp, inode, filp, 0, cmd, (void __user *)arg, error); |
| 443 | VMODIFY(vp); |
| 444 | |
| 445 | /* NOTE: some of the ioctl's return positive #'s as a |
| 446 | * byte count indicating success, such as |
| 447 | * readlink_by_handle. So we don't "sign flip" |
| 448 | * like most other routines. This means true |
| 449 | * errors need to be returned as a negative value. |
| 450 | */ |
| 451 | return error; |
| 452 | } |
| 453 | |
| 454 | STATIC long |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 455 | xfs_file_ioctl_invis( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | struct file *filp, |
| 457 | unsigned int cmd, |
| 458 | unsigned long arg) |
| 459 | { |
| 460 | int error; |
Nathan Scott | 1f6553f | 2006-03-14 13:30:48 +1100 | [diff] [blame] | 461 | struct inode *inode = filp->f_dentry->d_inode; |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 462 | vnode_t *vp = vn_from_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
| 464 | ASSERT(vp); |
| 465 | VOP_IOCTL(vp, inode, filp, IO_INVIS, cmd, (void __user *)arg, error); |
| 466 | VMODIFY(vp); |
| 467 | |
| 468 | /* NOTE: some of the ioctl's return positive #'s as a |
| 469 | * byte count indicating success, such as |
| 470 | * readlink_by_handle. So we don't "sign flip" |
| 471 | * like most other routines. This means true |
| 472 | * errors need to be returned as a negative value. |
| 473 | */ |
| 474 | return error; |
| 475 | } |
| 476 | |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 477 | #ifdef CONFIG_XFS_DMAPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | #ifdef HAVE_VMOP_MPROTECT |
| 479 | STATIC int |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 480 | xfs_vm_mprotect( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | struct vm_area_struct *vma, |
| 482 | unsigned int newflags) |
| 483 | { |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 484 | vnode_t *vp = vn_from_inode(vma->vm_file->f_dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | int error = 0; |
| 486 | |
| 487 | if (vp->v_vfsp->vfs_flag & VFS_DMI) { |
| 488 | if ((vma->vm_flags & VM_MAYSHARE) && |
| 489 | (newflags & VM_WRITE) && !(vma->vm_flags & VM_WRITE)) { |
| 490 | xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp); |
| 491 | |
| 492 | error = XFS_SEND_MMAP(mp, vma, VM_WRITE); |
| 493 | } |
| 494 | } |
| 495 | return error; |
| 496 | } |
| 497 | #endif /* HAVE_VMOP_MPROTECT */ |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 498 | #endif /* CONFIG_XFS_DMAPI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
| 500 | #ifdef HAVE_FOP_OPEN_EXEC |
| 501 | /* If the user is attempting to execute a file that is offline then |
| 502 | * we have to trigger a DMAPI READ event before the file is marked as busy |
| 503 | * otherwise the invisible I/O will not be able to write to the file to bring |
| 504 | * it back online. |
| 505 | */ |
| 506 | STATIC int |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 507 | xfs_file_open_exec( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | struct inode *inode) |
| 509 | { |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 510 | vnode_t *vp = vn_from_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp); |
| 512 | int error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | xfs_inode_t *ip; |
| 514 | |
| 515 | if (vp->v_vfsp->vfs_flag & VFS_DMI) { |
Christoph Hellwig | 75e17b3 | 2006-01-11 20:58:44 +1100 | [diff] [blame] | 516 | ip = xfs_vtoi(vp); |
| 517 | if (!ip) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | error = -EINVAL; |
| 519 | goto open_exec_out; |
| 520 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | if (DM_EVENT_ENABLED(vp->v_vfsp, ip, DM_EVENT_READ)) { |
| 522 | error = -XFS_SEND_DATA(mp, DM_EVENT_READ, vp, |
| 523 | 0, 0, 0, NULL); |
| 524 | } |
| 525 | } |
| 526 | open_exec_out: |
| 527 | return error; |
| 528 | } |
| 529 | #endif /* HAVE_FOP_OPEN_EXEC */ |
| 530 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 531 | const struct file_operations xfs_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | .llseek = generic_file_llseek, |
| 533 | .read = do_sync_read, |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 534 | .write = do_sync_write, |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 535 | .readv = xfs_file_readv, |
| 536 | .writev = xfs_file_writev, |
| 537 | .aio_read = xfs_file_aio_read, |
| 538 | .aio_write = xfs_file_aio_write, |
| 539 | .sendfile = xfs_file_sendfile, |
| 540 | .unlocked_ioctl = xfs_file_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | #ifdef CONFIG_COMPAT |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 542 | .compat_ioctl = xfs_file_compat_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | #endif |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 544 | .mmap = xfs_file_mmap, |
| 545 | .open = xfs_file_open, |
| 546 | .release = xfs_file_release, |
| 547 | .fsync = xfs_file_fsync, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | #ifdef HAVE_FOP_OPEN_EXEC |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 549 | .open_exec = xfs_file_open_exec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | #endif |
| 551 | }; |
| 552 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 553 | const struct file_operations xfs_invis_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | .llseek = generic_file_llseek, |
| 555 | .read = do_sync_read, |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 556 | .write = do_sync_write, |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 557 | .readv = xfs_file_readv_invis, |
| 558 | .writev = xfs_file_writev_invis, |
| 559 | .aio_read = xfs_file_aio_read_invis, |
| 560 | .aio_write = xfs_file_aio_write_invis, |
| 561 | .sendfile = xfs_file_sendfile, |
| 562 | .unlocked_ioctl = xfs_file_ioctl_invis, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | #ifdef CONFIG_COMPAT |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 564 | .compat_ioctl = xfs_file_compat_invis_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | #endif |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 566 | .mmap = xfs_file_mmap, |
| 567 | .open = xfs_file_open, |
| 568 | .release = xfs_file_release, |
| 569 | .fsync = xfs_file_fsync, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | }; |
| 571 | |
| 572 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 573 | const struct file_operations xfs_dir_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | .read = generic_read_dir, |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 575 | .readdir = xfs_file_readdir, |
| 576 | .unlocked_ioctl = xfs_file_ioctl, |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 577 | #ifdef CONFIG_COMPAT |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 578 | .compat_ioctl = xfs_file_compat_ioctl, |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 579 | #endif |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 580 | .fsync = xfs_file_fsync, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | }; |
| 582 | |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 583 | static struct vm_operations_struct xfs_file_vm_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | .nopage = filemap_nopage, |
| 585 | .populate = filemap_populate, |
Dean Roehrich | 6fac0cb | 2005-06-21 14:07:45 +1000 | [diff] [blame] | 586 | }; |
| 587 | |
| 588 | #ifdef CONFIG_XFS_DMAPI |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 589 | static struct vm_operations_struct xfs_dmapi_file_vm_ops = { |
| 590 | .nopage = xfs_vm_nopage, |
Dean Roehrich | 6fac0cb | 2005-06-21 14:07:45 +1000 | [diff] [blame] | 591 | .populate = filemap_populate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | #ifdef HAVE_VMOP_MPROTECT |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 593 | .mprotect = xfs_vm_mprotect, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | #endif |
| 595 | }; |
Dean Roehrich | 6fac0cb | 2005-06-21 14:07:45 +1000 | [diff] [blame] | 596 | #endif /* CONFIG_XFS_DMAPI */ |