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 if (unlikely(file->f_flags & O_DIRECT))
120 ioflags |= IO_ISDIRECT;
122 VOP_WRITE(vp, iocb, &iov, 1, &iocb->ki_pos, ioflags, NULL, rval);
130 const char __user *buf,
134 return __linvfs_write(iocb, buf, 0, count, pos);
140 const char __user *buf,
144 return __linvfs_write(iocb, buf, IO_INVIS, count, pos);
148 STATIC inline ssize_t
151 const struct iovec *iov,
153 unsigned long nr_segs,
156 struct inode *inode = file->f_mapping->host;
157 vnode_t *vp = LINVFS_GET_VP(inode);
161 init_sync_kiocb(&kiocb, file);
162 kiocb.ki_pos = *ppos;
164 if (unlikely(file->f_flags & O_DIRECT))
165 ioflags |= IO_ISDIRECT;
166 VOP_READ(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos, ioflags, NULL, rval);
168 *ppos = kiocb.ki_pos;
175 const struct iovec *iov,
176 unsigned long nr_segs,
179 return __linvfs_readv(file, iov, 0, nr_segs, ppos);
185 const struct iovec *iov,
186 unsigned long nr_segs,
189 return __linvfs_readv(file, iov, IO_INVIS, nr_segs, ppos);
193 STATIC inline ssize_t
196 const struct iovec *iov,
198 unsigned long nr_segs,
201 struct inode *inode = file->f_mapping->host;
202 vnode_t *vp = LINVFS_GET_VP(inode);
206 init_sync_kiocb(&kiocb, file);
207 kiocb.ki_pos = *ppos;
208 if (unlikely(file->f_flags & O_DIRECT))
209 ioflags |= IO_ISDIRECT;
211 VOP_WRITE(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos, ioflags, NULL, rval);
213 *ppos = kiocb.ki_pos;
221 const struct iovec *iov,
222 unsigned long nr_segs,
225 return __linvfs_writev(file, iov, 0, nr_segs, ppos);
231 const struct iovec *iov,
232 unsigned long nr_segs,
235 return __linvfs_writev(file, iov, IO_INVIS, nr_segs, ppos);
246 vnode_t *vp = LINVFS_GET_VP(filp->f_dentry->d_inode);
249 VOP_SENDFILE(vp, filp, ppos, 0, count, actor, target, NULL, rval);
259 vnode_t *vp = LINVFS_GET_VP(inode);
262 if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
266 VOP_OPEN(vp, NULL, error);
276 vnode_t *vp = LINVFS_GET_VP(inode);
280 VOP_RELEASE(vp, error);
288 struct dentry *dentry,
291 struct inode *inode = dentry->d_inode;
292 vnode_t *vp = LINVFS_GET_VP(inode);
294 int flags = FSYNC_WAIT;
300 VOP_FSYNC(vp, flags, NULL, (xfs_off_t)0, (xfs_off_t)-1, error);
305 * linvfs_readdir maps to VOP_READDIR().
306 * We need to build a uio, cred, ...
309 #define nextdp(dp) ((struct xfs_dirent *)((char *)(dp) + (dp)->d_reclen))
323 int namelen, size = 0;
324 size_t rlen = PAGE_CACHE_SIZE;
325 xfs_off_t start_offset, curr_offset;
326 xfs_dirent_t *dbp = NULL;
328 vp = LINVFS_GET_VP(filp->f_dentry->d_inode);
331 /* Try fairly hard to get memory */
333 if ((read_buf = (caddr_t)kmalloc(rlen, GFP_KERNEL)))
336 } while (rlen >= 1024);
338 if (read_buf == NULL)
342 uio.uio_segflg = UIO_SYSSPACE;
343 curr_offset = filp->f_pos;
344 if (filp->f_pos != 0x7fffffff)
345 uio.uio_offset = filp->f_pos;
347 uio.uio_offset = 0xffffffff;
350 uio.uio_resid = iov.iov_len = rlen;
351 iov.iov_base = read_buf;
354 start_offset = uio.uio_offset;
356 VOP_READDIR(vp, &uio, NULL, &eof, error);
357 if ((uio.uio_offset == start_offset) || error) {
362 size = rlen - uio.uio_resid;
363 dbp = (xfs_dirent_t *)read_buf;
365 namelen = strlen(dbp->d_name);
367 if (filldir(dirent, dbp->d_name, namelen,
368 (loff_t) curr_offset & 0x7fffffff,
373 size -= dbp->d_reclen;
374 curr_offset = (loff_t)dbp->d_off /* & 0x7fffffff */;
381 filp->f_pos = uio.uio_offset & 0x7fffffff;
383 filp->f_pos = curr_offset;
394 struct vm_area_struct *vma)
396 struct inode *ip = filp->f_dentry->d_inode;
397 vnode_t *vp = LINVFS_GET_VP(ip);
398 vattr_t va = { .va_mask = XFS_AT_UPDATIME };
401 if (vp->v_vfsp->vfs_flag & VFS_DMI) {
402 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
404 error = -XFS_SEND_MMAP(mp, vma, 0);
409 vma->vm_ops = &linvfs_file_vm_ops;
411 VOP_SETATTR(vp, &va, XFS_AT_UPDATIME, NULL, error);
413 vn_revalidate(vp); /* update Linux inode flags */
426 vnode_t *vp = LINVFS_GET_VP(inode);
429 VOP_IOCTL(vp, inode, filp, 0, cmd, (void __user *)arg, error);
433 /* NOTE: some of the ioctl's return positive #'s as a
434 * byte count indicating success, such as
435 * readlink_by_handle. So we don't "sign flip"
436 * like most other routines. This means true
437 * errors need to be returned as a negative value.
450 vnode_t *vp = LINVFS_GET_VP(inode);
454 VOP_IOCTL(vp, inode, filp, IO_INVIS, cmd, (void __user *)arg, error);
458 /* NOTE: some of the ioctl's return positive #'s as a
459 * byte count indicating success, such as
460 * readlink_by_handle. So we don't "sign flip"
461 * like most other routines. This means true
462 * errors need to be returned as a negative value.
467 #ifdef HAVE_VMOP_MPROTECT
470 struct vm_area_struct *vma,
471 unsigned int newflags)
473 vnode_t *vp = LINVFS_GET_VP(vma->vm_file->f_dentry->d_inode);
476 if (vp->v_vfsp->vfs_flag & VFS_DMI) {
477 if ((vma->vm_flags & VM_MAYSHARE) &&
478 (newflags & VM_WRITE) && !(vma->vm_flags & VM_WRITE)) {
479 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
481 error = XFS_SEND_MMAP(mp, vma, VM_WRITE);
486 #endif /* HAVE_VMOP_MPROTECT */
489 struct file_operations linvfs_file_operations = {
490 .llseek = generic_file_llseek,
491 .read = do_sync_read,
492 .write = do_sync_write,
493 .readv = linvfs_readv,
494 .writev = linvfs_writev,
495 .aio_read = linvfs_read,
496 .aio_write = linvfs_write,
497 .sendfile = linvfs_sendfile,
498 .ioctl = linvfs_ioctl,
499 .mmap = linvfs_file_mmap,
501 .release = linvfs_release,
502 .fsync = linvfs_fsync,
505 struct file_operations linvfs_invis_file_operations = {
506 .llseek = generic_file_llseek,
507 .read = do_sync_read,
508 .write = do_sync_write,
509 .readv = linvfs_readv_invis,
510 .writev = linvfs_writev_invis,
511 .aio_read = linvfs_read_invis,
512 .aio_write = linvfs_write_invis,
513 .sendfile = linvfs_sendfile,
514 .ioctl = linvfs_ioctl_invis,
515 .mmap = linvfs_file_mmap,
517 .release = linvfs_release,
518 .fsync = linvfs_fsync,
522 struct file_operations linvfs_dir_operations = {
523 .read = generic_read_dir,
524 .readdir = linvfs_readdir,
525 .ioctl = linvfs_ioctl,
526 .fsync = linvfs_fsync,
529 static struct vm_operations_struct linvfs_file_vm_ops = {
530 .nopage = filemap_nopage,
531 #ifdef HAVE_VMOP_MPROTECT
532 .mprotect = linvfs_mprotect,