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/pagemap.h>
14 #include <linux/sched.h>
15 #include <linux/ctype.h>
16 #include <linux/dcache.h>
17 #include <linux/namei.h>
23 #include <trace/events/f2fs.h>
25 static struct inode
*f2fs_new_inode(struct inode
*dir
, umode_t mode
)
27 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
30 bool nid_free
= false;
33 inode
= new_inode(dir
->i_sb
);
35 return ERR_PTR(-ENOMEM
);
38 if (!alloc_nid(sbi
, &ino
)) {
45 inode_init_owner(inode
, dir
, mode
);
49 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= CURRENT_TIME
;
50 inode
->i_generation
= sbi
->s_next_generation
++;
52 err
= insert_inode_locked(inode
);
59 /* If the directory encrypted, then we should encrypt the inode. */
60 if (f2fs_encrypted_inode(dir
) && f2fs_may_encrypt(inode
))
61 f2fs_set_encrypted_inode(inode
);
63 if (f2fs_may_inline_data(inode
))
64 set_inode_flag(F2FS_I(inode
), FI_INLINE_DATA
);
65 if (f2fs_may_inline_dentry(inode
))
66 set_inode_flag(F2FS_I(inode
), FI_INLINE_DENTRY
);
68 f2fs_init_extent_tree(inode
, NULL
);
70 stat_inc_inline_xattr(inode
);
71 stat_inc_inline_inode(inode
);
72 stat_inc_inline_dir(inode
);
74 trace_f2fs_new_inode(inode
, 0);
75 mark_inode_dirty(inode
);
79 trace_f2fs_new_inode(inode
, err
);
80 make_bad_inode(inode
);
82 set_inode_flag(F2FS_I(inode
), FI_FREE_NID
);
87 static int is_multimedia_file(const unsigned char *s
, const char *sub
)
89 size_t slen
= strlen(s
);
90 size_t sublen
= strlen(sub
);
93 * filename format of multimedia file should be defined as:
94 * "filename + '.' + extension".
96 if (slen
< sublen
+ 2)
99 if (s
[slen
- sublen
- 1] != '.')
102 return !strncasecmp(s
+ slen
- sublen
, sub
, sublen
);
106 * Set multimedia files as cold files for hot/cold data separation
108 static inline void set_cold_files(struct f2fs_sb_info
*sbi
, struct inode
*inode
,
109 const unsigned char *name
)
112 __u8 (*extlist
)[8] = sbi
->raw_super
->extension_list
;
114 int count
= le32_to_cpu(sbi
->raw_super
->extension_count
);
115 for (i
= 0; i
< count
; i
++) {
116 if (is_multimedia_file(name
, extlist
[i
])) {
117 file_set_cold(inode
);
123 static int f2fs_create(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
,
126 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
131 f2fs_balance_fs(sbi
);
133 inode
= f2fs_new_inode(dir
, mode
);
135 return PTR_ERR(inode
);
137 if (!test_opt(sbi
, DISABLE_EXT_IDENTIFY
))
138 set_cold_files(sbi
, inode
, dentry
->d_name
.name
);
140 inode
->i_op
= &f2fs_file_inode_operations
;
141 inode
->i_fop
= &f2fs_file_operations
;
142 inode
->i_mapping
->a_ops
= &f2fs_dblock_aops
;
146 err
= f2fs_add_link(dentry
, inode
);
151 alloc_nid_done(sbi
, ino
);
153 d_instantiate(dentry
, inode
);
154 unlock_new_inode(inode
);
157 f2fs_sync_fs(sbi
->sb
, 1);
160 handle_failed_inode(inode
);
164 static int f2fs_link(struct dentry
*old_dentry
, struct inode
*dir
,
165 struct dentry
*dentry
)
167 struct inode
*inode
= d_inode(old_dentry
);
168 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
171 if (f2fs_encrypted_inode(dir
) &&
172 !f2fs_is_child_context_consistent_with_parent(dir
, inode
))
175 f2fs_balance_fs(sbi
);
177 inode
->i_ctime
= CURRENT_TIME
;
180 set_inode_flag(F2FS_I(inode
), FI_INC_LINK
);
182 err
= f2fs_add_link(dentry
, inode
);
187 d_instantiate(dentry
, inode
);
190 f2fs_sync_fs(sbi
->sb
, 1);
193 clear_inode_flag(F2FS_I(inode
), FI_INC_LINK
);
199 struct dentry
*f2fs_get_parent(struct dentry
*child
)
201 struct qstr dotdot
= QSTR_INIT("..", 2);
202 unsigned long ino
= f2fs_inode_by_name(d_inode(child
), &dotdot
);
204 return ERR_PTR(-ENOENT
);
205 return d_obtain_alias(f2fs_iget(d_inode(child
)->i_sb
, ino
));
208 static int __recover_dot_dentries(struct inode
*dir
, nid_t pino
)
210 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
211 struct qstr dot
= QSTR_INIT(".", 1);
212 struct qstr dotdot
= QSTR_INIT("..", 2);
213 struct f2fs_dir_entry
*de
;
219 de
= f2fs_find_entry(dir
, &dot
, &page
);
221 f2fs_dentry_kunmap(dir
, page
);
222 f2fs_put_page(page
, 0);
224 err
= __f2fs_add_link(dir
, &dot
, NULL
, dir
->i_ino
, S_IFDIR
);
229 de
= f2fs_find_entry(dir
, &dotdot
, &page
);
231 f2fs_dentry_kunmap(dir
, page
);
232 f2fs_put_page(page
, 0);
234 err
= __f2fs_add_link(dir
, &dotdot
, NULL
, pino
, S_IFDIR
);
238 clear_inode_flag(F2FS_I(dir
), FI_INLINE_DOTS
);
239 mark_inode_dirty(dir
);
246 static struct dentry
*f2fs_lookup(struct inode
*dir
, struct dentry
*dentry
,
249 struct inode
*inode
= NULL
;
250 struct f2fs_dir_entry
*de
;
255 if (dentry
->d_name
.len
> F2FS_NAME_LEN
)
256 return ERR_PTR(-ENAMETOOLONG
);
258 de
= f2fs_find_entry(dir
, &dentry
->d_name
, &page
);
260 return d_splice_alias(inode
, dentry
);
262 ino
= le32_to_cpu(de
->ino
);
263 f2fs_dentry_kunmap(dir
, page
);
264 f2fs_put_page(page
, 0);
266 inode
= f2fs_iget(dir
->i_sb
, ino
);
268 return ERR_CAST(inode
);
270 if (f2fs_has_inline_dots(inode
)) {
271 err
= __recover_dot_dentries(inode
, dir
->i_ino
);
275 return d_splice_alias(inode
, dentry
);
282 static int f2fs_unlink(struct inode
*dir
, struct dentry
*dentry
)
284 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
285 struct inode
*inode
= d_inode(dentry
);
286 struct f2fs_dir_entry
*de
;
290 trace_f2fs_unlink_enter(dir
, dentry
);
291 f2fs_balance_fs(sbi
);
293 de
= f2fs_find_entry(dir
, &dentry
->d_name
, &page
);
298 err
= acquire_orphan_inode(sbi
);
301 f2fs_dentry_kunmap(dir
, page
);
302 f2fs_put_page(page
, 0);
305 f2fs_delete_entry(de
, page
, dir
, inode
);
308 /* In order to evict this inode, we set it dirty */
309 mark_inode_dirty(inode
);
312 f2fs_sync_fs(sbi
->sb
, 1);
314 trace_f2fs_unlink_exit(inode
, err
);
318 static const char *f2fs_follow_link(struct dentry
*dentry
, void **cookie
)
320 const char *link
= page_follow_link_light(dentry
, cookie
);
321 if (!IS_ERR(link
) && !*link
) {
322 /* this is broken symlink case */
323 page_put_link(NULL
, *cookie
);
324 link
= ERR_PTR(-ENOENT
);
329 static int f2fs_symlink(struct inode
*dir
, struct dentry
*dentry
,
332 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
334 size_t len
= strlen(symname
);
337 struct f2fs_str disk_link
= FSTR_INIT(NULL
, 0);
338 struct f2fs_encrypted_symlink_data
*sd
= NULL
;
341 if (len
> dir
->i_sb
->s_blocksize
)
342 return -ENAMETOOLONG
;
344 f2fs_balance_fs(sbi
);
346 inode
= f2fs_new_inode(dir
, S_IFLNK
| S_IRWXUGO
);
348 return PTR_ERR(inode
);
350 if (f2fs_encrypted_inode(inode
))
351 inode
->i_op
= &f2fs_encrypted_symlink_inode_operations
;
353 inode
->i_op
= &f2fs_symlink_inode_operations
;
354 inode_nohighmem(inode
);
355 inode
->i_mapping
->a_ops
= &f2fs_dblock_aops
;
358 err
= f2fs_add_link(dentry
, inode
);
362 alloc_nid_done(sbi
, inode
->i_ino
);
364 if (f2fs_encrypted_inode(dir
)) {
365 struct qstr istr
= QSTR_INIT(symname
, len
);
367 err
= f2fs_get_encryption_info(inode
);
371 err
= f2fs_fname_crypto_alloc_buffer(inode
, len
, &disk_link
);
375 err
= f2fs_fname_usr_to_disk(inode
, &istr
, &disk_link
);
379 p_len
= encrypted_symlink_data_len(disk_link
.len
) + 1;
381 if (p_len
> dir
->i_sb
->s_blocksize
) {
386 sd
= kzalloc(p_len
, GFP_NOFS
);
391 memcpy(sd
->encrypted_path
, disk_link
.name
, disk_link
.len
);
392 sd
->len
= cpu_to_le16(disk_link
.len
);
396 p_str
= (char *)symname
;
399 err
= page_symlink(inode
, p_str
, p_len
);
402 d_instantiate(dentry
, inode
);
403 unlock_new_inode(inode
);
406 * Let's flush symlink data in order to avoid broken symlink as much as
407 * possible. Nevertheless, fsyncing is the best way, but there is no
408 * way to get a file descriptor in order to flush that.
410 * Note that, it needs to do dir->fsync to make this recoverable.
411 * If the symlink path is stored into inline_data, there is no
412 * performance regression.
415 filemap_write_and_wait_range(inode
->i_mapping
, 0, p_len
- 1);
418 f2fs_sync_fs(sbi
->sb
, 1);
420 f2fs_unlink(dir
, dentry
);
424 f2fs_fname_crypto_free_buffer(&disk_link
);
427 handle_failed_inode(inode
);
431 static int f2fs_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
433 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
437 f2fs_balance_fs(sbi
);
439 inode
= f2fs_new_inode(dir
, S_IFDIR
| mode
);
441 return PTR_ERR(inode
);
443 inode
->i_op
= &f2fs_dir_inode_operations
;
444 inode
->i_fop
= &f2fs_dir_operations
;
445 inode
->i_mapping
->a_ops
= &f2fs_dblock_aops
;
446 mapping_set_gfp_mask(inode
->i_mapping
, GFP_F2FS_HIGH_ZERO
);
448 set_inode_flag(F2FS_I(inode
), FI_INC_LINK
);
450 err
= f2fs_add_link(dentry
, inode
);
455 alloc_nid_done(sbi
, inode
->i_ino
);
457 d_instantiate(dentry
, inode
);
458 unlock_new_inode(inode
);
461 f2fs_sync_fs(sbi
->sb
, 1);
465 clear_inode_flag(F2FS_I(inode
), FI_INC_LINK
);
466 handle_failed_inode(inode
);
470 static int f2fs_rmdir(struct inode
*dir
, struct dentry
*dentry
)
472 struct inode
*inode
= d_inode(dentry
);
473 if (f2fs_empty_dir(inode
))
474 return f2fs_unlink(dir
, dentry
);
478 static int f2fs_mknod(struct inode
*dir
, struct dentry
*dentry
,
479 umode_t mode
, dev_t rdev
)
481 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
485 f2fs_balance_fs(sbi
);
487 inode
= f2fs_new_inode(dir
, mode
);
489 return PTR_ERR(inode
);
491 init_special_inode(inode
, inode
->i_mode
, rdev
);
492 inode
->i_op
= &f2fs_special_inode_operations
;
495 err
= f2fs_add_link(dentry
, inode
);
500 alloc_nid_done(sbi
, inode
->i_ino
);
502 d_instantiate(dentry
, inode
);
503 unlock_new_inode(inode
);
506 f2fs_sync_fs(sbi
->sb
, 1);
509 handle_failed_inode(inode
);
513 static int __f2fs_tmpfile(struct inode
*dir
, struct dentry
*dentry
,
514 umode_t mode
, struct inode
**whiteout
)
516 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
521 f2fs_balance_fs(sbi
);
523 inode
= f2fs_new_inode(dir
, mode
);
525 return PTR_ERR(inode
);
528 init_special_inode(inode
, inode
->i_mode
, WHITEOUT_DEV
);
529 inode
->i_op
= &f2fs_special_inode_operations
;
531 inode
->i_op
= &f2fs_file_inode_operations
;
532 inode
->i_fop
= &f2fs_file_operations
;
533 inode
->i_mapping
->a_ops
= &f2fs_dblock_aops
;
537 err
= acquire_orphan_inode(sbi
);
541 err
= f2fs_do_tmpfile(inode
, dir
);
546 * add this non-linked tmpfile to orphan list, in this way we could
547 * remove all unused data of tmpfile after abnormal power-off.
549 add_orphan_inode(sbi
, inode
->i_ino
);
552 alloc_nid_done(sbi
, inode
->i_ino
);
555 inode_dec_link_count(inode
);
558 d_tmpfile(dentry
, inode
);
560 unlock_new_inode(inode
);
564 release_orphan_inode(sbi
);
566 handle_failed_inode(inode
);
570 static int f2fs_tmpfile(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
572 if (f2fs_encrypted_inode(dir
)) {
573 int err
= f2fs_get_encryption_info(dir
);
578 return __f2fs_tmpfile(dir
, dentry
, mode
, NULL
);
581 static int f2fs_create_whiteout(struct inode
*dir
, struct inode
**whiteout
)
583 return __f2fs_tmpfile(dir
, NULL
, S_IFCHR
| WHITEOUT_MODE
, whiteout
);
586 static int f2fs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
587 struct inode
*new_dir
, struct dentry
*new_dentry
,
590 struct f2fs_sb_info
*sbi
= F2FS_I_SB(old_dir
);
591 struct inode
*old_inode
= d_inode(old_dentry
);
592 struct inode
*new_inode
= d_inode(new_dentry
);
593 struct inode
*whiteout
= NULL
;
594 struct page
*old_dir_page
;
595 struct page
*old_page
, *new_page
= NULL
;
596 struct f2fs_dir_entry
*old_dir_entry
= NULL
;
597 struct f2fs_dir_entry
*old_entry
;
598 struct f2fs_dir_entry
*new_entry
;
601 if ((old_dir
!= new_dir
) && f2fs_encrypted_inode(new_dir
) &&
602 !f2fs_is_child_context_consistent_with_parent(new_dir
,
608 f2fs_balance_fs(sbi
);
610 old_entry
= f2fs_find_entry(old_dir
, &old_dentry
->d_name
, &old_page
);
614 if (S_ISDIR(old_inode
->i_mode
)) {
616 old_dir_entry
= f2fs_parent_dir(old_inode
, &old_dir_page
);
621 if (flags
& RENAME_WHITEOUT
) {
622 err
= f2fs_create_whiteout(old_dir
, &whiteout
);
630 if (old_dir_entry
&& !f2fs_empty_dir(new_inode
))
634 new_entry
= f2fs_find_entry(new_dir
, &new_dentry
->d_name
,
641 err
= acquire_orphan_inode(sbi
);
645 if (update_dent_inode(old_inode
, new_inode
,
646 &new_dentry
->d_name
)) {
647 release_orphan_inode(sbi
);
651 f2fs_set_link(new_dir
, new_entry
, new_page
, old_inode
);
653 new_inode
->i_ctime
= CURRENT_TIME
;
654 down_write(&F2FS_I(new_inode
)->i_sem
);
656 drop_nlink(new_inode
);
657 drop_nlink(new_inode
);
658 up_write(&F2FS_I(new_inode
)->i_sem
);
660 mark_inode_dirty(new_inode
);
662 if (!new_inode
->i_nlink
)
663 add_orphan_inode(sbi
, new_inode
->i_ino
);
665 release_orphan_inode(sbi
);
667 update_inode_page(old_inode
);
668 update_inode_page(new_inode
);
672 err
= f2fs_add_link(new_dentry
, old_inode
);
680 update_inode_page(new_dir
);
684 down_write(&F2FS_I(old_inode
)->i_sem
);
685 file_lost_pino(old_inode
);
686 if (new_inode
&& file_enc_name(new_inode
))
687 file_set_enc_name(old_inode
);
688 up_write(&F2FS_I(old_inode
)->i_sem
);
690 old_inode
->i_ctime
= CURRENT_TIME
;
691 mark_inode_dirty(old_inode
);
693 f2fs_delete_entry(old_entry
, old_page
, old_dir
, NULL
);
696 whiteout
->i_state
|= I_LINKABLE
;
697 set_inode_flag(F2FS_I(whiteout
), FI_INC_LINK
);
698 err
= f2fs_add_link(old_dentry
, whiteout
);
701 whiteout
->i_state
&= ~I_LINKABLE
;
706 if (old_dir
!= new_dir
&& !whiteout
) {
707 f2fs_set_link(old_inode
, old_dir_entry
,
708 old_dir_page
, new_dir
);
709 update_inode_page(old_inode
);
711 f2fs_dentry_kunmap(old_inode
, old_dir_page
);
712 f2fs_put_page(old_dir_page
, 0);
715 mark_inode_dirty(old_dir
);
716 update_inode_page(old_dir
);
721 if (IS_DIRSYNC(old_dir
) || IS_DIRSYNC(new_dir
))
722 f2fs_sync_fs(sbi
->sb
, 1);
728 f2fs_dentry_kunmap(new_dir
, new_page
);
729 f2fs_put_page(new_page
, 0);
736 f2fs_dentry_kunmap(old_inode
, old_dir_page
);
737 f2fs_put_page(old_dir_page
, 0);
740 f2fs_dentry_kunmap(old_dir
, old_page
);
741 f2fs_put_page(old_page
, 0);
746 static int f2fs_cross_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
747 struct inode
*new_dir
, struct dentry
*new_dentry
)
749 struct f2fs_sb_info
*sbi
= F2FS_I_SB(old_dir
);
750 struct inode
*old_inode
= d_inode(old_dentry
);
751 struct inode
*new_inode
= d_inode(new_dentry
);
752 struct page
*old_dir_page
, *new_dir_page
;
753 struct page
*old_page
, *new_page
;
754 struct f2fs_dir_entry
*old_dir_entry
= NULL
, *new_dir_entry
= NULL
;
755 struct f2fs_dir_entry
*old_entry
, *new_entry
;
756 int old_nlink
= 0, new_nlink
= 0;
759 if ((f2fs_encrypted_inode(old_dir
) || f2fs_encrypted_inode(new_dir
)) &&
760 (old_dir
!= new_dir
) &&
761 (!f2fs_is_child_context_consistent_with_parent(new_dir
,
763 !f2fs_is_child_context_consistent_with_parent(old_dir
,
767 f2fs_balance_fs(sbi
);
769 old_entry
= f2fs_find_entry(old_dir
, &old_dentry
->d_name
, &old_page
);
773 new_entry
= f2fs_find_entry(new_dir
, &new_dentry
->d_name
, &new_page
);
777 /* prepare for updating ".." directory entry info later */
778 if (old_dir
!= new_dir
) {
779 if (S_ISDIR(old_inode
->i_mode
)) {
781 old_dir_entry
= f2fs_parent_dir(old_inode
,
787 if (S_ISDIR(new_inode
->i_mode
)) {
789 new_dir_entry
= f2fs_parent_dir(new_inode
,
797 * If cross rename between file and directory those are not
798 * in the same directory, we will inc nlink of file's parent
799 * later, so we should check upper boundary of its nlink.
801 if ((!old_dir_entry
|| !new_dir_entry
) &&
802 old_dir_entry
!= new_dir_entry
) {
803 old_nlink
= old_dir_entry
? -1 : 1;
804 new_nlink
= -old_nlink
;
806 if ((old_nlink
> 0 && old_inode
->i_nlink
>= F2FS_LINK_MAX
) ||
807 (new_nlink
> 0 && new_inode
->i_nlink
>= F2FS_LINK_MAX
))
813 err
= update_dent_inode(old_inode
, new_inode
, &new_dentry
->d_name
);
816 if (file_enc_name(new_inode
))
817 file_set_enc_name(old_inode
);
819 err
= update_dent_inode(new_inode
, old_inode
, &old_dentry
->d_name
);
822 if (file_enc_name(old_inode
))
823 file_set_enc_name(new_inode
);
825 /* update ".." directory entry info of old dentry */
827 f2fs_set_link(old_inode
, old_dir_entry
, old_dir_page
, new_dir
);
829 /* update ".." directory entry info of new dentry */
831 f2fs_set_link(new_inode
, new_dir_entry
, new_dir_page
, old_dir
);
833 /* update directory entry info of old dir inode */
834 f2fs_set_link(old_dir
, old_entry
, old_page
, new_inode
);
836 down_write(&F2FS_I(old_inode
)->i_sem
);
837 file_lost_pino(old_inode
);
838 up_write(&F2FS_I(old_inode
)->i_sem
);
840 update_inode_page(old_inode
);
842 old_dir
->i_ctime
= CURRENT_TIME
;
844 down_write(&F2FS_I(old_dir
)->i_sem
);
849 up_write(&F2FS_I(old_dir
)->i_sem
);
851 mark_inode_dirty(old_dir
);
852 update_inode_page(old_dir
);
854 /* update directory entry info of new dir inode */
855 f2fs_set_link(new_dir
, new_entry
, new_page
, old_inode
);
857 down_write(&F2FS_I(new_inode
)->i_sem
);
858 file_lost_pino(new_inode
);
859 up_write(&F2FS_I(new_inode
)->i_sem
);
861 update_inode_page(new_inode
);
863 new_dir
->i_ctime
= CURRENT_TIME
;
865 down_write(&F2FS_I(new_dir
)->i_sem
);
870 up_write(&F2FS_I(new_dir
)->i_sem
);
872 mark_inode_dirty(new_dir
);
873 update_inode_page(new_dir
);
877 if (IS_DIRSYNC(old_dir
) || IS_DIRSYNC(new_dir
))
878 f2fs_sync_fs(sbi
->sb
, 1);
882 * Still we may fail to recover name info of f2fs_inode here
883 * Drop it, once its name is set as encrypted
885 update_dent_inode(old_inode
, old_inode
, &old_dentry
->d_name
);
890 f2fs_dentry_kunmap(new_inode
, new_dir_page
);
891 f2fs_put_page(new_dir_page
, 0);
895 f2fs_dentry_kunmap(old_inode
, old_dir_page
);
896 f2fs_put_page(old_dir_page
, 0);
899 f2fs_dentry_kunmap(new_dir
, new_page
);
900 f2fs_put_page(new_page
, 0);
902 f2fs_dentry_kunmap(old_dir
, old_page
);
903 f2fs_put_page(old_page
, 0);
908 static int f2fs_rename2(struct inode
*old_dir
, struct dentry
*old_dentry
,
909 struct inode
*new_dir
, struct dentry
*new_dentry
,
912 if (flags
& ~(RENAME_NOREPLACE
| RENAME_EXCHANGE
| RENAME_WHITEOUT
))
915 if (flags
& RENAME_EXCHANGE
) {
916 return f2fs_cross_rename(old_dir
, old_dentry
,
917 new_dir
, new_dentry
);
920 * VFS has already handled the new dentry existence case,
921 * here, we just deal with "RENAME_NOREPLACE" as regular rename.
923 return f2fs_rename(old_dir
, old_dentry
, new_dir
, new_dentry
, flags
);
926 #ifdef CONFIG_F2FS_FS_ENCRYPTION
927 static const char *f2fs_encrypted_follow_link(struct dentry
*dentry
, void **cookie
)
929 struct page
*cpage
= NULL
;
930 char *caddr
, *paddr
= NULL
;
931 struct f2fs_str cstr
;
932 struct f2fs_str pstr
= FSTR_INIT(NULL
, 0);
933 struct inode
*inode
= d_inode(dentry
);
934 struct f2fs_encrypted_symlink_data
*sd
;
935 loff_t size
= min_t(loff_t
, i_size_read(inode
), PAGE_SIZE
- 1);
936 u32 max_size
= inode
->i_sb
->s_blocksize
;
939 res
= f2fs_get_encryption_info(inode
);
943 cpage
= read_mapping_page(inode
->i_mapping
, 0, NULL
);
945 return ERR_CAST(cpage
);
946 caddr
= page_address(cpage
);
949 /* Symlink is encrypted */
950 sd
= (struct f2fs_encrypted_symlink_data
*)caddr
;
951 cstr
.len
= le16_to_cpu(sd
->len
);
952 cstr
.name
= kmalloc(cstr
.len
, GFP_NOFS
);
957 memcpy(cstr
.name
, sd
->encrypted_path
, cstr
.len
);
959 /* this is broken symlink case */
960 if (cstr
.name
[0] == 0 && cstr
.len
== 0) {
965 if ((cstr
.len
+ sizeof(struct f2fs_encrypted_symlink_data
) - 1) >
967 /* Symlink data on the disk is corrupted */
971 res
= f2fs_fname_crypto_alloc_buffer(inode
, cstr
.len
, &pstr
);
975 res
= f2fs_fname_disk_to_usr(inode
, NULL
, &cstr
, &pstr
);
983 /* Null-terminate the name */
986 page_cache_release(cpage
);
987 return *cookie
= paddr
;
990 f2fs_fname_crypto_free_buffer(&pstr
);
991 page_cache_release(cpage
);
995 const struct inode_operations f2fs_encrypted_symlink_inode_operations
= {
996 .readlink
= generic_readlink
,
997 .follow_link
= f2fs_encrypted_follow_link
,
998 .put_link
= kfree_put_link
,
999 .getattr
= f2fs_getattr
,
1000 .setattr
= f2fs_setattr
,
1001 .setxattr
= generic_setxattr
,
1002 .getxattr
= generic_getxattr
,
1003 .listxattr
= f2fs_listxattr
,
1004 .removexattr
= generic_removexattr
,
1008 const struct inode_operations f2fs_dir_inode_operations
= {
1009 .create
= f2fs_create
,
1010 .lookup
= f2fs_lookup
,
1012 .unlink
= f2fs_unlink
,
1013 .symlink
= f2fs_symlink
,
1014 .mkdir
= f2fs_mkdir
,
1015 .rmdir
= f2fs_rmdir
,
1016 .mknod
= f2fs_mknod
,
1017 .rename2
= f2fs_rename2
,
1018 .tmpfile
= f2fs_tmpfile
,
1019 .getattr
= f2fs_getattr
,
1020 .setattr
= f2fs_setattr
,
1021 .get_acl
= f2fs_get_acl
,
1022 .set_acl
= f2fs_set_acl
,
1023 #ifdef CONFIG_F2FS_FS_XATTR
1024 .setxattr
= generic_setxattr
,
1025 .getxattr
= generic_getxattr
,
1026 .listxattr
= f2fs_listxattr
,
1027 .removexattr
= generic_removexattr
,
1031 const struct inode_operations f2fs_symlink_inode_operations
= {
1032 .readlink
= generic_readlink
,
1033 .follow_link
= f2fs_follow_link
,
1034 .put_link
= page_put_link
,
1035 .getattr
= f2fs_getattr
,
1036 .setattr
= f2fs_setattr
,
1037 #ifdef CONFIG_F2FS_FS_XATTR
1038 .setxattr
= generic_setxattr
,
1039 .getxattr
= generic_getxattr
,
1040 .listxattr
= f2fs_listxattr
,
1041 .removexattr
= generic_removexattr
,
1045 const struct inode_operations f2fs_special_inode_operations
= {
1046 .getattr
= f2fs_getattr
,
1047 .setattr
= f2fs_setattr
,
1048 .get_acl
= f2fs_get_acl
,
1049 .set_acl
= f2fs_set_acl
,
1050 #ifdef CONFIG_F2FS_FS_XATTR
1051 .setxattr
= generic_setxattr
,
1052 .getxattr
= generic_getxattr
,
1053 .listxattr
= f2fs_listxattr
,
1054 .removexattr
= generic_removexattr
,