blob: b75dc2f4ad57f84889a7bf21d82aaef2f475b1ca [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
Gu Zhenge4795562013-09-27 18:08:30 +0800151 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900152 err = f2fs_add_link(dentry, inode);
153 if (err)
154 goto out;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700155 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900156
157 alloc_nid_done(sbi, ino);
158
Jaegeuk Kim0a364af2013-05-16 08:57:43 +0900159 d_instantiate(dentry, inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900160 unlock_new_inode(inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800161
162 if (IS_DIRSYNC(dir))
163 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim9bb02c32017-04-11 19:01:26 -0700164
165 f2fs_balance_fs(sbi, true);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900166 return 0;
167out:
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700168 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900169 return err;
170}
171
172static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
173 struct dentry *dentry)
174{
David Howells2b0143b2015-03-17 22:25:59 +0000175 struct inode *inode = d_inode(old_dentry);
Jaegeuk Kim40813632014-09-02 15:31:18 -0700176 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Gu Zhenge4795562013-09-27 18:08:30 +0800177 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900178
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700179 if (f2fs_encrypted_inode(dir) &&
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700180 !fscrypt_has_permitted_context(dir, inode))
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700181 return -EPERM;
182
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800183 f2fs_balance_fs(sbi, true);
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900184
Deepa Dinamani078cd822016-09-14 07:48:04 -0700185 inode->i_ctime = current_time(inode);
Jaegeuk Kim6f6fd832013-05-22 12:06:26 +0900186 ihold(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900187
Jaegeuk Kim91942322016-05-20 10:13:22 -0700188 set_inode_flag(inode, FI_INC_LINK);
Gu Zhenge4795562013-09-27 18:08:30 +0800189 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900190 err = f2fs_add_link(dentry, inode);
191 if (err)
192 goto out;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700193 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900194
195 d_instantiate(dentry, inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800196
197 if (IS_DIRSYNC(dir))
198 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900199 return 0;
200out:
Jaegeuk Kim91942322016-05-20 10:13:22 -0700201 clear_inode_flag(inode, FI_INC_LINK);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900202 iput(inode);
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700203 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900204 return err;
205}
206
207struct dentry *f2fs_get_parent(struct dentry *child)
208{
209 struct qstr dotdot = QSTR_INIT("..", 2);
Chao Yu91246c22016-07-19 08:27:47 +0800210 struct page *page;
211 unsigned long ino = f2fs_inode_by_name(d_inode(child), &dotdot, &page);
212 if (!ino) {
213 if (IS_ERR(page))
214 return ERR_CAST(page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900215 return ERR_PTR(-ENOENT);
Chao Yu91246c22016-07-19 08:27:47 +0800216 }
Al Virofc640052016-04-10 01:33:30 -0400217 return d_obtain_alias(f2fs_iget(child->d_sb, ino));
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900218}
219
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700220static int __recover_dot_dentries(struct inode *dir, nid_t pino)
221{
222 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
223 struct qstr dot = QSTR_INIT(".", 1);
224 struct qstr dotdot = QSTR_INIT("..", 2);
225 struct f2fs_dir_entry *de;
226 struct page *page;
227 int err = 0;
228
Chao Yu4e0d8362015-12-30 17:40:31 +0800229 if (f2fs_readonly(sbi->sb)) {
230 f2fs_msg(sbi->sb, KERN_INFO,
231 "skip recovering inline_dots inode (ino:%lu, pino:%u) "
232 "in readonly mountpoint", dir->i_ino, pino);
233 return 0;
234 }
235
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800236 f2fs_balance_fs(sbi, true);
Chao Yud5384172015-12-24 18:03:29 +0800237
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700238 f2fs_lock_op(sbi);
239
240 de = f2fs_find_entry(dir, &dot, &page);
241 if (de) {
242 f2fs_dentry_kunmap(dir, page);
243 f2fs_put_page(page, 0);
Jaegeuk Kim42d96402016-05-25 14:29:11 -0700244 } else if (IS_ERR(page)) {
245 err = PTR_ERR(page);
246 goto out;
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700247 } else {
248 err = __f2fs_add_link(dir, &dot, NULL, dir->i_ino, S_IFDIR);
249 if (err)
250 goto out;
251 }
252
253 de = f2fs_find_entry(dir, &dotdot, &page);
254 if (de) {
255 f2fs_dentry_kunmap(dir, page);
256 f2fs_put_page(page, 0);
Jaegeuk Kim42d96402016-05-25 14:29:11 -0700257 } else if (IS_ERR(page)) {
258 err = PTR_ERR(page);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700259 } else {
260 err = __f2fs_add_link(dir, &dotdot, NULL, pino, S_IFDIR);
261 }
262out:
Jaegeuk Kim205b9822016-05-20 09:52:20 -0700263 if (!err)
Jaegeuk Kim91942322016-05-20 10:13:22 -0700264 clear_inode_flag(dir, FI_INLINE_DOTS);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700265
266 f2fs_unlock_op(sbi);
267 return err;
268}
269
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900270static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
271 unsigned int flags)
272{
273 struct inode *inode = NULL;
274 struct f2fs_dir_entry *de;
275 struct page *page;
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700276 nid_t ino;
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700277 int err = 0;
Liu Xue8c2b1432016-02-26 06:39:23 +0000278 unsigned int root_ino = F2FS_ROOT_INO(F2FS_I_SB(dir));
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900279
Jaegeuk Kim8074bb52016-02-23 09:21:37 -0800280 if (f2fs_encrypted_inode(dir)) {
281 int res = fscrypt_get_encryption_info(dir);
282
283 /*
284 * DCACHE_ENCRYPTED_WITH_KEY is set if the dentry is
285 * created while the directory was encrypted and we
286 * don't have access to the key.
287 */
288 if (fscrypt_has_encryption_key(dir))
289 fscrypt_set_encrypted_dentry(dentry);
290 fscrypt_set_d_op(dentry);
291 if (res && res != -ENOKEY)
292 return ERR_PTR(res);
293 }
294
Jaegeuk Kim5a20d332013-03-03 13:58:05 +0900295 if (dentry->d_name.len > F2FS_NAME_LEN)
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900296 return ERR_PTR(-ENAMETOOLONG);
297
298 de = f2fs_find_entry(dir, &dentry->d_name, &page);
Jaegeuk Kimeb4246d2016-05-27 10:10:41 -0700299 if (!de) {
300 if (IS_ERR(page))
301 return (struct dentry *)page;
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700302 return d_splice_alias(inode, dentry);
Jaegeuk Kimeb4246d2016-05-27 10:10:41 -0700303 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900304
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700305 ino = le32_to_cpu(de->ino);
306 f2fs_dentry_kunmap(dir, page);
307 f2fs_put_page(page, 0);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700308
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700309 inode = f2fs_iget(dir->i_sb, ino);
310 if (IS_ERR(inode))
311 return ERR_CAST(inode);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700312
Liu Xue8c2b1432016-02-26 06:39:23 +0000313 if ((dir->i_ino == root_ino) && f2fs_has_inline_dots(dir)) {
314 err = __recover_dot_dentries(dir, root_ino);
315 if (err)
316 goto err_out;
317 }
318
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700319 if (f2fs_has_inline_dots(inode)) {
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700320 err = __recover_dot_dentries(inode, dir->i_ino);
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700321 if (err)
322 goto err_out;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900323 }
Dan Carpenter07fe8d42016-12-16 11:18:15 +0300324 if (f2fs_encrypted_inode(dir) &&
325 (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
326 !fscrypt_has_permitted_context(dir, inode)) {
Eric Biggersfaac7fd2017-04-07 10:58:39 -0700327 f2fs_msg(inode->i_sb, KERN_WARNING,
328 "Inconsistent encryption contexts: %lu/%lu",
329 dir->i_ino, inode->i_ino);
330 err = -EPERM;
Chao Yud7267322016-03-10 22:24:23 +0800331 goto err_out;
Jaegeuk Kim8074bb52016-02-23 09:21:37 -0800332 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900333 return d_splice_alias(inode, dentry);
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700334
335err_out:
Chao Yud7267322016-03-10 22:24:23 +0800336 iput(inode);
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700337 return ERR_PTR(err);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900338}
339
340static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
341{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700342 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
David Howells2b0143b2015-03-17 22:25:59 +0000343 struct inode *inode = d_inode(dentry);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900344 struct f2fs_dir_entry *de;
345 struct page *page;
346 int err = -ENOENT;
347
Namjae Jeona2a4a7e2013-04-20 01:28:40 +0900348 trace_f2fs_unlink_enter(dir, dentry);
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900349
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900350 de = f2fs_find_entry(dir, &dentry->d_name, &page);
Chao Yu91246c22016-07-19 08:27:47 +0800351 if (!de) {
352 if (IS_ERR(page))
353 err = PTR_ERR(page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900354 goto fail;
Chao Yu91246c22016-07-19 08:27:47 +0800355 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900356
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800357 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800358
Jaegeuk Kimccaaca22013-10-08 10:19:28 +0900359 f2fs_lock_op(sbi);
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900360 err = acquire_orphan_inode(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900361 if (err) {
Jaegeuk Kimccaaca22013-10-08 10:19:28 +0900362 f2fs_unlock_op(sbi);
Jaegeuk Kim9486ba42014-11-21 16:36:28 -0800363 f2fs_dentry_kunmap(dir, page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900364 f2fs_put_page(page, 0);
365 goto fail;
366 }
Chao Yudbeacf02014-09-24 18:17:04 +0800367 f2fs_delete_entry(de, page, dir, inode);
Gu Zhenge4795562013-09-27 18:08:30 +0800368 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900369
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800370 if (IS_DIRSYNC(dir))
371 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900372fail:
Namjae Jeona2a4a7e2013-04-20 01:28:40 +0900373 trace_f2fs_unlink_exit(inode, err);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900374 return err;
375}
376
Al Viro6b255392015-11-17 10:20:54 -0500377static const char *f2fs_get_link(struct dentry *dentry,
Al Virofceef392015-12-29 15:58:39 -0500378 struct inode *inode,
379 struct delayed_call *done)
Jaegeuk Kimfeb7cbb2015-04-15 13:49:55 -0700380{
Al Virofceef392015-12-29 15:58:39 -0500381 const char *link = page_get_link(dentry, inode, done);
Al Viro680baac2015-05-02 13:32:22 -0400382 if (!IS_ERR(link) && !*link) {
383 /* this is broken symlink case */
Al Virofceef392015-12-29 15:58:39 -0500384 do_delayed_call(done);
385 clear_delayed_call(done);
Al Viro680baac2015-05-02 13:32:22 -0400386 link = ERR_PTR(-ENOENT);
Jaegeuk Kimfeb7cbb2015-04-15 13:49:55 -0700387 }
Al Viro680baac2015-05-02 13:32:22 -0400388 return link;
Jaegeuk Kimfeb7cbb2015-04-15 13:49:55 -0700389}
390
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900391static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
392 const char *symname)
393{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700394 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900395 struct inode *inode;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700396 size_t len = strlen(symname);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700397 struct fscrypt_str disk_link = FSTR_INIT((char *)symname, len + 1);
398 struct fscrypt_symlink_data *sd = NULL;
Gu Zhenge4795562013-09-27 18:08:30 +0800399 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900400
Chao Yu922ec352016-02-15 17:54:26 +0800401 if (f2fs_encrypted_inode(dir)) {
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700402 err = fscrypt_get_encryption_info(dir);
Chao Yu922ec352016-02-15 17:54:26 +0800403 if (err)
404 return err;
405
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700406 if (!fscrypt_has_encryption_key(dir))
Eric Biggers54475f52016-12-05 11:12:44 -0800407 return -ENOKEY;
Chao Yu922ec352016-02-15 17:54:26 +0800408
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700409 disk_link.len = (fscrypt_fname_encrypted_size(dir, len) +
410 sizeof(struct fscrypt_symlink_data));
Chao Yu922ec352016-02-15 17:54:26 +0800411 }
412
413 if (disk_link.len > dir->i_sb->s_blocksize)
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700414 return -ENAMETOOLONG;
415
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900416 inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO);
417 if (IS_ERR(inode))
418 return PTR_ERR(inode);
419
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700420 if (f2fs_encrypted_inode(inode))
421 inode->i_op = &f2fs_encrypted_symlink_inode_operations;
422 else
423 inode->i_op = &f2fs_symlink_inode_operations;
Al Viro21fc61c2015-11-17 01:07:57 -0500424 inode_nohighmem(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900425 inode->i_mapping->a_ops = &f2fs_dblock_aops;
426
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 Biggers54475f52016-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:
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900466 d_instantiate(dentry, inode);
467 unlock_new_inode(inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800468
Jaegeuk Kimd0cae972015-04-15 13:37:53 -0700469 /*
470 * Let's flush symlink data in order to avoid broken symlink as much as
471 * possible. Nevertheless, fsyncing is the best way, but there is no
472 * way to get a file descriptor in order to flush that.
473 *
474 * Note that, it needs to do dir->fsync to make this recoverable.
475 * If the symlink path is stored into inline_data, there is no
476 * performance regression.
477 */
Chao Yua6be0142015-10-22 18:23:08 +0800478 if (!err) {
Chao Yu922ec352016-02-15 17:54:26 +0800479 filemap_write_and_wait_range(inode->i_mapping, 0,
480 disk_link.len - 1);
Jaegeuk Kimd0cae972015-04-15 13:37:53 -0700481
Chao Yua6be0142015-10-22 18:23:08 +0800482 if (IS_DIRSYNC(dir))
483 f2fs_sync_fs(sbi->sb, 1);
484 } else {
485 f2fs_unlink(dir, dentry);
486 }
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700487
488 kfree(sd);
Jaegeuk Kim9bb02c32017-04-11 19:01:26 -0700489
490 f2fs_balance_fs(sbi, true);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900491 return err;
492out:
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700493 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900494 return err;
495}
496
497static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
498{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700499 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900500 struct inode *inode;
Gu Zhenge4795562013-09-27 18:08:30 +0800501 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900502
503 inode = f2fs_new_inode(dir, S_IFDIR | mode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900504 if (IS_ERR(inode))
Namjae Jeon61412b62012-12-01 10:56:25 +0900505 return PTR_ERR(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900506
507 inode->i_op = &f2fs_dir_inode_operations;
508 inode->i_fop = &f2fs_dir_operations;
509 inode->i_mapping->a_ops = &f2fs_dblock_aops;
Chao Yu560d4672015-02-07 17:36:15 +0800510 mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_HIGH_ZERO);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900511
Jaegeuk Kim91942322016-05-20 10:13:22 -0700512 set_inode_flag(inode, FI_INC_LINK);
Gu Zhenge4795562013-09-27 18:08:30 +0800513 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900514 err = f2fs_add_link(dentry, inode);
515 if (err)
516 goto out_fail;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700517 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900518
519 alloc_nid_done(sbi, inode->i_ino);
520
521 d_instantiate(dentry, inode);
522 unlock_new_inode(inode);
523
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800524 if (IS_DIRSYNC(dir))
525 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim9bb02c32017-04-11 19:01:26 -0700526
527 f2fs_balance_fs(sbi, true);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900528 return 0;
529
530out_fail:
Jaegeuk Kim91942322016-05-20 10:13:22 -0700531 clear_inode_flag(inode, FI_INC_LINK);
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700532 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900533 return err;
534}
535
536static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)
537{
David Howells2b0143b2015-03-17 22:25:59 +0000538 struct inode *inode = d_inode(dentry);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900539 if (f2fs_empty_dir(inode))
540 return f2fs_unlink(dir, dentry);
541 return -ENOTEMPTY;
542}
543
544static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
545 umode_t mode, dev_t rdev)
546{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700547 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900548 struct inode *inode;
549 int err = 0;
550
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900551 inode = f2fs_new_inode(dir, mode);
552 if (IS_ERR(inode))
553 return PTR_ERR(inode);
554
555 init_special_inode(inode, inode->i_mode, rdev);
556 inode->i_op = &f2fs_special_inode_operations;
557
Gu Zhenge4795562013-09-27 18:08:30 +0800558 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900559 err = f2fs_add_link(dentry, inode);
560 if (err)
561 goto out;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700562 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900563
564 alloc_nid_done(sbi, inode->i_ino);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800565
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900566 d_instantiate(dentry, inode);
567 unlock_new_inode(inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800568
569 if (IS_DIRSYNC(dir))
570 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim9bb02c32017-04-11 19:01:26 -0700571
572 f2fs_balance_fs(sbi, true);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900573 return 0;
574out:
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700575 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900576 return err;
577}
578
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800579static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,
580 umode_t mode, struct inode **whiteout)
581{
582 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
583 struct inode *inode;
584 int err;
585
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800586 inode = f2fs_new_inode(dir, mode);
587 if (IS_ERR(inode))
588 return PTR_ERR(inode);
589
590 if (whiteout) {
591 init_special_inode(inode, inode->i_mode, WHITEOUT_DEV);
592 inode->i_op = &f2fs_special_inode_operations;
593 } else {
594 inode->i_op = &f2fs_file_inode_operations;
595 inode->i_fop = &f2fs_file_operations;
596 inode->i_mapping->a_ops = &f2fs_dblock_aops;
597 }
598
599 f2fs_lock_op(sbi);
600 err = acquire_orphan_inode(sbi);
601 if (err)
602 goto out;
603
604 err = f2fs_do_tmpfile(inode, dir);
605 if (err)
606 goto release_out;
607
608 /*
609 * add this non-linked tmpfile to orphan list, in this way we could
610 * remove all unused data of tmpfile after abnormal power-off.
611 */
Jaegeuk Kim67c37582016-06-13 18:27:02 -0700612 add_orphan_inode(inode);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800613 alloc_nid_done(sbi, inode->i_ino);
614
615 if (whiteout) {
Jaegeuk Kima1961242016-05-20 09:43:20 -0700616 f2fs_i_links_write(inode, false);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800617 *whiteout = inode;
618 } else {
619 d_tmpfile(dentry, inode);
620 }
Jaegeuk Kima1961242016-05-20 09:43:20 -0700621 /* link_count was changed by d_tmpfile as well. */
622 f2fs_unlock_op(sbi);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800623 unlock_new_inode(inode);
Jaegeuk Kim9bb02c32017-04-11 19:01:26 -0700624
625 f2fs_balance_fs(sbi, true);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800626 return 0;
627
628release_out:
629 release_orphan_inode(sbi);
630out:
631 handle_failed_inode(inode);
632 return err;
633}
634
635static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
636{
Jaegeuk Kim304eecc2015-05-19 16:11:40 -0700637 if (f2fs_encrypted_inode(dir)) {
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700638 int err = fscrypt_get_encryption_info(dir);
Jaegeuk Kim304eecc2015-05-19 16:11:40 -0700639 if (err)
640 return err;
641 }
642
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800643 return __f2fs_tmpfile(dir, dentry, mode, NULL);
644}
645
646static int f2fs_create_whiteout(struct inode *dir, struct inode **whiteout)
647{
648 return __f2fs_tmpfile(dir, NULL, S_IFCHR | WHITEOUT_MODE, whiteout);
649}
650
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900651static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800652 struct inode *new_dir, struct dentry *new_dentry,
653 unsigned int flags)
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900654{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700655 struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
David Howells2b0143b2015-03-17 22:25:59 +0000656 struct inode *old_inode = d_inode(old_dentry);
657 struct inode *new_inode = d_inode(new_dentry);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800658 struct inode *whiteout = NULL;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900659 struct page *old_dir_page;
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800660 struct page *old_page, *new_page = NULL;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900661 struct f2fs_dir_entry *old_dir_entry = NULL;
662 struct f2fs_dir_entry *old_entry;
663 struct f2fs_dir_entry *new_entry;
Chao Yu993a0492016-02-17 16:47:05 +0800664 bool is_old_inline = f2fs_has_inline_dentry(old_dir);
Gu Zhenge4795562013-09-27 18:08:30 +0800665 int err = -ENOENT;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900666
Jaegeuk Kim363fa4e2016-12-28 17:31:15 -0800667 if ((f2fs_encrypted_inode(old_dir) &&
668 !fscrypt_has_encryption_key(old_dir)) ||
669 (f2fs_encrypted_inode(new_dir) &&
670 !fscrypt_has_encryption_key(new_dir)))
671 return -ENOKEY;
672
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700673 if ((old_dir != new_dir) && f2fs_encrypted_inode(new_dir) &&
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700674 !fscrypt_has_permitted_context(new_dir, old_inode)) {
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700675 err = -EPERM;
676 goto out;
677 }
678
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900679 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
Chao Yu91246c22016-07-19 08:27:47 +0800680 if (!old_entry) {
681 if (IS_ERR(old_page))
682 err = PTR_ERR(old_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900683 goto out;
Chao Yu91246c22016-07-19 08:27:47 +0800684 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900685
686 if (S_ISDIR(old_inode->i_mode)) {
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900687 old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page);
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700688 if (!old_dir_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800689 if (IS_ERR(old_dir_page))
690 err = PTR_ERR(old_dir_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900691 goto out_old;
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700692 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900693 }
694
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800695 if (flags & RENAME_WHITEOUT) {
696 err = f2fs_create_whiteout(old_dir, &whiteout);
697 if (err)
698 goto out_dir;
699 }
700
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900701 if (new_inode) {
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900702
703 err = -ENOTEMPTY;
704 if (old_dir_entry && !f2fs_empty_dir(new_inode))
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800705 goto out_whiteout;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900706
707 err = -ENOENT;
708 new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name,
709 &new_page);
Chao Yu91246c22016-07-19 08:27:47 +0800710 if (!new_entry) {
711 if (IS_ERR(new_page))
712 err = PTR_ERR(new_page);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800713 goto out_whiteout;
Chao Yu91246c22016-07-19 08:27:47 +0800714 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900715
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800716 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800717
Chao Yu12560102014-06-24 14:16:24 +0800718 f2fs_lock_op(sbi);
719
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900720 err = acquire_orphan_inode(sbi);
721 if (err)
722 goto put_out_dir;
723
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900724 f2fs_set_link(new_dir, new_entry, new_page, old_inode);
725
Deepa Dinamani078cd822016-09-14 07:48:04 -0700726 new_inode->i_ctime = current_time(new_inode);
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900727 down_write(&F2FS_I(new_inode)->i_sem);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900728 if (old_dir_entry)
Jaegeuk Kima1961242016-05-20 09:43:20 -0700729 f2fs_i_links_write(new_inode, false);
730 f2fs_i_links_write(new_inode, false);
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900731 up_write(&F2FS_I(new_inode)->i_sem);
732
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900733 if (!new_inode->i_nlink)
Jaegeuk Kim67c37582016-06-13 18:27:02 -0700734 add_orphan_inode(new_inode);
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900735 else
736 release_orphan_inode(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900737 } else {
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800738 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800739
Chao Yu12560102014-06-24 14:16:24 +0800740 f2fs_lock_op(sbi);
741
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900742 err = f2fs_add_link(new_dentry, old_inode);
Chao Yu12560102014-06-24 14:16:24 +0800743 if (err) {
744 f2fs_unlock_op(sbi);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800745 goto out_whiteout;
Chao Yu12560102014-06-24 14:16:24 +0800746 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900747
Jaegeuk Kimee6d1822016-05-20 16:32:49 -0700748 if (old_dir_entry)
Jaegeuk Kima1961242016-05-20 09:43:20 -0700749 f2fs_i_links_write(new_dir, true);
Chao Yu993a0492016-02-17 16:47:05 +0800750
751 /*
752 * old entry and new entry can locate in the same inline
753 * dentry in inode, when attaching new entry in inline dentry,
754 * it could force inline dentry conversion, after that,
755 * old_entry and old_page will point to wrong address, in
756 * order to avoid this, let's do the check and update here.
757 */
758 if (is_old_inline && !f2fs_has_inline_dentry(old_dir)) {
759 f2fs_put_page(old_page, 0);
760 old_page = NULL;
761
762 old_entry = f2fs_find_entry(old_dir,
763 &old_dentry->d_name, &old_page);
764 if (!old_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800765 err = -ENOENT;
766 if (IS_ERR(old_page))
767 err = PTR_ERR(old_page);
Chao Yu993a0492016-02-17 16:47:05 +0800768 f2fs_unlock_op(sbi);
769 goto out_whiteout;
770 }
771 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900772 }
773
Jaegeuk Kimb2c08292014-06-30 18:09:55 +0900774 down_write(&F2FS_I(old_inode)->i_sem);
Sheng Yongb855bf02017-06-26 10:41:36 +0800775 if (!old_dir_entry || whiteout)
776 file_lost_pino(old_inode);
777 else
778 F2FS_I(old_inode)->i_pino = new_dir->i_ino;
Jaegeuk Kimb2c08292014-06-30 18:09:55 +0900779 up_write(&F2FS_I(old_inode)->i_sem);
780
Deepa Dinamani078cd822016-09-14 07:48:04 -0700781 old_inode->i_ctime = current_time(old_inode);
Jaegeuk Kim7c457292016-10-14 11:51:23 -0700782 f2fs_mark_inode_dirty_sync(old_inode, false);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900783
Chao Yudbeacf02014-09-24 18:17:04 +0800784 f2fs_delete_entry(old_entry, old_page, old_dir, NULL);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900785
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800786 if (whiteout) {
787 whiteout->i_state |= I_LINKABLE;
Jaegeuk Kim91942322016-05-20 10:13:22 -0700788 set_inode_flag(whiteout, FI_INC_LINK);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800789 err = f2fs_add_link(old_dentry, whiteout);
790 if (err)
791 goto put_out_dir;
792 whiteout->i_state &= ~I_LINKABLE;
793 iput(whiteout);
794 }
795
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900796 if (old_dir_entry) {
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800797 if (old_dir != new_dir && !whiteout) {
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900798 f2fs_set_link(old_inode, old_dir_entry,
799 old_dir_page, new_dir);
800 } else {
Jaegeuk Kim9486ba42014-11-21 16:36:28 -0800801 f2fs_dentry_kunmap(old_inode, old_dir_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900802 f2fs_put_page(old_dir_page, 0);
803 }
Jaegeuk Kima1961242016-05-20 09:43:20 -0700804 f2fs_i_links_write(old_dir, false);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900805 }
806
Gu Zhenge4795562013-09-27 18:08:30 +0800807 f2fs_unlock_op(sbi);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800808
809 if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
810 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900811 return 0;
812
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900813put_out_dir:
Chao Yu12560102014-06-24 14:16:24 +0800814 f2fs_unlock_op(sbi);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800815 if (new_page) {
816 f2fs_dentry_kunmap(new_dir, new_page);
817 f2fs_put_page(new_page, 0);
818 }
819out_whiteout:
820 if (whiteout)
821 iput(whiteout);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900822out_dir:
823 if (old_dir_entry) {
Jaegeuk Kim9486ba42014-11-21 16:36:28 -0800824 f2fs_dentry_kunmap(old_inode, old_dir_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900825 f2fs_put_page(old_dir_page, 0);
826 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900827out_old:
Jaegeuk Kim9486ba42014-11-21 16:36:28 -0800828 f2fs_dentry_kunmap(old_dir, old_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900829 f2fs_put_page(old_page, 0);
830out:
831 return err;
832}
833
Chao Yu32f9bc22014-07-12 19:13:54 +0800834static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
835 struct inode *new_dir, struct dentry *new_dentry)
836{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700837 struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
David Howells2b0143b2015-03-17 22:25:59 +0000838 struct inode *old_inode = d_inode(old_dentry);
839 struct inode *new_inode = d_inode(new_dentry);
Chao Yu32f9bc22014-07-12 19:13:54 +0800840 struct page *old_dir_page, *new_dir_page;
841 struct page *old_page, *new_page;
842 struct f2fs_dir_entry *old_dir_entry = NULL, *new_dir_entry = NULL;
843 struct f2fs_dir_entry *old_entry, *new_entry;
844 int old_nlink = 0, new_nlink = 0;
845 int err = -ENOENT;
846
Jaegeuk Kim363fa4e2016-12-28 17:31:15 -0800847 if ((f2fs_encrypted_inode(old_dir) &&
848 !fscrypt_has_encryption_key(old_dir)) ||
849 (f2fs_encrypted_inode(new_dir) &&
850 !fscrypt_has_encryption_key(new_dir)))
851 return -ENOKEY;
852
Chao Yud3baf7c2015-05-25 18:07:02 +0800853 if ((f2fs_encrypted_inode(old_dir) || f2fs_encrypted_inode(new_dir)) &&
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700854 (old_dir != new_dir) &&
855 (!fscrypt_has_permitted_context(new_dir, old_inode) ||
856 !fscrypt_has_permitted_context(old_dir, new_inode)))
Chao Yud3baf7c2015-05-25 18:07:02 +0800857 return -EPERM;
858
Chao Yu32f9bc22014-07-12 19:13:54 +0800859 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
Chao Yu91246c22016-07-19 08:27:47 +0800860 if (!old_entry) {
861 if (IS_ERR(old_page))
862 err = PTR_ERR(old_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800863 goto out;
Chao Yu91246c22016-07-19 08:27:47 +0800864 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800865
866 new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, &new_page);
Chao Yu91246c22016-07-19 08:27:47 +0800867 if (!new_entry) {
868 if (IS_ERR(new_page))
869 err = PTR_ERR(new_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800870 goto out_old;
Chao Yu91246c22016-07-19 08:27:47 +0800871 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800872
873 /* prepare for updating ".." directory entry info later */
874 if (old_dir != new_dir) {
875 if (S_ISDIR(old_inode->i_mode)) {
Chao Yu32f9bc22014-07-12 19:13:54 +0800876 old_dir_entry = f2fs_parent_dir(old_inode,
877 &old_dir_page);
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700878 if (!old_dir_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800879 if (IS_ERR(old_dir_page))
880 err = PTR_ERR(old_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800881 goto out_new;
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700882 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800883 }
884
885 if (S_ISDIR(new_inode->i_mode)) {
Chao Yu32f9bc22014-07-12 19:13:54 +0800886 new_dir_entry = f2fs_parent_dir(new_inode,
887 &new_dir_page);
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700888 if (!new_dir_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800889 if (IS_ERR(new_dir_page))
890 err = PTR_ERR(new_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800891 goto out_old_dir;
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700892 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800893 }
894 }
895
896 /*
897 * If cross rename between file and directory those are not
898 * in the same directory, we will inc nlink of file's parent
899 * later, so we should check upper boundary of its nlink.
900 */
901 if ((!old_dir_entry || !new_dir_entry) &&
902 old_dir_entry != new_dir_entry) {
903 old_nlink = old_dir_entry ? -1 : 1;
904 new_nlink = -old_nlink;
905 err = -EMLINK;
Kinglong Meee2f0e962017-03-04 21:48:28 +0800906 if ((old_nlink > 0 && old_dir->i_nlink >= F2FS_LINK_MAX) ||
907 (new_nlink > 0 && new_dir->i_nlink >= F2FS_LINK_MAX))
Chao Yu32f9bc22014-07-12 19:13:54 +0800908 goto out_new_dir;
909 }
910
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800911 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800912
Chao Yu32f9bc22014-07-12 19:13:54 +0800913 f2fs_lock_op(sbi);
914
Chao Yu32f9bc22014-07-12 19:13:54 +0800915 /* update ".." directory entry info of old dentry */
916 if (old_dir_entry)
917 f2fs_set_link(old_inode, old_dir_entry, old_dir_page, new_dir);
918
919 /* update ".." directory entry info of new dentry */
920 if (new_dir_entry)
921 f2fs_set_link(new_inode, new_dir_entry, new_dir_page, old_dir);
922
923 /* update directory entry info of old dir inode */
924 f2fs_set_link(old_dir, old_entry, old_page, new_inode);
925
926 down_write(&F2FS_I(old_inode)->i_sem);
927 file_lost_pino(old_inode);
928 up_write(&F2FS_I(old_inode)->i_sem);
929
Deepa Dinamani078cd822016-09-14 07:48:04 -0700930 old_dir->i_ctime = current_time(old_dir);
Chao Yu32f9bc22014-07-12 19:13:54 +0800931 if (old_nlink) {
932 down_write(&F2FS_I(old_dir)->i_sem);
Jaegeuk Kima1961242016-05-20 09:43:20 -0700933 f2fs_i_links_write(old_dir, old_nlink > 0);
Chao Yu32f9bc22014-07-12 19:13:54 +0800934 up_write(&F2FS_I(old_dir)->i_sem);
935 }
Jaegeuk Kim7c457292016-10-14 11:51:23 -0700936 f2fs_mark_inode_dirty_sync(old_dir, false);
Chao Yu32f9bc22014-07-12 19:13:54 +0800937
938 /* update directory entry info of new dir inode */
939 f2fs_set_link(new_dir, new_entry, new_page, old_inode);
940
941 down_write(&F2FS_I(new_inode)->i_sem);
942 file_lost_pino(new_inode);
943 up_write(&F2FS_I(new_inode)->i_sem);
944
Deepa Dinamani078cd822016-09-14 07:48:04 -0700945 new_dir->i_ctime = current_time(new_dir);
Chao Yu32f9bc22014-07-12 19:13:54 +0800946 if (new_nlink) {
947 down_write(&F2FS_I(new_dir)->i_sem);
Jaegeuk Kima1961242016-05-20 09:43:20 -0700948 f2fs_i_links_write(new_dir, new_nlink > 0);
Chao Yu32f9bc22014-07-12 19:13:54 +0800949 up_write(&F2FS_I(new_dir)->i_sem);
950 }
Jaegeuk Kim7c457292016-10-14 11:51:23 -0700951 f2fs_mark_inode_dirty_sync(new_dir, false);
Chao Yu32f9bc22014-07-12 19:13:54 +0800952
953 f2fs_unlock_op(sbi);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800954
955 if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
956 f2fs_sync_fs(sbi->sb, 1);
Chao Yu32f9bc22014-07-12 19:13:54 +0800957 return 0;
Chao Yu32f9bc22014-07-12 19:13:54 +0800958out_new_dir:
959 if (new_dir_entry) {
Jaegeuk Kim9486ba42014-11-21 16:36:28 -0800960 f2fs_dentry_kunmap(new_inode, new_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800961 f2fs_put_page(new_dir_page, 0);
962 }
963out_old_dir:
964 if (old_dir_entry) {
Jaegeuk Kim9486ba42014-11-21 16:36:28 -0800965 f2fs_dentry_kunmap(old_inode, old_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800966 f2fs_put_page(old_dir_page, 0);
967 }
968out_new:
Jaegeuk Kim9486ba42014-11-21 16:36:28 -0800969 f2fs_dentry_kunmap(new_dir, new_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800970 f2fs_put_page(new_page, 0);
971out_old:
Jaegeuk Kim9486ba42014-11-21 16:36:28 -0800972 f2fs_dentry_kunmap(old_dir, old_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800973 f2fs_put_page(old_page, 0);
974out:
975 return err;
976}
977
978static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry,
979 struct inode *new_dir, struct dentry *new_dentry,
980 unsigned int flags)
981{
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800982 if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
Chao Yu32f9bc22014-07-12 19:13:54 +0800983 return -EINVAL;
984
985 if (flags & RENAME_EXCHANGE) {
986 return f2fs_cross_rename(old_dir, old_dentry,
987 new_dir, new_dentry);
988 }
989 /*
990 * VFS has already handled the new dentry existence case,
991 * here, we just deal with "RENAME_NOREPLACE" as regular rename.
992 */
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800993 return f2fs_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
Chao Yu32f9bc22014-07-12 19:13:54 +0800994}
995
Al Viro6b255392015-11-17 10:20:54 -0500996static const char *f2fs_encrypted_get_link(struct dentry *dentry,
Al Virofceef392015-12-29 15:58:39 -0500997 struct inode *inode,
998 struct delayed_call *done)
Chao Yu50732df2014-06-19 16:23:19 +0800999{
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001000 struct page *cpage = NULL;
1001 char *caddr, *paddr = NULL;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001002 struct fscrypt_str cstr = FSTR_INIT(NULL, 0);
1003 struct fscrypt_str pstr = FSTR_INIT(NULL, 0);
1004 struct fscrypt_symlink_data *sd;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001005 u32 max_size = inode->i_sb->s_blocksize;
1006 int res;
Chao Yu50732df2014-06-19 16:23:19 +08001007
Al Viro6b255392015-11-17 10:20:54 -05001008 if (!dentry)
1009 return ERR_PTR(-ECHILD);
1010
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001011 res = fscrypt_get_encryption_info(inode);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001012 if (res)
1013 return ERR_PTR(res);
Chao Yu50732df2014-06-19 16:23:19 +08001014
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001015 cpage = read_mapping_page(inode->i_mapping, 0, NULL);
1016 if (IS_ERR(cpage))
Linus Torvaldscfcc0ad2015-06-24 20:38:29 -07001017 return ERR_CAST(cpage);
Al Viro21fc61c2015-11-17 01:07:57 -05001018 caddr = page_address(cpage);
Chao Yu50732df2014-06-19 16:23:19 +08001019
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001020 /* Symlink is encrypted */
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001021 sd = (struct fscrypt_symlink_data *)caddr;
Chao Yu922ec352016-02-15 17:54:26 +08001022 cstr.name = sd->encrypted_path;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001023 cstr.len = le16_to_cpu(sd->len);
Jaegeuk Kim8dc0d6a2015-12-24 16:13:09 -08001024
1025 /* this is broken symlink case */
1026 if (unlikely(cstr.len == 0)) {
1027 res = -ENOENT;
1028 goto errout;
1029 }
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -07001030
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001031 if ((cstr.len + sizeof(struct fscrypt_symlink_data) - 1) > max_size) {
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001032 /* Symlink data on the disk is corrupted */
1033 res = -EIO;
1034 goto errout;
1035 }
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001036 res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001037 if (res)
1038 goto errout;
Chao Yu50732df2014-06-19 16:23:19 +08001039
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001040 res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr);
Eric Biggersef1eb3a2016-09-15 17:25:55 -04001041 if (res)
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001042 goto errout;
Chao Yu3c0d84d2015-02-16 16:20:27 +08001043
Jaegeuk Kimc90e09f2016-03-30 13:13:16 -07001044 /* this is broken symlink case */
1045 if (unlikely(pstr.name[0] == 0)) {
1046 res = -ENOENT;
1047 goto errout;
1048 }
1049
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001050 paddr = pstr.name;
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -07001051
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001052 /* Null-terminate the name */
Eric Biggersef1eb3a2016-09-15 17:25:55 -04001053 paddr[pstr.len] = '\0';
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001054
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001055 put_page(cpage);
Al Virofceef392015-12-29 15:58:39 -05001056 set_delayed_call(done, kfree_link, paddr);
1057 return paddr;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001058errout:
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001059 fscrypt_fname_free_buffer(&pstr);
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001060 put_page(cpage);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001061 return ERR_PTR(res);
Chao Yu50732df2014-06-19 16:23:19 +08001062}
1063
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001064const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
Al Viro6b255392015-11-17 10:20:54 -05001065 .get_link = f2fs_encrypted_get_link,
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001066 .getattr = f2fs_getattr,
1067 .setattr = f2fs_setattr,
Chao Yu3a9e6432015-12-31 18:20:10 +08001068#ifdef CONFIG_F2FS_FS_XATTR
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001069 .listxattr = f2fs_listxattr,
Chao Yu3a9e6432015-12-31 18:20:10 +08001070#endif
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001071};
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001072
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001073const struct inode_operations f2fs_dir_inode_operations = {
1074 .create = f2fs_create,
1075 .lookup = f2fs_lookup,
1076 .link = f2fs_link,
1077 .unlink = f2fs_unlink,
1078 .symlink = f2fs_symlink,
1079 .mkdir = f2fs_mkdir,
1080 .rmdir = f2fs_rmdir,
1081 .mknod = f2fs_mknod,
Miklos Szeredi2773bf02016-09-27 11:03:58 +02001082 .rename = f2fs_rename2,
Chao Yu50732df2014-06-19 16:23:19 +08001083 .tmpfile = f2fs_tmpfile,
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +09001084 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001085 .setattr = f2fs_setattr,
1086 .get_acl = f2fs_get_acl,
Christoph Hellwiga6dda0e2013-12-20 05:16:45 -08001087 .set_acl = f2fs_set_acl,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001088#ifdef CONFIG_F2FS_FS_XATTR
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001089 .listxattr = f2fs_listxattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001090#endif
1091};
1092
1093const struct inode_operations f2fs_symlink_inode_operations = {
Al Viro6b255392015-11-17 10:20:54 -05001094 .get_link = f2fs_get_link,
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +09001095 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001096 .setattr = f2fs_setattr,
1097#ifdef CONFIG_F2FS_FS_XATTR
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001098 .listxattr = f2fs_listxattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001099#endif
1100};
1101
1102const struct inode_operations f2fs_special_inode_operations = {
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +09001103 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001104 .setattr = f2fs_setattr,
1105 .get_acl = f2fs_get_acl,
Christoph Hellwiga6dda0e2013-12-20 05:16:45 -08001106 .set_acl = f2fs_set_acl,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001107#ifdef CONFIG_F2FS_FS_XATTR
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001108 .listxattr = f2fs_listxattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001109#endif
1110};