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_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"
34 #include "xfs_dir2_sf.h"
35 #include "xfs_dinode.h"
36 #include "xfs_inode.h"
37 #include "xfs_inode_item.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! */
104 struct inode *inode = file->f_mapping->host;
105 struct xfs_inode *ip = XFS_I(inode);
106 struct xfs_trans *tp;
110 xfs_itrace_entry(ip);
112 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
113 return -XFS_ERROR(EIO);
115 xfs_iflags_clear(ip, XFS_ITRUNCATED);
120 * We always need to make sure that the required inode state is safe on
121 * disk. The inode might be clean but we still might need to force the
122 * log because of committed transactions that haven't hit the disk yet.
123 * Likewise, there could be unflushed non-transactional changes to the
124 * inode core that have to go to disk and this requires us to issue
125 * a synchronous transaction to capture these changes correctly.
127 * This code relies on the assumption that if the i_update_core field
128 * of the inode is clear and the inode is unpinned then it is clean
129 * and no action is required.
131 xfs_ilock(ip, XFS_ILOCK_SHARED);
134 * First check if the VFS inode is marked dirty. All the dirtying
135 * of non-transactional updates no goes through mark_inode_dirty*,
136 * which allows us to distinguish beteeen pure timestamp updates
137 * and i_size updates which need to be caught for fdatasync.
138 * After that also theck for the dirty state in the XFS inode, which
139 * might gets cleared when the inode gets written out via the AIL
140 * or xfs_iflush_cluster.
142 if (((inode->i_state & I_DIRTY_DATASYNC) ||
143 ((inode->i_state & I_DIRTY_SYNC) && !datasync)) &&
146 * Kick off a transaction to log the inode core to get the
147 * updates. The sync transaction will also force the log.
149 xfs_iunlock(ip, XFS_ILOCK_SHARED);
150 tp = xfs_trans_alloc(ip->i_mount, XFS_TRANS_FSYNC_TS);
151 error = xfs_trans_reserve(tp, 0,
152 XFS_FSYNC_TS_LOG_RES(ip->i_mount), 0, 0, 0);
154 xfs_trans_cancel(tp, 0);
157 xfs_ilock(ip, XFS_ILOCK_EXCL);
160 * Note - it's possible that we might have pushed ourselves out
161 * of the way during trans_reserve which would flush the inode.
162 * But there's no guarantee that the inode buffer has actually
163 * gone out yet (it's delwri). Plus the buffer could be pinned
164 * anyway if it's part of an inode in another recent
165 * transaction. So we play it safe and fire off the
166 * transaction anyway.
168 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
169 xfs_trans_ihold(tp, ip);
170 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
171 xfs_trans_set_sync(tp);
172 error = _xfs_trans_commit(tp, 0, &log_flushed);
174 xfs_iunlock(ip, XFS_ILOCK_EXCL);
177 * Timestamps/size haven't changed since last inode flush or
178 * inode transaction commit. That means either nothing got
179 * written or a transaction committed which caught the updates.
180 * If the latter happened and the transaction hasn't hit the
181 * disk yet, the inode will be still be pinned. If it is,
184 if (xfs_ipincount(ip)) {
185 error = _xfs_log_force_lsn(ip->i_mount,
186 ip->i_itemp->ili_last_lsn,
187 XFS_LOG_SYNC, &log_flushed);
189 xfs_iunlock(ip, XFS_ILOCK_SHARED);
192 if (ip->i_mount->m_flags & XFS_MOUNT_BARRIER) {
194 * If the log write didn't issue an ordered tag we need
195 * to flush the disk cache for the data device now.
198 xfs_blkdev_issue_flush(ip->i_mount->m_ddev_targp);
201 * If this inode is on the RT dev we need to flush that
204 if (XFS_IS_REALTIME_INODE(ip))
205 xfs_blkdev_issue_flush(ip->i_mount->m_rtdev_targp);
214 const struct iovec *iovp,
215 unsigned long nr_segs,
218 struct file *file = iocb->ki_filp;
219 struct inode *inode = file->f_mapping->host;
220 struct xfs_inode *ip = XFS_I(inode);
221 struct xfs_mount *mp = ip->i_mount;
228 XFS_STATS_INC(xs_read_calls);
230 BUG_ON(iocb->ki_pos != pos);
232 if (unlikely(file->f_flags & O_DIRECT))
233 ioflags |= IO_ISDIRECT;
234 if (file->f_mode & FMODE_NOCMTIME)
237 /* START copy & waste from filemap.c */
238 for (seg = 0; seg < nr_segs; seg++) {
239 const struct iovec *iv = &iovp[seg];
242 * If any segment has a negative length, or the cumulative
243 * length ever wraps negative then return -EINVAL.
246 if (unlikely((ssize_t)(size|iv->iov_len) < 0))
247 return XFS_ERROR(-EINVAL);
249 /* END copy & waste from filemap.c */
251 if (unlikely(ioflags & IO_ISDIRECT)) {
252 xfs_buftarg_t *target =
253 XFS_IS_REALTIME_INODE(ip) ?
254 mp->m_rtdev_targp : mp->m_ddev_targp;
255 if ((iocb->ki_pos & target->bt_smask) ||
256 (size & target->bt_smask)) {
257 if (iocb->ki_pos == ip->i_size)
259 return -XFS_ERROR(EINVAL);
263 n = XFS_MAXIOFFSET(mp) - iocb->ki_pos;
264 if (n <= 0 || size == 0)
270 if (XFS_FORCED_SHUTDOWN(mp))
273 if (unlikely(ioflags & IO_ISDIRECT))
274 mutex_lock(&inode->i_mutex);
275 xfs_ilock(ip, XFS_IOLOCK_SHARED);
277 if (unlikely(ioflags & IO_ISDIRECT)) {
278 if (inode->i_mapping->nrpages) {
279 ret = -xfs_flushinval_pages(ip,
280 (iocb->ki_pos & PAGE_CACHE_MASK),
281 -1, FI_REMAPF_LOCKED);
283 mutex_unlock(&inode->i_mutex);
285 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
290 trace_xfs_file_read(ip, size, iocb->ki_pos, ioflags);
292 ret = generic_file_aio_read(iocb, iovp, nr_segs, iocb->ki_pos);
294 XFS_STATS_ADD(xs_read_bytes, ret);
296 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
301 xfs_file_splice_read(
304 struct pipe_inode_info *pipe,
308 struct xfs_inode *ip = XFS_I(infilp->f_mapping->host);
312 XFS_STATS_INC(xs_read_calls);
314 if (infilp->f_mode & FMODE_NOCMTIME)
317 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
320 xfs_ilock(ip, XFS_IOLOCK_SHARED);
322 trace_xfs_file_splice_read(ip, count, *ppos, ioflags);
324 ret = generic_file_splice_read(infilp, ppos, pipe, count, flags);
326 XFS_STATS_ADD(xs_read_bytes, ret);
328 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
333 xfs_file_splice_write(
334 struct pipe_inode_info *pipe,
335 struct file *outfilp,
340 struct inode *inode = outfilp->f_mapping->host;
341 struct xfs_inode *ip = XFS_I(inode);
342 xfs_fsize_t isize, new_size;
346 XFS_STATS_INC(xs_write_calls);
348 if (outfilp->f_mode & FMODE_NOCMTIME)
351 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
354 xfs_ilock(ip, XFS_IOLOCK_EXCL);
356 new_size = *ppos + count;
358 xfs_ilock(ip, XFS_ILOCK_EXCL);
359 if (new_size > ip->i_size)
360 ip->i_new_size = new_size;
361 xfs_iunlock(ip, XFS_ILOCK_EXCL);
363 trace_xfs_file_splice_write(ip, count, *ppos, ioflags);
365 ret = generic_file_splice_write(pipe, outfilp, ppos, count, flags);
367 XFS_STATS_ADD(xs_write_bytes, ret);
369 isize = i_size_read(inode);
370 if (unlikely(ret < 0 && ret != -EFAULT && *ppos > isize))
373 if (*ppos > ip->i_size) {
374 xfs_ilock(ip, XFS_ILOCK_EXCL);
375 if (*ppos > ip->i_size)
377 xfs_iunlock(ip, XFS_ILOCK_EXCL);
380 if (ip->i_new_size) {
381 xfs_ilock(ip, XFS_ILOCK_EXCL);
383 if (ip->i_d.di_size > ip->i_size)
384 ip->i_d.di_size = ip->i_size;
385 xfs_iunlock(ip, XFS_ILOCK_EXCL);
387 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
392 * This routine is called to handle zeroing any space in the last
393 * block of the file that is beyond the EOF. We do this since the
394 * size is being increased without writing anything to that block
395 * and we don't want anyone to read the garbage on the disk.
397 STATIC int /* error (positive) */
403 xfs_fileoff_t last_fsb;
404 xfs_mount_t *mp = ip->i_mount;
409 xfs_bmbt_irec_t imap;
411 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
413 zero_offset = XFS_B_FSB_OFFSET(mp, isize);
414 if (zero_offset == 0) {
416 * There are no extra bytes in the last block on disk to
422 last_fsb = XFS_B_TO_FSBT(mp, isize);
424 error = xfs_bmapi(NULL, ip, last_fsb, 1, 0, NULL, 0, &imap,
425 &nimaps, NULL, NULL);
431 * If the block underlying isize is just a hole, then there
432 * is nothing to zero.
434 if (imap.br_startblock == HOLESTARTBLOCK) {
438 * Zero the part of the last block beyond the EOF, and write it
439 * out sync. We need to drop the ilock while we do this so we
440 * don't deadlock when the buffer cache calls back to us.
442 xfs_iunlock(ip, XFS_ILOCK_EXCL);
444 zero_len = mp->m_sb.sb_blocksize - zero_offset;
445 if (isize + zero_len > offset)
446 zero_len = offset - isize;
447 error = xfs_iozero(ip, isize, zero_len);
449 xfs_ilock(ip, XFS_ILOCK_EXCL);
455 * Zero any on disk space between the current EOF and the new,
456 * larger EOF. This handles the normal case of zeroing the remainder
457 * of the last block in the file and the unusual case of zeroing blocks
458 * out beyond the size of the file. This second case only happens
459 * with fixed size extents and when the system crashes before the inode
460 * size was updated but after blocks were allocated. If fill is set,
461 * then any holes in the range are filled and zeroed. If not, the holes
462 * are left alone as holes.
465 int /* error (positive) */
468 xfs_off_t offset, /* starting I/O offset */
469 xfs_fsize_t isize) /* current inode size */
471 xfs_mount_t *mp = ip->i_mount;
472 xfs_fileoff_t start_zero_fsb;
473 xfs_fileoff_t end_zero_fsb;
474 xfs_fileoff_t zero_count_fsb;
475 xfs_fileoff_t last_fsb;
476 xfs_fileoff_t zero_off;
477 xfs_fsize_t zero_len;
480 xfs_bmbt_irec_t imap;
482 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
483 ASSERT(offset > isize);
486 * First handle zeroing the block on which isize resides.
487 * We only zero a part of that block so it is handled specially.
489 error = xfs_zero_last_block(ip, offset, isize);
491 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
496 * Calculate the range between the new size and the old
497 * where blocks needing to be zeroed may exist. To get the
498 * block where the last byte in the file currently resides,
499 * we need to subtract one from the size and truncate back
500 * to a block boundary. We subtract 1 in case the size is
501 * exactly on a block boundary.
503 last_fsb = isize ? XFS_B_TO_FSBT(mp, isize - 1) : (xfs_fileoff_t)-1;
504 start_zero_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)isize);
505 end_zero_fsb = XFS_B_TO_FSBT(mp, offset - 1);
506 ASSERT((xfs_sfiloff_t)last_fsb < (xfs_sfiloff_t)start_zero_fsb);
507 if (last_fsb == end_zero_fsb) {
509 * The size was only incremented on its last block.
510 * We took care of that above, so just return.
515 ASSERT(start_zero_fsb <= end_zero_fsb);
516 while (start_zero_fsb <= end_zero_fsb) {
518 zero_count_fsb = end_zero_fsb - start_zero_fsb + 1;
519 error = xfs_bmapi(NULL, ip, start_zero_fsb, zero_count_fsb,
520 0, NULL, 0, &imap, &nimaps, NULL, NULL);
522 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
527 if (imap.br_state == XFS_EXT_UNWRITTEN ||
528 imap.br_startblock == HOLESTARTBLOCK) {
530 * This loop handles initializing pages that were
531 * partially initialized by the code below this
532 * loop. It basically zeroes the part of the page
533 * that sits on a hole and sets the page as P_HOLE
534 * and calls remapf if it is a mapped file.
536 start_zero_fsb = imap.br_startoff + imap.br_blockcount;
537 ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
542 * There are blocks we need to zero.
543 * Drop the inode lock while we're doing the I/O.
544 * We'll still have the iolock to protect us.
546 xfs_iunlock(ip, XFS_ILOCK_EXCL);
548 zero_off = XFS_FSB_TO_B(mp, start_zero_fsb);
549 zero_len = XFS_FSB_TO_B(mp, imap.br_blockcount);
551 if ((zero_off + zero_len) > offset)
552 zero_len = offset - zero_off;
554 error = xfs_iozero(ip, zero_off, zero_len);
559 start_zero_fsb = imap.br_startoff + imap.br_blockcount;
560 ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
562 xfs_ilock(ip, XFS_ILOCK_EXCL);
568 xfs_ilock(ip, XFS_ILOCK_EXCL);
576 const struct iovec *iovp,
577 unsigned long nr_segs,
580 struct file *file = iocb->ki_filp;
581 struct address_space *mapping = file->f_mapping;
582 struct inode *inode = mapping->host;
583 struct xfs_inode *ip = XFS_I(inode);
584 struct xfs_mount *mp = ip->i_mount;
585 ssize_t ret = 0, error = 0;
587 xfs_fsize_t isize, new_size;
589 size_t ocount = 0, count;
592 XFS_STATS_INC(xs_write_calls);
594 BUG_ON(iocb->ki_pos != pos);
596 if (unlikely(file->f_flags & O_DIRECT))
597 ioflags |= IO_ISDIRECT;
598 if (file->f_mode & FMODE_NOCMTIME)
601 error = generic_segment_checks(iovp, &nr_segs, &ocount, VERIFY_READ);
609 xfs_wait_for_freeze(mp, SB_FREEZE_WRITE);
611 if (XFS_FORCED_SHUTDOWN(mp))
615 if (ioflags & IO_ISDIRECT) {
616 iolock = XFS_IOLOCK_SHARED;
619 iolock = XFS_IOLOCK_EXCL;
621 mutex_lock(&inode->i_mutex);
624 xfs_ilock(ip, XFS_ILOCK_EXCL|iolock);
627 error = -generic_write_checks(file, &pos, &count,
628 S_ISBLK(inode->i_mode));
630 xfs_iunlock(ip, XFS_ILOCK_EXCL|iolock);
631 goto out_unlock_mutex;
634 if (ioflags & IO_ISDIRECT) {
635 xfs_buftarg_t *target =
636 XFS_IS_REALTIME_INODE(ip) ?
637 mp->m_rtdev_targp : mp->m_ddev_targp;
639 if ((pos & target->bt_smask) || (count & target->bt_smask)) {
640 xfs_iunlock(ip, XFS_ILOCK_EXCL|iolock);
641 return XFS_ERROR(-EINVAL);
644 if (!need_i_mutex && (mapping->nrpages || pos > ip->i_size)) {
645 xfs_iunlock(ip, XFS_ILOCK_EXCL|iolock);
646 iolock = XFS_IOLOCK_EXCL;
648 mutex_lock(&inode->i_mutex);
649 xfs_ilock(ip, XFS_ILOCK_EXCL|iolock);
654 new_size = pos + count;
655 if (new_size > ip->i_size)
656 ip->i_new_size = new_size;
658 if (likely(!(ioflags & IO_INVIS)))
659 file_update_time(file);
662 * If the offset is beyond the size of the file, we have a couple
663 * of things to do. First, if there is already space allocated
664 * we need to either create holes or zero the disk or ...
666 * If there is a page where the previous size lands, we need
667 * to zero it out up to the new size.
670 if (pos > ip->i_size) {
671 error = xfs_zero_eof(ip, pos, ip->i_size);
673 xfs_iunlock(ip, XFS_ILOCK_EXCL);
674 goto out_unlock_internal;
677 xfs_iunlock(ip, XFS_ILOCK_EXCL);
680 * If we're writing the file then make sure to clear the
681 * setuid and setgid bits if the process is not being run
682 * by root. This keeps people from modifying setuid and
685 error = -file_remove_suid(file);
687 goto out_unlock_internal;
689 /* We can write back this queue in page reclaim */
690 current->backing_dev_info = mapping->backing_dev_info;
692 if ((ioflags & IO_ISDIRECT)) {
693 if (mapping->nrpages) {
694 WARN_ON(need_i_mutex == 0);
695 error = xfs_flushinval_pages(ip,
696 (pos & PAGE_CACHE_MASK),
697 -1, FI_REMAPF_LOCKED);
699 goto out_unlock_internal;
703 /* demote the lock now the cached pages are gone */
704 xfs_ilock_demote(ip, XFS_IOLOCK_EXCL);
705 mutex_unlock(&inode->i_mutex);
707 iolock = XFS_IOLOCK_SHARED;
711 trace_xfs_file_direct_write(ip, count, iocb->ki_pos, ioflags);
712 ret = generic_file_direct_write(iocb, iovp,
713 &nr_segs, pos, &iocb->ki_pos, count, ocount);
716 * direct-io write to a hole: fall through to buffered I/O
717 * for completing the rest of the request.
719 if (ret >= 0 && ret != count) {
720 XFS_STATS_ADD(xs_write_bytes, ret);
725 ioflags &= ~IO_ISDIRECT;
726 xfs_iunlock(ip, iolock);
734 trace_xfs_file_buffered_write(ip, count, iocb->ki_pos, ioflags);
735 ret2 = generic_file_buffered_write(iocb, iovp, nr_segs,
736 pos, &iocb->ki_pos, count, ret);
738 * if we just got an ENOSPC, flush the inode now we
739 * aren't holding any page locks and retry *once*
741 if (ret2 == -ENOSPC && !enospc) {
742 error = xfs_flush_pages(ip, 0, -1, 0, FI_NONE);
744 goto out_unlock_internal;
751 current->backing_dev_info = NULL;
753 isize = i_size_read(inode);
754 if (unlikely(ret < 0 && ret != -EFAULT && iocb->ki_pos > isize))
755 iocb->ki_pos = isize;
757 if (iocb->ki_pos > ip->i_size) {
758 xfs_ilock(ip, XFS_ILOCK_EXCL);
759 if (iocb->ki_pos > ip->i_size)
760 ip->i_size = iocb->ki_pos;
761 xfs_iunlock(ip, XFS_ILOCK_EXCL);
766 goto out_unlock_internal;
768 XFS_STATS_ADD(xs_write_bytes, ret);
770 /* Handle various SYNC-type writes */
771 if ((file->f_flags & O_DSYNC) || IS_SYNC(inode)) {
772 loff_t end = pos + ret - 1;
775 xfs_iunlock(ip, iolock);
777 mutex_unlock(&inode->i_mutex);
779 error2 = filemap_write_and_wait_range(mapping, pos, end);
783 mutex_lock(&inode->i_mutex);
784 xfs_ilock(ip, iolock);
786 error2 = -xfs_file_fsync(file,
787 (file->f_flags & __O_SYNC) ? 0 : 1);
793 if (ip->i_new_size) {
794 xfs_ilock(ip, XFS_ILOCK_EXCL);
797 * If this was a direct or synchronous I/O that failed (such
798 * as ENOSPC) then part of the I/O may have been written to
799 * disk before the error occured. In this case the on-disk
800 * file size may have been adjusted beyond the in-memory file
801 * size and now needs to be truncated back.
803 if (ip->i_d.di_size > ip->i_size)
804 ip->i_d.di_size = ip->i_size;
805 xfs_iunlock(ip, XFS_ILOCK_EXCL);
807 xfs_iunlock(ip, iolock);
810 mutex_unlock(&inode->i_mutex);
819 if (!(file->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
821 if (XFS_FORCED_SHUTDOWN(XFS_M(inode->i_sb)))
831 struct xfs_inode *ip = XFS_I(inode);
835 error = xfs_file_open(inode, file);
840 * If there are any blocks, read-ahead block 0 as we're almost
841 * certain to have the next operation be a read there.
843 mode = xfs_ilock_map_shared(ip);
844 if (ip->i_d.di_nextents > 0)
845 xfs_da_reada_buf(NULL, ip, 0, XFS_DATA_FORK);
846 xfs_iunlock(ip, mode);
855 return -xfs_release(XFS_I(inode));
864 struct inode *inode = filp->f_path.dentry->d_inode;
865 xfs_inode_t *ip = XFS_I(inode);
870 * The Linux API doesn't pass down the total size of the buffer
871 * we read into down to the filesystem. With the filldir concept
872 * it's not needed for correct information, but the XFS dir2 leaf
873 * code wants an estimate of the buffer size to calculate it's
874 * readahead window and size the buffers used for mapping to
877 * Try to give it an estimate that's good enough, maybe at some
878 * point we can change the ->readdir prototype to include the
879 * buffer size. For now we use the current glibc buffer size.
881 bufsize = (size_t)min_t(loff_t, 32768, ip->i_d.di_size);
883 error = xfs_readdir(ip, dirent, bufsize,
884 (xfs_off_t *)&filp->f_pos, filldir);
893 struct vm_area_struct *vma)
895 vma->vm_ops = &xfs_file_vm_ops;
896 vma->vm_flags |= VM_CAN_NONLINEAR;
903 * mmap()d file has taken write protection fault and is being made
904 * writable. We can set the page state up correctly for a writable
905 * page, which means we can do correct delalloc accounting (ENOSPC
906 * checking!) and unwritten extent mapping.
910 struct vm_area_struct *vma,
911 struct vm_fault *vmf)
913 return block_page_mkwrite(vma, vmf, xfs_get_blocks);
916 const struct file_operations xfs_file_operations = {
917 .llseek = generic_file_llseek,
918 .read = do_sync_read,
919 .write = do_sync_write,
920 .aio_read = xfs_file_aio_read,
921 .aio_write = xfs_file_aio_write,
922 .splice_read = xfs_file_splice_read,
923 .splice_write = xfs_file_splice_write,
924 .unlocked_ioctl = xfs_file_ioctl,
926 .compat_ioctl = xfs_file_compat_ioctl,
928 .mmap = xfs_file_mmap,
929 .open = xfs_file_open,
930 .release = xfs_file_release,
931 .fsync = xfs_file_fsync,
932 #ifdef HAVE_FOP_OPEN_EXEC
933 .open_exec = xfs_file_open_exec,
937 const struct file_operations xfs_dir_file_operations = {
938 .open = xfs_dir_open,
939 .read = generic_read_dir,
940 .readdir = xfs_file_readdir,
941 .llseek = generic_file_llseek,
942 .unlocked_ioctl = xfs_file_ioctl,
944 .compat_ioctl = xfs_file_compat_ioctl,
946 .fsync = xfs_file_fsync,
949 static const struct vm_operations_struct xfs_file_vm_ops = {
950 .fault = filemap_fault,
951 .page_mkwrite = xfs_vm_page_mkwrite,