1 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
2 index 986e058..344ed3a 100644
5 @@ -1879,6 +1879,14 @@ extern int ext4_orphan_add(handle_t *, struct inode *);
6 extern int ext4_orphan_del(handle_t *, struct inode *);
7 extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
8 __u32 start_minor_hash, __u32 *next_hash);
9 +extern struct inode *ext4_create_inode(handle_t *handle,
10 + struct inode * dir, int mode,
12 +extern int ext4_delete_entry(handle_t *handle, struct inode * dir,
13 + struct ext4_dir_entry_2 * de_del,
14 + struct buffer_head * bh);
15 +extern int ext4_add_dot_dotdot(handle_t *handle, struct inode *dir,
16 + struct inode *inode);
19 extern int ext4_group_add(struct super_block *sb,
20 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
21 index cb049fe..2071f02 100644
28 +#include <linux/module.h>
30 #include <linux/pagemap.h>
31 #include <linux/jbd2.h>
32 @@ -1688,10 +1689,10 @@ cleanup:
33 * ext4_delete_entry deletes a directory entry by merging it with the
36 -static int ext4_delete_entry(handle_t *handle,
38 - struct ext4_dir_entry_2 *de_del,
39 - struct buffer_head *bh)
40 +int ext4_delete_entry(handle_t *handle,
42 + struct ext4_dir_entry_2 *de_del,
43 + struct buffer_head *bh)
45 struct ext4_dir_entry_2 *de, *pde;
46 unsigned int blocksize = dir->i_sb->s_blocksize;
47 @@ -1734,7 +1735,7 @@ static int ext4_delete_entry(handle_t *handle,
52 +EXPORT_SYMBOL(ext4_delete_entry);
54 * DIR_NLINK feature is set if 1) nlinks > EXT4_LINK_MAX or 2) nlinks == 2,
55 * since this indicates that nlinks count was previously 1.
56 @@ -1781,6 +1782,30 @@ static int ext4_add_nondir(handle_t *handle,
60 + /* Return locked inode, then the caller can modify the inode's states/flags
61 + * before others finding it. The caller should unlock the inode by itself. */
62 +struct inode *ext4_create_inode(handle_t *handle, struct inode *dir, int mode,
65 + struct inode *inode;
67 + inode = ext4_new_inode(handle, dir, mode, NULL,
68 + EXT4_SB(dir->i_sb)->s_inode_goal);
69 + if (!IS_ERR(inode)) {
70 + if (S_ISCHR(mode) || S_ISBLK(mode) || S_ISFIFO(mode)) {
71 +#ifdef CONFIG_EXT4_FS_XATTR
72 + inode->i_op = &ext4_special_inode_operations;
75 + inode->i_op = &ext4_file_inode_operations;
76 + inode->i_fop = &ext4_file_operations;
77 + ext4_set_aops(inode);
82 +EXPORT_SYMBOL(ext4_create_inode);
85 * By the time this is called, we already have created
86 * the directory cache entry for the new file, but it
87 @@ -1857,46 +1882,32 @@ retry:
91 -static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
92 +/* Initialize @inode as a subdirectory of @dir, and add the
93 + * "." and ".." entries into the first directory block. */
94 +int ext4_add_dot_dotdot(handle_t *handle, struct inode * dir,
95 + struct inode *inode)
98 - struct inode *inode;
99 - struct buffer_head *dir_block = NULL;
100 + struct buffer_head *dir_block;
101 struct ext4_dir_entry_2 *de;
102 unsigned int blocksize = dir->i_sb->s_blocksize;
103 - int err, retries = 0;
105 - if (EXT4_DIR_LINK_MAX(dir))
108 - dquot_initialize(dir);
112 - handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
113 - EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
114 - EXT4_MAXQUOTAS_INIT_BLOCKS(dir->i_sb));
116 return PTR_ERR(handle);
119 ext4_handle_sync(handle);
121 - inode = ext4_new_inode(handle, dir, S_IFDIR | mode,
122 - &dentry->d_name, 0);
123 - err = PTR_ERR(inode);
127 inode->i_op = &ext4_dir_inode_operations;
128 inode->i_fop = &ext4_dir_operations;
129 inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
130 dir_block = ext4_bread(handle, inode, 0, 1, &err);
132 - goto out_clear_inode;
134 BUFFER_TRACE(dir_block, "get_write_access");
135 err = ext4_journal_get_write_access(handle, dir_block);
137 - goto out_clear_inode;
139 de = (struct ext4_dir_entry_2 *) dir_block->b_data;
140 de->inode = cpu_to_le32(inode->i_ino);
142 @@ -1915,18 +1926,46 @@ retry:
143 BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
144 err = ext4_handle_dirty_metadata(handle, inode, dir_block);
146 - goto out_clear_inode;
148 err = ext4_mark_inode_dirty(handle, inode);
150 - err = ext4_add_entry(handle, dentry, inode);
153 - clear_nlink(inode);
154 - unlock_new_inode(inode);
155 - ext4_mark_inode_dirty(handle, inode);
161 +EXPORT_SYMBOL(ext4_add_dot_dotdot);
163 +static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
166 + struct inode *inode;
167 + int err, retries = 0;
169 + if (EXT4_DIR_LINK_MAX(dir))
172 + dquot_initialize(dir);
175 + handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
176 + EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
177 + EXT4_MAXQUOTAS_INIT_BLOCKS(dir->i_sb));
178 + if (IS_ERR(handle))
179 + return PTR_ERR(handle);
181 + if (IS_DIRSYNC(dir))
182 + ext4_handle_sync(handle);
184 + inode = ext4_new_inode(handle, dir, S_IFDIR | mode, &dentry->d_name, 0);
185 + err = PTR_ERR(inode);
190 + err = ext4_add_dot_dotdot(handle, dir, inode);
192 + goto out_clear_inode;
193 + err = ext4_add_entry(handle, dentry, inode);
195 + goto out_clear_inode;
196 ext4_inc_count(handle, dir);
197 ext4_update_dx_flag(dir);
198 err = ext4_mark_inode_dirty(handle, dir);
199 @@ -1935,11 +1974,16 @@ out_clear_inode:
200 d_instantiate(dentry, inode);
201 unlock_new_inode(inode);
204 ext4_journal_stop(handle);
205 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
209 + clear_nlink(inode);
210 + unlock_new_inode(inode);
211 + ext4_mark_inode_dirty(handle, inode);