blob: 3d4f6dff21134a26b622d4450b0e763906ccba1e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110019#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110021#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "xfs_sb.h"
Nathan Scotta844f452005-11-02 14:38:42 +110023#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "xfs_dir2.h"
25#include "xfs_trans.h"
26#include "xfs_dmapi.h"
27#include "xfs_mount.h"
28#include "xfs_bmap_btree.h"
29#include "xfs_alloc_btree.h"
30#include "xfs_ialloc_btree.h"
31#include "xfs_alloc.h"
32#include "xfs_btree.h"
33#include "xfs_attr_sf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "xfs_dir2_sf.h"
35#include "xfs_dinode.h"
36#include "xfs_inode.h"
37#include "xfs_error.h"
38#include "xfs_rw.h"
39#include "xfs_ioctl32.h"
40
41#include <linux/dcache.h>
42#include <linux/smp_lock.h>
43
Nathan Scott3562fd42006-03-14 14:00:35 +110044static struct vm_operations_struct xfs_file_vm_ops;
Dean Roehrich6fac0cb2005-06-21 14:07:45 +100045#ifdef CONFIG_XFS_DMAPI
Nathan Scott3562fd42006-03-14 14:00:35 +110046static struct vm_operations_struct xfs_dmapi_file_vm_ops;
Dean Roehrich6fac0cb2005-06-21 14:07:45 +100047#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49STATIC inline ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +110050__xfs_file_read(
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 struct kiocb *iocb,
52 char __user *buf,
53 int ioflags,
54 size_t count,
55 loff_t pos)
56{
57 struct iovec iov = {buf, count};
58 struct file *file = iocb->ki_filp;
Nathan Scott67fcaa72006-06-09 17:00:52 +100059 bhv_vnode_t *vp = vn_from_inode(file->f_dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 BUG_ON(iocb->ki_pos != pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 if (unlikely(file->f_flags & O_DIRECT))
63 ioflags |= IO_ISDIRECT;
Nathan Scott67fcaa72006-06-09 17:00:52 +100064 return bhv_vop_read(vp, iocb, &iov, 1, &iocb->ki_pos, ioflags, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +110068xfs_file_aio_read(
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 struct kiocb *iocb,
70 char __user *buf,
71 size_t count,
72 loff_t pos)
73{
Nathan Scott3562fd42006-03-14 14:00:35 +110074 return __xfs_file_read(iocb, buf, IO_ISAIO, count, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
76
77STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +110078xfs_file_aio_read_invis(
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 struct kiocb *iocb,
80 char __user *buf,
81 size_t count,
82 loff_t pos)
83{
Nathan Scott3562fd42006-03-14 14:00:35 +110084 return __xfs_file_read(iocb, buf, IO_ISAIO|IO_INVIS, count, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087STATIC inline ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +110088__xfs_file_write(
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 struct kiocb *iocb,
90 const char __user *buf,
91 int ioflags,
92 size_t count,
93 loff_t pos)
94{
95 struct iovec iov = {(void __user *)buf, count};
96 struct file *file = iocb->ki_filp;
97 struct inode *inode = file->f_mapping->host;
Nathan Scott67fcaa72006-06-09 17:00:52 +100098 bhv_vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 BUG_ON(iocb->ki_pos != pos);
101 if (unlikely(file->f_flags & O_DIRECT))
102 ioflags |= IO_ISDIRECT;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000103 return bhv_vop_write(vp, iocb, &iov, 1, &iocb->ki_pos, ioflags, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100107xfs_file_aio_write(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 struct kiocb *iocb,
109 const char __user *buf,
110 size_t count,
111 loff_t pos)
112{
Nathan Scott3562fd42006-03-14 14:00:35 +1100113 return __xfs_file_write(iocb, buf, IO_ISAIO, count, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
116STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100117xfs_file_aio_write_invis(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 struct kiocb *iocb,
119 const char __user *buf,
120 size_t count,
121 loff_t pos)
122{
Nathan Scott3562fd42006-03-14 14:00:35 +1100123 return __xfs_file_write(iocb, buf, IO_ISAIO|IO_INVIS, count, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124}
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126STATIC inline ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100127__xfs_file_readv(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 struct file *file,
129 const struct iovec *iov,
130 int ioflags,
131 unsigned long nr_segs,
132 loff_t *ppos)
133{
134 struct inode *inode = file->f_mapping->host;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000135 bhv_vnode_t *vp = vn_from_inode(inode);
Nathan Scott524fbf52006-03-14 14:07:53 +1100136 struct kiocb kiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 ssize_t rval;
138
Nathan Scott524fbf52006-03-14 14:07:53 +1100139 init_sync_kiocb(&kiocb, file);
140 kiocb.ki_pos = *ppos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142 if (unlikely(file->f_flags & O_DIRECT))
143 ioflags |= IO_ISDIRECT;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000144 rval = bhv_vop_read(vp, &kiocb, iov, nr_segs,
145 &kiocb.ki_pos, ioflags, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Nathan Scott524fbf52006-03-14 14:07:53 +1100147 *ppos = kiocb.ki_pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 return rval;
149}
150
151STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100152xfs_file_readv(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 struct file *file,
154 const struct iovec *iov,
155 unsigned long nr_segs,
156 loff_t *ppos)
157{
Nathan Scott3562fd42006-03-14 14:00:35 +1100158 return __xfs_file_readv(file, iov, 0, nr_segs, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
161STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100162xfs_file_readv_invis(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 struct file *file,
164 const struct iovec *iov,
165 unsigned long nr_segs,
166 loff_t *ppos)
167{
Nathan Scott3562fd42006-03-14 14:00:35 +1100168 return __xfs_file_readv(file, iov, IO_INVIS, nr_segs, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171STATIC inline ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100172__xfs_file_writev(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 struct file *file,
174 const struct iovec *iov,
175 int ioflags,
176 unsigned long nr_segs,
177 loff_t *ppos)
178{
179 struct inode *inode = file->f_mapping->host;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000180 bhv_vnode_t *vp = vn_from_inode(inode);
Nathan Scott524fbf52006-03-14 14:07:53 +1100181 struct kiocb kiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 ssize_t rval;
183
Nathan Scott524fbf52006-03-14 14:07:53 +1100184 init_sync_kiocb(&kiocb, file);
185 kiocb.ki_pos = *ppos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 if (unlikely(file->f_flags & O_DIRECT))
187 ioflags |= IO_ISDIRECT;
188
Nathan Scott67fcaa72006-06-09 17:00:52 +1000189 rval = bhv_vop_write(vp, &kiocb, iov, nr_segs,
190 &kiocb.ki_pos, ioflags, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Nathan Scott524fbf52006-03-14 14:07:53 +1100192 *ppos = kiocb.ki_pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return rval;
194}
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100197xfs_file_writev(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 struct file *file,
199 const struct iovec *iov,
200 unsigned long nr_segs,
201 loff_t *ppos)
202{
Nathan Scott3562fd42006-03-14 14:00:35 +1100203 return __xfs_file_writev(file, iov, 0, nr_segs, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
205
206STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100207xfs_file_writev_invis(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 struct file *file,
209 const struct iovec *iov,
210 unsigned long nr_segs,
211 loff_t *ppos)
212{
Nathan Scott3562fd42006-03-14 14:00:35 +1100213 return __xfs_file_writev(file, iov, IO_INVIS, nr_segs, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
215
216STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100217xfs_file_sendfile(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 struct file *filp,
Nathan Scott1b895842006-03-31 13:08:59 +1000219 loff_t *pos,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 size_t count,
221 read_actor_t actor,
222 void *target)
223{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000224 return bhv_vop_sendfile(vn_from_inode(filp->f_dentry->d_inode),
225 filp, pos, 0, count, actor, target, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
227
Nathan Scott1b895842006-03-31 13:08:59 +1000228STATIC ssize_t
229xfs_file_sendfile_invis(
230 struct file *filp,
231 loff_t *pos,
232 size_t count,
233 read_actor_t actor,
234 void *target)
235{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000236 return bhv_vop_sendfile(vn_from_inode(filp->f_dentry->d_inode),
237 filp, pos, IO_INVIS, count, actor, target, NULL);
Nathan Scott1b895842006-03-31 13:08:59 +1000238}
239
240STATIC ssize_t
241xfs_file_splice_read(
242 struct file *infilp,
Jens Axboecbb7e572006-04-11 14:57:50 +0200243 loff_t *ppos,
Ingo Molnar3a326a22006-04-10 15:18:35 +0200244 struct pipe_inode_info *pipe,
Nathan Scott1b895842006-03-31 13:08:59 +1000245 size_t len,
246 unsigned int flags)
247{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000248 return bhv_vop_splice_read(vn_from_inode(infilp->f_dentry->d_inode),
249 infilp, ppos, pipe, len, flags, 0, NULL);
Nathan Scott1b895842006-03-31 13:08:59 +1000250}
251
252STATIC ssize_t
253xfs_file_splice_read_invis(
254 struct file *infilp,
Jens Axboecbb7e572006-04-11 14:57:50 +0200255 loff_t *ppos,
Ingo Molnar3a326a22006-04-10 15:18:35 +0200256 struct pipe_inode_info *pipe,
Nathan Scott1b895842006-03-31 13:08:59 +1000257 size_t len,
258 unsigned int flags)
259{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000260 return bhv_vop_splice_read(vn_from_inode(infilp->f_dentry->d_inode),
261 infilp, ppos, pipe, len, flags, IO_INVIS,
262 NULL);
Nathan Scott1b895842006-03-31 13:08:59 +1000263}
264
265STATIC ssize_t
266xfs_file_splice_write(
Ingo Molnar3a326a22006-04-10 15:18:35 +0200267 struct pipe_inode_info *pipe,
Nathan Scott1b895842006-03-31 13:08:59 +1000268 struct file *outfilp,
Jens Axboecbb7e572006-04-11 14:57:50 +0200269 loff_t *ppos,
Nathan Scott1b895842006-03-31 13:08:59 +1000270 size_t len,
271 unsigned int flags)
272{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000273 return bhv_vop_splice_write(vn_from_inode(outfilp->f_dentry->d_inode),
274 pipe, outfilp, ppos, len, flags, 0, NULL);
Nathan Scott1b895842006-03-31 13:08:59 +1000275}
276
277STATIC ssize_t
278xfs_file_splice_write_invis(
Ingo Molnar3a326a22006-04-10 15:18:35 +0200279 struct pipe_inode_info *pipe,
Nathan Scott1b895842006-03-31 13:08:59 +1000280 struct file *outfilp,
Jens Axboecbb7e572006-04-11 14:57:50 +0200281 loff_t *ppos,
Nathan Scott1b895842006-03-31 13:08:59 +1000282 size_t len,
283 unsigned int flags)
284{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000285 return bhv_vop_splice_write(vn_from_inode(outfilp->f_dentry->d_inode),
286 pipe, outfilp, ppos, len, flags, IO_INVIS,
287 NULL);
Nathan Scott1b895842006-03-31 13:08:59 +1000288}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
290STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100291xfs_file_open(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 struct inode *inode,
293 struct file *filp)
294{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
296 return -EFBIG;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000297 return -bhv_vop_open(vn_from_inode(inode), NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300STATIC int
Nathan Scott7d4fb402006-06-09 15:27:16 +1000301xfs_file_close(
Alexey Dobriyan1e788f82006-06-25 16:42:33 -0700302 struct file *filp,
303 fl_owner_t id)
Nathan Scott7d4fb402006-06-09 15:27:16 +1000304{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000305 return -bhv_vop_close(vn_from_inode(filp->f_dentry->d_inode), 0,
306 file_count(filp) > 1 ? L_FALSE : L_TRUE, NULL);
Nathan Scott7d4fb402006-06-09 15:27:16 +1000307}
308
309STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100310xfs_file_release(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 struct inode *inode,
312 struct file *filp)
313{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000314 bhv_vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 if (vp)
Nathan Scott67fcaa72006-06-09 17:00:52 +1000317 return -bhv_vop_release(vp);
318 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319}
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100322xfs_file_fsync(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 struct file *filp,
324 struct dentry *dentry,
325 int datasync)
326{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000327 bhv_vnode_t *vp = vn_from_inode(dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 int flags = FSYNC_WAIT;
329
330 if (datasync)
331 flags |= FSYNC_DATA;
Nathan Scott7d4fb402006-06-09 15:27:16 +1000332 if (VN_TRUNC(vp))
333 VUNTRUNCATE(vp);
Nathan Scott67fcaa72006-06-09 17:00:52 +1000334 return -bhv_vop_fsync(vp, flags, NULL, (xfs_off_t)0, (xfs_off_t)-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335}
336
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000337#ifdef CONFIG_XFS_DMAPI
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000338STATIC struct page *
Nathan Scott3562fd42006-03-14 14:00:35 +1100339xfs_vm_nopage(
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000340 struct vm_area_struct *area,
341 unsigned long address,
342 int *type)
343{
344 struct inode *inode = area->vm_file->f_dentry->d_inode;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000345 bhv_vnode_t *vp = vn_from_inode(inode);
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000346
347 ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI);
Nathan Scottfbc14622006-06-09 14:52:13 +1000348 if (XFS_SEND_MMAP(XFS_VFSTOM(vp->v_vfsp), area, 0))
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000349 return NULL;
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000350 return filemap_nopage(area, address, type);
351}
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000352#endif /* CONFIG_XFS_DMAPI */
353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100355xfs_file_readdir(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 struct file *filp,
357 void *dirent,
358 filldir_t filldir)
359{
360 int error = 0;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000361 bhv_vnode_t *vp = vn_from_inode(filp->f_dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 uio_t uio;
363 iovec_t iov;
364 int eof = 0;
365 caddr_t read_buf;
366 int namelen, size = 0;
367 size_t rlen = PAGE_CACHE_SIZE;
368 xfs_off_t start_offset, curr_offset;
369 xfs_dirent_t *dbp = NULL;
370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 /* Try fairly hard to get memory */
372 do {
373 if ((read_buf = (caddr_t)kmalloc(rlen, GFP_KERNEL)))
374 break;
375 rlen >>= 1;
376 } while (rlen >= 1024);
377
378 if (read_buf == NULL)
379 return -ENOMEM;
380
381 uio.uio_iov = &iov;
382 uio.uio_segflg = UIO_SYSSPACE;
383 curr_offset = filp->f_pos;
384 if (filp->f_pos != 0x7fffffff)
385 uio.uio_offset = filp->f_pos;
386 else
387 uio.uio_offset = 0xffffffff;
388
389 while (!eof) {
390 uio.uio_resid = iov.iov_len = rlen;
391 iov.iov_base = read_buf;
392 uio.uio_iovcnt = 1;
393
394 start_offset = uio.uio_offset;
395
Nathan Scott67fcaa72006-06-09 17:00:52 +1000396 error = bhv_vop_readdir(vp, &uio, NULL, &eof);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 if ((uio.uio_offset == start_offset) || error) {
398 size = 0;
399 break;
400 }
401
402 size = rlen - uio.uio_resid;
403 dbp = (xfs_dirent_t *)read_buf;
404 while (size > 0) {
405 namelen = strlen(dbp->d_name);
406
407 if (filldir(dirent, dbp->d_name, namelen,
408 (loff_t) curr_offset & 0x7fffffff,
409 (ino_t) dbp->d_ino,
410 DT_UNKNOWN)) {
411 goto done;
412 }
413 size -= dbp->d_reclen;
414 curr_offset = (loff_t)dbp->d_off /* & 0x7fffffff */;
Nathan Scott1b895842006-03-31 13:08:59 +1000415 dbp = (xfs_dirent_t *)((char *)dbp + dbp->d_reclen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
417 }
418done:
419 if (!error) {
420 if (size == 0)
421 filp->f_pos = uio.uio_offset & 0x7fffffff;
422 else if (dbp)
423 filp->f_pos = curr_offset;
424 }
425
426 kfree(read_buf);
427 return -error;
428}
429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100431xfs_file_mmap(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 struct file *filp,
433 struct vm_area_struct *vma)
434{
Nathan Scott3562fd42006-03-14 14:00:35 +1100435 vma->vm_ops = &xfs_file_vm_ops;
Dean Roehrich6fac0cb2005-06-21 14:07:45 +1000436
Dean Roehrich6fac0cb2005-06-21 14:07:45 +1000437#ifdef CONFIG_XFS_DMAPI
Nathan Scottfbc14622006-06-09 14:52:13 +1000438 if (vn_from_inode(filp->f_dentry->d_inode)->v_vfsp->vfs_flag & VFS_DMI)
Nathan Scott3562fd42006-03-14 14:00:35 +1100439 vma->vm_ops = &xfs_dmapi_file_vm_ops;
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000440#endif /* CONFIG_XFS_DMAPI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Nathan Scottfbc14622006-06-09 14:52:13 +1000442 file_accessed(filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 return 0;
444}
445
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446STATIC long
Nathan Scott3562fd42006-03-14 14:00:35 +1100447xfs_file_ioctl(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 struct file *filp,
449 unsigned int cmd,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000450 unsigned long p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
452 int error;
Nathan Scott1f6553f2006-03-14 13:30:48 +1100453 struct inode *inode = filp->f_dentry->d_inode;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000454 bhv_vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Nathan Scott67fcaa72006-06-09 17:00:52 +1000456 error = bhv_vop_ioctl(vp, inode, filp, 0, cmd, (void __user *)p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 VMODIFY(vp);
458
459 /* NOTE: some of the ioctl's return positive #'s as a
460 * byte count indicating success, such as
461 * readlink_by_handle. So we don't "sign flip"
462 * like most other routines. This means true
463 * errors need to be returned as a negative value.
464 */
465 return error;
466}
467
468STATIC long
Nathan Scott3562fd42006-03-14 14:00:35 +1100469xfs_file_ioctl_invis(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 struct file *filp,
471 unsigned int cmd,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000472 unsigned long p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473{
Nathan Scott1b895842006-03-31 13:08:59 +1000474 int error;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000475 struct inode *inode = filp->f_dentry->d_inode;
476 bhv_vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Nathan Scott67fcaa72006-06-09 17:00:52 +1000478 error = bhv_vop_ioctl(vp, inode, filp, IO_INVIS, cmd, (void __user *)p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 VMODIFY(vp);
480
481 /* NOTE: some of the ioctl's return positive #'s as a
482 * byte count indicating success, such as
483 * readlink_by_handle. So we don't "sign flip"
484 * like most other routines. This means true
485 * errors need to be returned as a negative value.
486 */
487 return error;
488}
489
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000490#ifdef CONFIG_XFS_DMAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#ifdef HAVE_VMOP_MPROTECT
492STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100493xfs_vm_mprotect(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 struct vm_area_struct *vma,
495 unsigned int newflags)
496{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000497 bhv_vnode_t *vp = vn_from_inode(vma->vm_file->f_dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 int error = 0;
499
500 if (vp->v_vfsp->vfs_flag & VFS_DMI) {
501 if ((vma->vm_flags & VM_MAYSHARE) &&
502 (newflags & VM_WRITE) && !(vma->vm_flags & VM_WRITE)) {
503 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
504
505 error = XFS_SEND_MMAP(mp, vma, VM_WRITE);
506 }
507 }
508 return error;
509}
510#endif /* HAVE_VMOP_MPROTECT */
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000511#endif /* CONFIG_XFS_DMAPI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513#ifdef HAVE_FOP_OPEN_EXEC
514/* If the user is attempting to execute a file that is offline then
515 * we have to trigger a DMAPI READ event before the file is marked as busy
516 * otherwise the invisible I/O will not be able to write to the file to bring
517 * it back online.
518 */
519STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100520xfs_file_open_exec(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 struct inode *inode)
522{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000523 bhv_vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Nathan Scott1d47bec2006-06-19 08:39:16 +1000525 if (unlikely(vp->v_vfsp->vfs_flag & VFS_DMI)) {
526 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
527 xfs_inode_t *ip = xfs_vtoi(vp);
528
529 if (!ip)
530 return -EINVAL;
531 if (DM_EVENT_ENABLED(vp->v_vfsp, ip, DM_EVENT_READ))
532 return -XFS_SEND_DATA(mp, DM_EVENT_READ, vp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 0, 0, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 }
Nathan Scott1d47bec2006-06-19 08:39:16 +1000535 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536}
537#endif /* HAVE_FOP_OPEN_EXEC */
538
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800539const struct file_operations xfs_file_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 .llseek = generic_file_llseek,
541 .read = do_sync_read,
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000542 .write = do_sync_write,
Nathan Scott3562fd42006-03-14 14:00:35 +1100543 .readv = xfs_file_readv,
544 .writev = xfs_file_writev,
545 .aio_read = xfs_file_aio_read,
546 .aio_write = xfs_file_aio_write,
547 .sendfile = xfs_file_sendfile,
Nathan Scott1b895842006-03-31 13:08:59 +1000548 .splice_read = xfs_file_splice_read,
549 .splice_write = xfs_file_splice_write,
Nathan Scott3562fd42006-03-14 14:00:35 +1100550 .unlocked_ioctl = xfs_file_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551#ifdef CONFIG_COMPAT
Nathan Scott3562fd42006-03-14 14:00:35 +1100552 .compat_ioctl = xfs_file_compat_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553#endif
Nathan Scott3562fd42006-03-14 14:00:35 +1100554 .mmap = xfs_file_mmap,
555 .open = xfs_file_open,
Nathan Scott7d4fb402006-06-09 15:27:16 +1000556 .flush = xfs_file_close,
Nathan Scott3562fd42006-03-14 14:00:35 +1100557 .release = xfs_file_release,
558 .fsync = xfs_file_fsync,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#ifdef HAVE_FOP_OPEN_EXEC
Nathan Scott3562fd42006-03-14 14:00:35 +1100560 .open_exec = xfs_file_open_exec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561#endif
562};
563
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800564const struct file_operations xfs_invis_file_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 .llseek = generic_file_llseek,
566 .read = do_sync_read,
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000567 .write = do_sync_write,
Nathan Scott3562fd42006-03-14 14:00:35 +1100568 .readv = xfs_file_readv_invis,
569 .writev = xfs_file_writev_invis,
570 .aio_read = xfs_file_aio_read_invis,
571 .aio_write = xfs_file_aio_write_invis,
Nathan Scott1b895842006-03-31 13:08:59 +1000572 .sendfile = xfs_file_sendfile_invis,
573 .splice_read = xfs_file_splice_read_invis,
574 .splice_write = xfs_file_splice_write_invis,
Nathan Scott3562fd42006-03-14 14:00:35 +1100575 .unlocked_ioctl = xfs_file_ioctl_invis,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576#ifdef CONFIG_COMPAT
Nathan Scott3562fd42006-03-14 14:00:35 +1100577 .compat_ioctl = xfs_file_compat_invis_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578#endif
Nathan Scott3562fd42006-03-14 14:00:35 +1100579 .mmap = xfs_file_mmap,
580 .open = xfs_file_open,
Nathan Scott7d4fb402006-06-09 15:27:16 +1000581 .flush = xfs_file_close,
Nathan Scott3562fd42006-03-14 14:00:35 +1100582 .release = xfs_file_release,
583 .fsync = xfs_file_fsync,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584};
585
586
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800587const struct file_operations xfs_dir_file_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 .read = generic_read_dir,
Nathan Scott3562fd42006-03-14 14:00:35 +1100589 .readdir = xfs_file_readdir,
590 .unlocked_ioctl = xfs_file_ioctl,
Nathan Scottd3870392005-05-06 06:44:46 -0700591#ifdef CONFIG_COMPAT
Nathan Scott3562fd42006-03-14 14:00:35 +1100592 .compat_ioctl = xfs_file_compat_ioctl,
Nathan Scottd3870392005-05-06 06:44:46 -0700593#endif
Nathan Scott3562fd42006-03-14 14:00:35 +1100594 .fsync = xfs_file_fsync,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595};
596
Nathan Scott3562fd42006-03-14 14:00:35 +1100597static struct vm_operations_struct xfs_file_vm_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 .nopage = filemap_nopage,
599 .populate = filemap_populate,
Dean Roehrich6fac0cb2005-06-21 14:07:45 +1000600};
601
602#ifdef CONFIG_XFS_DMAPI
Nathan Scott3562fd42006-03-14 14:00:35 +1100603static struct vm_operations_struct xfs_dmapi_file_vm_ops = {
604 .nopage = xfs_vm_nopage,
Dean Roehrich6fac0cb2005-06-21 14:07:45 +1000605 .populate = filemap_populate,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606#ifdef HAVE_VMOP_MPROTECT
Nathan Scott3562fd42006-03-14 14:00:35 +1100607 .mprotect = xfs_vm_mprotect,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608#endif
609};
Dean Roehrich6fac0cb2005-06-21 14:07:45 +1000610#endif /* CONFIG_XFS_DMAPI */