2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * 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.
14 * 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
26 #include "xfs_trans.h"
27 #include "xfs_dmapi.h"
28 #include "xfs_mount.h"
29 #include "xfs_bmap_btree.h"
30 #include "xfs_alloc_btree.h"
31 #include "xfs_ialloc_btree.h"
32 #include "xfs_alloc.h"
33 #include "xfs_btree.h"
34 #include "xfs_attr_sf.h"
35 #include "xfs_dir2_sf.h"
36 #include "xfs_dinode.h"
37 #include "xfs_inode.h"
39 #include "xfs_error.h"
41 #include "xfs_vnodeops.h"
42 #include "xfs_da_btree.h"
43 #include "xfs_ioctl.h"
44 #include "xfs_trace.h"
46 #include <linux/dcache.h>
48 static const struct vm_operations_struct xfs_file_vm_ops;
53 * xfs_iozero clears the specified range of buffer supplied,
54 * and marks all the affected blocks as valid and modified. If
55 * an affected block is not allocated, it will be allocated. If
56 * an affected block is not completely overwritten, and is not
57 * valid before the operation, it will be read from disk before
58 * being partially zeroed.
62 struct xfs_inode *ip, /* inode */
63 loff_t pos, /* offset in file */
64 size_t count) /* size of data to zero */
67 struct address_space *mapping;
70 mapping = VFS_I(ip)->i_mapping;
72 unsigned offset, bytes;
75 offset = (pos & (PAGE_CACHE_SIZE -1)); /* Within page */
76 bytes = PAGE_CACHE_SIZE - offset;
80 status = pagecache_write_begin(NULL, mapping, pos, bytes,
81 AOP_FLAG_UNINTERRUPTIBLE,
86 zero_user(page, offset, bytes);
88 status = pagecache_write_end(NULL, mapping, pos, bytes, bytes,
90 WARN_ON(status <= 0); /* can't return less than zero! */
102 const struct iovec *iovp,
103 unsigned long nr_segs,
106 struct file *file = iocb->ki_filp;
107 struct inode *inode = file->f_mapping->host;
108 struct xfs_inode *ip = XFS_I(inode);
109 struct xfs_mount *mp = ip->i_mount;
116 XFS_STATS_INC(xs_read_calls);
118 BUG_ON(iocb->ki_pos != pos);
120 if (unlikely(file->f_flags & O_DIRECT))
121 ioflags |= IO_ISDIRECT;
122 if (file->f_mode & FMODE_NOCMTIME)
125 /* START copy & waste from filemap.c */
126 for (seg = 0; seg < nr_segs; seg++) {
127 const struct iovec *iv = &iovp[seg];
130 * If any segment has a negative length, or the cumulative
131 * length ever wraps negative then return -EINVAL.
134 if (unlikely((ssize_t)(size|iv->iov_len) < 0))
135 return XFS_ERROR(-EINVAL);
137 /* END copy & waste from filemap.c */
139 if (unlikely(ioflags & IO_ISDIRECT)) {
140 xfs_buftarg_t *target =
141 XFS_IS_REALTIME_INODE(ip) ?
142 mp->m_rtdev_targp : mp->m_ddev_targp;
143 if ((iocb->ki_pos & target->bt_smask) ||
144 (size & target->bt_smask)) {
145 if (iocb->ki_pos == ip->i_size)
147 return -XFS_ERROR(EINVAL);
151 n = XFS_MAXIOFFSET(mp) - iocb->ki_pos;
152 if (n <= 0 || size == 0)
158 if (XFS_FORCED_SHUTDOWN(mp))
161 if (unlikely(ioflags & IO_ISDIRECT))
162 mutex_lock(&inode->i_mutex);
163 xfs_ilock(ip, XFS_IOLOCK_SHARED);
165 if (DM_EVENT_ENABLED(ip, DM_EVENT_READ) && !(ioflags & IO_INVIS)) {
166 int dmflags = FILP_DELAY_FLAG(file) | DM_SEM_FLAG_RD(ioflags);
167 int iolock = XFS_IOLOCK_SHARED;
169 ret = -XFS_SEND_DATA(mp, DM_EVENT_READ, ip, iocb->ki_pos, size,
172 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
173 if (unlikely(ioflags & IO_ISDIRECT))
174 mutex_unlock(&inode->i_mutex);
179 if (unlikely(ioflags & IO_ISDIRECT)) {
180 if (inode->i_mapping->nrpages) {
181 ret = -xfs_flushinval_pages(ip,
182 (iocb->ki_pos & PAGE_CACHE_MASK),
183 -1, FI_REMAPF_LOCKED);
185 mutex_unlock(&inode->i_mutex);
187 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
192 trace_xfs_file_read(ip, size, iocb->ki_pos, ioflags);
194 ret = generic_file_aio_read(iocb, iovp, nr_segs, iocb->ki_pos);
196 XFS_STATS_ADD(xs_read_bytes, ret);
198 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
203 xfs_file_splice_read(
206 struct pipe_inode_info *pipe,
210 struct xfs_inode *ip = XFS_I(infilp->f_mapping->host);
211 struct xfs_mount *mp = ip->i_mount;
215 XFS_STATS_INC(xs_read_calls);
217 if (infilp->f_mode & FMODE_NOCMTIME)
220 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
223 xfs_ilock(ip, XFS_IOLOCK_SHARED);
225 if (DM_EVENT_ENABLED(ip, DM_EVENT_READ) && !(ioflags & IO_INVIS)) {
226 int iolock = XFS_IOLOCK_SHARED;
229 error = XFS_SEND_DATA(mp, DM_EVENT_READ, ip, *ppos, count,
230 FILP_DELAY_FLAG(infilp), &iolock);
232 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
237 trace_xfs_file_splice_read(ip, count, *ppos, ioflags);
239 ret = generic_file_splice_read(infilp, ppos, pipe, count, flags);
241 XFS_STATS_ADD(xs_read_bytes, ret);
243 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
248 xfs_file_splice_write(
249 struct pipe_inode_info *pipe,
250 struct file *outfilp,
255 struct inode *inode = outfilp->f_mapping->host;
256 struct xfs_inode *ip = XFS_I(inode);
257 struct xfs_mount *mp = ip->i_mount;
258 xfs_fsize_t isize, new_size;
262 XFS_STATS_INC(xs_write_calls);
264 if (outfilp->f_mode & FMODE_NOCMTIME)
267 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
270 xfs_ilock(ip, XFS_IOLOCK_EXCL);
272 if (DM_EVENT_ENABLED(ip, DM_EVENT_WRITE) && !(ioflags & IO_INVIS)) {
273 int iolock = XFS_IOLOCK_EXCL;
276 error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, ip, *ppos, count,
277 FILP_DELAY_FLAG(outfilp), &iolock);
279 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
284 new_size = *ppos + count;
286 xfs_ilock(ip, XFS_ILOCK_EXCL);
287 if (new_size > ip->i_size)
288 ip->i_new_size = new_size;
289 xfs_iunlock(ip, XFS_ILOCK_EXCL);
291 trace_xfs_file_splice_write(ip, count, *ppos, ioflags);
293 ret = generic_file_splice_write(pipe, outfilp, ppos, count, flags);
295 XFS_STATS_ADD(xs_write_bytes, ret);
297 isize = i_size_read(inode);
298 if (unlikely(ret < 0 && ret != -EFAULT && *ppos > isize))
301 if (*ppos > ip->i_size) {
302 xfs_ilock(ip, XFS_ILOCK_EXCL);
303 if (*ppos > ip->i_size)
305 xfs_iunlock(ip, XFS_ILOCK_EXCL);
308 if (ip->i_new_size) {
309 xfs_ilock(ip, XFS_ILOCK_EXCL);
311 if (ip->i_d.di_size > ip->i_size)
312 ip->i_d.di_size = ip->i_size;
313 xfs_iunlock(ip, XFS_ILOCK_EXCL);
315 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
320 * This routine is called to handle zeroing any space in the last
321 * block of the file that is beyond the EOF. We do this since the
322 * size is being increased without writing anything to that block
323 * and we don't want anyone to read the garbage on the disk.
325 STATIC int /* error (positive) */
331 xfs_fileoff_t last_fsb;
332 xfs_mount_t *mp = ip->i_mount;
337 xfs_bmbt_irec_t imap;
339 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
341 zero_offset = XFS_B_FSB_OFFSET(mp, isize);
342 if (zero_offset == 0) {
344 * There are no extra bytes in the last block on disk to
350 last_fsb = XFS_B_TO_FSBT(mp, isize);
352 error = xfs_bmapi(NULL, ip, last_fsb, 1, 0, NULL, 0, &imap,
353 &nimaps, NULL, NULL);
359 * If the block underlying isize is just a hole, then there
360 * is nothing to zero.
362 if (imap.br_startblock == HOLESTARTBLOCK) {
366 * Zero the part of the last block beyond the EOF, and write it
367 * out sync. We need to drop the ilock while we do this so we
368 * don't deadlock when the buffer cache calls back to us.
370 xfs_iunlock(ip, XFS_ILOCK_EXCL);
372 zero_len = mp->m_sb.sb_blocksize - zero_offset;
373 if (isize + zero_len > offset)
374 zero_len = offset - isize;
375 error = xfs_iozero(ip, isize, zero_len);
377 xfs_ilock(ip, XFS_ILOCK_EXCL);
383 * Zero any on disk space between the current EOF and the new,
384 * larger EOF. This handles the normal case of zeroing the remainder
385 * of the last block in the file and the unusual case of zeroing blocks
386 * out beyond the size of the file. This second case only happens
387 * with fixed size extents and when the system crashes before the inode
388 * size was updated but after blocks were allocated. If fill is set,
389 * then any holes in the range are filled and zeroed. If not, the holes
390 * are left alone as holes.
393 int /* error (positive) */
396 xfs_off_t offset, /* starting I/O offset */
397 xfs_fsize_t isize) /* current inode size */
399 xfs_mount_t *mp = ip->i_mount;
400 xfs_fileoff_t start_zero_fsb;
401 xfs_fileoff_t end_zero_fsb;
402 xfs_fileoff_t zero_count_fsb;
403 xfs_fileoff_t last_fsb;
404 xfs_fileoff_t zero_off;
405 xfs_fsize_t zero_len;
408 xfs_bmbt_irec_t imap;
410 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
411 ASSERT(offset > isize);
414 * First handle zeroing the block on which isize resides.
415 * We only zero a part of that block so it is handled specially.
417 error = xfs_zero_last_block(ip, offset, isize);
419 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
424 * Calculate the range between the new size and the old
425 * where blocks needing to be zeroed may exist. To get the
426 * block where the last byte in the file currently resides,
427 * we need to subtract one from the size and truncate back
428 * to a block boundary. We subtract 1 in case the size is
429 * exactly on a block boundary.
431 last_fsb = isize ? XFS_B_TO_FSBT(mp, isize - 1) : (xfs_fileoff_t)-1;
432 start_zero_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)isize);
433 end_zero_fsb = XFS_B_TO_FSBT(mp, offset - 1);
434 ASSERT((xfs_sfiloff_t)last_fsb < (xfs_sfiloff_t)start_zero_fsb);
435 if (last_fsb == end_zero_fsb) {
437 * The size was only incremented on its last block.
438 * We took care of that above, so just return.
443 ASSERT(start_zero_fsb <= end_zero_fsb);
444 while (start_zero_fsb <= end_zero_fsb) {
446 zero_count_fsb = end_zero_fsb - start_zero_fsb + 1;
447 error = xfs_bmapi(NULL, ip, start_zero_fsb, zero_count_fsb,
448 0, NULL, 0, &imap, &nimaps, NULL, NULL);
450 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
455 if (imap.br_state == XFS_EXT_UNWRITTEN ||
456 imap.br_startblock == HOLESTARTBLOCK) {
458 * This loop handles initializing pages that were
459 * partially initialized by the code below this
460 * loop. It basically zeroes the part of the page
461 * that sits on a hole and sets the page as P_HOLE
462 * and calls remapf if it is a mapped file.
464 start_zero_fsb = imap.br_startoff + imap.br_blockcount;
465 ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
470 * There are blocks we need to zero.
471 * Drop the inode lock while we're doing the I/O.
472 * We'll still have the iolock to protect us.
474 xfs_iunlock(ip, XFS_ILOCK_EXCL);
476 zero_off = XFS_FSB_TO_B(mp, start_zero_fsb);
477 zero_len = XFS_FSB_TO_B(mp, imap.br_blockcount);
479 if ((zero_off + zero_len) > offset)
480 zero_len = offset - zero_off;
482 error = xfs_iozero(ip, zero_off, zero_len);
487 start_zero_fsb = imap.br_startoff + imap.br_blockcount;
488 ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
490 xfs_ilock(ip, XFS_ILOCK_EXCL);
496 xfs_ilock(ip, XFS_ILOCK_EXCL);
504 const struct iovec *iovp,
505 unsigned long nr_segs,
508 struct file *file = iocb->ki_filp;
509 struct address_space *mapping = file->f_mapping;
510 struct inode *inode = mapping->host;
511 struct xfs_inode *ip = XFS_I(inode);
512 struct xfs_mount *mp = ip->i_mount;
513 ssize_t ret = 0, error = 0;
515 xfs_fsize_t isize, new_size;
518 size_t ocount = 0, count;
521 XFS_STATS_INC(xs_write_calls);
523 BUG_ON(iocb->ki_pos != pos);
525 if (unlikely(file->f_flags & O_DIRECT))
526 ioflags |= IO_ISDIRECT;
527 if (file->f_mode & FMODE_NOCMTIME)
530 error = generic_segment_checks(iovp, &nr_segs, &ocount, VERIFY_READ);
538 xfs_wait_for_freeze(mp, SB_FREEZE_WRITE);
540 if (XFS_FORCED_SHUTDOWN(mp))
544 if (ioflags & IO_ISDIRECT) {
545 iolock = XFS_IOLOCK_SHARED;
548 iolock = XFS_IOLOCK_EXCL;
550 mutex_lock(&inode->i_mutex);
553 xfs_ilock(ip, XFS_ILOCK_EXCL|iolock);
556 error = -generic_write_checks(file, &pos, &count,
557 S_ISBLK(inode->i_mode));
559 xfs_iunlock(ip, XFS_ILOCK_EXCL|iolock);
560 goto out_unlock_mutex;
563 if ((DM_EVENT_ENABLED(ip, DM_EVENT_WRITE) &&
564 !(ioflags & IO_INVIS) && !eventsent)) {
565 int dmflags = FILP_DELAY_FLAG(file);
568 dmflags |= DM_FLAGS_IMUX;
570 xfs_iunlock(ip, XFS_ILOCK_EXCL);
571 error = XFS_SEND_DATA(ip->i_mount, DM_EVENT_WRITE, ip,
572 pos, count, dmflags, &iolock);
574 goto out_unlock_internal;
576 xfs_ilock(ip, XFS_ILOCK_EXCL);
580 * The iolock was dropped and reacquired in XFS_SEND_DATA
581 * so we have to recheck the size when appending.
582 * We will only "goto start;" once, since having sent the
583 * event prevents another call to XFS_SEND_DATA, which is
584 * what allows the size to change in the first place.
586 if ((file->f_flags & O_APPEND) && pos != ip->i_size)
590 if (ioflags & IO_ISDIRECT) {
591 xfs_buftarg_t *target =
592 XFS_IS_REALTIME_INODE(ip) ?
593 mp->m_rtdev_targp : mp->m_ddev_targp;
595 if ((pos & target->bt_smask) || (count & target->bt_smask)) {
596 xfs_iunlock(ip, XFS_ILOCK_EXCL|iolock);
597 return XFS_ERROR(-EINVAL);
600 if (!need_i_mutex && (mapping->nrpages || pos > ip->i_size)) {
601 xfs_iunlock(ip, XFS_ILOCK_EXCL|iolock);
602 iolock = XFS_IOLOCK_EXCL;
604 mutex_lock(&inode->i_mutex);
605 xfs_ilock(ip, XFS_ILOCK_EXCL|iolock);
610 new_size = pos + count;
611 if (new_size > ip->i_size)
612 ip->i_new_size = new_size;
614 if (likely(!(ioflags & IO_INVIS)))
615 file_update_time(file);
618 * If the offset is beyond the size of the file, we have a couple
619 * of things to do. First, if there is already space allocated
620 * we need to either create holes or zero the disk or ...
622 * If there is a page where the previous size lands, we need
623 * to zero it out up to the new size.
626 if (pos > ip->i_size) {
627 error = xfs_zero_eof(ip, pos, ip->i_size);
629 xfs_iunlock(ip, XFS_ILOCK_EXCL);
630 goto out_unlock_internal;
633 xfs_iunlock(ip, XFS_ILOCK_EXCL);
636 * If we're writing the file then make sure to clear the
637 * setuid and setgid bits if the process is not being run
638 * by root. This keeps people from modifying setuid and
641 error = -file_remove_suid(file);
643 goto out_unlock_internal;
645 /* We can write back this queue in page reclaim */
646 current->backing_dev_info = mapping->backing_dev_info;
648 if ((ioflags & IO_ISDIRECT)) {
649 if (mapping->nrpages) {
650 WARN_ON(need_i_mutex == 0);
651 error = xfs_flushinval_pages(ip,
652 (pos & PAGE_CACHE_MASK),
653 -1, FI_REMAPF_LOCKED);
655 goto out_unlock_internal;
659 /* demote the lock now the cached pages are gone */
660 xfs_ilock_demote(ip, XFS_IOLOCK_EXCL);
661 mutex_unlock(&inode->i_mutex);
663 iolock = XFS_IOLOCK_SHARED;
667 trace_xfs_file_direct_write(ip, count, iocb->ki_pos, ioflags);
668 ret = generic_file_direct_write(iocb, iovp,
669 &nr_segs, pos, &iocb->ki_pos, count, ocount);
672 * direct-io write to a hole: fall through to buffered I/O
673 * for completing the rest of the request.
675 if (ret >= 0 && ret != count) {
676 XFS_STATS_ADD(xs_write_bytes, ret);
681 ioflags &= ~IO_ISDIRECT;
682 xfs_iunlock(ip, iolock);
690 trace_xfs_file_buffered_write(ip, count, iocb->ki_pos, ioflags);
691 ret2 = generic_file_buffered_write(iocb, iovp, nr_segs,
692 pos, &iocb->ki_pos, count, ret);
694 * if we just got an ENOSPC, flush the inode now we
695 * aren't holding any page locks and retry *once*
697 if (ret2 == -ENOSPC && !enospc) {
698 error = xfs_flush_pages(ip, 0, -1, 0, FI_NONE);
700 goto out_unlock_internal;
707 current->backing_dev_info = NULL;
709 isize = i_size_read(inode);
710 if (unlikely(ret < 0 && ret != -EFAULT && iocb->ki_pos > isize))
711 iocb->ki_pos = isize;
713 if (iocb->ki_pos > ip->i_size) {
714 xfs_ilock(ip, XFS_ILOCK_EXCL);
715 if (iocb->ki_pos > ip->i_size)
716 ip->i_size = iocb->ki_pos;
717 xfs_iunlock(ip, XFS_ILOCK_EXCL);
720 if (ret == -ENOSPC &&
721 DM_EVENT_ENABLED(ip, DM_EVENT_NOSPACE) && !(ioflags & IO_INVIS)) {
722 xfs_iunlock(ip, iolock);
724 mutex_unlock(&inode->i_mutex);
725 error = XFS_SEND_NAMESP(ip->i_mount, DM_EVENT_NOSPACE, ip,
726 DM_RIGHT_NULL, ip, DM_RIGHT_NULL, NULL, NULL,
727 0, 0, 0); /* Delay flag intentionally unused */
729 mutex_lock(&inode->i_mutex);
730 xfs_ilock(ip, iolock);
732 goto out_unlock_internal;
738 goto out_unlock_internal;
740 XFS_STATS_ADD(xs_write_bytes, ret);
742 /* Handle various SYNC-type writes */
743 if ((file->f_flags & O_DSYNC) || IS_SYNC(inode)) {
744 loff_t end = pos + ret - 1;
747 xfs_iunlock(ip, iolock);
749 mutex_unlock(&inode->i_mutex);
751 error2 = filemap_write_and_wait_range(mapping, pos, end);
755 mutex_lock(&inode->i_mutex);
756 xfs_ilock(ip, iolock);
758 error2 = xfs_fsync(ip);
764 if (ip->i_new_size) {
765 xfs_ilock(ip, XFS_ILOCK_EXCL);
768 * If this was a direct or synchronous I/O that failed (such
769 * as ENOSPC) then part of the I/O may have been written to
770 * disk before the error occured. In this case the on-disk
771 * file size may have been adjusted beyond the in-memory file
772 * size and now needs to be truncated back.
774 if (ip->i_d.di_size > ip->i_size)
775 ip->i_d.di_size = ip->i_size;
776 xfs_iunlock(ip, XFS_ILOCK_EXCL);
778 xfs_iunlock(ip, iolock);
781 mutex_unlock(&inode->i_mutex);
790 if (!(file->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
792 if (XFS_FORCED_SHUTDOWN(XFS_M(inode->i_sb)))
802 struct xfs_inode *ip = XFS_I(inode);
806 error = xfs_file_open(inode, file);
811 * If there are any blocks, read-ahead block 0 as we're almost
812 * certain to have the next operation be a read there.
814 mode = xfs_ilock_map_shared(ip);
815 if (ip->i_d.di_nextents > 0)
816 xfs_da_reada_buf(NULL, ip, 0, XFS_DATA_FORK);
817 xfs_iunlock(ip, mode);
826 return -xfs_release(XFS_I(inode));
830 * We ignore the datasync flag here because a datasync is effectively
831 * identical to an fsync. That is, datasync implies that we need to write
832 * only the metadata needed to be able to access the data that is written
833 * if we crash after the call completes. Hence if we are writing beyond
834 * EOF we have to log the inode size change as well, which makes it a
835 * full fsync. If we don't write beyond EOF, the inode core will be
836 * clean in memory and so we don't need to log the inode, just like
842 struct dentry *dentry,
845 struct xfs_inode *ip = XFS_I(dentry->d_inode);
847 xfs_iflags_clear(ip, XFS_ITRUNCATED);
848 return -xfs_fsync(ip);
857 struct inode *inode = filp->f_path.dentry->d_inode;
858 xfs_inode_t *ip = XFS_I(inode);
863 * The Linux API doesn't pass down the total size of the buffer
864 * we read into down to the filesystem. With the filldir concept
865 * it's not needed for correct information, but the XFS dir2 leaf
866 * code wants an estimate of the buffer size to calculate it's
867 * readahead window and size the buffers used for mapping to
870 * Try to give it an estimate that's good enough, maybe at some
871 * point we can change the ->readdir prototype to include the
872 * buffer size. For now we use the current glibc buffer size.
874 bufsize = (size_t)min_t(loff_t, 32768, ip->i_d.di_size);
876 error = xfs_readdir(ip, dirent, bufsize,
877 (xfs_off_t *)&filp->f_pos, filldir);
886 struct vm_area_struct *vma)
888 vma->vm_ops = &xfs_file_vm_ops;
889 vma->vm_flags |= VM_CAN_NONLINEAR;
896 * mmap()d file has taken write protection fault and is being made
897 * writable. We can set the page state up correctly for a writable
898 * page, which means we can do correct delalloc accounting (ENOSPC
899 * checking!) and unwritten extent mapping.
903 struct vm_area_struct *vma,
904 struct vm_fault *vmf)
906 return block_page_mkwrite(vma, vmf, xfs_get_blocks);
909 const struct file_operations xfs_file_operations = {
910 .llseek = generic_file_llseek,
911 .read = do_sync_read,
912 .write = do_sync_write,
913 .aio_read = xfs_file_aio_read,
914 .aio_write = xfs_file_aio_write,
915 .splice_read = xfs_file_splice_read,
916 .splice_write = xfs_file_splice_write,
917 .unlocked_ioctl = xfs_file_ioctl,
919 .compat_ioctl = xfs_file_compat_ioctl,
921 .mmap = xfs_file_mmap,
922 .open = xfs_file_open,
923 .release = xfs_file_release,
924 .fsync = xfs_file_fsync,
925 #ifdef HAVE_FOP_OPEN_EXEC
926 .open_exec = xfs_file_open_exec,
930 const struct file_operations xfs_dir_file_operations = {
931 .open = xfs_dir_open,
932 .read = generic_read_dir,
933 .readdir = xfs_file_readdir,
934 .llseek = generic_file_llseek,
935 .unlocked_ioctl = xfs_file_ioctl,
937 .compat_ioctl = xfs_file_compat_ioctl,
939 .fsync = xfs_file_fsync,
942 static const struct vm_operations_struct xfs_file_vm_ops = {
943 .fault = filemap_fault,
944 .page_mkwrite = xfs_vm_page_mkwrite,