Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * namei.c - NILFS pathname lookup operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Modified for NILFS by Amagai Yoshiji and Ryusuke Konishi.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *  linux/fs/ext2/namei.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Copyright (C) 1992, 1993, 1994, 1995
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * Remy Card (card@masi.ibp.fr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * Laboratoire MASI - Institut Blaise Pascal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * Universite Pierre et Marie Curie (Paris VI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *  from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *  linux/fs/minix/namei.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *  Copyright (C) 1991, 1992  Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *  Big-endian to little-endian byte-swapping/bitmaps by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *        David S. Miller (davem@caip.rutgers.edu), 1995
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "nilfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include "export.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define NILFS_FID_SIZE_NON_CONNECTABLE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	(offsetof(struct nilfs_fid, parent_gen) / 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define NILFS_FID_SIZE_CONNECTABLE	(sizeof(struct nilfs_fid) / 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static inline int nilfs_add_nondir(struct dentry *dentry, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int err = nilfs_add_link(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		d_instantiate_new(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	inode_dec_link_count(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * Methods themselves.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static struct dentry *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) nilfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	ino_t ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (dentry->d_name.len > NILFS_NAME_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		return ERR_PTR(-ENAMETOOLONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	ino = nilfs_inode_by_name(dir, &dentry->d_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	inode = ino ? nilfs_iget(dir->i_sb, NILFS_I(dir)->i_root, ino) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return d_splice_alias(inode, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * By the time this is called, we already have created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * the directory cache entry for the new file, but it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * is so far negative - it has no inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * If the create succeeds, we fill in the inode information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * with d_instantiate().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static int nilfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			bool excl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct nilfs_transaction_info ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	err = nilfs_transaction_begin(dir->i_sb, &ti, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	inode = nilfs_new_inode(dir, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (!IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		inode->i_op = &nilfs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		inode->i_fop = &nilfs_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		inode->i_mapping->a_ops = &nilfs_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		nilfs_mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		err = nilfs_add_nondir(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		err = nilfs_transaction_commit(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		nilfs_transaction_abort(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) nilfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct nilfs_transaction_info ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	err = nilfs_transaction_begin(dir->i_sb, &ti, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	inode = nilfs_new_inode(dir, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (!IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		init_special_inode(inode, inode->i_mode, rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		nilfs_mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		err = nilfs_add_nondir(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		err = nilfs_transaction_commit(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		nilfs_transaction_abort(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int nilfs_symlink(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			 const char *symname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct nilfs_transaction_info ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct super_block *sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	unsigned int l = strlen(symname) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (l > sb->s_blocksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return -ENAMETOOLONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	err = nilfs_transaction_begin(dir->i_sb, &ti, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	inode = nilfs_new_inode(dir, S_IFLNK | 0777);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	/* slow symlink */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	inode->i_op = &nilfs_symlink_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	inode_nohighmem(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	inode->i_mapping->a_ops = &nilfs_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	err = page_symlink(inode, symname, l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	/* mark_inode_dirty(inode); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	/* page_symlink() do this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	err = nilfs_add_nondir(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		err = nilfs_transaction_commit(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		nilfs_transaction_abort(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) out_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	drop_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	nilfs_mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static int nilfs_link(struct dentry *old_dentry, struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		      struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct inode *inode = d_inode(old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct nilfs_transaction_info ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	err = nilfs_transaction_begin(dir->i_sb, &ti, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	inode_inc_link_count(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	ihold(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	err = nilfs_add_link(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		err = nilfs_transaction_commit(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		inode_dec_link_count(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		nilfs_transaction_abort(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static int nilfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct nilfs_transaction_info ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	err = nilfs_transaction_begin(dir->i_sb, &ti, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	inc_nlink(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	inode = nilfs_new_inode(dir, S_IFDIR | mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		goto out_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	inode->i_op = &nilfs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	inode->i_fop = &nilfs_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	inode->i_mapping->a_ops = &nilfs_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	inc_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	err = nilfs_make_empty(inode, dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	err = nilfs_add_link(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	nilfs_mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	d_instantiate_new(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		err = nilfs_transaction_commit(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		nilfs_transaction_abort(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) out_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	drop_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	drop_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	nilfs_mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) out_dir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	drop_nlink(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	nilfs_mark_inode_dirty(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static int nilfs_do_unlink(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	struct nilfs_dir_entry *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	de = nilfs_find_entry(dir, &dentry->d_name, &page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (!de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (le64_to_cpu(de->inode) != inode->i_ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	if (!inode->i_nlink) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		nilfs_warn(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			   "deleting nonexistent file (ino=%lu), %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			   inode->i_ino, inode->i_nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		set_nlink(inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	err = nilfs_delete_entry(de, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	inode->i_ctime = dir->i_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	drop_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static int nilfs_unlink(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	struct nilfs_transaction_info ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	err = nilfs_transaction_begin(dir->i_sb, &ti, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	err = nilfs_do_unlink(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		nilfs_mark_inode_dirty(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		nilfs_mark_inode_dirty(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		err = nilfs_transaction_commit(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		nilfs_transaction_abort(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static int nilfs_rmdir(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	struct nilfs_transaction_info ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	err = nilfs_transaction_begin(dir->i_sb, &ti, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	err = -ENOTEMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (nilfs_empty_dir(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		err = nilfs_do_unlink(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			inode->i_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 			drop_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 			nilfs_mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 			drop_nlink(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 			nilfs_mark_inode_dirty(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		err = nilfs_transaction_commit(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		nilfs_transaction_abort(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			struct inode *new_dir,	struct dentry *new_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	struct inode *old_inode = d_inode(old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	struct inode *new_inode = d_inode(new_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	struct page *dir_page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	struct nilfs_dir_entry *dir_de = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	struct page *old_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	struct nilfs_dir_entry *old_de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	struct nilfs_transaction_info ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	if (flags & ~RENAME_NOREPLACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	err = nilfs_transaction_begin(old_dir->i_sb, &ti, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	if (unlikely(err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	old_de = nilfs_find_entry(old_dir, &old_dentry->d_name, &old_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (!old_de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	if (S_ISDIR(old_inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		dir_de = nilfs_dotdot(old_inode, &dir_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		if (!dir_de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			goto out_old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	if (new_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		struct page *new_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		struct nilfs_dir_entry *new_de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		err = -ENOTEMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		if (dir_de && !nilfs_empty_dir(new_inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 			goto out_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		new_de = nilfs_find_entry(new_dir, &new_dentry->d_name, &new_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		if (!new_de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 			goto out_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		nilfs_set_link(new_dir, new_de, new_page, old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		nilfs_mark_inode_dirty(new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		new_inode->i_ctime = current_time(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		if (dir_de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			drop_nlink(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		drop_nlink(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		nilfs_mark_inode_dirty(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		err = nilfs_add_link(new_dentry, old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 			goto out_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		if (dir_de) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 			inc_nlink(new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 			nilfs_mark_inode_dirty(new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	 * Like most other Unix systems, set the ctime for inodes on a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	 * rename.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	old_inode->i_ctime = current_time(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	nilfs_delete_entry(old_de, old_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (dir_de) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		nilfs_set_link(old_inode, dir_de, dir_page, new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		drop_nlink(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	nilfs_mark_inode_dirty(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	nilfs_mark_inode_dirty(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	err = nilfs_transaction_commit(old_dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) out_dir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	if (dir_de) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		kunmap(dir_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		put_page(dir_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) out_old:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	kunmap(old_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	put_page(old_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	nilfs_transaction_abort(old_dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)  * Export operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) static struct dentry *nilfs_get_parent(struct dentry *child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	unsigned long ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	struct qstr dotdot = QSTR_INIT("..", 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	struct nilfs_root *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	ino = nilfs_inode_by_name(d_inode(child), &dotdot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	if (!ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	root = NILFS_I(d_inode(child))->i_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	inode = nilfs_iget(child->d_sb, root, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		return ERR_CAST(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	return d_obtain_alias(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static struct dentry *nilfs_get_dentry(struct super_block *sb, u64 cno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 				       u64 ino, u32 gen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	struct nilfs_root *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	if (ino < NILFS_FIRST_INO(sb) && ino != NILFS_ROOT_INO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		return ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	root = nilfs_lookup_root(sb->s_fs_info, cno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	if (!root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		return ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	inode = nilfs_iget(sb, root, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	nilfs_put_root(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		return ERR_CAST(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	if (gen && inode->i_generation != gen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		return ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	return d_obtain_alias(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static struct dentry *nilfs_fh_to_dentry(struct super_block *sb, struct fid *fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 					 int fh_len, int fh_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	struct nilfs_fid *fid = (struct nilfs_fid *)fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	if (fh_len < NILFS_FID_SIZE_NON_CONNECTABLE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	    (fh_type != FILEID_NILFS_WITH_PARENT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	     fh_type != FILEID_NILFS_WITHOUT_PARENT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	return nilfs_get_dentry(sb, fid->cno, fid->ino, fid->gen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static struct dentry *nilfs_fh_to_parent(struct super_block *sb, struct fid *fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 					 int fh_len, int fh_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	struct nilfs_fid *fid = (struct nilfs_fid *)fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	if (fh_len < NILFS_FID_SIZE_CONNECTABLE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	    fh_type != FILEID_NILFS_WITH_PARENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	return nilfs_get_dentry(sb, fid->cno, fid->parent_ino, fid->parent_gen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) static int nilfs_encode_fh(struct inode *inode, __u32 *fh, int *lenp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 			   struct inode *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	struct nilfs_fid *fid = (struct nilfs_fid *)fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	struct nilfs_root *root = NILFS_I(inode)->i_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	if (parent && *lenp < NILFS_FID_SIZE_CONNECTABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		*lenp = NILFS_FID_SIZE_CONNECTABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 		return FILEID_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	if (*lenp < NILFS_FID_SIZE_NON_CONNECTABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		*lenp = NILFS_FID_SIZE_NON_CONNECTABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		return FILEID_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	fid->cno = root->cno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	fid->ino = inode->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	fid->gen = inode->i_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	if (parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		fid->parent_ino = parent->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		fid->parent_gen = parent->i_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		type = FILEID_NILFS_WITH_PARENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		*lenp = NILFS_FID_SIZE_CONNECTABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		type = FILEID_NILFS_WITHOUT_PARENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		*lenp = NILFS_FID_SIZE_NON_CONNECTABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	return type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) const struct inode_operations nilfs_dir_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	.create		= nilfs_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	.lookup		= nilfs_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	.link		= nilfs_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	.unlink		= nilfs_unlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	.symlink	= nilfs_symlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	.mkdir		= nilfs_mkdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	.rmdir		= nilfs_rmdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	.mknod		= nilfs_mknod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	.rename		= nilfs_rename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	.setattr	= nilfs_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	.permission	= nilfs_permission,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	.fiemap		= nilfs_fiemap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) const struct inode_operations nilfs_special_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	.setattr	= nilfs_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	.permission	= nilfs_permission,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) const struct inode_operations nilfs_symlink_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	.get_link	= page_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	.permission     = nilfs_permission,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) const struct export_operations nilfs_export_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	.encode_fh = nilfs_encode_fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	.fh_to_dentry = nilfs_fh_to_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	.fh_to_parent = nilfs_fh_to_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	.get_parent = nilfs_get_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) };