namei.c 28.2 KB
Newer Older
J
Jaegeuk Kim 已提交
1
/*
2 3 4 5 6 7 8 9 10 11 12 13 14 15
 * fs/f2fs/namei.c
 *
 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
 *             http://www.samsung.com/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#include <linux/fs.h>
#include <linux/f2fs_fs.h>
#include <linux/pagemap.h>
#include <linux/sched.h>
#include <linux/ctype.h>
C
Chao Yu 已提交
16
#include <linux/dcache.h>
17
#include <linux/namei.h>
C
Chao Yu 已提交
18
#include <linux/quotaops.h>
19 20

#include "f2fs.h"
21
#include "node.h"
22 23
#include "xattr.h"
#include "acl.h"
24
#include <trace/events/f2fs.h>
25 26 27

static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
{
28
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
29 30 31
	nid_t ino;
	struct inode *inode;
	bool nid_free = false;
C
Chao Yu 已提交
32
	int xattr_size = 0;
33
	int err;
34

35
	inode = new_inode(dir->i_sb);
36 37 38
	if (!inode)
		return ERR_PTR(-ENOMEM);

39
	f2fs_lock_op(sbi);
40
	if (!alloc_nid(sbi, &ino)) {
41
		f2fs_unlock_op(sbi);
42 43 44
		err = -ENOSPC;
		goto fail;
	}
45
	f2fs_unlock_op(sbi);
46

C
Chao Yu 已提交
47 48
	nid_free = true;

49
	inode_init_owner(inode, dir, mode);
50 51 52

	inode->i_ino = ino;
	inode->i_blocks = 0;
C
Chao Yu 已提交
53 54
	inode->i_mtime = inode->i_atime = inode->i_ctime =
			F2FS_I(inode)->i_crtime = current_time(inode);
55 56 57 58 59
	inode->i_generation = sbi->s_next_generation++;

	err = insert_inode_locked(inode);
	if (err) {
		err = -EINVAL;
60
		goto fail;
61
	}
C
Chao Yu 已提交
62

C
Chao Yu 已提交
63 64 65 66 67 68 69
	if (f2fs_sb_has_project_quota(sbi->sb) &&
		(F2FS_I(dir)->i_flags & FS_PROJINHERIT_FL))
		F2FS_I(inode)->i_projid = F2FS_I(dir)->i_projid;
	else
		F2FS_I(inode)->i_projid = make_kprojid(&init_user_ns,
							F2FS_DEF_PROJID);

C
Chao Yu 已提交
70 71 72 73 74 75 76 77
	err = dquot_initialize(inode);
	if (err)
		goto fail_drop;

	err = dquot_alloc_inode(inode);
	if (err)
		goto fail_drop;

78 79
	set_inode_flag(inode, FI_NEW_INODE);

80 81 82 83
	/* If the directory encrypted, then we should encrypt the inode. */
	if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode))
		f2fs_set_encrypted_inode(inode);

84 85 86 87 88
	if (f2fs_sb_has_extra_attr(sbi->sb)) {
		set_inode_flag(inode, FI_EXTRA_ATTR);
		F2FS_I(inode)->i_extra_isize = F2FS_TOTAL_EXTRA_ATTR_SIZE;
	}

89 90
	if (test_opt(sbi, INLINE_XATTR))
		set_inode_flag(inode, FI_INLINE_XATTR);
C
Chao Yu 已提交
91

92
	if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode))
93
		set_inode_flag(inode, FI_INLINE_DATA);
94
	if (f2fs_may_inline_dentry(inode))
95
		set_inode_flag(inode, FI_INLINE_DENTRY);
C
Chao Yu 已提交
96

C
Chao Yu 已提交
97 98 99
	if (f2fs_sb_has_flexible_inline_xattr(sbi->sb)) {
		f2fs_bug_on(sbi, !f2fs_has_extra_attr(inode));
		if (f2fs_has_inline_xattr(inode))
100
			xattr_size = F2FS_OPTION(sbi).inline_xattr_size;
C
Chao Yu 已提交
101 102 103 104 105 106 107
		/* Otherwise, will be 0 */
	} else if (f2fs_has_inline_xattr(inode) ||
				f2fs_has_inline_dentry(inode)) {
		xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
	}
	F2FS_I(inode)->i_inline_xattr_size = xattr_size;

J
Jaegeuk Kim 已提交
108 109
	f2fs_init_extent_tree(inode, NULL);

C
Chao Yu 已提交
110
	stat_inc_inline_xattr(inode);
111 112 113
	stat_inc_inline_inode(inode);
	stat_inc_inline_dir(inode);

C
Chao Yu 已提交
114 115 116
	F2FS_I(inode)->i_flags =
		f2fs_mask_flags(mode, F2FS_I(dir)->i_flags & F2FS_FL_INHERITED);

C
Chao Yu 已提交
117 118 119
	if (S_ISDIR(inode->i_mode))
		F2FS_I(inode)->i_flags |= FS_INDEX_FL;

C
Chao Yu 已提交
120 121 122
	if (F2FS_I(inode)->i_flags & FS_PROJINHERIT_FL)
		set_inode_flag(inode, FI_PROJ_INHERIT);

123
	trace_f2fs_new_inode(inode, 0);
124 125 126
	return inode;

fail:
127
	trace_f2fs_new_inode(inode, err);
128
	make_bad_inode(inode);
129
	if (nid_free)
130
		set_inode_flag(inode, FI_FREE_NID);
131
	iput(inode);
132
	return ERR_PTR(err);
C
Chao Yu 已提交
133 134 135 136 137 138 139 140 141 142
fail_drop:
	trace_f2fs_new_inode(inode, err);
	dquot_drop(inode);
	inode->i_flags |= S_NOQUOTA;
	if (nid_free)
		set_inode_flag(inode, FI_FREE_NID);
	clear_nlink(inode);
	unlock_new_inode(inode);
	iput(inode);
	return ERR_PTR(err);
143 144
}

C
Chao Yu 已提交
145
static int is_extension_exist(const unsigned char *s, const char *sub)
146
{
147 148
	size_t slen = strlen(s);
	size_t sublen = strlen(sub);
149
	int i;
150

C
Chao Yu 已提交
151 152
	/*
	 * filename format of multimedia file should be defined as:
153
	 * "filename + '.' + extension + (optional: '.' + temp extension)".
C
Chao Yu 已提交
154 155 156 157
	 */
	if (slen < sublen + 2)
		return 0;

158 159 160 161 162 163
	for (i = 1; i < slen - sublen; i++) {
		if (s[i] != '.')
			continue;
		if (!strncasecmp(s + i + 1, sub, sublen))
			return 1;
	}
164

165
	return 0;
166 167
}

J
Jaegeuk Kim 已提交
168
/*
169 170
 * Set multimedia files as cold files for hot/cold data separation
 */
C
Chao Yu 已提交
171
static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode *inode,
172 173
		const unsigned char *name)
{
174
	__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
C
Chao Yu 已提交
175
	int i, cold_count, hot_count;
176 177 178

	down_read(&sbi->sb_lock);

C
Chao Yu 已提交
179 180
	cold_count = le32_to_cpu(sbi->raw_super->extension_count);
	hot_count = sbi->raw_super->hot_ext_count;
181

C
Chao Yu 已提交
182 183 184 185
	for (i = 0; i < cold_count + hot_count; i++) {
		if (!is_extension_exist(name, extlist[i]))
			continue;
		if (i < cold_count)
186
			file_set_cold(inode);
C
Chao Yu 已提交
187 188 189
		else
			file_set_hot(inode);
		break;
190
	}
191 192 193 194

	up_read(&sbi->sb_lock);
}

C
Chao Yu 已提交
195 196
int update_extension_list(struct f2fs_sb_info *sbi, const char *name,
							bool hot, bool set)
197 198
{
	__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
C
Chao Yu 已提交
199 200 201 202
	int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
	int hot_count = sbi->raw_super->hot_ext_count;
	int total_count = cold_count + hot_count;
	int start, count;
203 204
	int i;

C
Chao Yu 已提交
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
	if (set) {
		if (total_count == F2FS_MAX_EXTENSION)
			return -EINVAL;
	} else {
		if (!hot && !cold_count)
			return -EINVAL;
		if (hot && !hot_count)
			return -EINVAL;
	}

	if (hot) {
		start = cold_count;
		count = total_count;
	} else {
		start = 0;
		count = cold_count;
	}

	for (i = start; i < count; i++) {
224 225 226 227 228 229 230
		if (strcmp(name, extlist[i]))
			continue;

		if (set)
			return -EINVAL;

		memcpy(extlist[i], extlist[i + 1],
C
Chao Yu 已提交
231 232 233 234 235 236 237
				F2FS_EXTENSION_LEN * (total_count - i - 1));
		memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN);
		if (hot)
			sbi->raw_super->hot_ext_count = hot_count - 1;
		else
			sbi->raw_super->extension_count =
						cpu_to_le32(cold_count - 1);
238 239 240 241 242 243
		return 0;
	}

	if (!set)
		return -EINVAL;

C
Chao Yu 已提交
244 245 246 247 248 249 250 251 252 253 254 255 256 257
	if (hot) {
		strncpy(extlist[count], name, strlen(name));
		sbi->raw_super->hot_ext_count = hot_count + 1;
	} else {
		char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN];

		memcpy(buf, &extlist[cold_count],
				F2FS_EXTENSION_LEN * hot_count);
		memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN);
		strncpy(extlist[cold_count], name, strlen(name));
		memcpy(&extlist[cold_count + 1], buf,
				F2FS_EXTENSION_LEN * hot_count);
		sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1);
	}
258
	return 0;
259 260 261 262 263
}

static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
						bool excl)
{
264
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
265 266
	struct inode *inode;
	nid_t ino = 0;
267
	int err;
268

269 270 271
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

C
Chao Yu 已提交
272 273 274 275
	err = dquot_initialize(dir);
	if (err)
		return err;

276 277 278 279 280
	inode = f2fs_new_inode(dir, mode);
	if (IS_ERR(inode))
		return PTR_ERR(inode);

	if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
C
Chao Yu 已提交
281
		set_file_temperature(sbi, inode, dentry->d_name.name);
282 283 284 285 286 287

	inode->i_op = &f2fs_file_inode_operations;
	inode->i_fop = &f2fs_file_operations;
	inode->i_mapping->a_ops = &f2fs_dblock_aops;
	ino = inode->i_ino;

288
	f2fs_lock_op(sbi);
289 290 291
	err = f2fs_add_link(dentry, inode);
	if (err)
		goto out;
292
	f2fs_unlock_op(sbi);
293 294 295

	alloc_nid_done(sbi, ino);

296
	d_instantiate(dentry, inode);
297
	unlock_new_inode(inode);
J
Jaegeuk Kim 已提交
298 299 300

	if (IS_DIRSYNC(dir))
		f2fs_sync_fs(sbi->sb, 1);
301 302

	f2fs_balance_fs(sbi, true);
303 304
	return 0;
out:
305
	handle_failed_inode(inode);
306 307 308 309 310 311
	return err;
}

static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
		struct dentry *dentry)
{
312
	struct inode *inode = d_inode(old_dentry);
313
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
314
	int err;
315

316 317 318
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

319 320 321
	err = fscrypt_prepare_link(old_dentry, dir, dentry);
	if (err)
		return err;
322

C
Chao Yu 已提交
323 324 325 326 327
	if (is_inode_flag_set(dir, FI_PROJ_INHERIT) &&
			(!projid_eq(F2FS_I(dir)->i_projid,
			F2FS_I(old_dentry->d_inode)->i_projid)))
		return -EXDEV;

C
Chao Yu 已提交
328 329 330 331
	err = dquot_initialize(dir);
	if (err)
		return err;

J
Jaegeuk Kim 已提交
332
	f2fs_balance_fs(sbi, true);
333

334
	inode->i_ctime = current_time(inode);
J
Jaegeuk Kim 已提交
335
	ihold(inode);
336

337
	set_inode_flag(inode, FI_INC_LINK);
338
	f2fs_lock_op(sbi);
339 340 341
	err = f2fs_add_link(dentry, inode);
	if (err)
		goto out;
342
	f2fs_unlock_op(sbi);
343 344

	d_instantiate(dentry, inode);
J
Jaegeuk Kim 已提交
345 346 347

	if (IS_DIRSYNC(dir))
		f2fs_sync_fs(sbi->sb, 1);
348 349
	return 0;
out:
350
	clear_inode_flag(inode, FI_INC_LINK);
351
	iput(inode);
352
	f2fs_unlock_op(sbi);
353 354 355 356 357 358
	return err;
}

struct dentry *f2fs_get_parent(struct dentry *child)
{
	struct qstr dotdot = QSTR_INIT("..", 2);
359 360 361 362 363
	struct page *page;
	unsigned long ino = f2fs_inode_by_name(d_inode(child), &dotdot, &page);
	if (!ino) {
		if (IS_ERR(page))
			return ERR_CAST(page);
364
		return ERR_PTR(-ENOENT);
365
	}
366
	return d_obtain_alias(f2fs_iget(child->d_sb, ino));
367 368
}

369 370 371 372 373 374 375 376 377
static int __recover_dot_dentries(struct inode *dir, nid_t pino)
{
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
	struct qstr dot = QSTR_INIT(".", 1);
	struct qstr dotdot = QSTR_INIT("..", 2);
	struct f2fs_dir_entry *de;
	struct page *page;
	int err = 0;

378 379 380 381 382 383 384
	if (f2fs_readonly(sbi->sb)) {
		f2fs_msg(sbi->sb, KERN_INFO,
			"skip recovering inline_dots inode (ino:%lu, pino:%u) "
			"in readonly mountpoint", dir->i_ino, pino);
		return 0;
	}

385 386 387 388
	err = dquot_initialize(dir);
	if (err)
		return err;

J
Jaegeuk Kim 已提交
389
	f2fs_balance_fs(sbi, true);
390

391 392 393 394 395
	f2fs_lock_op(sbi);

	de = f2fs_find_entry(dir, &dot, &page);
	if (de) {
		f2fs_put_page(page, 0);
396 397 398
	} else if (IS_ERR(page)) {
		err = PTR_ERR(page);
		goto out;
399 400 401 402 403 404 405
	} else {
		err = __f2fs_add_link(dir, &dot, NULL, dir->i_ino, S_IFDIR);
		if (err)
			goto out;
	}

	de = f2fs_find_entry(dir, &dotdot, &page);
406
	if (de)
407
		f2fs_put_page(page, 0);
408
	else if (IS_ERR(page))
409
		err = PTR_ERR(page);
410
	else
411 412
		err = __f2fs_add_link(dir, &dotdot, NULL, pino, S_IFDIR);
out:
413
	if (!err)
414
		clear_inode_flag(dir, FI_INLINE_DOTS);
415 416 417 418 419

	f2fs_unlock_op(sbi);
	return err;
}

420 421 422 423 424 425
static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
		unsigned int flags)
{
	struct inode *inode = NULL;
	struct f2fs_dir_entry *de;
	struct page *page;
C
Chao Yu 已提交
426 427
	struct dentry *new;
	nid_t ino = -1;
428
	int err = 0;
429
	unsigned int root_ino = F2FS_ROOT_INO(F2FS_I_SB(dir));
430

C
Chao Yu 已提交
431 432
	trace_f2fs_lookup_start(dir, dentry, flags);

433 434 435
	err = fscrypt_prepare_lookup(dir, dentry, flags);
	if (err)
		goto out;
436

C
Chao Yu 已提交
437 438 439 440
	if (dentry->d_name.len > F2FS_NAME_LEN) {
		err = -ENAMETOOLONG;
		goto out;
	}
441 442

	de = f2fs_find_entry(dir, &dentry->d_name, &page);
J
Jaegeuk Kim 已提交
443
	if (!de) {
C
Chao Yu 已提交
444 445 446 447 448
		if (IS_ERR(page)) {
			err = PTR_ERR(page);
			goto out;
		}
		goto out_splice;
J
Jaegeuk Kim 已提交
449
	}
450

J
Jaegeuk Kim 已提交
451 452
	ino = le32_to_cpu(de->ino);
	f2fs_put_page(page, 0);
453

J
Jaegeuk Kim 已提交
454
	inode = f2fs_iget(dir->i_sb, ino);
C
Chao Yu 已提交
455 456 457 458
	if (IS_ERR(inode)) {
		err = PTR_ERR(inode);
		goto out;
	}
459

460 461 462
	if ((dir->i_ino == root_ino) && f2fs_has_inline_dots(dir)) {
		err = __recover_dot_dentries(dir, root_ino);
		if (err)
C
Chao Yu 已提交
463
			goto out_iput;
464 465
	}

466
	if (f2fs_has_inline_dots(inode)) {
J
Jaegeuk Kim 已提交
467
		err = __recover_dot_dentries(inode, dir->i_ino);
468
		if (err)
C
Chao Yu 已提交
469
			goto out_iput;
470
	}
D
Dan Carpenter 已提交
471 472 473
	if (f2fs_encrypted_inode(dir) &&
	    (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
	    !fscrypt_has_permitted_context(dir, inode)) {
474 475 476 477
		f2fs_msg(inode->i_sb, KERN_WARNING,
			 "Inconsistent encryption contexts: %lu/%lu",
			 dir->i_ino, inode->i_ino);
		err = -EPERM;
C
Chao Yu 已提交
478
		goto out_iput;
479
	}
C
Chao Yu 已提交
480 481 482 483 484 485 486
out_splice:
	new = d_splice_alias(inode, dentry);
	if (IS_ERR(new))
		err = PTR_ERR(new);
	trace_f2fs_lookup_end(dir, dentry, ino, err);
	return new;
out_iput:
487
	iput(inode);
C
Chao Yu 已提交
488 489
out:
	trace_f2fs_lookup_end(dir, dentry, ino, err);
490
	return ERR_PTR(err);
491 492 493 494
}

static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
{
495
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
496
	struct inode *inode = d_inode(dentry);
497 498 499 500
	struct f2fs_dir_entry *de;
	struct page *page;
	int err = -ENOENT;

501
	trace_f2fs_unlink_enter(dir, dentry);
502

503 504 505
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

C
Chao Yu 已提交
506
	err = dquot_initialize(dir);
J
Jaegeuk Kim 已提交
507 508 509
	if (err)
		return err;
	err = dquot_initialize(inode);
C
Chao Yu 已提交
510 511 512
	if (err)
		return err;

513
	de = f2fs_find_entry(dir, &dentry->d_name, &page);
514 515 516
	if (!de) {
		if (IS_ERR(page))
			err = PTR_ERR(page);
517
		goto fail;
518
	}
519

J
Jaegeuk Kim 已提交
520
	f2fs_balance_fs(sbi, true);
521

522
	f2fs_lock_op(sbi);
J
Jaegeuk Kim 已提交
523
	err = acquire_orphan_inode(sbi);
524
	if (err) {
525
		f2fs_unlock_op(sbi);
526 527 528
		f2fs_put_page(page, 0);
		goto fail;
	}
529
	f2fs_delete_entry(de, page, dir, inode);
530
	f2fs_unlock_op(sbi);
531

J
Jaegeuk Kim 已提交
532 533
	if (IS_DIRSYNC(dir))
		f2fs_sync_fs(sbi->sb, 1);
534
fail:
535
	trace_f2fs_unlink_exit(inode, err);
536 537 538
	return err;
}

539
static const char *f2fs_get_link(struct dentry *dentry,
540 541
				 struct inode *inode,
				 struct delayed_call *done)
542
{
543
	const char *link = page_get_link(dentry, inode, done);
544 545
	if (!IS_ERR(link) && !*link) {
		/* this is broken symlink case */
546 547
		do_delayed_call(done);
		clear_delayed_call(done);
548
		link = ERR_PTR(-ENOENT);
549
	}
550
	return link;
551 552
}

553 554 555
static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
					const char *symname)
{
556
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
557
	struct inode *inode;
558
	size_t len = strlen(symname);
559
	struct fscrypt_str disk_link;
560
	int err;
561

562 563 564
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

565 566 567 568
	err = fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize,
				      &disk_link);
	if (err)
		return err;
569

C
Chao Yu 已提交
570 571 572 573
	err = dquot_initialize(dir);
	if (err)
		return err;

574 575 576 577
	inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO);
	if (IS_ERR(inode))
		return PTR_ERR(inode);

578
	if (IS_ENCRYPTED(inode))
579 580 581
		inode->i_op = &f2fs_encrypted_symlink_inode_operations;
	else
		inode->i_op = &f2fs_symlink_inode_operations;
582
	inode_nohighmem(inode);
583 584
	inode->i_mapping->a_ops = &f2fs_dblock_aops;

585
	f2fs_lock_op(sbi);
586 587
	err = f2fs_add_link(dentry, inode);
	if (err)
588
		goto out_handle_failed_inode;
589
	f2fs_unlock_op(sbi);
590 591
	alloc_nid_done(sbi, inode->i_ino);

592 593 594
	err = fscrypt_encrypt_symlink(inode, symname, len, &disk_link);
	if (err)
		goto err_out;
595

596
	err = page_symlink(inode, disk_link.name, disk_link.len);
597 598

err_out:
599 600
	d_instantiate(dentry, inode);
	unlock_new_inode(inode);
J
Jaegeuk Kim 已提交
601

602 603 604 605 606 607 608 609 610
	/*
	 * Let's flush symlink data in order to avoid broken symlink as much as
	 * possible. Nevertheless, fsyncing is the best way, but there is no
	 * way to get a file descriptor in order to flush that.
	 *
	 * Note that, it needs to do dir->fsync to make this recoverable.
	 * If the symlink path is stored into inline_data, there is no
	 * performance regression.
	 */
C
Chao Yu 已提交
611
	if (!err) {
612 613
		filemap_write_and_wait_range(inode->i_mapping, 0,
							disk_link.len - 1);
614

C
Chao Yu 已提交
615 616 617 618 619
		if (IS_DIRSYNC(dir))
			f2fs_sync_fs(sbi->sb, 1);
	} else {
		f2fs_unlink(dir, dentry);
	}
620

621
	f2fs_balance_fs(sbi, true);
622 623 624
	goto out_free_encrypted_link;

out_handle_failed_inode:
625
	handle_failed_inode(inode);
626 627 628
out_free_encrypted_link:
	if (disk_link.name != (unsigned char *)symname)
		kfree(disk_link.name);
629 630 631 632 633
	return err;
}

static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
{
634
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
635
	struct inode *inode;
636
	int err;
637

638 639 640
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

C
Chao Yu 已提交
641 642 643 644
	err = dquot_initialize(dir);
	if (err)
		return err;

645 646
	inode = f2fs_new_inode(dir, S_IFDIR | mode);
	if (IS_ERR(inode))
647
		return PTR_ERR(inode);
648 649 650 651

	inode->i_op = &f2fs_dir_inode_operations;
	inode->i_fop = &f2fs_dir_operations;
	inode->i_mapping->a_ops = &f2fs_dblock_aops;
652
	inode_nohighmem(inode);
653

654
	set_inode_flag(inode, FI_INC_LINK);
655
	f2fs_lock_op(sbi);
656 657 658
	err = f2fs_add_link(dentry, inode);
	if (err)
		goto out_fail;
659
	f2fs_unlock_op(sbi);
660 661 662 663 664 665

	alloc_nid_done(sbi, inode->i_ino);

	d_instantiate(dentry, inode);
	unlock_new_inode(inode);

J
Jaegeuk Kim 已提交
666 667
	if (IS_DIRSYNC(dir))
		f2fs_sync_fs(sbi->sb, 1);
668 669

	f2fs_balance_fs(sbi, true);
670 671 672
	return 0;

out_fail:
673
	clear_inode_flag(inode, FI_INC_LINK);
674
	handle_failed_inode(inode);
675 676 677 678 679
	return err;
}

static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)
{
680
	struct inode *inode = d_inode(dentry);
681 682 683 684 685 686 687 688
	if (f2fs_empty_dir(inode))
		return f2fs_unlink(dir, dentry);
	return -ENOTEMPTY;
}

static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
				umode_t mode, dev_t rdev)
{
689
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
690 691 692
	struct inode *inode;
	int err = 0;

693 694 695
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

C
Chao Yu 已提交
696 697 698 699
	err = dquot_initialize(dir);
	if (err)
		return err;

700 701 702 703 704 705 706
	inode = f2fs_new_inode(dir, mode);
	if (IS_ERR(inode))
		return PTR_ERR(inode);

	init_special_inode(inode, inode->i_mode, rdev);
	inode->i_op = &f2fs_special_inode_operations;

707
	f2fs_lock_op(sbi);
708 709 710
	err = f2fs_add_link(dentry, inode);
	if (err)
		goto out;
711
	f2fs_unlock_op(sbi);
712 713

	alloc_nid_done(sbi, inode->i_ino);
J
Jaegeuk Kim 已提交
714

715 716
	d_instantiate(dentry, inode);
	unlock_new_inode(inode);
J
Jaegeuk Kim 已提交
717 718 719

	if (IS_DIRSYNC(dir))
		f2fs_sync_fs(sbi->sb, 1);
720 721

	f2fs_balance_fs(sbi, true);
722 723
	return 0;
out:
724
	handle_failed_inode(inode);
725 726 727
	return err;
}

C
Chao Yu 已提交
728 729 730 731 732 733 734
static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,
					umode_t mode, struct inode **whiteout)
{
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
	struct inode *inode;
	int err;

C
Chao Yu 已提交
735 736 737 738
	err = dquot_initialize(dir);
	if (err)
		return err;

C
Chao Yu 已提交
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
	inode = f2fs_new_inode(dir, mode);
	if (IS_ERR(inode))
		return PTR_ERR(inode);

	if (whiteout) {
		init_special_inode(inode, inode->i_mode, WHITEOUT_DEV);
		inode->i_op = &f2fs_special_inode_operations;
	} else {
		inode->i_op = &f2fs_file_inode_operations;
		inode->i_fop = &f2fs_file_operations;
		inode->i_mapping->a_ops = &f2fs_dblock_aops;
	}

	f2fs_lock_op(sbi);
	err = acquire_orphan_inode(sbi);
	if (err)
		goto out;

	err = f2fs_do_tmpfile(inode, dir);
	if (err)
		goto release_out;

	/*
	 * add this non-linked tmpfile to orphan list, in this way we could
	 * remove all unused data of tmpfile after abnormal power-off.
	 */
765
	add_orphan_inode(inode);
C
Chao Yu 已提交
766 767 768
	alloc_nid_done(sbi, inode->i_ino);

	if (whiteout) {
769
		f2fs_i_links_write(inode, false);
C
Chao Yu 已提交
770 771 772 773
		*whiteout = inode;
	} else {
		d_tmpfile(dentry, inode);
	}
774 775
	/* link_count was changed by d_tmpfile as well. */
	f2fs_unlock_op(sbi);
C
Chao Yu 已提交
776
	unlock_new_inode(inode);
777 778

	f2fs_balance_fs(sbi, true);
C
Chao Yu 已提交
779 780 781 782 783 784 785 786 787 788 789
	return 0;

release_out:
	release_orphan_inode(sbi);
out:
	handle_failed_inode(inode);
	return err;
}

static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
{
790 791 792
	if (unlikely(f2fs_cp_error(F2FS_I_SB(dir))))
		return -EIO;

793
	if (f2fs_encrypted_inode(dir)) {
794
		int err = fscrypt_get_encryption_info(dir);
795 796 797 798
		if (err)
			return err;
	}

C
Chao Yu 已提交
799 800 801 802 803
	return __f2fs_tmpfile(dir, dentry, mode, NULL);
}

static int f2fs_create_whiteout(struct inode *dir, struct inode **whiteout)
{
804 805 806
	if (unlikely(f2fs_cp_error(F2FS_I_SB(dir))))
		return -EIO;

C
Chao Yu 已提交
807 808 809
	return __f2fs_tmpfile(dir, NULL, S_IFCHR | WHITEOUT_MODE, whiteout);
}

810
static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
C
Chao Yu 已提交
811 812
			struct inode *new_dir, struct dentry *new_dentry,
			unsigned int flags)
813
{
814
	struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
815 816
	struct inode *old_inode = d_inode(old_dentry);
	struct inode *new_inode = d_inode(new_dentry);
C
Chao Yu 已提交
817
	struct inode *whiteout = NULL;
818
	struct page *old_dir_page;
C
Chao Yu 已提交
819
	struct page *old_page, *new_page = NULL;
820 821 822
	struct f2fs_dir_entry *old_dir_entry = NULL;
	struct f2fs_dir_entry *old_entry;
	struct f2fs_dir_entry *new_entry;
823
	bool is_old_inline = f2fs_has_inline_dentry(old_dir);
824
	int err = -ENOENT;
825

826 827 828
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

C
Chao Yu 已提交
829 830 831 832 833
	if (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
			(!projid_eq(F2FS_I(new_dir)->i_projid,
			F2FS_I(old_dentry->d_inode)->i_projid)))
		return -EXDEV;

C
Chao Yu 已提交
834 835 836 837 838 839 840 841
	err = dquot_initialize(old_dir);
	if (err)
		goto out;

	err = dquot_initialize(new_dir);
	if (err)
		goto out;

J
Jaegeuk Kim 已提交
842 843 844 845 846 847
	if (new_inode) {
		err = dquot_initialize(new_inode);
		if (err)
			goto out;
	}

848
	old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
849 850 851
	if (!old_entry) {
		if (IS_ERR(old_page))
			err = PTR_ERR(old_page);
852
		goto out;
853
	}
854 855 856

	if (S_ISDIR(old_inode->i_mode)) {
		old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page);
857
		if (!old_dir_entry) {
858 859
			if (IS_ERR(old_dir_page))
				err = PTR_ERR(old_dir_page);
860
			goto out_old;
861
		}
862 863
	}

C
Chao Yu 已提交
864 865 866 867 868 869
	if (flags & RENAME_WHITEOUT) {
		err = f2fs_create_whiteout(old_dir, &whiteout);
		if (err)
			goto out_dir;
	}

870 871 872 873
	if (new_inode) {

		err = -ENOTEMPTY;
		if (old_dir_entry && !f2fs_empty_dir(new_inode))
C
Chao Yu 已提交
874
			goto out_whiteout;
875 876 877 878

		err = -ENOENT;
		new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name,
						&new_page);
879 880 881
		if (!new_entry) {
			if (IS_ERR(new_page))
				err = PTR_ERR(new_page);
C
Chao Yu 已提交
882
			goto out_whiteout;
883
		}
884

J
Jaegeuk Kim 已提交
885
		f2fs_balance_fs(sbi, true);
886

887 888
		f2fs_lock_op(sbi);

J
Jaegeuk Kim 已提交
889 890 891 892
		err = acquire_orphan_inode(sbi);
		if (err)
			goto put_out_dir;

893 894
		f2fs_set_link(new_dir, new_entry, new_page, old_inode);

895
		new_inode->i_ctime = current_time(new_inode);
896
		down_write(&F2FS_I(new_inode)->i_sem);
897
		if (old_dir_entry)
898 899
			f2fs_i_links_write(new_inode, false);
		f2fs_i_links_write(new_inode, false);
900 901
		up_write(&F2FS_I(new_inode)->i_sem);

902
		if (!new_inode->i_nlink)
903
			add_orphan_inode(new_inode);
J
Jaegeuk Kim 已提交
904 905
		else
			release_orphan_inode(sbi);
906
	} else {
J
Jaegeuk Kim 已提交
907
		f2fs_balance_fs(sbi, true);
908

909 910
		f2fs_lock_op(sbi);

911
		err = f2fs_add_link(new_dentry, old_inode);
912 913
		if (err) {
			f2fs_unlock_op(sbi);
C
Chao Yu 已提交
914
			goto out_whiteout;
915
		}
916

917
		if (old_dir_entry)
918
			f2fs_i_links_write(new_dir, true);
919 920 921 922 923 924 925 926 927 928 929 930 931 932 933

		/*
		 * old entry and new entry can locate in the same inline
		 * dentry in inode, when attaching new entry in inline dentry,
		 * it could force inline dentry conversion, after that,
		 * old_entry and old_page will point to wrong address, in
		 * order to avoid this, let's do the check and update here.
		 */
		if (is_old_inline && !f2fs_has_inline_dentry(old_dir)) {
			f2fs_put_page(old_page, 0);
			old_page = NULL;

			old_entry = f2fs_find_entry(old_dir,
						&old_dentry->d_name, &old_page);
			if (!old_entry) {
934 935 936
				err = -ENOENT;
				if (IS_ERR(old_page))
					err = PTR_ERR(old_page);
937 938 939 940
				f2fs_unlock_op(sbi);
				goto out_whiteout;
			}
		}
941 942
	}

943
	down_write(&F2FS_I(old_inode)->i_sem);
944 945 946 947
	if (!old_dir_entry || whiteout)
		file_lost_pino(old_inode);
	else
		F2FS_I(old_inode)->i_pino = new_dir->i_ino;
948 949
	up_write(&F2FS_I(old_inode)->i_sem);

950
	old_inode->i_ctime = current_time(old_inode);
951
	f2fs_mark_inode_dirty_sync(old_inode, false);
952

953
	f2fs_delete_entry(old_entry, old_page, old_dir, NULL);
954

C
Chao Yu 已提交
955 956
	if (whiteout) {
		whiteout->i_state |= I_LINKABLE;
957
		set_inode_flag(whiteout, FI_INC_LINK);
C
Chao Yu 已提交
958 959 960 961 962 963 964
		err = f2fs_add_link(old_dentry, whiteout);
		if (err)
			goto put_out_dir;
		whiteout->i_state &= ~I_LINKABLE;
		iput(whiteout);
	}

965
	if (old_dir_entry) {
966
		if (old_dir != new_dir && !whiteout)
967 968
			f2fs_set_link(old_inode, old_dir_entry,
						old_dir_page, new_dir);
969
		else
970
			f2fs_put_page(old_dir_page, 0);
971
		f2fs_i_links_write(old_dir, false);
972
	}
973
	if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT)
974
		add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO);
975

976
	f2fs_unlock_op(sbi);
J
Jaegeuk Kim 已提交
977 978 979

	if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
		f2fs_sync_fs(sbi->sb, 1);
980 981
	return 0;

J
Jaegeuk Kim 已提交
982
put_out_dir:
983
	f2fs_unlock_op(sbi);
984
	if (new_page)
C
Chao Yu 已提交
985 986 987 988
		f2fs_put_page(new_page, 0);
out_whiteout:
	if (whiteout)
		iput(whiteout);
989
out_dir:
990
	if (old_dir_entry)
991 992 993 994 995 996 997
		f2fs_put_page(old_dir_page, 0);
out_old:
	f2fs_put_page(old_page, 0);
out:
	return err;
}

C
Chao Yu 已提交
998 999 1000
static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
			     struct inode *new_dir, struct dentry *new_dentry)
{
1001
	struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
1002 1003
	struct inode *old_inode = d_inode(old_dentry);
	struct inode *new_inode = d_inode(new_dentry);
C
Chao Yu 已提交
1004 1005 1006 1007 1008 1009
	struct page *old_dir_page, *new_dir_page;
	struct page *old_page, *new_page;
	struct f2fs_dir_entry *old_dir_entry = NULL, *new_dir_entry = NULL;
	struct f2fs_dir_entry *old_entry, *new_entry;
	int old_nlink = 0, new_nlink = 0;
	int err = -ENOENT;
1010

1011 1012 1013
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

C
Chao Yu 已提交
1014 1015 1016 1017 1018 1019 1020 1021
	if ((is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
			!projid_eq(F2FS_I(new_dir)->i_projid,
			F2FS_I(old_dentry->d_inode)->i_projid)) ||
	    (is_inode_flag_set(new_dir, FI_PROJ_INHERIT) &&
			!projid_eq(F2FS_I(old_dir)->i_projid,
			F2FS_I(new_dentry->d_inode)->i_projid)))
		return -EXDEV;

C
Chao Yu 已提交
1022 1023 1024 1025 1026 1027 1028 1029
	err = dquot_initialize(old_dir);
	if (err)
		goto out;

	err = dquot_initialize(new_dir);
	if (err)
		goto out;

C
Chao Yu 已提交
1030
	old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
1031 1032 1033
	if (!old_entry) {
		if (IS_ERR(old_page))
			err = PTR_ERR(old_page);
C
Chao Yu 已提交
1034
		goto out;
1035
	}
C
Chao Yu 已提交
1036 1037

	new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, &new_page);
1038 1039 1040
	if (!new_entry) {
		if (IS_ERR(new_page))
			err = PTR_ERR(new_page);
C
Chao Yu 已提交
1041
		goto out_old;
1042
	}
C
Chao Yu 已提交
1043 1044 1045 1046 1047 1048

	/* prepare for updating ".." directory entry info later */
	if (old_dir != new_dir) {
		if (S_ISDIR(old_inode->i_mode)) {
			old_dir_entry = f2fs_parent_dir(old_inode,
							&old_dir_page);
1049
			if (!old_dir_entry) {
1050 1051
				if (IS_ERR(old_dir_page))
					err = PTR_ERR(old_dir_page);
C
Chao Yu 已提交
1052
				goto out_new;
1053
			}
C
Chao Yu 已提交
1054 1055 1056 1057 1058
		}

		if (S_ISDIR(new_inode->i_mode)) {
			new_dir_entry = f2fs_parent_dir(new_inode,
							&new_dir_page);
1059
			if (!new_dir_entry) {
1060 1061
				if (IS_ERR(new_dir_page))
					err = PTR_ERR(new_dir_page);
C
Chao Yu 已提交
1062
				goto out_old_dir;
1063
			}
C
Chao Yu 已提交
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
		}
	}

	/*
	 * If cross rename between file and directory those are not
	 * in the same directory, we will inc nlink of file's parent
	 * later, so we should check upper boundary of its nlink.
	 */
	if ((!old_dir_entry || !new_dir_entry) &&
				old_dir_entry != new_dir_entry) {
		old_nlink = old_dir_entry ? -1 : 1;
		new_nlink = -old_nlink;
		err = -EMLINK;
1077 1078
		if ((old_nlink > 0 && old_dir->i_nlink >= F2FS_LINK_MAX) ||
			(new_nlink > 0 && new_dir->i_nlink >= F2FS_LINK_MAX))
C
Chao Yu 已提交
1079 1080 1081
			goto out_new_dir;
	}

J
Jaegeuk Kim 已提交
1082
	f2fs_balance_fs(sbi, true);
1083

C
Chao Yu 已提交
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
	f2fs_lock_op(sbi);

	/* update ".." directory entry info of old dentry */
	if (old_dir_entry)
		f2fs_set_link(old_inode, old_dir_entry, old_dir_page, new_dir);

	/* update ".." directory entry info of new dentry */
	if (new_dir_entry)
		f2fs_set_link(new_inode, new_dir_entry, new_dir_page, old_dir);

	/* update directory entry info of old dir inode */
	f2fs_set_link(old_dir, old_entry, old_page, new_inode);

	down_write(&F2FS_I(old_inode)->i_sem);
	file_lost_pino(old_inode);
	up_write(&F2FS_I(old_inode)->i_sem);

1101
	old_dir->i_ctime = current_time(old_dir);
C
Chao Yu 已提交
1102 1103
	if (old_nlink) {
		down_write(&F2FS_I(old_dir)->i_sem);
1104
		f2fs_i_links_write(old_dir, old_nlink > 0);
C
Chao Yu 已提交
1105 1106
		up_write(&F2FS_I(old_dir)->i_sem);
	}
1107
	f2fs_mark_inode_dirty_sync(old_dir, false);
C
Chao Yu 已提交
1108 1109 1110 1111 1112 1113 1114 1115

	/* update directory entry info of new dir inode */
	f2fs_set_link(new_dir, new_entry, new_page, old_inode);

	down_write(&F2FS_I(new_inode)->i_sem);
	file_lost_pino(new_inode);
	up_write(&F2FS_I(new_inode)->i_sem);

1116
	new_dir->i_ctime = current_time(new_dir);
C
Chao Yu 已提交
1117 1118
	if (new_nlink) {
		down_write(&F2FS_I(new_dir)->i_sem);
1119
		f2fs_i_links_write(new_dir, new_nlink > 0);
C
Chao Yu 已提交
1120 1121
		up_write(&F2FS_I(new_dir)->i_sem);
	}
1122
	f2fs_mark_inode_dirty_sync(new_dir, false);
C
Chao Yu 已提交
1123

1124
	if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT) {
1125 1126 1127
		add_ino_entry(sbi, old_dir->i_ino, TRANS_DIR_INO);
		add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO);
	}
1128

C
Chao Yu 已提交
1129
	f2fs_unlock_op(sbi);
J
Jaegeuk Kim 已提交
1130 1131 1132

	if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
		f2fs_sync_fs(sbi->sb, 1);
C
Chao Yu 已提交
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
	return 0;
out_new_dir:
	if (new_dir_entry) {
		f2fs_put_page(new_dir_page, 0);
	}
out_old_dir:
	if (old_dir_entry) {
		f2fs_put_page(old_dir_page, 0);
	}
out_new:
	f2fs_put_page(new_page, 0);
out_old:
	f2fs_put_page(old_page, 0);
out:
	return err;
}

static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry,
			struct inode *new_dir, struct dentry *new_dentry,
			unsigned int flags)
{
1154 1155
	int err;

C
Chao Yu 已提交
1156
	if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
C
Chao Yu 已提交
1157 1158
		return -EINVAL;

1159 1160 1161 1162 1163
	err = fscrypt_prepare_rename(old_dir, old_dentry, new_dir, new_dentry,
				     flags);
	if (err)
		return err;

C
Chao Yu 已提交
1164 1165 1166 1167 1168 1169 1170 1171
	if (flags & RENAME_EXCHANGE) {
		return f2fs_cross_rename(old_dir, old_dentry,
					 new_dir, new_dentry);
	}
	/*
	 * VFS has already handled the new dentry existence case,
	 * here, we just deal with "RENAME_NOREPLACE" as regular rename.
	 */
C
Chao Yu 已提交
1172
	return f2fs_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
C
Chao Yu 已提交
1173 1174
}

1175
static const char *f2fs_encrypted_get_link(struct dentry *dentry,
1176 1177
					   struct inode *inode,
					   struct delayed_call *done)
C
Chao Yu 已提交
1178
{
1179 1180
	struct page *page;
	const char *target;
1181

1182 1183 1184
	if (!dentry)
		return ERR_PTR(-ECHILD);

1185 1186 1187
	page = read_mapping_page(inode->i_mapping, 0, NULL);
	if (IS_ERR(page))
		return ERR_CAST(page);
1188

1189 1190 1191 1192
	target = fscrypt_get_symlink(inode, page_address(page),
				     inode->i_sb->s_blocksize, done);
	put_page(page);
	return target;
C
Chao Yu 已提交
1193 1194
}

1195
const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
1196
	.get_link       = f2fs_encrypted_get_link,
1197 1198
	.getattr	= f2fs_getattr,
	.setattr	= f2fs_setattr,
1199
#ifdef CONFIG_F2FS_FS_XATTR
1200
	.listxattr	= f2fs_listxattr,
1201
#endif
1202 1203
};

1204 1205 1206 1207 1208 1209 1210 1211 1212
const struct inode_operations f2fs_dir_inode_operations = {
	.create		= f2fs_create,
	.lookup		= f2fs_lookup,
	.link		= f2fs_link,
	.unlink		= f2fs_unlink,
	.symlink	= f2fs_symlink,
	.mkdir		= f2fs_mkdir,
	.rmdir		= f2fs_rmdir,
	.mknod		= f2fs_mknod,
1213
	.rename		= f2fs_rename2,
C
Chao Yu 已提交
1214
	.tmpfile	= f2fs_tmpfile,
1215
	.getattr	= f2fs_getattr,
1216 1217
	.setattr	= f2fs_setattr,
	.get_acl	= f2fs_get_acl,
1218
	.set_acl	= f2fs_set_acl,
1219 1220 1221 1222 1223 1224
#ifdef CONFIG_F2FS_FS_XATTR
	.listxattr	= f2fs_listxattr,
#endif
};

const struct inode_operations f2fs_symlink_inode_operations = {
1225
	.get_link       = f2fs_get_link,
1226
	.getattr	= f2fs_getattr,
1227 1228 1229 1230 1231 1232 1233
	.setattr	= f2fs_setattr,
#ifdef CONFIG_F2FS_FS_XATTR
	.listxattr	= f2fs_listxattr,
#endif
};

const struct inode_operations f2fs_special_inode_operations = {
1234
	.getattr	= f2fs_getattr,
1235 1236
	.setattr        = f2fs_setattr,
	.get_acl	= f2fs_get_acl,
1237
	.set_acl	= f2fs_set_acl,
1238 1239 1240 1241
#ifdef CONFIG_F2FS_FS_XATTR
	.listxattr	= f2fs_listxattr,
#endif
};