Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * fs/f2fs/namei.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *             http://www.samsung.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/f2fs_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/dcache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/quotaops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include "f2fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include "node.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include "segment.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include "acl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <trace/events/f2fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 	nid_t ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 	bool nid_free = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 	bool encrypt = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 	int xattr_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 	inode = new_inode(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 	if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 	f2fs_lock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 	if (!f2fs_alloc_nid(sbi, &ino)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 		f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 		err = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 	nid_free = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	inode_init_owner(inode, dir, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 	inode->i_ino = ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 	inode->i_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	F2FS_I(inode)->i_crtime = inode->i_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 	inode->i_generation = prandom_u32();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 		F2FS_I(inode)->i_current_depth = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	err = insert_inode_locked(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	if (f2fs_sb_has_project_quota(sbi) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 		(F2FS_I(dir)->i_flags & F2FS_PROJINHERIT_FL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 		F2FS_I(inode)->i_projid = F2FS_I(dir)->i_projid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 		F2FS_I(inode)->i_projid = make_kprojid(&init_user_ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 							F2FS_DEF_PROJID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	err = fscrypt_prepare_new_inode(dir, inode, &encrypt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 		goto fail_drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	err = dquot_initialize(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 		goto fail_drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	set_inode_flag(inode, FI_NEW_INODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	if (encrypt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 		f2fs_set_encrypted_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	if (f2fs_sb_has_extra_attr(sbi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 		set_inode_flag(inode, FI_EXTRA_ATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 		F2FS_I(inode)->i_extra_isize = F2FS_TOTAL_EXTRA_ATTR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	if (test_opt(sbi, INLINE_XATTR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 		set_inode_flag(inode, FI_INLINE_XATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 		set_inode_flag(inode, FI_INLINE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	if (f2fs_may_inline_dentry(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 		set_inode_flag(inode, FI_INLINE_DENTRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	if (f2fs_sb_has_flexible_inline_xattr(sbi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 		f2fs_bug_on(sbi, !f2fs_has_extra_attr(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 		if (f2fs_has_inline_xattr(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 			xattr_size = F2FS_OPTION(sbi).inline_xattr_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 		/* Otherwise, will be 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	} else if (f2fs_has_inline_xattr(inode) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 				f2fs_has_inline_dentry(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 		xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	F2FS_I(inode)->i_inline_xattr_size = xattr_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	f2fs_init_extent_tree(inode, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	stat_inc_inline_xattr(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	stat_inc_inline_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	stat_inc_inline_dir(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	F2FS_I(inode)->i_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 		f2fs_mask_flags(mode, F2FS_I(dir)->i_flags & F2FS_FL_INHERITED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 		F2FS_I(inode)->i_flags |= F2FS_INDEX_FL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	if (F2FS_I(inode)->i_flags & F2FS_PROJINHERIT_FL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 		set_inode_flag(inode, FI_PROJ_INHERIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	if (f2fs_sb_has_compression(sbi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 		/* Inherit the compression flag in directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 		if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 					f2fs_may_compress(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 			set_compress_context(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	f2fs_set_inode_flags(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	trace_f2fs_new_inode(inode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	trace_f2fs_new_inode(inode, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	make_bad_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	if (nid_free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 		set_inode_flag(inode, FI_FREE_NID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) fail_drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	trace_f2fs_new_inode(inode, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	dquot_drop(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	inode->i_flags |= S_NOQUOTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	if (nid_free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		set_inode_flag(inode, FI_FREE_NID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	clear_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) static inline int is_extension_exist(const unsigned char *s, const char *sub,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 						bool tmp_ext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	size_t slen = strlen(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	size_t sublen = strlen(sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	if (sublen == 1 && *sub == '*')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	 * filename format of multimedia file should be defined as:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	 * "filename + '.' + extension + (optional: '.' + temp extension)".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	if (slen < sublen + 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	if (!tmp_ext) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 		/* file has no temp extension */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 		if (s[slen - sublen - 1] != '.')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		return !strncasecmp(s + slen - sublen, sub, sublen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	for (i = 1; i < slen - sublen; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 		if (s[i] != '.')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		if (!strncasecmp(s + i + 1, sub, sublen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191)  * Set file's temperature for hot/cold data separation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 		const unsigned char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	int i, cold_count, hot_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	f2fs_down_read(&sbi->sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	cold_count = le32_to_cpu(sbi->raw_super->extension_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	hot_count = sbi->raw_super->hot_ext_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	for (i = 0; i < cold_count + hot_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 		if (is_extension_exist(name, extlist[i], true))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	f2fs_up_read(&sbi->sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	if (i == cold_count + hot_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	if (i < cold_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 		file_set_cold(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 		file_set_hot(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 							bool hot, bool set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	int hot_count = sbi->raw_super->hot_ext_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	int total_count = cold_count + hot_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	int start, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	if (set) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		if (total_count == F2FS_MAX_EXTENSION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		if (!hot && !cold_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		if (hot && !hot_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	if (hot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		start = cold_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		count = total_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 		start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 		count = cold_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	for (i = start; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		if (strcmp(name, extlist[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 		if (set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		memcpy(extlist[i], extlist[i + 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 				F2FS_EXTENSION_LEN * (total_count - i - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 		if (hot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 			sbi->raw_super->hot_ext_count = hot_count - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 			sbi->raw_super->extension_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 						cpu_to_le32(cold_count - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	if (!set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	if (hot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 		memcpy(extlist[count], name, strlen(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		sbi->raw_super->hot_ext_count = hot_count + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 		char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 		memcpy(buf, &extlist[cold_count],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 				F2FS_EXTENSION_LEN * hot_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 		memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 		memcpy(extlist[cold_count], name, strlen(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 		memcpy(&extlist[cold_count + 1], buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 				F2FS_EXTENSION_LEN * hot_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 		sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 						const unsigned char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	unsigned char (*ext)[F2FS_EXTENSION_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	unsigned int ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	int i, cold_count, hot_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	if (!f2fs_sb_has_compression(sbi) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 			is_inode_flag_set(inode, FI_COMPRESSED_FILE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 			F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 			!f2fs_may_compress(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	f2fs_down_read(&sbi->sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	cold_count = le32_to_cpu(sbi->raw_super->extension_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	hot_count = sbi->raw_super->hot_ext_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	for (i = cold_count; i < cold_count + hot_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		if (is_extension_exist(name, extlist[i], false)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 			f2fs_up_read(&sbi->sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	f2fs_up_read(&sbi->sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	ext = F2FS_OPTION(sbi).extensions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	for (i = 0; i < ext_cnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		if (!is_extension_exist(name, ext[i], false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		set_compress_context(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 						bool excl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	nid_t ino = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	if (unlikely(f2fs_cp_error(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	if (!f2fs_is_checkpoint_ready(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	err = dquot_initialize(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	inode = f2fs_new_inode(dir, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		return PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		set_file_temperature(sbi, inode, dentry->d_name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	set_compress_inode(sbi, inode, dentry->d_name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	inode->i_op = &f2fs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	inode->i_fop = &f2fs_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	inode->i_mapping->a_ops = &f2fs_dblock_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	ino = inode->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	f2fs_lock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	err = f2fs_add_link(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	f2fs_alloc_nid_done(sbi, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	d_instantiate_new(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	if (IS_DIRSYNC(dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 		f2fs_sync_fs(sbi->sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	f2fs_balance_fs(sbi, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	f2fs_handle_failed_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 		struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	struct inode *inode = d_inode(old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	if (unlikely(f2fs_cp_error(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	if (!f2fs_is_checkpoint_ready(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	err = fscrypt_prepare_link(old_dentry, dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	if (is_inode_flag_set(dir, FI_PROJ_INHERIT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 			(!projid_eq(F2FS_I(dir)->i_projid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 			F2FS_I(old_dentry->d_inode)->i_projid)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		return -EXDEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	err = dquot_initialize(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	f2fs_balance_fs(sbi, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	ihold(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	set_inode_flag(inode, FI_INC_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	f2fs_lock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	err = f2fs_add_link(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	if (IS_DIRSYNC(dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		f2fs_sync_fs(sbi->sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	clear_inode_flag(inode, FI_INC_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) struct dentry *f2fs_get_parent(struct dentry *child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	struct qstr dotdot = QSTR_INIT("..", 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	unsigned long ino = f2fs_inode_by_name(d_inode(child), &dotdot, &page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	if (!ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		if (IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 			return ERR_CAST(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 		return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	return d_obtain_alias(f2fs_iget(child->d_sb, ino));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) static int __recover_dot_dentries(struct inode *dir, nid_t pino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	struct qstr dot = QSTR_INIT(".", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	struct qstr dotdot = QSTR_INIT("..", 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	struct f2fs_dir_entry *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	if (f2fs_readonly(sbi->sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		f2fs_info(sbi, "skip recovering inline_dots inode (ino:%lu, pino:%u) in readonly mountpoint",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 			  dir->i_ino, pino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	err = dquot_initialize(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	f2fs_balance_fs(sbi, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	f2fs_lock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	de = f2fs_find_entry(dir, &dot, &page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	if (de) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		f2fs_put_page(page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	} else if (IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		err = PTR_ERR(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 		err = f2fs_do_add_link(dir, &dot, NULL, dir->i_ino, S_IFDIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	de = f2fs_find_entry(dir, &dotdot, &page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	if (de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 		f2fs_put_page(page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	else if (IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		err = PTR_ERR(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		err = f2fs_do_add_link(dir, &dotdot, NULL, pino, S_IFDIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		clear_inode_flag(dir, FI_INLINE_DOTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	struct f2fs_dir_entry *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	struct dentry *new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	nid_t ino = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	unsigned int root_ino = F2FS_ROOT_INO(F2FS_I_SB(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	struct f2fs_filename fname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	trace_f2fs_lookup_start(dir, dentry, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	if (dentry->d_name.len > F2FS_NAME_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		err = -ENAMETOOLONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	err = f2fs_prepare_lookup(dir, dentry, &fname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	generic_set_encrypted_ci_d_ops(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	if (err == -ENOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		goto out_splice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	de = __f2fs_find_entry(dir, &fname, &page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	f2fs_free_filename(&fname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	if (!de) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		if (IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 			err = PTR_ERR(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 		err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		goto out_splice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	ino = le32_to_cpu(de->ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	f2fs_put_page(page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	inode = f2fs_iget(dir->i_sb, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 		err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	if ((dir->i_ino == root_ino) && f2fs_has_inline_dots(dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 		err = __recover_dot_dentries(dir, root_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 			goto out_iput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	if (f2fs_has_inline_dots(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		err = __recover_dot_dentries(inode, dir->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 			goto out_iput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	if (IS_ENCRYPTED(dir) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	    (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	    !fscrypt_has_permitted_context(dir, inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		f2fs_warn(F2FS_I_SB(inode), "Inconsistent encryption contexts: %lu/%lu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 			  dir->i_ino, inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		err = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		goto out_iput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) out_splice:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) #ifdef CONFIG_UNICODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	if (!inode && IS_CASEFOLDED(dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 		/* Eventually we want to call d_add_ci(dentry, NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 		 * for negative dentries in the encoding case as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		 * well.  For now, prevent the negative dentry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 		 * from being cached.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 		trace_f2fs_lookup_end(dir, dentry, ino, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	new = d_splice_alias(inode, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	err = PTR_ERR_OR_ZERO(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	trace_f2fs_lookup_end(dir, dentry, ino, !new ? -ENOENT : err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	return new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) out_iput:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	trace_f2fs_lookup_end(dir, dentry, ino, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	struct f2fs_dir_entry *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	trace_f2fs_unlink_enter(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	if (unlikely(f2fs_cp_error(sbi))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	err = dquot_initialize(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	err = dquot_initialize(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	de = f2fs_find_entry(dir, &dentry->d_name, &page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	if (!de) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 		if (IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 			err = PTR_ERR(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	f2fs_balance_fs(sbi, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	f2fs_lock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	err = f2fs_acquire_orphan_inode(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		f2fs_put_page(page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	f2fs_delete_entry(de, page, dir, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) #ifdef CONFIG_UNICODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	/* VFS negative dentries are incompatible with Encoding and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	 * Case-insensitiveness. Eventually we'll want avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	 * invalidating the dentries here, alongside with returning the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	 * negative dentries at f2fs_lookup(), when it is better
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	 * supported by the VFS for the CI case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	if (IS_CASEFOLDED(dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		d_invalidate(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	if (IS_DIRSYNC(dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		f2fs_sync_fs(sbi->sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	trace_f2fs_unlink_exit(inode, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) static const char *f2fs_get_link(struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 				 struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 				 struct delayed_call *done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	const char *link = page_get_link(dentry, inode, done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	if (!IS_ERR(link) && !*link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		/* this is broken symlink case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		do_delayed_call(done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		clear_delayed_call(done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		link = ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	return link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 					const char *symname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	size_t len = strlen(symname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	struct fscrypt_str disk_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	if (unlikely(f2fs_cp_error(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	if (!f2fs_is_checkpoint_ready(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	err = fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 				      &disk_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	err = dquot_initialize(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		return PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	if (IS_ENCRYPTED(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		inode->i_op = &f2fs_encrypted_symlink_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		inode->i_op = &f2fs_symlink_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	inode_nohighmem(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	inode->i_mapping->a_ops = &f2fs_dblock_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	f2fs_lock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	err = f2fs_add_link(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		goto out_f2fs_handle_failed_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	f2fs_alloc_nid_done(sbi, inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	err = fscrypt_encrypt_symlink(inode, symname, len, &disk_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	err = page_symlink(inode, disk_link.name, disk_link.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	d_instantiate_new(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	 * Let's flush symlink data in order to avoid broken symlink as much as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	 * possible. Nevertheless, fsyncing is the best way, but there is no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	 * way to get a file descriptor in order to flush that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	 * Note that, it needs to do dir->fsync to make this recoverable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	 * If the symlink path is stored into inline_data, there is no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	 * performance regression.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		filemap_write_and_wait_range(inode->i_mapping, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 							disk_link.len - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		if (IS_DIRSYNC(dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 			f2fs_sync_fs(sbi->sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		f2fs_unlink(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	f2fs_balance_fs(sbi, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	goto out_free_encrypted_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) out_f2fs_handle_failed_inode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	f2fs_handle_failed_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) out_free_encrypted_link:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	if (disk_link.name != (unsigned char *)symname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		kfree(disk_link.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	if (unlikely(f2fs_cp_error(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	err = dquot_initialize(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	inode = f2fs_new_inode(dir, S_IFDIR | mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		return PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	inode->i_op = &f2fs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	inode->i_fop = &f2fs_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	inode->i_mapping->a_ops = &f2fs_dblock_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	set_inode_flag(inode, FI_INC_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	f2fs_lock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	err = f2fs_add_link(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	f2fs_alloc_nid_done(sbi, inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	d_instantiate_new(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	if (IS_DIRSYNC(dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		f2fs_sync_fs(sbi->sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	f2fs_balance_fs(sbi, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) out_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	clear_inode_flag(inode, FI_INC_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	f2fs_handle_failed_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	if (f2fs_empty_dir(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		return f2fs_unlink(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	return -ENOTEMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 				umode_t mode, dev_t rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	if (unlikely(f2fs_cp_error(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	if (!f2fs_is_checkpoint_ready(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	err = dquot_initialize(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	inode = f2fs_new_inode(dir, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		return PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	init_special_inode(inode, inode->i_mode, rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	inode->i_op = &f2fs_special_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	f2fs_lock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	err = f2fs_add_link(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	f2fs_alloc_nid_done(sbi, inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	d_instantiate_new(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	if (IS_DIRSYNC(dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 		f2fs_sync_fs(sbi->sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	f2fs_balance_fs(sbi, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	f2fs_handle_failed_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 					umode_t mode, struct inode **whiteout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	err = dquot_initialize(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	inode = f2fs_new_inode(dir, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		return PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	if (whiteout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		init_special_inode(inode, inode->i_mode, WHITEOUT_DEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		inode->i_op = &f2fs_special_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 		inode->i_op = &f2fs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		inode->i_fop = &f2fs_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		inode->i_mapping->a_ops = &f2fs_dblock_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	f2fs_lock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	err = f2fs_acquire_orphan_inode(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	err = f2fs_do_tmpfile(inode, dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 		goto release_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	 * add this non-linked tmpfile to orphan list, in this way we could
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	 * remove all unused data of tmpfile after abnormal power-off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	f2fs_add_orphan_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	f2fs_alloc_nid_done(sbi, inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	if (whiteout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 		f2fs_i_links_write(inode, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 		inode->i_state |= I_LINKABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		*whiteout = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		d_tmpfile(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	/* link_count was changed by d_tmpfile as well. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	f2fs_balance_fs(sbi, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) release_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	f2fs_release_orphan_inode(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	f2fs_handle_failed_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	if (unlikely(f2fs_cp_error(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	if (!f2fs_is_checkpoint_ready(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	return __f2fs_tmpfile(dir, dentry, mode, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) static int f2fs_create_whiteout(struct inode *dir, struct inode **whiteout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	if (unlikely(f2fs_cp_error(F2FS_I_SB(dir))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	return __f2fs_tmpfile(dir, NULL, S_IFCHR | WHITEOUT_MODE, whiteout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 			struct inode *new_dir, struct dentry *new_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 			unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	struct inode *old_inode = d_inode(old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	struct inode *new_inode = d_inode(new_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	struct inode *whiteout = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	struct page *old_dir_page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	struct page *old_page, *new_page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	struct f2fs_dir_entry *old_dir_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	struct f2fs_dir_entry *old_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	struct f2fs_dir_entry *new_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	if (unlikely(f2fs_cp_error(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	if (!f2fs_is_checkpoint_ready(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 			(!projid_eq(F2FS_I(new_dir)->i_projid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 			F2FS_I(old_dentry->d_inode)->i_projid)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 		return -EXDEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	 * If new_inode is null, the below renaming flow will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	 * add a link in old_dir which can conver inline_dir.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	 * After then, if we failed to get the entry due to other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	 * reasons like ENOMEM, we had to remove the new entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	 * Instead of adding such the error handling routine, let's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	 * simply convert first here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	if (old_dir == new_dir && !new_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		err = f2fs_try_convert_inline_dir(old_dir, new_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	if (flags & RENAME_WHITEOUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		err = f2fs_create_whiteout(old_dir, &whiteout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	err = dquot_initialize(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	err = dquot_initialize(new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	if (new_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		err = dquot_initialize(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	if (!old_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 		if (IS_ERR(old_page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 			err = PTR_ERR(old_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	if (S_ISDIR(old_inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 		if (!old_dir_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 			if (IS_ERR(old_dir_page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 				err = PTR_ERR(old_dir_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 			goto out_old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	if (new_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 		err = -ENOTEMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		if (old_dir_entry && !f2fs_empty_dir(new_inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 			goto out_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 		err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 						&new_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		if (!new_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 			if (IS_ERR(new_page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 				err = PTR_ERR(new_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 			goto out_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		f2fs_balance_fs(sbi, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		f2fs_lock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 		err = f2fs_acquire_orphan_inode(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 			goto put_out_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		f2fs_set_link(new_dir, new_entry, new_page, old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 		new_page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		new_inode->i_ctime = current_time(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		f2fs_down_write(&F2FS_I(new_inode)->i_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 		if (old_dir_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 			f2fs_i_links_write(new_inode, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		f2fs_i_links_write(new_inode, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		f2fs_up_write(&F2FS_I(new_inode)->i_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		if (!new_inode->i_nlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 			f2fs_add_orphan_inode(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 			f2fs_release_orphan_inode(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 		f2fs_balance_fs(sbi, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 		f2fs_lock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		err = f2fs_add_link(new_dentry, old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 			f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 			goto out_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		if (old_dir_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 			f2fs_i_links_write(new_dir, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	f2fs_down_write(&F2FS_I(old_inode)->i_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	if (!old_dir_entry || whiteout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		file_lost_pino(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		/* adjust dir's i_pino to pass fsck check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		f2fs_i_pino_write(old_inode, new_dir->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	f2fs_up_write(&F2FS_I(old_inode)->i_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	old_inode->i_ctime = current_time(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	f2fs_mark_inode_dirty_sync(old_inode, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	f2fs_delete_entry(old_entry, old_page, old_dir, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	old_page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	if (whiteout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 		set_inode_flag(whiteout, FI_INC_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		err = f2fs_add_link(old_dentry, whiteout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 			goto put_out_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		spin_lock(&whiteout->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 		whiteout->i_state &= ~I_LINKABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		spin_unlock(&whiteout->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		iput(whiteout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	if (old_dir_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		if (old_dir != new_dir && !whiteout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 			f2fs_set_link(old_inode, old_dir_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 						old_dir_page, new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 			f2fs_put_page(old_dir_page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		f2fs_i_links_write(old_dir, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		f2fs_add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 		if (S_ISDIR(old_inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 			f2fs_add_ino_entry(sbi, old_inode->i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 							TRANS_DIR_INO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		f2fs_sync_fs(sbi->sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	f2fs_update_time(sbi, REQ_TIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) put_out_dir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	f2fs_put_page(new_page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) out_dir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	if (old_dir_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		f2fs_put_page(old_dir_page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) out_old:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	f2fs_put_page(old_page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	if (whiteout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		iput(whiteout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 			     struct inode *new_dir, struct dentry *new_dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	struct inode *old_inode = d_inode(old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	struct inode *new_inode = d_inode(new_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	struct page *old_dir_page, *new_dir_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	struct page *old_page, *new_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	struct f2fs_dir_entry *old_dir_entry = NULL, *new_dir_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	struct f2fs_dir_entry *old_entry, *new_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	int old_nlink = 0, new_nlink = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	if (unlikely(f2fs_cp_error(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	if (!f2fs_is_checkpoint_ready(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 			!projid_eq(F2FS_I(new_dir)->i_projid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 			F2FS_I(old_dentry->d_inode)->i_projid)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	    (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 			!projid_eq(F2FS_I(old_dir)->i_projid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 			F2FS_I(new_dentry->d_inode)->i_projid)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		return -EXDEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	err = dquot_initialize(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	err = dquot_initialize(new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	if (!old_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 		if (IS_ERR(old_page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 			err = PTR_ERR(old_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, &new_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	if (!new_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 		if (IS_ERR(new_page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 			err = PTR_ERR(new_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 		goto out_old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	/* prepare for updating ".." directory entry info later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	if (old_dir != new_dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 		if (S_ISDIR(old_inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 			old_dir_entry = f2fs_parent_dir(old_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 							&old_dir_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 			if (!old_dir_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 				if (IS_ERR(old_dir_page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 					err = PTR_ERR(old_dir_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 				goto out_new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		if (S_ISDIR(new_inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 			new_dir_entry = f2fs_parent_dir(new_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 							&new_dir_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 			if (!new_dir_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 				if (IS_ERR(new_dir_page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 					err = PTR_ERR(new_dir_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 				goto out_old_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	 * If cross rename between file and directory those are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	 * in the same directory, we will inc nlink of file's parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	 * later, so we should check upper boundary of its nlink.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	if ((!old_dir_entry || !new_dir_entry) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 				old_dir_entry != new_dir_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		old_nlink = old_dir_entry ? -1 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 		new_nlink = -old_nlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 		err = -EMLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 		if ((old_nlink > 0 && old_dir->i_nlink >= F2FS_LINK_MAX) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 			(new_nlink > 0 && new_dir->i_nlink >= F2FS_LINK_MAX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 			goto out_new_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	f2fs_balance_fs(sbi, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	f2fs_lock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	/* update ".." directory entry info of old dentry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	if (old_dir_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 		f2fs_set_link(old_inode, old_dir_entry, old_dir_page, new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	/* update ".." directory entry info of new dentry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	if (new_dir_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 		f2fs_set_link(new_inode, new_dir_entry, new_dir_page, old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	/* update directory entry info of old dir inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	f2fs_set_link(old_dir, old_entry, old_page, new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	f2fs_down_write(&F2FS_I(old_inode)->i_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	if (!old_dir_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 		file_lost_pino(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 		/* adjust dir's i_pino to pass fsck check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 		f2fs_i_pino_write(old_inode, new_dir->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	f2fs_up_write(&F2FS_I(old_inode)->i_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	old_dir->i_ctime = current_time(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	if (old_nlink) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 		f2fs_down_write(&F2FS_I(old_dir)->i_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 		f2fs_i_links_write(old_dir, old_nlink > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		f2fs_up_write(&F2FS_I(old_dir)->i_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	f2fs_mark_inode_dirty_sync(old_dir, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	/* update directory entry info of new dir inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	f2fs_set_link(new_dir, new_entry, new_page, old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	f2fs_down_write(&F2FS_I(new_inode)->i_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	if (!new_dir_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 		file_lost_pino(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 		/* adjust dir's i_pino to pass fsck check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 		f2fs_i_pino_write(new_inode, old_dir->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	f2fs_up_write(&F2FS_I(new_inode)->i_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	new_dir->i_ctime = current_time(new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	if (new_nlink) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 		f2fs_down_write(&F2FS_I(new_dir)->i_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 		f2fs_i_links_write(new_dir, new_nlink > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 		f2fs_up_write(&F2FS_I(new_dir)->i_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	f2fs_mark_inode_dirty_sync(new_dir, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 		f2fs_add_ino_entry(sbi, old_dir->i_ino, TRANS_DIR_INO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 		f2fs_add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	f2fs_unlock_op(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 		f2fs_sync_fs(sbi->sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	f2fs_update_time(sbi, REQ_TIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) out_new_dir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	if (new_dir_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 		f2fs_put_page(new_dir_page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) out_old_dir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	if (old_dir_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 		f2fs_put_page(old_dir_page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) out_new:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	f2fs_put_page(new_page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) out_old:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	f2fs_put_page(old_page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 			struct inode *new_dir, struct dentry *new_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 			unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	err = fscrypt_prepare_rename(old_dir, old_dentry, new_dir, new_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 				     flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 	if (flags & RENAME_EXCHANGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 		return f2fs_cross_rename(old_dir, old_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 					 new_dir, new_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	 * VFS has already handled the new dentry existence case,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	 * here, we just deal with "RENAME_NOREPLACE" as regular rename.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	return f2fs_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) static const char *f2fs_encrypted_get_link(struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 					   struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 					   struct delayed_call *done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	const char *target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	if (!dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 		return ERR_PTR(-ECHILD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	page = read_mapping_page(inode->i_mapping, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	if (IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 		return ERR_CAST(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	target = fscrypt_get_symlink(inode, page_address(page),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 				     inode->i_sb->s_blocksize, done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	return target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) static int f2fs_encrypted_symlink_getattr(const struct path *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 					  struct kstat *stat, u32 request_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 					  unsigned int query_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	f2fs_getattr(path, stat, request_mask, query_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	return fscrypt_symlink_getattr(path, stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	.get_link	= f2fs_encrypted_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	.getattr	= f2fs_encrypted_symlink_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	.setattr	= f2fs_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	.listxattr	= f2fs_listxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) const struct inode_operations f2fs_dir_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	.create		= f2fs_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	.lookup		= f2fs_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	.link		= f2fs_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	.unlink		= f2fs_unlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	.symlink	= f2fs_symlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	.mkdir		= f2fs_mkdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	.rmdir		= f2fs_rmdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	.mknod		= f2fs_mknod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	.rename		= f2fs_rename2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	.tmpfile	= f2fs_tmpfile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	.getattr	= f2fs_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	.setattr	= f2fs_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	.get_acl	= f2fs_get_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	.set_acl	= f2fs_set_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	.listxattr	= f2fs_listxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	.fiemap		= f2fs_fiemap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) const struct inode_operations f2fs_symlink_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	.get_link	= f2fs_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	.getattr	= f2fs_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	.setattr	= f2fs_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	.listxattr	= f2fs_listxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) const struct inode_operations f2fs_special_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	.getattr	= f2fs_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	.setattr	= f2fs_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	.get_acl	= f2fs_get_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	.set_acl	= f2fs_set_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	.listxattr	= f2fs_listxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) };