4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/f2fs_fs.h>
13 #include <linux/stat.h>
14 #include <linux/buffer_head.h>
15 #include <linux/writeback.h>
16 #include <linux/blkdev.h>
17 #include <linux/falloc.h>
18 #include <linux/types.h>
19 #include <linux/compat.h>
20 #include <linux/uaccess.h>
21 #include <linux/mount.h>
22 #include <linux/pagevec.h>
23 #include <linux/uio.h>
24 #include <linux/uuid.h>
25 #include <linux/file.h>
34 #include <trace/events/f2fs.h>
36 static int f2fs_filemap_fault(struct vm_fault
*vmf
)
38 struct inode
*inode
= file_inode(vmf
->vma
->vm_file
);
41 down_read(&F2FS_I(inode
)->i_mmap_sem
);
42 err
= filemap_fault(vmf
);
43 up_read(&F2FS_I(inode
)->i_mmap_sem
);
48 static int f2fs_vm_page_mkwrite(struct vm_fault
*vmf
)
50 struct page
*page
= vmf
->page
;
51 struct inode
*inode
= file_inode(vmf
->vma
->vm_file
);
52 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
53 struct dnode_of_data dn
;
56 sb_start_pagefault(inode
->i_sb
);
58 f2fs_bug_on(sbi
, f2fs_has_inline_data(inode
));
60 /* block allocation */
62 set_new_dnode(&dn
, inode
, NULL
, NULL
, 0);
63 err
= f2fs_reserve_block(&dn
, page
->index
);
71 f2fs_balance_fs(sbi
, dn
.node_changed
);
73 file_update_time(vmf
->vma
->vm_file
);
74 down_read(&F2FS_I(inode
)->i_mmap_sem
);
76 if (unlikely(page
->mapping
!= inode
->i_mapping
||
77 page_offset(page
) > i_size_read(inode
) ||
78 !PageUptodate(page
))) {
85 * check to see if the page is mapped already (no holes)
87 if (PageMappedToDisk(page
))
90 /* page is wholly or partially inside EOF */
91 if (((loff_t
)(page
->index
+ 1) << PAGE_SHIFT
) >
94 offset
= i_size_read(inode
) & ~PAGE_MASK
;
95 zero_user_segment(page
, offset
, PAGE_SIZE
);
98 if (!PageUptodate(page
))
99 SetPageUptodate(page
);
101 trace_f2fs_vm_page_mkwrite(page
, DATA
);
104 f2fs_wait_on_page_writeback(page
, DATA
, false);
106 /* wait for GCed encrypted page writeback */
107 if (f2fs_encrypted_inode(inode
) && S_ISREG(inode
->i_mode
))
108 f2fs_wait_on_encrypted_page_writeback(sbi
, dn
.data_blkaddr
);
111 up_read(&F2FS_I(inode
)->i_mmap_sem
);
113 sb_end_pagefault(inode
->i_sb
);
114 f2fs_update_time(sbi
, REQ_TIME
);
115 return block_page_mkwrite_return(err
);
118 static const struct vm_operations_struct f2fs_file_vm_ops
= {
119 .fault
= f2fs_filemap_fault
,
120 .map_pages
= filemap_map_pages
,
121 .page_mkwrite
= f2fs_vm_page_mkwrite
,
124 static int get_parent_ino(struct inode
*inode
, nid_t
*pino
)
126 struct dentry
*dentry
;
128 inode
= igrab(inode
);
129 dentry
= d_find_any_alias(inode
);
134 *pino
= parent_ino(dentry
);
139 static inline bool need_do_checkpoint(struct inode
*inode
)
141 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
142 bool need_cp
= false;
144 if (!S_ISREG(inode
->i_mode
) || inode
->i_nlink
!= 1)
146 else if (is_sbi_flag_set(sbi
, SBI_NEED_CP
))
148 else if (file_wrong_pino(inode
))
150 else if (!space_for_roll_forward(sbi
))
152 else if (!is_checkpointed_node(sbi
, F2FS_I(inode
)->i_pino
))
154 else if (test_opt(sbi
, FASTBOOT
))
156 else if (sbi
->active_logs
== 2)
162 static bool need_inode_page_update(struct f2fs_sb_info
*sbi
, nid_t ino
)
164 struct page
*i
= find_get_page(NODE_MAPPING(sbi
), ino
);
166 /* But we need to avoid that there are some inode updates */
167 if ((i
&& PageDirty(i
)) || need_inode_block_update(sbi
, ino
))
173 static void try_to_fix_pino(struct inode
*inode
)
175 struct f2fs_inode_info
*fi
= F2FS_I(inode
);
178 down_write(&fi
->i_sem
);
179 if (file_wrong_pino(inode
) && inode
->i_nlink
== 1 &&
180 get_parent_ino(inode
, &pino
)) {
181 f2fs_i_pino_write(inode
, pino
);
182 file_got_pino(inode
);
184 up_write(&fi
->i_sem
);
187 static int f2fs_do_sync_file(struct file
*file
, loff_t start
, loff_t end
,
188 int datasync
, bool atomic
)
190 struct inode
*inode
= file
->f_mapping
->host
;
191 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
192 nid_t ino
= inode
->i_ino
;
194 bool need_cp
= false;
195 struct writeback_control wbc
= {
196 .sync_mode
= WB_SYNC_ALL
,
197 .nr_to_write
= LONG_MAX
,
201 if (unlikely(f2fs_readonly(inode
->i_sb
)))
204 trace_f2fs_sync_file_enter(inode
);
206 /* if fdatasync is triggered, let's do in-place-update */
207 if (datasync
|| get_dirty_pages(inode
) <= SM_I(sbi
)->min_fsync_blocks
)
208 set_inode_flag(inode
, FI_NEED_IPU
);
209 ret
= filemap_write_and_wait_range(inode
->i_mapping
, start
, end
);
210 clear_inode_flag(inode
, FI_NEED_IPU
);
213 trace_f2fs_sync_file_exit(inode
, need_cp
, datasync
, ret
);
217 /* if the inode is dirty, let's recover all the time */
218 if (!f2fs_skip_inode_update(inode
, datasync
)) {
219 f2fs_write_inode(inode
, NULL
);
224 * if there is no written data, don't waste time to write recovery info.
226 if (!is_inode_flag_set(inode
, FI_APPEND_WRITE
) &&
227 !exist_written_data(sbi
, ino
, APPEND_INO
)) {
229 /* it may call write_inode just prior to fsync */
230 if (need_inode_page_update(sbi
, ino
))
233 if (is_inode_flag_set(inode
, FI_UPDATE_WRITE
) ||
234 exist_written_data(sbi
, ino
, UPDATE_INO
))
240 * Both of fdatasync() and fsync() are able to be recovered from
243 down_read(&F2FS_I(inode
)->i_sem
);
244 need_cp
= need_do_checkpoint(inode
);
245 up_read(&F2FS_I(inode
)->i_sem
);
248 /* all the dirty node pages should be flushed for POR */
249 ret
= f2fs_sync_fs(inode
->i_sb
, 1);
252 * We've secured consistency through sync_fs. Following pino
253 * will be used only for fsynced inodes after checkpoint.
255 try_to_fix_pino(inode
);
256 clear_inode_flag(inode
, FI_APPEND_WRITE
);
257 clear_inode_flag(inode
, FI_UPDATE_WRITE
);
261 ret
= fsync_node_pages(sbi
, inode
, &wbc
, atomic
);
265 /* if cp_error was enabled, we should avoid infinite loop */
266 if (unlikely(f2fs_cp_error(sbi
))) {
271 if (need_inode_block_update(sbi
, ino
)) {
272 f2fs_mark_inode_dirty_sync(inode
, true);
273 f2fs_write_inode(inode
, NULL
);
277 ret
= wait_on_node_pages_writeback(sbi
, ino
);
281 /* once recovery info is written, don't need to tack this */
282 remove_ino_entry(sbi
, ino
, APPEND_INO
);
283 clear_inode_flag(inode
, FI_APPEND_WRITE
);
285 remove_ino_entry(sbi
, ino
, UPDATE_INO
);
286 clear_inode_flag(inode
, FI_UPDATE_WRITE
);
288 ret
= f2fs_issue_flush(sbi
);
289 f2fs_update_time(sbi
, REQ_TIME
);
291 trace_f2fs_sync_file_exit(inode
, need_cp
, datasync
, ret
);
292 f2fs_trace_ios(NULL
, 1);
296 int f2fs_sync_file(struct file
*file
, loff_t start
, loff_t end
, int datasync
)
298 return f2fs_do_sync_file(file
, start
, end
, datasync
, false);
301 static pgoff_t
__get_first_dirty_index(struct address_space
*mapping
,
302 pgoff_t pgofs
, int whence
)
307 if (whence
!= SEEK_DATA
)
310 /* find first dirty page index */
311 pagevec_init(&pvec
, 0);
312 nr_pages
= pagevec_lookup_tag(&pvec
, mapping
, &pgofs
,
313 PAGECACHE_TAG_DIRTY
, 1);
314 pgofs
= nr_pages
? pvec
.pages
[0]->index
: ULONG_MAX
;
315 pagevec_release(&pvec
);
319 static bool __found_offset(block_t blkaddr
, pgoff_t dirty
, pgoff_t pgofs
,
324 if ((blkaddr
== NEW_ADDR
&& dirty
== pgofs
) ||
325 (blkaddr
!= NEW_ADDR
&& blkaddr
!= NULL_ADDR
))
329 if (blkaddr
== NULL_ADDR
)
336 static loff_t
f2fs_seek_block(struct file
*file
, loff_t offset
, int whence
)
338 struct inode
*inode
= file
->f_mapping
->host
;
339 loff_t maxbytes
= inode
->i_sb
->s_maxbytes
;
340 struct dnode_of_data dn
;
341 pgoff_t pgofs
, end_offset
, dirty
;
342 loff_t data_ofs
= offset
;
348 isize
= i_size_read(inode
);
352 /* handle inline data case */
353 if (f2fs_has_inline_data(inode
) || f2fs_has_inline_dentry(inode
)) {
354 if (whence
== SEEK_HOLE
)
359 pgofs
= (pgoff_t
)(offset
>> PAGE_SHIFT
);
361 dirty
= __get_first_dirty_index(inode
->i_mapping
, pgofs
, whence
);
363 for (; data_ofs
< isize
; data_ofs
= (loff_t
)pgofs
<< PAGE_SHIFT
) {
364 set_new_dnode(&dn
, inode
, NULL
, NULL
, 0);
365 err
= get_dnode_of_data(&dn
, pgofs
, LOOKUP_NODE
);
366 if (err
&& err
!= -ENOENT
) {
368 } else if (err
== -ENOENT
) {
369 /* direct node does not exists */
370 if (whence
== SEEK_DATA
) {
371 pgofs
= get_next_page_offset(&dn
, pgofs
);
378 end_offset
= ADDRS_PER_PAGE(dn
.node_page
, inode
);
380 /* find data/hole in dnode block */
381 for (; dn
.ofs_in_node
< end_offset
;
382 dn
.ofs_in_node
++, pgofs
++,
383 data_ofs
= (loff_t
)pgofs
<< PAGE_SHIFT
) {
385 blkaddr
= datablock_addr(dn
.node_page
, dn
.ofs_in_node
);
387 if (__found_offset(blkaddr
, dirty
, pgofs
, whence
)) {
395 if (whence
== SEEK_DATA
)
398 if (whence
== SEEK_HOLE
&& data_ofs
> isize
)
401 return vfs_setpos(file
, data_ofs
, maxbytes
);
407 static loff_t
f2fs_llseek(struct file
*file
, loff_t offset
, int whence
)
409 struct inode
*inode
= file
->f_mapping
->host
;
410 loff_t maxbytes
= inode
->i_sb
->s_maxbytes
;
416 return generic_file_llseek_size(file
, offset
, whence
,
417 maxbytes
, i_size_read(inode
));
422 return f2fs_seek_block(file
, offset
, whence
);
428 static int f2fs_file_mmap(struct file
*file
, struct vm_area_struct
*vma
)
430 struct inode
*inode
= file_inode(file
);
433 /* we don't need to use inline_data strictly */
434 err
= f2fs_convert_inline_inode(inode
);
439 vma
->vm_ops
= &f2fs_file_vm_ops
;
443 static int f2fs_file_open(struct inode
*inode
, struct file
*filp
)
447 if (f2fs_encrypted_inode(inode
)) {
448 int ret
= fscrypt_get_encryption_info(inode
);
451 if (!fscrypt_has_encryption_key(inode
))
454 dir
= dget_parent(file_dentry(filp
));
455 if (f2fs_encrypted_inode(d_inode(dir
)) &&
456 !fscrypt_has_permitted_context(d_inode(dir
), inode
)) {
461 return dquot_file_open(inode
, filp
);
464 int truncate_data_blocks_range(struct dnode_of_data
*dn
, int count
)
466 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dn
->inode
);
467 struct f2fs_node
*raw_node
;
468 int nr_free
= 0, ofs
= dn
->ofs_in_node
, len
= count
;
471 raw_node
= F2FS_NODE(dn
->node_page
);
472 addr
= blkaddr_in_node(raw_node
) + ofs
;
474 for (; count
> 0; count
--, addr
++, dn
->ofs_in_node
++) {
475 block_t blkaddr
= le32_to_cpu(*addr
);
476 if (blkaddr
== NULL_ADDR
)
479 dn
->data_blkaddr
= NULL_ADDR
;
480 set_data_blkaddr(dn
);
481 invalidate_blocks(sbi
, blkaddr
);
482 if (dn
->ofs_in_node
== 0 && IS_INODE(dn
->node_page
))
483 clear_inode_flag(dn
->inode
, FI_FIRST_BLOCK_WRITTEN
);
490 * once we invalidate valid blkaddr in range [ofs, ofs + count],
491 * we will invalidate all blkaddr in the whole range.
493 fofs
= start_bidx_of_node(ofs_of_node(dn
->node_page
),
495 f2fs_update_extent_cache_range(dn
, fofs
, 0, len
);
496 dec_valid_block_count(sbi
, dn
->inode
, nr_free
);
498 dn
->ofs_in_node
= ofs
;
500 f2fs_update_time(sbi
, REQ_TIME
);
501 trace_f2fs_truncate_data_blocks_range(dn
->inode
, dn
->nid
,
502 dn
->ofs_in_node
, nr_free
);
506 void truncate_data_blocks(struct dnode_of_data
*dn
)
508 truncate_data_blocks_range(dn
, ADDRS_PER_BLOCK
);
511 static int truncate_partial_data_page(struct inode
*inode
, u64 from
,
514 unsigned offset
= from
& (PAGE_SIZE
- 1);
515 pgoff_t index
= from
>> PAGE_SHIFT
;
516 struct address_space
*mapping
= inode
->i_mapping
;
519 if (!offset
&& !cache_only
)
523 page
= find_lock_page(mapping
, index
);
524 if (page
&& PageUptodate(page
))
526 f2fs_put_page(page
, 1);
530 page
= get_lock_data_page(inode
, index
, true);
532 return PTR_ERR(page
) == -ENOENT
? 0 : PTR_ERR(page
);
534 f2fs_wait_on_page_writeback(page
, DATA
, true);
535 zero_user(page
, offset
, PAGE_SIZE
- offset
);
537 /* An encrypted inode should have a key and truncate the last page. */
538 f2fs_bug_on(F2FS_I_SB(inode
), cache_only
&& f2fs_encrypted_inode(inode
));
540 set_page_dirty(page
);
541 f2fs_put_page(page
, 1);
545 int truncate_blocks(struct inode
*inode
, u64 from
, bool lock
)
547 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
548 unsigned int blocksize
= inode
->i_sb
->s_blocksize
;
549 struct dnode_of_data dn
;
551 int count
= 0, err
= 0;
553 bool truncate_page
= false;
555 trace_f2fs_truncate_blocks_enter(inode
, from
);
557 free_from
= (pgoff_t
)F2FS_BYTES_TO_BLK(from
+ blocksize
- 1);
559 if (free_from
>= sbi
->max_file_blocks
)
565 ipage
= get_node_page(sbi
, inode
->i_ino
);
567 err
= PTR_ERR(ipage
);
571 if (f2fs_has_inline_data(inode
)) {
572 truncate_inline_inode(inode
, ipage
, from
);
573 f2fs_put_page(ipage
, 1);
574 truncate_page
= true;
578 set_new_dnode(&dn
, inode
, ipage
, NULL
, 0);
579 err
= get_dnode_of_data(&dn
, free_from
, LOOKUP_NODE_RA
);
586 count
= ADDRS_PER_PAGE(dn
.node_page
, inode
);
588 count
-= dn
.ofs_in_node
;
589 f2fs_bug_on(sbi
, count
< 0);
591 if (dn
.ofs_in_node
|| IS_INODE(dn
.node_page
)) {
592 truncate_data_blocks_range(&dn
, count
);
598 err
= truncate_inode_blocks(inode
, free_from
);
603 /* lastly zero out the first data page */
605 err
= truncate_partial_data_page(inode
, from
, truncate_page
);
607 trace_f2fs_truncate_blocks_exit(inode
, err
);
611 int f2fs_truncate(struct inode
*inode
)
615 if (!(S_ISREG(inode
->i_mode
) || S_ISDIR(inode
->i_mode
) ||
616 S_ISLNK(inode
->i_mode
)))
619 trace_f2fs_truncate(inode
);
621 #ifdef CONFIG_F2FS_FAULT_INJECTION
622 if (time_to_inject(F2FS_I_SB(inode
), FAULT_TRUNCATE
)) {
623 f2fs_show_injection_info(FAULT_TRUNCATE
);
627 /* we should check inline_data size */
628 if (!f2fs_may_inline_data(inode
)) {
629 err
= f2fs_convert_inline_inode(inode
);
634 err
= truncate_blocks(inode
, i_size_read(inode
), true);
638 inode
->i_mtime
= inode
->i_ctime
= current_time(inode
);
639 f2fs_mark_inode_dirty_sync(inode
, false);
643 int f2fs_getattr(const struct path
*path
, struct kstat
*stat
,
644 u32 request_mask
, unsigned int query_flags
)
646 struct inode
*inode
= d_inode(path
->dentry
);
647 struct f2fs_inode_info
*fi
= F2FS_I(inode
);
650 flags
= fi
->i_flags
& FS_FL_USER_VISIBLE
;
651 if (flags
& FS_APPEND_FL
)
652 stat
->attributes
|= STATX_ATTR_APPEND
;
653 if (flags
& FS_COMPR_FL
)
654 stat
->attributes
|= STATX_ATTR_COMPRESSED
;
655 if (f2fs_encrypted_inode(inode
))
656 stat
->attributes
|= STATX_ATTR_ENCRYPTED
;
657 if (flags
& FS_IMMUTABLE_FL
)
658 stat
->attributes
|= STATX_ATTR_IMMUTABLE
;
659 if (flags
& FS_NODUMP_FL
)
660 stat
->attributes
|= STATX_ATTR_NODUMP
;
662 stat
->attributes_mask
|= (STATX_ATTR_APPEND
|
663 STATX_ATTR_COMPRESSED
|
664 STATX_ATTR_ENCRYPTED
|
665 STATX_ATTR_IMMUTABLE
|
668 generic_fillattr(inode
, stat
);
672 #ifdef CONFIG_F2FS_FS_POSIX_ACL
673 static void __setattr_copy(struct inode
*inode
, const struct iattr
*attr
)
675 unsigned int ia_valid
= attr
->ia_valid
;
677 if (ia_valid
& ATTR_UID
)
678 inode
->i_uid
= attr
->ia_uid
;
679 if (ia_valid
& ATTR_GID
)
680 inode
->i_gid
= attr
->ia_gid
;
681 if (ia_valid
& ATTR_ATIME
)
682 inode
->i_atime
= timespec_trunc(attr
->ia_atime
,
683 inode
->i_sb
->s_time_gran
);
684 if (ia_valid
& ATTR_MTIME
)
685 inode
->i_mtime
= timespec_trunc(attr
->ia_mtime
,
686 inode
->i_sb
->s_time_gran
);
687 if (ia_valid
& ATTR_CTIME
)
688 inode
->i_ctime
= timespec_trunc(attr
->ia_ctime
,
689 inode
->i_sb
->s_time_gran
);
690 if (ia_valid
& ATTR_MODE
) {
691 umode_t mode
= attr
->ia_mode
;
693 if (!in_group_p(inode
->i_gid
) && !capable(CAP_FSETID
))
695 set_acl_inode(inode
, mode
);
699 #define __setattr_copy setattr_copy
702 int f2fs_setattr(struct dentry
*dentry
, struct iattr
*attr
)
704 struct inode
*inode
= d_inode(dentry
);
706 bool size_changed
= false;
708 err
= setattr_prepare(dentry
, attr
);
712 if (is_quota_modification(inode
, attr
)) {
713 err
= dquot_initialize(inode
);
717 if ((attr
->ia_valid
& ATTR_UID
&&
718 !uid_eq(attr
->ia_uid
, inode
->i_uid
)) ||
719 (attr
->ia_valid
& ATTR_GID
&&
720 !gid_eq(attr
->ia_gid
, inode
->i_gid
))) {
721 err
= dquot_transfer(inode
, attr
);
726 if (attr
->ia_valid
& ATTR_SIZE
) {
727 if (f2fs_encrypted_inode(inode
)) {
728 err
= fscrypt_get_encryption_info(inode
);
731 if (!fscrypt_has_encryption_key(inode
))
735 if (attr
->ia_size
<= i_size_read(inode
)) {
736 down_write(&F2FS_I(inode
)->i_mmap_sem
);
737 truncate_setsize(inode
, attr
->ia_size
);
738 err
= f2fs_truncate(inode
);
739 up_write(&F2FS_I(inode
)->i_mmap_sem
);
744 * do not trim all blocks after i_size if target size is
745 * larger than i_size.
747 down_write(&F2FS_I(inode
)->i_mmap_sem
);
748 truncate_setsize(inode
, attr
->ia_size
);
749 up_write(&F2FS_I(inode
)->i_mmap_sem
);
751 /* should convert inline inode here */
752 if (!f2fs_may_inline_data(inode
)) {
753 err
= f2fs_convert_inline_inode(inode
);
757 inode
->i_mtime
= inode
->i_ctime
= current_time(inode
);
763 __setattr_copy(inode
, attr
);
765 if (attr
->ia_valid
& ATTR_MODE
) {
766 err
= posix_acl_chmod(inode
, get_inode_mode(inode
));
767 if (err
|| is_inode_flag_set(inode
, FI_ACL_MODE
)) {
768 inode
->i_mode
= F2FS_I(inode
)->i_acl_mode
;
769 clear_inode_flag(inode
, FI_ACL_MODE
);
773 /* file size may changed here */
774 f2fs_mark_inode_dirty_sync(inode
, size_changed
);
776 /* inode change will produce dirty node pages flushed by checkpoint */
777 f2fs_balance_fs(F2FS_I_SB(inode
), true);
782 const struct inode_operations f2fs_file_inode_operations
= {
783 .getattr
= f2fs_getattr
,
784 .setattr
= f2fs_setattr
,
785 .get_acl
= f2fs_get_acl
,
786 .set_acl
= f2fs_set_acl
,
787 #ifdef CONFIG_F2FS_FS_XATTR
788 .listxattr
= f2fs_listxattr
,
790 .fiemap
= f2fs_fiemap
,
793 static int fill_zero(struct inode
*inode
, pgoff_t index
,
794 loff_t start
, loff_t len
)
796 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
802 f2fs_balance_fs(sbi
, true);
805 page
= get_new_data_page(inode
, NULL
, index
, false);
809 return PTR_ERR(page
);
811 f2fs_wait_on_page_writeback(page
, DATA
, true);
812 zero_user(page
, start
, len
);
813 set_page_dirty(page
);
814 f2fs_put_page(page
, 1);
818 int truncate_hole(struct inode
*inode
, pgoff_t pg_start
, pgoff_t pg_end
)
822 while (pg_start
< pg_end
) {
823 struct dnode_of_data dn
;
824 pgoff_t end_offset
, count
;
826 set_new_dnode(&dn
, inode
, NULL
, NULL
, 0);
827 err
= get_dnode_of_data(&dn
, pg_start
, LOOKUP_NODE
);
829 if (err
== -ENOENT
) {
836 end_offset
= ADDRS_PER_PAGE(dn
.node_page
, inode
);
837 count
= min(end_offset
- dn
.ofs_in_node
, pg_end
- pg_start
);
839 f2fs_bug_on(F2FS_I_SB(inode
), count
== 0 || count
> end_offset
);
841 truncate_data_blocks_range(&dn
, count
);
849 static int punch_hole(struct inode
*inode
, loff_t offset
, loff_t len
)
851 pgoff_t pg_start
, pg_end
;
852 loff_t off_start
, off_end
;
855 ret
= f2fs_convert_inline_inode(inode
);
859 pg_start
= ((unsigned long long) offset
) >> PAGE_SHIFT
;
860 pg_end
= ((unsigned long long) offset
+ len
) >> PAGE_SHIFT
;
862 off_start
= offset
& (PAGE_SIZE
- 1);
863 off_end
= (offset
+ len
) & (PAGE_SIZE
- 1);
865 if (pg_start
== pg_end
) {
866 ret
= fill_zero(inode
, pg_start
, off_start
,
867 off_end
- off_start
);
872 ret
= fill_zero(inode
, pg_start
++, off_start
,
873 PAGE_SIZE
- off_start
);
878 ret
= fill_zero(inode
, pg_end
, 0, off_end
);
883 if (pg_start
< pg_end
) {
884 struct address_space
*mapping
= inode
->i_mapping
;
885 loff_t blk_start
, blk_end
;
886 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
888 f2fs_balance_fs(sbi
, true);
890 blk_start
= (loff_t
)pg_start
<< PAGE_SHIFT
;
891 blk_end
= (loff_t
)pg_end
<< PAGE_SHIFT
;
892 down_write(&F2FS_I(inode
)->i_mmap_sem
);
893 truncate_inode_pages_range(mapping
, blk_start
,
897 ret
= truncate_hole(inode
, pg_start
, pg_end
);
899 up_write(&F2FS_I(inode
)->i_mmap_sem
);
906 static int __read_out_blkaddrs(struct inode
*inode
, block_t
*blkaddr
,
907 int *do_replace
, pgoff_t off
, pgoff_t len
)
909 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
910 struct dnode_of_data dn
;
914 set_new_dnode(&dn
, inode
, NULL
, NULL
, 0);
915 ret
= get_dnode_of_data(&dn
, off
, LOOKUP_NODE_RA
);
916 if (ret
&& ret
!= -ENOENT
) {
918 } else if (ret
== -ENOENT
) {
919 if (dn
.max_level
== 0)
921 done
= min((pgoff_t
)ADDRS_PER_BLOCK
- dn
.ofs_in_node
, len
);
927 done
= min((pgoff_t
)ADDRS_PER_PAGE(dn
.node_page
, inode
) -
928 dn
.ofs_in_node
, len
);
929 for (i
= 0; i
< done
; i
++, blkaddr
++, do_replace
++, dn
.ofs_in_node
++) {
930 *blkaddr
= datablock_addr(dn
.node_page
, dn
.ofs_in_node
);
931 if (!is_checkpointed_data(sbi
, *blkaddr
)) {
933 if (test_opt(sbi
, LFS
)) {
938 /* do not invalidate this block address */
939 f2fs_update_data_blkaddr(&dn
, NULL_ADDR
);
952 static int __roll_back_blkaddrs(struct inode
*inode
, block_t
*blkaddr
,
953 int *do_replace
, pgoff_t off
, int len
)
955 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
956 struct dnode_of_data dn
;
959 for (i
= 0; i
< len
; i
++, do_replace
++, blkaddr
++) {
960 if (*do_replace
== 0)
963 set_new_dnode(&dn
, inode
, NULL
, NULL
, 0);
964 ret
= get_dnode_of_data(&dn
, off
+ i
, LOOKUP_NODE_RA
);
966 dec_valid_block_count(sbi
, inode
, 1);
967 invalidate_blocks(sbi
, *blkaddr
);
969 f2fs_update_data_blkaddr(&dn
, *blkaddr
);
976 static int __clone_blkaddrs(struct inode
*src_inode
, struct inode
*dst_inode
,
977 block_t
*blkaddr
, int *do_replace
,
978 pgoff_t src
, pgoff_t dst
, pgoff_t len
, bool full
)
980 struct f2fs_sb_info
*sbi
= F2FS_I_SB(src_inode
);
985 if (blkaddr
[i
] == NULL_ADDR
&& !full
) {
990 if (do_replace
[i
] || blkaddr
[i
] == NULL_ADDR
) {
991 struct dnode_of_data dn
;
996 set_new_dnode(&dn
, dst_inode
, NULL
, NULL
, 0);
997 ret
= get_dnode_of_data(&dn
, dst
+ i
, ALLOC_NODE
);
1001 get_node_info(sbi
, dn
.nid
, &ni
);
1002 ilen
= min((pgoff_t
)
1003 ADDRS_PER_PAGE(dn
.node_page
, dst_inode
) -
1004 dn
.ofs_in_node
, len
- i
);
1006 dn
.data_blkaddr
= datablock_addr(dn
.node_page
,
1008 truncate_data_blocks_range(&dn
, 1);
1010 if (do_replace
[i
]) {
1011 f2fs_i_blocks_write(src_inode
,
1013 f2fs_i_blocks_write(dst_inode
,
1015 f2fs_replace_block(sbi
, &dn
, dn
.data_blkaddr
,
1016 blkaddr
[i
], ni
.version
, true, false);
1022 new_size
= (dst
+ i
) << PAGE_SHIFT
;
1023 if (dst_inode
->i_size
< new_size
)
1024 f2fs_i_size_write(dst_inode
, new_size
);
1025 } while (--ilen
&& (do_replace
[i
] || blkaddr
[i
] == NULL_ADDR
));
1027 f2fs_put_dnode(&dn
);
1029 struct page
*psrc
, *pdst
;
1031 psrc
= get_lock_data_page(src_inode
, src
+ i
, true);
1033 return PTR_ERR(psrc
);
1034 pdst
= get_new_data_page(dst_inode
, NULL
, dst
+ i
,
1037 f2fs_put_page(psrc
, 1);
1038 return PTR_ERR(pdst
);
1040 f2fs_copy_page(psrc
, pdst
);
1041 set_page_dirty(pdst
);
1042 f2fs_put_page(pdst
, 1);
1043 f2fs_put_page(psrc
, 1);
1045 ret
= truncate_hole(src_inode
, src
+ i
, src
+ i
+ 1);
1054 static int __exchange_data_block(struct inode
*src_inode
,
1055 struct inode
*dst_inode
, pgoff_t src
, pgoff_t dst
,
1056 pgoff_t len
, bool full
)
1058 block_t
*src_blkaddr
;
1064 olen
= min((pgoff_t
)4 * ADDRS_PER_BLOCK
, len
);
1066 src_blkaddr
= kvzalloc(sizeof(block_t
) * olen
, GFP_KERNEL
);
1070 do_replace
= kvzalloc(sizeof(int) * olen
, GFP_KERNEL
);
1072 kvfree(src_blkaddr
);
1076 ret
= __read_out_blkaddrs(src_inode
, src_blkaddr
,
1077 do_replace
, src
, olen
);
1081 ret
= __clone_blkaddrs(src_inode
, dst_inode
, src_blkaddr
,
1082 do_replace
, src
, dst
, olen
, full
);
1090 kvfree(src_blkaddr
);
1096 __roll_back_blkaddrs(src_inode
, src_blkaddr
, do_replace
, src
, len
);
1097 kvfree(src_blkaddr
);
1102 static int f2fs_do_collapse(struct inode
*inode
, pgoff_t start
, pgoff_t end
)
1104 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
1105 pgoff_t nrpages
= (i_size_read(inode
) + PAGE_SIZE
- 1) / PAGE_SIZE
;
1108 f2fs_balance_fs(sbi
, true);
1111 f2fs_drop_extent_tree(inode
);
1113 ret
= __exchange_data_block(inode
, inode
, end
, start
, nrpages
- end
, true);
1114 f2fs_unlock_op(sbi
);
1118 static int f2fs_collapse_range(struct inode
*inode
, loff_t offset
, loff_t len
)
1120 pgoff_t pg_start
, pg_end
;
1124 if (offset
+ len
>= i_size_read(inode
))
1127 /* collapse range should be aligned to block size of f2fs. */
1128 if (offset
& (F2FS_BLKSIZE
- 1) || len
& (F2FS_BLKSIZE
- 1))
1131 ret
= f2fs_convert_inline_inode(inode
);
1135 pg_start
= offset
>> PAGE_SHIFT
;
1136 pg_end
= (offset
+ len
) >> PAGE_SHIFT
;
1138 down_write(&F2FS_I(inode
)->i_mmap_sem
);
1139 /* write out all dirty pages from offset */
1140 ret
= filemap_write_and_wait_range(inode
->i_mapping
, offset
, LLONG_MAX
);
1144 truncate_pagecache(inode
, offset
);
1146 ret
= f2fs_do_collapse(inode
, pg_start
, pg_end
);
1150 /* write out all moved pages, if possible */
1151 filemap_write_and_wait_range(inode
->i_mapping
, offset
, LLONG_MAX
);
1152 truncate_pagecache(inode
, offset
);
1154 new_size
= i_size_read(inode
) - len
;
1155 truncate_pagecache(inode
, new_size
);
1157 ret
= truncate_blocks(inode
, new_size
, true);
1159 f2fs_i_size_write(inode
, new_size
);
1162 up_write(&F2FS_I(inode
)->i_mmap_sem
);
1166 static int f2fs_do_zero_range(struct dnode_of_data
*dn
, pgoff_t start
,
1169 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dn
->inode
);
1170 pgoff_t index
= start
;
1171 unsigned int ofs_in_node
= dn
->ofs_in_node
;
1175 for (; index
< end
; index
++, dn
->ofs_in_node
++) {
1176 if (datablock_addr(dn
->node_page
, dn
->ofs_in_node
) == NULL_ADDR
)
1180 dn
->ofs_in_node
= ofs_in_node
;
1181 ret
= reserve_new_blocks(dn
, count
);
1185 dn
->ofs_in_node
= ofs_in_node
;
1186 for (index
= start
; index
< end
; index
++, dn
->ofs_in_node
++) {
1188 datablock_addr(dn
->node_page
, dn
->ofs_in_node
);
1190 * reserve_new_blocks will not guarantee entire block
1193 if (dn
->data_blkaddr
== NULL_ADDR
) {
1197 if (dn
->data_blkaddr
!= NEW_ADDR
) {
1198 invalidate_blocks(sbi
, dn
->data_blkaddr
);
1199 dn
->data_blkaddr
= NEW_ADDR
;
1200 set_data_blkaddr(dn
);
1204 f2fs_update_extent_cache_range(dn
, start
, 0, index
- start
);
1209 static int f2fs_zero_range(struct inode
*inode
, loff_t offset
, loff_t len
,
1212 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
1213 struct address_space
*mapping
= inode
->i_mapping
;
1214 pgoff_t index
, pg_start
, pg_end
;
1215 loff_t new_size
= i_size_read(inode
);
1216 loff_t off_start
, off_end
;
1219 ret
= inode_newsize_ok(inode
, (len
+ offset
));
1223 ret
= f2fs_convert_inline_inode(inode
);
1227 down_write(&F2FS_I(inode
)->i_mmap_sem
);
1228 ret
= filemap_write_and_wait_range(mapping
, offset
, offset
+ len
- 1);
1232 truncate_pagecache_range(inode
, offset
, offset
+ len
- 1);
1234 pg_start
= ((unsigned long long) offset
) >> PAGE_SHIFT
;
1235 pg_end
= ((unsigned long long) offset
+ len
) >> PAGE_SHIFT
;
1237 off_start
= offset
& (PAGE_SIZE
- 1);
1238 off_end
= (offset
+ len
) & (PAGE_SIZE
- 1);
1240 if (pg_start
== pg_end
) {
1241 ret
= fill_zero(inode
, pg_start
, off_start
,
1242 off_end
- off_start
);
1246 new_size
= max_t(loff_t
, new_size
, offset
+ len
);
1249 ret
= fill_zero(inode
, pg_start
++, off_start
,
1250 PAGE_SIZE
- off_start
);
1254 new_size
= max_t(loff_t
, new_size
,
1255 (loff_t
)pg_start
<< PAGE_SHIFT
);
1258 for (index
= pg_start
; index
< pg_end
;) {
1259 struct dnode_of_data dn
;
1260 unsigned int end_offset
;
1265 set_new_dnode(&dn
, inode
, NULL
, NULL
, 0);
1266 ret
= get_dnode_of_data(&dn
, index
, ALLOC_NODE
);
1268 f2fs_unlock_op(sbi
);
1272 end_offset
= ADDRS_PER_PAGE(dn
.node_page
, inode
);
1273 end
= min(pg_end
, end_offset
- dn
.ofs_in_node
+ index
);
1275 ret
= f2fs_do_zero_range(&dn
, index
, end
);
1276 f2fs_put_dnode(&dn
);
1277 f2fs_unlock_op(sbi
);
1279 f2fs_balance_fs(sbi
, dn
.node_changed
);
1285 new_size
= max_t(loff_t
, new_size
,
1286 (loff_t
)index
<< PAGE_SHIFT
);
1290 ret
= fill_zero(inode
, pg_end
, 0, off_end
);
1294 new_size
= max_t(loff_t
, new_size
, offset
+ len
);
1299 if (!(mode
& FALLOC_FL_KEEP_SIZE
) && i_size_read(inode
) < new_size
)
1300 f2fs_i_size_write(inode
, new_size
);
1302 up_write(&F2FS_I(inode
)->i_mmap_sem
);
1307 static int f2fs_insert_range(struct inode
*inode
, loff_t offset
, loff_t len
)
1309 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
1310 pgoff_t nr
, pg_start
, pg_end
, delta
, idx
;
1314 new_size
= i_size_read(inode
) + len
;
1315 ret
= inode_newsize_ok(inode
, new_size
);
1319 if (offset
>= i_size_read(inode
))
1322 /* insert range should be aligned to block size of f2fs. */
1323 if (offset
& (F2FS_BLKSIZE
- 1) || len
& (F2FS_BLKSIZE
- 1))
1326 ret
= f2fs_convert_inline_inode(inode
);
1330 f2fs_balance_fs(sbi
, true);
1332 down_write(&F2FS_I(inode
)->i_mmap_sem
);
1333 ret
= truncate_blocks(inode
, i_size_read(inode
), true);
1337 /* write out all dirty pages from offset */
1338 ret
= filemap_write_and_wait_range(inode
->i_mapping
, offset
, LLONG_MAX
);
1342 truncate_pagecache(inode
, offset
);
1344 pg_start
= offset
>> PAGE_SHIFT
;
1345 pg_end
= (offset
+ len
) >> PAGE_SHIFT
;
1346 delta
= pg_end
- pg_start
;
1347 idx
= (i_size_read(inode
) + PAGE_SIZE
- 1) / PAGE_SIZE
;
1349 while (!ret
&& idx
> pg_start
) {
1350 nr
= idx
- pg_start
;
1356 f2fs_drop_extent_tree(inode
);
1358 ret
= __exchange_data_block(inode
, inode
, idx
,
1359 idx
+ delta
, nr
, false);
1360 f2fs_unlock_op(sbi
);
1363 /* write out all moved pages, if possible */
1364 filemap_write_and_wait_range(inode
->i_mapping
, offset
, LLONG_MAX
);
1365 truncate_pagecache(inode
, offset
);
1368 f2fs_i_size_write(inode
, new_size
);
1370 up_write(&F2FS_I(inode
)->i_mmap_sem
);
1374 static int expand_inode_data(struct inode
*inode
, loff_t offset
,
1375 loff_t len
, int mode
)
1377 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
1378 struct f2fs_map_blocks map
= { .m_next_pgofs
= NULL
};
1380 loff_t new_size
= i_size_read(inode
);
1384 err
= inode_newsize_ok(inode
, (len
+ offset
));
1388 err
= f2fs_convert_inline_inode(inode
);
1392 f2fs_balance_fs(sbi
, true);
1394 pg_end
= ((unsigned long long)offset
+ len
) >> PAGE_SHIFT
;
1395 off_end
= (offset
+ len
) & (PAGE_SIZE
- 1);
1397 map
.m_lblk
= ((unsigned long long)offset
) >> PAGE_SHIFT
;
1398 map
.m_len
= pg_end
- map
.m_lblk
;
1402 err
= f2fs_map_blocks(inode
, &map
, 1, F2FS_GET_BLOCK_PRE_AIO
);
1409 last_off
= map
.m_lblk
+ map
.m_len
- 1;
1411 /* update new size to the failed position */
1412 new_size
= (last_off
== pg_end
) ? offset
+ len
:
1413 (loff_t
)(last_off
+ 1) << PAGE_SHIFT
;
1415 new_size
= ((loff_t
)pg_end
<< PAGE_SHIFT
) + off_end
;
1418 if (!(mode
& FALLOC_FL_KEEP_SIZE
) && i_size_read(inode
) < new_size
)
1419 f2fs_i_size_write(inode
, new_size
);
1424 static long f2fs_fallocate(struct file
*file
, int mode
,
1425 loff_t offset
, loff_t len
)
1427 struct inode
*inode
= file_inode(file
);
1430 /* f2fs only support ->fallocate for regular file */
1431 if (!S_ISREG(inode
->i_mode
))
1434 if (f2fs_encrypted_inode(inode
) &&
1435 (mode
& (FALLOC_FL_COLLAPSE_RANGE
| FALLOC_FL_INSERT_RANGE
)))
1438 if (mode
& ~(FALLOC_FL_KEEP_SIZE
| FALLOC_FL_PUNCH_HOLE
|
1439 FALLOC_FL_COLLAPSE_RANGE
| FALLOC_FL_ZERO_RANGE
|
1440 FALLOC_FL_INSERT_RANGE
))
1445 if (mode
& FALLOC_FL_PUNCH_HOLE
) {
1446 if (offset
>= inode
->i_size
)
1449 ret
= punch_hole(inode
, offset
, len
);
1450 } else if (mode
& FALLOC_FL_COLLAPSE_RANGE
) {
1451 ret
= f2fs_collapse_range(inode
, offset
, len
);
1452 } else if (mode
& FALLOC_FL_ZERO_RANGE
) {
1453 ret
= f2fs_zero_range(inode
, offset
, len
, mode
);
1454 } else if (mode
& FALLOC_FL_INSERT_RANGE
) {
1455 ret
= f2fs_insert_range(inode
, offset
, len
);
1457 ret
= expand_inode_data(inode
, offset
, len
, mode
);
1461 inode
->i_mtime
= inode
->i_ctime
= current_time(inode
);
1462 f2fs_mark_inode_dirty_sync(inode
, false);
1463 if (mode
& FALLOC_FL_KEEP_SIZE
)
1464 file_set_keep_isize(inode
);
1465 f2fs_update_time(F2FS_I_SB(inode
), REQ_TIME
);
1469 inode_unlock(inode
);
1471 trace_f2fs_fallocate(inode
, mode
, offset
, len
, ret
);
1475 static int f2fs_release_file(struct inode
*inode
, struct file
*filp
)
1478 * f2fs_relase_file is called at every close calls. So we should
1479 * not drop any inmemory pages by close called by other process.
1481 if (!(filp
->f_mode
& FMODE_WRITE
) ||
1482 atomic_read(&inode
->i_writecount
) != 1)
1485 /* some remained atomic pages should discarded */
1486 if (f2fs_is_atomic_file(inode
))
1487 drop_inmem_pages(inode
);
1488 if (f2fs_is_volatile_file(inode
)) {
1489 clear_inode_flag(inode
, FI_VOLATILE_FILE
);
1490 stat_dec_volatile_write(inode
);
1491 set_inode_flag(inode
, FI_DROP_CACHE
);
1492 filemap_fdatawrite(inode
->i_mapping
);
1493 clear_inode_flag(inode
, FI_DROP_CACHE
);
1498 #define F2FS_REG_FLMASK (~(FS_DIRSYNC_FL | FS_TOPDIR_FL))
1499 #define F2FS_OTHER_FLMASK (FS_NODUMP_FL | FS_NOATIME_FL)
1501 static inline __u32
f2fs_mask_flags(umode_t mode
, __u32 flags
)
1505 else if (S_ISREG(mode
))
1506 return flags
& F2FS_REG_FLMASK
;
1508 return flags
& F2FS_OTHER_FLMASK
;
1511 static int f2fs_ioc_getflags(struct file
*filp
, unsigned long arg
)
1513 struct inode
*inode
= file_inode(filp
);
1514 struct f2fs_inode_info
*fi
= F2FS_I(inode
);
1515 unsigned int flags
= fi
->i_flags
& FS_FL_USER_VISIBLE
;
1516 return put_user(flags
, (int __user
*)arg
);
1519 static int f2fs_ioc_setflags(struct file
*filp
, unsigned long arg
)
1521 struct inode
*inode
= file_inode(filp
);
1522 struct f2fs_inode_info
*fi
= F2FS_I(inode
);
1524 unsigned int oldflags
;
1527 if (!inode_owner_or_capable(inode
))
1530 if (get_user(flags
, (int __user
*)arg
))
1533 ret
= mnt_want_write_file(filp
);
1539 /* Is it quota file? Do not allow user to mess with it */
1540 if (IS_NOQUOTA(inode
)) {
1545 flags
= f2fs_mask_flags(inode
->i_mode
, flags
);
1547 oldflags
= fi
->i_flags
;
1549 if ((flags
^ oldflags
) & (FS_APPEND_FL
| FS_IMMUTABLE_FL
)) {
1550 if (!capable(CAP_LINUX_IMMUTABLE
)) {
1556 flags
= flags
& FS_FL_USER_MODIFIABLE
;
1557 flags
|= oldflags
& ~FS_FL_USER_MODIFIABLE
;
1558 fi
->i_flags
= flags
;
1560 inode
->i_ctime
= current_time(inode
);
1561 f2fs_set_inode_flags(inode
);
1562 f2fs_mark_inode_dirty_sync(inode
, false);
1564 inode_unlock(inode
);
1565 mnt_drop_write_file(filp
);
1569 static int f2fs_ioc_getversion(struct file
*filp
, unsigned long arg
)
1571 struct inode
*inode
= file_inode(filp
);
1573 return put_user(inode
->i_generation
, (int __user
*)arg
);
1576 static int f2fs_ioc_start_atomic_write(struct file
*filp
)
1578 struct inode
*inode
= file_inode(filp
);
1581 if (!inode_owner_or_capable(inode
))
1584 if (!S_ISREG(inode
->i_mode
))
1587 ret
= mnt_want_write_file(filp
);
1593 if (f2fs_is_atomic_file(inode
))
1596 ret
= f2fs_convert_inline_inode(inode
);
1600 set_inode_flag(inode
, FI_ATOMIC_FILE
);
1601 set_inode_flag(inode
, FI_HOT_DATA
);
1602 f2fs_update_time(F2FS_I_SB(inode
), REQ_TIME
);
1604 if (!get_dirty_pages(inode
))
1607 f2fs_msg(F2FS_I_SB(inode
)->sb
, KERN_WARNING
,
1608 "Unexpected flush for atomic writes: ino=%lu, npages=%u",
1609 inode
->i_ino
, get_dirty_pages(inode
));
1610 ret
= filemap_write_and_wait_range(inode
->i_mapping
, 0, LLONG_MAX
);
1612 clear_inode_flag(inode
, FI_ATOMIC_FILE
);
1617 stat_inc_atomic_write(inode
);
1618 stat_update_max_atomic_write(inode
);
1620 inode_unlock(inode
);
1621 mnt_drop_write_file(filp
);
1625 static int f2fs_ioc_commit_atomic_write(struct file
*filp
)
1627 struct inode
*inode
= file_inode(filp
);
1630 if (!inode_owner_or_capable(inode
))
1633 ret
= mnt_want_write_file(filp
);
1639 if (f2fs_is_volatile_file(inode
))
1642 if (f2fs_is_atomic_file(inode
)) {
1643 ret
= commit_inmem_pages(inode
);
1647 ret
= f2fs_do_sync_file(filp
, 0, LLONG_MAX
, 0, true);
1649 clear_inode_flag(inode
, FI_ATOMIC_FILE
);
1650 stat_dec_atomic_write(inode
);
1653 ret
= f2fs_do_sync_file(filp
, 0, LLONG_MAX
, 0, true);
1656 inode_unlock(inode
);
1657 mnt_drop_write_file(filp
);
1661 static int f2fs_ioc_start_volatile_write(struct file
*filp
)
1663 struct inode
*inode
= file_inode(filp
);
1666 if (!inode_owner_or_capable(inode
))
1669 if (!S_ISREG(inode
->i_mode
))
1672 ret
= mnt_want_write_file(filp
);
1678 if (f2fs_is_volatile_file(inode
))
1681 ret
= f2fs_convert_inline_inode(inode
);
1685 stat_inc_volatile_write(inode
);
1686 stat_update_max_volatile_write(inode
);
1688 set_inode_flag(inode
, FI_VOLATILE_FILE
);
1689 f2fs_update_time(F2FS_I_SB(inode
), REQ_TIME
);
1691 inode_unlock(inode
);
1692 mnt_drop_write_file(filp
);
1696 static int f2fs_ioc_release_volatile_write(struct file
*filp
)
1698 struct inode
*inode
= file_inode(filp
);
1701 if (!inode_owner_or_capable(inode
))
1704 ret
= mnt_want_write_file(filp
);
1710 if (!f2fs_is_volatile_file(inode
))
1713 if (!f2fs_is_first_block_written(inode
)) {
1714 ret
= truncate_partial_data_page(inode
, 0, true);
1718 ret
= punch_hole(inode
, 0, F2FS_BLKSIZE
);
1720 inode_unlock(inode
);
1721 mnt_drop_write_file(filp
);
1725 static int f2fs_ioc_abort_volatile_write(struct file
*filp
)
1727 struct inode
*inode
= file_inode(filp
);
1730 if (!inode_owner_or_capable(inode
))
1733 ret
= mnt_want_write_file(filp
);
1739 if (f2fs_is_atomic_file(inode
))
1740 drop_inmem_pages(inode
);
1741 if (f2fs_is_volatile_file(inode
)) {
1742 clear_inode_flag(inode
, FI_VOLATILE_FILE
);
1743 stat_dec_volatile_write(inode
);
1744 ret
= f2fs_do_sync_file(filp
, 0, LLONG_MAX
, 0, true);
1747 inode_unlock(inode
);
1749 mnt_drop_write_file(filp
);
1750 f2fs_update_time(F2FS_I_SB(inode
), REQ_TIME
);
1754 static int f2fs_ioc_shutdown(struct file
*filp
, unsigned long arg
)
1756 struct inode
*inode
= file_inode(filp
);
1757 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
1758 struct super_block
*sb
= sbi
->sb
;
1762 if (!capable(CAP_SYS_ADMIN
))
1765 if (get_user(in
, (__u32 __user
*)arg
))
1768 ret
= mnt_want_write_file(filp
);
1773 case F2FS_GOING_DOWN_FULLSYNC
:
1774 sb
= freeze_bdev(sb
->s_bdev
);
1775 if (sb
&& !IS_ERR(sb
)) {
1776 f2fs_stop_checkpoint(sbi
, false);
1777 thaw_bdev(sb
->s_bdev
, sb
);
1780 case F2FS_GOING_DOWN_METASYNC
:
1781 /* do checkpoint only */
1782 f2fs_sync_fs(sb
, 1);
1783 f2fs_stop_checkpoint(sbi
, false);
1785 case F2FS_GOING_DOWN_NOSYNC
:
1786 f2fs_stop_checkpoint(sbi
, false);
1788 case F2FS_GOING_DOWN_METAFLUSH
:
1789 sync_meta_pages(sbi
, META
, LONG_MAX
);
1790 f2fs_stop_checkpoint(sbi
, false);
1796 f2fs_update_time(sbi
, REQ_TIME
);
1798 mnt_drop_write_file(filp
);
1802 static int f2fs_ioc_fitrim(struct file
*filp
, unsigned long arg
)
1804 struct inode
*inode
= file_inode(filp
);
1805 struct super_block
*sb
= inode
->i_sb
;
1806 struct request_queue
*q
= bdev_get_queue(sb
->s_bdev
);
1807 struct fstrim_range range
;
1810 if (!capable(CAP_SYS_ADMIN
))
1813 if (!blk_queue_discard(q
))
1816 if (copy_from_user(&range
, (struct fstrim_range __user
*)arg
,
1820 ret
= mnt_want_write_file(filp
);
1824 range
.minlen
= max((unsigned int)range
.minlen
,
1825 q
->limits
.discard_granularity
);
1826 ret
= f2fs_trim_fs(F2FS_SB(sb
), &range
);
1827 mnt_drop_write_file(filp
);
1831 if (copy_to_user((struct fstrim_range __user
*)arg
, &range
,
1834 f2fs_update_time(F2FS_I_SB(inode
), REQ_TIME
);
1838 static bool uuid_is_nonzero(__u8 u
[16])
1842 for (i
= 0; i
< 16; i
++)
1848 static int f2fs_ioc_set_encryption_policy(struct file
*filp
, unsigned long arg
)
1850 struct inode
*inode
= file_inode(filp
);
1852 f2fs_update_time(F2FS_I_SB(inode
), REQ_TIME
);
1854 return fscrypt_ioctl_set_policy(filp
, (const void __user
*)arg
);
1857 static int f2fs_ioc_get_encryption_policy(struct file
*filp
, unsigned long arg
)
1859 return fscrypt_ioctl_get_policy(filp
, (void __user
*)arg
);
1862 static int f2fs_ioc_get_encryption_pwsalt(struct file
*filp
, unsigned long arg
)
1864 struct inode
*inode
= file_inode(filp
);
1865 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
1868 if (!f2fs_sb_has_crypto(inode
->i_sb
))
1871 if (uuid_is_nonzero(sbi
->raw_super
->encrypt_pw_salt
))
1874 err
= mnt_want_write_file(filp
);
1878 /* update superblock with uuid */
1879 generate_random_uuid(sbi
->raw_super
->encrypt_pw_salt
);
1881 err
= f2fs_commit_super(sbi
, false);
1884 memset(sbi
->raw_super
->encrypt_pw_salt
, 0, 16);
1885 mnt_drop_write_file(filp
);
1888 mnt_drop_write_file(filp
);
1890 if (copy_to_user((__u8 __user
*)arg
, sbi
->raw_super
->encrypt_pw_salt
,
1896 static int f2fs_ioc_gc(struct file
*filp
, unsigned long arg
)
1898 struct inode
*inode
= file_inode(filp
);
1899 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
1903 if (!capable(CAP_SYS_ADMIN
))
1906 if (get_user(sync
, (__u32 __user
*)arg
))
1909 if (f2fs_readonly(sbi
->sb
))
1912 ret
= mnt_want_write_file(filp
);
1917 if (!mutex_trylock(&sbi
->gc_mutex
)) {
1922 mutex_lock(&sbi
->gc_mutex
);
1925 ret
= f2fs_gc(sbi
, sync
, true, NULL_SEGNO
);
1927 mnt_drop_write_file(filp
);
1931 static int f2fs_ioc_gc_range(struct file
*filp
, unsigned long arg
)
1933 struct inode
*inode
= file_inode(filp
);
1934 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
1935 struct f2fs_gc_range range
;
1939 if (!capable(CAP_SYS_ADMIN
))
1942 if (copy_from_user(&range
, (struct f2fs_gc_range __user
*)arg
,
1946 if (f2fs_readonly(sbi
->sb
))
1949 ret
= mnt_want_write_file(filp
);
1953 end
= range
.start
+ range
.len
;
1954 if (range
.start
< MAIN_BLKADDR(sbi
) || end
>= MAX_BLKADDR(sbi
))
1958 if (!mutex_trylock(&sbi
->gc_mutex
)) {
1963 mutex_lock(&sbi
->gc_mutex
);
1966 ret
= f2fs_gc(sbi
, range
.sync
, true, GET_SEGNO(sbi
, range
.start
));
1967 range
.start
+= sbi
->blocks_per_seg
;
1968 if (range
.start
<= end
)
1971 mnt_drop_write_file(filp
);
1975 static int f2fs_ioc_write_checkpoint(struct file
*filp
, unsigned long arg
)
1977 struct inode
*inode
= file_inode(filp
);
1978 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
1981 if (!capable(CAP_SYS_ADMIN
))
1984 if (f2fs_readonly(sbi
->sb
))
1987 ret
= mnt_want_write_file(filp
);
1991 ret
= f2fs_sync_fs(sbi
->sb
, 1);
1993 mnt_drop_write_file(filp
);
1997 static int f2fs_defragment_range(struct f2fs_sb_info
*sbi
,
1999 struct f2fs_defragment
*range
)
2001 struct inode
*inode
= file_inode(filp
);
2002 struct f2fs_map_blocks map
= { .m_next_pgofs
= NULL
};
2003 struct extent_info ei
= {0,0,0};
2004 pgoff_t pg_start
, pg_end
;
2005 unsigned int blk_per_seg
= sbi
->blocks_per_seg
;
2006 unsigned int total
= 0, sec_num
;
2007 block_t blk_end
= 0;
2008 bool fragmented
= false;
2011 /* if in-place-update policy is enabled, don't waste time here */
2012 if (need_inplace_update_policy(inode
, NULL
))
2015 pg_start
= range
->start
>> PAGE_SHIFT
;
2016 pg_end
= (range
->start
+ range
->len
) >> PAGE_SHIFT
;
2018 f2fs_balance_fs(sbi
, true);
2022 /* writeback all dirty pages in the range */
2023 err
= filemap_write_and_wait_range(inode
->i_mapping
, range
->start
,
2024 range
->start
+ range
->len
- 1);
2029 * lookup mapping info in extent cache, skip defragmenting if physical
2030 * block addresses are continuous.
2032 if (f2fs_lookup_extent_cache(inode
, pg_start
, &ei
)) {
2033 if (ei
.fofs
+ ei
.len
>= pg_end
)
2037 map
.m_lblk
= pg_start
;
2040 * lookup mapping info in dnode page cache, skip defragmenting if all
2041 * physical block addresses are continuous even if there are hole(s)
2042 * in logical blocks.
2044 while (map
.m_lblk
< pg_end
) {
2045 map
.m_len
= pg_end
- map
.m_lblk
;
2046 err
= f2fs_map_blocks(inode
, &map
, 0, F2FS_GET_BLOCK_READ
);
2050 if (!(map
.m_flags
& F2FS_MAP_FLAGS
)) {
2055 if (blk_end
&& blk_end
!= map
.m_pblk
) {
2059 blk_end
= map
.m_pblk
+ map
.m_len
;
2061 map
.m_lblk
+= map
.m_len
;
2067 map
.m_lblk
= pg_start
;
2068 map
.m_len
= pg_end
- pg_start
;
2070 sec_num
= (map
.m_len
+ BLKS_PER_SEC(sbi
) - 1) / BLKS_PER_SEC(sbi
);
2073 * make sure there are enough free section for LFS allocation, this can
2074 * avoid defragment running in SSR mode when free section are allocated
2077 if (has_not_enough_free_secs(sbi
, 0, sec_num
)) {
2082 while (map
.m_lblk
< pg_end
) {
2087 map
.m_len
= pg_end
- map
.m_lblk
;
2088 err
= f2fs_map_blocks(inode
, &map
, 0, F2FS_GET_BLOCK_READ
);
2092 if (!(map
.m_flags
& F2FS_MAP_FLAGS
)) {
2097 set_inode_flag(inode
, FI_DO_DEFRAG
);
2100 while (idx
< map
.m_lblk
+ map
.m_len
&& cnt
< blk_per_seg
) {
2103 page
= get_lock_data_page(inode
, idx
, true);
2105 err
= PTR_ERR(page
);
2109 set_page_dirty(page
);
2110 f2fs_put_page(page
, 1);
2119 if (idx
< pg_end
&& cnt
< blk_per_seg
)
2122 clear_inode_flag(inode
, FI_DO_DEFRAG
);
2124 err
= filemap_fdatawrite(inode
->i_mapping
);
2129 clear_inode_flag(inode
, FI_DO_DEFRAG
);
2131 inode_unlock(inode
);
2133 range
->len
= (u64
)total
<< PAGE_SHIFT
;
2137 static int f2fs_ioc_defragment(struct file
*filp
, unsigned long arg
)
2139 struct inode
*inode
= file_inode(filp
);
2140 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
2141 struct f2fs_defragment range
;
2144 if (!capable(CAP_SYS_ADMIN
))
2147 if (!S_ISREG(inode
->i_mode
) || f2fs_is_atomic_file(inode
))
2150 if (f2fs_readonly(sbi
->sb
))
2153 if (copy_from_user(&range
, (struct f2fs_defragment __user
*)arg
,
2157 /* verify alignment of offset & size */
2158 if (range
.start
& (F2FS_BLKSIZE
- 1) || range
.len
& (F2FS_BLKSIZE
- 1))
2161 if (unlikely((range
.start
+ range
.len
) >> PAGE_SHIFT
>
2162 sbi
->max_file_blocks
))
2165 err
= mnt_want_write_file(filp
);
2169 err
= f2fs_defragment_range(sbi
, filp
, &range
);
2170 mnt_drop_write_file(filp
);
2172 f2fs_update_time(sbi
, REQ_TIME
);
2176 if (copy_to_user((struct f2fs_defragment __user
*)arg
, &range
,
2183 static int f2fs_move_file_range(struct file
*file_in
, loff_t pos_in
,
2184 struct file
*file_out
, loff_t pos_out
, size_t len
)
2186 struct inode
*src
= file_inode(file_in
);
2187 struct inode
*dst
= file_inode(file_out
);
2188 struct f2fs_sb_info
*sbi
= F2FS_I_SB(src
);
2189 size_t olen
= len
, dst_max_i_size
= 0;
2193 if (file_in
->f_path
.mnt
!= file_out
->f_path
.mnt
||
2194 src
->i_sb
!= dst
->i_sb
)
2197 if (unlikely(f2fs_readonly(src
->i_sb
)))
2200 if (!S_ISREG(src
->i_mode
) || !S_ISREG(dst
->i_mode
))
2203 if (f2fs_encrypted_inode(src
) || f2fs_encrypted_inode(dst
))
2207 if (pos_in
== pos_out
)
2209 if (pos_out
> pos_in
&& pos_out
< pos_in
+ len
)
2215 if (!inode_trylock(dst
)) {
2222 if (pos_in
+ len
> src
->i_size
|| pos_in
+ len
< pos_in
)
2225 olen
= len
= src
->i_size
- pos_in
;
2226 if (pos_in
+ len
== src
->i_size
)
2227 len
= ALIGN(src
->i_size
, F2FS_BLKSIZE
) - pos_in
;
2233 dst_osize
= dst
->i_size
;
2234 if (pos_out
+ olen
> dst
->i_size
)
2235 dst_max_i_size
= pos_out
+ olen
;
2237 /* verify the end result is block aligned */
2238 if (!IS_ALIGNED(pos_in
, F2FS_BLKSIZE
) ||
2239 !IS_ALIGNED(pos_in
+ len
, F2FS_BLKSIZE
) ||
2240 !IS_ALIGNED(pos_out
, F2FS_BLKSIZE
))
2243 ret
= f2fs_convert_inline_inode(src
);
2247 ret
= f2fs_convert_inline_inode(dst
);
2251 /* write out all dirty pages from offset */
2252 ret
= filemap_write_and_wait_range(src
->i_mapping
,
2253 pos_in
, pos_in
+ len
);
2257 ret
= filemap_write_and_wait_range(dst
->i_mapping
,
2258 pos_out
, pos_out
+ len
);
2262 f2fs_balance_fs(sbi
, true);
2264 ret
= __exchange_data_block(src
, dst
, pos_in
>> F2FS_BLKSIZE_BITS
,
2265 pos_out
>> F2FS_BLKSIZE_BITS
,
2266 len
>> F2FS_BLKSIZE_BITS
, false);
2270 f2fs_i_size_write(dst
, dst_max_i_size
);
2271 else if (dst_osize
!= dst
->i_size
)
2272 f2fs_i_size_write(dst
, dst_osize
);
2274 f2fs_unlock_op(sbi
);
2283 static int f2fs_ioc_move_range(struct file
*filp
, unsigned long arg
)
2285 struct f2fs_move_range range
;
2289 if (!(filp
->f_mode
& FMODE_READ
) ||
2290 !(filp
->f_mode
& FMODE_WRITE
))
2293 if (copy_from_user(&range
, (struct f2fs_move_range __user
*)arg
,
2297 dst
= fdget(range
.dst_fd
);
2301 if (!(dst
.file
->f_mode
& FMODE_WRITE
)) {
2306 err
= mnt_want_write_file(filp
);
2310 err
= f2fs_move_file_range(filp
, range
.pos_in
, dst
.file
,
2311 range
.pos_out
, range
.len
);
2313 mnt_drop_write_file(filp
);
2317 if (copy_to_user((struct f2fs_move_range __user
*)arg
,
2318 &range
, sizeof(range
)))
2325 static int f2fs_ioc_flush_device(struct file
*filp
, unsigned long arg
)
2327 struct inode
*inode
= file_inode(filp
);
2328 struct f2fs_sb_info
*sbi
= F2FS_I_SB(inode
);
2329 struct sit_info
*sm
= SIT_I(sbi
);
2330 unsigned int start_segno
= 0, end_segno
= 0;
2331 unsigned int dev_start_segno
= 0, dev_end_segno
= 0;
2332 struct f2fs_flush_device range
;
2335 if (!capable(CAP_SYS_ADMIN
))
2338 if (f2fs_readonly(sbi
->sb
))
2341 if (copy_from_user(&range
, (struct f2fs_flush_device __user
*)arg
,
2345 if (sbi
->s_ndevs
<= 1 || sbi
->s_ndevs
- 1 <= range
.dev_num
||
2346 sbi
->segs_per_sec
!= 1) {
2347 f2fs_msg(sbi
->sb
, KERN_WARNING
,
2348 "Can't flush %u in %d for segs_per_sec %u != 1\n",
2349 range
.dev_num
, sbi
->s_ndevs
,
2354 ret
= mnt_want_write_file(filp
);
2358 if (range
.dev_num
!= 0)
2359 dev_start_segno
= GET_SEGNO(sbi
, FDEV(range
.dev_num
).start_blk
);
2360 dev_end_segno
= GET_SEGNO(sbi
, FDEV(range
.dev_num
).end_blk
);
2362 start_segno
= sm
->last_victim
[FLUSH_DEVICE
];
2363 if (start_segno
< dev_start_segno
|| start_segno
>= dev_end_segno
)
2364 start_segno
= dev_start_segno
;
2365 end_segno
= min(start_segno
+ range
.segments
, dev_end_segno
);
2367 while (start_segno
< end_segno
) {
2368 if (!mutex_trylock(&sbi
->gc_mutex
)) {
2372 sm
->last_victim
[GC_CB
] = end_segno
+ 1;
2373 sm
->last_victim
[GC_GREEDY
] = end_segno
+ 1;
2374 sm
->last_victim
[ALLOC_NEXT
] = end_segno
+ 1;
2375 ret
= f2fs_gc(sbi
, true, true, start_segno
);
2383 mnt_drop_write_file(filp
);
2388 long f2fs_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
)
2391 case F2FS_IOC_GETFLAGS
:
2392 return f2fs_ioc_getflags(filp
, arg
);
2393 case F2FS_IOC_SETFLAGS
:
2394 return f2fs_ioc_setflags(filp
, arg
);
2395 case F2FS_IOC_GETVERSION
:
2396 return f2fs_ioc_getversion(filp
, arg
);
2397 case F2FS_IOC_START_ATOMIC_WRITE
:
2398 return f2fs_ioc_start_atomic_write(filp
);
2399 case F2FS_IOC_COMMIT_ATOMIC_WRITE
:
2400 return f2fs_ioc_commit_atomic_write(filp
);
2401 case F2FS_IOC_START_VOLATILE_WRITE
:
2402 return f2fs_ioc_start_volatile_write(filp
);
2403 case F2FS_IOC_RELEASE_VOLATILE_WRITE
:
2404 return f2fs_ioc_release_volatile_write(filp
);
2405 case F2FS_IOC_ABORT_VOLATILE_WRITE
:
2406 return f2fs_ioc_abort_volatile_write(filp
);
2407 case F2FS_IOC_SHUTDOWN
:
2408 return f2fs_ioc_shutdown(filp
, arg
);
2410 return f2fs_ioc_fitrim(filp
, arg
);
2411 case F2FS_IOC_SET_ENCRYPTION_POLICY
:
2412 return f2fs_ioc_set_encryption_policy(filp
, arg
);
2413 case F2FS_IOC_GET_ENCRYPTION_POLICY
:
2414 return f2fs_ioc_get_encryption_policy(filp
, arg
);
2415 case F2FS_IOC_GET_ENCRYPTION_PWSALT
:
2416 return f2fs_ioc_get_encryption_pwsalt(filp
, arg
);
2417 case F2FS_IOC_GARBAGE_COLLECT
:
2418 return f2fs_ioc_gc(filp
, arg
);
2419 case F2FS_IOC_GARBAGE_COLLECT_RANGE
:
2420 return f2fs_ioc_gc_range(filp
, arg
);
2421 case F2FS_IOC_WRITE_CHECKPOINT
:
2422 return f2fs_ioc_write_checkpoint(filp
, arg
);
2423 case F2FS_IOC_DEFRAGMENT
:
2424 return f2fs_ioc_defragment(filp
, arg
);
2425 case F2FS_IOC_MOVE_RANGE
:
2426 return f2fs_ioc_move_range(filp
, arg
);
2427 case F2FS_IOC_FLUSH_DEVICE
:
2428 return f2fs_ioc_flush_device(filp
, arg
);
2434 static ssize_t
f2fs_file_write_iter(struct kiocb
*iocb
, struct iov_iter
*from
)
2436 struct file
*file
= iocb
->ki_filp
;
2437 struct inode
*inode
= file_inode(file
);
2438 struct blk_plug plug
;
2442 ret
= generic_write_checks(iocb
, from
);
2446 if (iov_iter_fault_in_readable(from
, iov_iter_count(from
)))
2447 set_inode_flag(inode
, FI_NO_PREALLOC
);
2449 err
= f2fs_preallocate_blocks(iocb
, from
);
2451 inode_unlock(inode
);
2454 blk_start_plug(&plug
);
2455 ret
= __generic_file_write_iter(iocb
, from
);
2456 blk_finish_plug(&plug
);
2457 clear_inode_flag(inode
, FI_NO_PREALLOC
);
2459 inode_unlock(inode
);
2462 ret
= generic_write_sync(iocb
, ret
);
2466 #ifdef CONFIG_COMPAT
2467 long f2fs_compat_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2470 case F2FS_IOC32_GETFLAGS
:
2471 cmd
= F2FS_IOC_GETFLAGS
;
2473 case F2FS_IOC32_SETFLAGS
:
2474 cmd
= F2FS_IOC_SETFLAGS
;
2476 case F2FS_IOC32_GETVERSION
:
2477 cmd
= F2FS_IOC_GETVERSION
;
2479 case F2FS_IOC_START_ATOMIC_WRITE
:
2480 case F2FS_IOC_COMMIT_ATOMIC_WRITE
:
2481 case F2FS_IOC_START_VOLATILE_WRITE
:
2482 case F2FS_IOC_RELEASE_VOLATILE_WRITE
:
2483 case F2FS_IOC_ABORT_VOLATILE_WRITE
:
2484 case F2FS_IOC_SHUTDOWN
:
2485 case F2FS_IOC_SET_ENCRYPTION_POLICY
:
2486 case F2FS_IOC_GET_ENCRYPTION_PWSALT
:
2487 case F2FS_IOC_GET_ENCRYPTION_POLICY
:
2488 case F2FS_IOC_GARBAGE_COLLECT
:
2489 case F2FS_IOC_GARBAGE_COLLECT_RANGE
:
2490 case F2FS_IOC_WRITE_CHECKPOINT
:
2491 case F2FS_IOC_DEFRAGMENT
:
2492 case F2FS_IOC_MOVE_RANGE
:
2493 case F2FS_IOC_FLUSH_DEVICE
:
2496 return -ENOIOCTLCMD
;
2498 return f2fs_ioctl(file
, cmd
, (unsigned long) compat_ptr(arg
));
2502 const struct file_operations f2fs_file_operations
= {
2503 .llseek
= f2fs_llseek
,
2504 .read_iter
= generic_file_read_iter
,
2505 .write_iter
= f2fs_file_write_iter
,
2506 .open
= f2fs_file_open
,
2507 .release
= f2fs_release_file
,
2508 .mmap
= f2fs_file_mmap
,
2509 .fsync
= f2fs_sync_file
,
2510 .fallocate
= f2fs_fallocate
,
2511 .unlocked_ioctl
= f2fs_ioctl
,
2512 #ifdef CONFIG_COMPAT
2513 .compat_ioctl
= f2fs_compat_ioctl
,
2515 .splice_read
= generic_file_splice_read
,
2516 .splice_write
= iter_file_splice_write
,