blob: a9409d19dfd4815f38907b93f84ad3428383b07a [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>
16
17#include "f2fs.h"
Jaegeuk Kim953a3e22013-03-21 15:21:57 +090018#include "node.h"
Jaegeuk Kim57397d82012-11-02 17:11:10 +090019#include "xattr.h"
20#include "acl.h"
Namjae Jeona2a4a7e2013-04-20 01:28:40 +090021#include <trace/events/f2fs.h>
Jaegeuk Kim57397d82012-11-02 17:11:10 +090022
23static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
24{
25 struct super_block *sb = dir->i_sb;
26 struct f2fs_sb_info *sbi = F2FS_SB(sb);
27 nid_t ino;
28 struct inode *inode;
29 bool nid_free = false;
Gu Zhenge4795562013-09-27 18:08:30 +080030 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +090031
32 inode = new_inode(sb);
33 if (!inode)
34 return ERR_PTR(-ENOMEM);
35
Gu Zhenge4795562013-09-27 18:08:30 +080036 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090037 if (!alloc_nid(sbi, &ino)) {
Gu Zhenge4795562013-09-27 18:08:30 +080038 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090039 err = -ENOSPC;
40 goto fail;
41 }
Gu Zhenge4795562013-09-27 18:08:30 +080042 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090043
44 inode->i_uid = current_fsuid();
45
46 if (dir->i_mode & S_ISGID) {
47 inode->i_gid = dir->i_gid;
48 if (S_ISDIR(mode))
49 mode |= S_ISGID;
50 } else {
51 inode->i_gid = current_fsgid();
52 }
53
54 inode->i_ino = ino;
55 inode->i_mode = mode;
56 inode->i_blocks = 0;
57 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
58 inode->i_generation = sbi->s_next_generation++;
59
60 err = insert_inode_locked(inode);
61 if (err) {
62 err = -EINVAL;
63 nid_free = true;
64 goto out;
65 }
Jaegeuk Kimd70b4f52013-04-25 13:24:33 +090066 trace_f2fs_new_inode(inode, 0);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090067 mark_inode_dirty(inode);
68 return inode;
69
70out:
71 clear_nlink(inode);
72 unlock_new_inode(inode);
73fail:
Jaegeuk Kimd70b4f52013-04-25 13:24:33 +090074 trace_f2fs_new_inode(inode, err);
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +090075 make_bad_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090076 iput(inode);
77 if (nid_free)
78 alloc_nid_failed(sbi, ino);
79 return ERR_PTR(err);
80}
81
82static int is_multimedia_file(const unsigned char *s, const char *sub)
83{
Leon Romanovsky9836b8b2012-12-27 19:55:46 +020084 size_t slen = strlen(s);
85 size_t sublen = strlen(sub);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090086
87 if (sublen > slen)
Namjae Jeone66509f02013-04-20 01:27:21 +090088 return 0;
Jaegeuk Kim57397d82012-11-02 17:11:10 +090089
Gu Zheng749ebfd2013-08-22 18:11:25 +080090 return !strncasecmp(s + slen - sublen, sub, sublen);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090091}
92
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +090093/*
Jaegeuk Kim57397d82012-11-02 17:11:10 +090094 * Set multimedia files as cold files for hot/cold data separation
95 */
Jaegeuk Kim953a3e22013-03-21 15:21:57 +090096static inline void set_cold_files(struct f2fs_sb_info *sbi, struct inode *inode,
Jaegeuk Kim57397d82012-11-02 17:11:10 +090097 const unsigned char *name)
98{
99 int i;
100 __u8 (*extlist)[8] = sbi->raw_super->extension_list;
101
102 int count = le32_to_cpu(sbi->raw_super->extension_count);
103 for (i = 0; i < count; i++) {
Namjae Jeone66509f02013-04-20 01:27:21 +0900104 if (is_multimedia_file(name, extlist[i])) {
Jaegeuk Kim354a3392013-06-14 08:52:35 +0900105 file_set_cold(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900106 break;
107 }
108 }
109}
110
111static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
112 bool excl)
113{
114 struct super_block *sb = dir->i_sb;
115 struct f2fs_sb_info *sbi = F2FS_SB(sb);
116 struct inode *inode;
117 nid_t ino = 0;
Gu Zhenge4795562013-09-27 18:08:30 +0800118 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900119
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900120 f2fs_balance_fs(sbi);
121
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900122 inode = f2fs_new_inode(dir, mode);
123 if (IS_ERR(inode))
124 return PTR_ERR(inode);
125
126 if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
Jaegeuk Kim953a3e22013-03-21 15:21:57 +0900127 set_cold_files(sbi, inode, dentry->d_name.name);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900128
129 inode->i_op = &f2fs_file_inode_operations;
130 inode->i_fop = &f2fs_file_operations;
131 inode->i_mapping->a_ops = &f2fs_dblock_aops;
132 ino = inode->i_ino;
133
Gu Zhenge4795562013-09-27 18:08:30 +0800134 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900135 err = f2fs_add_link(dentry, inode);
Gu Zhenge4795562013-09-27 18:08:30 +0800136 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900137 if (err)
138 goto out;
139
140 alloc_nid_done(sbi, ino);
141
Jaegeuk Kim0a364af2013-05-16 08:57:43 +0900142 d_instantiate(dentry, inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900143 unlock_new_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900144 return 0;
145out:
146 clear_nlink(inode);
147 unlock_new_inode(inode);
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +0900148 make_bad_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900149 iput(inode);
150 alloc_nid_failed(sbi, ino);
151 return err;
152}
153
154static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
155 struct dentry *dentry)
156{
157 struct inode *inode = old_dentry->d_inode;
158 struct super_block *sb = dir->i_sb;
159 struct f2fs_sb_info *sbi = F2FS_SB(sb);
Gu Zhenge4795562013-09-27 18:08:30 +0800160 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900161
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900162 f2fs_balance_fs(sbi);
163
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900164 inode->i_ctime = CURRENT_TIME;
Jaegeuk Kim6f6fd832013-05-22 12:06:26 +0900165 ihold(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900166
167 set_inode_flag(F2FS_I(inode), FI_INC_LINK);
Gu Zhenge4795562013-09-27 18:08:30 +0800168 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900169 err = f2fs_add_link(dentry, inode);
Gu Zhenge4795562013-09-27 18:08:30 +0800170 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900171 if (err)
172 goto out;
173
174 d_instantiate(dentry, inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900175 return 0;
176out:
177 clear_inode_flag(F2FS_I(inode), FI_INC_LINK);
178 iput(inode);
179 return err;
180}
181
182struct dentry *f2fs_get_parent(struct dentry *child)
183{
184 struct qstr dotdot = QSTR_INIT("..", 2);
185 unsigned long ino = f2fs_inode_by_name(child->d_inode, &dotdot);
186 if (!ino)
187 return ERR_PTR(-ENOENT);
188 return d_obtain_alias(f2fs_iget(child->d_inode->i_sb, ino));
189}
190
191static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
192 unsigned int flags)
193{
194 struct inode *inode = NULL;
195 struct f2fs_dir_entry *de;
196 struct page *page;
197
Jaegeuk Kim5a20d332013-03-03 13:58:05 +0900198 if (dentry->d_name.len > F2FS_NAME_LEN)
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900199 return ERR_PTR(-ENAMETOOLONG);
200
201 de = f2fs_find_entry(dir, &dentry->d_name, &page);
202 if (de) {
203 nid_t ino = le32_to_cpu(de->ino);
204 kunmap(page);
205 f2fs_put_page(page, 0);
206
207 inode = f2fs_iget(dir->i_sb, ino);
208 if (IS_ERR(inode))
209 return ERR_CAST(inode);
Chao Yu48b230a2014-04-07 11:18:34 +0800210
211 stat_inc_inline_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900212 }
213
214 return d_splice_alias(inode, dentry);
215}
216
217static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
218{
219 struct super_block *sb = dir->i_sb;
220 struct f2fs_sb_info *sbi = F2FS_SB(sb);
221 struct inode *inode = dentry->d_inode;
222 struct f2fs_dir_entry *de;
223 struct page *page;
224 int err = -ENOENT;
225
Namjae Jeona2a4a7e2013-04-20 01:28:40 +0900226 trace_f2fs_unlink_enter(dir, dentry);
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900227 f2fs_balance_fs(sbi);
228
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900229 de = f2fs_find_entry(dir, &dentry->d_name, &page);
230 if (!de)
231 goto fail;
232
Jaegeuk Kimccaaca22013-10-08 10:19:28 +0900233 f2fs_lock_op(sbi);
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900234 err = acquire_orphan_inode(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900235 if (err) {
Jaegeuk Kimccaaca22013-10-08 10:19:28 +0900236 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900237 kunmap(page);
238 f2fs_put_page(page, 0);
239 goto fail;
240 }
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900241 f2fs_delete_entry(de, page, inode);
Gu Zhenge4795562013-09-27 18:08:30 +0800242 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900243
244 /* In order to evict this inode, we set it dirty */
245 mark_inode_dirty(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900246fail:
Namjae Jeona2a4a7e2013-04-20 01:28:40 +0900247 trace_f2fs_unlink_exit(inode, err);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900248 return err;
249}
250
251static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
252 const char *symname)
253{
254 struct super_block *sb = dir->i_sb;
255 struct f2fs_sb_info *sbi = F2FS_SB(sb);
256 struct inode *inode;
Leon Romanovsky9836b8b2012-12-27 19:55:46 +0200257 size_t symlen = strlen(symname) + 1;
Gu Zhenge4795562013-09-27 18:08:30 +0800258 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900259
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900260 f2fs_balance_fs(sbi);
261
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900262 inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO);
263 if (IS_ERR(inode))
264 return PTR_ERR(inode);
265
266 inode->i_op = &f2fs_symlink_inode_operations;
267 inode->i_mapping->a_ops = &f2fs_dblock_aops;
268
Gu Zhenge4795562013-09-27 18:08:30 +0800269 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900270 err = f2fs_add_link(dentry, inode);
Gu Zhenge4795562013-09-27 18:08:30 +0800271 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900272 if (err)
273 goto out;
274
275 err = page_symlink(inode, symname, symlen);
276 alloc_nid_done(sbi, inode->i_ino);
277
278 d_instantiate(dentry, inode);
279 unlock_new_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900280 return err;
281out:
282 clear_nlink(inode);
283 unlock_new_inode(inode);
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +0900284 make_bad_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900285 iput(inode);
286 alloc_nid_failed(sbi, inode->i_ino);
287 return err;
288}
289
290static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
291{
292 struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
293 struct inode *inode;
Gu Zhenge4795562013-09-27 18:08:30 +0800294 int err;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900295
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900296 f2fs_balance_fs(sbi);
297
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900298 inode = f2fs_new_inode(dir, S_IFDIR | mode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900299 if (IS_ERR(inode))
Namjae Jeon61412b62012-12-01 10:56:25 +0900300 return PTR_ERR(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900301
302 inode->i_op = &f2fs_dir_inode_operations;
303 inode->i_fop = &f2fs_dir_operations;
304 inode->i_mapping->a_ops = &f2fs_dblock_aops;
Namjae Jeona0d42532012-12-08 14:54:18 +0900305 mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_ZERO);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900306
307 set_inode_flag(F2FS_I(inode), FI_INC_LINK);
Gu Zhenge4795562013-09-27 18:08:30 +0800308 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900309 err = f2fs_add_link(dentry, inode);
Gu Zhenge4795562013-09-27 18:08:30 +0800310 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900311 if (err)
312 goto out_fail;
313
314 alloc_nid_done(sbi, inode->i_ino);
315
316 d_instantiate(dentry, inode);
317 unlock_new_inode(inode);
318
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900319 return 0;
320
321out_fail:
322 clear_inode_flag(F2FS_I(inode), FI_INC_LINK);
323 clear_nlink(inode);
324 unlock_new_inode(inode);
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +0900325 make_bad_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900326 iput(inode);
327 alloc_nid_failed(sbi, inode->i_ino);
328 return err;
329}
330
331static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)
332{
333 struct inode *inode = dentry->d_inode;
334 if (f2fs_empty_dir(inode))
335 return f2fs_unlink(dir, dentry);
336 return -ENOTEMPTY;
337}
338
339static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
340 umode_t mode, dev_t rdev)
341{
342 struct super_block *sb = dir->i_sb;
343 struct f2fs_sb_info *sbi = F2FS_SB(sb);
344 struct inode *inode;
345 int err = 0;
346
347 if (!new_valid_dev(rdev))
348 return -EINVAL;
349
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900350 f2fs_balance_fs(sbi);
351
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900352 inode = f2fs_new_inode(dir, mode);
353 if (IS_ERR(inode))
354 return PTR_ERR(inode);
355
356 init_special_inode(inode, inode->i_mode, rdev);
357 inode->i_op = &f2fs_special_inode_operations;
358
Gu Zhenge4795562013-09-27 18:08:30 +0800359 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900360 err = f2fs_add_link(dentry, inode);
Gu Zhenge4795562013-09-27 18:08:30 +0800361 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900362 if (err)
363 goto out;
364
365 alloc_nid_done(sbi, inode->i_ino);
366 d_instantiate(dentry, inode);
367 unlock_new_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900368 return 0;
369out:
370 clear_nlink(inode);
371 unlock_new_inode(inode);
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +0900372 make_bad_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900373 iput(inode);
374 alloc_nid_failed(sbi, inode->i_ino);
375 return err;
376}
377
378static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
379 struct inode *new_dir, struct dentry *new_dentry)
380{
381 struct super_block *sb = old_dir->i_sb;
382 struct f2fs_sb_info *sbi = F2FS_SB(sb);
383 struct inode *old_inode = old_dentry->d_inode;
384 struct inode *new_inode = new_dentry->d_inode;
385 struct page *old_dir_page;
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900386 struct page *old_page, *new_page;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900387 struct f2fs_dir_entry *old_dir_entry = NULL;
388 struct f2fs_dir_entry *old_entry;
389 struct f2fs_dir_entry *new_entry;
Gu Zhenge4795562013-09-27 18:08:30 +0800390 int err = -ENOENT;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900391
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900392 f2fs_balance_fs(sbi);
393
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900394 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
395 if (!old_entry)
396 goto out;
397
398 if (S_ISDIR(old_inode->i_mode)) {
399 err = -EIO;
400 old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page);
401 if (!old_dir_entry)
402 goto out_old;
403 }
404
Gu Zhenge4795562013-09-27 18:08:30 +0800405 f2fs_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900406
407 if (new_inode) {
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900408
409 err = -ENOTEMPTY;
410 if (old_dir_entry && !f2fs_empty_dir(new_inode))
411 goto out_dir;
412
413 err = -ENOENT;
414 new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name,
415 &new_page);
416 if (!new_entry)
417 goto out_dir;
418
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900419 err = acquire_orphan_inode(sbi);
420 if (err)
421 goto put_out_dir;
422
Jaegeuk Kim1cd14ca2013-07-18 18:02:31 +0900423 if (update_dent_inode(old_inode, &new_dentry->d_name)) {
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900424 release_orphan_inode(sbi);
425 goto put_out_dir;
Jaegeuk Kim1cd14ca2013-07-18 18:02:31 +0900426 }
427
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900428 f2fs_set_link(new_dir, new_entry, new_page, old_inode);
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900429 down_write(&F2FS_I(old_inode)->i_sem);
Chao Yudeead092013-12-21 18:03:28 +0800430 F2FS_I(old_inode)->i_pino = new_dir->i_ino;
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900431 up_write(&F2FS_I(old_inode)->i_sem);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900432
433 new_inode->i_ctime = CURRENT_TIME;
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900434 down_write(&F2FS_I(new_inode)->i_sem);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900435 if (old_dir_entry)
436 drop_nlink(new_inode);
437 drop_nlink(new_inode);
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900438 up_write(&F2FS_I(new_inode)->i_sem);
439
Jaegeuk Kima18ff062014-01-21 13:32:12 +0900440 mark_inode_dirty(new_inode);
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900441
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900442 if (!new_inode->i_nlink)
443 add_orphan_inode(sbi, new_inode->i_ino);
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900444 else
445 release_orphan_inode(sbi);
446
Jaegeuk Kim8cb82682013-08-26 21:25:31 +0900447 update_inode_page(old_inode);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900448 update_inode_page(new_inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900449 } else {
450 err = f2fs_add_link(new_dentry, old_inode);
451 if (err)
452 goto out_dir;
453
454 if (old_dir_entry) {
455 inc_nlink(new_dir);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900456 update_inode_page(new_dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900457 }
458 }
459
460 old_inode->i_ctime = CURRENT_TIME;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900461 mark_inode_dirty(old_inode);
462
463 f2fs_delete_entry(old_entry, old_page, NULL);
464
465 if (old_dir_entry) {
466 if (old_dir != new_dir) {
467 f2fs_set_link(old_inode, old_dir_entry,
468 old_dir_page, new_dir);
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900469 down_write(&F2FS_I(old_inode)->i_sem);
Chao Yudeead092013-12-21 18:03:28 +0800470 F2FS_I(old_inode)->i_pino = new_dir->i_ino;
Jaegeuk Kimd928bfb2014-03-20 19:10:08 +0900471 up_write(&F2FS_I(old_inode)->i_sem);
Jaegeuk Kima18ff062014-01-21 13:32:12 +0900472 update_inode_page(old_inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900473 } else {
474 kunmap(old_dir_page);
475 f2fs_put_page(old_dir_page, 0);
476 }
477 drop_nlink(old_dir);
Jaegeuk Kima18ff062014-01-21 13:32:12 +0900478 mark_inode_dirty(old_dir);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900479 update_inode_page(old_dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900480 }
481
Gu Zhenge4795562013-09-27 18:08:30 +0800482 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900483 return 0;
484
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900485put_out_dir:
486 f2fs_put_page(new_page, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900487out_dir:
488 if (old_dir_entry) {
489 kunmap(old_dir_page);
490 f2fs_put_page(old_dir_page, 0);
491 }
Gu Zhenge4795562013-09-27 18:08:30 +0800492 f2fs_unlock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900493out_old:
494 kunmap(old_page);
495 f2fs_put_page(old_page, 0);
496out:
497 return err;
498}
499
500const struct inode_operations f2fs_dir_inode_operations = {
501 .create = f2fs_create,
502 .lookup = f2fs_lookup,
503 .link = f2fs_link,
504 .unlink = f2fs_unlink,
505 .symlink = f2fs_symlink,
506 .mkdir = f2fs_mkdir,
507 .rmdir = f2fs_rmdir,
508 .mknod = f2fs_mknod,
509 .rename = f2fs_rename,
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +0900510 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900511 .setattr = f2fs_setattr,
512 .get_acl = f2fs_get_acl,
Christoph Hellwiga6dda0e2013-12-20 05:16:45 -0800513 .set_acl = f2fs_set_acl,
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900514#ifdef CONFIG_F2FS_FS_XATTR
515 .setxattr = generic_setxattr,
516 .getxattr = generic_getxattr,
517 .listxattr = f2fs_listxattr,
518 .removexattr = generic_removexattr,
519#endif
520};
521
522const struct inode_operations f2fs_symlink_inode_operations = {
523 .readlink = generic_readlink,
524 .follow_link = page_follow_link_light,
525 .put_link = page_put_link,
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +0900526 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900527 .setattr = f2fs_setattr,
528#ifdef CONFIG_F2FS_FS_XATTR
529 .setxattr = generic_setxattr,
530 .getxattr = generic_getxattr,
531 .listxattr = f2fs_listxattr,
532 .removexattr = generic_removexattr,
533#endif
534};
535
536const struct inode_operations f2fs_special_inode_operations = {
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +0900537 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900538 .setattr = f2fs_setattr,
539 .get_acl = f2fs_get_acl,
Christoph Hellwiga6dda0e2013-12-20 05:16:45 -0800540 .set_acl = f2fs_set_acl,
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900541#ifdef CONFIG_F2FS_FS_XATTR
542 .setxattr = generic_setxattr,
543 .getxattr = generic_getxattr,
544 .listxattr = f2fs_listxattr,
545 .removexattr = generic_removexattr,
546#endif
547};