1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * linux/fs/ext2/namei.c
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * Rewrite to pagecache. Almost all code had been changed, so blame me
61da177e4SLinus Torvalds * if the things go wrong. Please, send bug reports to
71da177e4SLinus Torvalds * viro@parcelfarce.linux.theplanet.co.uk
81da177e4SLinus Torvalds *
91da177e4SLinus Torvalds * Stuff here is basically a glue between the VFS and generic UNIXish
101da177e4SLinus Torvalds * filesystem that keeps everything in pagecache. All knowledge of the
111da177e4SLinus Torvalds * directory layout is in fs/ext2/dir.c - it turned out to be easily separatable
121da177e4SLinus Torvalds * and it's easier to debug that way. In principle we might want to
131da177e4SLinus Torvalds * generalize that a bit and turn it into a library. Or not.
141da177e4SLinus Torvalds *
151da177e4SLinus Torvalds * The only non-static object here is ext2_dir_inode_operations.
161da177e4SLinus Torvalds *
171da177e4SLinus Torvalds * TODO: get rid of kmap() use, add readahead.
181da177e4SLinus Torvalds *
191da177e4SLinus Torvalds * Copyright (C) 1992, 1993, 1994, 1995
201da177e4SLinus Torvalds * Remy Card (card@masi.ibp.fr)
211da177e4SLinus Torvalds * Laboratoire MASI - Institut Blaise Pascal
221da177e4SLinus Torvalds * Universite Pierre et Marie Curie (Paris VI)
231da177e4SLinus Torvalds *
241da177e4SLinus Torvalds * from
251da177e4SLinus Torvalds *
261da177e4SLinus Torvalds * linux/fs/minix/namei.c
271da177e4SLinus Torvalds *
281da177e4SLinus Torvalds * Copyright (C) 1991, 1992 Linus Torvalds
291da177e4SLinus Torvalds *
301da177e4SLinus Torvalds * Big-endian to little-endian byte-swapping/bitmaps by
311da177e4SLinus Torvalds * David S. Miller (davem@caip.rutgers.edu), 1995
321da177e4SLinus Torvalds */
331da177e4SLinus Torvalds
341da177e4SLinus Torvalds #include <linux/pagemap.h>
35907f4554SChristoph Hellwig #include <linux/quotaops.h>
361da177e4SLinus Torvalds #include "ext2.h"
371da177e4SLinus Torvalds #include "xattr.h"
381da177e4SLinus Torvalds #include "acl.h"
391da177e4SLinus Torvalds
ext2_add_nondir(struct dentry * dentry,struct inode * inode)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) {
441e2e547aSAl Viro d_instantiate_new(dentry, inode);
451da177e4SLinus Torvalds return 0;
461da177e4SLinus Torvalds }
47a513b035SAlexey Dobriyan inode_dec_link_count(inode);
482e5afe54SAl Viro discard_new_inode(inode);
491da177e4SLinus Torvalds return err;
501da177e4SLinus Torvalds }
511da177e4SLinus Torvalds
521da177e4SLinus Torvalds /*
531da177e4SLinus Torvalds * Methods themselves.
541da177e4SLinus Torvalds */
551da177e4SLinus Torvalds
ext2_lookup(struct inode * dir,struct dentry * dentry,unsigned int flags)5600cd8dd3SAl Viro static struct dentry *ext2_lookup(struct inode * dir, struct dentry *dentry, unsigned int flags)
571da177e4SLinus Torvalds {
581da177e4SLinus Torvalds struct inode * inode;
59a43850a3Szhangyi (F) ino_t ino;
60b4962091Szhangyi (F) int res;
611da177e4SLinus Torvalds
621da177e4SLinus Torvalds if (dentry->d_name.len > EXT2_NAME_LEN)
631da177e4SLinus Torvalds return ERR_PTR(-ENAMETOOLONG);
641da177e4SLinus Torvalds
65b4962091Szhangyi (F) res = ext2_inode_by_name(dir, &dentry->d_name, &ino);
66a43850a3Szhangyi (F) if (res) {
67a43850a3Szhangyi (F) if (res != -ENOENT)
68b4962091Szhangyi (F) return ERR_PTR(res);
691da177e4SLinus Torvalds inode = NULL;
70a43850a3Szhangyi (F) } else {
7152fcf703SDavid Howells inode = ext2_iget(dir->i_sb, ino);
72a9049376SAl Viro if (inode == ERR_PTR(-ESTALE)) {
734d6c13f8SBryan Donlan ext2_error(dir->i_sb, __func__,
744d6c13f8SBryan Donlan "deleted inode referenced: %lu",
75a4255e4cSHeiko Carstens (unsigned long) ino);
764d6c13f8SBryan Donlan return ERR_PTR(-EIO);
774d6c13f8SBryan Donlan }
784d6c13f8SBryan Donlan }
791da177e4SLinus Torvalds return d_splice_alias(inode, dentry);
801da177e4SLinus Torvalds }
811da177e4SLinus Torvalds
ext2_get_parent(struct dentry * child)821da177e4SLinus Torvalds struct dentry *ext2_get_parent(struct dentry *child)
831da177e4SLinus Torvalds {
84a43850a3Szhangyi (F) ino_t ino;
85b4962091Szhangyi (F) int res;
86b4962091Szhangyi (F)
8780e5d1ffSAl Viro res = ext2_inode_by_name(d_inode(child), &dotdot_name, &ino);
88b4962091Szhangyi (F) if (res)
89b4962091Szhangyi (F) return ERR_PTR(res);
90a43850a3Szhangyi (F)
91fc64005cSAl Viro return d_obtain_alias(ext2_iget(child->d_sb, ino));
921da177e4SLinus Torvalds }
931da177e4SLinus Torvalds
941da177e4SLinus Torvalds /*
951da177e4SLinus Torvalds * By the time this is called, we already have created
961da177e4SLinus Torvalds * the directory cache entry for the new file, but it
971da177e4SLinus Torvalds * is so far negative - it has no inode.
981da177e4SLinus Torvalds *
991da177e4SLinus Torvalds * If the create succeeds, we fill in the inode information
1001da177e4SLinus Torvalds * with d_instantiate().
1011da177e4SLinus Torvalds */
ext2_create(struct mnt_idmap * idmap,struct inode * dir,struct dentry * dentry,umode_t mode,bool excl)1026c960e68SChristian Brauner static int ext2_create (struct mnt_idmap * idmap,
103549c7297SChristian Brauner struct inode * dir, struct dentry * dentry,
104549c7297SChristian Brauner umode_t mode, bool excl)
1051da177e4SLinus Torvalds {
106907f4554SChristoph Hellwig struct inode *inode;
107c2edb305SJan Kara int err;
108907f4554SChristoph Hellwig
109c2edb305SJan Kara err = dquot_initialize(dir);
110c2edb305SJan Kara if (err)
111c2edb305SJan Kara return err;
112907f4554SChristoph Hellwig
1132a7dba39SEric Paris inode = ext2_new_inode(dir, mode, &dentry->d_name);
114907f4554SChristoph Hellwig if (IS_ERR(inode))
115907f4554SChristoph Hellwig return PTR_ERR(inode);
116907f4554SChristoph Hellwig
117fb094c90SDan Williams ext2_set_file_ops(inode);
1181da177e4SLinus Torvalds mark_inode_dirty(inode);
119907f4554SChristoph Hellwig return ext2_add_nondir(dentry, inode);
1201da177e4SLinus Torvalds }
1211da177e4SLinus Torvalds
ext2_tmpfile(struct mnt_idmap * idmap,struct inode * dir,struct file * file,umode_t mode)122011e2b71SChristian Brauner static int ext2_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
123863f144fSMiklos Szeredi struct file *file, umode_t mode)
12460545d0dSAl Viro {
12560545d0dSAl Viro struct inode *inode = ext2_new_inode(dir, mode, NULL);
12660545d0dSAl Viro if (IS_ERR(inode))
12760545d0dSAl Viro return PTR_ERR(inode);
12860545d0dSAl Viro
129fb094c90SDan Williams ext2_set_file_ops(inode);
13060545d0dSAl Viro mark_inode_dirty(inode);
131863f144fSMiklos Szeredi d_tmpfile(file, inode);
13260545d0dSAl Viro unlock_new_inode(inode);
133863f144fSMiklos Szeredi return finish_open_simple(file, 0);
13460545d0dSAl Viro }
13560545d0dSAl Viro
ext2_mknod(struct mnt_idmap * idmap,struct inode * dir,struct dentry * dentry,umode_t mode,dev_t rdev)1365ebb29beSChristian Brauner static int ext2_mknod (struct mnt_idmap * idmap, struct inode * dir,
137549c7297SChristian Brauner struct dentry *dentry, umode_t mode, dev_t rdev)
1381da177e4SLinus Torvalds {
1391da177e4SLinus Torvalds struct inode * inode;
1401da177e4SLinus Torvalds int err;
1411da177e4SLinus Torvalds
142c2edb305SJan Kara err = dquot_initialize(dir);
143c2edb305SJan Kara if (err)
144c2edb305SJan Kara return err;
145907f4554SChristoph Hellwig
1462a7dba39SEric Paris inode = ext2_new_inode (dir, mode, &dentry->d_name);
1471da177e4SLinus Torvalds err = PTR_ERR(inode);
1481da177e4SLinus Torvalds if (!IS_ERR(inode)) {
1491da177e4SLinus Torvalds init_special_inode(inode, inode->i_mode, rdev);
1501da177e4SLinus Torvalds inode->i_op = &ext2_special_inode_operations;
1511da177e4SLinus Torvalds mark_inode_dirty(inode);
1521da177e4SLinus Torvalds err = ext2_add_nondir(dentry, inode);
1531da177e4SLinus Torvalds }
1541da177e4SLinus Torvalds return err;
1551da177e4SLinus Torvalds }
1561da177e4SLinus Torvalds
ext2_symlink(struct mnt_idmap * idmap,struct inode * dir,struct dentry * dentry,const char * symname)1577a77db95SChristian Brauner static int ext2_symlink (struct mnt_idmap * idmap, struct inode * dir,
158549c7297SChristian Brauner struct dentry * dentry, const char * symname)
1591da177e4SLinus Torvalds {
1601da177e4SLinus Torvalds struct super_block * sb = dir->i_sb;
1611da177e4SLinus Torvalds int err = -ENAMETOOLONG;
1621da177e4SLinus Torvalds unsigned l = strlen(symname)+1;
1631da177e4SLinus Torvalds struct inode * inode;
1641da177e4SLinus Torvalds
1651da177e4SLinus Torvalds if (l > sb->s_blocksize)
1661da177e4SLinus Torvalds goto out;
1671da177e4SLinus Torvalds
168c2edb305SJan Kara err = dquot_initialize(dir);
169c2edb305SJan Kara if (err)
170c2edb305SJan Kara goto out;
171907f4554SChristoph Hellwig
1722a7dba39SEric Paris inode = ext2_new_inode (dir, S_IFLNK | S_IRWXUGO, &dentry->d_name);
1731da177e4SLinus Torvalds err = PTR_ERR(inode);
1741da177e4SLinus Torvalds if (IS_ERR(inode))
1751da177e4SLinus Torvalds goto out;
1761da177e4SLinus Torvalds
1771da177e4SLinus Torvalds if (l > sizeof (EXT2_I(inode)->i_data)) {
1781da177e4SLinus Torvalds /* slow symlink */
1791da177e4SLinus Torvalds inode->i_op = &ext2_symlink_inode_operations;
18021fc61c7SAl Viro inode_nohighmem(inode);
1811da177e4SLinus Torvalds inode->i_mapping->a_ops = &ext2_aops;
1821da177e4SLinus Torvalds err = page_symlink(inode, symname, l);
1831da177e4SLinus Torvalds if (err)
1841da177e4SLinus Torvalds goto out_fail;
1851da177e4SLinus Torvalds } else {
1861da177e4SLinus Torvalds /* fast symlink */
1871da177e4SLinus Torvalds inode->i_op = &ext2_fast_symlink_inode_operations;
188cbe0fa38SAl Viro inode->i_link = (char*)EXT2_I(inode)->i_data;
189cbe0fa38SAl Viro memcpy(inode->i_link, symname, l);
1901da177e4SLinus Torvalds inode->i_size = l-1;
1911da177e4SLinus Torvalds }
1921da177e4SLinus Torvalds mark_inode_dirty(inode);
1931da177e4SLinus Torvalds
1941da177e4SLinus Torvalds err = ext2_add_nondir(dentry, inode);
1951da177e4SLinus Torvalds out:
1961da177e4SLinus Torvalds return err;
1971da177e4SLinus Torvalds
1981da177e4SLinus Torvalds out_fail:
199a513b035SAlexey Dobriyan inode_dec_link_count(inode);
2002e5afe54SAl Viro discard_new_inode(inode);
2011da177e4SLinus Torvalds goto out;
2021da177e4SLinus Torvalds }
2031da177e4SLinus Torvalds
ext2_link(struct dentry * old_dentry,struct inode * dir,struct dentry * dentry)2041da177e4SLinus Torvalds static int ext2_link (struct dentry * old_dentry, struct inode * dir,
2051da177e4SLinus Torvalds struct dentry *dentry)
2061da177e4SLinus Torvalds {
2072b0143b5SDavid Howells struct inode *inode = d_inode(old_dentry);
20841080b5aSAl Viro int err;
2091da177e4SLinus Torvalds
210c2edb305SJan Kara err = dquot_initialize(dir);
211c2edb305SJan Kara if (err)
212c2edb305SJan Kara return err;
213907f4554SChristoph Hellwig
214*fc4eed64SJeff Layton inode_set_ctime_current(inode);
215a513b035SAlexey Dobriyan inode_inc_link_count(inode);
2167de9c6eeSAl Viro ihold(inode);
2171da177e4SLinus Torvalds
21841080b5aSAl Viro err = ext2_add_link(dentry, inode);
21941080b5aSAl Viro if (!err) {
22041080b5aSAl Viro d_instantiate(dentry, inode);
22141080b5aSAl Viro return 0;
22241080b5aSAl Viro }
22341080b5aSAl Viro inode_dec_link_count(inode);
22441080b5aSAl Viro iput(inode);
22541080b5aSAl Viro return err;
2261da177e4SLinus Torvalds }
2271da177e4SLinus Torvalds
ext2_mkdir(struct mnt_idmap * idmap,struct inode * dir,struct dentry * dentry,umode_t mode)228c54bd91eSChristian Brauner static int ext2_mkdir(struct mnt_idmap * idmap,
229549c7297SChristian Brauner struct inode * dir, struct dentry * dentry, umode_t mode)
2301da177e4SLinus Torvalds {
2311da177e4SLinus Torvalds struct inode * inode;
2328de52778SAl Viro int err;
2331da177e4SLinus Torvalds
234c2edb305SJan Kara err = dquot_initialize(dir);
235c2edb305SJan Kara if (err)
236c2edb305SJan Kara return err;
237907f4554SChristoph Hellwig
238a513b035SAlexey Dobriyan inode_inc_link_count(dir);
2391da177e4SLinus Torvalds
2402a7dba39SEric Paris inode = ext2_new_inode(dir, S_IFDIR | mode, &dentry->d_name);
2411da177e4SLinus Torvalds err = PTR_ERR(inode);
2421da177e4SLinus Torvalds if (IS_ERR(inode))
2431da177e4SLinus Torvalds goto out_dir;
2441da177e4SLinus Torvalds
2451da177e4SLinus Torvalds inode->i_op = &ext2_dir_inode_operations;
2461da177e4SLinus Torvalds inode->i_fop = &ext2_dir_operations;
2471da177e4SLinus Torvalds inode->i_mapping->a_ops = &ext2_aops;
2481da177e4SLinus Torvalds
249a513b035SAlexey Dobriyan inode_inc_link_count(inode);
2501da177e4SLinus Torvalds
2511da177e4SLinus Torvalds err = ext2_make_empty(inode, dir);
2521da177e4SLinus Torvalds if (err)
2531da177e4SLinus Torvalds goto out_fail;
2541da177e4SLinus Torvalds
2551da177e4SLinus Torvalds err = ext2_add_link(dentry, inode);
2561da177e4SLinus Torvalds if (err)
2571da177e4SLinus Torvalds goto out_fail;
2581da177e4SLinus Torvalds
2591e2e547aSAl Viro d_instantiate_new(dentry, inode);
2601da177e4SLinus Torvalds out:
2611da177e4SLinus Torvalds return err;
2621da177e4SLinus Torvalds
2631da177e4SLinus Torvalds out_fail:
264a513b035SAlexey Dobriyan inode_dec_link_count(inode);
265a513b035SAlexey Dobriyan inode_dec_link_count(inode);
2662e5afe54SAl Viro discard_new_inode(inode);
2671da177e4SLinus Torvalds out_dir:
268a513b035SAlexey Dobriyan inode_dec_link_count(dir);
2691da177e4SLinus Torvalds goto out;
2701da177e4SLinus Torvalds }
2711da177e4SLinus Torvalds
ext2_unlink(struct inode * dir,struct dentry * dentry)2721da177e4SLinus Torvalds static int ext2_unlink(struct inode *dir, struct dentry *dentry)
2731da177e4SLinus Torvalds {
2742b0143b5SDavid Howells struct inode *inode = d_inode(dentry);
2751da177e4SLinus Torvalds struct ext2_dir_entry_2 *de;
2761da177e4SLinus Torvalds struct page *page;
277c2edb305SJan Kara int err;
2781da177e4SLinus Torvalds
279c2edb305SJan Kara err = dquot_initialize(dir);
280c2edb305SJan Kara if (err)
281c2edb305SJan Kara goto out;
282907f4554SChristoph Hellwig
283b8b9e8b3SAl Viro de = ext2_find_entry(dir, &dentry->d_name, &page);
284b4962091Szhangyi (F) if (IS_ERR(de)) {
285b4962091Szhangyi (F) err = PTR_ERR(de);
286b4962091Szhangyi (F) goto out;
287b4962091Szhangyi (F) }
2881da177e4SLinus Torvalds
289dae42837SAl Viro err = ext2_delete_entry(de, page);
29091f646fbSAl Viro ext2_put_page(page, de);
2911da177e4SLinus Torvalds if (err)
2921da177e4SLinus Torvalds goto out;
2931da177e4SLinus Torvalds
294*fc4eed64SJeff Layton inode_set_ctime_to_ts(inode, inode_get_ctime(dir));
295a513b035SAlexey Dobriyan inode_dec_link_count(inode);
2961da177e4SLinus Torvalds err = 0;
2971da177e4SLinus Torvalds out:
2981da177e4SLinus Torvalds return err;
2991da177e4SLinus Torvalds }
3001da177e4SLinus Torvalds
ext2_rmdir(struct inode * dir,struct dentry * dentry)3011da177e4SLinus Torvalds static int ext2_rmdir (struct inode * dir, struct dentry *dentry)
3021da177e4SLinus Torvalds {
3032b0143b5SDavid Howells struct inode * inode = d_inode(dentry);
3041da177e4SLinus Torvalds int err = -ENOTEMPTY;
3051da177e4SLinus Torvalds
3061da177e4SLinus Torvalds if (ext2_empty_dir(inode)) {
3071da177e4SLinus Torvalds err = ext2_unlink(dir, dentry);
3081da177e4SLinus Torvalds if (!err) {
3091da177e4SLinus Torvalds inode->i_size = 0;
310a513b035SAlexey Dobriyan inode_dec_link_count(inode);
311a513b035SAlexey Dobriyan inode_dec_link_count(dir);
3121da177e4SLinus Torvalds }
3131da177e4SLinus Torvalds }
3141da177e4SLinus Torvalds return err;
3151da177e4SLinus Torvalds }
3161da177e4SLinus Torvalds
ext2_rename(struct mnt_idmap * idmap,struct inode * old_dir,struct dentry * old_dentry,struct inode * new_dir,struct dentry * new_dentry,unsigned int flags)317e18275aeSChristian Brauner static int ext2_rename (struct mnt_idmap * idmap,
318549c7297SChristian Brauner struct inode * old_dir, struct dentry * old_dentry,
319f03b8ad8SMiklos Szeredi struct inode * new_dir, struct dentry * new_dentry,
320f03b8ad8SMiklos Szeredi unsigned int flags)
3211da177e4SLinus Torvalds {
3222b0143b5SDavid Howells struct inode * old_inode = d_inode(old_dentry);
3232b0143b5SDavid Howells struct inode * new_inode = d_inode(new_dentry);
3241da177e4SLinus Torvalds struct page * dir_page = NULL;
3251da177e4SLinus Torvalds struct ext2_dir_entry_2 * dir_de = NULL;
3261da177e4SLinus Torvalds struct page * old_page;
3271da177e4SLinus Torvalds struct ext2_dir_entry_2 * old_de;
328c2edb305SJan Kara int err;
3291da177e4SLinus Torvalds
330f03b8ad8SMiklos Szeredi if (flags & ~RENAME_NOREPLACE)
331f03b8ad8SMiklos Szeredi return -EINVAL;
332f03b8ad8SMiklos Szeredi
333c2edb305SJan Kara err = dquot_initialize(old_dir);
334c2edb305SJan Kara if (err)
3358f1dca19SAl Viro return err;
336c2edb305SJan Kara
337c2edb305SJan Kara err = dquot_initialize(new_dir);
338c2edb305SJan Kara if (err)
3398f1dca19SAl Viro return err;
340907f4554SChristoph Hellwig
341b8b9e8b3SAl Viro old_de = ext2_find_entry(old_dir, &old_dentry->d_name, &old_page);
3428f1dca19SAl Viro if (IS_ERR(old_de))
3438f1dca19SAl Viro return PTR_ERR(old_de);
3441da177e4SLinus Torvalds
3451da177e4SLinus Torvalds if (S_ISDIR(old_inode->i_mode)) {
3461da177e4SLinus Torvalds err = -EIO;
347b8b9e8b3SAl Viro dir_de = ext2_dotdot(old_inode, &dir_page);
3481da177e4SLinus Torvalds if (!dir_de)
3491da177e4SLinus Torvalds goto out_old;
3501da177e4SLinus Torvalds }
3511da177e4SLinus Torvalds
3521da177e4SLinus Torvalds if (new_inode) {
3531da177e4SLinus Torvalds struct page *new_page;
3541da177e4SLinus Torvalds struct ext2_dir_entry_2 *new_de;
3551da177e4SLinus Torvalds
3561da177e4SLinus Torvalds err = -ENOTEMPTY;
3571da177e4SLinus Torvalds if (dir_de && !ext2_empty_dir (new_inode))
3581da177e4SLinus Torvalds goto out_dir;
3591da177e4SLinus Torvalds
360782b76d7SIra Weiny new_de = ext2_find_entry(new_dir, &new_dentry->d_name,
361b8b9e8b3SAl Viro &new_page);
362b4962091Szhangyi (F) if (IS_ERR(new_de)) {
363b4962091Szhangyi (F) err = PTR_ERR(new_de);
364b4962091Szhangyi (F) goto out_dir;
365b4962091Szhangyi (F) }
366dae42837SAl Viro err = ext2_set_link(new_dir, new_de, new_page, old_inode, true);
36791f646fbSAl Viro ext2_put_page(new_page, new_de);
3687a5fa171SChristoph Hellwig if (err)
3697a5fa171SChristoph Hellwig goto out_dir;
370*fc4eed64SJeff Layton inode_set_ctime_current(new_inode);
3711da177e4SLinus Torvalds if (dir_de)
3729a53c3a7SDave Hansen drop_nlink(new_inode);
373a513b035SAlexey Dobriyan inode_dec_link_count(new_inode);
3741da177e4SLinus Torvalds } else {
3751da177e4SLinus Torvalds err = ext2_add_link(new_dentry, old_inode);
376e8a80c6fSJosh Hunt if (err)
3771da177e4SLinus Torvalds goto out_dir;
3781da177e4SLinus Torvalds if (dir_de)
379a513b035SAlexey Dobriyan inode_inc_link_count(new_dir);
3801da177e4SLinus Torvalds }
3811da177e4SLinus Torvalds
3821da177e4SLinus Torvalds /*
3831da177e4SLinus Torvalds * Like most other Unix systems, set the ctime for inodes on a
3841da177e4SLinus Torvalds * rename.
3851da177e4SLinus Torvalds */
386*fc4eed64SJeff Layton inode_set_ctime_current(old_inode);
387e8a80c6fSJosh Hunt mark_inode_dirty(old_inode);
3881da177e4SLinus Torvalds
389dae42837SAl Viro err = ext2_delete_entry(old_de, old_page);
3908f1dca19SAl Viro if (!err && dir_de) {
3918f1dca19SAl Viro if (old_dir != new_dir)
3927a5fa171SChristoph Hellwig err = ext2_set_link(old_inode, dir_de, dir_page,
393dae42837SAl Viro new_dir, false);
394e2ebb123SIra Weiny
395a513b035SAlexey Dobriyan inode_dec_link_count(old_dir);
3961da177e4SLinus Torvalds }
3977a5fa171SChristoph Hellwig out_dir:
3987a5fa171SChristoph Hellwig if (dir_de)
39991f646fbSAl Viro ext2_put_page(dir_page, dir_de);
4008f1dca19SAl Viro out_old:
40191f646fbSAl Viro ext2_put_page(old_page, old_de);
4028f1dca19SAl Viro return err;
4031da177e4SLinus Torvalds }
4041da177e4SLinus Torvalds
405754661f1SArjan van de Ven const struct inode_operations ext2_dir_inode_operations = {
4061da177e4SLinus Torvalds .create = ext2_create,
4071da177e4SLinus Torvalds .lookup = ext2_lookup,
4081da177e4SLinus Torvalds .link = ext2_link,
4091da177e4SLinus Torvalds .unlink = ext2_unlink,
4101da177e4SLinus Torvalds .symlink = ext2_symlink,
4111da177e4SLinus Torvalds .mkdir = ext2_mkdir,
4121da177e4SLinus Torvalds .rmdir = ext2_rmdir,
4131da177e4SLinus Torvalds .mknod = ext2_mknod,
4141da177e4SLinus Torvalds .rename = ext2_rename,
4151da177e4SLinus Torvalds .listxattr = ext2_listxattr,
41693bc420eSyangerkun .getattr = ext2_getattr,
4171da177e4SLinus Torvalds .setattr = ext2_setattr,
418cac2f8b8SChristian Brauner .get_inode_acl = ext2_get_acl,
41964e178a7SChristoph Hellwig .set_acl = ext2_set_acl,
42060545d0dSAl Viro .tmpfile = ext2_tmpfile,
421aba405e3SMiklos Szeredi .fileattr_get = ext2_fileattr_get,
422aba405e3SMiklos Szeredi .fileattr_set = ext2_fileattr_set,
4231da177e4SLinus Torvalds };
4241da177e4SLinus Torvalds
425754661f1SArjan van de Ven const struct inode_operations ext2_special_inode_operations = {
4261da177e4SLinus Torvalds .listxattr = ext2_listxattr,
42793bc420eSyangerkun .getattr = ext2_getattr,
4281da177e4SLinus Torvalds .setattr = ext2_setattr,
429cac2f8b8SChristian Brauner .get_inode_acl = ext2_get_acl,
43064e178a7SChristoph Hellwig .set_acl = ext2_set_acl,
4311da177e4SLinus Torvalds };
432