3 @@ -1778,6 +1778,13 @@ extern int ext4_orphan_add(handle_t *, s
4 extern int ext4_orphan_del(handle_t *, struct inode *);
5 extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
6 __u32 start_minor_hash, __u32 *next_hash);
7 +extern struct inode *ext4_create_inode(handle_t *handle,
8 + struct inode * dir, int mode);
9 +extern int ext4_delete_entry(handle_t *handle, struct inode * dir,
10 + struct ext4_dir_entry_2 * de_del,
11 + struct buffer_head * bh);
12 +extern int ext4_add_dot_dotdot(handle_t *handle, struct inode *dir,
13 + struct inode *inode);
16 extern int ext4_group_add(struct super_block *sb,
23 +#include <linux/module.h>
25 #include <linux/pagemap.h>
26 #include <linux/jbd2.h>
27 @@ -1704,10 +1707,10 @@ cleanup:
28 * ext4_delete_entry deletes a directory entry by merging it with the
31 -static int ext4_delete_entry(handle_t *handle,
33 - struct ext4_dir_entry_2 *de_del,
34 - struct buffer_head *bh)
35 +int ext4_delete_entry(handle_t *handle,
37 + struct ext4_dir_entry_2 *de_del,
38 + struct buffer_head *bh)
40 struct ext4_dir_entry_2 *de, *pde;
41 unsigned int blocksize = dir->i_sb->s_blocksize;
42 @@ -1742,7 +1745,7 @@ static int ext4_delete_entry(handle_t *h
47 +EXPORT_SYMBOL(ext4_delete_entry);
49 * DIR_NLINK feature is set if 1) nlinks > EXT4_LINK_MAX or 2) nlinks == 2,
50 * since this indicates that nlinks count was previously 1.
51 @@ -1806,6 +1809,29 @@ static unsigned ext4_dentry_goal(struct
55 + /* Return locked inode, then the caller can modify the inode's states/flags
56 + * before others finding it. The caller should unlock the inode by itself. */
57 +struct inode *ext4_create_inode(handle_t *handle, struct inode *dir, int mode)
59 + struct inode *inode;
61 + inode = ext4_new_inode(handle, dir, mode, 0,
62 + EXT4_SB(dir->i_sb)->s_inode_goal);
63 + if (!IS_ERR(inode)) {
64 + if (S_ISCHR(mode) || S_ISBLK(mode) || S_ISFIFO(mode)) {
65 +#ifdef CONFIG_EXT4_FS_XATTR
66 + inode->i_op = &ext4_special_inode_operations;
69 + inode->i_op = &ext4_file_inode_operations;
70 + inode->i_fop = &ext4_file_operations;
71 + ext4_set_aops(inode);
76 +EXPORT_SYMBOL(ext4_create_inode);
79 * By the time this is called, we already have created
80 * the directory cache entry for the new file, but it
81 @@ -1882,44 +1908,32 @@ retry:
85 -static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
86 +/* Initialize @inode as a subdirectory of @dir, and add the
87 + * "." and ".." entries into the first directory block. */
88 +int ext4_add_dot_dotdot(handle_t *handle, struct inode * dir,
89 + struct inode *inode)
92 - struct inode *inode;
93 - struct buffer_head *dir_block = NULL;
94 - struct ext4_dir_entry_2 *de;
95 + struct buffer_head * dir_block;
96 + struct ext4_dir_entry_2 * de;
97 unsigned int blocksize = dir->i_sb->s_blocksize;
98 - int err, retries = 0;
101 - if (EXT4_DIR_LINK_MAX(dir))
105 - handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
106 - EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
107 - EXT4_MAXQUOTAS_INIT_BLOCKS(dir->i_sb));
109 return PTR_ERR(handle);
112 ext4_handle_sync(handle);
114 - inode = ext4_new_inode(handle, dir, S_IFDIR | mode,
115 - &dentry->d_name, 0);
116 - err = PTR_ERR(inode);
120 inode->i_op = &ext4_dir_inode_operations;
121 inode->i_fop = &ext4_dir_operations;
122 inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
123 dir_block = ext4_bread(handle, inode, 0, 1, &err);
125 - goto out_clear_inode;
127 BUFFER_TRACE(dir_block, "get_write_access");
128 err = ext4_journal_get_write_access(handle, dir_block);
130 - goto out_clear_inode;
132 de = (struct ext4_dir_entry_2 *) dir_block->b_data;
133 de->inode = cpu_to_le32(inode->i_ino);
135 @@ -1938,18 +1952,46 @@ retry:
136 BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
137 err = ext4_handle_dirty_metadata(handle, inode, dir_block);
139 - goto out_clear_inode;
141 err = ext4_mark_inode_dirty(handle, inode);
143 - err = ext4_add_entry(handle, dentry, inode);
146 - clear_nlink(inode);
147 - unlock_new_inode(inode);
148 - ext4_mark_inode_dirty(handle, inode);
154 +EXPORT_SYMBOL(ext4_add_dot_dotdot);
157 +static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
160 + struct inode *inode;
161 + int err, retries = 0;
163 + if (EXT4_DIR_LINK_MAX(dir))
167 + handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
168 + EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
169 + 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
170 + if (IS_ERR(handle))
171 + return PTR_ERR(handle);
173 + if (IS_DIRSYNC(dir))
174 + ext4_handle_sync(handle);
176 + inode = ext4_new_inode(handle, dir, S_IFDIR | mode, &dentry->d_name, 0);
177 + err = PTR_ERR(inode);
182 + err = ext4_add_dot_dotdot(handle, dir, inode);
184 + goto out_clear_inode;
186 + err = ext4_add_entry(handle, dentry, inode);
188 + goto out_clear_inode;
189 ext4_inc_count(handle, dir);
190 ext4_update_dx_flag(dir);
191 err = ext4_mark_inode_dirty(handle, dir);
192 @@ -1958,11 +2001,16 @@ out_clear_inode:
193 d_instantiate(dentry, inode);
194 unlock_new_inode(inode);
197 ext4_journal_stop(handle);
198 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
202 + clear_nlink(inode);
203 + unlock_new_inode(inode);
204 + ext4_mark_inode_dirty(handle, inode);