blob: 73fa356f8fbb0da2cc6782a310026d6fba3dbdeb [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;
49 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
50 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);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090094
Chao Yu741a7be2015-07-06 20:30:40 +080095 /*
96 * filename format of multimedia file should be defined as:
97 * "filename + '.' + extension".
98 */
99 if (slen < sublen + 2)
100 return 0;
101
102 if (s[slen - sublen - 1] != '.')
Namjae Jeone66509f02013-04-20 01:27:21 +0900103 return 0;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900104
Gu Zheng749ebfd2013-08-22 18:11:25 +0800105 return !strncasecmp(s + slen - sublen, sub, sublen);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900106}
107
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +0900108/*
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900109 * Set multimedia files as cold files for hot/cold data separation
110 */
Jaegeuk Kim953a3e22013-03-21 15:21:57 +0900111static inline void set_cold_files(struct f2fs_sb_info *sbi, struct inode *inode,
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900112 const unsigned char *name)
113{
114 int i;
115 __u8 (*extlist)[8] = sbi->raw_super->extension_list;
116
117 int count = le32_to_cpu(sbi->raw_super->extension_count);
118 for (i = 0; i < count; i++) {
Namjae Jeone66509f02013-04-20 01:27:21 +0900119 if (is_multimedia_file(name, extlist[i])) {
Jaegeuk Kim354a3392013-06-14 08:52:35 +0900120 file_set_cold(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900121 break;
122 }
123 }
124}
125
126static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
127 bool excl)
128{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700129 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900130 struct inode *inode;
131 nid_t ino = 0;
Gu Zhenge4795562013-09-27 18:08:30 +0800132 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900133
134 inode = f2fs_new_inode(dir, mode);
135 if (IS_ERR(inode))
136 return PTR_ERR(inode);
137
138 if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
Jaegeuk Kim953a3e22013-03-21 15:21:57 +0900139 set_cold_files(sbi, inode, dentry->d_name.name);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900140
141 inode->i_op = &f2fs_file_inode_operations;
142 inode->i_fop = &f2fs_file_operations;
143 inode->i_mapping->a_ops = &f2fs_dblock_aops;
144 ino = inode->i_ino;
145
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800146 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800147
Gu Zhenge4795562013-09-27 18:08:30 +0800148 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900149 err = f2fs_add_link(dentry, inode);
150 if (err)
151 goto out;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700152 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900153
154 alloc_nid_done(sbi, ino);
155
Jaegeuk Kim0a364af2013-05-16 08:57:43 +0900156 d_instantiate(dentry, inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900157 unlock_new_inode(inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800158
159 if (IS_DIRSYNC(dir))
160 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900161 return 0;
162out:
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700163 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900164 return err;
165}
166
167static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
168 struct dentry *dentry)
169{
David Howells2b0143b2015-03-17 22:25:59 +0000170 struct inode *inode = d_inode(old_dentry);
Jaegeuk Kim40813632014-09-02 15:31:18 -0700171 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Gu Zhenge4795562013-09-27 18:08:30 +0800172 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900173
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700174 if (f2fs_encrypted_inode(dir) &&
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700175 !fscrypt_has_permitted_context(dir, inode))
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700176 return -EPERM;
177
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800178 f2fs_balance_fs(sbi, true);
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900179
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900180 inode->i_ctime = CURRENT_TIME;
Jaegeuk Kim6f6fd832013-05-22 12:06:26 +0900181 ihold(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900182
Jaegeuk Kim91942322016-05-20 10:13:22 -0700183 set_inode_flag(inode, FI_INC_LINK);
Gu Zhenge4795562013-09-27 18:08:30 +0800184 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900185 err = f2fs_add_link(dentry, inode);
186 if (err)
187 goto out;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700188 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900189
190 d_instantiate(dentry, inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800191
192 if (IS_DIRSYNC(dir))
193 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900194 return 0;
195out:
Jaegeuk Kim91942322016-05-20 10:13:22 -0700196 clear_inode_flag(inode, FI_INC_LINK);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900197 iput(inode);
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700198 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900199 return err;
200}
201
202struct dentry *f2fs_get_parent(struct dentry *child)
203{
204 struct qstr dotdot = QSTR_INIT("..", 2);
Chao Yu91246c22016-07-19 08:27:47 +0800205 struct page *page;
206 unsigned long ino = f2fs_inode_by_name(d_inode(child), &dotdot, &page);
207 if (!ino) {
208 if (IS_ERR(page))
209 return ERR_CAST(page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900210 return ERR_PTR(-ENOENT);
Chao Yu91246c22016-07-19 08:27:47 +0800211 }
Al Virofc640052016-04-10 01:33:30 -0400212 return d_obtain_alias(f2fs_iget(child->d_sb, ino));
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900213}
214
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700215static int __recover_dot_dentries(struct inode *dir, nid_t pino)
216{
217 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
218 struct qstr dot = QSTR_INIT(".", 1);
219 struct qstr dotdot = QSTR_INIT("..", 2);
220 struct f2fs_dir_entry *de;
221 struct page *page;
222 int err = 0;
223
Chao Yu4e0d8362015-12-30 17:40:31 +0800224 if (f2fs_readonly(sbi->sb)) {
225 f2fs_msg(sbi->sb, KERN_INFO,
226 "skip recovering inline_dots inode (ino:%lu, pino:%u) "
227 "in readonly mountpoint", dir->i_ino, pino);
228 return 0;
229 }
230
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800231 f2fs_balance_fs(sbi, true);
Chao Yud5384172015-12-24 18:03:29 +0800232
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700233 f2fs_lock_op(sbi);
234
235 de = f2fs_find_entry(dir, &dot, &page);
236 if (de) {
237 f2fs_dentry_kunmap(dir, page);
238 f2fs_put_page(page, 0);
Jaegeuk Kim42d96402016-05-25 14:29:11 -0700239 } else if (IS_ERR(page)) {
240 err = PTR_ERR(page);
241 goto out;
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700242 } else {
243 err = __f2fs_add_link(dir, &dot, NULL, dir->i_ino, S_IFDIR);
244 if (err)
245 goto out;
246 }
247
248 de = f2fs_find_entry(dir, &dotdot, &page);
249 if (de) {
250 f2fs_dentry_kunmap(dir, page);
251 f2fs_put_page(page, 0);
Jaegeuk Kim42d96402016-05-25 14:29:11 -0700252 } else if (IS_ERR(page)) {
253 err = PTR_ERR(page);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700254 } else {
255 err = __f2fs_add_link(dir, &dotdot, NULL, pino, S_IFDIR);
256 }
257out:
Jaegeuk Kim205b9822016-05-20 09:52:20 -0700258 if (!err)
Jaegeuk Kim91942322016-05-20 10:13:22 -0700259 clear_inode_flag(dir, FI_INLINE_DOTS);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700260
261 f2fs_unlock_op(sbi);
262 return err;
263}
264
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900265static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
266 unsigned int flags)
267{
268 struct inode *inode = NULL;
269 struct f2fs_dir_entry *de;
270 struct page *page;
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700271 nid_t ino;
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700272 int err = 0;
Liu Xue8c2b1432016-02-26 06:39:23 +0000273 unsigned int root_ino = F2FS_ROOT_INO(F2FS_I_SB(dir));
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900274
Jaegeuk Kim8074bb52016-02-23 09:21:37 -0800275 if (f2fs_encrypted_inode(dir)) {
276 int res = fscrypt_get_encryption_info(dir);
277
278 /*
279 * DCACHE_ENCRYPTED_WITH_KEY is set if the dentry is
280 * created while the directory was encrypted and we
281 * don't have access to the key.
282 */
283 if (fscrypt_has_encryption_key(dir))
284 fscrypt_set_encrypted_dentry(dentry);
285 fscrypt_set_d_op(dentry);
286 if (res && res != -ENOKEY)
287 return ERR_PTR(res);
288 }
289
Jaegeuk Kim5a20d332013-03-03 13:58:05 +0900290 if (dentry->d_name.len > F2FS_NAME_LEN)
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900291 return ERR_PTR(-ENAMETOOLONG);
292
293 de = f2fs_find_entry(dir, &dentry->d_name, &page);
Jaegeuk Kimeb4246d2016-05-27 10:10:41 -0700294 if (!de) {
295 if (IS_ERR(page))
296 return (struct dentry *)page;
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700297 return d_splice_alias(inode, dentry);
Jaegeuk Kimeb4246d2016-05-27 10:10:41 -0700298 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900299
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700300 ino = le32_to_cpu(de->ino);
301 f2fs_dentry_kunmap(dir, page);
302 f2fs_put_page(page, 0);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700303
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700304 inode = f2fs_iget(dir->i_sb, ino);
305 if (IS_ERR(inode))
306 return ERR_CAST(inode);
Jaegeuk Kim510022a2015-03-30 15:07:16 -0700307
Liu Xue8c2b1432016-02-26 06:39:23 +0000308 if ((dir->i_ino == root_ino) && f2fs_has_inline_dots(dir)) {
309 err = __recover_dot_dentries(dir, root_ino);
310 if (err)
311 goto err_out;
312 }
313
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700314 if (f2fs_has_inline_dots(inode)) {
Jaegeuk Kim06957e82015-04-22 11:40:27 -0700315 err = __recover_dot_dentries(inode, dir->i_ino);
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700316 if (err)
317 goto err_out;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900318 }
Jaegeuk Kim8074bb52016-02-23 09:21:37 -0800319 if (!IS_ERR(inode) && f2fs_encrypted_inode(dir) &&
320 (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
321 !fscrypt_has_permitted_context(dir, inode)) {
322 bool nokey = f2fs_encrypted_inode(inode) &&
323 !fscrypt_has_encryption_key(inode);
Chao Yud7267322016-03-10 22:24:23 +0800324 err = nokey ? -ENOKEY : -EPERM;
325 goto err_out;
Jaegeuk Kim8074bb52016-02-23 09:21:37 -0800326 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900327 return d_splice_alias(inode, dentry);
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700328
329err_out:
Chao Yud7267322016-03-10 22:24:23 +0800330 iput(inode);
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700331 return ERR_PTR(err);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900332}
333
334static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
335{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700336 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
David Howells2b0143b2015-03-17 22:25:59 +0000337 struct inode *inode = d_inode(dentry);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900338 struct f2fs_dir_entry *de;
339 struct page *page;
340 int err = -ENOENT;
341
Namjae Jeona2a4a7e2013-04-20 01:28:40 +0900342 trace_f2fs_unlink_enter(dir, dentry);
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900343
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900344 de = f2fs_find_entry(dir, &dentry->d_name, &page);
Chao Yu91246c22016-07-19 08:27:47 +0800345 if (!de) {
346 if (IS_ERR(page))
347 err = PTR_ERR(page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900348 goto fail;
Chao Yu91246c22016-07-19 08:27:47 +0800349 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900350
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800351 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800352
Jaegeuk Kimccaaca22013-10-08 10:19:28 +0900353 f2fs_lock_op(sbi);
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900354 err = acquire_orphan_inode(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900355 if (err) {
Jaegeuk Kimccaaca22013-10-08 10:19:28 +0900356 f2fs_unlock_op(sbi);
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800357 f2fs_dentry_kunmap(dir, page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900358 f2fs_put_page(page, 0);
359 goto fail;
360 }
Chao Yudbeacf02014-09-24 18:17:04 +0800361 f2fs_delete_entry(de, page, dir, inode);
Gu Zhenge4795562013-09-27 18:08:30 +0800362 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900363
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800364 if (IS_DIRSYNC(dir))
365 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900366fail:
Namjae Jeona2a4a7e2013-04-20 01:28:40 +0900367 trace_f2fs_unlink_exit(inode, err);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900368 return err;
369}
370
Al Viro6b255392015-11-17 10:20:54 -0500371static const char *f2fs_get_link(struct dentry *dentry,
Al Virofceef392015-12-29 15:58:39 -0500372 struct inode *inode,
373 struct delayed_call *done)
Jaegeuk Kimfeb7cbb2015-04-15 13:49:55 -0700374{
Al Virofceef392015-12-29 15:58:39 -0500375 const char *link = page_get_link(dentry, inode, done);
Al Viro680baac2015-05-02 13:32:22 -0400376 if (!IS_ERR(link) && !*link) {
377 /* this is broken symlink case */
Al Virofceef392015-12-29 15:58:39 -0500378 do_delayed_call(done);
379 clear_delayed_call(done);
Al Viro680baac2015-05-02 13:32:22 -0400380 link = ERR_PTR(-ENOENT);
Jaegeuk Kimfeb7cbb2015-04-15 13:49:55 -0700381 }
Al Viro680baac2015-05-02 13:32:22 -0400382 return link;
Jaegeuk Kimfeb7cbb2015-04-15 13:49:55 -0700383}
384
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900385static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
386 const char *symname)
387{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700388 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900389 struct inode *inode;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700390 size_t len = strlen(symname);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700391 struct fscrypt_str disk_link = FSTR_INIT((char *)symname, len + 1);
392 struct fscrypt_symlink_data *sd = NULL;
Gu Zhenge4795562013-09-27 18:08:30 +0800393 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900394
Chao Yu922ec352016-02-15 17:54:26 +0800395 if (f2fs_encrypted_inode(dir)) {
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700396 err = fscrypt_get_encryption_info(dir);
Chao Yu922ec352016-02-15 17:54:26 +0800397 if (err)
398 return err;
399
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700400 if (!fscrypt_has_encryption_key(dir))
Chao Yu922ec352016-02-15 17:54:26 +0800401 return -EPERM;
402
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700403 disk_link.len = (fscrypt_fname_encrypted_size(dir, len) +
404 sizeof(struct fscrypt_symlink_data));
Chao Yu922ec352016-02-15 17:54:26 +0800405 }
406
407 if (disk_link.len > dir->i_sb->s_blocksize)
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700408 return -ENAMETOOLONG;
409
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900410 inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO);
411 if (IS_ERR(inode))
412 return PTR_ERR(inode);
413
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700414 if (f2fs_encrypted_inode(inode))
415 inode->i_op = &f2fs_encrypted_symlink_inode_operations;
416 else
417 inode->i_op = &f2fs_symlink_inode_operations;
Al Viro21fc61c2015-11-17 01:07:57 -0500418 inode_nohighmem(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900419 inode->i_mapping->a_ops = &f2fs_dblock_aops;
420
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800421 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800422
Gu Zhenge4795562013-09-27 18:08:30 +0800423 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900424 err = f2fs_add_link(dentry, inode);
425 if (err)
426 goto out;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700427 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900428 alloc_nid_done(sbi, inode->i_ino);
429
Chao Yu922ec352016-02-15 17:54:26 +0800430 if (f2fs_encrypted_inode(inode)) {
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700431 struct qstr istr = QSTR_INIT(symname, len);
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700432 struct fscrypt_str ostr;
Chao Yu922ec352016-02-15 17:54:26 +0800433
434 sd = kzalloc(disk_link.len, GFP_NOFS);
435 if (!sd) {
436 err = -ENOMEM;
437 goto err_out;
438 }
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700439
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700440 err = fscrypt_get_encryption_info(inode);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700441 if (err)
442 goto err_out;
443
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700444 if (!fscrypt_has_encryption_key(inode)) {
Chao Yu922ec352016-02-15 17:54:26 +0800445 err = -EPERM;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700446 goto err_out;
Chao Yu922ec352016-02-15 17:54:26 +0800447 }
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700448
Chao Yu922ec352016-02-15 17:54:26 +0800449 ostr.name = sd->encrypted_path;
450 ostr.len = disk_link.len;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700451 err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700452 if (err < 0)
453 goto err_out;
454
Chao Yu922ec352016-02-15 17:54:26 +0800455 sd->len = cpu_to_le16(ostr.len);
456 disk_link.name = (char *)sd;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700457 }
458
Chao Yu922ec352016-02-15 17:54:26 +0800459 err = page_symlink(inode, disk_link.name, disk_link.len);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700460
461err_out:
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900462 d_instantiate(dentry, inode);
463 unlock_new_inode(inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800464
Jaegeuk Kimd0cae972015-04-15 13:37:53 -0700465 /*
466 * Let's flush symlink data in order to avoid broken symlink as much as
467 * possible. Nevertheless, fsyncing is the best way, but there is no
468 * way to get a file descriptor in order to flush that.
469 *
470 * Note that, it needs to do dir->fsync to make this recoverable.
471 * If the symlink path is stored into inline_data, there is no
472 * performance regression.
473 */
Chao Yua6be0142015-10-22 18:23:08 +0800474 if (!err) {
Chao Yu922ec352016-02-15 17:54:26 +0800475 filemap_write_and_wait_range(inode->i_mapping, 0,
476 disk_link.len - 1);
Jaegeuk Kimd0cae972015-04-15 13:37:53 -0700477
Chao Yua6be0142015-10-22 18:23:08 +0800478 if (IS_DIRSYNC(dir))
479 f2fs_sync_fs(sbi->sb, 1);
480 } else {
481 f2fs_unlink(dir, dentry);
482 }
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -0700483
484 kfree(sd);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900485 return err;
486out:
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700487 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900488 return err;
489}
490
491static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
492{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700493 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900494 struct inode *inode;
Gu Zhenge4795562013-09-27 18:08:30 +0800495 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900496
497 inode = f2fs_new_inode(dir, S_IFDIR | mode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900498 if (IS_ERR(inode))
Namjae Jeon61412b62012-12-01 10:56:25 +0900499 return PTR_ERR(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900500
501 inode->i_op = &f2fs_dir_inode_operations;
502 inode->i_fop = &f2fs_dir_operations;
503 inode->i_mapping->a_ops = &f2fs_dblock_aops;
Chao Yu560d4672015-02-07 17:36:15 +0800504 mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_HIGH_ZERO);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900505
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800506 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800507
Jaegeuk Kim91942322016-05-20 10:13:22 -0700508 set_inode_flag(inode, FI_INC_LINK);
Gu Zhenge4795562013-09-27 18:08:30 +0800509 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900510 err = f2fs_add_link(dentry, inode);
511 if (err)
512 goto out_fail;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700513 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900514
515 alloc_nid_done(sbi, inode->i_ino);
516
517 d_instantiate(dentry, inode);
518 unlock_new_inode(inode);
519
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800520 if (IS_DIRSYNC(dir))
521 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900522 return 0;
523
524out_fail:
Jaegeuk Kim91942322016-05-20 10:13:22 -0700525 clear_inode_flag(inode, FI_INC_LINK);
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700526 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900527 return err;
528}
529
530static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)
531{
David Howells2b0143b2015-03-17 22:25:59 +0000532 struct inode *inode = d_inode(dentry);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900533 if (f2fs_empty_dir(inode))
534 return f2fs_unlink(dir, dentry);
535 return -ENOTEMPTY;
536}
537
538static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
539 umode_t mode, dev_t rdev)
540{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700541 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900542 struct inode *inode;
543 int err = 0;
544
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900545 inode = f2fs_new_inode(dir, mode);
546 if (IS_ERR(inode))
547 return PTR_ERR(inode);
548
549 init_special_inode(inode, inode->i_mode, rdev);
550 inode->i_op = &f2fs_special_inode_operations;
551
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800552 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800553
Gu Zhenge4795562013-09-27 18:08:30 +0800554 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900555 err = f2fs_add_link(dentry, inode);
556 if (err)
557 goto out;
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700558 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900559
560 alloc_nid_done(sbi, inode->i_ino);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800561
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900562 d_instantiate(dentry, inode);
563 unlock_new_inode(inode);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800564
565 if (IS_DIRSYNC(dir))
566 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900567 return 0;
568out:
Jaegeuk Kim44c16152014-09-25 11:55:53 -0700569 handle_failed_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900570 return err;
571}
572
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800573static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,
574 umode_t mode, struct inode **whiteout)
575{
576 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
577 struct inode *inode;
578 int err;
579
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800580 inode = f2fs_new_inode(dir, mode);
581 if (IS_ERR(inode))
582 return PTR_ERR(inode);
583
584 if (whiteout) {
585 init_special_inode(inode, inode->i_mode, WHITEOUT_DEV);
586 inode->i_op = &f2fs_special_inode_operations;
587 } else {
588 inode->i_op = &f2fs_file_inode_operations;
589 inode->i_fop = &f2fs_file_operations;
590 inode->i_mapping->a_ops = &f2fs_dblock_aops;
591 }
592
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800593 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800594
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800595 f2fs_lock_op(sbi);
596 err = acquire_orphan_inode(sbi);
597 if (err)
598 goto out;
599
600 err = f2fs_do_tmpfile(inode, dir);
601 if (err)
602 goto release_out;
603
604 /*
605 * add this non-linked tmpfile to orphan list, in this way we could
606 * remove all unused data of tmpfile after abnormal power-off.
607 */
Jaegeuk Kim67c37582016-06-13 18:27:02 -0700608 add_orphan_inode(inode);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800609 alloc_nid_done(sbi, inode->i_ino);
610
611 if (whiteout) {
Jaegeuk Kima1961242016-05-20 09:43:20 -0700612 f2fs_i_links_write(inode, false);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800613 *whiteout = inode;
614 } else {
615 d_tmpfile(dentry, inode);
616 }
Jaegeuk Kima1961242016-05-20 09:43:20 -0700617 /* link_count was changed by d_tmpfile as well. */
618 f2fs_unlock_op(sbi);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800619 unlock_new_inode(inode);
620 return 0;
621
622release_out:
623 release_orphan_inode(sbi);
624out:
625 handle_failed_inode(inode);
626 return err;
627}
628
629static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
630{
Jaegeuk Kim304eecc2015-05-19 16:11:40 -0700631 if (f2fs_encrypted_inode(dir)) {
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700632 int err = fscrypt_get_encryption_info(dir);
Jaegeuk Kim304eecc2015-05-19 16:11:40 -0700633 if (err)
634 return err;
635 }
636
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800637 return __f2fs_tmpfile(dir, dentry, mode, NULL);
638}
639
640static int f2fs_create_whiteout(struct inode *dir, struct inode **whiteout)
641{
642 return __f2fs_tmpfile(dir, NULL, S_IFCHR | WHITEOUT_MODE, whiteout);
643}
644
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900645static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800646 struct inode *new_dir, struct dentry *new_dentry,
647 unsigned int flags)
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900648{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700649 struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
David Howells2b0143b2015-03-17 22:25:59 +0000650 struct inode *old_inode = d_inode(old_dentry);
651 struct inode *new_inode = d_inode(new_dentry);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800652 struct inode *whiteout = NULL;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900653 struct page *old_dir_page;
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800654 struct page *old_page, *new_page = NULL;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900655 struct f2fs_dir_entry *old_dir_entry = NULL;
656 struct f2fs_dir_entry *old_entry;
657 struct f2fs_dir_entry *new_entry;
Chao Yu993a0492016-02-17 16:47:05 +0800658 bool is_old_inline = f2fs_has_inline_dentry(old_dir);
Gu Zhenge4795562013-09-27 18:08:30 +0800659 int err = -ENOENT;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900660
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700661 if ((old_dir != new_dir) && f2fs_encrypted_inode(new_dir) &&
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700662 !fscrypt_has_permitted_context(new_dir, old_inode)) {
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -0700663 err = -EPERM;
664 goto out;
665 }
666
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900667 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
Chao Yu91246c22016-07-19 08:27:47 +0800668 if (!old_entry) {
669 if (IS_ERR(old_page))
670 err = PTR_ERR(old_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900671 goto out;
Chao Yu91246c22016-07-19 08:27:47 +0800672 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900673
674 if (S_ISDIR(old_inode->i_mode)) {
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900675 old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page);
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700676 if (!old_dir_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800677 if (IS_ERR(old_dir_page))
678 err = PTR_ERR(old_dir_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900679 goto out_old;
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700680 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900681 }
682
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800683 if (flags & RENAME_WHITEOUT) {
684 err = f2fs_create_whiteout(old_dir, &whiteout);
685 if (err)
686 goto out_dir;
687 }
688
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900689 if (new_inode) {
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900690
691 err = -ENOTEMPTY;
692 if (old_dir_entry && !f2fs_empty_dir(new_inode))
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800693 goto out_whiteout;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900694
695 err = -ENOENT;
696 new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name,
697 &new_page);
Chao Yu91246c22016-07-19 08:27:47 +0800698 if (!new_entry) {
699 if (IS_ERR(new_page))
700 err = PTR_ERR(new_page);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800701 goto out_whiteout;
Chao Yu91246c22016-07-19 08:27:47 +0800702 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900703
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800704 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800705
Chao Yu12560102014-06-24 14:16:24 +0800706 f2fs_lock_op(sbi);
707
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900708 err = acquire_orphan_inode(sbi);
709 if (err)
710 goto put_out_dir;
711
Chao Yu9def1e92016-02-17 16:45:44 +0800712 err = update_dent_inode(old_inode, new_inode,
713 &new_dentry->d_name);
714 if (err) {
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900715 release_orphan_inode(sbi);
716 goto put_out_dir;
Jaegeuk Kim1cd14ca2013-07-18 18:02:31 +0900717 }
718
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900719 f2fs_set_link(new_dir, new_entry, new_page, old_inode);
720
721 new_inode->i_ctime = CURRENT_TIME;
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900722 down_write(&F2FS_I(new_inode)->i_sem);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900723 if (old_dir_entry)
Jaegeuk Kima1961242016-05-20 09:43:20 -0700724 f2fs_i_links_write(new_inode, false);
725 f2fs_i_links_write(new_inode, false);
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900726 up_write(&F2FS_I(new_inode)->i_sem);
727
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900728 if (!new_inode->i_nlink)
Jaegeuk Kim67c37582016-06-13 18:27:02 -0700729 add_orphan_inode(new_inode);
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900730 else
731 release_orphan_inode(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900732 } else {
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800733 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800734
Chao Yu12560102014-06-24 14:16:24 +0800735 f2fs_lock_op(sbi);
736
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900737 err = f2fs_add_link(new_dentry, old_inode);
Chao Yu12560102014-06-24 14:16:24 +0800738 if (err) {
739 f2fs_unlock_op(sbi);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800740 goto out_whiteout;
Chao Yu12560102014-06-24 14:16:24 +0800741 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900742
Jaegeuk Kimee6d1822016-05-20 16:32:49 -0700743 if (old_dir_entry)
Jaegeuk Kima1961242016-05-20 09:43:20 -0700744 f2fs_i_links_write(new_dir, true);
Chao Yu993a0492016-02-17 16:47:05 +0800745
746 /*
747 * old entry and new entry can locate in the same inline
748 * dentry in inode, when attaching new entry in inline dentry,
749 * it could force inline dentry conversion, after that,
750 * old_entry and old_page will point to wrong address, in
751 * order to avoid this, let's do the check and update here.
752 */
753 if (is_old_inline && !f2fs_has_inline_dentry(old_dir)) {
754 f2fs_put_page(old_page, 0);
755 old_page = NULL;
756
757 old_entry = f2fs_find_entry(old_dir,
758 &old_dentry->d_name, &old_page);
759 if (!old_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800760 err = -ENOENT;
761 if (IS_ERR(old_page))
762 err = PTR_ERR(old_page);
Chao Yu993a0492016-02-17 16:47:05 +0800763 f2fs_unlock_op(sbi);
764 goto out_whiteout;
765 }
766 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900767 }
768
Jaegeuk Kimb2c08292014-06-30 18:09:55 +0900769 down_write(&F2FS_I(old_inode)->i_sem);
770 file_lost_pino(old_inode);
Jaegeuk Kime7d55452015-04-29 17:02:18 -0700771 if (new_inode && file_enc_name(new_inode))
772 file_set_enc_name(old_inode);
Jaegeuk Kimb2c08292014-06-30 18:09:55 +0900773 up_write(&F2FS_I(old_inode)->i_sem);
774
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900775 old_inode->i_ctime = CURRENT_TIME;
Jaegeuk Kimb56ab832016-06-30 19:09:37 -0700776 f2fs_mark_inode_dirty_sync(old_inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900777
Chao Yudbeacf02014-09-24 18:17:04 +0800778 f2fs_delete_entry(old_entry, old_page, old_dir, NULL);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900779
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800780 if (whiteout) {
781 whiteout->i_state |= I_LINKABLE;
Jaegeuk Kim91942322016-05-20 10:13:22 -0700782 set_inode_flag(whiteout, FI_INC_LINK);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800783 err = f2fs_add_link(old_dentry, whiteout);
784 if (err)
785 goto put_out_dir;
786 whiteout->i_state &= ~I_LINKABLE;
787 iput(whiteout);
788 }
789
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900790 if (old_dir_entry) {
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800791 if (old_dir != new_dir && !whiteout) {
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900792 f2fs_set_link(old_inode, old_dir_entry,
793 old_dir_page, new_dir);
794 } else {
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800795 f2fs_dentry_kunmap(old_inode, old_dir_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900796 f2fs_put_page(old_dir_page, 0);
797 }
Jaegeuk Kima1961242016-05-20 09:43:20 -0700798 f2fs_i_links_write(old_dir, false);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900799 }
800
Gu Zhenge4795562013-09-27 18:08:30 +0800801 f2fs_unlock_op(sbi);
Jaegeuk Kimb7e1d802014-11-09 22:15:31 -0800802
803 if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
804 f2fs_sync_fs(sbi->sb, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900805 return 0;
806
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900807put_out_dir:
Chao Yu12560102014-06-24 14:16:24 +0800808 f2fs_unlock_op(sbi);
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800809 if (new_page) {
810 f2fs_dentry_kunmap(new_dir, new_page);
811 f2fs_put_page(new_page, 0);
812 }
813out_whiteout:
814 if (whiteout)
815 iput(whiteout);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900816out_dir:
817 if (old_dir_entry) {
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800818 f2fs_dentry_kunmap(old_inode, old_dir_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900819 f2fs_put_page(old_dir_page, 0);
820 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900821out_old:
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800822 f2fs_dentry_kunmap(old_dir, old_page);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900823 f2fs_put_page(old_page, 0);
824out:
825 return err;
826}
827
Chao Yu32f9bc22014-07-12 19:13:54 +0800828static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
829 struct inode *new_dir, struct dentry *new_dentry)
830{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700831 struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
David Howells2b0143b2015-03-17 22:25:59 +0000832 struct inode *old_inode = d_inode(old_dentry);
833 struct inode *new_inode = d_inode(new_dentry);
Chao Yu32f9bc22014-07-12 19:13:54 +0800834 struct page *old_dir_page, *new_dir_page;
835 struct page *old_page, *new_page;
836 struct f2fs_dir_entry *old_dir_entry = NULL, *new_dir_entry = NULL;
837 struct f2fs_dir_entry *old_entry, *new_entry;
838 int old_nlink = 0, new_nlink = 0;
839 int err = -ENOENT;
840
Chao Yud3baf7c2015-05-25 18:07:02 +0800841 if ((f2fs_encrypted_inode(old_dir) || f2fs_encrypted_inode(new_dir)) &&
Jaegeuk Kim0b81d072015-05-15 16:26:10 -0700842 (old_dir != new_dir) &&
843 (!fscrypt_has_permitted_context(new_dir, old_inode) ||
844 !fscrypt_has_permitted_context(old_dir, new_inode)))
Chao Yud3baf7c2015-05-25 18:07:02 +0800845 return -EPERM;
846
Chao Yu32f9bc22014-07-12 19:13:54 +0800847 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
Chao Yu91246c22016-07-19 08:27:47 +0800848 if (!old_entry) {
849 if (IS_ERR(old_page))
850 err = PTR_ERR(old_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800851 goto out;
Chao Yu91246c22016-07-19 08:27:47 +0800852 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800853
854 new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, &new_page);
Chao Yu91246c22016-07-19 08:27:47 +0800855 if (!new_entry) {
856 if (IS_ERR(new_page))
857 err = PTR_ERR(new_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800858 goto out_old;
Chao Yu91246c22016-07-19 08:27:47 +0800859 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800860
861 /* prepare for updating ".." directory entry info later */
862 if (old_dir != new_dir) {
863 if (S_ISDIR(old_inode->i_mode)) {
Chao Yu32f9bc22014-07-12 19:13:54 +0800864 old_dir_entry = f2fs_parent_dir(old_inode,
865 &old_dir_page);
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700866 if (!old_dir_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800867 if (IS_ERR(old_dir_page))
868 err = PTR_ERR(old_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800869 goto out_new;
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700870 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800871 }
872
873 if (S_ISDIR(new_inode->i_mode)) {
Chao Yu32f9bc22014-07-12 19:13:54 +0800874 new_dir_entry = f2fs_parent_dir(new_inode,
875 &new_dir_page);
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700876 if (!new_dir_entry) {
Chao Yu91246c22016-07-19 08:27:47 +0800877 if (IS_ERR(new_dir_page))
878 err = PTR_ERR(new_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800879 goto out_old_dir;
Jaegeuk Kim3e198862016-06-09 14:57:19 -0700880 }
Chao Yu32f9bc22014-07-12 19:13:54 +0800881 }
882 }
883
884 /*
885 * If cross rename between file and directory those are not
886 * in the same directory, we will inc nlink of file's parent
887 * later, so we should check upper boundary of its nlink.
888 */
889 if ((!old_dir_entry || !new_dir_entry) &&
890 old_dir_entry != new_dir_entry) {
891 old_nlink = old_dir_entry ? -1 : 1;
892 new_nlink = -old_nlink;
893 err = -EMLINK;
894 if ((old_nlink > 0 && old_inode->i_nlink >= F2FS_LINK_MAX) ||
895 (new_nlink > 0 && new_inode->i_nlink >= F2FS_LINK_MAX))
896 goto out_new_dir;
897 }
898
Jaegeuk Kim2c4db1a2016-01-07 14:15:04 -0800899 f2fs_balance_fs(sbi, true);
Jaegeuk Kim00623e62015-12-22 11:56:08 -0800900
Chao Yu32f9bc22014-07-12 19:13:54 +0800901 f2fs_lock_op(sbi);
902
Jaegeuk Kime7d55452015-04-29 17:02:18 -0700903 err = update_dent_inode(old_inode, new_inode, &new_dentry->d_name);
Chao Yu32f9bc22014-07-12 19:13:54 +0800904 if (err)
905 goto out_unlock;
Jaegeuk Kime7d55452015-04-29 17:02:18 -0700906 if (file_enc_name(new_inode))
907 file_set_enc_name(old_inode);
Chao Yu32f9bc22014-07-12 19:13:54 +0800908
Jaegeuk Kime7d55452015-04-29 17:02:18 -0700909 err = update_dent_inode(new_inode, old_inode, &old_dentry->d_name);
Chao Yu32f9bc22014-07-12 19:13:54 +0800910 if (err)
911 goto out_undo;
Jaegeuk Kime7d55452015-04-29 17:02:18 -0700912 if (file_enc_name(old_inode))
913 file_set_enc_name(new_inode);
Chao Yu32f9bc22014-07-12 19:13:54 +0800914
915 /* 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
Chao Yu32f9bc22014-07-12 19:13:54 +0800930 old_dir->i_ctime = CURRENT_TIME;
931 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 Kimb56ab832016-06-30 19:09:37 -0700936 f2fs_mark_inode_dirty_sync(old_dir);
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
Chao Yu32f9bc22014-07-12 19:13:54 +0800945 new_dir->i_ctime = CURRENT_TIME;
946 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 Kimb56ab832016-06-30 19:09:37 -0700951 f2fs_mark_inode_dirty_sync(new_dir);
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;
958out_undo:
Jaegeuk Kime7d55452015-04-29 17:02:18 -0700959 /*
960 * Still we may fail to recover name info of f2fs_inode here
961 * Drop it, once its name is set as encrypted
962 */
963 update_dent_inode(old_inode, old_inode, &old_dentry->d_name);
Chao Yu32f9bc22014-07-12 19:13:54 +0800964out_unlock:
965 f2fs_unlock_op(sbi);
966out_new_dir:
967 if (new_dir_entry) {
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800968 f2fs_dentry_kunmap(new_inode, new_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800969 f2fs_put_page(new_dir_page, 0);
970 }
971out_old_dir:
972 if (old_dir_entry) {
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800973 f2fs_dentry_kunmap(old_inode, old_dir_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800974 f2fs_put_page(old_dir_page, 0);
975 }
976out_new:
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800977 f2fs_dentry_kunmap(new_dir, new_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800978 f2fs_put_page(new_page, 0);
979out_old:
Jaegeuk Kim9486ba4422014-11-21 16:36:28 -0800980 f2fs_dentry_kunmap(old_dir, old_page);
Chao Yu32f9bc22014-07-12 19:13:54 +0800981 f2fs_put_page(old_page, 0);
982out:
983 return err;
984}
985
986static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry,
987 struct inode *new_dir, struct dentry *new_dentry,
988 unsigned int flags)
989{
Chao Yu7e01e7ad2015-05-19 17:37:26 +0800990 if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
Chao Yu32f9bc22014-07-12 19:13:54 +0800991 return -EINVAL;
992
993 if (flags & RENAME_EXCHANGE) {
994 return f2fs_cross_rename(old_dir, old_dentry,
995 new_dir, new_dentry);
996 }
997 /*
998 * VFS has already handled the new dentry existence case,
999 * here, we just deal with "RENAME_NOREPLACE" as regular rename.
1000 */
Chao Yu7e01e7ad2015-05-19 17:37:26 +08001001 return f2fs_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
Chao Yu32f9bc22014-07-12 19:13:54 +08001002}
1003
Al Viro6b255392015-11-17 10:20:54 -05001004static const char *f2fs_encrypted_get_link(struct dentry *dentry,
Al Virofceef392015-12-29 15:58:39 -05001005 struct inode *inode,
1006 struct delayed_call *done)
Chao Yu50732df2014-06-19 16:23:19 +08001007{
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001008 struct page *cpage = NULL;
1009 char *caddr, *paddr = NULL;
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001010 struct fscrypt_str cstr = FSTR_INIT(NULL, 0);
1011 struct fscrypt_str pstr = FSTR_INIT(NULL, 0);
1012 struct fscrypt_symlink_data *sd;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001013 loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1);
1014 u32 max_size = inode->i_sb->s_blocksize;
1015 int res;
Chao Yu50732df2014-06-19 16:23:19 +08001016
Al Viro6b255392015-11-17 10:20:54 -05001017 if (!dentry)
1018 return ERR_PTR(-ECHILD);
1019
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001020 res = fscrypt_get_encryption_info(inode);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001021 if (res)
1022 return ERR_PTR(res);
Chao Yu50732df2014-06-19 16:23:19 +08001023
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001024 cpage = read_mapping_page(inode->i_mapping, 0, NULL);
1025 if (IS_ERR(cpage))
Linus Torvaldscfcc0ad2015-06-24 20:38:29 -07001026 return ERR_CAST(cpage);
Al Viro21fc61c2015-11-17 01:07:57 -05001027 caddr = page_address(cpage);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001028 caddr[size] = 0;
Chao Yu50732df2014-06-19 16:23:19 +08001029
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001030 /* Symlink is encrypted */
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001031 sd = (struct fscrypt_symlink_data *)caddr;
Chao Yu922ec352016-02-15 17:54:26 +08001032 cstr.name = sd->encrypted_path;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001033 cstr.len = le16_to_cpu(sd->len);
Jaegeuk Kim8dc0d6a2015-12-24 16:13:09 -08001034
1035 /* this is broken symlink case */
1036 if (unlikely(cstr.len == 0)) {
1037 res = -ENOENT;
1038 goto errout;
1039 }
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -07001040
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001041 if ((cstr.len + sizeof(struct fscrypt_symlink_data) - 1) > max_size) {
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001042 /* Symlink data on the disk is corrupted */
1043 res = -EIO;
1044 goto errout;
1045 }
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001046 res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001047 if (res)
1048 goto errout;
Chao Yu50732df2014-06-19 16:23:19 +08001049
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001050 res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001051 if (res < 0)
1052 goto errout;
Chao Yu3c0d84d2015-02-16 16:20:27 +08001053
Jaegeuk Kimc90e09f2016-03-30 13:13:16 -07001054 /* this is broken symlink case */
1055 if (unlikely(pstr.name[0] == 0)) {
1056 res = -ENOENT;
1057 goto errout;
1058 }
1059
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001060 paddr = pstr.name;
Jaegeuk Kimb97a9b52014-06-20 21:37:02 -07001061
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001062 /* Null-terminate the name */
1063 paddr[res] = '\0';
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001064
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001065 put_page(cpage);
Al Virofceef392015-12-29 15:58:39 -05001066 set_delayed_call(done, kfree_link, paddr);
1067 return paddr;
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001068errout:
Jaegeuk Kim0b81d072015-05-15 16:26:10 -07001069 fscrypt_fname_free_buffer(&pstr);
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03001070 put_page(cpage);
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001071 return ERR_PTR(res);
Chao Yu50732df2014-06-19 16:23:19 +08001072}
1073
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001074const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
1075 .readlink = generic_readlink,
Al Viro6b255392015-11-17 10:20:54 -05001076 .get_link = f2fs_encrypted_get_link,
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001077 .getattr = f2fs_getattr,
1078 .setattr = f2fs_setattr,
Chao Yu3a9e6432015-12-31 18:20:10 +08001079#ifdef CONFIG_F2FS_FS_XATTR
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001080 .setxattr = generic_setxattr,
1081 .getxattr = generic_getxattr,
1082 .listxattr = f2fs_listxattr,
1083 .removexattr = generic_removexattr,
Chao Yu3a9e6432015-12-31 18:20:10 +08001084#endif
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001085};
Jaegeuk Kimcbaf0422015-04-29 15:10:53 -07001086
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001087const struct inode_operations f2fs_dir_inode_operations = {
1088 .create = f2fs_create,
1089 .lookup = f2fs_lookup,
1090 .link = f2fs_link,
1091 .unlink = f2fs_unlink,
1092 .symlink = f2fs_symlink,
1093 .mkdir = f2fs_mkdir,
1094 .rmdir = f2fs_rmdir,
1095 .mknod = f2fs_mknod,
Chao Yu32f9bc22014-07-12 19:13:54 +08001096 .rename2 = f2fs_rename2,
Chao Yu50732df2014-06-19 16:23:19 +08001097 .tmpfile = f2fs_tmpfile,
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +09001098 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001099 .setattr = f2fs_setattr,
1100 .get_acl = f2fs_get_acl,
Christoph Hellwiga6dda0e2013-12-20 05:16:45 -08001101 .set_acl = f2fs_set_acl,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001102#ifdef CONFIG_F2FS_FS_XATTR
1103 .setxattr = generic_setxattr,
1104 .getxattr = generic_getxattr,
1105 .listxattr = f2fs_listxattr,
1106 .removexattr = generic_removexattr,
1107#endif
1108};
1109
1110const struct inode_operations f2fs_symlink_inode_operations = {
1111 .readlink = generic_readlink,
Al Viro6b255392015-11-17 10:20:54 -05001112 .get_link = f2fs_get_link,
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +09001113 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001114 .setattr = f2fs_setattr,
1115#ifdef CONFIG_F2FS_FS_XATTR
1116 .setxattr = generic_setxattr,
1117 .getxattr = generic_getxattr,
1118 .listxattr = f2fs_listxattr,
1119 .removexattr = generic_removexattr,
1120#endif
1121};
1122
1123const struct inode_operations f2fs_special_inode_operations = {
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +09001124 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001125 .setattr = f2fs_setattr,
1126 .get_acl = f2fs_get_acl,
Christoph Hellwiga6dda0e2013-12-20 05:16:45 -08001127 .set_acl = f2fs_set_acl,
Jaegeuk Kim57397d82012-11-02 17:11:10 +09001128#ifdef CONFIG_F2FS_FS_XATTR
1129 .setxattr = generic_setxattr,
1130 .getxattr = generic_getxattr,
1131 .listxattr = f2fs_listxattr,
1132 .removexattr = generic_removexattr,
1133#endif
1134};