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! */
99 ssize_t /* bytes read, or (-) error */
103 const struct iovec *iovp,
108 struct file *file = iocb->ki_filp;
109 struct inode *inode = file->f_mapping->host;
110 xfs_mount_t *mp = ip->i_mount;
117 XFS_STATS_INC(xs_read_calls);
119 /* START copy & waste from filemap.c */
120 for (seg = 0; seg < segs; seg++) {
121 const struct iovec *iv = &iovp[seg];
124 * If any segment has a negative length, or the cumulative
125 * length ever wraps negative then return -EINVAL.
128 if (unlikely((ssize_t)(size|iv->iov_len) < 0))
129 return XFS_ERROR(-EINVAL);
131 /* END copy & waste from filemap.c */
133 if (unlikely(ioflags & IO_ISDIRECT)) {
134 xfs_buftarg_t *target =
135 XFS_IS_REALTIME_INODE(ip) ?
136 mp->m_rtdev_targp : mp->m_ddev_targp;
137 if ((*offset & target->bt_smask) ||
138 (size & target->bt_smask)) {
139 if (*offset == ip->i_size) {
142 return -XFS_ERROR(EINVAL);
146 n = XFS_MAXIOFFSET(mp) - *offset;
147 if ((n <= 0) || (size == 0))
153 if (XFS_FORCED_SHUTDOWN(mp))
156 if (unlikely(ioflags & IO_ISDIRECT))
157 mutex_lock(&inode->i_mutex);
158 xfs_ilock(ip, XFS_IOLOCK_SHARED);
160 if (DM_EVENT_ENABLED(ip, DM_EVENT_READ) && !(ioflags & IO_INVIS)) {
161 int dmflags = FILP_DELAY_FLAG(file) | DM_SEM_FLAG_RD(ioflags);
162 int iolock = XFS_IOLOCK_SHARED;
164 ret = -XFS_SEND_DATA(mp, DM_EVENT_READ, ip, *offset, size,
167 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
168 if (unlikely(ioflags & IO_ISDIRECT))
169 mutex_unlock(&inode->i_mutex);
174 if (unlikely(ioflags & IO_ISDIRECT)) {
175 if (inode->i_mapping->nrpages)
176 ret = -xfs_flushinval_pages(ip, (*offset & PAGE_CACHE_MASK),
177 -1, FI_REMAPF_LOCKED);
178 mutex_unlock(&inode->i_mutex);
180 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
185 trace_xfs_file_read(ip, size, *offset, ioflags);
187 iocb->ki_pos = *offset;
188 ret = generic_file_aio_read(iocb, iovp, segs, *offset);
190 XFS_STATS_ADD(xs_read_bytes, ret);
192 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
201 struct pipe_inode_info *pipe,
206 xfs_mount_t *mp = ip->i_mount;
209 XFS_STATS_INC(xs_read_calls);
210 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
213 xfs_ilock(ip, XFS_IOLOCK_SHARED);
215 if (DM_EVENT_ENABLED(ip, DM_EVENT_READ) && !(ioflags & IO_INVIS)) {
216 int iolock = XFS_IOLOCK_SHARED;
219 error = XFS_SEND_DATA(mp, DM_EVENT_READ, ip, *ppos, count,
220 FILP_DELAY_FLAG(infilp), &iolock);
222 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
227 trace_xfs_file_splice_read(ip, count, *ppos, ioflags);
229 ret = generic_file_splice_read(infilp, ppos, pipe, count, flags);
231 XFS_STATS_ADD(xs_read_bytes, ret);
233 xfs_iunlock(ip, XFS_IOLOCK_SHARED);
240 struct pipe_inode_info *pipe,
241 struct file *outfilp,
247 xfs_mount_t *mp = ip->i_mount;
249 struct inode *inode = outfilp->f_mapping->host;
250 xfs_fsize_t isize, new_size;
252 XFS_STATS_INC(xs_write_calls);
253 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
256 xfs_ilock(ip, XFS_IOLOCK_EXCL);
258 if (DM_EVENT_ENABLED(ip, DM_EVENT_WRITE) && !(ioflags & IO_INVIS)) {
259 int iolock = XFS_IOLOCK_EXCL;
262 error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, ip, *ppos, count,
263 FILP_DELAY_FLAG(outfilp), &iolock);
265 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
270 new_size = *ppos + count;
272 xfs_ilock(ip, XFS_ILOCK_EXCL);
273 if (new_size > ip->i_size)
274 ip->i_new_size = new_size;
275 xfs_iunlock(ip, XFS_ILOCK_EXCL);
277 trace_xfs_file_splice_write(ip, count, *ppos, ioflags);
279 ret = generic_file_splice_write(pipe, outfilp, ppos, count, flags);
281 XFS_STATS_ADD(xs_write_bytes, ret);
283 isize = i_size_read(inode);
284 if (unlikely(ret < 0 && ret != -EFAULT && *ppos > isize))
287 if (*ppos > ip->i_size) {
288 xfs_ilock(ip, XFS_ILOCK_EXCL);
289 if (*ppos > ip->i_size)
291 xfs_iunlock(ip, XFS_ILOCK_EXCL);
294 if (ip->i_new_size) {
295 xfs_ilock(ip, XFS_ILOCK_EXCL);
297 if (ip->i_d.di_size > ip->i_size)
298 ip->i_d.di_size = ip->i_size;
299 xfs_iunlock(ip, XFS_ILOCK_EXCL);
301 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
306 * This routine is called to handle zeroing any space in the last
307 * block of the file that is beyond the EOF. We do this since the
308 * size is being increased without writing anything to that block
309 * and we don't want anyone to read the garbage on the disk.
311 STATIC int /* error (positive) */
317 xfs_fileoff_t last_fsb;
318 xfs_mount_t *mp = ip->i_mount;
323 xfs_bmbt_irec_t imap;
325 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
327 zero_offset = XFS_B_FSB_OFFSET(mp, isize);
328 if (zero_offset == 0) {
330 * There are no extra bytes in the last block on disk to
336 last_fsb = XFS_B_TO_FSBT(mp, isize);
338 error = xfs_bmapi(NULL, ip, last_fsb, 1, 0, NULL, 0, &imap,
339 &nimaps, NULL, NULL);
345 * If the block underlying isize is just a hole, then there
346 * is nothing to zero.
348 if (imap.br_startblock == HOLESTARTBLOCK) {
352 * Zero the part of the last block beyond the EOF, and write it
353 * out sync. We need to drop the ilock while we do this so we
354 * don't deadlock when the buffer cache calls back to us.
356 xfs_iunlock(ip, XFS_ILOCK_EXCL);
358 zero_len = mp->m_sb.sb_blocksize - zero_offset;
359 if (isize + zero_len > offset)
360 zero_len = offset - isize;
361 error = xfs_iozero(ip, isize, zero_len);
363 xfs_ilock(ip, XFS_ILOCK_EXCL);
369 * Zero any on disk space between the current EOF and the new,
370 * larger EOF. This handles the normal case of zeroing the remainder
371 * of the last block in the file and the unusual case of zeroing blocks
372 * out beyond the size of the file. This second case only happens
373 * with fixed size extents and when the system crashes before the inode
374 * size was updated but after blocks were allocated. If fill is set,
375 * then any holes in the range are filled and zeroed. If not, the holes
376 * are left alone as holes.
379 int /* error (positive) */
382 xfs_off_t offset, /* starting I/O offset */
383 xfs_fsize_t isize) /* current inode size */
385 xfs_mount_t *mp = ip->i_mount;
386 xfs_fileoff_t start_zero_fsb;
387 xfs_fileoff_t end_zero_fsb;
388 xfs_fileoff_t zero_count_fsb;
389 xfs_fileoff_t last_fsb;
390 xfs_fileoff_t zero_off;
391 xfs_fsize_t zero_len;
394 xfs_bmbt_irec_t imap;
396 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
397 ASSERT(offset > isize);
400 * First handle zeroing the block on which isize resides.
401 * We only zero a part of that block so it is handled specially.
403 error = xfs_zero_last_block(ip, offset, isize);
405 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
410 * Calculate the range between the new size and the old
411 * where blocks needing to be zeroed may exist. To get the
412 * block where the last byte in the file currently resides,
413 * we need to subtract one from the size and truncate back
414 * to a block boundary. We subtract 1 in case the size is
415 * exactly on a block boundary.
417 last_fsb = isize ? XFS_B_TO_FSBT(mp, isize - 1) : (xfs_fileoff_t)-1;
418 start_zero_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)isize);
419 end_zero_fsb = XFS_B_TO_FSBT(mp, offset - 1);
420 ASSERT((xfs_sfiloff_t)last_fsb < (xfs_sfiloff_t)start_zero_fsb);
421 if (last_fsb == end_zero_fsb) {
423 * The size was only incremented on its last block.
424 * We took care of that above, so just return.
429 ASSERT(start_zero_fsb <= end_zero_fsb);
430 while (start_zero_fsb <= end_zero_fsb) {
432 zero_count_fsb = end_zero_fsb - start_zero_fsb + 1;
433 error = xfs_bmapi(NULL, ip, start_zero_fsb, zero_count_fsb,
434 0, NULL, 0, &imap, &nimaps, NULL, NULL);
436 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
441 if (imap.br_state == XFS_EXT_UNWRITTEN ||
442 imap.br_startblock == HOLESTARTBLOCK) {
444 * This loop handles initializing pages that were
445 * partially initialized by the code below this
446 * loop. It basically zeroes the part of the page
447 * that sits on a hole and sets the page as P_HOLE
448 * and calls remapf if it is a mapped file.
450 start_zero_fsb = imap.br_startoff + imap.br_blockcount;
451 ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
456 * There are blocks we need to zero.
457 * Drop the inode lock while we're doing the I/O.
458 * We'll still have the iolock to protect us.
460 xfs_iunlock(ip, XFS_ILOCK_EXCL);
462 zero_off = XFS_FSB_TO_B(mp, start_zero_fsb);
463 zero_len = XFS_FSB_TO_B(mp, imap.br_blockcount);
465 if ((zero_off + zero_len) > offset)
466 zero_len = offset - zero_off;
468 error = xfs_iozero(ip, zero_off, zero_len);
473 start_zero_fsb = imap.br_startoff + imap.br_blockcount;
474 ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
476 xfs_ilock(ip, XFS_ILOCK_EXCL);
482 xfs_ilock(ip, XFS_ILOCK_EXCL);
487 ssize_t /* bytes written, or (-) error */
489 struct xfs_inode *xip,
491 const struct iovec *iovp,
496 struct file *file = iocb->ki_filp;
497 struct address_space *mapping = file->f_mapping;
498 struct inode *inode = mapping->host;
499 unsigned long segs = nsegs;
501 ssize_t ret = 0, error = 0;
502 xfs_fsize_t isize, new_size;
505 size_t ocount = 0, count;
509 XFS_STATS_INC(xs_write_calls);
511 error = generic_segment_checks(iovp, &segs, &ocount, VERIFY_READ);
523 xfs_wait_for_freeze(mp, SB_FREEZE_WRITE);
525 if (XFS_FORCED_SHUTDOWN(mp))
529 if (ioflags & IO_ISDIRECT) {
530 iolock = XFS_IOLOCK_SHARED;
533 iolock = XFS_IOLOCK_EXCL;
535 mutex_lock(&inode->i_mutex);
538 xfs_ilock(xip, XFS_ILOCK_EXCL|iolock);
541 error = -generic_write_checks(file, &pos, &count,
542 S_ISBLK(inode->i_mode));
544 xfs_iunlock(xip, XFS_ILOCK_EXCL|iolock);
545 goto out_unlock_mutex;
548 if ((DM_EVENT_ENABLED(xip, DM_EVENT_WRITE) &&
549 !(ioflags & IO_INVIS) && !eventsent)) {
550 int dmflags = FILP_DELAY_FLAG(file);
553 dmflags |= DM_FLAGS_IMUX;
555 xfs_iunlock(xip, XFS_ILOCK_EXCL);
556 error = XFS_SEND_DATA(xip->i_mount, DM_EVENT_WRITE, xip,
557 pos, count, dmflags, &iolock);
559 goto out_unlock_internal;
561 xfs_ilock(xip, XFS_ILOCK_EXCL);
565 * The iolock was dropped and reacquired in XFS_SEND_DATA
566 * so we have to recheck the size when appending.
567 * We will only "goto start;" once, since having sent the
568 * event prevents another call to XFS_SEND_DATA, which is
569 * what allows the size to change in the first place.
571 if ((file->f_flags & O_APPEND) && pos != xip->i_size)
575 if (ioflags & IO_ISDIRECT) {
576 xfs_buftarg_t *target =
577 XFS_IS_REALTIME_INODE(xip) ?
578 mp->m_rtdev_targp : mp->m_ddev_targp;
580 if ((pos & target->bt_smask) || (count & target->bt_smask)) {
581 xfs_iunlock(xip, XFS_ILOCK_EXCL|iolock);
582 return XFS_ERROR(-EINVAL);
585 if (!need_i_mutex && (mapping->nrpages || pos > xip->i_size)) {
586 xfs_iunlock(xip, XFS_ILOCK_EXCL|iolock);
587 iolock = XFS_IOLOCK_EXCL;
589 mutex_lock(&inode->i_mutex);
590 xfs_ilock(xip, XFS_ILOCK_EXCL|iolock);
595 new_size = pos + count;
596 if (new_size > xip->i_size)
597 xip->i_new_size = new_size;
599 if (likely(!(ioflags & IO_INVIS)))
600 file_update_time(file);
603 * If the offset is beyond the size of the file, we have a couple
604 * of things to do. First, if there is already space allocated
605 * we need to either create holes or zero the disk or ...
607 * If there is a page where the previous size lands, we need
608 * to zero it out up to the new size.
611 if (pos > xip->i_size) {
612 error = xfs_zero_eof(xip, pos, xip->i_size);
614 xfs_iunlock(xip, XFS_ILOCK_EXCL);
615 goto out_unlock_internal;
618 xfs_iunlock(xip, XFS_ILOCK_EXCL);
621 * If we're writing the file then make sure to clear the
622 * setuid and setgid bits if the process is not being run
623 * by root. This keeps people from modifying setuid and
626 error = -file_remove_suid(file);
628 goto out_unlock_internal;
630 /* We can write back this queue in page reclaim */
631 current->backing_dev_info = mapping->backing_dev_info;
633 if ((ioflags & IO_ISDIRECT)) {
634 if (mapping->nrpages) {
635 WARN_ON(need_i_mutex == 0);
636 error = xfs_flushinval_pages(xip,
637 (pos & PAGE_CACHE_MASK),
638 -1, FI_REMAPF_LOCKED);
640 goto out_unlock_internal;
644 /* demote the lock now the cached pages are gone */
645 xfs_ilock_demote(xip, XFS_IOLOCK_EXCL);
646 mutex_unlock(&inode->i_mutex);
648 iolock = XFS_IOLOCK_SHARED;
652 trace_xfs_file_direct_write(xip, count, *offset, ioflags);
653 ret = generic_file_direct_write(iocb, iovp,
654 &segs, pos, offset, count, ocount);
657 * direct-io write to a hole: fall through to buffered I/O
658 * for completing the rest of the request.
660 if (ret >= 0 && ret != count) {
661 XFS_STATS_ADD(xs_write_bytes, ret);
666 ioflags &= ~IO_ISDIRECT;
667 xfs_iunlock(xip, iolock);
675 trace_xfs_file_buffered_write(xip, count, *offset, ioflags);
676 ret2 = generic_file_buffered_write(iocb, iovp, segs,
677 pos, offset, count, ret);
679 * if we just got an ENOSPC, flush the inode now we
680 * aren't holding any page locks and retry *once*
682 if (ret2 == -ENOSPC && !enospc) {
683 error = xfs_flush_pages(xip, 0, -1, 0, FI_NONE);
685 goto out_unlock_internal;
692 current->backing_dev_info = NULL;
694 isize = i_size_read(inode);
695 if (unlikely(ret < 0 && ret != -EFAULT && *offset > isize))
698 if (*offset > xip->i_size) {
699 xfs_ilock(xip, XFS_ILOCK_EXCL);
700 if (*offset > xip->i_size)
701 xip->i_size = *offset;
702 xfs_iunlock(xip, XFS_ILOCK_EXCL);
705 if (ret == -ENOSPC &&
706 DM_EVENT_ENABLED(xip, DM_EVENT_NOSPACE) && !(ioflags & IO_INVIS)) {
707 xfs_iunlock(xip, iolock);
709 mutex_unlock(&inode->i_mutex);
710 error = XFS_SEND_NAMESP(xip->i_mount, DM_EVENT_NOSPACE, xip,
711 DM_RIGHT_NULL, xip, DM_RIGHT_NULL, NULL, NULL,
712 0, 0, 0); /* Delay flag intentionally unused */
714 mutex_lock(&inode->i_mutex);
715 xfs_ilock(xip, iolock);
717 goto out_unlock_internal;
723 goto out_unlock_internal;
725 XFS_STATS_ADD(xs_write_bytes, ret);
727 /* Handle various SYNC-type writes */
728 if ((file->f_flags & O_DSYNC) || IS_SYNC(inode)) {
729 loff_t end = pos + ret - 1;
732 xfs_iunlock(xip, iolock);
734 mutex_unlock(&inode->i_mutex);
736 error2 = filemap_write_and_wait_range(mapping, pos, end);
740 mutex_lock(&inode->i_mutex);
741 xfs_ilock(xip, iolock);
743 error2 = xfs_fsync(xip);
749 if (xip->i_new_size) {
750 xfs_ilock(xip, XFS_ILOCK_EXCL);
753 * If this was a direct or synchronous I/O that failed (such
754 * as ENOSPC) then part of the I/O may have been written to
755 * disk before the error occured. In this case the on-disk
756 * file size may have been adjusted beyond the in-memory file
757 * size and now needs to be truncated back.
759 if (xip->i_d.di_size > xip->i_size)
760 xip->i_d.di_size = xip->i_size;
761 xfs_iunlock(xip, XFS_ILOCK_EXCL);
763 xfs_iunlock(xip, iolock);
766 mutex_unlock(&inode->i_mutex);
773 const struct iovec *iov,
774 unsigned long nr_segs,
777 struct file *file = iocb->ki_filp;
780 BUG_ON(iocb->ki_pos != pos);
781 if (unlikely(file->f_flags & O_DIRECT))
782 ioflags |= IO_ISDIRECT;
783 if (file->f_mode & FMODE_NOCMTIME)
785 return xfs_read(XFS_I(file->f_path.dentry->d_inode), iocb, iov,
786 nr_segs, &iocb->ki_pos, ioflags);
792 const struct iovec *iov,
793 unsigned long nr_segs,
796 struct file *file = iocb->ki_filp;
799 BUG_ON(iocb->ki_pos != pos);
800 if (unlikely(file->f_flags & O_DIRECT))
801 ioflags |= IO_ISDIRECT;
802 if (file->f_mode & FMODE_NOCMTIME)
804 return xfs_write(XFS_I(file->f_mapping->host), iocb, iov, nr_segs,
805 &iocb->ki_pos, ioflags);
809 xfs_file_splice_read(
812 struct pipe_inode_info *pipe,
818 if (infilp->f_mode & FMODE_NOCMTIME)
821 return xfs_splice_read(XFS_I(infilp->f_path.dentry->d_inode),
822 infilp, ppos, pipe, len, flags, ioflags);
826 xfs_file_splice_write(
827 struct pipe_inode_info *pipe,
828 struct file *outfilp,
835 if (outfilp->f_mode & FMODE_NOCMTIME)
838 return xfs_splice_write(XFS_I(outfilp->f_path.dentry->d_inode),
839 pipe, outfilp, ppos, len, flags, ioflags);
847 if (!(file->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
849 if (XFS_FORCED_SHUTDOWN(XFS_M(inode->i_sb)))
859 struct xfs_inode *ip = XFS_I(inode);
863 error = xfs_file_open(inode, file);
868 * If there are any blocks, read-ahead block 0 as we're almost
869 * certain to have the next operation be a read there.
871 mode = xfs_ilock_map_shared(ip);
872 if (ip->i_d.di_nextents > 0)
873 xfs_da_reada_buf(NULL, ip, 0, XFS_DATA_FORK);
874 xfs_iunlock(ip, mode);
883 return -xfs_release(XFS_I(inode));
887 * We ignore the datasync flag here because a datasync is effectively
888 * identical to an fsync. That is, datasync implies that we need to write
889 * only the metadata needed to be able to access the data that is written
890 * if we crash after the call completes. Hence if we are writing beyond
891 * EOF we have to log the inode size change as well, which makes it a
892 * full fsync. If we don't write beyond EOF, the inode core will be
893 * clean in memory and so we don't need to log the inode, just like
899 struct dentry *dentry,
902 struct xfs_inode *ip = XFS_I(dentry->d_inode);
904 xfs_iflags_clear(ip, XFS_ITRUNCATED);
905 return -xfs_fsync(ip);
914 struct inode *inode = filp->f_path.dentry->d_inode;
915 xfs_inode_t *ip = XFS_I(inode);
920 * The Linux API doesn't pass down the total size of the buffer
921 * we read into down to the filesystem. With the filldir concept
922 * it's not needed for correct information, but the XFS dir2 leaf
923 * code wants an estimate of the buffer size to calculate it's
924 * readahead window and size the buffers used for mapping to
927 * Try to give it an estimate that's good enough, maybe at some
928 * point we can change the ->readdir prototype to include the
929 * buffer size. For now we use the current glibc buffer size.
931 bufsize = (size_t)min_t(loff_t, 32768, ip->i_d.di_size);
933 error = xfs_readdir(ip, dirent, bufsize,
934 (xfs_off_t *)&filp->f_pos, filldir);
943 struct vm_area_struct *vma)
945 vma->vm_ops = &xfs_file_vm_ops;
946 vma->vm_flags |= VM_CAN_NONLINEAR;
953 * mmap()d file has taken write protection fault and is being made
954 * writable. We can set the page state up correctly for a writable
955 * page, which means we can do correct delalloc accounting (ENOSPC
956 * checking!) and unwritten extent mapping.
960 struct vm_area_struct *vma,
961 struct vm_fault *vmf)
963 return block_page_mkwrite(vma, vmf, xfs_get_blocks);
966 const struct file_operations xfs_file_operations = {
967 .llseek = generic_file_llseek,
968 .read = do_sync_read,
969 .write = do_sync_write,
970 .aio_read = xfs_file_aio_read,
971 .aio_write = xfs_file_aio_write,
972 .splice_read = xfs_file_splice_read,
973 .splice_write = xfs_file_splice_write,
974 .unlocked_ioctl = xfs_file_ioctl,
976 .compat_ioctl = xfs_file_compat_ioctl,
978 .mmap = xfs_file_mmap,
979 .open = xfs_file_open,
980 .release = xfs_file_release,
981 .fsync = xfs_file_fsync,
982 #ifdef HAVE_FOP_OPEN_EXEC
983 .open_exec = xfs_file_open_exec,
987 const struct file_operations xfs_dir_file_operations = {
988 .open = xfs_dir_open,
989 .read = generic_read_dir,
990 .readdir = xfs_file_readdir,
991 .llseek = generic_file_llseek,
992 .unlocked_ioctl = xfs_file_ioctl,
994 .compat_ioctl = xfs_file_compat_ioctl,
996 .fsync = xfs_file_fsync,
999 static const struct vm_operations_struct xfs_file_vm_ops = {
1000 .fault = filemap_fault,
1001 .page_mkwrite = xfs_vm_page_mkwrite,