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