2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
39 #include "xfs_trans.h"
40 #include "xfs_dmapi.h"
41 #include "xfs_mount.h"
42 #include "xfs_bmap_btree.h"
43 #include "xfs_alloc_btree.h"
44 #include "xfs_ialloc_btree.h"
45 #include "xfs_alloc.h"
46 #include "xfs_btree.h"
47 #include "xfs_attr_sf.h"
48 #include "xfs_dir_sf.h"
49 #include "xfs_dir2_sf.h"
50 #include "xfs_dinode.h"
51 #include "xfs_inode.h"
52 #include "xfs_error.h"
55 #include <linux/dcache.h>
57 static struct vm_operations_struct linvfs_file_vm_ops;
68 struct iovec iov = {buf, count};
69 struct file *file = iocb->ki_filp;
70 vnode_t *vp = LINVFS_GET_VP(file->f_dentry->d_inode);
73 BUG_ON(iocb->ki_pos != pos);
75 if (unlikely(file->f_flags & O_DIRECT))
76 ioflags |= IO_ISDIRECT;
77 VOP_READ(vp, iocb, &iov, 1, &iocb->ki_pos, ioflags, NULL, rval);
89 return __linvfs_read(iocb, buf, 0, count, pos);
99 return __linvfs_read(iocb, buf, IO_INVIS, count, pos);
103 STATIC inline ssize_t
111 struct iovec iov = {(void *)buf, count};
112 struct file *file = iocb->ki_filp;
113 struct inode *inode = file->f_mapping->host;
114 vnode_t *vp = LINVFS_GET_VP(inode);
117 BUG_ON(iocb->ki_pos != pos);
118 if (unlikely(file->f_flags & O_DIRECT)) {
119 ioflags |= IO_ISDIRECT;
120 VOP_WRITE(vp, iocb, &iov, 1, &iocb->ki_pos,
121 ioflags, NULL, rval);
124 VOP_WRITE(vp, iocb, &iov, 1, &iocb->ki_pos,
125 ioflags, NULL, rval);
136 const char __user *buf,
140 return __linvfs_write(iocb, buf, 0, count, pos);
146 const char __user *buf,
150 return __linvfs_write(iocb, buf, IO_INVIS, count, pos);
154 STATIC inline ssize_t
157 const struct iovec *iov,
159 unsigned long nr_segs,
162 struct inode *inode = file->f_mapping->host;
163 vnode_t *vp = LINVFS_GET_VP(inode);
167 init_sync_kiocb(&kiocb, file);
168 kiocb.ki_pos = *ppos;
170 if (unlikely(file->f_flags & O_DIRECT))
171 ioflags |= IO_ISDIRECT;
172 VOP_READ(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos, ioflags, NULL, rval);
173 if (rval == -EIOCBQUEUED)
174 rval = wait_on_sync_kiocb(&kiocb);
176 *ppos = kiocb.ki_pos;
183 const struct iovec *iov,
184 unsigned long nr_segs,
187 return __linvfs_readv(file, iov, 0, nr_segs, ppos);
193 const struct iovec *iov,
194 unsigned long nr_segs,
197 return __linvfs_readv(file, iov, IO_INVIS, nr_segs, ppos);
201 STATIC inline ssize_t
204 const struct iovec *iov,
206 unsigned long nr_segs,
209 struct inode *inode = file->f_mapping->host;
210 vnode_t *vp = LINVFS_GET_VP(inode);
214 init_sync_kiocb(&kiocb, file);
215 kiocb.ki_pos = *ppos;
216 if (unlikely(file->f_flags & O_DIRECT)) {
217 ioflags |= IO_ISDIRECT;
218 VOP_WRITE(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos,
219 ioflags, NULL, rval);
222 VOP_WRITE(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos,
223 ioflags, NULL, rval);
227 if (rval == -EIOCBQUEUED)
228 rval = wait_on_sync_kiocb(&kiocb);
230 *ppos = kiocb.ki_pos;
238 const struct iovec *iov,
239 unsigned long nr_segs,
242 return __linvfs_writev(file, iov, 0, nr_segs, ppos);
248 const struct iovec *iov,
249 unsigned long nr_segs,
252 return __linvfs_writev(file, iov, IO_INVIS, nr_segs, ppos);
263 vnode_t *vp = LINVFS_GET_VP(filp->f_dentry->d_inode);
266 VOP_SENDFILE(vp, filp, ppos, 0, count, actor, target, NULL, error);
276 vnode_t *vp = LINVFS_GET_VP(inode);
279 if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
283 VOP_OPEN(vp, NULL, error);
293 vnode_t *vp = LINVFS_GET_VP(inode);
297 VOP_RELEASE(vp, error);
305 struct dentry *dentry,
308 struct inode *inode = dentry->d_inode;
309 vnode_t *vp = LINVFS_GET_VP(inode);
311 int flags = FSYNC_WAIT;
317 VOP_FSYNC(vp, flags, NULL, (xfs_off_t)0, (xfs_off_t)-1, error);
322 * linvfs_readdir maps to VOP_READDIR().
323 * We need to build a uio, cred, ...
326 #define nextdp(dp) ((struct xfs_dirent *)((char *)(dp) + (dp)->d_reclen))
340 int namelen, size = 0;
341 size_t rlen = PAGE_CACHE_SIZE;
342 xfs_off_t start_offset, curr_offset;
343 xfs_dirent_t *dbp = NULL;
345 vp = LINVFS_GET_VP(filp->f_dentry->d_inode);
348 /* Try fairly hard to get memory */
350 if ((read_buf = (caddr_t)kmalloc(rlen, GFP_KERNEL)))
353 } while (rlen >= 1024);
355 if (read_buf == NULL)
359 uio.uio_segflg = UIO_SYSSPACE;
360 curr_offset = filp->f_pos;
361 if (filp->f_pos != 0x7fffffff)
362 uio.uio_offset = filp->f_pos;
364 uio.uio_offset = 0xffffffff;
367 uio.uio_resid = iov.iov_len = rlen;
368 iov.iov_base = read_buf;
371 start_offset = uio.uio_offset;
373 VOP_READDIR(vp, &uio, NULL, &eof, error);
374 if ((uio.uio_offset == start_offset) || error) {
379 size = rlen - uio.uio_resid;
380 dbp = (xfs_dirent_t *)read_buf;
382 namelen = strlen(dbp->d_name);
384 if (filldir(dirent, dbp->d_name, namelen,
385 (loff_t) curr_offset & 0x7fffffff,
390 size -= dbp->d_reclen;
391 curr_offset = (loff_t)dbp->d_off /* & 0x7fffffff */;
398 filp->f_pos = uio.uio_offset & 0x7fffffff;
400 filp->f_pos = curr_offset;
411 struct vm_area_struct *vma)
413 struct inode *ip = filp->f_dentry->d_inode;
414 vnode_t *vp = LINVFS_GET_VP(ip);
415 vattr_t va = { .va_mask = XFS_AT_UPDATIME };
418 if ((vp->v_type == VREG) && (vp->v_vfsp->vfs_flag & VFS_DMI)) {
419 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
421 error = -XFS_SEND_MMAP(mp, vma, 0);
426 vma->vm_ops = &linvfs_file_vm_ops;
428 VOP_SETATTR(vp, &va, XFS_AT_UPDATIME, NULL, error);
441 vnode_t *vp = LINVFS_GET_VP(inode);
444 VOP_IOCTL(vp, inode, filp, 0, cmd, arg, error);
447 /* NOTE: some of the ioctl's return positive #'s as a
448 * byte count indicating success, such as
449 * readlink_by_handle. So we don't "sign flip"
450 * like most other routines. This means true
451 * errors need to be returned as a negative value.
464 vnode_t *vp = LINVFS_GET_VP(inode);
467 VOP_IOCTL(vp, inode, filp, IO_INVIS, cmd, arg, error);
470 /* NOTE: some of the ioctl's return positive #'s as a
471 * byte count indicating success, such as
472 * readlink_by_handle. So we don't "sign flip"
473 * like most other routines. This means true
474 * errors need to be returned as a negative value.
479 #ifdef HAVE_VMOP_MPROTECT
482 struct vm_area_struct *vma,
483 unsigned int newflags)
485 vnode_t *vp = LINVFS_GET_VP(vma->vm_file->f_dentry->d_inode);
488 if ((vp->v_type == VREG) && (vp->v_vfsp->vfs_flag & VFS_DMI)) {
489 if ((vma->vm_flags & VM_MAYSHARE) &&
490 (newflags & VM_WRITE) && !(vma->vm_flags & VM_WRITE)) {
491 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
493 error = XFS_SEND_MMAP(mp, vma, VM_WRITE);
498 #endif /* HAVE_VMOP_MPROTECT */
501 struct file_operations linvfs_file_operations = {
502 .llseek = generic_file_llseek,
503 .read = do_sync_read,
504 .write = do_sync_write,
505 .readv = linvfs_readv,
506 .writev = linvfs_writev,
507 .aio_read = linvfs_read,
508 .aio_write = linvfs_write,
509 .sendfile = linvfs_sendfile,
510 .ioctl = linvfs_ioctl,
511 .mmap = linvfs_file_mmap,
513 .release = linvfs_release,
514 .fsync = linvfs_fsync,
517 struct file_operations linvfs_invis_file_operations = {
518 .llseek = generic_file_llseek,
519 .read = do_sync_read,
520 .write = do_sync_write,
521 .readv = linvfs_readv_invis,
522 .writev = linvfs_writev_invis,
523 .aio_read = linvfs_read_invis,
524 .aio_write = linvfs_write_invis,
525 .sendfile = linvfs_sendfile,
526 .ioctl = linvfs_ioctl_invis,
527 .mmap = linvfs_file_mmap,
529 .release = linvfs_release,
530 .fsync = linvfs_fsync,
534 struct file_operations linvfs_dir_operations = {
535 .read = generic_read_dir,
536 .readdir = linvfs_readdir,
537 .ioctl = linvfs_ioctl,
538 .fsync = linvfs_fsync,
541 static struct vm_operations_struct linvfs_file_vm_ops = {
542 .nopage = filemap_nopage,
543 #ifdef HAVE_VMOP_MPROTECT
544 .mprotect = linvfs_mprotect,