blob: 760d85223c8133b8b0ac808205df1f49aa42a4c2 [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>
Chao Yu0abd6752017-07-09 00:13:07 +080018#include <linux/quotaops.h>
Jaegeuk Kim57397d82012-11-02 17:11:10 +090019
20#include "f2fs.h"
Jaegeuk Kim953a3e22013-03-21 15:21:57 +090021#include "node.h"
Jaegeuk Kim57397d82012-11-02 17:11:10 +090022#include "xattr.h"
23#include "acl.h"
Namjae Jeona2a4a7e2013-04-20 01:28:40 +090024#include <trace/events/f2fs.h>
Jaegeuk Kim57397d82012-11-02 17:11:10 +090025
26static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
27{
Jaegeuk Kim40813632014-09-02 15:31:18 -070028 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090029 nid_t ino;
30 struct inode *inode;
31 bool nid_free = false;
Gu Zhenge4795562013-09-27 18:08:30 +080032 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +090033
Jaegeuk Kima014e032014-06-20 21:44:02 -070034 inode = new_inode(dir->i_sb);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090035 if (!inode)
36 return ERR_PTR(-ENOMEM);
37
Gu Zhenge4795562013-09-27 18:08:30 +080038 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090039 if (!alloc_nid(sbi, &ino)) {
Gu Zhenge4795562013-09-27 18:08:30 +080040 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090041 err = -ENOSPC;
42 goto fail;
43 }
Gu Zhenge4795562013-09-27 18:08:30 +080044 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090045
Chao Yu0abd6752017-07-09 00:13:07 +080046 nid_free = true;
47
Chao Yu70ff5df2014-05-08 17:09:30 +080048 inode_init_owner(inode, dir, mode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090049
50 inode->i_ino = ino;
Jaegeuk Kim57397d82012-11-02 17:11:10 +090051 inode->i_blocks = 0;
Deepa Dinamani078cd822016-09-14 07:48:04 -070052 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090053 inode->i_generation = sbi->s_next_generation++;
54
55 err = insert_inode_locked(inode);
56 if (err) {
57 err = -EINVAL;
Jaegeuk Kima21c20f2015-08-16 12:38:15 -070058 goto fail;
Jaegeuk Kim57397d82012-11-02 17:11:10 +090059 }
Chao Yu622f28a2014-09-24 18:19:10 +080060
Chao Yu0abd6752017-07-09 00:13:07 +080061 err = dquot_initialize(inode);
62 if (err)
63 goto fail_drop;
64
65 err = dquot_alloc_inode(inode);
66 if (err)
67 goto fail_drop;
68
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -070069 /* If the directory encrypted, then we should encrypt the inode. */
70 if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode))
71 f2fs_set_encrypted_inode(inode);
72
Jaegeuk Kim91942322016-05-20 10:13:22 -070073 set_inode_flag(inode, FI_NEW_INODE);
74
75 if (test_opt(sbi, INLINE_XATTR))
76 set_inode_flag(inode, FI_INLINE_XATTR);
Chao Yufba48a82015-12-23 17:51:35 +080077 if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode))
Jaegeuk Kim91942322016-05-20 10:13:22 -070078 set_inode_flag(inode, FI_INLINE_DATA);
Jaegeuk Kim01b960e2015-04-23 10:27:21 -070079 if (f2fs_may_inline_dentry(inode))
Jaegeuk Kim91942322016-05-20 10:13:22 -070080 set_inode_flag(inode, FI_INLINE_DENTRY);
Chao Yu622f28a2014-09-24 18:19:10 +080081
Jaegeuk Kim3e72f722015-06-19 17:53:26 -070082 f2fs_init_extent_tree(inode, NULL);
83
Chao Yud5e8f6c2015-07-15 17:28:53 +080084 stat_inc_inline_xattr(inode);
Jaegeuk Kim2fb2c952015-04-30 18:58:22 -070085 stat_inc_inline_inode(inode);
86 stat_inc_inline_dir(inode);
87
Jaegeuk Kimd70b4f52013-04-25 13:24:33 +090088 trace_f2fs_new_inode(inode, 0);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090089 return inode;
90
Jaegeuk Kim57397d82012-11-02 17:11:10 +090091fail:
Jaegeuk Kimd70b4f52013-04-25 13:24:33 +090092 trace_f2fs_new_inode(inode, err);
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +090093 make_bad_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090094 if (nid_free)
Jaegeuk Kim91942322016-05-20 10:13:22 -070095 set_inode_flag(inode, FI_FREE_NID);
Jaegeuk Kimc9b63bd2015-06-23 10:36:08 -070096 iput(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090097 return ERR_PTR(err);
Chao Yu0abd6752017-07-09 00:13:07 +080098fail_drop:
99 trace_f2fs_new_inode(inode, err);
100 dquot_drop(inode);
101 inode->i_flags |= S_NOQUOTA;
102 if (nid_free)
103 set_inode_flag(inode, FI_FREE_NID);
104 clear_nlink(inode);
105 unlock_new_inode(inode);
106 iput(inode);
107 return ERR_PTR(err);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900108}
109
110static int is_multimedia_file(const unsigned char *s, const char *sub)
111{
Leon Romanovsky9836b8b2012-12-27 19:55:46 +0200112 size_t slen = strlen(s);
113 size_t sublen = strlen(sub);
Chao Yu7732c262016-09-05 12:28:27 +0800114 int i;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900115
Chao Yu741a7be2015-07-06 20:30:40 +0800116 /*
117 * filename format of multimedia file should be defined as:
Chao Yu7732c262016-09-05 12:28:27 +0800118 * "filename + '.' + extension + (optional: '.' + temp extension)".
Chao Yu741a7be2015-07-06 20:30:40 +0800119 */
120 if (slen < sublen + 2)
121 return 0;
122
Chao Yu7732c262016-09-05 12:28:27 +0800123 for (i = 1; i < slen - sublen; i++) {
124 if (s[i] != '.')
125 continue;
126 if (!strncasecmp(s + i + 1, sub, sublen))
127 return 1;
128 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900129
Chao Yu7732c262016-09-05 12:28:27 +0800130 return 0;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900131}
132
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +0900133/*
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900134 * Set multimedia files as cold files for hot/cold data separation
135 */
Jaegeuk Kim953a3e22013-03-21 15:21:57 +0900136static inline void set_cold_files(struct f2fs_sb_info *sbi, struct inode *inode,
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900137 const unsigned char *name)
138{
139 int i;
140 __u8 (*extlist)[8] = sbi->raw_super->extension_list;
141
142 int count = le32_to_cpu(sbi->raw_super->extension_count);
143 for (i = 0; i < count; i++) {
Namjae Jeone66509f02013-04-20 01:27:21 +0900144 if (is_multimedia_file(name, extlist[i])) {
Jaegeuk Kim354a3392013-06-14 08:52:35 +0900145 file_set_cold(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900146 break;
147 }
148 }
149}
150
151static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
152 bool excl)
153{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700154 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900155 struct inode *inode;
156 nid_t ino = 0;
Gu Zhenge4795562013-09-27 18:08:30 +0800157 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900158
Chao Yu0abd6752017-07-09 00:13:07 +0800159 err = dquot_initialize(dir);
160 if (err)
161 return err;
162
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900163 inode = f2fs_new_inode(dir, mode);
164 if (IS_ERR(inode))
165 return PTR_ERR(inode);
166
167 if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
Jaegeuk Kim953a3e22013-03-21 15:21:57 +0900168 set_cold_files(sbi, inode, dentry->d_name.name);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900169
170 inode->i_op = &f2fs_file_inode_operations;
171 inode->i_fop = &f2fs_file_operations;
172 inode->i_mapping->a_ops = &f2fs_dblock_aops;
173 ino = inode->i_ino;
174
Gu Zhenge4795562013-09-27 18:08:30 +0800175 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900176 err = f2fs_add_link(dentry, inode);
177 if (err)
178 goto out;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700179 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900180
181 alloc_nid_done(sbi, ino);
182
Jaegeuk Kim0a364af2013-05-16 08:57:43 +0900183 d_instantiate(dentry, inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900184 unlock_new_inode(inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800185
186 if (IS_DIRSYNC(dir))
187 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim9bb02c32017-04-11 19:01:26 -0700188
189 f2fs_balance_fs(sbi, true);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900190 return 0;
191out:
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700192 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900193 return err;
194}
195
196static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
197 struct dentry *dentry)
198{
David Howells2b0143b2015-03-17 22:25:59 +0000199 struct inode *inode = d_inode(old_dentry);
Jaegeuk Kim40813632014-09-02 15:31:18 -0700200 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Gu Zhenge4795562013-09-27 18:08:30 +0800201 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900202
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700203 if (f2fs_encrypted_inode(dir) &&
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700204 !fscrypt_has_permitted_context(dir, inode))
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700205 return -EPERM;
206
Chao Yu0abd6752017-07-09 00:13:07 +0800207 err = dquot_initialize(dir);
208 if (err)
209 return err;
210
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800211 f2fs_balance_fs(sbi, true);
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900212
Deepa Dinamani078cd822016-09-14 07:48:04 -0700213 inode->i_ctime = current_time(inode);
Jaegeuk Kim6f6fd832013-05-22 12:06:26 +0900214 ihold(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900215
Jaegeuk Kim91942322016-05-20 10:13:22 -0700216 set_inode_flag(inode, FI_INC_LINK);
Gu Zhenge4795562013-09-27 18:08:30 +0800217 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900218 err = f2fs_add_link(dentry, inode);
219 if (err)
220 goto out;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700221 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900222
223 d_instantiate(dentry, inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800224
225 if (IS_DIRSYNC(dir))
226 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900227 return 0;
228out:
Jaegeuk Kim91942322016-05-20 10:13:22 -0700229 clear_inode_flag(inode, FI_INC_LINK);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900230 iput(inode);
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700231 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900232 return err;
233}
234
235struct dentry *f2fs_get_parent(struct dentry *child)
236{
237 struct qstr dotdot = QSTR_INIT("..", 2);
Chao Yu91246c22016-07-19 08:27:47 +0800238 struct page *page;
239 unsigned long ino = f2fs_inode_by_name(d_inode(child), &dotdot, &page);
240 if (!ino) {
241 if (IS_ERR(page))
242 return ERR_CAST(page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900243 return ERR_PTR(-ENOENT);
Chao Yu91246c22016-07-19 08:27:47 +0800244 }
Al Virofc640052016-04-10 01:33:30 -0400245 return d_obtain_alias(f2fs_iget(child->d_sb, ino));
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900246}
247
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700248static int __recover_dot_dentries(struct inode *dir, nid_t pino)
249{
250 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
251 struct qstr dot = QSTR_INIT(".", 1);
252 struct qstr dotdot = QSTR_INIT("..", 2);
253 struct f2fs_dir_entry *de;
254 struct page *page;
255 int err = 0;
256
Chao Yu4e0d8362015-12-30 17:40:31 +0800257 if (f2fs_readonly(sbi->sb)) {
258 f2fs_msg(sbi->sb, KERN_INFO,
259 "skip recovering inline_dots inode (ino:%lu, pino:%u) "
260 "in readonly mountpoint", dir->i_ino, pino);
261 return 0;
262 }
263
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800264 f2fs_balance_fs(sbi, true);
Chao Yud5384172015-12-24 18:03:29 +0800265
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700266 f2fs_lock_op(sbi);
267
268 de = f2fs_find_entry(dir, &dot, &page);
269 if (de) {
270 f2fs_dentry_kunmap(dir, page);
271 f2fs_put_page(page, 0);
Jaegeuk Kim42d96402016-05-25 14:29:11 -0700272 } else if (IS_ERR(page)) {
273 err = PTR_ERR(page);
274 goto out;
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700275 } else {
276 err = __f2fs_add_link(dir, &dot, NULL, dir->i_ino, S_IFDIR);
277 if (err)
278 goto out;
279 }
280
281 de = f2fs_find_entry(dir, &dotdot, &page);
282 if (de) {
283 f2fs_dentry_kunmap(dir, page);
284 f2fs_put_page(page, 0);
Jaegeuk Kim42d96402016-05-25 14:29:11 -0700285 } else if (IS_ERR(page)) {
286 err = PTR_ERR(page);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700287 } else {
288 err = __f2fs_add_link(dir, &dotdot, NULL, pino, S_IFDIR);
289 }
290out:
Jaegeuk Kim205b9822016-05-20 09:52:20 -0700291 if (!err)
Jaegeuk Kim91942322016-05-20 10:13:22 -0700292 clear_inode_flag(dir, FI_INLINE_DOTS);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700293
294 f2fs_unlock_op(sbi);
295 return err;
296}
297
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900298static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
299 unsigned int flags)
300{
301 struct inode *inode = NULL;
302 struct f2fs_dir_entry *de;
303 struct page *page;
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700304 nid_t ino;
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700305 int err = 0;
Liu Xue8c2b1432016-02-26 06:39:23 +0000306 unsigned int root_ino = F2FS_ROOT_INO(F2FS_I_SB(dir));
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900307
Jaegeuk Kim8074bb52016-02-23 09:21:37 -0800308 if (f2fs_encrypted_inode(dir)) {
309 int res = fscrypt_get_encryption_info(dir);
310
311 /*
312 * DCACHE_ENCRYPTED_WITH_KEY is set if the dentry is
313 * created while the directory was encrypted and we
314 * don't have access to the key.
315 */
316 if (fscrypt_has_encryption_key(dir))
317 fscrypt_set_encrypted_dentry(dentry);
318 fscrypt_set_d_op(dentry);
319 if (res && res != -ENOKEY)
320 return ERR_PTR(res);
321 }
322
Jaegeuk Kim5a20d332013-03-03 13:58:05 +0900323 if (dentry->d_name.len > F2FS_NAME_LEN)
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900324 return ERR_PTR(-ENAMETOOLONG);
325
326 de = f2fs_find_entry(dir, &dentry->d_name, &page);
Jaegeuk Kimeb4246d2016-05-27 10:10:41 -0700327 if (!de) {
328 if (IS_ERR(page))
329 return (struct dentry *)page;
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700330 return d_splice_alias(inode, dentry);
Jaegeuk Kimeb4246d2016-05-27 10:10:41 -0700331 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900332
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700333 ino = le32_to_cpu(de->ino);
334 f2fs_dentry_kunmap(dir, page);
335 f2fs_put_page(page, 0);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700336
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700337 inode = f2fs_iget(dir->i_sb, ino);
338 if (IS_ERR(inode))
339 return ERR_CAST(inode);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700340
Liu Xue8c2b1432016-02-26 06:39:23 +0000341 if ((dir->i_ino == root_ino) && f2fs_has_inline_dots(dir)) {
342 err = __recover_dot_dentries(dir, root_ino);
343 if (err)
344 goto err_out;
345 }
346
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700347 if (f2fs_has_inline_dots(inode)) {
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700348 err = __recover_dot_dentries(inode, dir->i_ino);
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700349 if (err)
350 goto err_out;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900351 }
Dan Carpenter07fe8d42016-12-16 11:18:15 +0300352 if (f2fs_encrypted_inode(dir) &&
353 (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
354 !fscrypt_has_permitted_context(dir, inode)) {
Eric Biggersfaac7fd2017-04-07 10:58:39 -0700355 f2fs_msg(inode->i_sb, KERN_WARNING,
356 "Inconsistent encryption contexts: %lu/%lu",
357 dir->i_ino, inode->i_ino);
358 err = -EPERM;
Chao Yud7267322016-03-10 22:24:23 +0800359 goto err_out;
Jaegeuk Kim8074bb52016-02-23 09:21:37 -0800360 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900361 return d_splice_alias(inode, dentry);
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700362
363err_out:
Chao Yud7267322016-03-10 22:24:23 +0800364 iput(inode);
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700365 return ERR_PTR(err);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900366}
367
368static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
369{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700370 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
David Howells2b0143b2015-03-17 22:25:59 +0000371 struct inode *inode = d_inode(dentry);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900372 struct f2fs_dir_entry *de;
373 struct page *page;
374 int err = -ENOENT;
375
Namjae Jeona2a4a7e2013-04-20 01:28:40 +0900376 trace_f2fs_unlink_enter(dir, dentry);
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900377
Chao Yu0abd6752017-07-09 00:13:07 +0800378 err = dquot_initialize(dir);
379 if (err)
380 return err;
381
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900382 de = f2fs_find_entry(dir, &dentry->d_name, &page);
Chao Yu91246c22016-07-19 08:27:47 +0800383 if (!de) {
384 if (IS_ERR(page))
385 err = PTR_ERR(page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900386 goto fail;
Chao Yu91246c22016-07-19 08:27:47 +0800387 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900388
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800389 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800390
Jaegeuk Kimccaaca22013-10-08 10:19:28 +0900391 f2fs_lock_op(sbi);
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900392 err = acquire_orphan_inode(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900393 if (err) {
Jaegeuk Kimccaaca22013-10-08 10:19:28 +0900394 f2fs_unlock_op(sbi);
Jaegeuk Kim9486ba42014-11-21 16:36:28 -0800395 f2fs_dentry_kunmap(dir, page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900396 f2fs_put_page(page, 0);
397 goto fail;
398 }
Chao Yudbeacf02014-09-24 18:17:04 +0800399 f2fs_delete_entry(de, page, dir, inode);
Gu Zhenge4795562013-09-27 18:08:30 +0800400 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900401
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800402 if (IS_DIRSYNC(dir))
403 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900404fail:
Namjae Jeona2a4a7e2013-04-20 01:28:40 +0900405 trace_f2fs_unlink_exit(inode, err);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900406 return err;
407}
408
Al Viro6b255392015-11-17 10:20:54 -0500409static const char *f2fs_get_link(struct dentry *dentry,
Al Virofceef392015-12-29 15:58:39 -0500410 struct inode *inode,
411 struct delayed_call *done)
Jaegeuk Kimfeb7cbb2015-04-15 13:49:55 -0700412{
Al Virofceef392015-12-29 15:58:39 -0500413 const char *link = page_get_link(dentry, inode, done);
Al Viro680baac2015-05-02 13:32:22 -0400414 if (!IS_ERR(link) && !*link) {
415 /* this is broken symlink case */
Al Virofceef392015-12-29 15:58:39 -0500416 do_delayed_call(done);
417 clear_delayed_call(done);
Al Viro680baac2015-05-02 13:32:22 -0400418 link = ERR_PTR(-ENOENT);
Jaegeuk Kimfeb7cbb2015-04-15 13:49:55 -0700419 }
Al Viro680baac2015-05-02 13:32:22 -0400420 return link;
Jaegeuk Kimfeb7cbb2015-04-15 13:49:55 -0700421}
422
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900423static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
424 const char *symname)
425{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700426 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900427 struct inode *inode;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700428 size_t len = strlen(symname);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700429 struct fscrypt_str disk_link = FSTR_INIT((char *)symname, len + 1);
430 struct fscrypt_symlink_data *sd = NULL;
Gu Zhenge4795562013-09-27 18:08:30 +0800431 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900432
Chao Yu922ec352016-02-15 17:54:26 +0800433 if (f2fs_encrypted_inode(dir)) {
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700434 err = fscrypt_get_encryption_info(dir);
Chao Yu922ec352016-02-15 17:54:26 +0800435 if (err)
436 return err;
437
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700438 if (!fscrypt_has_encryption_key(dir))
Eric Biggers54475f52016-12-05 11:12:44 -0800439 return -ENOKEY;
Chao Yu922ec352016-02-15 17:54:26 +0800440
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700441 disk_link.len = (fscrypt_fname_encrypted_size(dir, len) +
442 sizeof(struct fscrypt_symlink_data));
Chao Yu922ec352016-02-15 17:54:26 +0800443 }
444
445 if (disk_link.len > dir->i_sb->s_blocksize)
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700446 return -ENAMETOOLONG;
447
Chao Yu0abd6752017-07-09 00:13:07 +0800448 err = dquot_initialize(dir);
449 if (err)
450 return err;
451
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900452 inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO);
453 if (IS_ERR(inode))
454 return PTR_ERR(inode);
455
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700456 if (f2fs_encrypted_inode(inode))
457 inode->i_op = &f2fs_encrypted_symlink_inode_operations;
458 else
459 inode->i_op = &f2fs_symlink_inode_operations;
Al Viro21fc61c2015-11-17 01:07:57 -0500460 inode_nohighmem(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900461 inode->i_mapping->a_ops = &f2fs_dblock_aops;
462
Gu Zhenge4795562013-09-27 18:08:30 +0800463 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900464 err = f2fs_add_link(dentry, inode);
465 if (err)
466 goto out;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700467 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900468 alloc_nid_done(sbi, inode->i_ino);
469
Chao Yu922ec352016-02-15 17:54:26 +0800470 if (f2fs_encrypted_inode(inode)) {
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700471 struct qstr istr = QSTR_INIT(symname, len);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700472 struct fscrypt_str ostr;
Chao Yu922ec352016-02-15 17:54:26 +0800473
474 sd = kzalloc(disk_link.len, GFP_NOFS);
475 if (!sd) {
476 err = -ENOMEM;
477 goto err_out;
478 }
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700479
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700480 err = fscrypt_get_encryption_info(inode);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700481 if (err)
482 goto err_out;
483
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700484 if (!fscrypt_has_encryption_key(inode)) {
Eric Biggers54475f52016-12-05 11:12:44 -0800485 err = -ENOKEY;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700486 goto err_out;
Chao Yu922ec352016-02-15 17:54:26 +0800487 }
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700488
Chao Yu922ec352016-02-15 17:54:26 +0800489 ostr.name = sd->encrypted_path;
490 ostr.len = disk_link.len;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700491 err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr);
Eric Biggersef1eb3a2016-09-15 17:25:55 -0400492 if (err)
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700493 goto err_out;
494
Chao Yu922ec352016-02-15 17:54:26 +0800495 sd->len = cpu_to_le16(ostr.len);
496 disk_link.name = (char *)sd;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700497 }
498
Chao Yu922ec352016-02-15 17:54:26 +0800499 err = page_symlink(inode, disk_link.name, disk_link.len);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700500
501err_out:
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900502 d_instantiate(dentry, inode);
503 unlock_new_inode(inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800504
Jaegeuk Kimd0cae972015-04-15 13:37:53 -0700505 /*
506 * Let's flush symlink data in order to avoid broken symlink as much as
507 * possible. Nevertheless, fsyncing is the best way, but there is no
508 * way to get a file descriptor in order to flush that.
509 *
510 * Note that, it needs to do dir->fsync to make this recoverable.
511 * If the symlink path is stored into inline_data, there is no
512 * performance regression.
513 */
Chao Yua6be0142015-10-22 18:23:08 +0800514 if (!err) {
Chao Yu922ec352016-02-15 17:54:26 +0800515 filemap_write_and_wait_range(inode->i_mapping, 0,
516 disk_link.len - 1);
Jaegeuk Kimd0cae972015-04-15 13:37:53 -0700517
Chao Yua6be0142015-10-22 18:23:08 +0800518 if (IS_DIRSYNC(dir))
519 f2fs_sync_fs(sbi->sb, 1);
520 } else {
521 f2fs_unlink(dir, dentry);
522 }
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700523
524 kfree(sd);
Jaegeuk Kim9bb02c32017-04-11 19:01:26 -0700525
526 f2fs_balance_fs(sbi, true);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900527 return err;
528out:
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700529 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900530 return err;
531}
532
533static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
534{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700535 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900536 struct inode *inode;
Gu Zhenge4795562013-09-27 18:08:30 +0800537 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900538
Chao Yu0abd6752017-07-09 00:13:07 +0800539 err = dquot_initialize(dir);
540 if (err)
541 return err;
542
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900543 inode = f2fs_new_inode(dir, S_IFDIR | mode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900544 if (IS_ERR(inode))
Namjae Jeon61412b62012-12-01 10:56:25 +0900545 return PTR_ERR(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900546
547 inode->i_op = &f2fs_dir_inode_operations;
548 inode->i_fop = &f2fs_dir_operations;
549 inode->i_mapping->a_ops = &f2fs_dblock_aops;
Chao Yu560d4672015-02-07 17:36:15 +0800550 mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_HIGH_ZERO);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900551
Jaegeuk Kim91942322016-05-20 10:13:22 -0700552 set_inode_flag(inode, FI_INC_LINK);
Gu Zhenge4795562013-09-27 18:08:30 +0800553 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900554 err = f2fs_add_link(dentry, inode);
555 if (err)
556 goto out_fail;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700557 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900558
559 alloc_nid_done(sbi, inode->i_ino);
560
561 d_instantiate(dentry, inode);
562 unlock_new_inode(inode);
563
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800564 if (IS_DIRSYNC(dir))
565 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim9bb02c32017-04-11 19:01:26 -0700566
567 f2fs_balance_fs(sbi, true);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900568 return 0;
569
570out_fail:
Jaegeuk Kim91942322016-05-20 10:13:22 -0700571 clear_inode_flag(inode, FI_INC_LINK);
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700572 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900573 return err;
574}
575
576static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)
577{
David Howells2b0143b2015-03-17 22:25:59 +0000578 struct inode *inode = d_inode(dentry);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900579 if (f2fs_empty_dir(inode))
580 return f2fs_unlink(dir, dentry);
581 return -ENOTEMPTY;
582}
583
584static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
585 umode_t mode, dev_t rdev)
586{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700587 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900588 struct inode *inode;
589 int err = 0;
590
Chao Yu0abd6752017-07-09 00:13:07 +0800591 err = dquot_initialize(dir);
592 if (err)
593 return err;
594
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900595 inode = f2fs_new_inode(dir, mode);
596 if (IS_ERR(inode))
597 return PTR_ERR(inode);
598
599 init_special_inode(inode, inode->i_mode, rdev);
600 inode->i_op = &f2fs_special_inode_operations;
601
Gu Zhenge4795562013-09-27 18:08:30 +0800602 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900603 err = f2fs_add_link(dentry, inode);
604 if (err)
605 goto out;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700606 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900607
608 alloc_nid_done(sbi, inode->i_ino);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800609
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900610 d_instantiate(dentry, inode);
611 unlock_new_inode(inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800612
613 if (IS_DIRSYNC(dir))
614 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim9bb02c32017-04-11 19:01:26 -0700615
616 f2fs_balance_fs(sbi, true);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900617 return 0;
618out:
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700619 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900620 return err;
621}
622
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800623static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,
624 umode_t mode, struct inode **whiteout)
625{
626 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
627 struct inode *inode;
628 int err;
629
Chao Yu0abd6752017-07-09 00:13:07 +0800630 err = dquot_initialize(dir);
631 if (err)
632 return err;
633
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800634 inode = f2fs_new_inode(dir, mode);
635 if (IS_ERR(inode))
636 return PTR_ERR(inode);
637
638 if (whiteout) {
639 init_special_inode(inode, inode->i_mode, WHITEOUT_DEV);
640 inode->i_op = &f2fs_special_inode_operations;
641 } else {
642 inode->i_op = &f2fs_file_inode_operations;
643 inode->i_fop = &f2fs_file_operations;
644 inode->i_mapping->a_ops = &f2fs_dblock_aops;
645 }
646
647 f2fs_lock_op(sbi);
648 err = acquire_orphan_inode(sbi);
649 if (err)
650 goto out;
651
652 err = f2fs_do_tmpfile(inode, dir);
653 if (err)
654 goto release_out;
655
656 /*
657 * add this non-linked tmpfile to orphan list, in this way we could
658 * remove all unused data of tmpfile after abnormal power-off.
659 */
Jaegeuk Kim67c37582016-06-13 18:27:02 -0700660 add_orphan_inode(inode);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800661 alloc_nid_done(sbi, inode->i_ino);
662
663 if (whiteout) {
Jaegeuk Kima1961242016-05-20 09:43:20 -0700664 f2fs_i_links_write(inode, false);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800665 *whiteout = inode;
666 } else {
667 d_tmpfile(dentry, inode);
668 }
Jaegeuk Kima1961242016-05-20 09:43:20 -0700669 /* link_count was changed by d_tmpfile as well. */
670 f2fs_unlock_op(sbi);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800671 unlock_new_inode(inode);
Jaegeuk Kim9bb02c32017-04-11 19:01:26 -0700672
673 f2fs_balance_fs(sbi, true);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800674 return 0;
675
676release_out:
677 release_orphan_inode(sbi);
678out:
679 handle_failed_inode(inode);
680 return err;
681}
682
683static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
684{
Jaegeuk Kim304eecc2015-05-19 16:11:40 -0700685 if (f2fs_encrypted_inode(dir)) {
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700686 int err = fscrypt_get_encryption_info(dir);
Jaegeuk Kim304eecc2015-05-19 16:11:40 -0700687 if (err)
688 return err;
689 }
690
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800691 return __f2fs_tmpfile(dir, dentry, mode, NULL);
692}
693
694static int f2fs_create_whiteout(struct inode *dir, struct inode **whiteout)
695{
696 return __f2fs_tmpfile(dir, NULL, S_IFCHR | WHITEOUT_MODE, whiteout);
697}
698
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900699static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800700 struct inode *new_dir, struct dentry *new_dentry,
701 unsigned int flags)
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900702{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700703 struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
David Howells2b0143b2015-03-17 22:25:59 +0000704 struct inode *old_inode = d_inode(old_dentry);
705 struct inode *new_inode = d_inode(new_dentry);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800706 struct inode *whiteout = NULL;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900707 struct page *old_dir_page;
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800708 struct page *old_page, *new_page = NULL;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900709 struct f2fs_dir_entry *old_dir_entry = NULL;
710 struct f2fs_dir_entry *old_entry;
711 struct f2fs_dir_entry *new_entry;
Chao Yu993a0492016-02-17 16:47:05 +0800712 bool is_old_inline = f2fs_has_inline_dentry(old_dir);
Gu Zhenge4795562013-09-27 18:08:30 +0800713 int err = -ENOENT;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900714
Jaegeuk Kim363fa4e2016-12-28 17:31:15 -0800715 if ((f2fs_encrypted_inode(old_dir) &&
716 !fscrypt_has_encryption_key(old_dir)) ||
717 (f2fs_encrypted_inode(new_dir) &&
718 !fscrypt_has_encryption_key(new_dir)))
719 return -ENOKEY;
720
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700721 if ((old_dir != new_dir) && f2fs_encrypted_inode(new_dir) &&
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700722 !fscrypt_has_permitted_context(new_dir, old_inode)) {
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700723 err = -EPERM;
724 goto out;
725 }
726
Chao Yu0abd6752017-07-09 00:13:07 +0800727 err = dquot_initialize(old_dir);
728 if (err)
729 goto out;
730
731 err = dquot_initialize(new_dir);
732 if (err)
733 goto out;
734
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900735 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
Chao Yu91246c22016-07-19 08:27:47 +0800736 if (!old_entry) {
737 if (IS_ERR(old_page))
738 err = PTR_ERR(old_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900739 goto out;
Chao Yu91246c22016-07-19 08:27:47 +0800740 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900741
742 if (S_ISDIR(old_inode->i_mode)) {
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900743 old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page);
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700744 if (!old_dir_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800745 if (IS_ERR(old_dir_page))
746 err = PTR_ERR(old_dir_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900747 goto out_old;
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700748 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900749 }
750
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800751 if (flags & RENAME_WHITEOUT) {
752 err = f2fs_create_whiteout(old_dir, &whiteout);
753 if (err)
754 goto out_dir;
755 }
756
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900757 if (new_inode) {
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900758
759 err = -ENOTEMPTY;
760 if (old_dir_entry && !f2fs_empty_dir(new_inode))
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800761 goto out_whiteout;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900762
763 err = -ENOENT;
764 new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name,
765 &new_page);
Chao Yu91246c22016-07-19 08:27:47 +0800766 if (!new_entry) {
767 if (IS_ERR(new_page))
768 err = PTR_ERR(new_page);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800769 goto out_whiteout;
Chao Yu91246c22016-07-19 08:27:47 +0800770 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900771
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800772 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800773
Chao Yu12560102014-06-24 14:16:24 +0800774 f2fs_lock_op(sbi);
775
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900776 err = acquire_orphan_inode(sbi);
777 if (err)
778 goto put_out_dir;
779
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900780 f2fs_set_link(new_dir, new_entry, new_page, old_inode);
781
Deepa Dinamani078cd822016-09-14 07:48:04 -0700782 new_inode->i_ctime = current_time(new_inode);
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900783 down_write(&F2FS_I(new_inode)->i_sem);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900784 if (old_dir_entry)
Jaegeuk Kima1961242016-05-20 09:43:20 -0700785 f2fs_i_links_write(new_inode, false);
786 f2fs_i_links_write(new_inode, false);
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900787 up_write(&F2FS_I(new_inode)->i_sem);
788
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900789 if (!new_inode->i_nlink)
Jaegeuk Kim67c37582016-06-13 18:27:02 -0700790 add_orphan_inode(new_inode);
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900791 else
792 release_orphan_inode(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900793 } else {
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800794 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800795
Chao Yu12560102014-06-24 14:16:24 +0800796 f2fs_lock_op(sbi);
797
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900798 err = f2fs_add_link(new_dentry, old_inode);
Chao Yu12560102014-06-24 14:16:24 +0800799 if (err) {
800 f2fs_unlock_op(sbi);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800801 goto out_whiteout;
Chao Yu12560102014-06-24 14:16:24 +0800802 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900803
Jaegeuk Kimee6d1822016-05-20 16:32:49 -0700804 if (old_dir_entry)
Jaegeuk Kima1961242016-05-20 09:43:20 -0700805 f2fs_i_links_write(new_dir, true);
Chao Yu993a0492016-02-17 16:47:05 +0800806
807 /*
808 * old entry and new entry can locate in the same inline
809 * dentry in inode, when attaching new entry in inline dentry,
810 * it could force inline dentry conversion, after that,
811 * old_entry and old_page will point to wrong address, in
812 * order to avoid this, let's do the check and update here.
813 */
814 if (is_old_inline && !f2fs_has_inline_dentry(old_dir)) {
815 f2fs_put_page(old_page, 0);
816 old_page = NULL;
817
818 old_entry = f2fs_find_entry(old_dir,
819 &old_dentry->d_name, &old_page);
820 if (!old_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800821 err = -ENOENT;
822 if (IS_ERR(old_page))
823 err = PTR_ERR(old_page);
Chao Yu993a0492016-02-17 16:47:05 +0800824 f2fs_unlock_op(sbi);
825 goto out_whiteout;
826 }
827 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900828 }
829
Jaegeuk Kimb2c08292014-06-30 18:09:55 +0900830 down_write(&F2FS_I(old_inode)->i_sem);
Sheng Yongb855bf02017-06-26 10:41:36 +0800831 if (!old_dir_entry || whiteout)
832 file_lost_pino(old_inode);
833 else
834 F2FS_I(old_inode)->i_pino = new_dir->i_ino;
Jaegeuk Kimb2c08292014-06-30 18:09:55 +0900835 up_write(&F2FS_I(old_inode)->i_sem);
836
Deepa Dinamani078cd822016-09-14 07:48:04 -0700837 old_inode->i_ctime = current_time(old_inode);
Jaegeuk Kim7c457292016-10-14 11:51:23 -0700838 f2fs_mark_inode_dirty_sync(old_inode, false);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900839
Chao Yudbeacf02014-09-24 18:17:04 +0800840 f2fs_delete_entry(old_entry, old_page, old_dir, NULL);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900841
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800842 if (whiteout) {
843 whiteout->i_state |= I_LINKABLE;
Jaegeuk Kim91942322016-05-20 10:13:22 -0700844 set_inode_flag(whiteout, FI_INC_LINK);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800845 err = f2fs_add_link(old_dentry, whiteout);
846 if (err)
847 goto put_out_dir;
848 whiteout->i_state &= ~I_LINKABLE;
849 iput(whiteout);
850 }
851
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900852 if (old_dir_entry) {
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800853 if (old_dir != new_dir && !whiteout) {
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900854 f2fs_set_link(old_inode, old_dir_entry,
855 old_dir_page, new_dir);
856 } else {
Jaegeuk Kim9486ba42014-11-21 16:36:28 -0800857 f2fs_dentry_kunmap(old_inode, old_dir_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900858 f2fs_put_page(old_dir_page, 0);
859 }
Jaegeuk Kima1961242016-05-20 09:43:20 -0700860 f2fs_i_links_write(old_dir, false);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900861 }
862
Gu Zhenge4795562013-09-27 18:08:30 +0800863 f2fs_unlock_op(sbi);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800864
865 if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
866 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900867 return 0;
868
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900869put_out_dir:
Chao Yu12560102014-06-24 14:16:24 +0800870 f2fs_unlock_op(sbi);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800871 if (new_page) {
872 f2fs_dentry_kunmap(new_dir, new_page);
873 f2fs_put_page(new_page, 0);
874 }
875out_whiteout:
876 if (whiteout)
877 iput(whiteout);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900878out_dir:
879 if (old_dir_entry) {
Jaegeuk Kim9486ba42014-11-21 16:36:28 -0800880 f2fs_dentry_kunmap(old_inode, old_dir_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900881 f2fs_put_page(old_dir_page, 0);
882 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900883out_old:
Jaegeuk Kim9486ba42014-11-21 16:36:28 -0800884 f2fs_dentry_kunmap(old_dir, old_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900885 f2fs_put_page(old_page, 0);
886out:
887 return err;
888}
889
Chao Yu32f9bc22014-07-12 19:13:54 +0800890static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
891 struct inode *new_dir, struct dentry *new_dentry)
892{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700893 struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
David Howells2b0143b2015-03-17 22:25:59 +0000894 struct inode *old_inode = d_inode(old_dentry);
895 struct inode *new_inode = d_inode(new_dentry);
Chao Yu32f9bc22014-07-12 19:13:54 +0800896 struct page *old_dir_page, *new_dir_page;
897 struct page *old_page, *new_page;
898 struct f2fs_dir_entry *old_dir_entry = NULL, *new_dir_entry = NULL;
899 struct f2fs_dir_entry *old_entry, *new_entry;
900 int old_nlink = 0, new_nlink = 0;
901 int err = -ENOENT;
902
Jaegeuk Kim363fa4e2016-12-28 17:31:15 -0800903 if ((f2fs_encrypted_inode(old_dir) &&
904 !fscrypt_has_encryption_key(old_dir)) ||
905 (f2fs_encrypted_inode(new_dir) &&
906 !fscrypt_has_encryption_key(new_dir)))
907 return -ENOKEY;
908
Chao Yud3baf7c2015-05-25 18:07:02 +0800909 if ((f2fs_encrypted_inode(old_dir) || f2fs_encrypted_inode(new_dir)) &&
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700910 (old_dir != new_dir) &&
911 (!fscrypt_has_permitted_context(new_dir, old_inode) ||
912 !fscrypt_has_permitted_context(old_dir, new_inode)))
Chao Yud3baf7c2015-05-25 18:07:02 +0800913 return -EPERM;
914
Chao Yu0abd6752017-07-09 00:13:07 +0800915 err = dquot_initialize(old_dir);
916 if (err)
917 goto out;
918
919 err = dquot_initialize(new_dir);
920 if (err)
921 goto out;
922
Chao Yu32f9bc22014-07-12 19:13:54 +0800923 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
Chao Yu91246c22016-07-19 08:27:47 +0800924 if (!old_entry) {
925 if (IS_ERR(old_page))
926 err = PTR_ERR(old_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800927 goto out;
Chao Yu91246c22016-07-19 08:27:47 +0800928 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800929
930 new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, &new_page);
Chao Yu91246c22016-07-19 08:27:47 +0800931 if (!new_entry) {
932 if (IS_ERR(new_page))
933 err = PTR_ERR(new_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800934 goto out_old;
Chao Yu91246c22016-07-19 08:27:47 +0800935 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800936
937 /* prepare for updating ".." directory entry info later */
938 if (old_dir != new_dir) {
939 if (S_ISDIR(old_inode->i_mode)) {
Chao Yu32f9bc22014-07-12 19:13:54 +0800940 old_dir_entry = f2fs_parent_dir(old_inode,
941 &old_dir_page);
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700942 if (!old_dir_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800943 if (IS_ERR(old_dir_page))
944 err = PTR_ERR(old_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800945 goto out_new;
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700946 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800947 }
948
949 if (S_ISDIR(new_inode->i_mode)) {
Chao Yu32f9bc22014-07-12 19:13:54 +0800950 new_dir_entry = f2fs_parent_dir(new_inode,
951 &new_dir_page);
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700952 if (!new_dir_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800953 if (IS_ERR(new_dir_page))
954 err = PTR_ERR(new_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800955 goto out_old_dir;
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700956 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800957 }
958 }
959
960 /*
961 * If cross rename between file and directory those are not
962 * in the same directory, we will inc nlink of file's parent
963 * later, so we should check upper boundary of its nlink.
964 */
965 if ((!old_dir_entry || !new_dir_entry) &&
966 old_dir_entry != new_dir_entry) {
967 old_nlink = old_dir_entry ? -1 : 1;
968 new_nlink = -old_nlink;
969 err = -EMLINK;
Kinglong Meee2f0e962017-03-04 21:48:28 +0800970 if ((old_nlink > 0 && old_dir->i_nlink >= F2FS_LINK_MAX) ||
971 (new_nlink > 0 && new_dir->i_nlink >= F2FS_LINK_MAX))
Chao Yu32f9bc22014-07-12 19:13:54 +0800972 goto out_new_dir;
973 }
974
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800975 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800976
Chao Yu32f9bc22014-07-12 19:13:54 +0800977 f2fs_lock_op(sbi);
978
Chao Yu32f9bc22014-07-12 19:13:54 +0800979 /* update ".." directory entry info of old dentry */
980 if (old_dir_entry)
981 f2fs_set_link(old_inode, old_dir_entry, old_dir_page, new_dir);
982
983 /* update ".." directory entry info of new dentry */
984 if (new_dir_entry)
985 f2fs_set_link(new_inode, new_dir_entry, new_dir_page, old_dir);
986
987 /* update directory entry info of old dir inode */
988 f2fs_set_link(old_dir, old_entry, old_page, new_inode);
989
990 down_write(&F2FS_I(old_inode)->i_sem);
991 file_lost_pino(old_inode);
992 up_write(&F2FS_I(old_inode)->i_sem);
993
Deepa Dinamani078cd822016-09-14 07:48:04 -0700994 old_dir->i_ctime = current_time(old_dir);
Chao Yu32f9bc22014-07-12 19:13:54 +0800995 if (old_nlink) {
996 down_write(&F2FS_I(old_dir)->i_sem);
Jaegeuk Kima1961242016-05-20 09:43:20 -0700997 f2fs_i_links_write(old_dir, old_nlink > 0);
Chao Yu32f9bc22014-07-12 19:13:54 +0800998 up_write(&F2FS_I(old_dir)->i_sem);
999 }
Jaegeuk Kim7c457292016-10-14 11:51:23 -07001000 f2fs_mark_inode_dirty_sync(old_dir, false);
Chao Yu32f9bc22014-07-12 19:13:54 +08001001
1002 /* update directory entry info of new dir inode */
1003 f2fs_set_link(new_dir, new_entry, new_page, old_inode);
1004
1005 down_write(&F2FS_I(new_inode)->i_sem);
1006 file_lost_pino(new_inode);
1007 up_write(&F2FS_I(new_inode)->i_sem);
1008
Deepa Dinamani078cd822016-09-14 07:48:04 -07001009 new_dir->i_ctime = current_time(new_dir);
Chao Yu32f9bc22014-07-12 19:13:54 +08001010 if (new_nlink) {
1011 down_write(&F2FS_I(new_dir)->i_sem);
Jaegeuk Kima1961242016-05-20 09:43:20 -07001012 f2fs_i_links_write(new_dir, new_nlink > 0);
Chao Yu32f9bc22014-07-12 19:13:54 +08001013 up_write(&F2FS_I(new_dir)->i_sem);
1014 }
Jaegeuk Kim7c457292016-10-14 11:51:23 -07001015 f2fs_mark_inode_dirty_sync(new_dir, false);
Chao Yu32f9bc22014-07-12 19:13:54 +08001016
1017 f2fs_unlock_op(sbi);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -08001018
1019 if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
1020 f2fs_sync_fs(sbi->sb, 1);
Chao Yu32f9bc22014-07-12 19:13:54 +08001021 return 0;
Chao Yu32f9bc22014-07-12 19:13:54 +08001022out_new_dir:
1023 if (new_dir_entry) {
Jaegeuk Kim9486ba42014-11-21 16:36:28 -08001024 f2fs_dentry_kunmap(new_inode, new_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +08001025 f2fs_put_page(new_dir_page, 0);
1026 }
1027out_old_dir:
1028 if (old_dir_entry) {
Jaegeuk Kim9486ba42014-11-21 16:36:28 -08001029 f2fs_dentry_kunmap(old_inode, old_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +08001030 f2fs_put_page(old_dir_page, 0);
1031 }
1032out_new:
Jaegeuk Kim9486ba42014-11-21 16:36:28 -08001033 f2fs_dentry_kunmap(new_dir, new_page);
Chao Yu32f9bc22014-07-12 19:13:54 +08001034 f2fs_put_page(new_page, 0);
1035out_old:
Jaegeuk Kim9486ba42014-11-21 16:36:28 -08001036 f2fs_dentry_kunmap(old_dir, old_page);
Chao Yu32f9bc22014-07-12 19:13:54 +08001037 f2fs_put_page(old_page, 0);
1038out:
1039 return err;
1040}
1041
1042static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry,
1043 struct inode *new_dir, struct dentry *new_dentry,
1044 unsigned int flags)
1045{
Chao Yu7e01e7ad2015-05-19 17:37:26 +08001046 if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
Chao Yu32f9bc22014-07-12 19:13:54 +08001047 return -EINVAL;
1048
1049 if (flags & RENAME_EXCHANGE) {
1050 return f2fs_cross_rename(old_dir, old_dentry,
1051 new_dir, new_dentry);
1052 }
1053 /*
1054 * VFS has already handled the new dentry existence case,
1055 * here, we just deal with "RENAME_NOREPLACE" as regular rename.
1056 */
Chao Yu7e01e7ad2015-05-19 17:37:26 +08001057 return f2fs_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
Chao Yu32f9bc22014-07-12 19:13:54 +08001058}
1059
Al Viro6b255392015-11-17 10:20:54 -05001060static const char *f2fs_encrypted_get_link(struct dentry *dentry,
Al Virofceef392015-12-29 15:58:39 -05001061 struct inode *inode,
1062 struct delayed_call *done)
Chao Yu50732df2014-06-19 16:23:19 +08001063{
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001064 struct page *cpage = NULL;
1065 char *caddr, *paddr = NULL;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001066 struct fscrypt_str cstr = FSTR_INIT(NULL, 0);
1067 struct fscrypt_str pstr = FSTR_INIT(NULL, 0);
1068 struct fscrypt_symlink_data *sd;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001069 u32 max_size = inode->i_sb->s_blocksize;
1070 int res;
Chao Yu50732df2014-06-19 16:23:19 +08001071
Al Viro6b255392015-11-17 10:20:54 -05001072 if (!dentry)
1073 return ERR_PTR(-ECHILD);
1074
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001075 res = fscrypt_get_encryption_info(inode);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001076 if (res)
1077 return ERR_PTR(res);
Chao Yu50732df2014-06-19 16:23:19 +08001078
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001079 cpage = read_mapping_page(inode->i_mapping, 0, NULL);
1080 if (IS_ERR(cpage))
Linus Torvaldscfcc0ad2015-06-24 20:38:29 -07001081 return ERR_CAST(cpage);
Al Viro21fc61c2015-11-17 01:07:57 -05001082 caddr = page_address(cpage);
Chao Yu50732df2014-06-19 16:23:19 +08001083
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001084 /* Symlink is encrypted */
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001085 sd = (struct fscrypt_symlink_data *)caddr;
Chao Yu922ec352016-02-15 17:54:26 +08001086 cstr.name = sd->encrypted_path;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001087 cstr.len = le16_to_cpu(sd->len);
Jaegeuk Kim8dc0d6a2015-12-24 16:13:09 -08001088
1089 /* this is broken symlink case */
1090 if (unlikely(cstr.len == 0)) {
1091 res = -ENOENT;
1092 goto errout;
1093 }
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -07001094
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001095 if ((cstr.len + sizeof(struct fscrypt_symlink_data) - 1) > max_size) {
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001096 /* Symlink data on the disk is corrupted */
1097 res = -EIO;
1098 goto errout;
1099 }
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001100 res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001101 if (res)
1102 goto errout;
Chao Yu50732df2014-06-19 16:23:19 +08001103
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001104 res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr);
Eric Biggersef1eb3a2016-09-15 17:25:55 -04001105 if (res)
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001106 goto errout;
Chao Yu3c0d84d2015-02-16 16:20:27 +08001107
Jaegeuk Kimc90e09f2016-03-30 13:13:16 -07001108 /* this is broken symlink case */
1109 if (unlikely(pstr.name[0] == 0)) {
1110 res = -ENOENT;
1111 goto errout;
1112 }
1113
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001114 paddr = pstr.name;
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -07001115
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001116 /* Null-terminate the name */
Eric Biggersef1eb3a2016-09-15 17:25:55 -04001117 paddr[pstr.len] = '\0';
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001118
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001119 put_page(cpage);
Al Virofceef392015-12-29 15:58:39 -05001120 set_delayed_call(done, kfree_link, paddr);
1121 return paddr;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001122errout:
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001123 fscrypt_fname_free_buffer(&pstr);
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001124 put_page(cpage);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001125 return ERR_PTR(res);
Chao Yu50732df2014-06-19 16:23:19 +08001126}
1127
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001128const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
Al Viro6b255392015-11-17 10:20:54 -05001129 .get_link = f2fs_encrypted_get_link,
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001130 .getattr = f2fs_getattr,
1131 .setattr = f2fs_setattr,
Chao Yu3a9e6432015-12-31 18:20:10 +08001132#ifdef CONFIG_F2FS_FS_XATTR
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001133 .listxattr = f2fs_listxattr,
Chao Yu3a9e6432015-12-31 18:20:10 +08001134#endif
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001135};
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001136
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001137const struct inode_operations f2fs_dir_inode_operations = {
1138 .create = f2fs_create,
1139 .lookup = f2fs_lookup,
1140 .link = f2fs_link,
1141 .unlink = f2fs_unlink,
1142 .symlink = f2fs_symlink,
1143 .mkdir = f2fs_mkdir,
1144 .rmdir = f2fs_rmdir,
1145 .mknod = f2fs_mknod,
Miklos Szeredi2773bf02016-09-27 11:03:58 +02001146 .rename = f2fs_rename2,
Chao Yu50732df2014-06-19 16:23:19 +08001147 .tmpfile = f2fs_tmpfile,
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +09001148 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001149 .setattr = f2fs_setattr,
1150 .get_acl = f2fs_get_acl,
Christoph Hellwiga6dda0e2013-12-20 05:16:45 -08001151 .set_acl = f2fs_set_acl,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001152#ifdef CONFIG_F2FS_FS_XATTR
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001153 .listxattr = f2fs_listxattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001154#endif
1155};
1156
1157const struct inode_operations f2fs_symlink_inode_operations = {
Al Viro6b255392015-11-17 10:20:54 -05001158 .get_link = f2fs_get_link,
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +09001159 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001160 .setattr = f2fs_setattr,
1161#ifdef CONFIG_F2FS_FS_XATTR
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001162 .listxattr = f2fs_listxattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001163#endif
1164};
1165
1166const struct inode_operations f2fs_special_inode_operations = {
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +09001167 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001168 .setattr = f2fs_setattr,
1169 .get_acl = f2fs_get_acl,
Christoph Hellwiga6dda0e2013-12-20 05:16:45 -08001170 .set_acl = f2fs_set_acl,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001171#ifdef CONFIG_F2FS_FS_XATTR
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001172 .listxattr = f2fs_listxattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001173#endif
1174};