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