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)  * linux/fs/ufs/namei.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Migration to usage of "page cache" on May 2006 by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Evgeniy Dushistov <dushistov@mail.ru> based on ext2 code base.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (C) 1998
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Daniel Pirkl <daniel.pirkl@email.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Charles University, Faculty of Mathematics and Physics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *  linux/fs/ext2/namei.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * Copyright (C) 1992, 1993, 1994, 1995
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * Remy Card (card@masi.ibp.fr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * Laboratoire MASI - Institut Blaise Pascal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * Universite Pierre et Marie Curie (Paris VI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *  from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *  linux/fs/minix/namei.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *  Copyright (C) 1991, 1992  Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *  Big-endian to little-endian byte-swapping/bitmaps by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *        David S. Miller (davem@caip.rutgers.edu), 1995
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include "ufs_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include "ufs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include "util.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static inline int ufs_add_nondir(struct dentry *dentry, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	int err = ufs_add_link(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		d_instantiate_new(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	inode_dec_link_count(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	discard_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	return err;
^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) static struct dentry *ufs_lookup(struct inode * dir, struct dentry *dentry, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct inode * inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	ino_t ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (dentry->d_name.len > UFS_MAXNAMLEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		return ERR_PTR(-ENAMETOOLONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	ino = ufs_inode_by_name(dir, &dentry->d_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		inode = ufs_iget(dir->i_sb, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	return d_splice_alias(inode, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * By the time this is called, we already have created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * the directory cache entry for the new file, but it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * is so far negative - it has no inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * If the create succeeds, we fill in the inode information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * with d_instantiate(). 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static int ufs_create (struct inode * dir, struct dentry * dentry, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		bool excl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	inode = ufs_new_inode(dir, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		return PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	inode->i_op = &ufs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	inode->i_fop = &ufs_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	inode->i_mapping->a_ops = &ufs_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	return ufs_add_nondir(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static int ufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (!old_valid_dev(rdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	inode = ufs_new_inode(dir, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (!IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		init_special_inode(inode, mode, rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		ufs_set_inode_dev(inode->i_sb, UFS_I(inode), rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		err = ufs_add_nondir(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int ufs_symlink (struct inode * dir, struct dentry * dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	const char * symname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct super_block * sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	unsigned l = strlen(symname)+1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct inode * inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (l > sb->s_blocksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return -ENAMETOOLONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	inode = ufs_new_inode(dir, S_IFLNK | S_IRWXUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (l > UFS_SB(sb)->s_uspi->s_maxsymlinklen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		/* slow symlink */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		inode->i_op = &page_symlink_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		inode_nohighmem(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		inode->i_mapping->a_ops = &ufs_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		err = page_symlink(inode, symname, l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		/* fast symlink */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		inode->i_op = &simple_symlink_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		inode->i_link = (char *)UFS_I(inode)->i_u1.i_symlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		memcpy(inode->i_link, symname, l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		inode->i_size = l-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	return ufs_add_nondir(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) out_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	inode_dec_link_count(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	discard_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static int ufs_link (struct dentry * old_dentry, struct inode * dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct inode *inode = d_inode(old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	inode_inc_link_count(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	ihold(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	error = ufs_add_link(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		inode_dec_link_count(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static int ufs_mkdir(struct inode * dir, struct dentry * dentry, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct inode * inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	inode_inc_link_count(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	inode = ufs_new_inode(dir, S_IFDIR|mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	err = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		goto out_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	inode->i_op = &ufs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	inode->i_fop = &ufs_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	inode->i_mapping->a_ops = &ufs_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	inode_inc_link_count(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	err = ufs_make_empty(inode, dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	err = ufs_add_link(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		goto out_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	d_instantiate_new(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) out_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	inode_dec_link_count(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	inode_dec_link_count(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	discard_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) out_dir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	inode_dec_link_count(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static int ufs_unlink(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct inode * inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	struct ufs_dir_entry *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	int err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	de = ufs_find_entry(dir, &dentry->d_name, &page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (!de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	err = ufs_delete_entry(dir, de, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	inode->i_ctime = dir->i_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	inode_dec_link_count(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static int ufs_rmdir (struct inode * dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	struct inode * inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	int err= -ENOTEMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (ufs_empty_dir (inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		err = ufs_unlink(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			inode->i_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			inode_dec_link_count(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			inode_dec_link_count(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static int ufs_rename(struct inode *old_dir, struct dentry *old_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		      struct inode *new_dir, struct dentry *new_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		      unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	struct inode *old_inode = d_inode(old_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	struct inode *new_inode = d_inode(new_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	struct page *dir_page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	struct ufs_dir_entry * dir_de = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	struct page *old_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	struct ufs_dir_entry *old_de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	int err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (flags & ~RENAME_NOREPLACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	old_de = ufs_find_entry(old_dir, &old_dentry->d_name, &old_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (!old_de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (S_ISDIR(old_inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		dir_de = ufs_dotdot(old_inode, &dir_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		if (!dir_de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			goto out_old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	if (new_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		struct page *new_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		struct ufs_dir_entry *new_de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		err = -ENOTEMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		if (dir_de && !ufs_empty_dir(new_inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			goto out_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		new_de = ufs_find_entry(new_dir, &new_dentry->d_name, &new_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		if (!new_de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			goto out_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		ufs_set_link(new_dir, new_de, new_page, old_inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		new_inode->i_ctime = current_time(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		if (dir_de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			drop_nlink(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		inode_dec_link_count(new_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		err = ufs_add_link(new_dentry, old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			goto out_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		if (dir_de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			inode_inc_link_count(new_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	 * Like most other Unix systems, set the ctime for inodes on a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)  	 * rename.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	old_inode->i_ctime = current_time(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	ufs_delete_entry(old_dir, old_de, old_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	mark_inode_dirty(old_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	if (dir_de) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		if (old_dir != new_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			ufs_set_link(old_inode, dir_de, dir_page, new_dir, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			kunmap(dir_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			put_page(dir_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		inode_dec_link_count(old_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) out_dir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (dir_de) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		kunmap(dir_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		put_page(dir_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) out_old:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	kunmap(old_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	put_page(old_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) const struct inode_operations ufs_dir_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	.create		= ufs_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	.lookup		= ufs_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	.link		= ufs_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	.unlink		= ufs_unlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	.symlink	= ufs_symlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	.mkdir		= ufs_mkdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	.rmdir		= ufs_rmdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	.mknod		= ufs_mknod,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	.rename		= ufs_rename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) };