blob: ce0957318771cc379f520394b3bf07a36c95cdbc [file] [log] [blame]
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +09001/*
Jaegeuk Kim57397d82012-11-02 17:11:10 +09002 * fs/f2fs/namei.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/fs.h>
12#include <linux/f2fs_fs.h>
13#include <linux/pagemap.h>
14#include <linux/sched.h>
15#include <linux/ctype.h>
Chao Yu50732df2014-06-19 16:23:19 +080016#include <linux/dcache.h>
Jaegeuk Kimfeb7cbb2015-04-15 13:49:55 -070017#include <linux/namei.h>
Jaegeuk Kim57397d82012-11-02 17:11:10 +090018
19#include "f2fs.h"
Jaegeuk Kim953a3e22013-03-21 15:21:57 +090020#include "node.h"
Jaegeuk Kim57397d82012-11-02 17:11:10 +090021#include "xattr.h"
22#include "acl.h"
Namjae Jeona2a4a7e2013-04-20 01:28:40 +090023#include <trace/events/f2fs.h>
Jaegeuk Kim57397d82012-11-02 17:11:10 +090024
25static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
26{
Jaegeuk Kim40813632014-09-02 15:31:18 -070027 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090028 nid_t ino;
29 struct inode *inode;
30 bool nid_free = false;
Gu Zhenge4795562013-09-27 18:08:30 +080031 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +090032
Jaegeuk Kima014e032014-06-20 21:44:02 -070033 inode = new_inode(dir->i_sb);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090034 if (!inode)
35 return ERR_PTR(-ENOMEM);
36
Gu Zhenge4795562013-09-27 18:08:30 +080037 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090038 if (!alloc_nid(sbi, &ino)) {
Gu Zhenge4795562013-09-27 18:08:30 +080039 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090040 err = -ENOSPC;
41 goto fail;
42 }
Gu Zhenge4795562013-09-27 18:08:30 +080043 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090044
Chao Yu70ff5df2014-05-08 17:09:30 +080045 inode_init_owner(inode, dir, mode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090046
47 inode->i_ino = ino;
Jaegeuk Kim57397d82012-11-02 17:11:10 +090048 inode->i_blocks = 0;
Deepa Dinamani078cd822016-09-14 07:48:04 -070049 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090050 inode->i_generation = sbi->s_next_generation++;
51
52 err = insert_inode_locked(inode);
53 if (err) {
54 err = -EINVAL;
55 nid_free = true;
Jaegeuk Kima21c20f2015-08-16 12:38:15 -070056 goto fail;
Jaegeuk Kim57397d82012-11-02 17:11:10 +090057 }
Chao Yu622f28a2014-09-24 18:19:10 +080058
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -070059 /* If the directory encrypted, then we should encrypt the inode. */
60 if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode))
61 f2fs_set_encrypted_inode(inode);
62
Jaegeuk Kim91942322016-05-20 10:13:22 -070063 set_inode_flag(inode, FI_NEW_INODE);
64
65 if (test_opt(sbi, INLINE_XATTR))
66 set_inode_flag(inode, FI_INLINE_XATTR);
Chao Yufba48a82015-12-23 17:51:35 +080067 if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode))
Jaegeuk Kim91942322016-05-20 10:13:22 -070068 set_inode_flag(inode, FI_INLINE_DATA);
Jaegeuk Kim01b960e2015-04-23 10:27:21 -070069 if (f2fs_may_inline_dentry(inode))
Jaegeuk Kim91942322016-05-20 10:13:22 -070070 set_inode_flag(inode, FI_INLINE_DENTRY);
Chao Yu622f28a2014-09-24 18:19:10 +080071
Jaegeuk Kim3e72f722015-06-19 17:53:26 -070072 f2fs_init_extent_tree(inode, NULL);
73
Chao Yud5e8f6c2015-07-15 17:28:53 +080074 stat_inc_inline_xattr(inode);
Jaegeuk Kim2fb2c952015-04-30 18:58:22 -070075 stat_inc_inline_inode(inode);
76 stat_inc_inline_dir(inode);
77
Jaegeuk Kimd70b4f52013-04-25 13:24:33 +090078 trace_f2fs_new_inode(inode, 0);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090079 return inode;
80
Jaegeuk Kim57397d82012-11-02 17:11:10 +090081fail:
Jaegeuk Kimd70b4f52013-04-25 13:24:33 +090082 trace_f2fs_new_inode(inode, err);
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +090083 make_bad_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090084 if (nid_free)
Jaegeuk Kim91942322016-05-20 10:13:22 -070085 set_inode_flag(inode, FI_FREE_NID);
Jaegeuk Kimc9b63bd2015-06-23 10:36:08 -070086 iput(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090087 return ERR_PTR(err);
88}
89
90static int is_multimedia_file(const unsigned char *s, const char *sub)
91{
Leon Romanovsky9836b8b2012-12-27 19:55:46 +020092 size_t slen = strlen(s);
93 size_t sublen = strlen(sub);
Chao Yu7732c262016-09-05 12:28:27 +080094 int i;
Jaegeuk Kim57397d82012-11-02 17:11:10 +090095
Chao Yu741a7be2015-07-06 20:30:40 +080096 /*
97 * filename format of multimedia file should be defined as:
Chao Yu7732c262016-09-05 12:28:27 +080098 * "filename + '.' + extension + (optional: '.' + temp extension)".
Chao Yu741a7be2015-07-06 20:30:40 +080099 */
100 if (slen < sublen + 2)
101 return 0;
102
Chao Yu7732c262016-09-05 12:28:27 +0800103 for (i = 1; i < slen - sublen; i++) {
104 if (s[i] != '.')
105 continue;
106 if (!strncasecmp(s + i + 1, sub, sublen))
107 return 1;
108 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900109
Chao Yu7732c262016-09-05 12:28:27 +0800110 return 0;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900111}
112
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +0900113/*
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900114 * Set multimedia files as cold files for hot/cold data separation
115 */
Jaegeuk Kim953a3e22013-03-21 15:21:57 +0900116static inline void set_cold_files(struct f2fs_sb_info *sbi, struct inode *inode,
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900117 const unsigned char *name)
118{
119 int i;
120 __u8 (*extlist)[8] = sbi->raw_super->extension_list;
121
122 int count = le32_to_cpu(sbi->raw_super->extension_count);
123 for (i = 0; i < count; i++) {
Namjae Jeone66509f02013-04-20 01:27:21 +0900124 if (is_multimedia_file(name, extlist[i])) {
Jaegeuk Kim354a3392013-06-14 08:52:35 +0900125 file_set_cold(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900126 break;
127 }
128 }
129}
130
131static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
132 bool excl)
133{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700134 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900135 struct inode *inode;
136 nid_t ino = 0;
Gu Zhenge4795562013-09-27 18:08:30 +0800137 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900138
139 inode = f2fs_new_inode(dir, mode);
140 if (IS_ERR(inode))
141 return PTR_ERR(inode);
142
143 if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
Jaegeuk Kim953a3e22013-03-21 15:21:57 +0900144 set_cold_files(sbi, inode, dentry->d_name.name);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900145
146 inode->i_op = &f2fs_file_inode_operations;
147 inode->i_fop = &f2fs_file_operations;
148 inode->i_mapping->a_ops = &f2fs_dblock_aops;
149 ino = inode->i_ino;
150
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800151 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800152
Gu Zhenge4795562013-09-27 18:08:30 +0800153 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900154 err = f2fs_add_link(dentry, inode);
155 if (err)
156 goto out;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700157 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900158
159 alloc_nid_done(sbi, ino);
160
Al Viro2d2d3f12018-05-04 08:23:01 -0400161 d_instantiate_new(dentry, inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800162
163 if (IS_DIRSYNC(dir))
164 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900165 return 0;
166out:
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700167 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900168 return err;
169}
170
171static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
172 struct dentry *dentry)
173{
David Howells2b0143b2015-03-17 22:25:59 +0000174 struct inode *inode = d_inode(old_dentry);
Jaegeuk Kim40813632014-09-02 15:31:18 -0700175 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Gu Zhenge4795562013-09-27 18:08:30 +0800176 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900177
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700178 if (f2fs_encrypted_inode(dir) &&
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700179 !fscrypt_has_permitted_context(dir, inode))
Eric Biggersa5edcea2019-01-22 16:20:21 -0800180 return -EXDEV;
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700181
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800182 f2fs_balance_fs(sbi, true);
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900183
Deepa Dinamani078cd822016-09-14 07:48:04 -0700184 inode->i_ctime = current_time(inode);
Jaegeuk Kim6f6fd832013-05-22 12:06:26 +0900185 ihold(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900186
Jaegeuk Kim91942322016-05-20 10:13:22 -0700187 set_inode_flag(inode, FI_INC_LINK);
Gu Zhenge4795562013-09-27 18:08:30 +0800188 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900189 err = f2fs_add_link(dentry, inode);
190 if (err)
191 goto out;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700192 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900193
194 d_instantiate(dentry, inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800195
196 if (IS_DIRSYNC(dir))
197 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900198 return 0;
199out:
Jaegeuk Kim91942322016-05-20 10:13:22 -0700200 clear_inode_flag(inode, FI_INC_LINK);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900201 iput(inode);
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700202 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900203 return err;
204}
205
206struct dentry *f2fs_get_parent(struct dentry *child)
207{
208 struct qstr dotdot = QSTR_INIT("..", 2);
Chao Yu91246c22016-07-19 08:27:47 +0800209 struct page *page;
210 unsigned long ino = f2fs_inode_by_name(d_inode(child), &dotdot, &page);
211 if (!ino) {
212 if (IS_ERR(page))
213 return ERR_CAST(page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900214 return ERR_PTR(-ENOENT);
Chao Yu91246c22016-07-19 08:27:47 +0800215 }
Al Virofc640052016-04-10 01:33:30 -0400216 return d_obtain_alias(f2fs_iget(child->d_sb, ino));
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900217}
218
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700219static int __recover_dot_dentries(struct inode *dir, nid_t pino)
220{
221 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
222 struct qstr dot = QSTR_INIT(".", 1);
223 struct qstr dotdot = QSTR_INIT("..", 2);
224 struct f2fs_dir_entry *de;
225 struct page *page;
226 int err = 0;
227
Chao Yu4e0d8362015-12-30 17:40:31 +0800228 if (f2fs_readonly(sbi->sb)) {
229 f2fs_msg(sbi->sb, KERN_INFO,
230 "skip recovering inline_dots inode (ino:%lu, pino:%u) "
231 "in readonly mountpoint", dir->i_ino, pino);
232 return 0;
233 }
234
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800235 f2fs_balance_fs(sbi, true);
Chao Yud5384172015-12-24 18:03:29 +0800236
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700237 f2fs_lock_op(sbi);
238
239 de = f2fs_find_entry(dir, &dot, &page);
240 if (de) {
241 f2fs_dentry_kunmap(dir, page);
242 f2fs_put_page(page, 0);
Jaegeuk Kim42d96402016-05-25 14:29:11 -0700243 } else if (IS_ERR(page)) {
244 err = PTR_ERR(page);
245 goto out;
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700246 } else {
247 err = __f2fs_add_link(dir, &dot, NULL, dir->i_ino, S_IFDIR);
248 if (err)
249 goto out;
250 }
251
252 de = f2fs_find_entry(dir, &dotdot, &page);
253 if (de) {
254 f2fs_dentry_kunmap(dir, page);
255 f2fs_put_page(page, 0);
Jaegeuk Kim42d96402016-05-25 14:29:11 -0700256 } else if (IS_ERR(page)) {
257 err = PTR_ERR(page);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700258 } else {
259 err = __f2fs_add_link(dir, &dotdot, NULL, pino, S_IFDIR);
260 }
261out:
Jaegeuk Kim205b9822016-05-20 09:52:20 -0700262 if (!err)
Jaegeuk Kim91942322016-05-20 10:13:22 -0700263 clear_inode_flag(dir, FI_INLINE_DOTS);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700264
265 f2fs_unlock_op(sbi);
266 return err;
267}
268
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900269static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
270 unsigned int flags)
271{
272 struct inode *inode = NULL;
273 struct f2fs_dir_entry *de;
274 struct page *page;
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700275 nid_t ino;
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700276 int err = 0;
Liu Xue8c2b1432016-02-26 06:39:23 +0000277 unsigned int root_ino = F2FS_ROOT_INO(F2FS_I_SB(dir));
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900278
Jaegeuk Kim8074bb52016-02-23 09:21:37 -0800279 if (f2fs_encrypted_inode(dir)) {
280 int res = fscrypt_get_encryption_info(dir);
281
282 /*
283 * DCACHE_ENCRYPTED_WITH_KEY is set if the dentry is
284 * created while the directory was encrypted and we
285 * don't have access to the key.
286 */
287 if (fscrypt_has_encryption_key(dir))
288 fscrypt_set_encrypted_dentry(dentry);
289 fscrypt_set_d_op(dentry);
290 if (res && res != -ENOKEY)
291 return ERR_PTR(res);
292 }
293
Jaegeuk Kim5a20d332013-03-03 13:58:05 +0900294 if (dentry->d_name.len > F2FS_NAME_LEN)
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900295 return ERR_PTR(-ENAMETOOLONG);
296
297 de = f2fs_find_entry(dir, &dentry->d_name, &page);
Jaegeuk Kimeb4246d2016-05-27 10:10:41 -0700298 if (!de) {
299 if (IS_ERR(page))
300 return (struct dentry *)page;
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700301 return d_splice_alias(inode, dentry);
Jaegeuk Kimeb4246d2016-05-27 10:10:41 -0700302 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900303
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700304 ino = le32_to_cpu(de->ino);
305 f2fs_dentry_kunmap(dir, page);
306 f2fs_put_page(page, 0);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700307
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700308 inode = f2fs_iget(dir->i_sb, ino);
309 if (IS_ERR(inode))
310 return ERR_CAST(inode);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700311
Liu Xue8c2b1432016-02-26 06:39:23 +0000312 if ((dir->i_ino == root_ino) && f2fs_has_inline_dots(dir)) {
313 err = __recover_dot_dentries(dir, root_ino);
314 if (err)
315 goto err_out;
316 }
317
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700318 if (f2fs_has_inline_dots(inode)) {
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700319 err = __recover_dot_dentries(inode, dir->i_ino);
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700320 if (err)
321 goto err_out;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900322 }
Jaegeuk Kim8074bb52016-02-23 09:21:37 -0800323 if (!IS_ERR(inode) && f2fs_encrypted_inode(dir) &&
324 (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
325 !fscrypt_has_permitted_context(dir, inode)) {
326 bool nokey = f2fs_encrypted_inode(inode) &&
327 !fscrypt_has_encryption_key(inode);
Chao Yud7267322016-03-10 22:24:23 +0800328 err = nokey ? -ENOKEY : -EPERM;
329 goto err_out;
Jaegeuk Kim8074bb52016-02-23 09:21:37 -0800330 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900331 return d_splice_alias(inode, dentry);
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700332
333err_out:
Chao Yud7267322016-03-10 22:24:23 +0800334 iput(inode);
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700335 return ERR_PTR(err);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900336}
337
338static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
339{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700340 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
David Howells2b0143b2015-03-17 22:25:59 +0000341 struct inode *inode = d_inode(dentry);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900342 struct f2fs_dir_entry *de;
343 struct page *page;
344 int err = -ENOENT;
345
Namjae Jeona2a4a7e2013-04-20 01:28:40 +0900346 trace_f2fs_unlink_enter(dir, dentry);
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900347
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900348 de = f2fs_find_entry(dir, &dentry->d_name, &page);
Chao Yu91246c22016-07-19 08:27:47 +0800349 if (!de) {
350 if (IS_ERR(page))
351 err = PTR_ERR(page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900352 goto fail;
Chao Yu91246c22016-07-19 08:27:47 +0800353 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900354
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800355 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800356
Jaegeuk Kimccaaca22013-10-08 10:19:28 +0900357 f2fs_lock_op(sbi);
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900358 err = acquire_orphan_inode(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900359 if (err) {
Jaegeuk Kimccaaca22013-10-08 10:19:28 +0900360 f2fs_unlock_op(sbi);
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800361 f2fs_dentry_kunmap(dir, page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900362 f2fs_put_page(page, 0);
363 goto fail;
364 }
Chao Yudbeacf02014-09-24 18:17:04 +0800365 f2fs_delete_entry(de, page, dir, inode);
Gu Zhenge4795562013-09-27 18:08:30 +0800366 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900367
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800368 if (IS_DIRSYNC(dir))
369 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900370fail:
Namjae Jeona2a4a7e2013-04-20 01:28:40 +0900371 trace_f2fs_unlink_exit(inode, err);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900372 return err;
373}
374
Al Viro6b255392015-11-17 10:20:54 -0500375static const char *f2fs_get_link(struct dentry *dentry,
Al Virofceef392015-12-29 15:58:39 -0500376 struct inode *inode,
377 struct delayed_call *done)
Jaegeuk Kimfeb7cbb2015-04-15 13:49:55 -0700378{
Al Virofceef392015-12-29 15:58:39 -0500379 const char *link = page_get_link(dentry, inode, done);
Al Viro680baac2015-05-02 13:32:22 -0400380 if (!IS_ERR(link) && !*link) {
381 /* this is broken symlink case */
Al Virofceef392015-12-29 15:58:39 -0500382 do_delayed_call(done);
383 clear_delayed_call(done);
Al Viro680baac2015-05-02 13:32:22 -0400384 link = ERR_PTR(-ENOENT);
Jaegeuk Kimfeb7cbb2015-04-15 13:49:55 -0700385 }
Al Viro680baac2015-05-02 13:32:22 -0400386 return link;
Jaegeuk Kimfeb7cbb2015-04-15 13:49:55 -0700387}
388
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900389static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
390 const char *symname)
391{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700392 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900393 struct inode *inode;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700394 size_t len = strlen(symname);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700395 struct fscrypt_str disk_link = FSTR_INIT((char *)symname, len + 1);
396 struct fscrypt_symlink_data *sd = NULL;
Gu Zhenge4795562013-09-27 18:08:30 +0800397 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900398
Chao Yu922ec352016-02-15 17:54:26 +0800399 if (f2fs_encrypted_inode(dir)) {
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700400 err = fscrypt_get_encryption_info(dir);
Chao Yu922ec352016-02-15 17:54:26 +0800401 if (err)
402 return err;
403
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700404 if (!fscrypt_has_encryption_key(dir))
Eric Biggersd612bee2016-12-05 11:12:44 -0800405 return -ENOKEY;
Chao Yu922ec352016-02-15 17:54:26 +0800406
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700407 disk_link.len = (fscrypt_fname_encrypted_size(dir, len) +
408 sizeof(struct fscrypt_symlink_data));
Chao Yu922ec352016-02-15 17:54:26 +0800409 }
410
411 if (disk_link.len > dir->i_sb->s_blocksize)
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700412 return -ENAMETOOLONG;
413
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900414 inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO);
415 if (IS_ERR(inode))
416 return PTR_ERR(inode);
417
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700418 if (f2fs_encrypted_inode(inode))
419 inode->i_op = &f2fs_encrypted_symlink_inode_operations;
420 else
421 inode->i_op = &f2fs_symlink_inode_operations;
Al Viro21fc61c2015-11-17 01:07:57 -0500422 inode_nohighmem(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900423 inode->i_mapping->a_ops = &f2fs_dblock_aops;
424
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800425 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800426
Gu Zhenge4795562013-09-27 18:08:30 +0800427 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900428 err = f2fs_add_link(dentry, inode);
429 if (err)
430 goto out;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700431 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900432 alloc_nid_done(sbi, inode->i_ino);
433
Chao Yu922ec352016-02-15 17:54:26 +0800434 if (f2fs_encrypted_inode(inode)) {
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700435 struct qstr istr = QSTR_INIT(symname, len);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700436 struct fscrypt_str ostr;
Chao Yu922ec352016-02-15 17:54:26 +0800437
438 sd = kzalloc(disk_link.len, GFP_NOFS);
439 if (!sd) {
440 err = -ENOMEM;
441 goto err_out;
442 }
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700443
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700444 err = fscrypt_get_encryption_info(inode);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700445 if (err)
446 goto err_out;
447
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700448 if (!fscrypt_has_encryption_key(inode)) {
Eric Biggersd612bee2016-12-05 11:12:44 -0800449 err = -ENOKEY;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700450 goto err_out;
Chao Yu922ec352016-02-15 17:54:26 +0800451 }
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700452
Chao Yu922ec352016-02-15 17:54:26 +0800453 ostr.name = sd->encrypted_path;
454 ostr.len = disk_link.len;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700455 err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr);
Eric Biggersef1eb3a2016-09-15 17:25:55 -0400456 if (err)
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700457 goto err_out;
458
Chao Yu922ec352016-02-15 17:54:26 +0800459 sd->len = cpu_to_le16(ostr.len);
460 disk_link.name = (char *)sd;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700461 }
462
Chao Yu922ec352016-02-15 17:54:26 +0800463 err = page_symlink(inode, disk_link.name, disk_link.len);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700464
465err_out:
Al Viro2d2d3f12018-05-04 08:23:01 -0400466 d_instantiate_new(dentry, inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800467
Jaegeuk Kimd0cae972015-04-15 13:37:53 -0700468 /*
469 * Let's flush symlink data in order to avoid broken symlink as much as
470 * possible. Nevertheless, fsyncing is the best way, but there is no
471 * way to get a file descriptor in order to flush that.
472 *
473 * Note that, it needs to do dir->fsync to make this recoverable.
474 * If the symlink path is stored into inline_data, there is no
475 * performance regression.
476 */
Chao Yua6be0142015-10-22 18:23:08 +0800477 if (!err) {
Chao Yu922ec352016-02-15 17:54:26 +0800478 filemap_write_and_wait_range(inode->i_mapping, 0,
479 disk_link.len - 1);
Jaegeuk Kimd0cae972015-04-15 13:37:53 -0700480
Chao Yua6be0142015-10-22 18:23:08 +0800481 if (IS_DIRSYNC(dir))
482 f2fs_sync_fs(sbi->sb, 1);
483 } else {
484 f2fs_unlink(dir, dentry);
485 }
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700486
487 kfree(sd);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900488 return err;
489out:
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700490 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900491 return err;
492}
493
494static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
495{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700496 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900497 struct inode *inode;
Gu Zhenge4795562013-09-27 18:08:30 +0800498 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900499
500 inode = f2fs_new_inode(dir, S_IFDIR | mode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900501 if (IS_ERR(inode))
Namjae Jeon61412b62012-12-01 10:56:25 +0900502 return PTR_ERR(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900503
504 inode->i_op = &f2fs_dir_inode_operations;
505 inode->i_fop = &f2fs_dir_operations;
506 inode->i_mapping->a_ops = &f2fs_dblock_aops;
Chao Yu560d4672015-02-07 17:36:15 +0800507 mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_HIGH_ZERO);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900508
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800509 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800510
Jaegeuk Kim91942322016-05-20 10:13:22 -0700511 set_inode_flag(inode, FI_INC_LINK);
Gu Zhenge4795562013-09-27 18:08:30 +0800512 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900513 err = f2fs_add_link(dentry, inode);
514 if (err)
515 goto out_fail;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700516 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900517
518 alloc_nid_done(sbi, inode->i_ino);
519
Al Viro2d2d3f12018-05-04 08:23:01 -0400520 d_instantiate_new(dentry, inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900521
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800522 if (IS_DIRSYNC(dir))
523 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900524 return 0;
525
526out_fail:
Jaegeuk Kim91942322016-05-20 10:13:22 -0700527 clear_inode_flag(inode, FI_INC_LINK);
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700528 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900529 return err;
530}
531
532static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)
533{
David Howells2b0143b2015-03-17 22:25:59 +0000534 struct inode *inode = d_inode(dentry);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900535 if (f2fs_empty_dir(inode))
536 return f2fs_unlink(dir, dentry);
537 return -ENOTEMPTY;
538}
539
540static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
541 umode_t mode, dev_t rdev)
542{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700543 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900544 struct inode *inode;
545 int err = 0;
546
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900547 inode = f2fs_new_inode(dir, mode);
548 if (IS_ERR(inode))
549 return PTR_ERR(inode);
550
551 init_special_inode(inode, inode->i_mode, rdev);
552 inode->i_op = &f2fs_special_inode_operations;
553
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800554 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800555
Gu Zhenge4795562013-09-27 18:08:30 +0800556 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900557 err = f2fs_add_link(dentry, inode);
558 if (err)
559 goto out;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700560 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900561
562 alloc_nid_done(sbi, inode->i_ino);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800563
Al Viro2d2d3f12018-05-04 08:23:01 -0400564 d_instantiate_new(dentry, inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800565
566 if (IS_DIRSYNC(dir))
567 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900568 return 0;
569out:
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700570 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900571 return err;
572}
573
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800574static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,
575 umode_t mode, struct inode **whiteout)
576{
577 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
578 struct inode *inode;
579 int err;
580
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800581 inode = f2fs_new_inode(dir, mode);
582 if (IS_ERR(inode))
583 return PTR_ERR(inode);
584
585 if (whiteout) {
586 init_special_inode(inode, inode->i_mode, WHITEOUT_DEV);
587 inode->i_op = &f2fs_special_inode_operations;
588 } else {
589 inode->i_op = &f2fs_file_inode_operations;
590 inode->i_fop = &f2fs_file_operations;
591 inode->i_mapping->a_ops = &f2fs_dblock_aops;
592 }
593
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800594 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800595
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800596 f2fs_lock_op(sbi);
597 err = acquire_orphan_inode(sbi);
598 if (err)
599 goto out;
600
601 err = f2fs_do_tmpfile(inode, dir);
602 if (err)
603 goto release_out;
604
605 /*
606 * add this non-linked tmpfile to orphan list, in this way we could
607 * remove all unused data of tmpfile after abnormal power-off.
608 */
Jaegeuk Kim67c37582016-06-13 18:27:02 -0700609 add_orphan_inode(inode);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800610 alloc_nid_done(sbi, inode->i_ino);
611
612 if (whiteout) {
Jaegeuk Kima1961242016-05-20 09:43:20 -0700613 f2fs_i_links_write(inode, false);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800614 *whiteout = inode;
615 } else {
616 d_tmpfile(dentry, inode);
617 }
Jaegeuk Kima1961242016-05-20 09:43:20 -0700618 /* link_count was changed by d_tmpfile as well. */
619 f2fs_unlock_op(sbi);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800620 unlock_new_inode(inode);
621 return 0;
622
623release_out:
624 release_orphan_inode(sbi);
625out:
626 handle_failed_inode(inode);
627 return err;
628}
629
630static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
631{
Jaegeuk Kim304eecc2015-05-19 16:11:40 -0700632 if (f2fs_encrypted_inode(dir)) {
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700633 int err = fscrypt_get_encryption_info(dir);
Jaegeuk Kim304eecc2015-05-19 16:11:40 -0700634 if (err)
635 return err;
636 }
637
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800638 return __f2fs_tmpfile(dir, dentry, mode, NULL);
639}
640
641static int f2fs_create_whiteout(struct inode *dir, struct inode **whiteout)
642{
643 return __f2fs_tmpfile(dir, NULL, S_IFCHR | WHITEOUT_MODE, whiteout);
644}
645
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900646static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800647 struct inode *new_dir, struct dentry *new_dentry,
648 unsigned int flags)
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900649{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700650 struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
David Howells2b0143b2015-03-17 22:25:59 +0000651 struct inode *old_inode = d_inode(old_dentry);
652 struct inode *new_inode = d_inode(new_dentry);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800653 struct inode *whiteout = NULL;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900654 struct page *old_dir_page;
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800655 struct page *old_page, *new_page = NULL;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900656 struct f2fs_dir_entry *old_dir_entry = NULL;
657 struct f2fs_dir_entry *old_entry;
658 struct f2fs_dir_entry *new_entry;
Chao Yu993a0492016-02-17 16:47:05 +0800659 bool is_old_inline = f2fs_has_inline_dentry(old_dir);
Gu Zhenge4795562013-09-27 18:08:30 +0800660 int err = -ENOENT;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900661
Jaegeuk Kimec86c1c2016-12-28 17:31:15 -0800662 if ((f2fs_encrypted_inode(old_dir) &&
663 !fscrypt_has_encryption_key(old_dir)) ||
664 (f2fs_encrypted_inode(new_dir) &&
665 !fscrypt_has_encryption_key(new_dir)))
666 return -ENOKEY;
667
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700668 if ((old_dir != new_dir) && f2fs_encrypted_inode(new_dir) &&
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700669 !fscrypt_has_permitted_context(new_dir, old_inode)) {
Eric Biggersa5edcea2019-01-22 16:20:21 -0800670 err = -EXDEV;
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700671 goto out;
672 }
673
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900674 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
Chao Yu91246c22016-07-19 08:27:47 +0800675 if (!old_entry) {
676 if (IS_ERR(old_page))
677 err = PTR_ERR(old_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900678 goto out;
Chao Yu91246c22016-07-19 08:27:47 +0800679 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900680
681 if (S_ISDIR(old_inode->i_mode)) {
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900682 old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page);
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700683 if (!old_dir_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800684 if (IS_ERR(old_dir_page))
685 err = PTR_ERR(old_dir_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900686 goto out_old;
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700687 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900688 }
689
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800690 if (flags & RENAME_WHITEOUT) {
691 err = f2fs_create_whiteout(old_dir, &whiteout);
692 if (err)
693 goto out_dir;
694 }
695
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900696 if (new_inode) {
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900697
698 err = -ENOTEMPTY;
699 if (old_dir_entry && !f2fs_empty_dir(new_inode))
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800700 goto out_whiteout;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900701
702 err = -ENOENT;
703 new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name,
704 &new_page);
Chao Yu91246c22016-07-19 08:27:47 +0800705 if (!new_entry) {
706 if (IS_ERR(new_page))
707 err = PTR_ERR(new_page);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800708 goto out_whiteout;
Chao Yu91246c22016-07-19 08:27:47 +0800709 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900710
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800711 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800712
Chao Yu12560102014-06-24 14:16:24 +0800713 f2fs_lock_op(sbi);
714
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900715 err = acquire_orphan_inode(sbi);
716 if (err)
717 goto put_out_dir;
718
Chao Yu9def1e92016-02-17 16:45:44 +0800719 err = update_dent_inode(old_inode, new_inode,
720 &new_dentry->d_name);
721 if (err) {
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900722 release_orphan_inode(sbi);
723 goto put_out_dir;
Jaegeuk Kim1cd14ca2013-07-18 18:02:31 +0900724 }
725
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900726 f2fs_set_link(new_dir, new_entry, new_page, old_inode);
727
Deepa Dinamani078cd822016-09-14 07:48:04 -0700728 new_inode->i_ctime = current_time(new_inode);
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900729 down_write(&F2FS_I(new_inode)->i_sem);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900730 if (old_dir_entry)
Jaegeuk Kima1961242016-05-20 09:43:20 -0700731 f2fs_i_links_write(new_inode, false);
732 f2fs_i_links_write(new_inode, false);
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900733 up_write(&F2FS_I(new_inode)->i_sem);
734
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900735 if (!new_inode->i_nlink)
Jaegeuk Kim67c37582016-06-13 18:27:02 -0700736 add_orphan_inode(new_inode);
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900737 else
738 release_orphan_inode(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900739 } else {
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800740 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800741
Chao Yu12560102014-06-24 14:16:24 +0800742 f2fs_lock_op(sbi);
743
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900744 err = f2fs_add_link(new_dentry, old_inode);
Chao Yu12560102014-06-24 14:16:24 +0800745 if (err) {
746 f2fs_unlock_op(sbi);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800747 goto out_whiteout;
Chao Yu12560102014-06-24 14:16:24 +0800748 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900749
Jaegeuk Kimee6d1822016-05-20 16:32:49 -0700750 if (old_dir_entry)
Jaegeuk Kima1961242016-05-20 09:43:20 -0700751 f2fs_i_links_write(new_dir, true);
Chao Yu993a0492016-02-17 16:47:05 +0800752
753 /*
754 * old entry and new entry can locate in the same inline
755 * dentry in inode, when attaching new entry in inline dentry,
756 * it could force inline dentry conversion, after that,
757 * old_entry and old_page will point to wrong address, in
758 * order to avoid this, let's do the check and update here.
759 */
760 if (is_old_inline && !f2fs_has_inline_dentry(old_dir)) {
761 f2fs_put_page(old_page, 0);
762 old_page = NULL;
763
764 old_entry = f2fs_find_entry(old_dir,
765 &old_dentry->d_name, &old_page);
766 if (!old_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800767 err = -ENOENT;
768 if (IS_ERR(old_page))
769 err = PTR_ERR(old_page);
Chao Yu993a0492016-02-17 16:47:05 +0800770 f2fs_unlock_op(sbi);
771 goto out_whiteout;
772 }
773 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900774 }
775
Jaegeuk Kimb2c08292014-06-30 18:09:55 +0900776 down_write(&F2FS_I(old_inode)->i_sem);
777 file_lost_pino(old_inode);
Jaegeuk Kime7d55452015-04-29 17:02:18 -0700778 if (new_inode && file_enc_name(new_inode))
779 file_set_enc_name(old_inode);
Jaegeuk Kimb2c08292014-06-30 18:09:55 +0900780 up_write(&F2FS_I(old_inode)->i_sem);
781
Deepa Dinamani078cd822016-09-14 07:48:04 -0700782 old_inode->i_ctime = current_time(old_inode);
Jaegeuk Kimb56ab832016-06-30 19:09:37 -0700783 f2fs_mark_inode_dirty_sync(old_inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900784
Chao Yudbeacf02014-09-24 18:17:04 +0800785 f2fs_delete_entry(old_entry, old_page, old_dir, NULL);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900786
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800787 if (whiteout) {
788 whiteout->i_state |= I_LINKABLE;
Jaegeuk Kim91942322016-05-20 10:13:22 -0700789 set_inode_flag(whiteout, FI_INC_LINK);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800790 err = f2fs_add_link(old_dentry, whiteout);
791 if (err)
792 goto put_out_dir;
793 whiteout->i_state &= ~I_LINKABLE;
794 iput(whiteout);
795 }
796
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900797 if (old_dir_entry) {
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800798 if (old_dir != new_dir && !whiteout) {
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900799 f2fs_set_link(old_inode, old_dir_entry,
800 old_dir_page, new_dir);
801 } else {
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800802 f2fs_dentry_kunmap(old_inode, old_dir_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900803 f2fs_put_page(old_dir_page, 0);
804 }
Jaegeuk Kima1961242016-05-20 09:43:20 -0700805 f2fs_i_links_write(old_dir, false);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900806 }
807
Gu Zhenge4795562013-09-27 18:08:30 +0800808 f2fs_unlock_op(sbi);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800809
810 if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
811 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900812 return 0;
813
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900814put_out_dir:
Chao Yu12560102014-06-24 14:16:24 +0800815 f2fs_unlock_op(sbi);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800816 if (new_page) {
817 f2fs_dentry_kunmap(new_dir, new_page);
818 f2fs_put_page(new_page, 0);
819 }
820out_whiteout:
821 if (whiteout)
822 iput(whiteout);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900823out_dir:
824 if (old_dir_entry) {
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800825 f2fs_dentry_kunmap(old_inode, old_dir_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900826 f2fs_put_page(old_dir_page, 0);
827 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900828out_old:
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800829 f2fs_dentry_kunmap(old_dir, old_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900830 f2fs_put_page(old_page, 0);
831out:
832 return err;
833}
834
Chao Yu32f9bc22014-07-12 19:13:54 +0800835static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
836 struct inode *new_dir, struct dentry *new_dentry)
837{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700838 struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
David Howells2b0143b2015-03-17 22:25:59 +0000839 struct inode *old_inode = d_inode(old_dentry);
840 struct inode *new_inode = d_inode(new_dentry);
Chao Yu32f9bc22014-07-12 19:13:54 +0800841 struct page *old_dir_page, *new_dir_page;
842 struct page *old_page, *new_page;
843 struct f2fs_dir_entry *old_dir_entry = NULL, *new_dir_entry = NULL;
844 struct f2fs_dir_entry *old_entry, *new_entry;
845 int old_nlink = 0, new_nlink = 0;
846 int err = -ENOENT;
847
Jaegeuk Kimec86c1c2016-12-28 17:31:15 -0800848 if ((f2fs_encrypted_inode(old_dir) &&
849 !fscrypt_has_encryption_key(old_dir)) ||
850 (f2fs_encrypted_inode(new_dir) &&
851 !fscrypt_has_encryption_key(new_dir)))
852 return -ENOKEY;
853
Chao Yud3baf7c2015-05-25 18:07:02 +0800854 if ((f2fs_encrypted_inode(old_dir) || f2fs_encrypted_inode(new_dir)) &&
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700855 (old_dir != new_dir) &&
856 (!fscrypt_has_permitted_context(new_dir, old_inode) ||
857 !fscrypt_has_permitted_context(old_dir, new_inode)))
Eric Biggersa5edcea2019-01-22 16:20:21 -0800858 return -EXDEV;
Chao Yud3baf7c2015-05-25 18:07:02 +0800859
Chao Yu32f9bc22014-07-12 19:13:54 +0800860 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
Chao Yu91246c22016-07-19 08:27:47 +0800861 if (!old_entry) {
862 if (IS_ERR(old_page))
863 err = PTR_ERR(old_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800864 goto out;
Chao Yu91246c22016-07-19 08:27:47 +0800865 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800866
867 new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, &new_page);
Chao Yu91246c22016-07-19 08:27:47 +0800868 if (!new_entry) {
869 if (IS_ERR(new_page))
870 err = PTR_ERR(new_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800871 goto out_old;
Chao Yu91246c22016-07-19 08:27:47 +0800872 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800873
874 /* prepare for updating ".." directory entry info later */
875 if (old_dir != new_dir) {
876 if (S_ISDIR(old_inode->i_mode)) {
Chao Yu32f9bc22014-07-12 19:13:54 +0800877 old_dir_entry = f2fs_parent_dir(old_inode,
878 &old_dir_page);
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700879 if (!old_dir_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800880 if (IS_ERR(old_dir_page))
881 err = PTR_ERR(old_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800882 goto out_new;
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700883 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800884 }
885
886 if (S_ISDIR(new_inode->i_mode)) {
Chao Yu32f9bc22014-07-12 19:13:54 +0800887 new_dir_entry = f2fs_parent_dir(new_inode,
888 &new_dir_page);
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700889 if (!new_dir_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800890 if (IS_ERR(new_dir_page))
891 err = PTR_ERR(new_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800892 goto out_old_dir;
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700893 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800894 }
895 }
896
897 /*
898 * If cross rename between file and directory those are not
899 * in the same directory, we will inc nlink of file's parent
900 * later, so we should check upper boundary of its nlink.
901 */
902 if ((!old_dir_entry || !new_dir_entry) &&
903 old_dir_entry != new_dir_entry) {
904 old_nlink = old_dir_entry ? -1 : 1;
905 new_nlink = -old_nlink;
906 err = -EMLINK;
907 if ((old_nlink > 0 && old_inode->i_nlink >= F2FS_LINK_MAX) ||
908 (new_nlink > 0 && new_inode->i_nlink >= F2FS_LINK_MAX))
909 goto out_new_dir;
910 }
911
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800912 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800913
Chao Yu32f9bc22014-07-12 19:13:54 +0800914 f2fs_lock_op(sbi);
915
Jaegeuk Kime7d55452015-04-29 17:02:18 -0700916 err = update_dent_inode(old_inode, new_inode, &new_dentry->d_name);
Chao Yu32f9bc22014-07-12 19:13:54 +0800917 if (err)
918 goto out_unlock;
Jaegeuk Kime7d55452015-04-29 17:02:18 -0700919 if (file_enc_name(new_inode))
920 file_set_enc_name(old_inode);
Chao Yu32f9bc22014-07-12 19:13:54 +0800921
Jaegeuk Kime7d55452015-04-29 17:02:18 -0700922 err = update_dent_inode(new_inode, old_inode, &old_dentry->d_name);
Chao Yu32f9bc22014-07-12 19:13:54 +0800923 if (err)
924 goto out_undo;
Jaegeuk Kime7d55452015-04-29 17:02:18 -0700925 if (file_enc_name(old_inode))
926 file_set_enc_name(new_inode);
Chao Yu32f9bc22014-07-12 19:13:54 +0800927
928 /* update ".." directory entry info of old dentry */
929 if (old_dir_entry)
930 f2fs_set_link(old_inode, old_dir_entry, old_dir_page, new_dir);
931
932 /* update ".." directory entry info of new dentry */
933 if (new_dir_entry)
934 f2fs_set_link(new_inode, new_dir_entry, new_dir_page, old_dir);
935
936 /* update directory entry info of old dir inode */
937 f2fs_set_link(old_dir, old_entry, old_page, new_inode);
938
939 down_write(&F2FS_I(old_inode)->i_sem);
940 file_lost_pino(old_inode);
941 up_write(&F2FS_I(old_inode)->i_sem);
942
Deepa Dinamani078cd822016-09-14 07:48:04 -0700943 old_dir->i_ctime = current_time(old_dir);
Chao Yu32f9bc22014-07-12 19:13:54 +0800944 if (old_nlink) {
945 down_write(&F2FS_I(old_dir)->i_sem);
Jaegeuk Kima1961242016-05-20 09:43:20 -0700946 f2fs_i_links_write(old_dir, old_nlink > 0);
Chao Yu32f9bc22014-07-12 19:13:54 +0800947 up_write(&F2FS_I(old_dir)->i_sem);
948 }
Jaegeuk Kimb56ab832016-06-30 19:09:37 -0700949 f2fs_mark_inode_dirty_sync(old_dir);
Chao Yu32f9bc22014-07-12 19:13:54 +0800950
951 /* update directory entry info of new dir inode */
952 f2fs_set_link(new_dir, new_entry, new_page, old_inode);
953
954 down_write(&F2FS_I(new_inode)->i_sem);
955 file_lost_pino(new_inode);
956 up_write(&F2FS_I(new_inode)->i_sem);
957
Deepa Dinamani078cd822016-09-14 07:48:04 -0700958 new_dir->i_ctime = current_time(new_dir);
Chao Yu32f9bc22014-07-12 19:13:54 +0800959 if (new_nlink) {
960 down_write(&F2FS_I(new_dir)->i_sem);
Jaegeuk Kima1961242016-05-20 09:43:20 -0700961 f2fs_i_links_write(new_dir, new_nlink > 0);
Chao Yu32f9bc22014-07-12 19:13:54 +0800962 up_write(&F2FS_I(new_dir)->i_sem);
963 }
Jaegeuk Kimb56ab832016-06-30 19:09:37 -0700964 f2fs_mark_inode_dirty_sync(new_dir);
Chao Yu32f9bc22014-07-12 19:13:54 +0800965
966 f2fs_unlock_op(sbi);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800967
968 if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
969 f2fs_sync_fs(sbi->sb, 1);
Chao Yu32f9bc22014-07-12 19:13:54 +0800970 return 0;
971out_undo:
Jaegeuk Kime7d55452015-04-29 17:02:18 -0700972 /*
973 * Still we may fail to recover name info of f2fs_inode here
974 * Drop it, once its name is set as encrypted
975 */
976 update_dent_inode(old_inode, old_inode, &old_dentry->d_name);
Chao Yu32f9bc22014-07-12 19:13:54 +0800977out_unlock:
978 f2fs_unlock_op(sbi);
979out_new_dir:
980 if (new_dir_entry) {
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800981 f2fs_dentry_kunmap(new_inode, new_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800982 f2fs_put_page(new_dir_page, 0);
983 }
984out_old_dir:
985 if (old_dir_entry) {
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800986 f2fs_dentry_kunmap(old_inode, old_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800987 f2fs_put_page(old_dir_page, 0);
988 }
989out_new:
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800990 f2fs_dentry_kunmap(new_dir, new_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800991 f2fs_put_page(new_page, 0);
992out_old:
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800993 f2fs_dentry_kunmap(old_dir, old_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800994 f2fs_put_page(old_page, 0);
995out:
996 return err;
997}
998
999static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry,
1000 struct inode *new_dir, struct dentry *new_dentry,
1001 unsigned int flags)
1002{
Chao Yu7e01e7ad2015-05-19 17:37:26 +08001003 if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
Chao Yu32f9bc22014-07-12 19:13:54 +08001004 return -EINVAL;
1005
1006 if (flags & RENAME_EXCHANGE) {
1007 return f2fs_cross_rename(old_dir, old_dentry,
1008 new_dir, new_dentry);
1009 }
1010 /*
1011 * VFS has already handled the new dentry existence case,
1012 * here, we just deal with "RENAME_NOREPLACE" as regular rename.
1013 */
Chao Yu7e01e7ad2015-05-19 17:37:26 +08001014 return f2fs_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
Chao Yu32f9bc22014-07-12 19:13:54 +08001015}
1016
Al Viro6b255392015-11-17 10:20:54 -05001017static const char *f2fs_encrypted_get_link(struct dentry *dentry,
Al Virofceef392015-12-29 15:58:39 -05001018 struct inode *inode,
1019 struct delayed_call *done)
Chao Yu50732df2014-06-19 16:23:19 +08001020{
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001021 struct page *cpage = NULL;
1022 char *caddr, *paddr = NULL;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001023 struct fscrypt_str cstr = FSTR_INIT(NULL, 0);
1024 struct fscrypt_str pstr = FSTR_INIT(NULL, 0);
1025 struct fscrypt_symlink_data *sd;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001026 u32 max_size = inode->i_sb->s_blocksize;
1027 int res;
Chao Yu50732df2014-06-19 16:23:19 +08001028
Al Viro6b255392015-11-17 10:20:54 -05001029 if (!dentry)
1030 return ERR_PTR(-ECHILD);
1031
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001032 res = fscrypt_get_encryption_info(inode);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001033 if (res)
1034 return ERR_PTR(res);
Chao Yu50732df2014-06-19 16:23:19 +08001035
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001036 cpage = read_mapping_page(inode->i_mapping, 0, NULL);
1037 if (IS_ERR(cpage))
Linus Torvaldscfcc0ad2015-06-24 20:38:29 -07001038 return ERR_CAST(cpage);
Al Viro21fc61c2015-11-17 01:07:57 -05001039 caddr = page_address(cpage);
Chao Yu50732df2014-06-19 16:23:19 +08001040
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001041 /* Symlink is encrypted */
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001042 sd = (struct fscrypt_symlink_data *)caddr;
Chao Yu922ec352016-02-15 17:54:26 +08001043 cstr.name = sd->encrypted_path;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001044 cstr.len = le16_to_cpu(sd->len);
Jaegeuk Kim8dc0d6a2015-12-24 16:13:09 -08001045
1046 /* this is broken symlink case */
1047 if (unlikely(cstr.len == 0)) {
1048 res = -ENOENT;
1049 goto errout;
1050 }
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -07001051
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001052 if ((cstr.len + sizeof(struct fscrypt_symlink_data) - 1) > max_size) {
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001053 /* Symlink data on the disk is corrupted */
1054 res = -EIO;
1055 goto errout;
1056 }
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001057 res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001058 if (res)
1059 goto errout;
Chao Yu50732df2014-06-19 16:23:19 +08001060
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001061 res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr);
Eric Biggersef1eb3a2016-09-15 17:25:55 -04001062 if (res)
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001063 goto errout;
Chao Yu3c0d84d2015-02-16 16:20:27 +08001064
Jaegeuk Kimc90e09f2016-03-30 13:13:16 -07001065 /* this is broken symlink case */
1066 if (unlikely(pstr.name[0] == 0)) {
1067 res = -ENOENT;
1068 goto errout;
1069 }
1070
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001071 paddr = pstr.name;
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -07001072
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001073 /* Null-terminate the name */
Eric Biggersef1eb3a2016-09-15 17:25:55 -04001074 paddr[pstr.len] = '\0';
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001075
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001076 put_page(cpage);
Al Virofceef392015-12-29 15:58:39 -05001077 set_delayed_call(done, kfree_link, paddr);
1078 return paddr;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001079errout:
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001080 fscrypt_fname_free_buffer(&pstr);
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001081 put_page(cpage);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001082 return ERR_PTR(res);
Chao Yu50732df2014-06-19 16:23:19 +08001083}
1084
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001085const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
1086 .readlink = generic_readlink,
Al Viro6b255392015-11-17 10:20:54 -05001087 .get_link = f2fs_encrypted_get_link,
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001088 .getattr = f2fs_getattr,
1089 .setattr = f2fs_setattr,
Chao Yu3a9e6432015-12-31 18:20:10 +08001090#ifdef CONFIG_F2FS_FS_XATTR
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001091 .listxattr = f2fs_listxattr,
Chao Yu3a9e6432015-12-31 18:20:10 +08001092#endif
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001093};
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001094
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001095const struct inode_operations f2fs_dir_inode_operations = {
1096 .create = f2fs_create,
1097 .lookup = f2fs_lookup,
1098 .link = f2fs_link,
1099 .unlink = f2fs_unlink,
1100 .symlink = f2fs_symlink,
1101 .mkdir = f2fs_mkdir,
1102 .rmdir = f2fs_rmdir,
1103 .mknod = f2fs_mknod,
Miklos Szeredi2773bf02016-09-27 11:03:58 +02001104 .rename = f2fs_rename2,
Chao Yu50732df2014-06-19 16:23:19 +08001105 .tmpfile = f2fs_tmpfile,
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +09001106 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001107 .setattr = f2fs_setattr,
1108 .get_acl = f2fs_get_acl,
Christoph Hellwiga6dda0e2013-12-20 05:16:45 -08001109 .set_acl = f2fs_set_acl,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001110#ifdef CONFIG_F2FS_FS_XATTR
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001111 .listxattr = f2fs_listxattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001112#endif
1113};
1114
1115const struct inode_operations f2fs_symlink_inode_operations = {
1116 .readlink = generic_readlink,
Al Viro6b255392015-11-17 10:20:54 -05001117 .get_link = f2fs_get_link,
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +09001118 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001119 .setattr = f2fs_setattr,
1120#ifdef CONFIG_F2FS_FS_XATTR
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001121 .listxattr = f2fs_listxattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001122#endif
1123};
1124
1125const struct inode_operations f2fs_special_inode_operations = {
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +09001126 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001127 .setattr = f2fs_setattr,
1128 .get_acl = f2fs_get_acl,
Christoph Hellwiga6dda0e2013-12-20 05:16:45 -08001129 .set_acl = f2fs_set_acl,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001130#ifdef CONFIG_F2FS_FS_XATTR
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001131 .listxattr = f2fs_listxattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001132#endif
1133};