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_get_link(struct dentry
*dentry
,
320 struct delayed_call
*done
)
322 const char *link
= page_get_link(dentry
, inode
, done
);
323 if (!IS_ERR(link
) && !*link
) {
324 /* this is broken symlink case */
325 do_delayed_call(done
);
326 clear_delayed_call(done
);
327 link
= ERR_PTR(-ENOENT
);
332 static int f2fs_symlink(struct inode
*dir
, struct dentry
*dentry
,
335 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
337 size_t len
= strlen(symname
);
340 struct f2fs_str disk_link
= FSTR_INIT(NULL
, 0);
341 struct f2fs_encrypted_symlink_data
*sd
= NULL
;
344 if (len
> dir
->i_sb
->s_blocksize
)
345 return -ENAMETOOLONG
;
347 f2fs_balance_fs(sbi
);
349 inode
= f2fs_new_inode(dir
, S_IFLNK
| S_IRWXUGO
);
351 return PTR_ERR(inode
);
353 if (f2fs_encrypted_inode(inode
))
354 inode
->i_op
= &f2fs_encrypted_symlink_inode_operations
;
356 inode
->i_op
= &f2fs_symlink_inode_operations
;
357 inode_nohighmem(inode
);
358 inode
->i_mapping
->a_ops
= &f2fs_dblock_aops
;
361 err
= f2fs_add_link(dentry
, inode
);
365 alloc_nid_done(sbi
, inode
->i_ino
);
367 if (f2fs_encrypted_inode(dir
)) {
368 struct qstr istr
= QSTR_INIT(symname
, len
);
370 err
= f2fs_get_encryption_info(inode
);
374 err
= f2fs_fname_crypto_alloc_buffer(inode
, len
, &disk_link
);
378 err
= f2fs_fname_usr_to_disk(inode
, &istr
, &disk_link
);
382 p_len
= encrypted_symlink_data_len(disk_link
.len
) + 1;
384 if (p_len
> dir
->i_sb
->s_blocksize
) {
389 sd
= kzalloc(p_len
, GFP_NOFS
);
394 memcpy(sd
->encrypted_path
, disk_link
.name
, disk_link
.len
);
395 sd
->len
= cpu_to_le16(disk_link
.len
);
399 p_str
= (char *)symname
;
402 err
= page_symlink(inode
, p_str
, p_len
);
405 d_instantiate(dentry
, inode
);
406 unlock_new_inode(inode
);
409 * Let's flush symlink data in order to avoid broken symlink as much as
410 * possible. Nevertheless, fsyncing is the best way, but there is no
411 * way to get a file descriptor in order to flush that.
413 * Note that, it needs to do dir->fsync to make this recoverable.
414 * If the symlink path is stored into inline_data, there is no
415 * performance regression.
418 filemap_write_and_wait_range(inode
->i_mapping
, 0, p_len
- 1);
421 f2fs_sync_fs(sbi
->sb
, 1);
423 f2fs_unlink(dir
, dentry
);
427 f2fs_fname_crypto_free_buffer(&disk_link
);
430 handle_failed_inode(inode
);
434 static int f2fs_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
436 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
440 f2fs_balance_fs(sbi
);
442 inode
= f2fs_new_inode(dir
, S_IFDIR
| mode
);
444 return PTR_ERR(inode
);
446 inode
->i_op
= &f2fs_dir_inode_operations
;
447 inode
->i_fop
= &f2fs_dir_operations
;
448 inode
->i_mapping
->a_ops
= &f2fs_dblock_aops
;
449 mapping_set_gfp_mask(inode
->i_mapping
, GFP_F2FS_HIGH_ZERO
);
451 set_inode_flag(F2FS_I(inode
), FI_INC_LINK
);
453 err
= f2fs_add_link(dentry
, inode
);
458 alloc_nid_done(sbi
, inode
->i_ino
);
460 d_instantiate(dentry
, inode
);
461 unlock_new_inode(inode
);
464 f2fs_sync_fs(sbi
->sb
, 1);
468 clear_inode_flag(F2FS_I(inode
), FI_INC_LINK
);
469 handle_failed_inode(inode
);
473 static int f2fs_rmdir(struct inode
*dir
, struct dentry
*dentry
)
475 struct inode
*inode
= d_inode(dentry
);
476 if (f2fs_empty_dir(inode
))
477 return f2fs_unlink(dir
, dentry
);
481 static int f2fs_mknod(struct inode
*dir
, struct dentry
*dentry
,
482 umode_t mode
, dev_t rdev
)
484 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
488 f2fs_balance_fs(sbi
);
490 inode
= f2fs_new_inode(dir
, mode
);
492 return PTR_ERR(inode
);
494 init_special_inode(inode
, inode
->i_mode
, rdev
);
495 inode
->i_op
= &f2fs_special_inode_operations
;
498 err
= f2fs_add_link(dentry
, inode
);
503 alloc_nid_done(sbi
, inode
->i_ino
);
505 d_instantiate(dentry
, inode
);
506 unlock_new_inode(inode
);
509 f2fs_sync_fs(sbi
->sb
, 1);
512 handle_failed_inode(inode
);
516 static int __f2fs_tmpfile(struct inode
*dir
, struct dentry
*dentry
,
517 umode_t mode
, struct inode
**whiteout
)
519 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
524 f2fs_balance_fs(sbi
);
526 inode
= f2fs_new_inode(dir
, mode
);
528 return PTR_ERR(inode
);
531 init_special_inode(inode
, inode
->i_mode
, WHITEOUT_DEV
);
532 inode
->i_op
= &f2fs_special_inode_operations
;
534 inode
->i_op
= &f2fs_file_inode_operations
;
535 inode
->i_fop
= &f2fs_file_operations
;
536 inode
->i_mapping
->a_ops
= &f2fs_dblock_aops
;
540 err
= acquire_orphan_inode(sbi
);
544 err
= f2fs_do_tmpfile(inode
, dir
);
549 * add this non-linked tmpfile to orphan list, in this way we could
550 * remove all unused data of tmpfile after abnormal power-off.
552 add_orphan_inode(sbi
, inode
->i_ino
);
555 alloc_nid_done(sbi
, inode
->i_ino
);
558 inode_dec_link_count(inode
);
561 d_tmpfile(dentry
, inode
);
563 unlock_new_inode(inode
);
567 release_orphan_inode(sbi
);
569 handle_failed_inode(inode
);
573 static int f2fs_tmpfile(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
575 if (f2fs_encrypted_inode(dir
)) {
576 int err
= f2fs_get_encryption_info(dir
);
581 return __f2fs_tmpfile(dir
, dentry
, mode
, NULL
);
584 static int f2fs_create_whiteout(struct inode
*dir
, struct inode
**whiteout
)
586 return __f2fs_tmpfile(dir
, NULL
, S_IFCHR
| WHITEOUT_MODE
, whiteout
);
589 static int f2fs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
590 struct inode
*new_dir
, struct dentry
*new_dentry
,
593 struct f2fs_sb_info
*sbi
= F2FS_I_SB(old_dir
);
594 struct inode
*old_inode
= d_inode(old_dentry
);
595 struct inode
*new_inode
= d_inode(new_dentry
);
596 struct inode
*whiteout
= NULL
;
597 struct page
*old_dir_page
;
598 struct page
*old_page
, *new_page
= NULL
;
599 struct f2fs_dir_entry
*old_dir_entry
= NULL
;
600 struct f2fs_dir_entry
*old_entry
;
601 struct f2fs_dir_entry
*new_entry
;
604 if ((old_dir
!= new_dir
) && f2fs_encrypted_inode(new_dir
) &&
605 !f2fs_is_child_context_consistent_with_parent(new_dir
,
611 f2fs_balance_fs(sbi
);
613 old_entry
= f2fs_find_entry(old_dir
, &old_dentry
->d_name
, &old_page
);
617 if (S_ISDIR(old_inode
->i_mode
)) {
619 old_dir_entry
= f2fs_parent_dir(old_inode
, &old_dir_page
);
624 if (flags
& RENAME_WHITEOUT
) {
625 err
= f2fs_create_whiteout(old_dir
, &whiteout
);
633 if (old_dir_entry
&& !f2fs_empty_dir(new_inode
))
637 new_entry
= f2fs_find_entry(new_dir
, &new_dentry
->d_name
,
644 err
= acquire_orphan_inode(sbi
);
648 if (update_dent_inode(old_inode
, new_inode
,
649 &new_dentry
->d_name
)) {
650 release_orphan_inode(sbi
);
654 f2fs_set_link(new_dir
, new_entry
, new_page
, old_inode
);
656 new_inode
->i_ctime
= CURRENT_TIME
;
657 down_write(&F2FS_I(new_inode
)->i_sem
);
659 drop_nlink(new_inode
);
660 drop_nlink(new_inode
);
661 up_write(&F2FS_I(new_inode
)->i_sem
);
663 mark_inode_dirty(new_inode
);
665 if (!new_inode
->i_nlink
)
666 add_orphan_inode(sbi
, new_inode
->i_ino
);
668 release_orphan_inode(sbi
);
670 update_inode_page(old_inode
);
671 update_inode_page(new_inode
);
675 err
= f2fs_add_link(new_dentry
, old_inode
);
683 update_inode_page(new_dir
);
687 down_write(&F2FS_I(old_inode
)->i_sem
);
688 file_lost_pino(old_inode
);
689 if (new_inode
&& file_enc_name(new_inode
))
690 file_set_enc_name(old_inode
);
691 up_write(&F2FS_I(old_inode
)->i_sem
);
693 old_inode
->i_ctime
= CURRENT_TIME
;
694 mark_inode_dirty(old_inode
);
696 f2fs_delete_entry(old_entry
, old_page
, old_dir
, NULL
);
699 whiteout
->i_state
|= I_LINKABLE
;
700 set_inode_flag(F2FS_I(whiteout
), FI_INC_LINK
);
701 err
= f2fs_add_link(old_dentry
, whiteout
);
704 whiteout
->i_state
&= ~I_LINKABLE
;
709 if (old_dir
!= new_dir
&& !whiteout
) {
710 f2fs_set_link(old_inode
, old_dir_entry
,
711 old_dir_page
, new_dir
);
712 update_inode_page(old_inode
);
714 f2fs_dentry_kunmap(old_inode
, old_dir_page
);
715 f2fs_put_page(old_dir_page
, 0);
718 mark_inode_dirty(old_dir
);
719 update_inode_page(old_dir
);
724 if (IS_DIRSYNC(old_dir
) || IS_DIRSYNC(new_dir
))
725 f2fs_sync_fs(sbi
->sb
, 1);
731 f2fs_dentry_kunmap(new_dir
, new_page
);
732 f2fs_put_page(new_page
, 0);
739 f2fs_dentry_kunmap(old_inode
, old_dir_page
);
740 f2fs_put_page(old_dir_page
, 0);
743 f2fs_dentry_kunmap(old_dir
, old_page
);
744 f2fs_put_page(old_page
, 0);
749 static int f2fs_cross_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
750 struct inode
*new_dir
, struct dentry
*new_dentry
)
752 struct f2fs_sb_info
*sbi
= F2FS_I_SB(old_dir
);
753 struct inode
*old_inode
= d_inode(old_dentry
);
754 struct inode
*new_inode
= d_inode(new_dentry
);
755 struct page
*old_dir_page
, *new_dir_page
;
756 struct page
*old_page
, *new_page
;
757 struct f2fs_dir_entry
*old_dir_entry
= NULL
, *new_dir_entry
= NULL
;
758 struct f2fs_dir_entry
*old_entry
, *new_entry
;
759 int old_nlink
= 0, new_nlink
= 0;
762 if ((f2fs_encrypted_inode(old_dir
) || f2fs_encrypted_inode(new_dir
)) &&
763 (old_dir
!= new_dir
) &&
764 (!f2fs_is_child_context_consistent_with_parent(new_dir
,
766 !f2fs_is_child_context_consistent_with_parent(old_dir
,
770 f2fs_balance_fs(sbi
);
772 old_entry
= f2fs_find_entry(old_dir
, &old_dentry
->d_name
, &old_page
);
776 new_entry
= f2fs_find_entry(new_dir
, &new_dentry
->d_name
, &new_page
);
780 /* prepare for updating ".." directory entry info later */
781 if (old_dir
!= new_dir
) {
782 if (S_ISDIR(old_inode
->i_mode
)) {
784 old_dir_entry
= f2fs_parent_dir(old_inode
,
790 if (S_ISDIR(new_inode
->i_mode
)) {
792 new_dir_entry
= f2fs_parent_dir(new_inode
,
800 * If cross rename between file and directory those are not
801 * in the same directory, we will inc nlink of file's parent
802 * later, so we should check upper boundary of its nlink.
804 if ((!old_dir_entry
|| !new_dir_entry
) &&
805 old_dir_entry
!= new_dir_entry
) {
806 old_nlink
= old_dir_entry
? -1 : 1;
807 new_nlink
= -old_nlink
;
809 if ((old_nlink
> 0 && old_inode
->i_nlink
>= F2FS_LINK_MAX
) ||
810 (new_nlink
> 0 && new_inode
->i_nlink
>= F2FS_LINK_MAX
))
816 err
= update_dent_inode(old_inode
, new_inode
, &new_dentry
->d_name
);
819 if (file_enc_name(new_inode
))
820 file_set_enc_name(old_inode
);
822 err
= update_dent_inode(new_inode
, old_inode
, &old_dentry
->d_name
);
825 if (file_enc_name(old_inode
))
826 file_set_enc_name(new_inode
);
828 /* update ".." directory entry info of old dentry */
830 f2fs_set_link(old_inode
, old_dir_entry
, old_dir_page
, new_dir
);
832 /* update ".." directory entry info of new dentry */
834 f2fs_set_link(new_inode
, new_dir_entry
, new_dir_page
, old_dir
);
836 /* update directory entry info of old dir inode */
837 f2fs_set_link(old_dir
, old_entry
, old_page
, new_inode
);
839 down_write(&F2FS_I(old_inode
)->i_sem
);
840 file_lost_pino(old_inode
);
841 up_write(&F2FS_I(old_inode
)->i_sem
);
843 update_inode_page(old_inode
);
845 old_dir
->i_ctime
= CURRENT_TIME
;
847 down_write(&F2FS_I(old_dir
)->i_sem
);
852 up_write(&F2FS_I(old_dir
)->i_sem
);
854 mark_inode_dirty(old_dir
);
855 update_inode_page(old_dir
);
857 /* update directory entry info of new dir inode */
858 f2fs_set_link(new_dir
, new_entry
, new_page
, old_inode
);
860 down_write(&F2FS_I(new_inode
)->i_sem
);
861 file_lost_pino(new_inode
);
862 up_write(&F2FS_I(new_inode
)->i_sem
);
864 update_inode_page(new_inode
);
866 new_dir
->i_ctime
= CURRENT_TIME
;
868 down_write(&F2FS_I(new_dir
)->i_sem
);
873 up_write(&F2FS_I(new_dir
)->i_sem
);
875 mark_inode_dirty(new_dir
);
876 update_inode_page(new_dir
);
880 if (IS_DIRSYNC(old_dir
) || IS_DIRSYNC(new_dir
))
881 f2fs_sync_fs(sbi
->sb
, 1);
885 * Still we may fail to recover name info of f2fs_inode here
886 * Drop it, once its name is set as encrypted
888 update_dent_inode(old_inode
, old_inode
, &old_dentry
->d_name
);
893 f2fs_dentry_kunmap(new_inode
, new_dir_page
);
894 f2fs_put_page(new_dir_page
, 0);
898 f2fs_dentry_kunmap(old_inode
, old_dir_page
);
899 f2fs_put_page(old_dir_page
, 0);
902 f2fs_dentry_kunmap(new_dir
, new_page
);
903 f2fs_put_page(new_page
, 0);
905 f2fs_dentry_kunmap(old_dir
, old_page
);
906 f2fs_put_page(old_page
, 0);
911 static int f2fs_rename2(struct inode
*old_dir
, struct dentry
*old_dentry
,
912 struct inode
*new_dir
, struct dentry
*new_dentry
,
915 if (flags
& ~(RENAME_NOREPLACE
| RENAME_EXCHANGE
| RENAME_WHITEOUT
))
918 if (flags
& RENAME_EXCHANGE
) {
919 return f2fs_cross_rename(old_dir
, old_dentry
,
920 new_dir
, new_dentry
);
923 * VFS has already handled the new dentry existence case,
924 * here, we just deal with "RENAME_NOREPLACE" as regular rename.
926 return f2fs_rename(old_dir
, old_dentry
, new_dir
, new_dentry
, flags
);
929 #ifdef CONFIG_F2FS_FS_ENCRYPTION
930 static const char *f2fs_encrypted_get_link(struct dentry
*dentry
,
932 struct delayed_call
*done
)
934 struct page
*cpage
= NULL
;
935 char *caddr
, *paddr
= NULL
;
936 struct f2fs_str cstr
;
937 struct f2fs_str pstr
= FSTR_INIT(NULL
, 0);
938 struct f2fs_encrypted_symlink_data
*sd
;
939 loff_t size
= min_t(loff_t
, i_size_read(inode
), PAGE_SIZE
- 1);
940 u32 max_size
= inode
->i_sb
->s_blocksize
;
944 return ERR_PTR(-ECHILD
);
946 res
= f2fs_get_encryption_info(inode
);
950 cpage
= read_mapping_page(inode
->i_mapping
, 0, NULL
);
952 return ERR_CAST(cpage
);
953 caddr
= page_address(cpage
);
956 /* Symlink is encrypted */
957 sd
= (struct f2fs_encrypted_symlink_data
*)caddr
;
958 cstr
.len
= le16_to_cpu(sd
->len
);
959 cstr
.name
= kmalloc(cstr
.len
, GFP_NOFS
);
964 memcpy(cstr
.name
, sd
->encrypted_path
, cstr
.len
);
966 /* this is broken symlink case */
967 if (cstr
.name
[0] == 0 && cstr
.len
== 0) {
972 if ((cstr
.len
+ sizeof(struct f2fs_encrypted_symlink_data
) - 1) >
974 /* Symlink data on the disk is corrupted */
978 res
= f2fs_fname_crypto_alloc_buffer(inode
, cstr
.len
, &pstr
);
982 res
= f2fs_fname_disk_to_usr(inode
, NULL
, &cstr
, &pstr
);
990 /* Null-terminate the name */
993 page_cache_release(cpage
);
994 set_delayed_call(done
, kfree_link
, paddr
);
998 f2fs_fname_crypto_free_buffer(&pstr
);
999 page_cache_release(cpage
);
1000 return ERR_PTR(res
);
1003 const struct inode_operations f2fs_encrypted_symlink_inode_operations
= {
1004 .readlink
= generic_readlink
,
1005 .get_link
= f2fs_encrypted_get_link
,
1006 .getattr
= f2fs_getattr
,
1007 .setattr
= f2fs_setattr
,
1008 .setxattr
= generic_setxattr
,
1009 .getxattr
= generic_getxattr
,
1010 .listxattr
= f2fs_listxattr
,
1011 .removexattr
= generic_removexattr
,
1015 const struct inode_operations f2fs_dir_inode_operations
= {
1016 .create
= f2fs_create
,
1017 .lookup
= f2fs_lookup
,
1019 .unlink
= f2fs_unlink
,
1020 .symlink
= f2fs_symlink
,
1021 .mkdir
= f2fs_mkdir
,
1022 .rmdir
= f2fs_rmdir
,
1023 .mknod
= f2fs_mknod
,
1024 .rename2
= f2fs_rename2
,
1025 .tmpfile
= f2fs_tmpfile
,
1026 .getattr
= f2fs_getattr
,
1027 .setattr
= f2fs_setattr
,
1028 .get_acl
= f2fs_get_acl
,
1029 .set_acl
= f2fs_set_acl
,
1030 #ifdef CONFIG_F2FS_FS_XATTR
1031 .setxattr
= generic_setxattr
,
1032 .getxattr
= generic_getxattr
,
1033 .listxattr
= f2fs_listxattr
,
1034 .removexattr
= generic_removexattr
,
1038 const struct inode_operations f2fs_symlink_inode_operations
= {
1039 .readlink
= generic_readlink
,
1040 .get_link
= f2fs_get_link
,
1041 .getattr
= f2fs_getattr
,
1042 .setattr
= f2fs_setattr
,
1043 #ifdef CONFIG_F2FS_FS_XATTR
1044 .setxattr
= generic_setxattr
,
1045 .getxattr
= generic_getxattr
,
1046 .listxattr
= f2fs_listxattr
,
1047 .removexattr
= generic_removexattr
,
1051 const struct inode_operations f2fs_special_inode_operations
= {
1052 .getattr
= f2fs_getattr
,
1053 .setattr
= f2fs_setattr
,
1054 .get_acl
= f2fs_get_acl
,
1055 .set_acl
= f2fs_set_acl
,
1056 #ifdef CONFIG_F2FS_FS_XATTR
1057 .setxattr
= generic_setxattr
,
1058 .getxattr
= generic_getxattr
,
1059 .listxattr
= f2fs_listxattr
,
1060 .removexattr
= generic_removexattr
,