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
107 const char __user *buf,
112 struct iovec iov = {(void __user *)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 /* Kludge for now - unlocked O_DIRECT is still unsafe */
120 if (0 && unlikely(file->f_flags & O_DIRECT)) {
121 ioflags |= IO_ISDIRECT;
122 VOP_WRITE(vp, iocb, &iov, 1, &iocb->ki_pos,
123 ioflags, NULL, rval);
126 VOP_WRITE(vp, iocb, &iov, 1, &iocb->ki_pos,
127 ioflags, NULL, rval);
138 const char __user *buf,
142 return __linvfs_write(iocb, buf, 0, count, pos);
148 const char __user *buf,
152 return __linvfs_write(iocb, buf, IO_INVIS, count, pos);
156 STATIC inline ssize_t
159 const struct iovec *iov,
161 unsigned long nr_segs,
164 struct inode *inode = file->f_mapping->host;
165 vnode_t *vp = LINVFS_GET_VP(inode);
169 init_sync_kiocb(&kiocb, file);
170 kiocb.ki_pos = *ppos;
172 if (unlikely(file->f_flags & O_DIRECT))
173 ioflags |= IO_ISDIRECT;
174 VOP_READ(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos, ioflags, NULL, rval);
175 if (rval == -EIOCBQUEUED)
176 rval = wait_on_sync_kiocb(&kiocb);
178 *ppos = kiocb.ki_pos;
185 const struct iovec *iov,
186 unsigned long nr_segs,
189 return __linvfs_readv(file, iov, 0, nr_segs, ppos);
195 const struct iovec *iov,
196 unsigned long nr_segs,
199 return __linvfs_readv(file, iov, IO_INVIS, nr_segs, ppos);
203 STATIC inline ssize_t
206 const struct iovec *iov,
208 unsigned long nr_segs,
211 struct inode *inode = file->f_mapping->host;
212 vnode_t *vp = LINVFS_GET_VP(inode);
216 init_sync_kiocb(&kiocb, file);
217 kiocb.ki_pos = *ppos;
218 /* kludge for now - unlocked O_DIRECT is still unsafe */
219 if (0 && unlikely(file->f_flags & O_DIRECT)) {
220 ioflags |= IO_ISDIRECT;
221 VOP_WRITE(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos,
222 ioflags, NULL, rval);
225 VOP_WRITE(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos,
226 ioflags, NULL, rval);
230 if (rval == -EIOCBQUEUED)
231 rval = wait_on_sync_kiocb(&kiocb);
233 *ppos = kiocb.ki_pos;
241 const struct iovec *iov,
242 unsigned long nr_segs,
245 return __linvfs_writev(file, iov, 0, nr_segs, ppos);
251 const struct iovec *iov,
252 unsigned long nr_segs,
255 return __linvfs_writev(file, iov, IO_INVIS, nr_segs, ppos);
266 vnode_t *vp = LINVFS_GET_VP(filp->f_dentry->d_inode);
269 VOP_SENDFILE(vp, filp, ppos, 0, count, actor, target, NULL, rval);
279 vnode_t *vp = LINVFS_GET_VP(inode);
282 if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
286 VOP_OPEN(vp, NULL, error);
296 vnode_t *vp = LINVFS_GET_VP(inode);
300 VOP_RELEASE(vp, error);
308 struct dentry *dentry,
311 struct inode *inode = dentry->d_inode;
312 vnode_t *vp = LINVFS_GET_VP(inode);
314 int flags = FSYNC_WAIT;
320 VOP_FSYNC(vp, flags, NULL, (xfs_off_t)0, (xfs_off_t)-1, error);
325 * linvfs_readdir maps to VOP_READDIR().
326 * We need to build a uio, cred, ...
329 #define nextdp(dp) ((struct xfs_dirent *)((char *)(dp) + (dp)->d_reclen))
343 int namelen, size = 0;
344 size_t rlen = PAGE_CACHE_SIZE;
345 xfs_off_t start_offset, curr_offset;
346 xfs_dirent_t *dbp = NULL;
348 vp = LINVFS_GET_VP(filp->f_dentry->d_inode);
351 /* Try fairly hard to get memory */
353 if ((read_buf = (caddr_t)kmalloc(rlen, GFP_KERNEL)))
356 } while (rlen >= 1024);
358 if (read_buf == NULL)
362 uio.uio_segflg = UIO_SYSSPACE;
363 curr_offset = filp->f_pos;
364 if (filp->f_pos != 0x7fffffff)
365 uio.uio_offset = filp->f_pos;
367 uio.uio_offset = 0xffffffff;
370 uio.uio_resid = iov.iov_len = rlen;
371 iov.iov_base = read_buf;
374 start_offset = uio.uio_offset;
376 VOP_READDIR(vp, &uio, NULL, &eof, error);
377 if ((uio.uio_offset == start_offset) || error) {
382 size = rlen - uio.uio_resid;
383 dbp = (xfs_dirent_t *)read_buf;
385 namelen = strlen(dbp->d_name);
387 if (filldir(dirent, dbp->d_name, namelen,
388 (loff_t) curr_offset & 0x7fffffff,
393 size -= dbp->d_reclen;
394 curr_offset = (loff_t)dbp->d_off /* & 0x7fffffff */;
401 filp->f_pos = uio.uio_offset & 0x7fffffff;
403 filp->f_pos = curr_offset;
414 struct vm_area_struct *vma)
416 struct inode *ip = filp->f_dentry->d_inode;
417 vnode_t *vp = LINVFS_GET_VP(ip);
418 vattr_t va = { .va_mask = XFS_AT_UPDATIME };
421 if ((vp->v_type == VREG) && (vp->v_vfsp->vfs_flag & VFS_DMI)) {
422 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
424 error = -XFS_SEND_MMAP(mp, vma, 0);
429 vma->vm_ops = &linvfs_file_vm_ops;
431 VOP_SETATTR(vp, &va, XFS_AT_UPDATIME, NULL, error);
444 vnode_t *vp = LINVFS_GET_VP(inode);
447 VOP_IOCTL(vp, inode, filp, 0, cmd, (void __user *)arg, error);
451 /* NOTE: some of the ioctl's return positive #'s as a
452 * byte count indicating success, such as
453 * readlink_by_handle. So we don't "sign flip"
454 * like most other routines. This means true
455 * errors need to be returned as a negative value.
468 vnode_t *vp = LINVFS_GET_VP(inode);
472 VOP_IOCTL(vp, inode, filp, IO_INVIS, cmd, (void __user *)arg, error);
476 /* NOTE: some of the ioctl's return positive #'s as a
477 * byte count indicating success, such as
478 * readlink_by_handle. So we don't "sign flip"
479 * like most other routines. This means true
480 * errors need to be returned as a negative value.
485 #ifdef HAVE_VMOP_MPROTECT
488 struct vm_area_struct *vma,
489 unsigned int newflags)
491 vnode_t *vp = LINVFS_GET_VP(vma->vm_file->f_dentry->d_inode);
494 if ((vp->v_type == VREG) && (vp->v_vfsp->vfs_flag & VFS_DMI)) {
495 if ((vma->vm_flags & VM_MAYSHARE) &&
496 (newflags & VM_WRITE) && !(vma->vm_flags & VM_WRITE)) {
497 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
499 error = XFS_SEND_MMAP(mp, vma, VM_WRITE);
504 #endif /* HAVE_VMOP_MPROTECT */
507 struct file_operations linvfs_file_operations = {
508 .llseek = generic_file_llseek,
509 .read = do_sync_read,
510 .write = do_sync_write,
511 .readv = linvfs_readv,
512 .writev = linvfs_writev,
513 .aio_read = linvfs_read,
514 .aio_write = linvfs_write,
515 .sendfile = linvfs_sendfile,
516 .ioctl = linvfs_ioctl,
517 .mmap = linvfs_file_mmap,
519 .release = linvfs_release,
520 .fsync = linvfs_fsync,
523 struct file_operations linvfs_invis_file_operations = {
524 .llseek = generic_file_llseek,
525 .read = do_sync_read,
526 .write = do_sync_write,
527 .readv = linvfs_readv_invis,
528 .writev = linvfs_writev_invis,
529 .aio_read = linvfs_read_invis,
530 .aio_write = linvfs_write_invis,
531 .sendfile = linvfs_sendfile,
532 .ioctl = linvfs_ioctl_invis,
533 .mmap = linvfs_file_mmap,
535 .release = linvfs_release,
536 .fsync = linvfs_fsync,
540 struct file_operations linvfs_dir_operations = {
541 .read = generic_read_dir,
542 .readdir = linvfs_readdir,
543 .ioctl = linvfs_ioctl,
544 .fsync = linvfs_fsync,
547 static struct vm_operations_struct linvfs_file_vm_ops = {
548 .nopage = filemap_nopage,
549 #ifdef HAVE_VMOP_MPROTECT
550 .mprotect = linvfs_mprotect,