xref: /openbmc/linux/fs/ext2/namei.c (revision 4e34e719e457f2e031297175410fc0bd4016a085)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * linux/fs/ext2/namei.c
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Rewrite to pagecache. Almost all code had been changed, so blame me
51da177e4SLinus Torvalds  * if the things go wrong. Please, send bug reports to
61da177e4SLinus Torvalds  * viro@parcelfarce.linux.theplanet.co.uk
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * Stuff here is basically a glue between the VFS and generic UNIXish
91da177e4SLinus Torvalds  * filesystem that keeps everything in pagecache. All knowledge of the
101da177e4SLinus Torvalds  * directory layout is in fs/ext2/dir.c - it turned out to be easily separatable
111da177e4SLinus Torvalds  * and it's easier to debug that way. In principle we might want to
121da177e4SLinus Torvalds  * generalize that a bit and turn it into a library. Or not.
131da177e4SLinus Torvalds  *
141da177e4SLinus Torvalds  * The only non-static object here is ext2_dir_inode_operations.
151da177e4SLinus Torvalds  *
161da177e4SLinus Torvalds  * TODO: get rid of kmap() use, add readahead.
171da177e4SLinus Torvalds  *
181da177e4SLinus Torvalds  * Copyright (C) 1992, 1993, 1994, 1995
191da177e4SLinus Torvalds  * Remy Card (card@masi.ibp.fr)
201da177e4SLinus Torvalds  * Laboratoire MASI - Institut Blaise Pascal
211da177e4SLinus Torvalds  * Universite Pierre et Marie Curie (Paris VI)
221da177e4SLinus Torvalds  *
231da177e4SLinus Torvalds  *  from
241da177e4SLinus Torvalds  *
251da177e4SLinus Torvalds  *  linux/fs/minix/namei.c
261da177e4SLinus Torvalds  *
271da177e4SLinus Torvalds  *  Copyright (C) 1991, 1992  Linus Torvalds
281da177e4SLinus Torvalds  *
291da177e4SLinus Torvalds  *  Big-endian to little-endian byte-swapping/bitmaps by
301da177e4SLinus Torvalds  *        David S. Miller (davem@caip.rutgers.edu), 1995
311da177e4SLinus Torvalds  */
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds #include <linux/pagemap.h>
34907f4554SChristoph Hellwig #include <linux/quotaops.h>
351da177e4SLinus Torvalds #include "ext2.h"
361da177e4SLinus Torvalds #include "xattr.h"
371da177e4SLinus Torvalds #include "acl.h"
386d79125bSCarsten Otte #include "xip.h"
391da177e4SLinus Torvalds 
401da177e4SLinus Torvalds static inline int ext2_add_nondir(struct dentry *dentry, struct inode *inode)
411da177e4SLinus Torvalds {
421da177e4SLinus Torvalds 	int err = ext2_add_link(dentry, inode);
431da177e4SLinus Torvalds 	if (!err) {
441da177e4SLinus Torvalds 		d_instantiate(dentry, inode);
4541080b5aSAl Viro 		unlock_new_inode(inode);
461da177e4SLinus Torvalds 		return 0;
471da177e4SLinus Torvalds 	}
48a513b035SAlexey Dobriyan 	inode_dec_link_count(inode);
4941080b5aSAl Viro 	unlock_new_inode(inode);
501da177e4SLinus Torvalds 	iput(inode);
511da177e4SLinus Torvalds 	return err;
521da177e4SLinus Torvalds }
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds /*
551da177e4SLinus Torvalds  * Methods themselves.
561da177e4SLinus Torvalds  */
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds static struct dentry *ext2_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
591da177e4SLinus Torvalds {
601da177e4SLinus Torvalds 	struct inode * inode;
611da177e4SLinus Torvalds 	ino_t ino;
621da177e4SLinus Torvalds 
631da177e4SLinus Torvalds 	if (dentry->d_name.len > EXT2_NAME_LEN)
641da177e4SLinus Torvalds 		return ERR_PTR(-ENAMETOOLONG);
651da177e4SLinus Torvalds 
66a9885444SAl Viro 	ino = ext2_inode_by_name(dir, &dentry->d_name);
671da177e4SLinus Torvalds 	inode = NULL;
681da177e4SLinus Torvalds 	if (ino) {
6952fcf703SDavid Howells 		inode = ext2_iget(dir->i_sb, ino);
70a9049376SAl Viro 		if (inode == ERR_PTR(-ESTALE)) {
714d6c13f8SBryan Donlan 			ext2_error(dir->i_sb, __func__,
724d6c13f8SBryan Donlan 					"deleted inode referenced: %lu",
73a4255e4cSHeiko Carstens 					(unsigned long) ino);
744d6c13f8SBryan Donlan 			return ERR_PTR(-EIO);
754d6c13f8SBryan Donlan 		}
764d6c13f8SBryan Donlan 	}
771da177e4SLinus Torvalds 	return d_splice_alias(inode, dentry);
781da177e4SLinus Torvalds }
791da177e4SLinus Torvalds 
801da177e4SLinus Torvalds struct dentry *ext2_get_parent(struct dentry *child)
811da177e4SLinus Torvalds {
82a9885444SAl Viro 	struct qstr dotdot = {.name = "..", .len = 2};
83a9885444SAl Viro 	unsigned long ino = ext2_inode_by_name(child->d_inode, &dotdot);
841da177e4SLinus Torvalds 	if (!ino)
851da177e4SLinus Torvalds 		return ERR_PTR(-ENOENT);
8644003728SChristoph Hellwig 	return d_obtain_alias(ext2_iget(child->d_inode->i_sb, ino));
871da177e4SLinus Torvalds }
881da177e4SLinus Torvalds 
891da177e4SLinus Torvalds /*
901da177e4SLinus Torvalds  * By the time this is called, we already have created
911da177e4SLinus Torvalds  * the directory cache entry for the new file, but it
921da177e4SLinus Torvalds  * is so far negative - it has no inode.
931da177e4SLinus Torvalds  *
941da177e4SLinus Torvalds  * If the create succeeds, we fill in the inode information
951da177e4SLinus Torvalds  * with d_instantiate().
961da177e4SLinus Torvalds  */
971da177e4SLinus Torvalds static int ext2_create (struct inode * dir, struct dentry * dentry, int mode, struct nameidata *nd)
981da177e4SLinus Torvalds {
99907f4554SChristoph Hellwig 	struct inode *inode;
100907f4554SChristoph Hellwig 
101871a2931SChristoph Hellwig 	dquot_initialize(dir);
102907f4554SChristoph Hellwig 
1032a7dba39SEric Paris 	inode = ext2_new_inode(dir, mode, &dentry->d_name);
104907f4554SChristoph Hellwig 	if (IS_ERR(inode))
105907f4554SChristoph Hellwig 		return PTR_ERR(inode);
106907f4554SChristoph Hellwig 
1071da177e4SLinus Torvalds 	inode->i_op = &ext2_file_inode_operations;
1086d79125bSCarsten Otte 	if (ext2_use_xip(inode->i_sb)) {
1096d79125bSCarsten Otte 		inode->i_mapping->a_ops = &ext2_aops_xip;
1106d79125bSCarsten Otte 		inode->i_fop = &ext2_xip_file_operations;
1116d79125bSCarsten Otte 	} else if (test_opt(inode->i_sb, NOBH)) {
1121da177e4SLinus Torvalds 		inode->i_mapping->a_ops = &ext2_nobh_aops;
1136d79125bSCarsten Otte 		inode->i_fop = &ext2_file_operations;
1146d79125bSCarsten Otte 	} else {
1151da177e4SLinus Torvalds 		inode->i_mapping->a_ops = &ext2_aops;
1166d79125bSCarsten Otte 		inode->i_fop = &ext2_file_operations;
1176d79125bSCarsten Otte 	}
1181da177e4SLinus Torvalds 	mark_inode_dirty(inode);
119907f4554SChristoph Hellwig 	return ext2_add_nondir(dentry, inode);
1201da177e4SLinus Torvalds }
1211da177e4SLinus Torvalds 
1221da177e4SLinus Torvalds static int ext2_mknod (struct inode * dir, struct dentry *dentry, int mode, dev_t rdev)
1231da177e4SLinus Torvalds {
1241da177e4SLinus Torvalds 	struct inode * inode;
1251da177e4SLinus Torvalds 	int err;
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds 	if (!new_valid_dev(rdev))
1281da177e4SLinus Torvalds 		return -EINVAL;
1291da177e4SLinus Torvalds 
130871a2931SChristoph Hellwig 	dquot_initialize(dir);
131907f4554SChristoph Hellwig 
1322a7dba39SEric Paris 	inode = ext2_new_inode (dir, mode, &dentry->d_name);
1331da177e4SLinus Torvalds 	err = PTR_ERR(inode);
1341da177e4SLinus Torvalds 	if (!IS_ERR(inode)) {
1351da177e4SLinus Torvalds 		init_special_inode(inode, inode->i_mode, rdev);
1361da177e4SLinus Torvalds #ifdef CONFIG_EXT2_FS_XATTR
1371da177e4SLinus Torvalds 		inode->i_op = &ext2_special_inode_operations;
1381da177e4SLinus Torvalds #endif
1391da177e4SLinus Torvalds 		mark_inode_dirty(inode);
1401da177e4SLinus Torvalds 		err = ext2_add_nondir(dentry, inode);
1411da177e4SLinus Torvalds 	}
1421da177e4SLinus Torvalds 	return err;
1431da177e4SLinus Torvalds }
1441da177e4SLinus Torvalds 
1451da177e4SLinus Torvalds static int ext2_symlink (struct inode * dir, struct dentry * dentry,
1461da177e4SLinus Torvalds 	const char * symname)
1471da177e4SLinus Torvalds {
1481da177e4SLinus Torvalds 	struct super_block * sb = dir->i_sb;
1491da177e4SLinus Torvalds 	int err = -ENAMETOOLONG;
1501da177e4SLinus Torvalds 	unsigned l = strlen(symname)+1;
1511da177e4SLinus Torvalds 	struct inode * inode;
1521da177e4SLinus Torvalds 
1531da177e4SLinus Torvalds 	if (l > sb->s_blocksize)
1541da177e4SLinus Torvalds 		goto out;
1551da177e4SLinus Torvalds 
156871a2931SChristoph Hellwig 	dquot_initialize(dir);
157907f4554SChristoph Hellwig 
1582a7dba39SEric Paris 	inode = ext2_new_inode (dir, S_IFLNK | S_IRWXUGO, &dentry->d_name);
1591da177e4SLinus Torvalds 	err = PTR_ERR(inode);
1601da177e4SLinus Torvalds 	if (IS_ERR(inode))
1611da177e4SLinus Torvalds 		goto out;
1621da177e4SLinus Torvalds 
1631da177e4SLinus Torvalds 	if (l > sizeof (EXT2_I(inode)->i_data)) {
1641da177e4SLinus Torvalds 		/* slow symlink */
1651da177e4SLinus Torvalds 		inode->i_op = &ext2_symlink_inode_operations;
1661da177e4SLinus Torvalds 		if (test_opt(inode->i_sb, NOBH))
1671da177e4SLinus Torvalds 			inode->i_mapping->a_ops = &ext2_nobh_aops;
1681da177e4SLinus Torvalds 		else
1691da177e4SLinus Torvalds 			inode->i_mapping->a_ops = &ext2_aops;
1701da177e4SLinus Torvalds 		err = page_symlink(inode, symname, l);
1711da177e4SLinus Torvalds 		if (err)
1721da177e4SLinus Torvalds 			goto out_fail;
1731da177e4SLinus Torvalds 	} else {
1741da177e4SLinus Torvalds 		/* fast symlink */
1751da177e4SLinus Torvalds 		inode->i_op = &ext2_fast_symlink_inode_operations;
1761da177e4SLinus Torvalds 		memcpy((char*)(EXT2_I(inode)->i_data),symname,l);
1771da177e4SLinus Torvalds 		inode->i_size = l-1;
1781da177e4SLinus Torvalds 	}
1791da177e4SLinus Torvalds 	mark_inode_dirty(inode);
1801da177e4SLinus Torvalds 
1811da177e4SLinus Torvalds 	err = ext2_add_nondir(dentry, inode);
1821da177e4SLinus Torvalds out:
1831da177e4SLinus Torvalds 	return err;
1841da177e4SLinus Torvalds 
1851da177e4SLinus Torvalds out_fail:
186a513b035SAlexey Dobriyan 	inode_dec_link_count(inode);
18741080b5aSAl Viro 	unlock_new_inode(inode);
1881da177e4SLinus Torvalds 	iput (inode);
1891da177e4SLinus Torvalds 	goto out;
1901da177e4SLinus Torvalds }
1911da177e4SLinus Torvalds 
1921da177e4SLinus Torvalds static int ext2_link (struct dentry * old_dentry, struct inode * dir,
1931da177e4SLinus Torvalds 	struct dentry *dentry)
1941da177e4SLinus Torvalds {
1951da177e4SLinus Torvalds 	struct inode *inode = old_dentry->d_inode;
19641080b5aSAl Viro 	int err;
1971da177e4SLinus Torvalds 
1981da177e4SLinus Torvalds 	if (inode->i_nlink >= EXT2_LINK_MAX)
1991da177e4SLinus Torvalds 		return -EMLINK;
2001da177e4SLinus Torvalds 
201871a2931SChristoph Hellwig 	dquot_initialize(dir);
202907f4554SChristoph Hellwig 
2031da177e4SLinus Torvalds 	inode->i_ctime = CURRENT_TIME_SEC;
204a513b035SAlexey Dobriyan 	inode_inc_link_count(inode);
2057de9c6eeSAl Viro 	ihold(inode);
2061da177e4SLinus Torvalds 
20741080b5aSAl Viro 	err = ext2_add_link(dentry, inode);
20841080b5aSAl Viro 	if (!err) {
20941080b5aSAl Viro 		d_instantiate(dentry, inode);
21041080b5aSAl Viro 		return 0;
21141080b5aSAl Viro 	}
21241080b5aSAl Viro 	inode_dec_link_count(inode);
21341080b5aSAl Viro 	iput(inode);
21441080b5aSAl Viro 	return err;
2151da177e4SLinus Torvalds }
2161da177e4SLinus Torvalds 
2171da177e4SLinus Torvalds static int ext2_mkdir(struct inode * dir, struct dentry * dentry, int mode)
2181da177e4SLinus Torvalds {
2191da177e4SLinus Torvalds 	struct inode * inode;
2201da177e4SLinus Torvalds 	int err = -EMLINK;
2211da177e4SLinus Torvalds 
2221da177e4SLinus Torvalds 	if (dir->i_nlink >= EXT2_LINK_MAX)
2231da177e4SLinus Torvalds 		goto out;
2241da177e4SLinus Torvalds 
225871a2931SChristoph Hellwig 	dquot_initialize(dir);
226907f4554SChristoph Hellwig 
227a513b035SAlexey Dobriyan 	inode_inc_link_count(dir);
2281da177e4SLinus Torvalds 
2292a7dba39SEric Paris 	inode = ext2_new_inode(dir, S_IFDIR | mode, &dentry->d_name);
2301da177e4SLinus Torvalds 	err = PTR_ERR(inode);
2311da177e4SLinus Torvalds 	if (IS_ERR(inode))
2321da177e4SLinus Torvalds 		goto out_dir;
2331da177e4SLinus Torvalds 
2341da177e4SLinus Torvalds 	inode->i_op = &ext2_dir_inode_operations;
2351da177e4SLinus Torvalds 	inode->i_fop = &ext2_dir_operations;
2361da177e4SLinus Torvalds 	if (test_opt(inode->i_sb, NOBH))
2371da177e4SLinus Torvalds 		inode->i_mapping->a_ops = &ext2_nobh_aops;
2381da177e4SLinus Torvalds 	else
2391da177e4SLinus Torvalds 		inode->i_mapping->a_ops = &ext2_aops;
2401da177e4SLinus Torvalds 
241a513b035SAlexey Dobriyan 	inode_inc_link_count(inode);
2421da177e4SLinus Torvalds 
2431da177e4SLinus Torvalds 	err = ext2_make_empty(inode, dir);
2441da177e4SLinus Torvalds 	if (err)
2451da177e4SLinus Torvalds 		goto out_fail;
2461da177e4SLinus Torvalds 
2471da177e4SLinus Torvalds 	err = ext2_add_link(dentry, inode);
2481da177e4SLinus Torvalds 	if (err)
2491da177e4SLinus Torvalds 		goto out_fail;
2501da177e4SLinus Torvalds 
2511da177e4SLinus Torvalds 	d_instantiate(dentry, inode);
25241080b5aSAl Viro 	unlock_new_inode(inode);
2531da177e4SLinus Torvalds out:
2541da177e4SLinus Torvalds 	return err;
2551da177e4SLinus Torvalds 
2561da177e4SLinus Torvalds out_fail:
257a513b035SAlexey Dobriyan 	inode_dec_link_count(inode);
258a513b035SAlexey Dobriyan 	inode_dec_link_count(inode);
25941080b5aSAl Viro 	unlock_new_inode(inode);
2601da177e4SLinus Torvalds 	iput(inode);
2611da177e4SLinus Torvalds out_dir:
262a513b035SAlexey Dobriyan 	inode_dec_link_count(dir);
2631da177e4SLinus Torvalds 	goto out;
2641da177e4SLinus Torvalds }
2651da177e4SLinus Torvalds 
2661da177e4SLinus Torvalds static int ext2_unlink(struct inode * dir, struct dentry *dentry)
2671da177e4SLinus Torvalds {
2681da177e4SLinus Torvalds 	struct inode * inode = dentry->d_inode;
2691da177e4SLinus Torvalds 	struct ext2_dir_entry_2 * de;
2701da177e4SLinus Torvalds 	struct page * page;
2711da177e4SLinus Torvalds 	int err = -ENOENT;
2721da177e4SLinus Torvalds 
273871a2931SChristoph Hellwig 	dquot_initialize(dir);
274907f4554SChristoph Hellwig 
275a9885444SAl Viro 	de = ext2_find_entry (dir, &dentry->d_name, &page);
2761da177e4SLinus Torvalds 	if (!de)
2771da177e4SLinus Torvalds 		goto out;
2781da177e4SLinus Torvalds 
2791da177e4SLinus Torvalds 	err = ext2_delete_entry (de, page);
2801da177e4SLinus Torvalds 	if (err)
2811da177e4SLinus Torvalds 		goto out;
2821da177e4SLinus Torvalds 
2831da177e4SLinus Torvalds 	inode->i_ctime = dir->i_ctime;
284a513b035SAlexey Dobriyan 	inode_dec_link_count(inode);
2851da177e4SLinus Torvalds 	err = 0;
2861da177e4SLinus Torvalds out:
2871da177e4SLinus Torvalds 	return err;
2881da177e4SLinus Torvalds }
2891da177e4SLinus Torvalds 
2901da177e4SLinus Torvalds static int ext2_rmdir (struct inode * dir, struct dentry *dentry)
2911da177e4SLinus Torvalds {
2921da177e4SLinus Torvalds 	struct inode * inode = dentry->d_inode;
2931da177e4SLinus Torvalds 	int err = -ENOTEMPTY;
2941da177e4SLinus Torvalds 
2951da177e4SLinus Torvalds 	if (ext2_empty_dir(inode)) {
2961da177e4SLinus Torvalds 		err = ext2_unlink(dir, dentry);
2971da177e4SLinus Torvalds 		if (!err) {
2981da177e4SLinus Torvalds 			inode->i_size = 0;
299a513b035SAlexey Dobriyan 			inode_dec_link_count(inode);
300a513b035SAlexey Dobriyan 			inode_dec_link_count(dir);
3011da177e4SLinus Torvalds 		}
3021da177e4SLinus Torvalds 	}
3031da177e4SLinus Torvalds 	return err;
3041da177e4SLinus Torvalds }
3051da177e4SLinus Torvalds 
3061da177e4SLinus Torvalds static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
3071da177e4SLinus Torvalds 	struct inode * new_dir,	struct dentry * new_dentry )
3081da177e4SLinus Torvalds {
3091da177e4SLinus Torvalds 	struct inode * old_inode = old_dentry->d_inode;
3101da177e4SLinus Torvalds 	struct inode * new_inode = new_dentry->d_inode;
3111da177e4SLinus Torvalds 	struct page * dir_page = NULL;
3121da177e4SLinus Torvalds 	struct ext2_dir_entry_2 * dir_de = NULL;
3131da177e4SLinus Torvalds 	struct page * old_page;
3141da177e4SLinus Torvalds 	struct ext2_dir_entry_2 * old_de;
3151da177e4SLinus Torvalds 	int err = -ENOENT;
3161da177e4SLinus Torvalds 
317871a2931SChristoph Hellwig 	dquot_initialize(old_dir);
318871a2931SChristoph Hellwig 	dquot_initialize(new_dir);
319907f4554SChristoph Hellwig 
320a9885444SAl Viro 	old_de = ext2_find_entry (old_dir, &old_dentry->d_name, &old_page);
3211da177e4SLinus Torvalds 	if (!old_de)
3221da177e4SLinus Torvalds 		goto out;
3231da177e4SLinus Torvalds 
3241da177e4SLinus Torvalds 	if (S_ISDIR(old_inode->i_mode)) {
3251da177e4SLinus Torvalds 		err = -EIO;
3261da177e4SLinus Torvalds 		dir_de = ext2_dotdot(old_inode, &dir_page);
3271da177e4SLinus Torvalds 		if (!dir_de)
3281da177e4SLinus Torvalds 			goto out_old;
3291da177e4SLinus Torvalds 	}
3301da177e4SLinus Torvalds 
3311da177e4SLinus Torvalds 	if (new_inode) {
3321da177e4SLinus Torvalds 		struct page *new_page;
3331da177e4SLinus Torvalds 		struct ext2_dir_entry_2 *new_de;
3341da177e4SLinus Torvalds 
3351da177e4SLinus Torvalds 		err = -ENOTEMPTY;
3361da177e4SLinus Torvalds 		if (dir_de && !ext2_empty_dir (new_inode))
3371da177e4SLinus Torvalds 			goto out_dir;
3381da177e4SLinus Torvalds 
3391da177e4SLinus Torvalds 		err = -ENOENT;
340a9885444SAl Viro 		new_de = ext2_find_entry (new_dir, &new_dentry->d_name, &new_page);
3411da177e4SLinus Torvalds 		if (!new_de)
3421da177e4SLinus Torvalds 			goto out_dir;
34339fe7557SJan Kara 		ext2_set_link(new_dir, new_de, new_page, old_inode, 1);
3441da177e4SLinus Torvalds 		new_inode->i_ctime = CURRENT_TIME_SEC;
3451da177e4SLinus Torvalds 		if (dir_de)
3469a53c3a7SDave Hansen 			drop_nlink(new_inode);
347a513b035SAlexey Dobriyan 		inode_dec_link_count(new_inode);
3481da177e4SLinus Torvalds 	} else {
3491da177e4SLinus Torvalds 		if (dir_de) {
3501da177e4SLinus Torvalds 			err = -EMLINK;
3511da177e4SLinus Torvalds 			if (new_dir->i_nlink >= EXT2_LINK_MAX)
3521da177e4SLinus Torvalds 				goto out_dir;
3531da177e4SLinus Torvalds 		}
3541da177e4SLinus Torvalds 		err = ext2_add_link(new_dentry, old_inode);
355e8a80c6fSJosh Hunt 		if (err)
3561da177e4SLinus Torvalds 			goto out_dir;
3571da177e4SLinus Torvalds 		if (dir_de)
358a513b035SAlexey Dobriyan 			inode_inc_link_count(new_dir);
3591da177e4SLinus Torvalds 	}
3601da177e4SLinus Torvalds 
3611da177e4SLinus Torvalds 	/*
3621da177e4SLinus Torvalds 	 * Like most other Unix systems, set the ctime for inodes on a
3631da177e4SLinus Torvalds  	 * rename.
3641da177e4SLinus Torvalds 	 */
3651da177e4SLinus Torvalds 	old_inode->i_ctime = CURRENT_TIME_SEC;
366e8a80c6fSJosh Hunt 	mark_inode_dirty(old_inode);
3671da177e4SLinus Torvalds 
3681da177e4SLinus Torvalds 	ext2_delete_entry (old_de, old_page);
3691da177e4SLinus Torvalds 
3701da177e4SLinus Torvalds 	if (dir_de) {
37139fe7557SJan Kara 		if (old_dir != new_dir)
37239fe7557SJan Kara 			ext2_set_link(old_inode, dir_de, dir_page, new_dir, 0);
3739de6886eSNicolas Pitre 		else {
3749de6886eSNicolas Pitre 			kunmap(dir_page);
3759de6886eSNicolas Pitre 			page_cache_release(dir_page);
3769de6886eSNicolas Pitre 		}
377a513b035SAlexey Dobriyan 		inode_dec_link_count(old_dir);
3781da177e4SLinus Torvalds 	}
3791da177e4SLinus Torvalds 	return 0;
3801da177e4SLinus Torvalds 
3811da177e4SLinus Torvalds 
3821da177e4SLinus Torvalds out_dir:
3831da177e4SLinus Torvalds 	if (dir_de) {
3841da177e4SLinus Torvalds 		kunmap(dir_page);
3851da177e4SLinus Torvalds 		page_cache_release(dir_page);
3861da177e4SLinus Torvalds 	}
3871da177e4SLinus Torvalds out_old:
3881da177e4SLinus Torvalds 	kunmap(old_page);
3891da177e4SLinus Torvalds 	page_cache_release(old_page);
3901da177e4SLinus Torvalds out:
3911da177e4SLinus Torvalds 	return err;
3921da177e4SLinus Torvalds }
3931da177e4SLinus Torvalds 
394754661f1SArjan van de Ven const struct inode_operations ext2_dir_inode_operations = {
3951da177e4SLinus Torvalds 	.create		= ext2_create,
3961da177e4SLinus Torvalds 	.lookup		= ext2_lookup,
3971da177e4SLinus Torvalds 	.link		= ext2_link,
3981da177e4SLinus Torvalds 	.unlink		= ext2_unlink,
3991da177e4SLinus Torvalds 	.symlink	= ext2_symlink,
4001da177e4SLinus Torvalds 	.mkdir		= ext2_mkdir,
4011da177e4SLinus Torvalds 	.rmdir		= ext2_rmdir,
4021da177e4SLinus Torvalds 	.mknod		= ext2_mknod,
4031da177e4SLinus Torvalds 	.rename		= ext2_rename,
4041da177e4SLinus Torvalds #ifdef CONFIG_EXT2_FS_XATTR
4051da177e4SLinus Torvalds 	.setxattr	= generic_setxattr,
4061da177e4SLinus Torvalds 	.getxattr	= generic_getxattr,
4071da177e4SLinus Torvalds 	.listxattr	= ext2_listxattr,
4081da177e4SLinus Torvalds 	.removexattr	= generic_removexattr,
4091da177e4SLinus Torvalds #endif
4101da177e4SLinus Torvalds 	.setattr	= ext2_setattr,
411*4e34e719SChristoph Hellwig 	.get_acl	= ext2_get_acl,
4121da177e4SLinus Torvalds };
4131da177e4SLinus Torvalds 
414754661f1SArjan van de Ven const struct inode_operations ext2_special_inode_operations = {
4151da177e4SLinus Torvalds #ifdef CONFIG_EXT2_FS_XATTR
4161da177e4SLinus Torvalds 	.setxattr	= generic_setxattr,
4171da177e4SLinus Torvalds 	.getxattr	= generic_getxattr,
4181da177e4SLinus Torvalds 	.listxattr	= ext2_listxattr,
4191da177e4SLinus Torvalds 	.removexattr	= generic_removexattr,
4201da177e4SLinus Torvalds #endif
4211da177e4SLinus Torvalds 	.setattr	= ext2_setattr,
422*4e34e719SChristoph Hellwig 	.get_acl	= ext2_get_acl,
4231da177e4SLinus Torvalds };
424