2 * Copyright (c) 2000-2004 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>
56 #include <linux/smp_lock.h>
58 static struct vm_operations_struct linvfs_file_vm_ops;
69 struct iovec iov = {buf, count};
70 struct file *file = iocb->ki_filp;
71 vnode_t *vp = LINVFS_GET_VP(file->f_dentry->d_inode);
74 BUG_ON(iocb->ki_pos != pos);
76 if (unlikely(file->f_flags & O_DIRECT))
77 ioflags |= IO_ISDIRECT;
78 VOP_READ(vp, iocb, &iov, 1, &iocb->ki_pos, ioflags, NULL, rval);
90 return __linvfs_read(iocb, buf, 0, count, pos);
100 return __linvfs_read(iocb, buf, IO_INVIS, count, pos);
104 STATIC inline ssize_t
112 struct iovec iov = {(void *)buf, count};
113 struct file *file = iocb->ki_filp;
114 struct inode *inode = file->f_mapping->host;
115 vnode_t *vp = LINVFS_GET_VP(inode);
118 BUG_ON(iocb->ki_pos != pos);
119 if (unlikely(file->f_flags & O_DIRECT)) {
120 ioflags |= IO_ISDIRECT;
121 VOP_WRITE(vp, iocb, &iov, 1, &iocb->ki_pos,
122 ioflags, NULL, rval);
125 VOP_WRITE(vp, iocb, &iov, 1, &iocb->ki_pos,
126 ioflags, NULL, rval);
137 const char __user *buf,
141 return __linvfs_write(iocb, buf, 0, count, pos);
147 const char __user *buf,
151 return __linvfs_write(iocb, buf, IO_INVIS, count, pos);
155 STATIC inline ssize_t
158 const struct iovec *iov,
160 unsigned long nr_segs,
163 struct inode *inode = file->f_mapping->host;
164 vnode_t *vp = LINVFS_GET_VP(inode);
168 init_sync_kiocb(&kiocb, file);
169 kiocb.ki_pos = *ppos;
171 if (unlikely(file->f_flags & O_DIRECT))
172 ioflags |= IO_ISDIRECT;
173 VOP_READ(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos, ioflags, NULL, rval);
174 if (rval == -EIOCBQUEUED)
175 rval = wait_on_sync_kiocb(&kiocb);
177 *ppos = kiocb.ki_pos;
184 const struct iovec *iov,
185 unsigned long nr_segs,
188 return __linvfs_readv(file, iov, 0, nr_segs, ppos);
194 const struct iovec *iov,
195 unsigned long nr_segs,
198 return __linvfs_readv(file, iov, IO_INVIS, nr_segs, ppos);
202 STATIC inline ssize_t
205 const struct iovec *iov,
207 unsigned long nr_segs,
210 struct inode *inode = file->f_mapping->host;
211 vnode_t *vp = LINVFS_GET_VP(inode);
215 init_sync_kiocb(&kiocb, file);
216 kiocb.ki_pos = *ppos;
217 if (unlikely(file->f_flags & O_DIRECT)) {
218 ioflags |= IO_ISDIRECT;
219 VOP_WRITE(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos,
220 ioflags, NULL, rval);
223 VOP_WRITE(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos,
224 ioflags, NULL, rval);
228 if (rval == -EIOCBQUEUED)
229 rval = wait_on_sync_kiocb(&kiocb);
231 *ppos = kiocb.ki_pos;
239 const struct iovec *iov,
240 unsigned long nr_segs,
243 return __linvfs_writev(file, iov, 0, nr_segs, ppos);
249 const struct iovec *iov,
250 unsigned long nr_segs,
253 return __linvfs_writev(file, iov, IO_INVIS, nr_segs, ppos);
264 vnode_t *vp = LINVFS_GET_VP(filp->f_dentry->d_inode);
267 VOP_SENDFILE(vp, filp, ppos, 0, count, actor, target, NULL, rval);
277 vnode_t *vp = LINVFS_GET_VP(inode);
280 if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
284 VOP_OPEN(vp, NULL, error);
294 vnode_t *vp = LINVFS_GET_VP(inode);
298 VOP_RELEASE(vp, error);
306 struct dentry *dentry,
309 struct inode *inode = dentry->d_inode;
310 vnode_t *vp = LINVFS_GET_VP(inode);
312 int flags = FSYNC_WAIT;
318 VOP_FSYNC(vp, flags, NULL, (xfs_off_t)0, (xfs_off_t)-1, error);
323 * linvfs_readdir maps to VOP_READDIR().
324 * We need to build a uio, cred, ...
327 #define nextdp(dp) ((struct xfs_dirent *)((char *)(dp) + (dp)->d_reclen))
341 int namelen, size = 0;
342 size_t rlen = PAGE_CACHE_SIZE;
343 xfs_off_t start_offset, curr_offset;
344 xfs_dirent_t *dbp = NULL;
346 vp = LINVFS_GET_VP(filp->f_dentry->d_inode);
349 /* Try fairly hard to get memory */
351 if ((read_buf = (caddr_t)kmalloc(rlen, GFP_KERNEL)))
354 } while (rlen >= 1024);
356 if (read_buf == NULL)
360 uio.uio_segflg = UIO_SYSSPACE;
361 curr_offset = filp->f_pos;
362 if (filp->f_pos != 0x7fffffff)
363 uio.uio_offset = filp->f_pos;
365 uio.uio_offset = 0xffffffff;
368 uio.uio_resid = iov.iov_len = rlen;
369 iov.iov_base = read_buf;
372 start_offset = uio.uio_offset;
374 VOP_READDIR(vp, &uio, NULL, &eof, error);
375 if ((uio.uio_offset == start_offset) || error) {
380 size = rlen - uio.uio_resid;
381 dbp = (xfs_dirent_t *)read_buf;
383 namelen = strlen(dbp->d_name);
385 if (filldir(dirent, dbp->d_name, namelen,
386 (loff_t) curr_offset & 0x7fffffff,
391 size -= dbp->d_reclen;
392 curr_offset = (loff_t)dbp->d_off /* & 0x7fffffff */;
399 filp->f_pos = uio.uio_offset & 0x7fffffff;
401 filp->f_pos = curr_offset;
412 struct vm_area_struct *vma)
414 struct inode *ip = filp->f_dentry->d_inode;
415 vnode_t *vp = LINVFS_GET_VP(ip);
416 vattr_t va = { .va_mask = XFS_AT_UPDATIME };
419 if ((vp->v_type == VREG) && (vp->v_vfsp->vfs_flag & VFS_DMI)) {
420 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
422 error = -XFS_SEND_MMAP(mp, vma, 0);
427 vma->vm_ops = &linvfs_file_vm_ops;
429 VOP_SETATTR(vp, &va, XFS_AT_UPDATIME, NULL, error);
442 vnode_t *vp = LINVFS_GET_VP(inode);
445 VOP_IOCTL(vp, inode, filp, 0, cmd, arg, error);
449 /* NOTE: some of the ioctl's return positive #'s as a
450 * byte count indicating success, such as
451 * readlink_by_handle. So we don't "sign flip"
452 * like most other routines. This means true
453 * errors need to be returned as a negative value.
466 vnode_t *vp = LINVFS_GET_VP(inode);
470 VOP_IOCTL(vp, inode, filp, IO_INVIS, cmd, arg, error);
474 /* NOTE: some of the ioctl's return positive #'s as a
475 * byte count indicating success, such as
476 * readlink_by_handle. So we don't "sign flip"
477 * like most other routines. This means true
478 * errors need to be returned as a negative value.
483 #ifdef HAVE_VMOP_MPROTECT
486 struct vm_area_struct *vma,
487 unsigned int newflags)
489 vnode_t *vp = LINVFS_GET_VP(vma->vm_file->f_dentry->d_inode);
492 if ((vp->v_type == VREG) && (vp->v_vfsp->vfs_flag & VFS_DMI)) {
493 if ((vma->vm_flags & VM_MAYSHARE) &&
494 (newflags & VM_WRITE) && !(vma->vm_flags & VM_WRITE)) {
495 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
497 error = XFS_SEND_MMAP(mp, vma, VM_WRITE);
502 #endif /* HAVE_VMOP_MPROTECT */
505 struct file_operations linvfs_file_operations = {
506 .llseek = generic_file_llseek,
507 .read = do_sync_read,
508 .write = do_sync_write,
509 .readv = linvfs_readv,
510 .writev = linvfs_writev,
511 .aio_read = linvfs_read,
512 .aio_write = linvfs_write,
513 .sendfile = linvfs_sendfile,
514 .ioctl = linvfs_ioctl,
515 .mmap = linvfs_file_mmap,
517 .release = linvfs_release,
518 .fsync = linvfs_fsync,
521 struct file_operations linvfs_invis_file_operations = {
522 .llseek = generic_file_llseek,
523 .read = do_sync_read,
524 .write = do_sync_write,
525 .readv = linvfs_readv_invis,
526 .writev = linvfs_writev_invis,
527 .aio_read = linvfs_read_invis,
528 .aio_write = linvfs_write_invis,
529 .sendfile = linvfs_sendfile,
530 .ioctl = linvfs_ioctl_invis,
531 .mmap = linvfs_file_mmap,
533 .release = linvfs_release,
534 .fsync = linvfs_fsync,
538 struct file_operations linvfs_dir_operations = {
539 .read = generic_read_dir,
540 .readdir = linvfs_readdir,
541 .ioctl = linvfs_ioctl,
542 .fsync = linvfs_fsync,
545 static struct vm_operations_struct linvfs_file_vm_ops = {
546 .nopage = filemap_nopage,
547 #ifdef HAVE_VMOP_MPROTECT
548 .mprotect = linvfs_mprotect,