namei.c 28.8 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;
32
	int err;
33

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

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

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

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

	inode->i_ino = ino;
	inode->i_blocks = 0;
52
	inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
53 54 55 56 57
	inode->i_generation = sbi->s_next_generation++;

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

C
Chao Yu 已提交
61 62 63 64 65 66 67
	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 已提交
68 69 70 71 72 73 74 75
	err = dquot_initialize(inode);
	if (err)
		goto fail_drop;

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

76 77 78 79
	/* If the directory encrypted, then we should encrypt the inode. */
	if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode))
		f2fs_set_encrypted_inode(inode);

80 81
	set_inode_flag(inode, FI_NEW_INODE);

82 83 84 85 86
	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;
	}

87 88
	if (test_opt(sbi, INLINE_XATTR))
		set_inode_flag(inode, FI_INLINE_XATTR);
89
	if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode))
90
		set_inode_flag(inode, FI_INLINE_DATA);
91
	if (f2fs_may_inline_dentry(inode))
92
		set_inode_flag(inode, FI_INLINE_DENTRY);
C
Chao Yu 已提交
93

J
Jaegeuk Kim 已提交
94 95
	f2fs_init_extent_tree(inode, NULL);

C
Chao Yu 已提交
96
	stat_inc_inline_xattr(inode);
97 98 99
	stat_inc_inline_inode(inode);
	stat_inc_inline_dir(inode);

C
Chao Yu 已提交
100 101 102
	F2FS_I(inode)->i_flags =
		f2fs_mask_flags(mode, F2FS_I(dir)->i_flags & F2FS_FL_INHERITED);

C
Chao Yu 已提交
103 104 105
	if (S_ISDIR(inode->i_mode))
		F2FS_I(inode)->i_flags |= FS_INDEX_FL;

C
Chao Yu 已提交
106 107 108
	if (F2FS_I(inode)->i_flags & FS_PROJINHERIT_FL)
		set_inode_flag(inode, FI_PROJ_INHERIT);

109
	trace_f2fs_new_inode(inode, 0);
110 111 112
	return inode;

fail:
113
	trace_f2fs_new_inode(inode, err);
114
	make_bad_inode(inode);
115
	if (nid_free)
116
		set_inode_flag(inode, FI_FREE_NID);
117
	iput(inode);
118
	return ERR_PTR(err);
C
Chao Yu 已提交
119 120 121 122 123 124 125 126 127 128
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);
129 130 131 132
}

static int is_multimedia_file(const unsigned char *s, const char *sub)
{
133 134
	size_t slen = strlen(s);
	size_t sublen = strlen(sub);
135
	int i;
136

C
Chao Yu 已提交
137 138
	/*
	 * filename format of multimedia file should be defined as:
139
	 * "filename + '.' + extension + (optional: '.' + temp extension)".
C
Chao Yu 已提交
140 141 142 143
	 */
	if (slen < sublen + 2)
		return 0;

144 145 146 147 148 149
	for (i = 1; i < slen - sublen; i++) {
		if (s[i] != '.')
			continue;
		if (!strncasecmp(s + i + 1, sub, sublen))
			return 1;
	}
150

151
	return 0;
152 153
}

J
Jaegeuk Kim 已提交
154
/*
155 156
 * Set multimedia files as cold files for hot/cold data separation
 */
157
static inline void set_cold_files(struct f2fs_sb_info *sbi, struct inode *inode,
158 159 160 161 162 163 164
		const unsigned char *name)
{
	int i;
	__u8 (*extlist)[8] = sbi->raw_super->extension_list;

	int count = le32_to_cpu(sbi->raw_super->extension_count);
	for (i = 0; i < count; i++) {
165
		if (is_multimedia_file(name, extlist[i])) {
166
			file_set_cold(inode);
167 168 169 170 171 172 173 174
			break;
		}
	}
}

static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
						bool excl)
{
175
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
176 177
	struct inode *inode;
	nid_t ino = 0;
178
	int err;
179

180 181 182
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

C
Chao Yu 已提交
183 184 185 186
	err = dquot_initialize(dir);
	if (err)
		return err;

187 188 189 190 191
	inode = f2fs_new_inode(dir, mode);
	if (IS_ERR(inode))
		return PTR_ERR(inode);

	if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
192
		set_cold_files(sbi, inode, dentry->d_name.name);
193 194 195 196 197 198

	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;

199
	f2fs_lock_op(sbi);
200 201 202
	err = f2fs_add_link(dentry, inode);
	if (err)
		goto out;
203
	f2fs_unlock_op(sbi);
204 205 206

	alloc_nid_done(sbi, ino);

207
	d_instantiate(dentry, inode);
208
	unlock_new_inode(inode);
J
Jaegeuk Kim 已提交
209 210 211

	if (IS_DIRSYNC(dir))
		f2fs_sync_fs(sbi->sb, 1);
212 213

	f2fs_balance_fs(sbi, true);
214 215
	return 0;
out:
216
	handle_failed_inode(inode);
217 218 219 220 221 222
	return err;
}

static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
		struct dentry *dentry)
{
223
	struct inode *inode = d_inode(old_dentry);
224
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
225
	int err;
226

227 228 229
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

230
	if (f2fs_encrypted_inode(dir) &&
231
			!fscrypt_has_permitted_context(dir, inode))
232 233
		return -EPERM;

C
Chao Yu 已提交
234 235 236 237 238
	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 已提交
239 240 241 242
	err = dquot_initialize(dir);
	if (err)
		return err;

J
Jaegeuk Kim 已提交
243
	f2fs_balance_fs(sbi, true);
244

245
	inode->i_ctime = current_time(inode);
J
Jaegeuk Kim 已提交
246
	ihold(inode);
247

248
	set_inode_flag(inode, FI_INC_LINK);
249
	f2fs_lock_op(sbi);
250 251 252
	err = f2fs_add_link(dentry, inode);
	if (err)
		goto out;
253
	f2fs_unlock_op(sbi);
254 255

	d_instantiate(dentry, inode);
J
Jaegeuk Kim 已提交
256 257 258

	if (IS_DIRSYNC(dir))
		f2fs_sync_fs(sbi->sb, 1);
259 260
	return 0;
out:
261
	clear_inode_flag(inode, FI_INC_LINK);
262
	iput(inode);
263
	f2fs_unlock_op(sbi);
264 265 266 267 268 269
	return err;
}

struct dentry *f2fs_get_parent(struct dentry *child)
{
	struct qstr dotdot = QSTR_INIT("..", 2);
270 271 272 273 274
	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);
275
		return ERR_PTR(-ENOENT);
276
	}
277
	return d_obtain_alias(f2fs_iget(child->d_sb, ino));
278 279
}

280 281 282 283 284 285 286 287 288
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;

289 290 291 292 293 294 295
	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;
	}

296 297 298 299
	err = dquot_initialize(dir);
	if (err)
		return err;

J
Jaegeuk Kim 已提交
300
	f2fs_balance_fs(sbi, true);
301

302 303 304 305 306 307
	f2fs_lock_op(sbi);

	de = f2fs_find_entry(dir, &dot, &page);
	if (de) {
		f2fs_dentry_kunmap(dir, page);
		f2fs_put_page(page, 0);
308 309 310
	} else if (IS_ERR(page)) {
		err = PTR_ERR(page);
		goto out;
311 312 313 314 315 316 317 318 319 320
	} else {
		err = __f2fs_add_link(dir, &dot, NULL, dir->i_ino, S_IFDIR);
		if (err)
			goto out;
	}

	de = f2fs_find_entry(dir, &dotdot, &page);
	if (de) {
		f2fs_dentry_kunmap(dir, page);
		f2fs_put_page(page, 0);
321 322
	} else if (IS_ERR(page)) {
		err = PTR_ERR(page);
323 324 325 326
	} else {
		err = __f2fs_add_link(dir, &dotdot, NULL, pino, S_IFDIR);
	}
out:
327
	if (!err)
328
		clear_inode_flag(dir, FI_INLINE_DOTS);
329 330 331 332 333

	f2fs_unlock_op(sbi);
	return err;
}

334 335 336 337 338 339
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 已提交
340 341
	struct dentry *new;
	nid_t ino = -1;
342
	int err = 0;
343
	unsigned int root_ino = F2FS_ROOT_INO(F2FS_I_SB(dir));
344

C
Chao Yu 已提交
345 346
	trace_f2fs_lookup_start(dir, dentry, flags);

347
	if (f2fs_encrypted_inode(dir)) {
C
Chao Yu 已提交
348
		err = fscrypt_get_encryption_info(dir);
349 350 351 352 353 354 355 356 357

		/*
		 * DCACHE_ENCRYPTED_WITH_KEY is set if the dentry is
		 * created while the directory was encrypted and we
		 * don't have access to the key.
		 */
		if (fscrypt_has_encryption_key(dir))
			fscrypt_set_encrypted_dentry(dentry);
		fscrypt_set_d_op(dentry);
C
Chao Yu 已提交
358 359
		if (err && err != -ENOKEY)
			goto out;
360 361
	}

C
Chao Yu 已提交
362 363 364 365
	if (dentry->d_name.len > F2FS_NAME_LEN) {
		err = -ENAMETOOLONG;
		goto out;
	}
366 367

	de = f2fs_find_entry(dir, &dentry->d_name, &page);
J
Jaegeuk Kim 已提交
368
	if (!de) {
C
Chao Yu 已提交
369 370 371 372 373
		if (IS_ERR(page)) {
			err = PTR_ERR(page);
			goto out;
		}
		goto out_splice;
J
Jaegeuk Kim 已提交
374
	}
375

J
Jaegeuk Kim 已提交
376 377 378
	ino = le32_to_cpu(de->ino);
	f2fs_dentry_kunmap(dir, page);
	f2fs_put_page(page, 0);
379

J
Jaegeuk Kim 已提交
380
	inode = f2fs_iget(dir->i_sb, ino);
C
Chao Yu 已提交
381 382 383 384
	if (IS_ERR(inode)) {
		err = PTR_ERR(inode);
		goto out;
	}
385

386 387 388
	if ((dir->i_ino == root_ino) && f2fs_has_inline_dots(dir)) {
		err = __recover_dot_dentries(dir, root_ino);
		if (err)
C
Chao Yu 已提交
389
			goto out_iput;
390 391
	}

392
	if (f2fs_has_inline_dots(inode)) {
J
Jaegeuk Kim 已提交
393
		err = __recover_dot_dentries(inode, dir->i_ino);
394
		if (err)
C
Chao Yu 已提交
395
			goto out_iput;
396
	}
D
Dan Carpenter 已提交
397 398 399
	if (f2fs_encrypted_inode(dir) &&
	    (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
	    !fscrypt_has_permitted_context(dir, inode)) {
400 401 402 403
		f2fs_msg(inode->i_sb, KERN_WARNING,
			 "Inconsistent encryption contexts: %lu/%lu",
			 dir->i_ino, inode->i_ino);
		err = -EPERM;
C
Chao Yu 已提交
404
		goto out_iput;
405
	}
C
Chao Yu 已提交
406 407 408 409 410 411 412
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:
413
	iput(inode);
C
Chao Yu 已提交
414 415
out:
	trace_f2fs_lookup_end(dir, dentry, ino, err);
416
	return ERR_PTR(err);
417 418 419 420
}

static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
{
421
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
422
	struct inode *inode = d_inode(dentry);
423 424 425 426
	struct f2fs_dir_entry *de;
	struct page *page;
	int err = -ENOENT;

427
	trace_f2fs_unlink_enter(dir, dentry);
428

429 430 431
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

C
Chao Yu 已提交
432 433 434 435
	err = dquot_initialize(dir);
	if (err)
		return err;

436
	de = f2fs_find_entry(dir, &dentry->d_name, &page);
437 438 439
	if (!de) {
		if (IS_ERR(page))
			err = PTR_ERR(page);
440
		goto fail;
441
	}
442

J
Jaegeuk Kim 已提交
443
	f2fs_balance_fs(sbi, true);
444

445
	f2fs_lock_op(sbi);
J
Jaegeuk Kim 已提交
446
	err = acquire_orphan_inode(sbi);
447
	if (err) {
448
		f2fs_unlock_op(sbi);
449
		f2fs_dentry_kunmap(dir, page);
450 451 452
		f2fs_put_page(page, 0);
		goto fail;
	}
453
	f2fs_delete_entry(de, page, dir, inode);
454
	f2fs_unlock_op(sbi);
455

J
Jaegeuk Kim 已提交
456 457
	if (IS_DIRSYNC(dir))
		f2fs_sync_fs(sbi->sb, 1);
458
fail:
459
	trace_f2fs_unlink_exit(inode, err);
460 461 462
	return err;
}

463
static const char *f2fs_get_link(struct dentry *dentry,
464 465
				 struct inode *inode,
				 struct delayed_call *done)
466
{
467
	const char *link = page_get_link(dentry, inode, done);
468 469
	if (!IS_ERR(link) && !*link) {
		/* this is broken symlink case */
470 471
		do_delayed_call(done);
		clear_delayed_call(done);
472
		link = ERR_PTR(-ENOENT);
473
	}
474
	return link;
475 476
}

477 478 479
static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
					const char *symname)
{
480
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
481
	struct inode *inode;
482
	size_t len = strlen(symname);
483 484
	struct fscrypt_str disk_link = FSTR_INIT((char *)symname, len + 1);
	struct fscrypt_symlink_data *sd = NULL;
485
	int err;
486

487 488 489
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

490
	if (f2fs_encrypted_inode(dir)) {
491
		err = fscrypt_get_encryption_info(dir);
492 493 494
		if (err)
			return err;

495
		if (!fscrypt_has_encryption_key(dir))
496
			return -ENOKEY;
497

498 499
		disk_link.len = (fscrypt_fname_encrypted_size(dir, len) +
				sizeof(struct fscrypt_symlink_data));
500 501 502
	}

	if (disk_link.len > dir->i_sb->s_blocksize)
503 504
		return -ENAMETOOLONG;

C
Chao Yu 已提交
505 506 507 508
	err = dquot_initialize(dir);
	if (err)
		return err;

509 510 511 512
	inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO);
	if (IS_ERR(inode))
		return PTR_ERR(inode);

513 514 515 516
	if (f2fs_encrypted_inode(inode))
		inode->i_op = &f2fs_encrypted_symlink_inode_operations;
	else
		inode->i_op = &f2fs_symlink_inode_operations;
517
	inode_nohighmem(inode);
518 519
	inode->i_mapping->a_ops = &f2fs_dblock_aops;

520
	f2fs_lock_op(sbi);
521 522 523
	err = f2fs_add_link(dentry, inode);
	if (err)
		goto out;
524
	f2fs_unlock_op(sbi);
525 526
	alloc_nid_done(sbi, inode->i_ino);

527
	if (f2fs_encrypted_inode(inode)) {
528
		struct qstr istr = QSTR_INIT(symname, len);
529
		struct fscrypt_str ostr;
530

531 532 533
		sd = kzalloc(disk_link.len, GFP_NOFS);
		if (!sd) {
			err = -ENOMEM;
534
			goto err_out;
535
		}
536

537
		err = fscrypt_get_encryption_info(inode);
538 539 540
		if (err)
			goto err_out;

541
		if (!fscrypt_has_encryption_key(inode)) {
542
			err = -ENOKEY;
543 544 545
			goto err_out;
		}

546 547
		ostr.name = sd->encrypted_path;
		ostr.len = disk_link.len;
548
		err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr);
549
		if (err)
550
			goto err_out;
551 552 553

		sd->len = cpu_to_le16(ostr.len);
		disk_link.name = (char *)sd;
554 555
	}

556
	err = page_symlink(inode, disk_link.name, disk_link.len);
557 558

err_out:
559 560
	d_instantiate(dentry, inode);
	unlock_new_inode(inode);
J
Jaegeuk Kim 已提交
561

562 563 564 565 566 567 568 569 570
	/*
	 * 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 已提交
571
	if (!err) {
572 573
		filemap_write_and_wait_range(inode->i_mapping, 0,
							disk_link.len - 1);
574

C
Chao Yu 已提交
575 576 577 578 579
		if (IS_DIRSYNC(dir))
			f2fs_sync_fs(sbi->sb, 1);
	} else {
		f2fs_unlink(dir, dentry);
	}
580 581

	kfree(sd);
582 583

	f2fs_balance_fs(sbi, true);
584 585
	return err;
out:
586
	handle_failed_inode(inode);
587 588 589 590 591
	return err;
}

static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
{
592
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
593
	struct inode *inode;
594
	int err;
595

596 597 598
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

C
Chao Yu 已提交
599 600 601 602
	err = dquot_initialize(dir);
	if (err)
		return err;

603 604
	inode = f2fs_new_inode(dir, S_IFDIR | mode);
	if (IS_ERR(inode))
605
		return PTR_ERR(inode);
606 607 608 609

	inode->i_op = &f2fs_dir_inode_operations;
	inode->i_fop = &f2fs_dir_operations;
	inode->i_mapping->a_ops = &f2fs_dblock_aops;
610
	mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_HIGH_ZERO);
611

612
	set_inode_flag(inode, FI_INC_LINK);
613
	f2fs_lock_op(sbi);
614 615 616
	err = f2fs_add_link(dentry, inode);
	if (err)
		goto out_fail;
617
	f2fs_unlock_op(sbi);
618 619 620 621 622 623

	alloc_nid_done(sbi, inode->i_ino);

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

J
Jaegeuk Kim 已提交
624 625
	if (IS_DIRSYNC(dir))
		f2fs_sync_fs(sbi->sb, 1);
626 627

	f2fs_balance_fs(sbi, true);
628 629 630
	return 0;

out_fail:
631
	clear_inode_flag(inode, FI_INC_LINK);
632
	handle_failed_inode(inode);
633 634 635 636 637
	return err;
}

static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)
{
638
	struct inode *inode = d_inode(dentry);
639 640 641 642 643 644 645 646
	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)
{
647
	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
648 649 650
	struct inode *inode;
	int err = 0;

651 652 653
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

C
Chao Yu 已提交
654 655 656 657
	err = dquot_initialize(dir);
	if (err)
		return err;

658 659 660 661 662 663 664
	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;

665
	f2fs_lock_op(sbi);
666 667 668
	err = f2fs_add_link(dentry, inode);
	if (err)
		goto out;
669
	f2fs_unlock_op(sbi);
670 671

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

673 674
	d_instantiate(dentry, inode);
	unlock_new_inode(inode);
J
Jaegeuk Kim 已提交
675 676 677

	if (IS_DIRSYNC(dir))
		f2fs_sync_fs(sbi->sb, 1);
678 679

	f2fs_balance_fs(sbi, true);
680 681
	return 0;
out:
682
	handle_failed_inode(inode);
683 684 685
	return err;
}

C
Chao Yu 已提交
686 687 688 689 690 691 692
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 已提交
693 694 695 696
	err = dquot_initialize(dir);
	if (err)
		return err;

C
Chao Yu 已提交
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
	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.
	 */
723
	add_orphan_inode(inode);
C
Chao Yu 已提交
724 725 726
	alloc_nid_done(sbi, inode->i_ino);

	if (whiteout) {
727
		f2fs_i_links_write(inode, false);
C
Chao Yu 已提交
728 729 730 731
		*whiteout = inode;
	} else {
		d_tmpfile(dentry, inode);
	}
732 733
	/* link_count was changed by d_tmpfile as well. */
	f2fs_unlock_op(sbi);
C
Chao Yu 已提交
734
	unlock_new_inode(inode);
735 736

	f2fs_balance_fs(sbi, true);
C
Chao Yu 已提交
737 738 739 740 741 742 743 744 745 746 747
	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)
{
748 749 750
	if (unlikely(f2fs_cp_error(F2FS_I_SB(dir))))
		return -EIO;

751
	if (f2fs_encrypted_inode(dir)) {
752
		int err = fscrypt_get_encryption_info(dir);
753 754 755 756
		if (err)
			return err;
	}

C
Chao Yu 已提交
757 758 759 760 761
	return __f2fs_tmpfile(dir, dentry, mode, NULL);
}

static int f2fs_create_whiteout(struct inode *dir, struct inode **whiteout)
{
762 763 764
	if (unlikely(f2fs_cp_error(F2FS_I_SB(dir))))
		return -EIO;

C
Chao Yu 已提交
765 766 767
	return __f2fs_tmpfile(dir, NULL, S_IFCHR | WHITEOUT_MODE, whiteout);
}

768
static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
C
Chao Yu 已提交
769 770
			struct inode *new_dir, struct dentry *new_dentry,
			unsigned int flags)
771
{
772
	struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
773 774
	struct inode *old_inode = d_inode(old_dentry);
	struct inode *new_inode = d_inode(new_dentry);
C
Chao Yu 已提交
775
	struct inode *whiteout = NULL;
776
	struct page *old_dir_page;
C
Chao Yu 已提交
777
	struct page *old_page, *new_page = NULL;
778 779 780
	struct f2fs_dir_entry *old_dir_entry = NULL;
	struct f2fs_dir_entry *old_entry;
	struct f2fs_dir_entry *new_entry;
781
	bool is_old_inline = f2fs_has_inline_dentry(old_dir);
782
	int err = -ENOENT;
783

784 785 786
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

787 788 789 790 791 792
	if ((f2fs_encrypted_inode(old_dir) &&
			!fscrypt_has_encryption_key(old_dir)) ||
			(f2fs_encrypted_inode(new_dir) &&
			!fscrypt_has_encryption_key(new_dir)))
		return -ENOKEY;

793
	if ((old_dir != new_dir) && f2fs_encrypted_inode(new_dir) &&
794
			!fscrypt_has_permitted_context(new_dir, old_inode)) {
795 796 797 798
		err = -EPERM;
		goto out;
	}

C
Chao Yu 已提交
799 800 801 802 803
	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 已提交
804 805 806 807 808 809 810 811
	err = dquot_initialize(old_dir);
	if (err)
		goto out;

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

812
	old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
813 814 815
	if (!old_entry) {
		if (IS_ERR(old_page))
			err = PTR_ERR(old_page);
816
		goto out;
817
	}
818 819 820

	if (S_ISDIR(old_inode->i_mode)) {
		old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page);
821
		if (!old_dir_entry) {
822 823
			if (IS_ERR(old_dir_page))
				err = PTR_ERR(old_dir_page);
824
			goto out_old;
825
		}
826 827
	}

C
Chao Yu 已提交
828 829 830 831 832 833
	if (flags & RENAME_WHITEOUT) {
		err = f2fs_create_whiteout(old_dir, &whiteout);
		if (err)
			goto out_dir;
	}

834 835 836 837
	if (new_inode) {

		err = -ENOTEMPTY;
		if (old_dir_entry && !f2fs_empty_dir(new_inode))
C
Chao Yu 已提交
838
			goto out_whiteout;
839 840 841 842

		err = -ENOENT;
		new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name,
						&new_page);
843 844 845
		if (!new_entry) {
			if (IS_ERR(new_page))
				err = PTR_ERR(new_page);
C
Chao Yu 已提交
846
			goto out_whiteout;
847
		}
848

J
Jaegeuk Kim 已提交
849
		f2fs_balance_fs(sbi, true);
850

851 852
		f2fs_lock_op(sbi);

J
Jaegeuk Kim 已提交
853 854 855 856
		err = acquire_orphan_inode(sbi);
		if (err)
			goto put_out_dir;

857 858
		f2fs_set_link(new_dir, new_entry, new_page, old_inode);

859
		new_inode->i_ctime = current_time(new_inode);
860
		down_write(&F2FS_I(new_inode)->i_sem);
861
		if (old_dir_entry)
862 863
			f2fs_i_links_write(new_inode, false);
		f2fs_i_links_write(new_inode, false);
864 865
		up_write(&F2FS_I(new_inode)->i_sem);

866
		if (!new_inode->i_nlink)
867
			add_orphan_inode(new_inode);
J
Jaegeuk Kim 已提交
868 869
		else
			release_orphan_inode(sbi);
870
	} else {
J
Jaegeuk Kim 已提交
871
		f2fs_balance_fs(sbi, true);
872

873 874
		f2fs_lock_op(sbi);

875
		err = f2fs_add_link(new_dentry, old_inode);
876 877
		if (err) {
			f2fs_unlock_op(sbi);
C
Chao Yu 已提交
878
			goto out_whiteout;
879
		}
880

881
		if (old_dir_entry)
882
			f2fs_i_links_write(new_dir, true);
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897

		/*
		 * 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) {
898 899 900
				err = -ENOENT;
				if (IS_ERR(old_page))
					err = PTR_ERR(old_page);
901 902 903 904
				f2fs_unlock_op(sbi);
				goto out_whiteout;
			}
		}
905 906
	}

907
	down_write(&F2FS_I(old_inode)->i_sem);
908 909 910 911
	if (!old_dir_entry || whiteout)
		file_lost_pino(old_inode);
	else
		F2FS_I(old_inode)->i_pino = new_dir->i_ino;
912 913
	up_write(&F2FS_I(old_inode)->i_sem);

914
	old_inode->i_ctime = current_time(old_inode);
915
	f2fs_mark_inode_dirty_sync(old_inode, false);
916

917
	f2fs_delete_entry(old_entry, old_page, old_dir, NULL);
918

C
Chao Yu 已提交
919 920
	if (whiteout) {
		whiteout->i_state |= I_LINKABLE;
921
		set_inode_flag(whiteout, FI_INC_LINK);
C
Chao Yu 已提交
922 923 924 925 926 927 928
		err = f2fs_add_link(old_dentry, whiteout);
		if (err)
			goto put_out_dir;
		whiteout->i_state &= ~I_LINKABLE;
		iput(whiteout);
	}

929
	if (old_dir_entry) {
C
Chao Yu 已提交
930
		if (old_dir != new_dir && !whiteout) {
931 932 933
			f2fs_set_link(old_inode, old_dir_entry,
						old_dir_page, new_dir);
		} else {
934
			f2fs_dentry_kunmap(old_inode, old_dir_page);
935 936
			f2fs_put_page(old_dir_page, 0);
		}
937
		f2fs_i_links_write(old_dir, false);
938 939
	}

940
	f2fs_unlock_op(sbi);
J
Jaegeuk Kim 已提交
941 942 943

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

J
Jaegeuk Kim 已提交
946
put_out_dir:
947
	f2fs_unlock_op(sbi);
C
Chao Yu 已提交
948 949 950 951 952 953 954
	if (new_page) {
		f2fs_dentry_kunmap(new_dir, new_page);
		f2fs_put_page(new_page, 0);
	}
out_whiteout:
	if (whiteout)
		iput(whiteout);
955 956
out_dir:
	if (old_dir_entry) {
957
		f2fs_dentry_kunmap(old_inode, old_dir_page);
958 959 960
		f2fs_put_page(old_dir_page, 0);
	}
out_old:
961
	f2fs_dentry_kunmap(old_dir, old_page);
962 963 964 965 966
	f2fs_put_page(old_page, 0);
out:
	return err;
}

C
Chao Yu 已提交
967 968 969
static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
			     struct inode *new_dir, struct dentry *new_dentry)
{
970
	struct f2fs_sb_info *sbi = F2FS_I_SB(old_dir);
971 972
	struct inode *old_inode = d_inode(old_dentry);
	struct inode *new_inode = d_inode(new_dentry);
C
Chao Yu 已提交
973 974 975 976 977 978
	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;
979

980 981 982
	if (unlikely(f2fs_cp_error(sbi)))
		return -EIO;

983 984 985 986 987
	if ((f2fs_encrypted_inode(old_dir) &&
			!fscrypt_has_encryption_key(old_dir)) ||
			(f2fs_encrypted_inode(new_dir) &&
			!fscrypt_has_encryption_key(new_dir)))
		return -ENOKEY;
C
Chao Yu 已提交
988

989
	if ((f2fs_encrypted_inode(old_dir) || f2fs_encrypted_inode(new_dir)) &&
990 991 992
			(old_dir != new_dir) &&
			(!fscrypt_has_permitted_context(new_dir, old_inode) ||
			 !fscrypt_has_permitted_context(old_dir, new_inode)))
993 994
		return -EPERM;

C
Chao Yu 已提交
995 996 997 998 999 1000 1001 1002
	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 已提交
1003 1004 1005 1006 1007 1008 1009 1010
	err = dquot_initialize(old_dir);
	if (err)
		goto out;

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

C
Chao Yu 已提交
1011
	old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
1012 1013 1014
	if (!old_entry) {
		if (IS_ERR(old_page))
			err = PTR_ERR(old_page);
C
Chao Yu 已提交
1015
		goto out;
1016
	}
C
Chao Yu 已提交
1017 1018

	new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, &new_page);
1019 1020 1021
	if (!new_entry) {
		if (IS_ERR(new_page))
			err = PTR_ERR(new_page);
C
Chao Yu 已提交
1022
		goto out_old;
1023
	}
C
Chao Yu 已提交
1024 1025 1026 1027 1028 1029

	/* 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);
1030
			if (!old_dir_entry) {
1031 1032
				if (IS_ERR(old_dir_page))
					err = PTR_ERR(old_dir_page);
C
Chao Yu 已提交
1033
				goto out_new;
1034
			}
C
Chao Yu 已提交
1035 1036 1037 1038 1039
		}

		if (S_ISDIR(new_inode->i_mode)) {
			new_dir_entry = f2fs_parent_dir(new_inode,
							&new_dir_page);
1040
			if (!new_dir_entry) {
1041 1042
				if (IS_ERR(new_dir_page))
					err = PTR_ERR(new_dir_page);
C
Chao Yu 已提交
1043
				goto out_old_dir;
1044
			}
C
Chao Yu 已提交
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
		}
	}

	/*
	 * 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;
1058 1059
		if ((old_nlink > 0 && old_dir->i_nlink >= F2FS_LINK_MAX) ||
			(new_nlink > 0 && new_dir->i_nlink >= F2FS_LINK_MAX))
C
Chao Yu 已提交
1060 1061 1062
			goto out_new_dir;
	}

J
Jaegeuk Kim 已提交
1063
	f2fs_balance_fs(sbi, true);
1064

C
Chao Yu 已提交
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
	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);

1082
	old_dir->i_ctime = current_time(old_dir);
C
Chao Yu 已提交
1083 1084
	if (old_nlink) {
		down_write(&F2FS_I(old_dir)->i_sem);
1085
		f2fs_i_links_write(old_dir, old_nlink > 0);
C
Chao Yu 已提交
1086 1087
		up_write(&F2FS_I(old_dir)->i_sem);
	}
1088
	f2fs_mark_inode_dirty_sync(old_dir, false);
C
Chao Yu 已提交
1089 1090 1091 1092 1093 1094 1095 1096

	/* 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);

1097
	new_dir->i_ctime = current_time(new_dir);
C
Chao Yu 已提交
1098 1099
	if (new_nlink) {
		down_write(&F2FS_I(new_dir)->i_sem);
1100
		f2fs_i_links_write(new_dir, new_nlink > 0);
C
Chao Yu 已提交
1101 1102
		up_write(&F2FS_I(new_dir)->i_sem);
	}
1103
	f2fs_mark_inode_dirty_sync(new_dir, false);
C
Chao Yu 已提交
1104 1105

	f2fs_unlock_op(sbi);
J
Jaegeuk Kim 已提交
1106 1107 1108

	if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
		f2fs_sync_fs(sbi->sb, 1);
C
Chao Yu 已提交
1109 1110 1111
	return 0;
out_new_dir:
	if (new_dir_entry) {
1112
		f2fs_dentry_kunmap(new_inode, new_dir_page);
C
Chao Yu 已提交
1113 1114 1115 1116
		f2fs_put_page(new_dir_page, 0);
	}
out_old_dir:
	if (old_dir_entry) {
1117
		f2fs_dentry_kunmap(old_inode, old_dir_page);
C
Chao Yu 已提交
1118 1119 1120
		f2fs_put_page(old_dir_page, 0);
	}
out_new:
1121
	f2fs_dentry_kunmap(new_dir, new_page);
C
Chao Yu 已提交
1122 1123
	f2fs_put_page(new_page, 0);
out_old:
1124
	f2fs_dentry_kunmap(old_dir, old_page);
C
Chao Yu 已提交
1125 1126 1127 1128 1129 1130 1131 1132 1133
	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)
{
C
Chao Yu 已提交
1134
	if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
C
Chao Yu 已提交
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
		return -EINVAL;

	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 已提交
1145
	return f2fs_rename(old_dir, old_dentry, new_dir, new_dentry, flags);
C
Chao Yu 已提交
1146 1147
}

1148
static const char *f2fs_encrypted_get_link(struct dentry *dentry,
1149 1150
					   struct inode *inode,
					   struct delayed_call *done)
C
Chao Yu 已提交
1151
{
1152 1153
	struct page *cpage = NULL;
	char *caddr, *paddr = NULL;
1154 1155 1156
	struct fscrypt_str cstr = FSTR_INIT(NULL, 0);
	struct fscrypt_str pstr = FSTR_INIT(NULL, 0);
	struct fscrypt_symlink_data *sd;
1157 1158 1159
	u32 max_size = inode->i_sb->s_blocksize;
	int res;

1160 1161 1162
	if (!dentry)
		return ERR_PTR(-ECHILD);

1163
	res = fscrypt_get_encryption_info(inode);
1164 1165 1166 1167 1168
	if (res)
		return ERR_PTR(res);

	cpage = read_mapping_page(inode->i_mapping, 0, NULL);
	if (IS_ERR(cpage))
1169
		return ERR_CAST(cpage);
1170
	caddr = page_address(cpage);
1171 1172

	/* Symlink is encrypted */
1173
	sd = (struct fscrypt_symlink_data *)caddr;
1174
	cstr.name = sd->encrypted_path;
1175
	cstr.len = le16_to_cpu(sd->len);
1176 1177 1178 1179 1180 1181

	/* this is broken symlink case */
	if (unlikely(cstr.len == 0)) {
		res = -ENOENT;
		goto errout;
	}
1182

1183
	if ((cstr.len + sizeof(struct fscrypt_symlink_data) - 1) > max_size) {
1184 1185 1186 1187
		/* Symlink data on the disk is corrupted */
		res = -EIO;
		goto errout;
	}
1188
	res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr);
1189 1190 1191
	if (res)
		goto errout;

1192
	res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr);
1193
	if (res)
1194 1195
		goto errout;

1196 1197 1198 1199 1200 1201
	/* this is broken symlink case */
	if (unlikely(pstr.name[0] == 0)) {
		res = -ENOENT;
		goto errout;
	}

1202 1203 1204
	paddr = pstr.name;

	/* Null-terminate the name */
1205
	paddr[pstr.len] = '\0';
1206

1207
	put_page(cpage);
1208 1209
	set_delayed_call(done, kfree_link, paddr);
	return paddr;
1210
errout:
1211
	fscrypt_fname_free_buffer(&pstr);
1212
	put_page(cpage);
1213
	return ERR_PTR(res);
C
Chao Yu 已提交
1214 1215
}

1216
const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
1217
	.get_link       = f2fs_encrypted_get_link,
1218 1219
	.getattr	= f2fs_getattr,
	.setattr	= f2fs_setattr,
1220
#ifdef CONFIG_F2FS_FS_XATTR
1221
	.listxattr	= f2fs_listxattr,
1222
#endif
1223 1224
};

1225 1226 1227 1228 1229 1230 1231 1232 1233
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,
1234
	.rename		= f2fs_rename2,
C
Chao Yu 已提交
1235
	.tmpfile	= f2fs_tmpfile,
1236
	.getattr	= f2fs_getattr,
1237 1238
	.setattr	= f2fs_setattr,
	.get_acl	= f2fs_get_acl,
1239
	.set_acl	= f2fs_set_acl,
1240 1241 1242 1243 1244 1245
#ifdef CONFIG_F2FS_FS_XATTR
	.listxattr	= f2fs_listxattr,
#endif
};

const struct inode_operations f2fs_symlink_inode_operations = {
1246
	.get_link       = f2fs_get_link,
1247
	.getattr	= f2fs_getattr,
1248 1249 1250 1251 1252 1253 1254
	.setattr	= f2fs_setattr,
#ifdef CONFIG_F2FS_FS_XATTR
	.listxattr	= f2fs_listxattr,
#endif
};

const struct inode_operations f2fs_special_inode_operations = {
1255
	.getattr	= f2fs_getattr,
1256 1257
	.setattr        = f2fs_setattr,
	.get_acl	= f2fs_get_acl,
1258
	.set_acl	= f2fs_set_acl,
1259 1260 1261 1262
#ifdef CONFIG_F2FS_FS_XATTR
	.listxattr	= f2fs_listxattr,
#endif
};