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_new(dentry
, inode
);
156 f2fs_sync_fs(sbi
->sb
, 1);
159 handle_failed_inode(inode
);
163 static int f2fs_link(struct dentry
*old_dentry
, struct inode
*dir
,
164 struct dentry
*dentry
)
166 struct inode
*inode
= d_inode(old_dentry
);
167 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
170 if (f2fs_encrypted_inode(dir
) &&
171 !f2fs_is_child_context_consistent_with_parent(dir
, inode
))
174 f2fs_balance_fs(sbi
);
176 inode
->i_ctime
= CURRENT_TIME
;
179 set_inode_flag(F2FS_I(inode
), FI_INC_LINK
);
181 err
= f2fs_add_link(dentry
, inode
);
186 d_instantiate(dentry
, inode
);
189 f2fs_sync_fs(sbi
->sb
, 1);
192 clear_inode_flag(F2FS_I(inode
), FI_INC_LINK
);
198 struct dentry
*f2fs_get_parent(struct dentry
*child
)
200 struct qstr dotdot
= QSTR_INIT("..", 2);
201 unsigned long ino
= f2fs_inode_by_name(d_inode(child
), &dotdot
);
203 return ERR_PTR(-ENOENT
);
204 return d_obtain_alias(f2fs_iget(d_inode(child
)->i_sb
, ino
));
207 static int __recover_dot_dentries(struct inode
*dir
, nid_t pino
)
209 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
210 struct qstr dot
= QSTR_INIT(".", 1);
211 struct qstr dotdot
= QSTR_INIT("..", 2);
212 struct f2fs_dir_entry
*de
;
218 de
= f2fs_find_entry(dir
, &dot
, &page
);
220 f2fs_dentry_kunmap(dir
, page
);
221 f2fs_put_page(page
, 0);
223 err
= __f2fs_add_link(dir
, &dot
, NULL
, dir
->i_ino
, S_IFDIR
);
228 de
= f2fs_find_entry(dir
, &dotdot
, &page
);
230 f2fs_dentry_kunmap(dir
, page
);
231 f2fs_put_page(page
, 0);
233 err
= __f2fs_add_link(dir
, &dotdot
, NULL
, pino
, S_IFDIR
);
237 clear_inode_flag(F2FS_I(dir
), FI_INLINE_DOTS
);
238 mark_inode_dirty(dir
);
245 static struct dentry
*f2fs_lookup(struct inode
*dir
, struct dentry
*dentry
,
248 struct inode
*inode
= NULL
;
249 struct f2fs_dir_entry
*de
;
254 if (dentry
->d_name
.len
> F2FS_NAME_LEN
)
255 return ERR_PTR(-ENAMETOOLONG
);
257 de
= f2fs_find_entry(dir
, &dentry
->d_name
, &page
);
259 return d_splice_alias(inode
, dentry
);
261 ino
= le32_to_cpu(de
->ino
);
262 f2fs_dentry_kunmap(dir
, page
);
263 f2fs_put_page(page
, 0);
265 inode
= f2fs_iget(dir
->i_sb
, ino
);
267 return ERR_CAST(inode
);
269 if (f2fs_has_inline_dots(inode
)) {
270 err
= __recover_dot_dentries(inode
, dir
->i_ino
);
274 return d_splice_alias(inode
, dentry
);
281 static int f2fs_unlink(struct inode
*dir
, struct dentry
*dentry
)
283 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
284 struct inode
*inode
= d_inode(dentry
);
285 struct f2fs_dir_entry
*de
;
289 trace_f2fs_unlink_enter(dir
, dentry
);
290 f2fs_balance_fs(sbi
);
292 de
= f2fs_find_entry(dir
, &dentry
->d_name
, &page
);
297 err
= acquire_orphan_inode(sbi
);
300 f2fs_dentry_kunmap(dir
, page
);
301 f2fs_put_page(page
, 0);
304 f2fs_delete_entry(de
, page
, dir
, inode
);
307 /* In order to evict this inode, we set it dirty */
308 mark_inode_dirty(inode
);
311 f2fs_sync_fs(sbi
->sb
, 1);
313 trace_f2fs_unlink_exit(inode
, err
);
317 static const char *f2fs_follow_link(struct dentry
*dentry
, void **cookie
)
319 const char *link
= page_follow_link_light(dentry
, cookie
);
320 if (!IS_ERR(link
) && !*link
) {
321 /* this is broken symlink case */
322 page_put_link(NULL
, *cookie
);
323 link
= ERR_PTR(-ENOENT
);
328 static int f2fs_symlink(struct inode
*dir
, struct dentry
*dentry
,
331 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
333 size_t len
= strlen(symname
);
336 struct f2fs_str disk_link
= FSTR_INIT(NULL
, 0);
337 struct f2fs_encrypted_symlink_data
*sd
= NULL
;
340 if (len
> dir
->i_sb
->s_blocksize
)
341 return -ENAMETOOLONG
;
343 f2fs_balance_fs(sbi
);
345 inode
= f2fs_new_inode(dir
, S_IFLNK
| S_IRWXUGO
);
347 return PTR_ERR(inode
);
349 if (f2fs_encrypted_inode(inode
))
350 inode
->i_op
= &f2fs_encrypted_symlink_inode_operations
;
352 inode
->i_op
= &f2fs_symlink_inode_operations
;
353 inode_nohighmem(inode
);
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_new(dentry
, inode
);
404 * Let's flush symlink data in order to avoid broken symlink as much as
405 * possible. Nevertheless, fsyncing is the best way, but there is no
406 * way to get a file descriptor in order to flush that.
408 * Note that, it needs to do dir->fsync to make this recoverable.
409 * If the symlink path is stored into inline_data, there is no
410 * performance regression.
413 filemap_write_and_wait_range(inode
->i_mapping
, 0, p_len
- 1);
416 f2fs_sync_fs(sbi
->sb
, 1);
418 f2fs_unlink(dir
, dentry
);
422 f2fs_fname_crypto_free_buffer(&disk_link
);
425 handle_failed_inode(inode
);
429 static int f2fs_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
431 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
435 f2fs_balance_fs(sbi
);
437 inode
= f2fs_new_inode(dir
, S_IFDIR
| mode
);
439 return PTR_ERR(inode
);
441 inode
->i_op
= &f2fs_dir_inode_operations
;
442 inode
->i_fop
= &f2fs_dir_operations
;
443 inode
->i_mapping
->a_ops
= &f2fs_dblock_aops
;
444 mapping_set_gfp_mask(inode
->i_mapping
, GFP_F2FS_HIGH_ZERO
);
446 set_inode_flag(F2FS_I(inode
), FI_INC_LINK
);
448 err
= f2fs_add_link(dentry
, inode
);
453 alloc_nid_done(sbi
, inode
->i_ino
);
455 d_instantiate_new(dentry
, inode
);
458 f2fs_sync_fs(sbi
->sb
, 1);
462 clear_inode_flag(F2FS_I(inode
), FI_INC_LINK
);
463 handle_failed_inode(inode
);
467 static int f2fs_rmdir(struct inode
*dir
, struct dentry
*dentry
)
469 struct inode
*inode
= d_inode(dentry
);
470 if (f2fs_empty_dir(inode
))
471 return f2fs_unlink(dir
, dentry
);
475 static int f2fs_mknod(struct inode
*dir
, struct dentry
*dentry
,
476 umode_t mode
, dev_t rdev
)
478 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
482 f2fs_balance_fs(sbi
);
484 inode
= f2fs_new_inode(dir
, mode
);
486 return PTR_ERR(inode
);
488 init_special_inode(inode
, inode
->i_mode
, rdev
);
489 inode
->i_op
= &f2fs_special_inode_operations
;
492 err
= f2fs_add_link(dentry
, inode
);
497 alloc_nid_done(sbi
, inode
->i_ino
);
499 d_instantiate_new(dentry
, inode
);
502 f2fs_sync_fs(sbi
->sb
, 1);
505 handle_failed_inode(inode
);
509 static int __f2fs_tmpfile(struct inode
*dir
, struct dentry
*dentry
,
510 umode_t mode
, struct inode
**whiteout
)
512 struct f2fs_sb_info
*sbi
= F2FS_I_SB(dir
);
517 f2fs_balance_fs(sbi
);
519 inode
= f2fs_new_inode(dir
, mode
);
521 return PTR_ERR(inode
);
524 init_special_inode(inode
, inode
->i_mode
, WHITEOUT_DEV
);
525 inode
->i_op
= &f2fs_special_inode_operations
;
527 inode
->i_op
= &f2fs_file_inode_operations
;
528 inode
->i_fop
= &f2fs_file_operations
;
529 inode
->i_mapping
->a_ops
= &f2fs_dblock_aops
;
533 err
= acquire_orphan_inode(sbi
);
537 err
= f2fs_do_tmpfile(inode
, dir
);
542 * add this non-linked tmpfile to orphan list, in this way we could
543 * remove all unused data of tmpfile after abnormal power-off.
545 add_orphan_inode(sbi
, inode
->i_ino
);
548 alloc_nid_done(sbi
, inode
->i_ino
);
551 inode_dec_link_count(inode
);
554 d_tmpfile(dentry
, inode
);
556 unlock_new_inode(inode
);
560 release_orphan_inode(sbi
);
562 handle_failed_inode(inode
);
566 static int f2fs_tmpfile(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
568 if (f2fs_encrypted_inode(dir
)) {
569 int err
= f2fs_get_encryption_info(dir
);
574 return __f2fs_tmpfile(dir
, dentry
, mode
, NULL
);
577 static int f2fs_create_whiteout(struct inode
*dir
, struct inode
**whiteout
)
579 return __f2fs_tmpfile(dir
, NULL
, S_IFCHR
| WHITEOUT_MODE
, whiteout
);
582 static int f2fs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
583 struct inode
*new_dir
, struct dentry
*new_dentry
,
586 struct f2fs_sb_info
*sbi
= F2FS_I_SB(old_dir
);
587 struct inode
*old_inode
= d_inode(old_dentry
);
588 struct inode
*new_inode
= d_inode(new_dentry
);
589 struct inode
*whiteout
= NULL
;
590 struct page
*old_dir_page
;
591 struct page
*old_page
, *new_page
= NULL
;
592 struct f2fs_dir_entry
*old_dir_entry
= NULL
;
593 struct f2fs_dir_entry
*old_entry
;
594 struct f2fs_dir_entry
*new_entry
;
597 if ((old_dir
!= new_dir
) && f2fs_encrypted_inode(new_dir
) &&
598 !f2fs_is_child_context_consistent_with_parent(new_dir
,
604 f2fs_balance_fs(sbi
);
606 old_entry
= f2fs_find_entry(old_dir
, &old_dentry
->d_name
, &old_page
);
610 if (S_ISDIR(old_inode
->i_mode
)) {
612 old_dir_entry
= f2fs_parent_dir(old_inode
, &old_dir_page
);
617 if (flags
& RENAME_WHITEOUT
) {
618 err
= f2fs_create_whiteout(old_dir
, &whiteout
);
626 if (old_dir_entry
&& !f2fs_empty_dir(new_inode
))
630 new_entry
= f2fs_find_entry(new_dir
, &new_dentry
->d_name
,
637 err
= acquire_orphan_inode(sbi
);
641 if (update_dent_inode(old_inode
, new_inode
,
642 &new_dentry
->d_name
)) {
643 release_orphan_inode(sbi
);
647 f2fs_set_link(new_dir
, new_entry
, new_page
, old_inode
);
649 new_inode
->i_ctime
= CURRENT_TIME
;
650 down_write(&F2FS_I(new_inode
)->i_sem
);
652 drop_nlink(new_inode
);
653 drop_nlink(new_inode
);
654 up_write(&F2FS_I(new_inode
)->i_sem
);
656 mark_inode_dirty(new_inode
);
658 if (!new_inode
->i_nlink
)
659 add_orphan_inode(sbi
, new_inode
->i_ino
);
661 release_orphan_inode(sbi
);
663 update_inode_page(old_inode
);
664 update_inode_page(new_inode
);
668 err
= f2fs_add_link(new_dentry
, old_inode
);
676 update_inode_page(new_dir
);
680 down_write(&F2FS_I(old_inode
)->i_sem
);
681 file_lost_pino(old_inode
);
682 if (new_inode
&& file_enc_name(new_inode
))
683 file_set_enc_name(old_inode
);
684 up_write(&F2FS_I(old_inode
)->i_sem
);
686 old_inode
->i_ctime
= CURRENT_TIME
;
687 mark_inode_dirty(old_inode
);
689 f2fs_delete_entry(old_entry
, old_page
, old_dir
, NULL
);
692 whiteout
->i_state
|= I_LINKABLE
;
693 set_inode_flag(F2FS_I(whiteout
), FI_INC_LINK
);
694 err
= f2fs_add_link(old_dentry
, whiteout
);
697 whiteout
->i_state
&= ~I_LINKABLE
;
702 if (old_dir
!= new_dir
&& !whiteout
) {
703 f2fs_set_link(old_inode
, old_dir_entry
,
704 old_dir_page
, new_dir
);
705 update_inode_page(old_inode
);
707 f2fs_dentry_kunmap(old_inode
, old_dir_page
);
708 f2fs_put_page(old_dir_page
, 0);
711 mark_inode_dirty(old_dir
);
712 update_inode_page(old_dir
);
717 if (IS_DIRSYNC(old_dir
) || IS_DIRSYNC(new_dir
))
718 f2fs_sync_fs(sbi
->sb
, 1);
724 f2fs_dentry_kunmap(new_dir
, new_page
);
725 f2fs_put_page(new_page
, 0);
732 f2fs_dentry_kunmap(old_inode
, old_dir_page
);
733 f2fs_put_page(old_dir_page
, 0);
736 f2fs_dentry_kunmap(old_dir
, old_page
);
737 f2fs_put_page(old_page
, 0);
742 static int f2fs_cross_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
743 struct inode
*new_dir
, struct dentry
*new_dentry
)
745 struct f2fs_sb_info
*sbi
= F2FS_I_SB(old_dir
);
746 struct inode
*old_inode
= d_inode(old_dentry
);
747 struct inode
*new_inode
= d_inode(new_dentry
);
748 struct page
*old_dir_page
, *new_dir_page
;
749 struct page
*old_page
, *new_page
;
750 struct f2fs_dir_entry
*old_dir_entry
= NULL
, *new_dir_entry
= NULL
;
751 struct f2fs_dir_entry
*old_entry
, *new_entry
;
752 int old_nlink
= 0, new_nlink
= 0;
755 if ((f2fs_encrypted_inode(old_dir
) || f2fs_encrypted_inode(new_dir
)) &&
756 (old_dir
!= new_dir
) &&
757 (!f2fs_is_child_context_consistent_with_parent(new_dir
,
759 !f2fs_is_child_context_consistent_with_parent(old_dir
,
763 f2fs_balance_fs(sbi
);
765 old_entry
= f2fs_find_entry(old_dir
, &old_dentry
->d_name
, &old_page
);
769 new_entry
= f2fs_find_entry(new_dir
, &new_dentry
->d_name
, &new_page
);
773 /* prepare for updating ".." directory entry info later */
774 if (old_dir
!= new_dir
) {
775 if (S_ISDIR(old_inode
->i_mode
)) {
777 old_dir_entry
= f2fs_parent_dir(old_inode
,
783 if (S_ISDIR(new_inode
->i_mode
)) {
785 new_dir_entry
= f2fs_parent_dir(new_inode
,
793 * If cross rename between file and directory those are not
794 * in the same directory, we will inc nlink of file's parent
795 * later, so we should check upper boundary of its nlink.
797 if ((!old_dir_entry
|| !new_dir_entry
) &&
798 old_dir_entry
!= new_dir_entry
) {
799 old_nlink
= old_dir_entry
? -1 : 1;
800 new_nlink
= -old_nlink
;
802 if ((old_nlink
> 0 && old_inode
->i_nlink
>= F2FS_LINK_MAX
) ||
803 (new_nlink
> 0 && new_inode
->i_nlink
>= F2FS_LINK_MAX
))
809 err
= update_dent_inode(old_inode
, new_inode
, &new_dentry
->d_name
);
812 if (file_enc_name(new_inode
))
813 file_set_enc_name(old_inode
);
815 err
= update_dent_inode(new_inode
, old_inode
, &old_dentry
->d_name
);
818 if (file_enc_name(old_inode
))
819 file_set_enc_name(new_inode
);
821 /* update ".." directory entry info of old dentry */
823 f2fs_set_link(old_inode
, old_dir_entry
, old_dir_page
, new_dir
);
825 /* update ".." directory entry info of new dentry */
827 f2fs_set_link(new_inode
, new_dir_entry
, new_dir_page
, old_dir
);
829 /* update directory entry info of old dir inode */
830 f2fs_set_link(old_dir
, old_entry
, old_page
, new_inode
);
832 down_write(&F2FS_I(old_inode
)->i_sem
);
833 file_lost_pino(old_inode
);
834 up_write(&F2FS_I(old_inode
)->i_sem
);
836 update_inode_page(old_inode
);
838 old_dir
->i_ctime
= CURRENT_TIME
;
840 down_write(&F2FS_I(old_dir
)->i_sem
);
845 up_write(&F2FS_I(old_dir
)->i_sem
);
847 mark_inode_dirty(old_dir
);
848 update_inode_page(old_dir
);
850 /* update directory entry info of new dir inode */
851 f2fs_set_link(new_dir
, new_entry
, new_page
, old_inode
);
853 down_write(&F2FS_I(new_inode
)->i_sem
);
854 file_lost_pino(new_inode
);
855 up_write(&F2FS_I(new_inode
)->i_sem
);
857 update_inode_page(new_inode
);
859 new_dir
->i_ctime
= CURRENT_TIME
;
861 down_write(&F2FS_I(new_dir
)->i_sem
);
866 up_write(&F2FS_I(new_dir
)->i_sem
);
868 mark_inode_dirty(new_dir
);
869 update_inode_page(new_dir
);
873 if (IS_DIRSYNC(old_dir
) || IS_DIRSYNC(new_dir
))
874 f2fs_sync_fs(sbi
->sb
, 1);
878 * Still we may fail to recover name info of f2fs_inode here
879 * Drop it, once its name is set as encrypted
881 update_dent_inode(old_inode
, old_inode
, &old_dentry
->d_name
);
886 f2fs_dentry_kunmap(new_inode
, new_dir_page
);
887 f2fs_put_page(new_dir_page
, 0);
891 f2fs_dentry_kunmap(old_inode
, old_dir_page
);
892 f2fs_put_page(old_dir_page
, 0);
895 f2fs_dentry_kunmap(new_dir
, new_page
);
896 f2fs_put_page(new_page
, 0);
898 f2fs_dentry_kunmap(old_dir
, old_page
);
899 f2fs_put_page(old_page
, 0);
904 static int f2fs_rename2(struct inode
*old_dir
, struct dentry
*old_dentry
,
905 struct inode
*new_dir
, struct dentry
*new_dentry
,
908 if (flags
& ~(RENAME_NOREPLACE
| RENAME_EXCHANGE
| RENAME_WHITEOUT
))
911 if (flags
& RENAME_EXCHANGE
) {
912 return f2fs_cross_rename(old_dir
, old_dentry
,
913 new_dir
, new_dentry
);
916 * VFS has already handled the new dentry existence case,
917 * here, we just deal with "RENAME_NOREPLACE" as regular rename.
919 return f2fs_rename(old_dir
, old_dentry
, new_dir
, new_dentry
, flags
);
922 #ifdef CONFIG_F2FS_FS_ENCRYPTION
923 static const char *f2fs_encrypted_follow_link(struct dentry
*dentry
, void **cookie
)
925 struct page
*cpage
= NULL
;
926 char *caddr
, *paddr
= NULL
;
927 struct f2fs_str cstr
;
928 struct f2fs_str pstr
= FSTR_INIT(NULL
, 0);
929 struct inode
*inode
= d_inode(dentry
);
930 struct f2fs_encrypted_symlink_data
*sd
;
931 loff_t size
= min_t(loff_t
, i_size_read(inode
), PAGE_SIZE
- 1);
932 u32 max_size
= inode
->i_sb
->s_blocksize
;
935 res
= f2fs_get_encryption_info(inode
);
939 cpage
= read_mapping_page(inode
->i_mapping
, 0, NULL
);
941 return ERR_CAST(cpage
);
942 caddr
= page_address(cpage
);
945 /* Symlink is encrypted */
946 sd
= (struct f2fs_encrypted_symlink_data
*)caddr
;
947 cstr
.len
= le16_to_cpu(sd
->len
);
948 cstr
.name
= kmalloc(cstr
.len
, GFP_NOFS
);
953 memcpy(cstr
.name
, sd
->encrypted_path
, cstr
.len
);
955 /* this is broken symlink case */
956 if (cstr
.name
[0] == 0 && cstr
.len
== 0) {
961 if ((cstr
.len
+ sizeof(struct f2fs_encrypted_symlink_data
) - 1) >
963 /* Symlink data on the disk is corrupted */
967 res
= f2fs_fname_crypto_alloc_buffer(inode
, cstr
.len
, &pstr
);
971 res
= f2fs_fname_disk_to_usr(inode
, NULL
, &cstr
, &pstr
);
979 /* Null-terminate the name */
982 page_cache_release(cpage
);
983 return *cookie
= paddr
;
986 f2fs_fname_crypto_free_buffer(&pstr
);
987 page_cache_release(cpage
);
991 const struct inode_operations f2fs_encrypted_symlink_inode_operations
= {
992 .readlink
= generic_readlink
,
993 .follow_link
= f2fs_encrypted_follow_link
,
994 .put_link
= kfree_put_link
,
995 .getattr
= f2fs_getattr
,
996 .setattr
= f2fs_setattr
,
997 .setxattr
= generic_setxattr
,
998 .getxattr
= generic_getxattr
,
999 .listxattr
= f2fs_listxattr
,
1000 .removexattr
= generic_removexattr
,
1004 const struct inode_operations f2fs_dir_inode_operations
= {
1005 .create
= f2fs_create
,
1006 .lookup
= f2fs_lookup
,
1008 .unlink
= f2fs_unlink
,
1009 .symlink
= f2fs_symlink
,
1010 .mkdir
= f2fs_mkdir
,
1011 .rmdir
= f2fs_rmdir
,
1012 .mknod
= f2fs_mknod
,
1013 .rename2
= f2fs_rename2
,
1014 .tmpfile
= f2fs_tmpfile
,
1015 .getattr
= f2fs_getattr
,
1016 .setattr
= f2fs_setattr
,
1017 .get_acl
= f2fs_get_acl
,
1018 .set_acl
= f2fs_set_acl
,
1019 #ifdef CONFIG_F2FS_FS_XATTR
1020 .setxattr
= generic_setxattr
,
1021 .getxattr
= generic_getxattr
,
1022 .listxattr
= f2fs_listxattr
,
1023 .removexattr
= generic_removexattr
,
1027 const struct inode_operations f2fs_symlink_inode_operations
= {
1028 .readlink
= generic_readlink
,
1029 .follow_link
= f2fs_follow_link
,
1030 .put_link
= page_put_link
,
1031 .getattr
= f2fs_getattr
,
1032 .setattr
= f2fs_setattr
,
1033 #ifdef CONFIG_F2FS_FS_XATTR
1034 .setxattr
= generic_setxattr
,
1035 .getxattr
= generic_getxattr
,
1036 .listxattr
= f2fs_listxattr
,
1037 .removexattr
= generic_removexattr
,
1041 const struct inode_operations f2fs_special_inode_operations
= {
1042 .getattr
= f2fs_getattr
,
1043 .setattr
= f2fs_setattr
,
1044 .get_acl
= f2fs_get_acl
,
1045 .set_acl
= f2fs_set_acl
,
1046 #ifdef CONFIG_F2FS_FS_XATTR
1047 .setxattr
= generic_setxattr
,
1048 .getxattr
= generic_getxattr
,
1049 .listxattr
= f2fs_listxattr
,
1050 .removexattr
= generic_removexattr
,