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>
56 #include <linux/mman.h> /* for PROT_WRITE */
58 static struct vm_operations_struct linvfs_file_vm_ops;
68 struct iovec iov = {buf, count};
72 BUG_ON(iocb->ki_pos != pos);
73 vp = LINVFS_GET_VP(iocb->ki_filp->f_dentry->d_inode);
74 VOP_READ(vp, iocb, &iov, 1, &iocb->ki_pos, NULL, error);
87 struct iovec iov = {(void *)buf, count};
88 struct file *file = iocb->ki_filp;
89 struct inode *inode = file->f_dentry->d_inode->i_mapping->host;
90 vnode_t *vp = LINVFS_GET_VP(inode);
92 int direct = file->f_flags & O_DIRECT;
94 BUG_ON(iocb->ki_pos != pos);
97 VOP_WRITE(vp, iocb, &iov, 1, &iocb->ki_pos, NULL, error);
100 VOP_WRITE(vp, iocb, &iov, 1, &iocb->ki_pos, NULL, error);
110 const struct iovec *iov,
111 unsigned long nr_segs,
114 struct inode *inode = file->f_dentry->d_inode->i_mapping->host;
115 vnode_t *vp = LINVFS_GET_VP(inode);
119 init_sync_kiocb(&kiocb, file);
120 kiocb.ki_pos = *ppos;
121 VOP_READ(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos, NULL, error);
122 if (-EIOCBQUEUED == error)
123 error = wait_on_sync_kiocb(&kiocb);
124 *ppos = kiocb.ki_pos;
132 const struct iovec *iov,
133 unsigned long nr_segs,
136 struct inode *inode = file->f_dentry->d_inode->i_mapping->host;
137 vnode_t *vp = LINVFS_GET_VP(inode);
140 int direct = file->f_flags & O_DIRECT;
142 init_sync_kiocb(&kiocb, file);
143 kiocb.ki_pos = *ppos;
145 VOP_WRITE(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos, NULL, error);
148 VOP_WRITE(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos, NULL, error);
151 if (-EIOCBQUEUED == error)
152 error = wait_on_sync_kiocb(&kiocb);
153 *ppos = kiocb.ki_pos;
166 vnode_t *vp = LINVFS_GET_VP(filp->f_dentry->d_inode);
169 VOP_SENDFILE(vp, filp, ppos, count, actor, target, NULL, error);
180 vnode_t *vp = LINVFS_GET_VP(inode);
183 if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
187 VOP_OPEN(vp, NULL, error);
197 vnode_t *vp = LINVFS_GET_VP(inode);
201 VOP_RELEASE(vp, error);
209 struct dentry *dentry,
212 struct inode *inode = dentry->d_inode;
213 vnode_t *vp = LINVFS_GET_VP(inode);
215 int flags = FSYNC_WAIT;
221 VOP_FSYNC(vp, flags, NULL, (xfs_off_t)0, (xfs_off_t)-1, error);
226 * linvfs_readdir maps to VOP_READDIR().
227 * We need to build a uio, cred, ...
230 #define nextdp(dp) ((struct xfs_dirent *)((char *)(dp) + (dp)->d_reclen))
244 int namelen, size = 0;
245 size_t rlen = PAGE_CACHE_SIZE;
246 xfs_off_t start_offset, curr_offset;
247 xfs_dirent_t *dbp = NULL;
249 vp = LINVFS_GET_VP(filp->f_dentry->d_inode);
252 /* Try fairly hard to get memory */
254 if ((read_buf = (caddr_t)kmalloc(rlen, GFP_KERNEL)))
257 } while (rlen >= 1024);
259 if (read_buf == NULL)
263 uio.uio_fmode = filp->f_mode;
264 uio.uio_segflg = UIO_SYSSPACE;
265 curr_offset = uio.uio_offset = filp->f_pos;
268 uio.uio_resid = iov.iov_len = rlen;
269 iov.iov_base = read_buf;
272 start_offset = uio.uio_offset;
274 VOP_READDIR(vp, &uio, NULL, &eof, error);
275 if ((uio.uio_offset == start_offset) || error) {
280 size = rlen - uio.uio_resid;
281 dbp = (xfs_dirent_t *)read_buf;
283 namelen = strlen(dbp->d_name);
285 if (filldir(dirent, dbp->d_name, namelen,
286 (loff_t) curr_offset,
291 size -= dbp->d_reclen;
292 curr_offset = (loff_t)dbp->d_off & 0x7fffffff;
299 filp->f_pos = uio.uio_offset & 0x7fffffff;
301 filp->f_pos = curr_offset;
312 struct vm_area_struct *vma)
314 struct inode *ip = filp->f_dentry->d_inode;
315 vnode_t *vp = LINVFS_GET_VP(ip);
316 vattr_t va = { .va_mask = XFS_AT_UPDATIME };
319 if ((vp->v_type == VREG) && (vp->v_vfsp->vfs_flag & VFS_DMI)) {
320 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
322 error = -XFS_SEND_MMAP(mp, vma, 0);
327 vma->vm_ops = &linvfs_file_vm_ops;
329 VOP_SETATTR(vp, &va, XFS_AT_UPDATIME, NULL, error);
342 vnode_t *vp = LINVFS_GET_VP(inode);
345 VOP_IOCTL(vp, inode, filp, cmd, arg, error);
348 /* NOTE: some of the ioctl's return positive #'s as a
349 * byte count indicating success, such as
350 * readlink_by_handle. So we don't "sign flip"
351 * like most other routines. This means true
352 * errors need to be returned as a negative value.
357 #ifdef HAVE_VMOP_MPROTECT
360 struct vm_area_struct *vma,
361 unsigned int newflags)
363 vnode_t *vp = LINVFS_GET_VP(vma->vm_file->f_dentry->d_inode);
366 if ((vp->v_type == VREG) && (vp->v_vfsp->vfs_flag & VFS_DMI)) {
367 if ((vma->vm_flags & VM_MAYSHARE) &&
368 (newflags & PROT_WRITE) && !(vma->vm_flags & PROT_WRITE)) {
369 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
371 error = XFS_SEND_MMAP(mp, vma, VM_WRITE);
376 #endif /* HAVE_VMOP_MPROTECT */
379 struct file_operations linvfs_file_operations = {
380 .llseek = generic_file_llseek,
381 .read = do_sync_read,
382 .write = do_sync_write,
383 .readv = linvfs_readv,
384 .writev = linvfs_writev,
385 .aio_read = linvfs_read,
386 .aio_write = linvfs_write,
387 .sendfile = linvfs_sendfile,
388 .ioctl = linvfs_ioctl,
389 .mmap = linvfs_file_mmap,
391 .release = linvfs_release,
392 .fsync = linvfs_fsync,
395 struct file_operations linvfs_dir_operations = {
396 .read = generic_read_dir,
397 .readdir = linvfs_readdir,
398 .ioctl = linvfs_ioctl,
399 .fsync = linvfs_fsync,
402 static struct vm_operations_struct linvfs_file_vm_ops = {
403 .nopage = filemap_nopage,
404 #ifdef HAVE_VMOP_MPROTECT
405 .mprotect = linvfs_mprotect,