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
->i_mapping
->a_ops
= &f2fs_dblock_aops
;
357 err
= f2fs_add_link(dentry
, inode
);
361 alloc_nid_done(sbi
, inode
->i_ino
);
363 if (f2fs_encrypted_inode(dir
)) {
364 struct qstr istr
= QSTR_INIT(symname
, len
);
366 err
= f2fs_get_encryption_info(inode
);
370 err
= f2fs_fname_crypto_alloc_buffer(inode
, len
, &disk_link
);
374 err
= f2fs_fname_usr_to_disk(inode
, &istr
, &disk_link
);
378 p_len
= encrypted_symlink_data_len(disk_link
.len
) + 1;
380 if (p_len
> dir
->i_sb
->s_blocksize
) {
385 sd
= kzalloc(p_len
, GFP_NOFS
);
390 memcpy(sd
->encrypted_path
, disk_link
.name
, disk_link
.len
);
391 sd
->len
= cpu_to_le16(disk_link
.len
);
395 p_str
= (char *)symname
;
398 err
= page_symlink(inode
, p_str
, p_len
);
401 d_instantiate(dentry
, inode
);
402 unlock_new_inode(inode
);
405 * Let's flush symlink data in order to avoid broken symlink as much as
406 * possible. Nevertheless, fsyncing is the best way, but there is no
407 * way to get a file descriptor in order to flush that.
409 * Note that, it needs to do dir->fsync to make this recoverable.
410 * If the symlink path is stored into inline_data, there is no
411 * performance regression.
414 filemap_write_and_wait_range(inode
->i_mapping
, 0, p_len
- 1);
417 f2fs_sync_fs(sbi
->sb
, 1);
419 f2fs_unlink(dir
, dentry
);
423 f2fs_fname_crypto_free_buffer(&disk_link
);
426 handle_failed_inode(inode
);
430 static int f2fs_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
432 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
436 f2fs_balance_fs(sbi
);
438 inode
= f2fs_new_inode(dir
, S_IFDIR
| mode
);
440 return PTR_ERR(inode
);
442 inode
->i_op
= &f2fs_dir_inode_operations
;
443 inode
->i_fop
= &f2fs_dir_operations
;
444 inode
->i_mapping
->a_ops
= &f2fs_dblock_aops
;
445 mapping_set_gfp_mask(inode
->i_mapping
, GFP_F2FS_HIGH_ZERO
);
447 set_inode_flag(F2FS_I(inode
), FI_INC_LINK
);
449 err
= f2fs_add_link(dentry
, inode
);
454 alloc_nid_done(sbi
, inode
->i_ino
);
456 d_instantiate(dentry
, inode
);
457 unlock_new_inode(inode
);
460 f2fs_sync_fs(sbi
->sb
, 1);
464 clear_inode_flag(F2FS_I(inode
), FI_INC_LINK
);
465 handle_failed_inode(inode
);
469 static int f2fs_rmdir(struct inode
*dir
, struct dentry
*dentry
)
471 struct inode
*inode
= d_inode(dentry
);
472 if (f2fs_empty_dir(inode
))
473 return f2fs_unlink(dir
, dentry
);
477 static int f2fs_mknod(struct inode
*dir
, struct dentry
*dentry
,
478 umode_t mode
, dev_t rdev
)
480 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
484 f2fs_balance_fs(sbi
);
486 inode
= f2fs_new_inode(dir
, mode
);
488 return PTR_ERR(inode
);
490 init_special_inode(inode
, inode
->i_mode
, rdev
);
491 inode
->i_op
= &f2fs_special_inode_operations
;
494 err
= f2fs_add_link(dentry
, inode
);
499 alloc_nid_done(sbi
, inode
->i_ino
);
501 d_instantiate(dentry
, inode
);
502 unlock_new_inode(inode
);
505 f2fs_sync_fs(sbi
->sb
, 1);
508 handle_failed_inode(inode
);
512 static int __f2fs_tmpfile(struct inode
*dir
, struct dentry
*dentry
,
513 umode_t mode
, struct inode
**whiteout
)
515 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
520 f2fs_balance_fs(sbi
);
522 inode
= f2fs_new_inode(dir
, mode
);
524 return PTR_ERR(inode
);
527 init_special_inode(inode
, inode
->i_mode
, WHITEOUT_DEV
);
528 inode
->i_op
= &f2fs_special_inode_operations
;
530 inode
->i_op
= &f2fs_file_inode_operations
;
531 inode
->i_fop
= &f2fs_file_operations
;
532 inode
->i_mapping
->a_ops
= &f2fs_dblock_aops
;
536 err
= acquire_orphan_inode(sbi
);
540 err
= f2fs_do_tmpfile(inode
, dir
);
545 * add this non-linked tmpfile to orphan list, in this way we could
546 * remove all unused data of tmpfile after abnormal power-off.
548 add_orphan_inode(sbi
, inode
->i_ino
);
551 alloc_nid_done(sbi
, inode
->i_ino
);
554 inode_dec_link_count(inode
);
557 d_tmpfile(dentry
, inode
);
559 unlock_new_inode(inode
);
563 release_orphan_inode(sbi
);
565 handle_failed_inode(inode
);
569 static int f2fs_tmpfile(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
571 if (f2fs_encrypted_inode(dir
)) {
572 int err
= f2fs_get_encryption_info(dir
);
577 return __f2fs_tmpfile(dir
, dentry
, mode
, NULL
);
580 static int f2fs_create_whiteout(struct inode
*dir
, struct inode
**whiteout
)
582 return __f2fs_tmpfile(dir
, NULL
, S_IFCHR
| WHITEOUT_MODE
, whiteout
);
585 static int f2fs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
586 struct inode
*new_dir
, struct dentry
*new_dentry
,
589 struct f2fs_sb_info
*sbi
= F2FS_I_SB(old_dir
);
590 struct inode
*old_inode
= d_inode(old_dentry
);
591 struct inode
*new_inode
= d_inode(new_dentry
);
592 struct inode
*whiteout
= NULL
;
593 struct page
*old_dir_page
;
594 struct page
*old_page
, *new_page
= NULL
;
595 struct f2fs_dir_entry
*old_dir_entry
= NULL
;
596 struct f2fs_dir_entry
*old_entry
;
597 struct f2fs_dir_entry
*new_entry
;
600 if ((old_dir
!= new_dir
) && f2fs_encrypted_inode(new_dir
) &&
601 !f2fs_is_child_context_consistent_with_parent(new_dir
,
607 f2fs_balance_fs(sbi
);
609 old_entry
= f2fs_find_entry(old_dir
, &old_dentry
->d_name
, &old_page
);
613 if (S_ISDIR(old_inode
->i_mode
)) {
615 old_dir_entry
= f2fs_parent_dir(old_inode
, &old_dir_page
);
620 if (flags
& RENAME_WHITEOUT
) {
621 err
= f2fs_create_whiteout(old_dir
, &whiteout
);
629 if (old_dir_entry
&& !f2fs_empty_dir(new_inode
))
633 new_entry
= f2fs_find_entry(new_dir
, &new_dentry
->d_name
,
640 err
= acquire_orphan_inode(sbi
);
644 if (update_dent_inode(old_inode
, new_inode
,
645 &new_dentry
->d_name
)) {
646 release_orphan_inode(sbi
);
650 f2fs_set_link(new_dir
, new_entry
, new_page
, old_inode
);
652 new_inode
->i_ctime
= CURRENT_TIME
;
653 down_write(&F2FS_I(new_inode
)->i_sem
);
655 drop_nlink(new_inode
);
656 drop_nlink(new_inode
);
657 up_write(&F2FS_I(new_inode
)->i_sem
);
659 mark_inode_dirty(new_inode
);
661 if (!new_inode
->i_nlink
)
662 add_orphan_inode(sbi
, new_inode
->i_ino
);
664 release_orphan_inode(sbi
);
666 update_inode_page(old_inode
);
667 update_inode_page(new_inode
);
671 err
= f2fs_add_link(new_dentry
, old_inode
);
679 update_inode_page(new_dir
);
683 down_write(&F2FS_I(old_inode
)->i_sem
);
684 file_lost_pino(old_inode
);
685 if (new_inode
&& file_enc_name(new_inode
))
686 file_set_enc_name(old_inode
);
687 up_write(&F2FS_I(old_inode
)->i_sem
);
689 old_inode
->i_ctime
= CURRENT_TIME
;
690 mark_inode_dirty(old_inode
);
692 f2fs_delete_entry(old_entry
, old_page
, old_dir
, NULL
);
695 whiteout
->i_state
|= I_LINKABLE
;
696 set_inode_flag(F2FS_I(whiteout
), FI_INC_LINK
);
697 err
= f2fs_add_link(old_dentry
, whiteout
);
700 whiteout
->i_state
&= ~I_LINKABLE
;
705 if (old_dir
!= new_dir
&& !whiteout
) {
706 f2fs_set_link(old_inode
, old_dir_entry
,
707 old_dir_page
, new_dir
);
708 update_inode_page(old_inode
);
710 f2fs_dentry_kunmap(old_inode
, old_dir_page
);
711 f2fs_put_page(old_dir_page
, 0);
714 mark_inode_dirty(old_dir
);
715 update_inode_page(old_dir
);
720 if (IS_DIRSYNC(old_dir
) || IS_DIRSYNC(new_dir
))
721 f2fs_sync_fs(sbi
->sb
, 1);
727 f2fs_dentry_kunmap(new_dir
, new_page
);
728 f2fs_put_page(new_page
, 0);
735 f2fs_dentry_kunmap(old_inode
, old_dir_page
);
736 f2fs_put_page(old_dir_page
, 0);
739 f2fs_dentry_kunmap(old_dir
, old_page
);
740 f2fs_put_page(old_page
, 0);
745 static int f2fs_cross_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
746 struct inode
*new_dir
, struct dentry
*new_dentry
)
748 struct f2fs_sb_info
*sbi
= F2FS_I_SB(old_dir
);
749 struct inode
*old_inode
= d_inode(old_dentry
);
750 struct inode
*new_inode
= d_inode(new_dentry
);
751 struct page
*old_dir_page
, *new_dir_page
;
752 struct page
*old_page
, *new_page
;
753 struct f2fs_dir_entry
*old_dir_entry
= NULL
, *new_dir_entry
= NULL
;
754 struct f2fs_dir_entry
*old_entry
, *new_entry
;
755 int old_nlink
= 0, new_nlink
= 0;
758 if ((f2fs_encrypted_inode(old_dir
) || f2fs_encrypted_inode(new_dir
)) &&
759 (old_dir
!= new_dir
) &&
760 (!f2fs_is_child_context_consistent_with_parent(new_dir
,
762 !f2fs_is_child_context_consistent_with_parent(old_dir
,
766 f2fs_balance_fs(sbi
);
768 old_entry
= f2fs_find_entry(old_dir
, &old_dentry
->d_name
, &old_page
);
772 new_entry
= f2fs_find_entry(new_dir
, &new_dentry
->d_name
, &new_page
);
776 /* prepare for updating ".." directory entry info later */
777 if (old_dir
!= new_dir
) {
778 if (S_ISDIR(old_inode
->i_mode
)) {
780 old_dir_entry
= f2fs_parent_dir(old_inode
,
786 if (S_ISDIR(new_inode
->i_mode
)) {
788 new_dir_entry
= f2fs_parent_dir(new_inode
,
796 * If cross rename between file and directory those are not
797 * in the same directory, we will inc nlink of file's parent
798 * later, so we should check upper boundary of its nlink.
800 if ((!old_dir_entry
|| !new_dir_entry
) &&
801 old_dir_entry
!= new_dir_entry
) {
802 old_nlink
= old_dir_entry
? -1 : 1;
803 new_nlink
= -old_nlink
;
805 if ((old_nlink
> 0 && old_inode
->i_nlink
>= F2FS_LINK_MAX
) ||
806 (new_nlink
> 0 && new_inode
->i_nlink
>= F2FS_LINK_MAX
))
812 err
= update_dent_inode(old_inode
, new_inode
, &new_dentry
->d_name
);
815 if (file_enc_name(new_inode
))
816 file_set_enc_name(old_inode
);
818 err
= update_dent_inode(new_inode
, old_inode
, &old_dentry
->d_name
);
821 if (file_enc_name(old_inode
))
822 file_set_enc_name(new_inode
);
824 /* update ".." directory entry info of old dentry */
826 f2fs_set_link(old_inode
, old_dir_entry
, old_dir_page
, new_dir
);
828 /* update ".." directory entry info of new dentry */
830 f2fs_set_link(new_inode
, new_dir_entry
, new_dir_page
, old_dir
);
832 /* update directory entry info of old dir inode */
833 f2fs_set_link(old_dir
, old_entry
, old_page
, new_inode
);
835 down_write(&F2FS_I(old_inode
)->i_sem
);
836 file_lost_pino(old_inode
);
837 up_write(&F2FS_I(old_inode
)->i_sem
);
839 update_inode_page(old_inode
);
841 old_dir
->i_ctime
= CURRENT_TIME
;
843 down_write(&F2FS_I(old_dir
)->i_sem
);
848 up_write(&F2FS_I(old_dir
)->i_sem
);
850 mark_inode_dirty(old_dir
);
851 update_inode_page(old_dir
);
853 /* update directory entry info of new dir inode */
854 f2fs_set_link(new_dir
, new_entry
, new_page
, old_inode
);
856 down_write(&F2FS_I(new_inode
)->i_sem
);
857 file_lost_pino(new_inode
);
858 up_write(&F2FS_I(new_inode
)->i_sem
);
860 update_inode_page(new_inode
);
862 new_dir
->i_ctime
= CURRENT_TIME
;
864 down_write(&F2FS_I(new_dir
)->i_sem
);
869 up_write(&F2FS_I(new_dir
)->i_sem
);
871 mark_inode_dirty(new_dir
);
872 update_inode_page(new_dir
);
876 if (IS_DIRSYNC(old_dir
) || IS_DIRSYNC(new_dir
))
877 f2fs_sync_fs(sbi
->sb
, 1);
881 * Still we may fail to recover name info of f2fs_inode here
882 * Drop it, once its name is set as encrypted
884 update_dent_inode(old_inode
, old_inode
, &old_dentry
->d_name
);
889 f2fs_dentry_kunmap(new_inode
, new_dir_page
);
890 f2fs_put_page(new_dir_page
, 0);
894 f2fs_dentry_kunmap(old_inode
, old_dir_page
);
895 f2fs_put_page(old_dir_page
, 0);
898 f2fs_dentry_kunmap(new_dir
, new_page
);
899 f2fs_put_page(new_page
, 0);
901 f2fs_dentry_kunmap(old_dir
, old_page
);
902 f2fs_put_page(old_page
, 0);
907 static int f2fs_rename2(struct inode
*old_dir
, struct dentry
*old_dentry
,
908 struct inode
*new_dir
, struct dentry
*new_dentry
,
911 if (flags
& ~(RENAME_NOREPLACE
| RENAME_EXCHANGE
| RENAME_WHITEOUT
))
914 if (flags
& RENAME_EXCHANGE
) {
915 return f2fs_cross_rename(old_dir
, old_dentry
,
916 new_dir
, new_dentry
);
919 * VFS has already handled the new dentry existence case,
920 * here, we just deal with "RENAME_NOREPLACE" as regular rename.
922 return f2fs_rename(old_dir
, old_dentry
, new_dir
, new_dentry
, flags
);
925 #ifdef CONFIG_F2FS_FS_ENCRYPTION
926 static const char *f2fs_encrypted_follow_link(struct dentry
*dentry
, void **cookie
)
928 struct page
*cpage
= NULL
;
929 char *caddr
, *paddr
= NULL
;
930 struct f2fs_str cstr
;
931 struct f2fs_str pstr
= FSTR_INIT(NULL
, 0);
932 struct inode
*inode
= d_inode(dentry
);
933 struct f2fs_encrypted_symlink_data
*sd
;
934 loff_t size
= min_t(loff_t
, i_size_read(inode
), PAGE_SIZE
- 1);
935 u32 max_size
= inode
->i_sb
->s_blocksize
;
938 res
= f2fs_get_encryption_info(inode
);
942 cpage
= read_mapping_page(inode
->i_mapping
, 0, NULL
);
944 return ERR_CAST(cpage
);
948 /* Symlink is encrypted */
949 sd
= (struct f2fs_encrypted_symlink_data
*)caddr
;
950 cstr
.len
= le16_to_cpu(sd
->len
);
951 cstr
.name
= kmalloc(cstr
.len
, GFP_NOFS
);
956 memcpy(cstr
.name
, sd
->encrypted_path
, cstr
.len
);
958 /* this is broken symlink case */
959 if (cstr
.name
[0] == 0 && cstr
.len
== 0) {
964 if ((cstr
.len
+ sizeof(struct f2fs_encrypted_symlink_data
) - 1) >
966 /* Symlink data on the disk is corrupted */
970 res
= f2fs_fname_crypto_alloc_buffer(inode
, cstr
.len
, &pstr
);
974 res
= f2fs_fname_disk_to_usr(inode
, NULL
, &cstr
, &pstr
);
982 /* Null-terminate the name */
986 page_cache_release(cpage
);
987 return *cookie
= paddr
;
990 f2fs_fname_crypto_free_buffer(&pstr
);
992 page_cache_release(cpage
);
996 const struct inode_operations f2fs_encrypted_symlink_inode_operations
= {
997 .readlink
= generic_readlink
,
998 .follow_link
= f2fs_encrypted_follow_link
,
999 .put_link
= kfree_put_link
,
1000 .getattr
= f2fs_getattr
,
1001 .setattr
= f2fs_setattr
,
1002 .setxattr
= generic_setxattr
,
1003 .getxattr
= generic_getxattr
,
1004 .listxattr
= f2fs_listxattr
,
1005 .removexattr
= generic_removexattr
,
1009 const struct inode_operations f2fs_dir_inode_operations
= {
1010 .create
= f2fs_create
,
1011 .lookup
= f2fs_lookup
,
1013 .unlink
= f2fs_unlink
,
1014 .symlink
= f2fs_symlink
,
1015 .mkdir
= f2fs_mkdir
,
1016 .rmdir
= f2fs_rmdir
,
1017 .mknod
= f2fs_mknod
,
1018 .rename2
= f2fs_rename2
,
1019 .tmpfile
= f2fs_tmpfile
,
1020 .getattr
= f2fs_getattr
,
1021 .setattr
= f2fs_setattr
,
1022 .get_acl
= f2fs_get_acl
,
1023 .set_acl
= f2fs_set_acl
,
1024 #ifdef CONFIG_F2FS_FS_XATTR
1025 .setxattr
= generic_setxattr
,
1026 .getxattr
= generic_getxattr
,
1027 .listxattr
= f2fs_listxattr
,
1028 .removexattr
= generic_removexattr
,
1032 const struct inode_operations f2fs_symlink_inode_operations
= {
1033 .readlink
= generic_readlink
,
1034 .follow_link
= f2fs_follow_link
,
1035 .put_link
= page_put_link
,
1036 .getattr
= f2fs_getattr
,
1037 .setattr
= f2fs_setattr
,
1038 #ifdef CONFIG_F2FS_FS_XATTR
1039 .setxattr
= generic_setxattr
,
1040 .getxattr
= generic_getxattr
,
1041 .listxattr
= f2fs_listxattr
,
1042 .removexattr
= generic_removexattr
,
1046 const struct inode_operations f2fs_special_inode_operations
= {
1047 .getattr
= f2fs_getattr
,
1048 .setattr
= f2fs_setattr
,
1049 .get_acl
= f2fs_get_acl
,
1050 .set_acl
= f2fs_set_acl
,
1051 #ifdef CONFIG_F2FS_FS_XATTR
1052 .setxattr
= generic_setxattr
,
1053 .getxattr
= generic_getxattr
,
1054 .listxattr
= f2fs_listxattr
,
1055 .removexattr
= generic_removexattr
,