xref: /openbmc/linux/fs/ext2/namei.c (revision 7de9c6ee3ecffd99e1628e81a5ea5468f7581a1f)
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);
704d6c13f8SBryan Donlan 		if (unlikely(IS_ERR(inode))) {
714d6c13f8SBryan Donlan 			if (PTR_ERR(inode) == -ESTALE) {
724d6c13f8SBryan Donlan 				ext2_error(dir->i_sb, __func__,
734d6c13f8SBryan Donlan 						"deleted inode referenced: %lu",
74a4255e4cSHeiko Carstens 						(unsigned long) ino);
754d6c13f8SBryan Donlan 				return ERR_PTR(-EIO);
764d6c13f8SBryan Donlan 			} else {
7752fcf703SDavid Howells 				return ERR_CAST(inode);
781da177e4SLinus Torvalds 			}
794d6c13f8SBryan Donlan 		}
804d6c13f8SBryan Donlan 	}
811da177e4SLinus Torvalds 	return d_splice_alias(inode, dentry);
821da177e4SLinus Torvalds }
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds struct dentry *ext2_get_parent(struct dentry *child)
851da177e4SLinus Torvalds {
86a9885444SAl Viro 	struct qstr dotdot = {.name = "..", .len = 2};
87a9885444SAl Viro 	unsigned long ino = ext2_inode_by_name(child->d_inode, &dotdot);
881da177e4SLinus Torvalds 	if (!ino)
891da177e4SLinus Torvalds 		return ERR_PTR(-ENOENT);
9044003728SChristoph Hellwig 	return d_obtain_alias(ext2_iget(child->d_inode->i_sb, ino));
911da177e4SLinus Torvalds }
921da177e4SLinus Torvalds 
931da177e4SLinus Torvalds /*
941da177e4SLinus Torvalds  * By the time this is called, we already have created
951da177e4SLinus Torvalds  * the directory cache entry for the new file, but it
961da177e4SLinus Torvalds  * is so far negative - it has no inode.
971da177e4SLinus Torvalds  *
981da177e4SLinus Torvalds  * If the create succeeds, we fill in the inode information
991da177e4SLinus Torvalds  * with d_instantiate().
1001da177e4SLinus Torvalds  */
1011da177e4SLinus Torvalds static int ext2_create (struct inode * dir, struct dentry * dentry, int mode, struct nameidata *nd)
1021da177e4SLinus Torvalds {
103907f4554SChristoph Hellwig 	struct inode *inode;
104907f4554SChristoph Hellwig 
105871a2931SChristoph Hellwig 	dquot_initialize(dir);
106907f4554SChristoph Hellwig 
107907f4554SChristoph Hellwig 	inode = ext2_new_inode(dir, mode);
108907f4554SChristoph Hellwig 	if (IS_ERR(inode))
109907f4554SChristoph Hellwig 		return PTR_ERR(inode);
110907f4554SChristoph Hellwig 
1111da177e4SLinus Torvalds 	inode->i_op = &ext2_file_inode_operations;
1126d79125bSCarsten Otte 	if (ext2_use_xip(inode->i_sb)) {
1136d79125bSCarsten Otte 		inode->i_mapping->a_ops = &ext2_aops_xip;
1146d79125bSCarsten Otte 		inode->i_fop = &ext2_xip_file_operations;
1156d79125bSCarsten Otte 	} else if (test_opt(inode->i_sb, NOBH)) {
1161da177e4SLinus Torvalds 		inode->i_mapping->a_ops = &ext2_nobh_aops;
1176d79125bSCarsten Otte 		inode->i_fop = &ext2_file_operations;
1186d79125bSCarsten Otte 	} else {
1191da177e4SLinus Torvalds 		inode->i_mapping->a_ops = &ext2_aops;
1206d79125bSCarsten Otte 		inode->i_fop = &ext2_file_operations;
1216d79125bSCarsten Otte 	}
1221da177e4SLinus Torvalds 	mark_inode_dirty(inode);
123907f4554SChristoph Hellwig 	return ext2_add_nondir(dentry, inode);
1241da177e4SLinus Torvalds }
1251da177e4SLinus Torvalds 
1261da177e4SLinus Torvalds static int ext2_mknod (struct inode * dir, struct dentry *dentry, int mode, dev_t rdev)
1271da177e4SLinus Torvalds {
1281da177e4SLinus Torvalds 	struct inode * inode;
1291da177e4SLinus Torvalds 	int err;
1301da177e4SLinus Torvalds 
1311da177e4SLinus Torvalds 	if (!new_valid_dev(rdev))
1321da177e4SLinus Torvalds 		return -EINVAL;
1331da177e4SLinus Torvalds 
134871a2931SChristoph Hellwig 	dquot_initialize(dir);
135907f4554SChristoph Hellwig 
1361da177e4SLinus Torvalds 	inode = ext2_new_inode (dir, mode);
1371da177e4SLinus Torvalds 	err = PTR_ERR(inode);
1381da177e4SLinus Torvalds 	if (!IS_ERR(inode)) {
1391da177e4SLinus Torvalds 		init_special_inode(inode, inode->i_mode, rdev);
1401da177e4SLinus Torvalds #ifdef CONFIG_EXT2_FS_XATTR
1411da177e4SLinus Torvalds 		inode->i_op = &ext2_special_inode_operations;
1421da177e4SLinus Torvalds #endif
1431da177e4SLinus Torvalds 		mark_inode_dirty(inode);
1441da177e4SLinus Torvalds 		err = ext2_add_nondir(dentry, inode);
1451da177e4SLinus Torvalds 	}
1461da177e4SLinus Torvalds 	return err;
1471da177e4SLinus Torvalds }
1481da177e4SLinus Torvalds 
1491da177e4SLinus Torvalds static int ext2_symlink (struct inode * dir, struct dentry * dentry,
1501da177e4SLinus Torvalds 	const char * symname)
1511da177e4SLinus Torvalds {
1521da177e4SLinus Torvalds 	struct super_block * sb = dir->i_sb;
1531da177e4SLinus Torvalds 	int err = -ENAMETOOLONG;
1541da177e4SLinus Torvalds 	unsigned l = strlen(symname)+1;
1551da177e4SLinus Torvalds 	struct inode * inode;
1561da177e4SLinus Torvalds 
1571da177e4SLinus Torvalds 	if (l > sb->s_blocksize)
1581da177e4SLinus Torvalds 		goto out;
1591da177e4SLinus Torvalds 
160871a2931SChristoph Hellwig 	dquot_initialize(dir);
161907f4554SChristoph Hellwig 
1621da177e4SLinus Torvalds 	inode = ext2_new_inode (dir, S_IFLNK | S_IRWXUGO);
1631da177e4SLinus Torvalds 	err = PTR_ERR(inode);
1641da177e4SLinus Torvalds 	if (IS_ERR(inode))
1651da177e4SLinus Torvalds 		goto out;
1661da177e4SLinus Torvalds 
1671da177e4SLinus Torvalds 	if (l > sizeof (EXT2_I(inode)->i_data)) {
1681da177e4SLinus Torvalds 		/* slow symlink */
1691da177e4SLinus Torvalds 		inode->i_op = &ext2_symlink_inode_operations;
1701da177e4SLinus Torvalds 		if (test_opt(inode->i_sb, NOBH))
1711da177e4SLinus Torvalds 			inode->i_mapping->a_ops = &ext2_nobh_aops;
1721da177e4SLinus Torvalds 		else
1731da177e4SLinus Torvalds 			inode->i_mapping->a_ops = &ext2_aops;
1741da177e4SLinus Torvalds 		err = page_symlink(inode, symname, l);
1751da177e4SLinus Torvalds 		if (err)
1761da177e4SLinus Torvalds 			goto out_fail;
1771da177e4SLinus Torvalds 	} else {
1781da177e4SLinus Torvalds 		/* fast symlink */
1791da177e4SLinus Torvalds 		inode->i_op = &ext2_fast_symlink_inode_operations;
1801da177e4SLinus Torvalds 		memcpy((char*)(EXT2_I(inode)->i_data),symname,l);
1811da177e4SLinus Torvalds 		inode->i_size = l-1;
1821da177e4SLinus Torvalds 	}
1831da177e4SLinus Torvalds 	mark_inode_dirty(inode);
1841da177e4SLinus Torvalds 
1851da177e4SLinus Torvalds 	err = ext2_add_nondir(dentry, inode);
1861da177e4SLinus Torvalds out:
1871da177e4SLinus Torvalds 	return err;
1881da177e4SLinus Torvalds 
1891da177e4SLinus Torvalds out_fail:
190a513b035SAlexey Dobriyan 	inode_dec_link_count(inode);
19141080b5aSAl Viro 	unlock_new_inode(inode);
1921da177e4SLinus Torvalds 	iput (inode);
1931da177e4SLinus Torvalds 	goto out;
1941da177e4SLinus Torvalds }
1951da177e4SLinus Torvalds 
1961da177e4SLinus Torvalds static int ext2_link (struct dentry * old_dentry, struct inode * dir,
1971da177e4SLinus Torvalds 	struct dentry *dentry)
1981da177e4SLinus Torvalds {
1991da177e4SLinus Torvalds 	struct inode *inode = old_dentry->d_inode;
20041080b5aSAl Viro 	int err;
2011da177e4SLinus Torvalds 
2021da177e4SLinus Torvalds 	if (inode->i_nlink >= EXT2_LINK_MAX)
2031da177e4SLinus Torvalds 		return -EMLINK;
2041da177e4SLinus Torvalds 
205871a2931SChristoph Hellwig 	dquot_initialize(dir);
206907f4554SChristoph Hellwig 
2071da177e4SLinus Torvalds 	inode->i_ctime = CURRENT_TIME_SEC;
208a513b035SAlexey Dobriyan 	inode_inc_link_count(inode);
209*7de9c6eeSAl Viro 	ihold(inode);
2101da177e4SLinus Torvalds 
21141080b5aSAl Viro 	err = ext2_add_link(dentry, inode);
21241080b5aSAl Viro 	if (!err) {
21341080b5aSAl Viro 		d_instantiate(dentry, inode);
21441080b5aSAl Viro 		return 0;
21541080b5aSAl Viro 	}
21641080b5aSAl Viro 	inode_dec_link_count(inode);
21741080b5aSAl Viro 	iput(inode);
21841080b5aSAl Viro 	return err;
2191da177e4SLinus Torvalds }
2201da177e4SLinus Torvalds 
2211da177e4SLinus Torvalds static int ext2_mkdir(struct inode * dir, struct dentry * dentry, int mode)
2221da177e4SLinus Torvalds {
2231da177e4SLinus Torvalds 	struct inode * inode;
2241da177e4SLinus Torvalds 	int err = -EMLINK;
2251da177e4SLinus Torvalds 
2261da177e4SLinus Torvalds 	if (dir->i_nlink >= EXT2_LINK_MAX)
2271da177e4SLinus Torvalds 		goto out;
2281da177e4SLinus Torvalds 
229871a2931SChristoph Hellwig 	dquot_initialize(dir);
230907f4554SChristoph Hellwig 
231a513b035SAlexey Dobriyan 	inode_inc_link_count(dir);
2321da177e4SLinus Torvalds 
2331da177e4SLinus Torvalds 	inode = ext2_new_inode (dir, S_IFDIR | mode);
2341da177e4SLinus Torvalds 	err = PTR_ERR(inode);
2351da177e4SLinus Torvalds 	if (IS_ERR(inode))
2361da177e4SLinus Torvalds 		goto out_dir;
2371da177e4SLinus Torvalds 
2381da177e4SLinus Torvalds 	inode->i_op = &ext2_dir_inode_operations;
2391da177e4SLinus Torvalds 	inode->i_fop = &ext2_dir_operations;
2401da177e4SLinus Torvalds 	if (test_opt(inode->i_sb, NOBH))
2411da177e4SLinus Torvalds 		inode->i_mapping->a_ops = &ext2_nobh_aops;
2421da177e4SLinus Torvalds 	else
2431da177e4SLinus Torvalds 		inode->i_mapping->a_ops = &ext2_aops;
2441da177e4SLinus Torvalds 
245a513b035SAlexey Dobriyan 	inode_inc_link_count(inode);
2461da177e4SLinus Torvalds 
2471da177e4SLinus Torvalds 	err = ext2_make_empty(inode, dir);
2481da177e4SLinus Torvalds 	if (err)
2491da177e4SLinus Torvalds 		goto out_fail;
2501da177e4SLinus Torvalds 
2511da177e4SLinus Torvalds 	err = ext2_add_link(dentry, inode);
2521da177e4SLinus Torvalds 	if (err)
2531da177e4SLinus Torvalds 		goto out_fail;
2541da177e4SLinus Torvalds 
2551da177e4SLinus Torvalds 	d_instantiate(dentry, inode);
25641080b5aSAl Viro 	unlock_new_inode(inode);
2571da177e4SLinus Torvalds out:
2581da177e4SLinus Torvalds 	return err;
2591da177e4SLinus Torvalds 
2601da177e4SLinus Torvalds out_fail:
261a513b035SAlexey Dobriyan 	inode_dec_link_count(inode);
262a513b035SAlexey Dobriyan 	inode_dec_link_count(inode);
26341080b5aSAl Viro 	unlock_new_inode(inode);
2641da177e4SLinus Torvalds 	iput(inode);
2651da177e4SLinus Torvalds out_dir:
266a513b035SAlexey Dobriyan 	inode_dec_link_count(dir);
2671da177e4SLinus Torvalds 	goto out;
2681da177e4SLinus Torvalds }
2691da177e4SLinus Torvalds 
2701da177e4SLinus Torvalds static int ext2_unlink(struct inode * dir, struct dentry *dentry)
2711da177e4SLinus Torvalds {
2721da177e4SLinus Torvalds 	struct inode * inode = dentry->d_inode;
2731da177e4SLinus Torvalds 	struct ext2_dir_entry_2 * de;
2741da177e4SLinus Torvalds 	struct page * page;
2751da177e4SLinus Torvalds 	int err = -ENOENT;
2761da177e4SLinus Torvalds 
277871a2931SChristoph Hellwig 	dquot_initialize(dir);
278907f4554SChristoph Hellwig 
279a9885444SAl Viro 	de = ext2_find_entry (dir, &dentry->d_name, &page);
2801da177e4SLinus Torvalds 	if (!de)
2811da177e4SLinus Torvalds 		goto out;
2821da177e4SLinus Torvalds 
2831da177e4SLinus Torvalds 	err = ext2_delete_entry (de, page);
2841da177e4SLinus Torvalds 	if (err)
2851da177e4SLinus Torvalds 		goto out;
2861da177e4SLinus Torvalds 
2871da177e4SLinus Torvalds 	inode->i_ctime = dir->i_ctime;
288a513b035SAlexey Dobriyan 	inode_dec_link_count(inode);
2891da177e4SLinus Torvalds 	err = 0;
2901da177e4SLinus Torvalds out:
2911da177e4SLinus Torvalds 	return err;
2921da177e4SLinus Torvalds }
2931da177e4SLinus Torvalds 
2941da177e4SLinus Torvalds static int ext2_rmdir (struct inode * dir, struct dentry *dentry)
2951da177e4SLinus Torvalds {
2961da177e4SLinus Torvalds 	struct inode * inode = dentry->d_inode;
2971da177e4SLinus Torvalds 	int err = -ENOTEMPTY;
2981da177e4SLinus Torvalds 
2991da177e4SLinus Torvalds 	if (ext2_empty_dir(inode)) {
3001da177e4SLinus Torvalds 		err = ext2_unlink(dir, dentry);
3011da177e4SLinus Torvalds 		if (!err) {
3021da177e4SLinus Torvalds 			inode->i_size = 0;
303a513b035SAlexey Dobriyan 			inode_dec_link_count(inode);
304a513b035SAlexey Dobriyan 			inode_dec_link_count(dir);
3051da177e4SLinus Torvalds 		}
3061da177e4SLinus Torvalds 	}
3071da177e4SLinus Torvalds 	return err;
3081da177e4SLinus Torvalds }
3091da177e4SLinus Torvalds 
3101da177e4SLinus Torvalds static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
3111da177e4SLinus Torvalds 	struct inode * new_dir,	struct dentry * new_dentry )
3121da177e4SLinus Torvalds {
3131da177e4SLinus Torvalds 	struct inode * old_inode = old_dentry->d_inode;
3141da177e4SLinus Torvalds 	struct inode * new_inode = new_dentry->d_inode;
3151da177e4SLinus Torvalds 	struct page * dir_page = NULL;
3161da177e4SLinus Torvalds 	struct ext2_dir_entry_2 * dir_de = NULL;
3171da177e4SLinus Torvalds 	struct page * old_page;
3181da177e4SLinus Torvalds 	struct ext2_dir_entry_2 * old_de;
3191da177e4SLinus Torvalds 	int err = -ENOENT;
3201da177e4SLinus Torvalds 
321871a2931SChristoph Hellwig 	dquot_initialize(old_dir);
322871a2931SChristoph Hellwig 	dquot_initialize(new_dir);
323907f4554SChristoph Hellwig 
324a9885444SAl Viro 	old_de = ext2_find_entry (old_dir, &old_dentry->d_name, &old_page);
3251da177e4SLinus Torvalds 	if (!old_de)
3261da177e4SLinus Torvalds 		goto out;
3271da177e4SLinus Torvalds 
3281da177e4SLinus Torvalds 	if (S_ISDIR(old_inode->i_mode)) {
3291da177e4SLinus Torvalds 		err = -EIO;
3301da177e4SLinus Torvalds 		dir_de = ext2_dotdot(old_inode, &dir_page);
3311da177e4SLinus Torvalds 		if (!dir_de)
3321da177e4SLinus Torvalds 			goto out_old;
3331da177e4SLinus Torvalds 	}
3341da177e4SLinus Torvalds 
3351da177e4SLinus Torvalds 	if (new_inode) {
3361da177e4SLinus Torvalds 		struct page *new_page;
3371da177e4SLinus Torvalds 		struct ext2_dir_entry_2 *new_de;
3381da177e4SLinus Torvalds 
3391da177e4SLinus Torvalds 		err = -ENOTEMPTY;
3401da177e4SLinus Torvalds 		if (dir_de && !ext2_empty_dir (new_inode))
3411da177e4SLinus Torvalds 			goto out_dir;
3421da177e4SLinus Torvalds 
3431da177e4SLinus Torvalds 		err = -ENOENT;
344a9885444SAl Viro 		new_de = ext2_find_entry (new_dir, &new_dentry->d_name, &new_page);
3451da177e4SLinus Torvalds 		if (!new_de)
3461da177e4SLinus Torvalds 			goto out_dir;
347a513b035SAlexey Dobriyan 		inode_inc_link_count(old_inode);
34839fe7557SJan Kara 		ext2_set_link(new_dir, new_de, new_page, old_inode, 1);
3491da177e4SLinus Torvalds 		new_inode->i_ctime = CURRENT_TIME_SEC;
3501da177e4SLinus Torvalds 		if (dir_de)
3519a53c3a7SDave Hansen 			drop_nlink(new_inode);
352a513b035SAlexey Dobriyan 		inode_dec_link_count(new_inode);
3531da177e4SLinus Torvalds 	} else {
3541da177e4SLinus Torvalds 		if (dir_de) {
3551da177e4SLinus Torvalds 			err = -EMLINK;
3561da177e4SLinus Torvalds 			if (new_dir->i_nlink >= EXT2_LINK_MAX)
3571da177e4SLinus Torvalds 				goto out_dir;
3581da177e4SLinus Torvalds 		}
359a513b035SAlexey Dobriyan 		inode_inc_link_count(old_inode);
3601da177e4SLinus Torvalds 		err = ext2_add_link(new_dentry, old_inode);
3611da177e4SLinus Torvalds 		if (err) {
362a513b035SAlexey Dobriyan 			inode_dec_link_count(old_inode);
3631da177e4SLinus Torvalds 			goto out_dir;
3641da177e4SLinus Torvalds 		}
3651da177e4SLinus Torvalds 		if (dir_de)
366a513b035SAlexey Dobriyan 			inode_inc_link_count(new_dir);
3671da177e4SLinus Torvalds 	}
3681da177e4SLinus Torvalds 
3691da177e4SLinus Torvalds 	/*
3701da177e4SLinus Torvalds 	 * Like most other Unix systems, set the ctime for inodes on a
3711da177e4SLinus Torvalds  	 * rename.
372a513b035SAlexey Dobriyan 	 * inode_dec_link_count() will mark the inode dirty.
3731da177e4SLinus Torvalds 	 */
3741da177e4SLinus Torvalds 	old_inode->i_ctime = CURRENT_TIME_SEC;
3751da177e4SLinus Torvalds 
3761da177e4SLinus Torvalds 	ext2_delete_entry (old_de, old_page);
377a513b035SAlexey Dobriyan 	inode_dec_link_count(old_inode);
3781da177e4SLinus Torvalds 
3791da177e4SLinus Torvalds 	if (dir_de) {
38039fe7557SJan Kara 		if (old_dir != new_dir)
38139fe7557SJan Kara 			ext2_set_link(old_inode, dir_de, dir_page, new_dir, 0);
3829de6886eSNicolas Pitre 		else {
3839de6886eSNicolas Pitre 			kunmap(dir_page);
3849de6886eSNicolas Pitre 			page_cache_release(dir_page);
3859de6886eSNicolas Pitre 		}
386a513b035SAlexey Dobriyan 		inode_dec_link_count(old_dir);
3871da177e4SLinus Torvalds 	}
3881da177e4SLinus Torvalds 	return 0;
3891da177e4SLinus Torvalds 
3901da177e4SLinus Torvalds 
3911da177e4SLinus Torvalds out_dir:
3921da177e4SLinus Torvalds 	if (dir_de) {
3931da177e4SLinus Torvalds 		kunmap(dir_page);
3941da177e4SLinus Torvalds 		page_cache_release(dir_page);
3951da177e4SLinus Torvalds 	}
3961da177e4SLinus Torvalds out_old:
3971da177e4SLinus Torvalds 	kunmap(old_page);
3981da177e4SLinus Torvalds 	page_cache_release(old_page);
3991da177e4SLinus Torvalds out:
4001da177e4SLinus Torvalds 	return err;
4011da177e4SLinus Torvalds }
4021da177e4SLinus Torvalds 
403754661f1SArjan van de Ven const struct inode_operations ext2_dir_inode_operations = {
4041da177e4SLinus Torvalds 	.create		= ext2_create,
4051da177e4SLinus Torvalds 	.lookup		= ext2_lookup,
4061da177e4SLinus Torvalds 	.link		= ext2_link,
4071da177e4SLinus Torvalds 	.unlink		= ext2_unlink,
4081da177e4SLinus Torvalds 	.symlink	= ext2_symlink,
4091da177e4SLinus Torvalds 	.mkdir		= ext2_mkdir,
4101da177e4SLinus Torvalds 	.rmdir		= ext2_rmdir,
4111da177e4SLinus Torvalds 	.mknod		= ext2_mknod,
4121da177e4SLinus Torvalds 	.rename		= ext2_rename,
4131da177e4SLinus Torvalds #ifdef CONFIG_EXT2_FS_XATTR
4141da177e4SLinus Torvalds 	.setxattr	= generic_setxattr,
4151da177e4SLinus Torvalds 	.getxattr	= generic_getxattr,
4161da177e4SLinus Torvalds 	.listxattr	= ext2_listxattr,
4171da177e4SLinus Torvalds 	.removexattr	= generic_removexattr,
4181da177e4SLinus Torvalds #endif
4191da177e4SLinus Torvalds 	.setattr	= ext2_setattr,
4201d5ccd1cSLinus Torvalds 	.check_acl	= ext2_check_acl,
4211da177e4SLinus Torvalds };
4221da177e4SLinus Torvalds 
423754661f1SArjan van de Ven const struct inode_operations ext2_special_inode_operations = {
4241da177e4SLinus Torvalds #ifdef CONFIG_EXT2_FS_XATTR
4251da177e4SLinus Torvalds 	.setxattr	= generic_setxattr,
4261da177e4SLinus Torvalds 	.getxattr	= generic_getxattr,
4271da177e4SLinus Torvalds 	.listxattr	= ext2_listxattr,
4281da177e4SLinus Torvalds 	.removexattr	= generic_removexattr,
4291da177e4SLinus Torvalds #endif
4301da177e4SLinus Torvalds 	.setattr	= ext2_setattr,
4311d5ccd1cSLinus Torvalds 	.check_acl	= ext2_check_acl,
4321da177e4SLinus Torvalds };
433