blob: 7e43f6829afd6b16597a5c838c9487d242d08915 [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;
Jaegeuk Kim39936832012-11-22 16:21:29 +090030 int err, ilock;
Jaegeuk Kim57397d82012-11-02 17:11:10 +090031
32 inode = new_inode(sb);
33 if (!inode)
34 return ERR_PTR(-ENOMEM);
35
Jaegeuk Kim39936832012-11-22 16:21:29 +090036 ilock = mutex_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090037 if (!alloc_nid(sbi, &ino)) {
Jaegeuk Kim39936832012-11-22 16:21:29 +090038 mutex_unlock_op(sbi, ilock);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090039 err = -ENOSPC;
40 goto fail;
41 }
Jaegeuk Kim39936832012-11-22 16:21:29 +090042 mutex_unlock_op(sbi, ilock);
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 int ret;
87
88 if (sublen > slen)
Namjae Jeone66509f02013-04-20 01:27:21 +090089 return 0;
Jaegeuk Kim57397d82012-11-02 17:11:10 +090090
91 ret = memcmp(s + slen - sublen, sub, sublen);
92 if (ret) { /* compare upper case */
93 int i;
94 char upper_sub[8];
95 for (i = 0; i < sublen && i < sizeof(upper_sub); i++)
96 upper_sub[i] = toupper(sub[i]);
Namjae Jeone66509f02013-04-20 01:27:21 +090097 return !memcmp(s + slen - sublen, upper_sub, sublen);
Jaegeuk Kim57397d82012-11-02 17:11:10 +090098 }
99
Namjae Jeone66509f02013-04-20 01:27:21 +0900100 return !ret;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900101}
102
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +0900103/*
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900104 * Set multimedia files as cold files for hot/cold data separation
105 */
Jaegeuk Kim953a3e22013-03-21 15:21:57 +0900106static inline void set_cold_files(struct f2fs_sb_info *sbi, struct inode *inode,
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900107 const unsigned char *name)
108{
109 int i;
110 __u8 (*extlist)[8] = sbi->raw_super->extension_list;
111
112 int count = le32_to_cpu(sbi->raw_super->extension_count);
113 for (i = 0; i < count; i++) {
Namjae Jeone66509f02013-04-20 01:27:21 +0900114 if (is_multimedia_file(name, extlist[i])) {
Jaegeuk Kim354a3392013-06-14 08:52:35 +0900115 file_set_cold(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900116 break;
117 }
118 }
119}
120
121static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
122 bool excl)
123{
124 struct super_block *sb = dir->i_sb;
125 struct f2fs_sb_info *sbi = F2FS_SB(sb);
126 struct inode *inode;
127 nid_t ino = 0;
Jaegeuk Kim39936832012-11-22 16:21:29 +0900128 int err, ilock;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900129
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900130 f2fs_balance_fs(sbi);
131
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900132 inode = f2fs_new_inode(dir, mode);
133 if (IS_ERR(inode))
134 return PTR_ERR(inode);
135
136 if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
Jaegeuk Kim953a3e22013-03-21 15:21:57 +0900137 set_cold_files(sbi, inode, dentry->d_name.name);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900138
139 inode->i_op = &f2fs_file_inode_operations;
140 inode->i_fop = &f2fs_file_operations;
141 inode->i_mapping->a_ops = &f2fs_dblock_aops;
142 ino = inode->i_ino;
143
Jaegeuk Kim39936832012-11-22 16:21:29 +0900144 ilock = mutex_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900145 err = f2fs_add_link(dentry, inode);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900146 mutex_unlock_op(sbi, ilock);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900147 if (err)
148 goto out;
149
150 alloc_nid_done(sbi, ino);
151
Jaegeuk Kim0a364af2013-05-16 08:57:43 +0900152 d_instantiate(dentry, inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900153 unlock_new_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900154 return 0;
155out:
156 clear_nlink(inode);
157 unlock_new_inode(inode);
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +0900158 make_bad_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900159 iput(inode);
160 alloc_nid_failed(sbi, ino);
161 return err;
162}
163
164static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
165 struct dentry *dentry)
166{
167 struct inode *inode = old_dentry->d_inode;
168 struct super_block *sb = dir->i_sb;
169 struct f2fs_sb_info *sbi = F2FS_SB(sb);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900170 int err, ilock;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900171
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900172 f2fs_balance_fs(sbi);
173
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900174 inode->i_ctime = CURRENT_TIME;
Jaegeuk Kim6f6fd832013-05-22 12:06:26 +0900175 ihold(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900176
177 set_inode_flag(F2FS_I(inode), FI_INC_LINK);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900178 ilock = mutex_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900179 err = f2fs_add_link(dentry, inode);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900180 mutex_unlock_op(sbi, ilock);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900181 if (err)
182 goto out;
183
184 d_instantiate(dentry, inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900185 return 0;
186out:
187 clear_inode_flag(F2FS_I(inode), FI_INC_LINK);
188 iput(inode);
189 return err;
190}
191
192struct dentry *f2fs_get_parent(struct dentry *child)
193{
194 struct qstr dotdot = QSTR_INIT("..", 2);
195 unsigned long ino = f2fs_inode_by_name(child->d_inode, &dotdot);
196 if (!ino)
197 return ERR_PTR(-ENOENT);
198 return d_obtain_alias(f2fs_iget(child->d_inode->i_sb, ino));
199}
200
201static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
202 unsigned int flags)
203{
204 struct inode *inode = NULL;
205 struct f2fs_dir_entry *de;
206 struct page *page;
207
Jaegeuk Kim5a20d332013-03-03 13:58:05 +0900208 if (dentry->d_name.len > F2FS_NAME_LEN)
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900209 return ERR_PTR(-ENAMETOOLONG);
210
211 de = f2fs_find_entry(dir, &dentry->d_name, &page);
212 if (de) {
213 nid_t ino = le32_to_cpu(de->ino);
214 kunmap(page);
215 f2fs_put_page(page, 0);
216
217 inode = f2fs_iget(dir->i_sb, ino);
218 if (IS_ERR(inode))
219 return ERR_CAST(inode);
220 }
221
222 return d_splice_alias(inode, dentry);
223}
224
225static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
226{
227 struct super_block *sb = dir->i_sb;
228 struct f2fs_sb_info *sbi = F2FS_SB(sb);
229 struct inode *inode = dentry->d_inode;
230 struct f2fs_dir_entry *de;
231 struct page *page;
232 int err = -ENOENT;
Jaegeuk Kim39936832012-11-22 16:21:29 +0900233 int ilock;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900234
Namjae Jeona2a4a7e2013-04-20 01:28:40 +0900235 trace_f2fs_unlink_enter(dir, dentry);
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900236 f2fs_balance_fs(sbi);
237
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900238 de = f2fs_find_entry(dir, &dentry->d_name, &page);
239 if (!de)
240 goto fail;
241
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900242 err = acquire_orphan_inode(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900243 if (err) {
244 kunmap(page);
245 f2fs_put_page(page, 0);
246 goto fail;
247 }
248
Jaegeuk Kim39936832012-11-22 16:21:29 +0900249 ilock = mutex_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900250 f2fs_delete_entry(de, page, inode);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900251 mutex_unlock_op(sbi, ilock);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900252
253 /* In order to evict this inode, we set it dirty */
254 mark_inode_dirty(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900255fail:
Namjae Jeona2a4a7e2013-04-20 01:28:40 +0900256 trace_f2fs_unlink_exit(inode, err);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900257 return err;
258}
259
260static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
261 const char *symname)
262{
263 struct super_block *sb = dir->i_sb;
264 struct f2fs_sb_info *sbi = F2FS_SB(sb);
265 struct inode *inode;
Leon Romanovsky9836b8b2012-12-27 19:55:46 +0200266 size_t symlen = strlen(symname) + 1;
Jaegeuk Kim39936832012-11-22 16:21:29 +0900267 int err, ilock;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900268
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900269 f2fs_balance_fs(sbi);
270
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900271 inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO);
272 if (IS_ERR(inode))
273 return PTR_ERR(inode);
274
275 inode->i_op = &f2fs_symlink_inode_operations;
276 inode->i_mapping->a_ops = &f2fs_dblock_aops;
277
Jaegeuk Kim39936832012-11-22 16:21:29 +0900278 ilock = mutex_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900279 err = f2fs_add_link(dentry, inode);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900280 mutex_unlock_op(sbi, ilock);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900281 if (err)
282 goto out;
283
284 err = page_symlink(inode, symname, symlen);
285 alloc_nid_done(sbi, inode->i_ino);
286
287 d_instantiate(dentry, inode);
288 unlock_new_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900289 return err;
290out:
291 clear_nlink(inode);
292 unlock_new_inode(inode);
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +0900293 make_bad_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900294 iput(inode);
295 alloc_nid_failed(sbi, inode->i_ino);
296 return err;
297}
298
299static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
300{
301 struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
302 struct inode *inode;
Jaegeuk Kim39936832012-11-22 16:21:29 +0900303 int err, ilock;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900304
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900305 f2fs_balance_fs(sbi);
306
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900307 inode = f2fs_new_inode(dir, S_IFDIR | mode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900308 if (IS_ERR(inode))
Namjae Jeon61412b62012-12-01 10:56:25 +0900309 return PTR_ERR(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900310
311 inode->i_op = &f2fs_dir_inode_operations;
312 inode->i_fop = &f2fs_dir_operations;
313 inode->i_mapping->a_ops = &f2fs_dblock_aops;
Namjae Jeona0d42532012-12-08 14:54:18 +0900314 mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_ZERO);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900315
316 set_inode_flag(F2FS_I(inode), FI_INC_LINK);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900317 ilock = mutex_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900318 err = f2fs_add_link(dentry, inode);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900319 mutex_unlock_op(sbi, ilock);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900320 if (err)
321 goto out_fail;
322
323 alloc_nid_done(sbi, inode->i_ino);
324
325 d_instantiate(dentry, inode);
326 unlock_new_inode(inode);
327
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900328 return 0;
329
330out_fail:
331 clear_inode_flag(F2FS_I(inode), FI_INC_LINK);
332 clear_nlink(inode);
333 unlock_new_inode(inode);
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +0900334 make_bad_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900335 iput(inode);
336 alloc_nid_failed(sbi, inode->i_ino);
337 return err;
338}
339
340static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)
341{
342 struct inode *inode = dentry->d_inode;
343 if (f2fs_empty_dir(inode))
344 return f2fs_unlink(dir, dentry);
345 return -ENOTEMPTY;
346}
347
348static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
349 umode_t mode, dev_t rdev)
350{
351 struct super_block *sb = dir->i_sb;
352 struct f2fs_sb_info *sbi = F2FS_SB(sb);
353 struct inode *inode;
354 int err = 0;
Jaegeuk Kim39936832012-11-22 16:21:29 +0900355 int ilock;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900356
357 if (!new_valid_dev(rdev))
358 return -EINVAL;
359
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900360 f2fs_balance_fs(sbi);
361
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900362 inode = f2fs_new_inode(dir, mode);
363 if (IS_ERR(inode))
364 return PTR_ERR(inode);
365
366 init_special_inode(inode, inode->i_mode, rdev);
367 inode->i_op = &f2fs_special_inode_operations;
368
Jaegeuk Kim39936832012-11-22 16:21:29 +0900369 ilock = mutex_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900370 err = f2fs_add_link(dentry, inode);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900371 mutex_unlock_op(sbi, ilock);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900372 if (err)
373 goto out;
374
375 alloc_nid_done(sbi, inode->i_ino);
376 d_instantiate(dentry, inode);
377 unlock_new_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900378 return 0;
379out:
380 clear_nlink(inode);
381 unlock_new_inode(inode);
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +0900382 make_bad_inode(inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900383 iput(inode);
384 alloc_nid_failed(sbi, inode->i_ino);
385 return err;
386}
387
388static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
389 struct inode *new_dir, struct dentry *new_dentry)
390{
391 struct super_block *sb = old_dir->i_sb;
392 struct f2fs_sb_info *sbi = F2FS_SB(sb);
393 struct inode *old_inode = old_dentry->d_inode;
394 struct inode *new_inode = new_dentry->d_inode;
395 struct page *old_dir_page;
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900396 struct page *old_page, *new_page;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900397 struct f2fs_dir_entry *old_dir_entry = NULL;
398 struct f2fs_dir_entry *old_entry;
399 struct f2fs_dir_entry *new_entry;
Jaegeuk Kim39936832012-11-22 16:21:29 +0900400 int err = -ENOENT, ilock = -1;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900401
Jaegeuk Kim1efef832012-12-19 16:25:21 +0900402 f2fs_balance_fs(sbi);
403
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900404 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
405 if (!old_entry)
406 goto out;
407
408 if (S_ISDIR(old_inode->i_mode)) {
409 err = -EIO;
410 old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page);
411 if (!old_dir_entry)
412 goto out_old;
413 }
414
Jaegeuk Kim39936832012-11-22 16:21:29 +0900415 ilock = mutex_lock_op(sbi);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900416
417 if (new_inode) {
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900418
419 err = -ENOTEMPTY;
420 if (old_dir_entry && !f2fs_empty_dir(new_inode))
421 goto out_dir;
422
423 err = -ENOENT;
424 new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name,
425 &new_page);
426 if (!new_entry)
427 goto out_dir;
428
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900429 err = acquire_orphan_inode(sbi);
430 if (err)
431 goto put_out_dir;
432
Jaegeuk Kim1cd14ca2013-07-18 18:02:31 +0900433 if (update_dent_inode(old_inode, &new_dentry->d_name)) {
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900434 release_orphan_inode(sbi);
435 goto put_out_dir;
Jaegeuk Kim1cd14ca2013-07-18 18:02:31 +0900436 }
437
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900438 f2fs_set_link(new_dir, new_entry, new_page, old_inode);
439
440 new_inode->i_ctime = CURRENT_TIME;
441 if (old_dir_entry)
442 drop_nlink(new_inode);
443 drop_nlink(new_inode);
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900444
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900445 if (!new_inode->i_nlink)
446 add_orphan_inode(sbi, new_inode->i_ino);
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900447 else
448 release_orphan_inode(sbi);
449
Jaegeuk Kim8cb82682013-08-26 21:25:31 +0900450 update_inode_page(old_inode);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900451 update_inode_page(new_inode);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900452 } else {
453 err = f2fs_add_link(new_dentry, old_inode);
454 if (err)
455 goto out_dir;
456
457 if (old_dir_entry) {
458 inc_nlink(new_dir);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900459 update_inode_page(new_dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900460 }
461 }
462
463 old_inode->i_ctime = CURRENT_TIME;
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900464 mark_inode_dirty(old_inode);
465
466 f2fs_delete_entry(old_entry, old_page, NULL);
467
468 if (old_dir_entry) {
469 if (old_dir != new_dir) {
470 f2fs_set_link(old_inode, old_dir_entry,
471 old_dir_page, new_dir);
472 } else {
473 kunmap(old_dir_page);
474 f2fs_put_page(old_dir_page, 0);
475 }
476 drop_nlink(old_dir);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900477 update_inode_page(old_dir);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900478 }
479
Jaegeuk Kim39936832012-11-22 16:21:29 +0900480 mutex_unlock_op(sbi, ilock);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900481 return 0;
482
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +0900483put_out_dir:
484 f2fs_put_page(new_page, 1);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900485out_dir:
486 if (old_dir_entry) {
487 kunmap(old_dir_page);
488 f2fs_put_page(old_dir_page, 0);
489 }
Jaegeuk Kim39936832012-11-22 16:21:29 +0900490 mutex_unlock_op(sbi, ilock);
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900491out_old:
492 kunmap(old_page);
493 f2fs_put_page(old_page, 0);
494out:
495 return err;
496}
497
498const struct inode_operations f2fs_dir_inode_operations = {
499 .create = f2fs_create,
500 .lookup = f2fs_lookup,
501 .link = f2fs_link,
502 .unlink = f2fs_unlink,
503 .symlink = f2fs_symlink,
504 .mkdir = f2fs_mkdir,
505 .rmdir = f2fs_rmdir,
506 .mknod = f2fs_mknod,
507 .rename = f2fs_rename,
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +0900508 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900509 .setattr = f2fs_setattr,
510 .get_acl = f2fs_get_acl,
511#ifdef CONFIG_F2FS_FS_XATTR
512 .setxattr = generic_setxattr,
513 .getxattr = generic_getxattr,
514 .listxattr = f2fs_listxattr,
515 .removexattr = generic_removexattr,
516#endif
517};
518
519const struct inode_operations f2fs_symlink_inode_operations = {
520 .readlink = generic_readlink,
521 .follow_link = page_follow_link_light,
522 .put_link = page_put_link,
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +0900523 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900524 .setattr = f2fs_setattr,
525#ifdef CONFIG_F2FS_FS_XATTR
526 .setxattr = generic_setxattr,
527 .getxattr = generic_getxattr,
528 .listxattr = f2fs_listxattr,
529 .removexattr = generic_removexattr,
530#endif
531};
532
533const struct inode_operations f2fs_special_inode_operations = {
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +0900534 .getattr = f2fs_getattr,
Jaegeuk Kim57397d82012-11-02 17:11:10 +0900535 .setattr = f2fs_setattr,
536 .get_acl = f2fs_get_acl,
537#ifdef CONFIG_F2FS_FS_XATTR
538 .setxattr = generic_setxattr,
539 .getxattr = generic_getxattr,
540 .listxattr = f2fs_listxattr,
541 .removexattr = generic_removexattr,
542#endif
543};