aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/ext4/Makefile12
-rw-r--r--fs/ext4/acl.c188
-rw-r--r--fs/ext4/acl.h58
-rw-r--r--fs/ext4/balloc.c536
-rw-r--r--fs/ext4/bitmap.c10
-rw-r--r--fs/ext4/dir.c102
-rw-r--r--fs/ext4/file.c50
-rw-r--r--fs/ext4/fsync.c20
-rw-r--r--fs/ext4/hash.c10
-rw-r--r--fs/ext4/ialloc.c230
-rw-r--r--fs/ext4/inode.c1020
-rw-r--r--fs/ext4/ioctl.c156
-rw-r--r--fs/ext4/namei.c830
-rw-r--r--fs/ext4/namei.h4
-rw-r--r--fs/ext4/resize.c412
-rw-r--r--fs/ext4/super.c1114
-rw-r--r--fs/ext4/symlink.c24
-rw-r--r--fs/ext4/xattr.c560
-rw-r--r--fs/ext4/xattr.h110
-rw-r--r--fs/ext4/xattr_security.c28
-rw-r--r--fs/ext4/xattr_trusted.c24
-rw-r--r--fs/ext4/xattr_user.c24
-rw-r--r--include/linux/ext4_fs.h702
-rw-r--r--include/linux/ext4_fs_i.h56
-rw-r--r--include/linux/ext4_fs_sb.h14
-rw-r--r--include/linux/ext4_jbd.h160
26 files changed, 3227 insertions, 3227 deletions
diff --git a/fs/ext4/Makefile b/fs/ext4/Makefile
index 704cd44a40c..09c487893e4 100644
--- a/fs/ext4/Makefile
+++ b/fs/ext4/Makefile
@@ -1,12 +1,12 @@
1# 1#
2# Makefile for the linux ext3-filesystem routines. 2# Makefile for the linux ext4-filesystem routines.
3# 3#
4 4
5obj-$(CONFIG_EXT3_FS) += ext3.o 5obj-$(CONFIG_EXT4DEV_FS) += ext4dev.o
6 6
7ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \ 7ext4dev-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
8 ioctl.o namei.o super.o symlink.o hash.o resize.o 8 ioctl.o namei.o super.o symlink.o hash.o resize.o
9 9
10ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o 10ext4dev-$(CONFIG_EXT4DEV_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
11ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o 11ext4dev-$(CONFIG_EXT4DEV_FS_POSIX_ACL) += acl.o
12ext3-$(CONFIG_EXT3_FS_SECURITY) += xattr_security.o 12ext4dev-$(CONFIG_EXT4DEV_FS_SECURITY) += xattr_security.o
diff --git a/fs/ext4/acl.c b/fs/ext4/acl.c
index 1e5038d9a01..d143489aeb4 100644
--- a/fs/ext4/acl.c
+++ b/fs/ext4/acl.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/acl.c 2 * linux/fs/ext4/acl.c
3 * 3 *
4 * Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de> 4 * Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de>
5 */ 5 */
@@ -9,8 +9,8 @@
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/capability.h> 10#include <linux/capability.h>
11#include <linux/fs.h> 11#include <linux/fs.h>
12#include <linux/ext3_jbd.h> 12#include <linux/ext4_jbd.h>
13#include <linux/ext3_fs.h> 13#include <linux/ext4_fs.h>
14#include "xattr.h" 14#include "xattr.h"
15#include "acl.h" 15#include "acl.h"
16 16
@@ -18,7 +18,7 @@
18 * Convert from filesystem to in-memory representation. 18 * Convert from filesystem to in-memory representation.
19 */ 19 */
20static struct posix_acl * 20static struct posix_acl *
21ext3_acl_from_disk(const void *value, size_t size) 21ext4_acl_from_disk(const void *value, size_t size)
22{ 22{
23 const char *end = (char *)value + size; 23 const char *end = (char *)value + size;
24 int n, count; 24 int n, count;
@@ -26,13 +26,13 @@ ext3_acl_from_disk(const void *value, size_t size)
26 26
27 if (!value) 27 if (!value)
28 return NULL; 28 return NULL;
29 if (size < sizeof(ext3_acl_header)) 29 if (size < sizeof(ext4_acl_header))
30 return ERR_PTR(-EINVAL); 30 return ERR_PTR(-EINVAL);
31 if (((ext3_acl_header *)value)->a_version != 31 if (((ext4_acl_header *)value)->a_version !=
32 cpu_to_le32(EXT3_ACL_VERSION)) 32 cpu_to_le32(EXT4_ACL_VERSION))
33 return ERR_PTR(-EINVAL); 33 return ERR_PTR(-EINVAL);
34 value = (char *)value + sizeof(ext3_acl_header); 34 value = (char *)value + sizeof(ext4_acl_header);
35 count = ext3_acl_count(size); 35 count = ext4_acl_count(size);
36 if (count < 0) 36 if (count < 0)
37 return ERR_PTR(-EINVAL); 37 return ERR_PTR(-EINVAL);
38 if (count == 0) 38 if (count == 0)
@@ -41,9 +41,9 @@ ext3_acl_from_disk(const void *value, size_t size)
41 if (!acl) 41 if (!acl)
42 return ERR_PTR(-ENOMEM); 42 return ERR_PTR(-ENOMEM);
43 for (n=0; n < count; n++) { 43 for (n=0; n < count; n++) {
44 ext3_acl_entry *entry = 44 ext4_acl_entry *entry =
45 (ext3_acl_entry *)value; 45 (ext4_acl_entry *)value;
46 if ((char *)value + sizeof(ext3_acl_entry_short) > end) 46 if ((char *)value + sizeof(ext4_acl_entry_short) > end)
47 goto fail; 47 goto fail;
48 acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag); 48 acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag);
49 acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm); 49 acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm);
@@ -53,13 +53,13 @@ ext3_acl_from_disk(const void *value, size_t size)
53 case ACL_MASK: 53 case ACL_MASK:
54 case ACL_OTHER: 54 case ACL_OTHER:
55 value = (char *)value + 55 value = (char *)value +
56 sizeof(ext3_acl_entry_short); 56 sizeof(ext4_acl_entry_short);
57 acl->a_entries[n].e_id = ACL_UNDEFINED_ID; 57 acl->a_entries[n].e_id = ACL_UNDEFINED_ID;
58 break; 58 break;
59 59
60 case ACL_USER: 60 case ACL_USER:
61 case ACL_GROUP: 61 case ACL_GROUP:
62 value = (char *)value + sizeof(ext3_acl_entry); 62 value = (char *)value + sizeof(ext4_acl_entry);
63 if ((char *)value > end) 63 if ((char *)value > end)
64 goto fail; 64 goto fail;
65 acl->a_entries[n].e_id = 65 acl->a_entries[n].e_id =
@@ -83,21 +83,21 @@ fail:
83 * Convert from in-memory to filesystem representation. 83 * Convert from in-memory to filesystem representation.
84 */ 84 */
85static void * 85static void *
86ext3_acl_to_disk(const struct posix_acl *acl, size_t *size) 86ext4_acl_to_disk(const struct posix_acl *acl, size_t *size)
87{ 87{
88 ext3_acl_header *ext_acl; 88 ext4_acl_header *ext_acl;
89 char *e; 89 char *e;
90 size_t n; 90 size_t n;
91 91
92 *size = ext3_acl_size(acl->a_count); 92 *size = ext4_acl_size(acl->a_count);
93 ext_acl = kmalloc(sizeof(ext3_acl_header) + acl->a_count * 93 ext_acl = kmalloc(sizeof(ext4_acl_header) + acl->a_count *
94 sizeof(ext3_acl_entry), GFP_KERNEL); 94 sizeof(ext4_acl_entry), GFP_KERNEL);
95 if (!ext_acl) 95 if (!ext_acl)
96 return ERR_PTR(-ENOMEM); 96 return ERR_PTR(-ENOMEM);
97 ext_acl->a_version = cpu_to_le32(EXT3_ACL_VERSION); 97 ext_acl->a_version = cpu_to_le32(EXT4_ACL_VERSION);
98 e = (char *)ext_acl + sizeof(ext3_acl_header); 98 e = (char *)ext_acl + sizeof(ext4_acl_header);
99 for (n=0; n < acl->a_count; n++) { 99 for (n=0; n < acl->a_count; n++) {
100 ext3_acl_entry *entry = (ext3_acl_entry *)e; 100 ext4_acl_entry *entry = (ext4_acl_entry *)e;
101 entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag); 101 entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag);
102 entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm); 102 entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm);
103 switch(acl->a_entries[n].e_tag) { 103 switch(acl->a_entries[n].e_tag) {
@@ -105,14 +105,14 @@ ext3_acl_to_disk(const struct posix_acl *acl, size_t *size)
105 case ACL_GROUP: 105 case ACL_GROUP:
106 entry->e_id = 106 entry->e_id =
107 cpu_to_le32(acl->a_entries[n].e_id); 107 cpu_to_le32(acl->a_entries[n].e_id);
108 e += sizeof(ext3_acl_entry); 108 e += sizeof(ext4_acl_entry);
109 break; 109 break;
110 110
111 case ACL_USER_OBJ: 111 case ACL_USER_OBJ:
112 case ACL_GROUP_OBJ: 112 case ACL_GROUP_OBJ:
113 case ACL_MASK: 113 case ACL_MASK:
114 case ACL_OTHER: 114 case ACL_OTHER:
115 e += sizeof(ext3_acl_entry_short); 115 e += sizeof(ext4_acl_entry_short);
116 break; 116 break;
117 117
118 default: 118 default:
@@ -127,12 +127,12 @@ fail:
127} 127}
128 128
129static inline struct posix_acl * 129static inline struct posix_acl *
130ext3_iget_acl(struct inode *inode, struct posix_acl **i_acl) 130ext4_iget_acl(struct inode *inode, struct posix_acl **i_acl)
131{ 131{
132 struct posix_acl *acl = EXT3_ACL_NOT_CACHED; 132 struct posix_acl *acl = EXT4_ACL_NOT_CACHED;
133 133
134 spin_lock(&inode->i_lock); 134 spin_lock(&inode->i_lock);
135 if (*i_acl != EXT3_ACL_NOT_CACHED) 135 if (*i_acl != EXT4_ACL_NOT_CACHED)
136 acl = posix_acl_dup(*i_acl); 136 acl = posix_acl_dup(*i_acl);
137 spin_unlock(&inode->i_lock); 137 spin_unlock(&inode->i_lock);
138 138
@@ -140,11 +140,11 @@ ext3_iget_acl(struct inode *inode, struct posix_acl **i_acl)
140} 140}
141 141
142static inline void 142static inline void
143ext3_iset_acl(struct inode *inode, struct posix_acl **i_acl, 143ext4_iset_acl(struct inode *inode, struct posix_acl **i_acl,
144 struct posix_acl *acl) 144 struct posix_acl *acl)
145{ 145{
146 spin_lock(&inode->i_lock); 146 spin_lock(&inode->i_lock);
147 if (*i_acl != EXT3_ACL_NOT_CACHED) 147 if (*i_acl != EXT4_ACL_NOT_CACHED)
148 posix_acl_release(*i_acl); 148 posix_acl_release(*i_acl);
149 *i_acl = posix_acl_dup(acl); 149 *i_acl = posix_acl_dup(acl);
150 spin_unlock(&inode->i_lock); 150 spin_unlock(&inode->i_lock);
@@ -156,9 +156,9 @@ ext3_iset_acl(struct inode *inode, struct posix_acl **i_acl,
156 * inode->i_mutex: don't care 156 * inode->i_mutex: don't care
157 */ 157 */
158static struct posix_acl * 158static struct posix_acl *
159ext3_get_acl(struct inode *inode, int type) 159ext4_get_acl(struct inode *inode, int type)
160{ 160{
161 struct ext3_inode_info *ei = EXT3_I(inode); 161 struct ext4_inode_info *ei = EXT4_I(inode);
162 int name_index; 162 int name_index;
163 char *value = NULL; 163 char *value = NULL;
164 struct posix_acl *acl; 164 struct posix_acl *acl;
@@ -169,31 +169,31 @@ ext3_get_acl(struct inode *inode, int type)
169 169
170 switch(type) { 170 switch(type) {
171 case ACL_TYPE_ACCESS: 171 case ACL_TYPE_ACCESS:
172 acl = ext3_iget_acl(inode, &ei->i_acl); 172 acl = ext4_iget_acl(inode, &ei->i_acl);
173 if (acl != EXT3_ACL_NOT_CACHED) 173 if (acl != EXT4_ACL_NOT_CACHED)
174 return acl; 174 return acl;
175 name_index = EXT3_XATTR_INDEX_POSIX_ACL_ACCESS; 175 name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS;
176 break; 176 break;
177 177
178 case ACL_TYPE_DEFAULT: 178 case ACL_TYPE_DEFAULT:
179 acl = ext3_iget_acl(inode, &ei->i_default_acl); 179 acl = ext4_iget_acl(inode, &ei->i_default_acl);
180 if (acl != EXT3_ACL_NOT_CACHED) 180 if (acl != EXT4_ACL_NOT_CACHED)
181 return acl; 181 return acl;
182 name_index = EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT; 182 name_index = EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT;
183 break; 183 break;
184 184
185 default: 185 default:
186 return ERR_PTR(-EINVAL); 186 return ERR_PTR(-EINVAL);
187 } 187 }
188 retval = ext3_xattr_get(inode, name_index, "", NULL, 0); 188 retval = ext4_xattr_get(inode, name_index, "", NULL, 0);
189 if (retval > 0) { 189 if (retval > 0) {
190 value = kmalloc(retval, GFP_KERNEL); 190 value = kmalloc(retval, GFP_KERNEL);
191 if (!value) 191 if (!value)
192 return ERR_PTR(-ENOMEM); 192 return ERR_PTR(-ENOMEM);
193 retval = ext3_xattr_get(inode, name_index, "", value, retval); 193 retval = ext4_xattr_get(inode, name_index, "", value, retval);
194 } 194 }
195 if (retval > 0) 195 if (retval > 0)
196 acl = ext3_acl_from_disk(value, retval); 196 acl = ext4_acl_from_disk(value, retval);
197 else if (retval == -ENODATA || retval == -ENOSYS) 197 else if (retval == -ENODATA || retval == -ENOSYS)
198 acl = NULL; 198 acl = NULL;
199 else 199 else
@@ -203,11 +203,11 @@ ext3_get_acl(struct inode *inode, int type)
203 if (!IS_ERR(acl)) { 203 if (!IS_ERR(acl)) {
204 switch(type) { 204 switch(type) {
205 case ACL_TYPE_ACCESS: 205 case ACL_TYPE_ACCESS:
206 ext3_iset_acl(inode, &ei->i_acl, acl); 206 ext4_iset_acl(inode, &ei->i_acl, acl);
207 break; 207 break;
208 208
209 case ACL_TYPE_DEFAULT: 209 case ACL_TYPE_DEFAULT:
210 ext3_iset_acl(inode, &ei->i_default_acl, acl); 210 ext4_iset_acl(inode, &ei->i_default_acl, acl);
211 break; 211 break;
212 } 212 }
213 } 213 }
@@ -217,13 +217,13 @@ ext3_get_acl(struct inode *inode, int type)
217/* 217/*
218 * Set the access or default ACL of an inode. 218 * Set the access or default ACL of an inode.
219 * 219 *
220 * inode->i_mutex: down unless called from ext3_new_inode 220 * inode->i_mutex: down unless called from ext4_new_inode
221 */ 221 */
222static int 222static int
223ext3_set_acl(handle_t *handle, struct inode *inode, int type, 223ext4_set_acl(handle_t *handle, struct inode *inode, int type,
224 struct posix_acl *acl) 224 struct posix_acl *acl)
225{ 225{
226 struct ext3_inode_info *ei = EXT3_I(inode); 226 struct ext4_inode_info *ei = EXT4_I(inode);
227 int name_index; 227 int name_index;
228 void *value = NULL; 228 void *value = NULL;
229 size_t size = 0; 229 size_t size = 0;
@@ -234,7 +234,7 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
234 234
235 switch(type) { 235 switch(type) {
236 case ACL_TYPE_ACCESS: 236 case ACL_TYPE_ACCESS:
237 name_index = EXT3_XATTR_INDEX_POSIX_ACL_ACCESS; 237 name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS;
238 if (acl) { 238 if (acl) {
239 mode_t mode = inode->i_mode; 239 mode_t mode = inode->i_mode;
240 error = posix_acl_equiv_mode(acl, &mode); 240 error = posix_acl_equiv_mode(acl, &mode);
@@ -242,7 +242,7 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
242 return error; 242 return error;
243 else { 243 else {
244 inode->i_mode = mode; 244 inode->i_mode = mode;
245 ext3_mark_inode_dirty(handle, inode); 245 ext4_mark_inode_dirty(handle, inode);
246 if (error == 0) 246 if (error == 0)
247 acl = NULL; 247 acl = NULL;
248 } 248 }
@@ -250,7 +250,7 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
250 break; 250 break;
251 251
252 case ACL_TYPE_DEFAULT: 252 case ACL_TYPE_DEFAULT:
253 name_index = EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT; 253 name_index = EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT;
254 if (!S_ISDIR(inode->i_mode)) 254 if (!S_ISDIR(inode->i_mode))
255 return acl ? -EACCES : 0; 255 return acl ? -EACCES : 0;
256 break; 256 break;
@@ -259,23 +259,23 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
259 return -EINVAL; 259 return -EINVAL;
260 } 260 }
261 if (acl) { 261 if (acl) {
262 value = ext3_acl_to_disk(acl, &size); 262 value = ext4_acl_to_disk(acl, &size);
263 if (IS_ERR(value)) 263 if (IS_ERR(value))
264 return (int)PTR_ERR(value); 264 return (int)PTR_ERR(value);
265 } 265 }
266 266
267 error = ext3_xattr_set_handle(handle, inode, name_index, "", 267 error = ext4_xattr_set_handle(handle, inode, name_index, "",
268 value, size, 0); 268 value, size, 0);
269 269
270 kfree(value); 270 kfree(value);
271 if (!error) { 271 if (!error) {
272 switch(type) { 272 switch(type) {
273 case ACL_TYPE_ACCESS: 273 case ACL_TYPE_ACCESS:
274 ext3_iset_acl(inode, &ei->i_acl, acl); 274 ext4_iset_acl(inode, &ei->i_acl, acl);
275 break; 275 break;
276 276
277 case ACL_TYPE_DEFAULT: 277 case ACL_TYPE_DEFAULT:
278 ext3_iset_acl(inode, &ei->i_default_acl, acl); 278 ext4_iset_acl(inode, &ei->i_default_acl, acl);
279 break; 279 break;
280 } 280 }
281 } 281 }
@@ -283,9 +283,9 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
283} 283}
284 284
285static int 285static int
286ext3_check_acl(struct inode *inode, int mask) 286ext4_check_acl(struct inode *inode, int mask)
287{ 287{
288 struct posix_acl *acl = ext3_get_acl(inode, ACL_TYPE_ACCESS); 288 struct posix_acl *acl = ext4_get_acl(inode, ACL_TYPE_ACCESS);
289 289
290 if (IS_ERR(acl)) 290 if (IS_ERR(acl))
291 return PTR_ERR(acl); 291 return PTR_ERR(acl);
@@ -299,26 +299,26 @@ ext3_check_acl(struct inode *inode, int mask)
299} 299}
300 300
301int 301int
302ext3_permission(struct inode *inode, int mask, struct nameidata *nd) 302ext4_permission(struct inode *inode, int mask, struct nameidata *nd)
303{ 303{
304 return generic_permission(inode, mask, ext3_check_acl); 304 return generic_permission(inode, mask, ext4_check_acl);
305} 305}
306 306
307/* 307/*
308 * Initialize the ACLs of a new inode. Called from ext3_new_inode. 308 * Initialize the ACLs of a new inode. Called from ext4_new_inode.
309 * 309 *
310 * dir->i_mutex: down 310 * dir->i_mutex: down
311 * inode->i_mutex: up (access to inode is still exclusive) 311 * inode->i_mutex: up (access to inode is still exclusive)
312 */ 312 */
313int 313int
314ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir) 314ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
315{ 315{
316 struct posix_acl *acl = NULL; 316 struct posix_acl *acl = NULL;
317 int error = 0; 317 int error = 0;
318 318
319 if (!S_ISLNK(inode->i_mode)) { 319 if (!S_ISLNK(inode->i_mode)) {
320 if (test_opt(dir->i_sb, POSIX_ACL)) { 320 if (test_opt(dir->i_sb, POSIX_ACL)) {
321 acl = ext3_get_acl(dir, ACL_TYPE_DEFAULT); 321 acl = ext4_get_acl(dir, ACL_TYPE_DEFAULT);
322 if (IS_ERR(acl)) 322 if (IS_ERR(acl))
323 return PTR_ERR(acl); 323 return PTR_ERR(acl);
324 } 324 }
@@ -330,7 +330,7 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
330 mode_t mode; 330 mode_t mode;
331 331
332 if (S_ISDIR(inode->i_mode)) { 332 if (S_ISDIR(inode->i_mode)) {
333 error = ext3_set_acl(handle, inode, 333 error = ext4_set_acl(handle, inode,
334 ACL_TYPE_DEFAULT, acl); 334 ACL_TYPE_DEFAULT, acl);
335 if (error) 335 if (error)
336 goto cleanup; 336 goto cleanup;
@@ -346,7 +346,7 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
346 inode->i_mode = mode; 346 inode->i_mode = mode;
347 if (error > 0) { 347 if (error > 0) {
348 /* This is an extended ACL */ 348 /* This is an extended ACL */
349 error = ext3_set_acl(handle, inode, 349 error = ext4_set_acl(handle, inode,
350 ACL_TYPE_ACCESS, clone); 350 ACL_TYPE_ACCESS, clone);
351 } 351 }
352 } 352 }
@@ -372,7 +372,7 @@ cleanup:
372 * inode->i_mutex: down 372 * inode->i_mutex: down
373 */ 373 */
374int 374int
375ext3_acl_chmod(struct inode *inode) 375ext4_acl_chmod(struct inode *inode)
376{ 376{
377 struct posix_acl *acl, *clone; 377 struct posix_acl *acl, *clone;
378 int error; 378 int error;
@@ -381,7 +381,7 @@ ext3_acl_chmod(struct inode *inode)
381 return -EOPNOTSUPP; 381 return -EOPNOTSUPP;
382 if (!test_opt(inode->i_sb, POSIX_ACL)) 382 if (!test_opt(inode->i_sb, POSIX_ACL))
383 return 0; 383 return 0;
384 acl = ext3_get_acl(inode, ACL_TYPE_ACCESS); 384 acl = ext4_get_acl(inode, ACL_TYPE_ACCESS);
385 if (IS_ERR(acl) || !acl) 385 if (IS_ERR(acl) || !acl)
386 return PTR_ERR(acl); 386 return PTR_ERR(acl);
387 clone = posix_acl_clone(acl, GFP_KERNEL); 387 clone = posix_acl_clone(acl, GFP_KERNEL);
@@ -394,17 +394,17 @@ ext3_acl_chmod(struct inode *inode)
394 int retries = 0; 394 int retries = 0;
395 395
396 retry: 396 retry:
397 handle = ext3_journal_start(inode, 397 handle = ext4_journal_start(inode,
398 EXT3_DATA_TRANS_BLOCKS(inode->i_sb)); 398 EXT4_DATA_TRANS_BLOCKS(inode->i_sb));
399 if (IS_ERR(handle)) { 399 if (IS_ERR(handle)) {
400 error = PTR_ERR(handle); 400 error = PTR_ERR(handle);
401 ext3_std_error(inode->i_sb, error); 401 ext4_std_error(inode->i_sb, error);
402 goto out; 402 goto out;
403 } 403 }
404 error = ext3_set_acl(handle, inode, ACL_TYPE_ACCESS, clone); 404 error = ext4_set_acl(handle, inode, ACL_TYPE_ACCESS, clone);
405 ext3_journal_stop(handle); 405 ext4_journal_stop(handle);
406 if (error == -ENOSPC && 406 if (error == -ENOSPC &&
407 ext3_should_retry_alloc(inode->i_sb, &retries)) 407 ext4_should_retry_alloc(inode->i_sb, &retries))
408 goto retry; 408 goto retry;
409 } 409 }
410out: 410out:
@@ -416,7 +416,7 @@ out:
416 * Extended attribute handlers 416 * Extended attribute handlers
417 */ 417 */
418static size_t 418static size_t
419ext3_xattr_list_acl_access(struct inode *inode, char *list, size_t list_len, 419ext4_xattr_list_acl_access(struct inode *inode, char *list, size_t list_len,
420 const char *name, size_t name_len) 420 const char *name, size_t name_len)
421{ 421{
422 const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS); 422 const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS);
@@ -429,7 +429,7 @@ ext3_xattr_list_acl_access(struct inode *inode, char *list, size_t list_len,
429} 429}
430 430
431static size_t 431static size_t
432ext3_xattr_list_acl_default(struct inode *inode, char *list, size_t list_len, 432ext4_xattr_list_acl_default(struct inode *inode, char *list, size_t list_len,
433 const char *name, size_t name_len) 433 const char *name, size_t name_len)
434{ 434{
435 const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT); 435 const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT);
@@ -442,7 +442,7 @@ ext3_xattr_list_acl_default(struct inode *inode, char *list, size_t list_len,
442} 442}
443 443
444static int 444static int
445ext3_xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size) 445ext4_xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size)
446{ 446{
447 struct posix_acl *acl; 447 struct posix_acl *acl;
448 int error; 448 int error;
@@ -450,7 +450,7 @@ ext3_xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size)
450 if (!test_opt(inode->i_sb, POSIX_ACL)) 450 if (!test_opt(inode->i_sb, POSIX_ACL))
451 return -EOPNOTSUPP; 451 return -EOPNOTSUPP;
452 452
453 acl = ext3_get_acl(inode, type); 453 acl = ext4_get_acl(inode, type);
454 if (IS_ERR(acl)) 454 if (IS_ERR(acl))
455 return PTR_ERR(acl); 455 return PTR_ERR(acl);
456 if (acl == NULL) 456 if (acl == NULL)
@@ -462,25 +462,25 @@ ext3_xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size)
462} 462}
463 463
464static int 464static int
465ext3_xattr_get_acl_access(struct inode *inode, const char *name, 465ext4_xattr_get_acl_access(struct inode *inode, const char *name,
466 void *buffer, size_t size) 466 void *buffer, size_t size)
467{ 467{
468 if (strcmp(name, "") != 0) 468 if (strcmp(name, "") != 0)
469 return -EINVAL; 469 return -EINVAL;
470 return ext3_xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size); 470 return ext4_xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size);
471} 471}
472 472
473static int 473static int
474ext3_xattr_get_acl_default(struct inode *inode, const char *name, 474ext4_xattr_get_acl_default(struct inode *inode, const char *name,
475 void *buffer, size_t size) 475 void *buffer, size_t size)
476{ 476{
477 if (strcmp(name, "") != 0) 477 if (strcmp(name, "") != 0)
478 return -EINVAL; 478 return -EINVAL;
479 return ext3_xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size); 479 return ext4_xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size);
480} 480}
481 481
482static int 482static int
483ext3_xattr_set_acl(struct inode *inode, int type, const void *value, 483ext4_xattr_set_acl(struct inode *inode, int type, const void *value,
484 size_t size) 484 size_t size)
485{ 485{
486 handle_t *handle; 486 handle_t *handle;
@@ -505,12 +505,12 @@ ext3_xattr_set_acl(struct inode *inode, int type, const void *value,
505 acl = NULL; 505 acl = NULL;
506 506
507retry: 507retry:
508 handle = ext3_journal_start(inode, EXT3_DATA_TRANS_BLOCKS(inode->i_sb)); 508 handle = ext4_journal_start(inode, EXT4_DATA_TRANS_BLOCKS(inode->i_sb));
509 if (IS_ERR(handle)) 509 if (IS_ERR(handle))
510 return PTR_ERR(handle); 510 return PTR_ERR(handle);
511 error = ext3_set_acl(handle, inode, type, acl); 511 error = ext4_set_acl(handle, inode, type, acl);
512 ext3_journal_stop(handle); 512 ext4_journal_stop(handle);
513 if (error == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries)) 513 if (error == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
514 goto retry; 514 goto retry;
515 515
516release_and_out: 516release_and_out:
@@ -519,33 +519,33 @@ release_and_out:
519} 519}
520 520
521static int 521static int
522ext3_xattr_set_acl_access(struct inode *inode, const char *name, 522ext4_xattr_set_acl_access(struct inode *inode, const char *name,
523 const void *value, size_t size, int flags) 523 const void *value, size_t size, int flags)
524{ 524{
525 if (strcmp(name, "") != 0) 525 if (strcmp(name, "") != 0)
526 return -EINVAL; 526 return -EINVAL;
527 return ext3_xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size); 527 return ext4_xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size);
528} 528}
529 529
530static int 530static int
531ext3_xattr_set_acl_default(struct inode *inode, const char *name, 531ext4_xattr_set_acl_default(struct inode *inode, const char *name,
532 const void *value, size_t size, int flags) 532 const void *value, size_t size, int flags)
533{ 533{
534 if (strcmp(name, "") != 0) 534 if (strcmp(name, "") != 0)
535 return -EINVAL; 535 return -EINVAL;
536 return ext3_xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size); 536 return ext4_xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size);
537} 537}
538 538
539struct xattr_handler ext3_xattr_acl_access_handler = { 539struct xattr_handler ext4_xattr_acl_access_handler = {
540 .prefix = POSIX_ACL_XATTR_ACCESS, 540 .prefix = POSIX_ACL_XATTR_ACCESS,
541 .list = ext3_xattr_list_acl_access, 541 .list = ext4_xattr_list_acl_access,
542 .get = ext3_xattr_get_acl_access, 542 .get = ext4_xattr_get_acl_access,
543 .set = ext3_xattr_set_acl_access, 543 .set = ext4_xattr_set_acl_access,
544}; 544};
545 545
546struct xattr_handler ext3_xattr_acl_default_handler = { 546struct xattr_handler ext4_xattr_acl_default_handler = {
547 .prefix = POSIX_ACL_XATTR_DEFAULT, 547 .prefix = POSIX_ACL_XATTR_DEFAULT,
548 .list = ext3_xattr_list_acl_default, 548 .list = ext4_xattr_list_acl_default,
549 .get = ext3_xattr_get_acl_default, 549 .get = ext4_xattr_get_acl_default,
550 .set = ext3_xattr_set_acl_default, 550 .set = ext4_xattr_set_acl_default,
551}; 551};
diff --git a/fs/ext4/acl.h b/fs/ext4/acl.h
index 0d1e6279cbf..26a5c1abf14 100644
--- a/fs/ext4/acl.h
+++ b/fs/ext4/acl.h
@@ -1,81 +1,81 @@
1/* 1/*
2 File: fs/ext3/acl.h 2 File: fs/ext4/acl.h
3 3
4 (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org> 4 (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
5*/ 5*/
6 6
7#include <linux/posix_acl_xattr.h> 7#include <linux/posix_acl_xattr.h>
8 8
9#define EXT3_ACL_VERSION 0x0001 9#define EXT4_ACL_VERSION 0x0001
10 10
11typedef struct { 11typedef struct {
12 __le16 e_tag; 12 __le16 e_tag;
13 __le16 e_perm; 13 __le16 e_perm;
14 __le32 e_id; 14 __le32 e_id;
15} ext3_acl_entry; 15} ext4_acl_entry;
16 16
17typedef struct { 17typedef struct {
18 __le16 e_tag; 18 __le16 e_tag;
19 __le16 e_perm; 19 __le16 e_perm;
20} ext3_acl_entry_short; 20} ext4_acl_entry_short;
21 21
22typedef struct { 22typedef struct {
23 __le32 a_version; 23 __le32 a_version;
24} ext3_acl_header; 24} ext4_acl_header;
25 25
26static inline size_t ext3_acl_size(int count) 26static inline size_t ext4_acl_size(int count)
27{ 27{
28 if (count <= 4) { 28 if (count <= 4) {
29 return sizeof(ext3_acl_header) + 29 return sizeof(ext4_acl_header) +
30 count * sizeof(ext3_acl_entry_short); 30 count * sizeof(ext4_acl_entry_short);
31 } else { 31 } else {
32 return sizeof(ext3_acl_header) + 32 return sizeof(ext4_acl_header) +
33 4 * sizeof(ext3_acl_entry_short) + 33 4 * sizeof(ext4_acl_entry_short) +
34 (count - 4) * sizeof(ext3_acl_entry); 34 (count - 4) * sizeof(ext4_acl_entry);
35 } 35 }
36} 36}
37 37
38static inline int ext3_acl_count(size_t size) 38static inline int ext4_acl_count(size_t size)
39{ 39{
40 ssize_t s; 40 ssize_t s;
41 size -= sizeof(ext3_acl_header); 41 size -= sizeof(ext4_acl_header);
42 s = size - 4 * sizeof(ext3_acl_entry_short); 42 s = size - 4 * sizeof(ext4_acl_entry_short);
43 if (s < 0) { 43 if (s < 0) {
44 if (size % sizeof(ext3_acl_entry_short)) 44 if (size % sizeof(ext4_acl_entry_short))
45 return -1; 45 return -1;
46 return size / sizeof(ext3_acl_entry_short); 46 return size / sizeof(ext4_acl_entry_short);
47 } else { 47 } else {
48 if (s % sizeof(ext3_acl_entry)) 48 if (s % sizeof(ext4_acl_entry))
49 return -1; 49 return -1;
50 return s / sizeof(ext3_acl_entry) + 4; 50 return s / sizeof(ext4_acl_entry) + 4;
51 } 51 }
52} 52}
53 53
54#ifdef CONFIG_EXT3_FS_POSIX_ACL 54#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
55 55
56/* Value for inode->u.ext3_i.i_acl and inode->u.ext3_i.i_default_acl 56/* Value for inode->u.ext4_i.i_acl and inode->u.ext4_i.i_default_acl
57 if the ACL has not been cached */ 57 if the ACL has not been cached */
58#define EXT3_ACL_NOT_CACHED ((void *)-1) 58#define EXT4_ACL_NOT_CACHED ((void *)-1)
59 59
60/* acl.c */ 60/* acl.c */
61extern int ext3_permission (struct inode *, int, struct nameidata *); 61extern int ext4_permission (struct inode *, int, struct nameidata *);
62extern int ext3_acl_chmod (struct inode *); 62extern int ext4_acl_chmod (struct inode *);
63extern int ext3_init_acl (handle_t *, struct inode *, struct inode *); 63extern int ext4_init_acl (handle_t *, struct inode *, struct inode *);
64 64
65#else /* CONFIG_EXT3_FS_POSIX_ACL */ 65#else /* CONFIG_EXT4DEV_FS_POSIX_ACL */
66#include <linux/sched.h> 66#include <linux/sched.h>
67#define ext3_permission NULL 67#define ext4_permission NULL
68 68
69static inline int 69static inline int
70ext3_acl_chmod(struct inode *inode) 70ext4_acl_chmod(struct inode *inode)
71{ 71{
72 return 0; 72 return 0;
73} 73}
74 74
75static inline int 75static inline int
76ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir) 76ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
77{ 77{
78 return 0; 78 return 0;
79} 79}
80#endif /* CONFIG_EXT3_FS_POSIX_ACL */ 80#endif /* CONFIG_EXT4DEV_FS_POSIX_ACL */
81 81
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index b41a7d7e20f..357e4e50374 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/balloc.c 2 * linux/fs/ext4/balloc.c
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -15,8 +15,8 @@
15#include <linux/capability.h> 15#include <linux/capability.h>
16#include <linux/fs.h> 16#include <linux/fs.h>
17#include <linux/jbd.h> 17#include <linux/jbd.h>
18#include <linux/ext3_fs.h> 18#include <linux/ext4_fs.h>
19#include <linux/ext3_jbd.h> 19#include <linux/ext4_jbd.h>
20#include <linux/quotaops.h> 20#include <linux/quotaops.h>
21#include <linux/buffer_head.h> 21#include <linux/buffer_head.h>
22 22
@@ -32,30 +32,30 @@
32 * The file system contains group descriptors which are located after the 32 * The file system contains group descriptors which are located after the
33 * super block. Each descriptor contains the number of the bitmap block and 33 * super block. Each descriptor contains the number of the bitmap block and
34 * the free blocks count in the block. The descriptors are loaded in memory 34 * the free blocks count in the block. The descriptors are loaded in memory
35 * when a file system is mounted (see ext3_read_super). 35 * when a file system is mounted (see ext4_read_super).
36 */ 36 */
37 37
38 38
39#define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1) 39#define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1)
40 40
41/** 41/**
42 * ext3_get_group_desc() -- load group descriptor from disk 42 * ext4_get_group_desc() -- load group descriptor from disk
43 * @sb: super block 43 * @sb: super block
44 * @block_group: given block group 44 * @block_group: given block group
45 * @bh: pointer to the buffer head to store the block 45 * @bh: pointer to the buffer head to store the block
46 * group descriptor 46 * group descriptor
47 */ 47 */
48struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb, 48struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
49 unsigned int block_group, 49 unsigned int block_group,
50 struct buffer_head ** bh) 50 struct buffer_head ** bh)
51{ 51{
52 unsigned long group_desc; 52 unsigned long group_desc;
53 unsigned long offset; 53 unsigned long offset;
54 struct ext3_group_desc * desc; 54 struct ext4_group_desc * desc;
55 struct ext3_sb_info *sbi = EXT3_SB(sb); 55 struct ext4_sb_info *sbi = EXT4_SB(sb);
56 56
57 if (block_group >= sbi->s_groups_count) { 57 if (block_group >= sbi->s_groups_count) {
58 ext3_error (sb, "ext3_get_group_desc", 58 ext4_error (sb, "ext4_get_group_desc",
59 "block_group >= groups_count - " 59 "block_group >= groups_count - "
60 "block_group = %d, groups_count = %lu", 60 "block_group = %d, groups_count = %lu",
61 block_group, sbi->s_groups_count); 61 block_group, sbi->s_groups_count);
@@ -64,17 +64,17 @@ struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb,
64 } 64 }
65 smp_rmb(); 65 smp_rmb();
66 66
67 group_desc = block_group >> EXT3_DESC_PER_BLOCK_BITS(sb); 67 group_desc = block_group >> EXT4_DESC_PER_BLOCK_BITS(sb);
68 offset = block_group & (EXT3_DESC_PER_BLOCK(sb) - 1); 68 offset = block_group & (EXT4_DESC_PER_BLOCK(sb) - 1);
69 if (!sbi->s_group_desc[group_desc]) { 69 if (!sbi->s_group_desc[group_desc]) {
70 ext3_error (sb, "ext3_get_group_desc", 70 ext4_error (sb, "ext4_get_group_desc",
71 "Group descriptor not loaded - " 71 "Group descriptor not loaded - "
72 "block_group = %d, group_desc = %lu, desc = %lu", 72 "block_group = %d, group_desc = %lu, desc = %lu",
73 block_group, group_desc, offset); 73 block_group, group_desc, offset);
74 return NULL; 74 return NULL;
75 } 75 }
76 76
77 desc = (struct ext3_group_desc *) sbi->s_group_desc[group_desc]->b_data; 77 desc = (struct ext4_group_desc *) sbi->s_group_desc[group_desc]->b_data;
78 if (bh) 78 if (bh)
79 *bh = sbi->s_group_desc[group_desc]; 79 *bh = sbi->s_group_desc[group_desc];
80 return desc + offset; 80 return desc + offset;
@@ -93,15 +93,15 @@ struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb,
93static struct buffer_head * 93static struct buffer_head *
94read_block_bitmap(struct super_block *sb, unsigned int block_group) 94read_block_bitmap(struct super_block *sb, unsigned int block_group)
95{ 95{
96 struct ext3_group_desc * desc; 96 struct ext4_group_desc * desc;
97 struct buffer_head * bh = NULL; 97 struct buffer_head * bh = NULL;
98 98
99 desc = ext3_get_group_desc (sb, block_group, NULL); 99 desc = ext4_get_group_desc (sb, block_group, NULL);
100 if (!desc) 100 if (!desc)
101 goto error_out; 101 goto error_out;
102 bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap)); 102 bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap));
103 if (!bh) 103 if (!bh)
104 ext3_error (sb, "read_block_bitmap", 104 ext4_error (sb, "read_block_bitmap",
105 "Cannot read block bitmap - " 105 "Cannot read block bitmap - "
106 "block_group = %d, block_bitmap = %u", 106 "block_group = %d, block_bitmap = %u",
107 block_group, le32_to_cpu(desc->bg_block_bitmap)); 107 block_group, le32_to_cpu(desc->bg_block_bitmap));
@@ -134,7 +134,7 @@ static void __rsv_window_dump(struct rb_root *root, int verbose,
134 const char *fn) 134 const char *fn)
135{ 135{
136 struct rb_node *n; 136 struct rb_node *n;
137 struct ext3_reserve_window_node *rsv, *prev; 137 struct ext4_reserve_window_node *rsv, *prev;
138 int bad; 138 int bad;
139 139
140restart: 140restart:
@@ -144,7 +144,7 @@ restart:
144 144
145 printk("Block Allocation Reservation Windows Map (%s):\n", fn); 145 printk("Block Allocation Reservation Windows Map (%s):\n", fn);
146 while (n) { 146 while (n) {
147 rsv = list_entry(n, struct ext3_reserve_window_node, rsv_node); 147 rsv = list_entry(n, struct ext4_reserve_window_node, rsv_node);
148 if (verbose) 148 if (verbose)
149 printk("reservation window 0x%p " 149 printk("reservation window 0x%p "
150 "start: %lu, end: %lu\n", 150 "start: %lu, end: %lu\n",
@@ -196,13 +196,13 @@ restart:
196 * otherwise, return 0; 196 * otherwise, return 0;
197 */ 197 */
198static int 198static int
199goal_in_my_reservation(struct ext3_reserve_window *rsv, ext3_grpblk_t grp_goal, 199goal_in_my_reservation(struct ext4_reserve_window *rsv, ext4_grpblk_t grp_goal,
200 unsigned int group, struct super_block * sb) 200 unsigned int group, struct super_block * sb)
201{ 201{
202 ext3_fsblk_t group_first_block, group_last_block; 202 ext4_fsblk_t group_first_block, group_last_block;
203 203
204 group_first_block = ext3_group_first_block_no(sb, group); 204 group_first_block = ext4_group_first_block_no(sb, group);
205 group_last_block = group_first_block + (EXT3_BLOCKS_PER_GROUP(sb) - 1); 205 group_last_block = group_first_block + (EXT4_BLOCKS_PER_GROUP(sb) - 1);
206 206
207 if ((rsv->_rsv_start > group_last_block) || 207 if ((rsv->_rsv_start > group_last_block) ||
208 (rsv->_rsv_end < group_first_block)) 208 (rsv->_rsv_end < group_first_block))
@@ -222,17 +222,17 @@ goal_in_my_reservation(struct ext3_reserve_window *rsv, ext3_grpblk_t grp_goal,
222 * if the goal is not in any window. 222 * if the goal is not in any window.
223 * Returns NULL if there are no windows or if all windows start after the goal. 223 * Returns NULL if there are no windows or if all windows start after the goal.
224 */ 224 */
225static struct ext3_reserve_window_node * 225static struct ext4_reserve_window_node *
226search_reserve_window(struct rb_root *root, ext3_fsblk_t goal) 226search_reserve_window(struct rb_root *root, ext4_fsblk_t goal)
227{ 227{
228 struct rb_node *n = root->rb_node; 228 struct rb_node *n = root->rb_node;
229 struct ext3_reserve_window_node *rsv; 229 struct ext4_reserve_window_node *rsv;
230 230
231 if (!n) 231 if (!n)
232 return NULL; 232 return NULL;
233 233
234 do { 234 do {
235 rsv = rb_entry(n, struct ext3_reserve_window_node, rsv_node); 235 rsv = rb_entry(n, struct ext4_reserve_window_node, rsv_node);
236 236
237 if (goal < rsv->rsv_start) 237 if (goal < rsv->rsv_start)
238 n = n->rb_left; 238 n = n->rb_left;
@@ -249,33 +249,33 @@ search_reserve_window(struct rb_root *root, ext3_fsblk_t goal)
249 */ 249 */
250 if (rsv->rsv_start > goal) { 250 if (rsv->rsv_start > goal) {
251 n = rb_prev(&rsv->rsv_node); 251 n = rb_prev(&rsv->rsv_node);
252 rsv = rb_entry(n, struct ext3_reserve_window_node, rsv_node); 252 rsv = rb_entry(n, struct ext4_reserve_window_node, rsv_node);
253 } 253 }
254 return rsv; 254 return rsv;
255} 255}
256 256
257/** 257/**
258 * ext3_rsv_window_add() -- Insert a window to the block reservation rb tree. 258 * ext4_rsv_window_add() -- Insert a window to the block reservation rb tree.
259 * @sb: super block 259 * @sb: super block
260 * @rsv: reservation window to add 260 * @rsv: reservation window to add
261 * 261 *
262 * Must be called with rsv_lock hold. 262 * Must be called with rsv_lock hold.
263 */ 263 */
264void ext3_rsv_window_add(struct super_block *sb, 264void ext4_rsv_window_add(struct super_block *sb,
265 struct ext3_reserve_window_node *rsv) 265 struct ext4_reserve_window_node *rsv)
266{ 266{
267 struct rb_root *root = &EXT3_SB(sb)->s_rsv_window_root; 267 struct rb_root *root = &EXT4_SB(sb)->s_rsv_window_root;
268 struct rb_node *node = &rsv->rsv_node; 268 struct rb_node *node = &rsv->rsv_node;
269 ext3_fsblk_t start = rsv->rsv_start; 269 ext4_fsblk_t start = rsv->rsv_start;
270 270
271 struct rb_node ** p = &root->rb_node; 271 struct rb_node ** p = &root->rb_node;
272 struct rb_node * parent = NULL; 272 struct rb_node * parent = NULL;
273 struct ext3_reserve_window_node *this; 273 struct ext4_reserve_window_node *this;
274 274
275 while (*p) 275 while (*p)
276 { 276 {
277 parent = *p; 277 parent = *p;
278 this = rb_entry(parent, struct ext3_reserve_window_node, rsv_node); 278 this = rb_entry(parent, struct ext4_reserve_window_node, rsv_node);
279 279
280 if (start < this->rsv_start) 280 if (start < this->rsv_start)
281 p = &(*p)->rb_left; 281 p = &(*p)->rb_left;
@@ -292,7 +292,7 @@ void ext3_rsv_window_add(struct super_block *sb,
292} 292}
293 293
294/** 294/**
295 * ext3_rsv_window_remove() -- unlink a window from the reservation rb tree 295 * ext4_rsv_window_remove() -- unlink a window from the reservation rb tree
296 * @sb: super block 296 * @sb: super block
297 * @rsv: reservation window to remove 297 * @rsv: reservation window to remove
298 * 298 *
@@ -301,59 +301,59 @@ void ext3_rsv_window_add(struct super_block *sb,
301 * rsv_lock hold. 301 * rsv_lock hold.
302 */ 302 */
303static void rsv_window_remove(struct super_block *sb, 303static void rsv_window_remove(struct super_block *sb,
304 struct ext3_reserve_window_node *rsv) 304 struct ext4_reserve_window_node *rsv)
305{ 305{
306 rsv->rsv_start = EXT3_RESERVE_WINDOW_NOT_ALLOCATED; 306 rsv->rsv_start = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
307 rsv->rsv_end = EXT3_RESERVE_WINDOW_NOT_ALLOCATED; 307 rsv->rsv_end = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
308 rsv->rsv_alloc_hit = 0; 308 rsv->rsv_alloc_hit = 0;
309 rb_erase(&rsv->rsv_node, &EXT3_SB(sb)->s_rsv_window_root); 309 rb_erase(&rsv->rsv_node, &EXT4_SB(sb)->s_rsv_window_root);
310} 310}
311 311
312/* 312/*
313 * rsv_is_empty() -- Check if the reservation window is allocated. 313 * rsv_is_empty() -- Check if the reservation window is allocated.
314 * @rsv: given reservation window to check 314 * @rsv: given reservation window to check
315 * 315 *
316 * returns 1 if the end block is EXT3_RESERVE_WINDOW_NOT_ALLOCATED. 316 * returns 1 if the end block is EXT4_RESERVE_WINDOW_NOT_ALLOCATED.
317 */ 317 */
318static inline int rsv_is_empty(struct ext3_reserve_window *rsv) 318static inline int rsv_is_empty(struct ext4_reserve_window *rsv)
319{ 319{
320 /* a valid reservation end block could not be 0 */ 320 /* a valid reservation end block could not be 0 */
321 return rsv->_rsv_end == EXT3_RESERVE_WINDOW_NOT_ALLOCATED; 321 return rsv->_rsv_end == EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
322} 322}
323 323
324/** 324/**
325 * ext3_init_block_alloc_info() 325 * ext4_init_block_alloc_info()
326 * @inode: file inode structure 326 * @inode: file inode structure
327 * 327 *
328 * Allocate and initialize the reservation window structure, and 328 * Allocate and initialize the reservation window structure, and
329 * link the window to the ext3 inode structure at last 329 * link the window to the ext4 inode structure at last
330 * 330 *
331 * The reservation window structure is only dynamically allocated 331 * The reservation window structure is only dynamically allocated
332 * and linked to ext3 inode the first time the open file 332 * and linked to ext4 inode the first time the open file
333 * needs a new block. So, before every ext3_new_block(s) call, for 333 * needs a new block. So, before every ext4_new_block(s) call, for
334 * regular files, we should check whether the reservation window 334 * regular files, we should check whether the reservation window
335 * structure exists or not. In the latter case, this function is called. 335 * structure exists or not. In the latter case, this function is called.
336 * Fail to do so will result in block reservation being turned off for that 336 * Fail to do so will result in block reservation being turned off for that
337 * open file. 337 * open file.
338 * 338 *
339 * This function is called from ext3_get_blocks_handle(), also called 339 * This function is called from ext4_get_blocks_handle(), also called
340 * when setting the reservation window size through ioctl before the file 340 * when setting the reservation window size through ioctl before the file
341 * is open for write (needs block allocation). 341 * is open for write (needs block allocation).
342 * 342 *
343 * Needs truncate_mutex protection prior to call this function. 343 * Needs truncate_mutex protection prior to call this function.
344 */ 344 */
345void ext3_init_block_alloc_info(struct inode *inode) 345void ext4_init_block_alloc_info(struct inode *inode)
346{ 346{
347 struct ext3_inode_info *ei = EXT3_I(inode); 347 struct ext4_inode_info *ei = EXT4_I(inode);
348 struct ext3_block_alloc_info *block_i = ei->i_block_alloc_info; 348 struct ext4_block_alloc_info *block_i = ei->i_block_alloc_info;
349 struct super_block *sb = inode->i_sb; 349 struct super_block *sb = inode->i_sb;
350 350
351 block_i = kmalloc(sizeof(*block_i), GFP_NOFS); 351 block_i = kmalloc(sizeof(*block_i), GFP_NOFS);
352 if (block_i) { 352 if (block_i) {
353 struct ext3_reserve_window_node *rsv = &block_i->rsv_window_node; 353 struct ext4_reserve_window_node *rsv = &block_i->rsv_window_node;
354 354
355 rsv->rsv_start = EXT3_RESERVE_WINDOW_NOT_ALLOCATED; 355 rsv->rsv_start = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
356 rsv->rsv_end = EXT3_RESERVE_WINDOW_NOT_ALLOCATED; 356 rsv->rsv_end = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
357 357
358 /* 358 /*
359 * if filesystem is mounted with NORESERVATION, the goal 359 * if filesystem is mounted with NORESERVATION, the goal
@@ -363,7 +363,7 @@ void ext3_init_block_alloc_info(struct inode *inode)
363 if (!test_opt(sb, RESERVATION)) 363 if (!test_opt(sb, RESERVATION))
364 rsv->rsv_goal_size = 0; 364 rsv->rsv_goal_size = 0;
365 else 365 else
366 rsv->rsv_goal_size = EXT3_DEFAULT_RESERVE_BLOCKS; 366 rsv->rsv_goal_size = EXT4_DEFAULT_RESERVE_BLOCKS;
367 rsv->rsv_alloc_hit = 0; 367 rsv->rsv_alloc_hit = 0;
368 block_i->last_alloc_logical_block = 0; 368 block_i->last_alloc_logical_block = 0;
369 block_i->last_alloc_physical_block = 0; 369 block_i->last_alloc_physical_block = 0;
@@ -372,24 +372,24 @@ void ext3_init_block_alloc_info(struct inode *inode)
372} 372}
373 373
374/** 374/**
375 * ext3_discard_reservation() 375 * ext4_discard_reservation()
376 * @inode: inode 376 * @inode: inode
377 * 377 *
378 * Discard(free) block reservation window on last file close, or truncate 378 * Discard(free) block reservation window on last file close, or truncate
379 * or at last iput(). 379 * or at last iput().
380 * 380 *
381 * It is being called in three cases: 381 * It is being called in three cases:
382 * ext3_release_file(): last writer close the file 382 * ext4_release_file(): last writer close the file
383 * ext3_clear_inode(): last iput(), when nobody link to this file. 383 * ext4_clear_inode(): last iput(), when nobody link to this file.
384 * ext3_truncate(): when the block indirect map is about to change. 384 * ext4_truncate(): when the block indirect map is about to change.
385 * 385 *
386 */ 386 */
387void ext3_discard_reservation(struct inode *inode) 387void ext4_discard_reservation(struct inode *inode)
388{ 388{
389 struct ext3_inode_info *ei = EXT3_I(inode); 389 struct ext4_inode_info *ei = EXT4_I(inode);
390 struct ext3_block_alloc_info *block_i = ei->i_block_alloc_info; 390 struct ext4_block_alloc_info *block_i = ei->i_block_alloc_info;
391 struct ext3_reserve_window_node *rsv; 391 struct ext4_reserve_window_node *rsv;
392 spinlock_t *rsv_lock = &EXT3_SB(inode->i_sb)->s_rsv_window_lock; 392 spinlock_t *rsv_lock = &EXT4_SB(inode->i_sb)->s_rsv_window_lock;
393 393
394 if (!block_i) 394 if (!block_i)
395 return; 395 return;
@@ -404,62 +404,62 @@ void ext3_discard_reservation(struct inode *inode)
404} 404}
405 405
406/** 406/**
407 * ext3_free_blocks_sb() -- Free given blocks and update quota 407 * ext4_free_blocks_sb() -- Free given blocks and update quota
408 * @handle: handle to this transaction 408 * @handle: handle to this transaction
409 * @sb: super block 409 * @sb: super block
410 * @block: start physcial block to free 410 * @block: start physcial block to free
411 * @count: number of blocks to free 411 * @count: number of blocks to free
412 * @pdquot_freed_blocks: pointer to quota 412 * @pdquot_freed_blocks: pointer to quota
413 */ 413 */
414void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb, 414void ext4_free_blocks_sb(handle_t *handle, struct super_block *sb,
415 ext3_fsblk_t block, unsigned long count, 415 ext4_fsblk_t block, unsigned long count,
416 unsigned long *pdquot_freed_blocks) 416 unsigned long *pdquot_freed_blocks)
417{ 417{
418 struct buffer_head *bitmap_bh = NULL; 418 struct buffer_head *bitmap_bh = NULL;
419 struct buffer_head *gd_bh; 419 struct buffer_head *gd_bh;
420 unsigned long block_group; 420 unsigned long block_group;
421 ext3_grpblk_t bit; 421 ext4_grpblk_t bit;
422 unsigned long i; 422 unsigned long i;
423 unsigned long overflow; 423 unsigned long overflow;
424 struct ext3_group_desc * desc; 424 struct ext4_group_desc * desc;
425 struct ext3_super_block * es; 425 struct ext4_super_block * es;
426 struct ext3_sb_info *sbi; 426 struct ext4_sb_info *sbi;
427 int err = 0, ret; 427 int err = 0, ret;
428 ext3_grpblk_t group_freed; 428 ext4_grpblk_t group_freed;
429 429
430 *pdquot_freed_blocks = 0; 430 *pdquot_freed_blocks = 0;
431 sbi = EXT3_SB(sb); 431 sbi = EXT4_SB(sb);
432 es = sbi->s_es; 432 es = sbi->s_es;
433 if (block < le32_to_cpu(es->s_first_data_block) || 433 if (block < le32_to_cpu(es->s_first_data_block) ||
434 block + count < block || 434 block + count < block ||
435 block + count > le32_to_cpu(es->s_blocks_count)) { 435 block + count > le32_to_cpu(es->s_blocks_count)) {
436 ext3_error (sb, "ext3_free_blocks", 436 ext4_error (sb, "ext4_free_blocks",
437 "Freeing blocks not in datazone - " 437 "Freeing blocks not in datazone - "
438 "block = "E3FSBLK", count = %lu", block, count); 438 "block = "E3FSBLK", count = %lu", block, count);
439 goto error_return; 439 goto error_return;
440 } 440 }
441 441
442 ext3_debug ("freeing block(s) %lu-%lu\n", block, block + count - 1); 442 ext4_debug ("freeing block(s) %lu-%lu\n", block, block + count - 1);
443 443
444do_more: 444do_more:
445 overflow = 0; 445 overflow = 0;
446 block_group = (block - le32_to_cpu(es->s_first_data_block)) / 446 block_group = (block - le32_to_cpu(es->s_first_data_block)) /
447 EXT3_BLOCKS_PER_GROUP(sb); 447 EXT4_BLOCKS_PER_GROUP(sb);
448 bit = (block - le32_to_cpu(es->s_first_data_block)) % 448 bit = (block - le32_to_cpu(es->s_first_data_block)) %
449 EXT3_BLOCKS_PER_GROUP(sb); 449 EXT4_BLOCKS_PER_GROUP(sb);
450 /* 450 /*
451 * Check to see if we are freeing blocks across a group 451 * Check to see if we are freeing blocks across a group
452 * boundary. 452 * boundary.
453 */ 453 */
454 if (bit + count > EXT3_BLOCKS_PER_GROUP(sb)) { 454 if (bit + count > EXT4_BLOCKS_PER_GROUP(sb)) {
455 overflow = bit + count - EXT3_BLOCKS_PER_GROUP(sb); 455 overflow = bit + count - EXT4_BLOCKS_PER_GROUP(sb);
456 count -= overflow; 456 count -= overflow;
457 } 457 }
458 brelse(bitmap_bh); 458 brelse(bitmap_bh);
459 bitmap_bh = read_block_bitmap(sb, block_group); 459 bitmap_bh = read_block_bitmap(sb, block_group);
460 if (!bitmap_bh) 460 if (!bitmap_bh)
461 goto error_return; 461 goto error_return;
462 desc = ext3_get_group_desc (sb, block_group, &gd_bh); 462 desc = ext4_get_group_desc (sb, block_group, &gd_bh);
463 if (!desc) 463 if (!desc)
464 goto error_return; 464 goto error_return;
465 465
@@ -469,7 +469,7 @@ do_more:
469 sbi->s_itb_per_group) || 469 sbi->s_itb_per_group) ||
470 in_range (block + count - 1, le32_to_cpu(desc->bg_inode_table), 470 in_range (block + count - 1, le32_to_cpu(desc->bg_inode_table),
471 sbi->s_itb_per_group)) 471 sbi->s_itb_per_group))
472 ext3_error (sb, "ext3_free_blocks", 472 ext4_error (sb, "ext4_free_blocks",
473 "Freeing blocks in system zones - " 473 "Freeing blocks in system zones - "
474 "Block = "E3FSBLK", count = %lu", 474 "Block = "E3FSBLK", count = %lu",
475 block, count); 475 block, count);
@@ -480,7 +480,7 @@ do_more:
480 */ 480 */
481 /* @@@ check errors */ 481 /* @@@ check errors */
482 BUFFER_TRACE(bitmap_bh, "getting undo access"); 482 BUFFER_TRACE(bitmap_bh, "getting undo access");
483 err = ext3_journal_get_undo_access(handle, bitmap_bh); 483 err = ext4_journal_get_undo_access(handle, bitmap_bh);
484 if (err) 484 if (err)
485 goto error_return; 485 goto error_return;
486 486
@@ -490,7 +490,7 @@ do_more:
490 * using it 490 * using it
491 */ 491 */
492 BUFFER_TRACE(gd_bh, "get_write_access"); 492 BUFFER_TRACE(gd_bh, "get_write_access");
493 err = ext3_journal_get_write_access(handle, gd_bh); 493 err = ext4_journal_get_write_access(handle, gd_bh);
494 if (err) 494 if (err)
495 goto error_return; 495 goto error_return;
496 496
@@ -542,7 +542,7 @@ do_more:
542 BUFFER_TRACE(bitmap_bh, "set in b_committed_data"); 542 BUFFER_TRACE(bitmap_bh, "set in b_committed_data");
543 J_ASSERT_BH(bitmap_bh, 543 J_ASSERT_BH(bitmap_bh,
544 bh2jh(bitmap_bh)->b_committed_data != NULL); 544 bh2jh(bitmap_bh)->b_committed_data != NULL);
545 ext3_set_bit_atomic(sb_bgl_lock(sbi, block_group), bit + i, 545 ext4_set_bit_atomic(sb_bgl_lock(sbi, block_group), bit + i,
546 bh2jh(bitmap_bh)->b_committed_data); 546 bh2jh(bitmap_bh)->b_committed_data);
547 547
548 /* 548 /*
@@ -551,10 +551,10 @@ do_more:
551 * the allocator uses. 551 * the allocator uses.
552 */ 552 */
553 BUFFER_TRACE(bitmap_bh, "clear bit"); 553 BUFFER_TRACE(bitmap_bh, "clear bit");
554 if (!ext3_clear_bit_atomic(sb_bgl_lock(sbi, block_group), 554 if (!ext4_clear_bit_atomic(sb_bgl_lock(sbi, block_group),
555 bit + i, bitmap_bh->b_data)) { 555 bit + i, bitmap_bh->b_data)) {
556 jbd_unlock_bh_state(bitmap_bh); 556 jbd_unlock_bh_state(bitmap_bh);
557 ext3_error(sb, __FUNCTION__, 557 ext4_error(sb, __FUNCTION__,
558 "bit already cleared for block "E3FSBLK, 558 "bit already cleared for block "E3FSBLK,
559 block + i); 559 block + i);
560 jbd_lock_bh_state(bitmap_bh); 560 jbd_lock_bh_state(bitmap_bh);
@@ -574,11 +574,11 @@ do_more:
574 574
575 /* We dirtied the bitmap block */ 575 /* We dirtied the bitmap block */
576 BUFFER_TRACE(bitmap_bh, "dirtied bitmap block"); 576 BUFFER_TRACE(bitmap_bh, "dirtied bitmap block");
577 err = ext3_journal_dirty_metadata(handle, bitmap_bh); 577 err = ext4_journal_dirty_metadata(handle, bitmap_bh);
578 578
579 /* And the group descriptor block */ 579 /* And the group descriptor block */
580 BUFFER_TRACE(gd_bh, "dirtied group descriptor block"); 580 BUFFER_TRACE(gd_bh, "dirtied group descriptor block");
581 ret = ext3_journal_dirty_metadata(handle, gd_bh); 581 ret = ext4_journal_dirty_metadata(handle, gd_bh);
582 if (!err) err = ret; 582 if (!err) err = ret;
583 *pdquot_freed_blocks += group_freed; 583 *pdquot_freed_blocks += group_freed;
584 584
@@ -590,40 +590,40 @@ do_more:
590 sb->s_dirt = 1; 590 sb->s_dirt = 1;
591error_return: 591error_return:
592 brelse(bitmap_bh); 592 brelse(bitmap_bh);
593 ext3_std_error(sb, err); 593 ext4_std_error(sb, err);
594 return; 594 return;
595} 595}
596 596
597/** 597/**
598 * ext3_free_blocks() -- Free given blocks and update quota 598 * ext4_free_blocks() -- Free given blocks and update quota
599 * @handle: handle for this transaction 599 * @handle: handle for this transaction
600 * @inode: inode 600 * @inode: inode
601 * @block: start physical block to free 601 * @block: start physical block to free
602 * @count: number of blocks to count 602 * @count: number of blocks to count
603 */ 603 */
604void ext3_free_blocks(handle_t *handle, struct inode *inode, 604void ext4_free_blocks(handle_t *handle, struct inode *inode,
605 ext3_fsblk_t block, unsigned long count) 605 ext4_fsblk_t block, unsigned long count)
606{ 606{
607 struct super_block * sb; 607 struct super_block * sb;
608 unsigned long dquot_freed_blocks; 608 unsigned long dquot_freed_blocks;
609 609
610 sb = inode->i_sb; 610 sb = inode->i_sb;
611 if (!sb) { 611 if (!sb) {
612 printk ("ext3_free_blocks: nonexistent device"); 612 printk ("ext4_free_blocks: nonexistent device");
613 return; 613 return;
614 } 614 }
615 ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks); 615 ext4_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
616 if (dquot_freed_blocks) 616 if (dquot_freed_blocks)
617 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks); 617 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
618 return; 618 return;
619} 619}
620 620
621/** 621/**
622 * ext3_test_allocatable() 622 * ext4_test_allocatable()
623 * @nr: given allocation block group 623 * @nr: given allocation block group
624 * @bh: bufferhead contains the bitmap of the given block group 624 * @bh: bufferhead contains the bitmap of the given block group
625 * 625 *
626 * For ext3 allocations, we must not reuse any blocks which are 626 * For ext4 allocations, we must not reuse any blocks which are
627 * allocated in the bitmap buffer's "last committed data" copy. This 627 * allocated in the bitmap buffer's "last committed data" copy. This
628 * prevents deletes from freeing up the page for reuse until we have 628 * prevents deletes from freeing up the page for reuse until we have
629 * committed the delete transaction. 629 * committed the delete transaction.
@@ -638,19 +638,19 @@ void ext3_free_blocks(handle_t *handle, struct inode *inode,
638 * data-writes at some point, and disable it for metadata allocations or 638 * data-writes at some point, and disable it for metadata allocations or
639 * sync-data inodes. 639 * sync-data inodes.
640 */ 640 */
641static int ext3_test_allocatable(ext3_grpblk_t nr, struct buffer_head *bh) 641static int ext4_test_allocatable(ext4_grpblk_t nr, struct buffer_head *bh)
642{ 642{
643 int ret; 643 int ret;
644 struct journal_head *jh = bh2jh(bh); 644 struct journal_head *jh = bh2jh(bh);
645 645
646 if (ext3_test_bit(nr, bh->b_data)) 646 if (ext4_test_bit(nr, bh->b_data))
647 return 0; 647 return 0;
648 648
649 jbd_lock_bh_state(bh); 649 jbd_lock_bh_state(bh);
650 if (!jh->b_committed_data) 650 if (!jh->b_committed_data)
651 ret = 1; 651 ret = 1;
652 else 652 else
653 ret = !ext3_test_bit(nr, jh->b_committed_data); 653 ret = !ext4_test_bit(nr, jh->b_committed_data);
654 jbd_unlock_bh_state(bh); 654 jbd_unlock_bh_state(bh);
655 return ret; 655 return ret;
656} 656}
@@ -665,22 +665,22 @@ static int ext3_test_allocatable(ext3_grpblk_t nr, struct buffer_head *bh)
665 * bitmap on disk and the last-committed copy in journal, until we find a 665 * bitmap on disk and the last-committed copy in journal, until we find a
666 * bit free in both bitmaps. 666 * bit free in both bitmaps.
667 */ 667 */
668static ext3_grpblk_t 668static ext4_grpblk_t
669bitmap_search_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh, 669bitmap_search_next_usable_block(ext4_grpblk_t start, struct buffer_head *bh,
670 ext3_grpblk_t maxblocks) 670 ext4_grpblk_t maxblocks)
671{ 671{
672 ext3_grpblk_t next; 672 ext4_grpblk_t next;
673 struct journal_head *jh = bh2jh(bh); 673 struct journal_head *jh = bh2jh(bh);
674 674
675 while (start < maxblocks) { 675 while (start < maxblocks) {
676 next = ext3_find_next_zero_bit(bh->b_data, maxblocks, start); 676 next = ext4_find_next_zero_bit(bh->b_data, maxblocks, start);
677 if (next >= maxblocks) 677 if (next >= maxblocks)
678 return -1; 678 return -1;
679 if (ext3_test_allocatable(next, bh)) 679 if (ext4_test_allocatable(next, bh))
680 return next; 680 return next;
681 jbd_lock_bh_state(bh); 681 jbd_lock_bh_state(bh);
682 if (jh->b_committed_data) 682 if (jh->b_committed_data)
683 start = ext3_find_next_zero_bit(jh->b_committed_data, 683 start = ext4_find_next_zero_bit(jh->b_committed_data,
684 maxblocks, next); 684 maxblocks, next);
685 jbd_unlock_bh_state(bh); 685 jbd_unlock_bh_state(bh);
686 } 686 }
@@ -700,11 +700,11 @@ bitmap_search_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh,
700 * the initial goal; then for a free byte somewhere in the bitmap; then 700 * the initial goal; then for a free byte somewhere in the bitmap; then
701 * for any free bit in the bitmap. 701 * for any free bit in the bitmap.
702 */ 702 */
703static ext3_grpblk_t 703static ext4_grpblk_t
704find_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh, 704find_next_usable_block(ext4_grpblk_t start, struct buffer_head *bh,
705 ext3_grpblk_t maxblocks) 705 ext4_grpblk_t maxblocks)
706{ 706{
707 ext3_grpblk_t here, next; 707 ext4_grpblk_t here, next;
708 char *p, *r; 708 char *p, *r;
709 709
710 if (start > 0) { 710 if (start > 0) {
@@ -713,16 +713,16 @@ find_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh,
713 * block within the next XX blocks. 713 * block within the next XX blocks.
714 * 714 *
715 * end_goal is more or less random, but it has to be 715 * end_goal is more or less random, but it has to be
716 * less than EXT3_BLOCKS_PER_GROUP. Aligning up to the 716 * less than EXT4_BLOCKS_PER_GROUP. Aligning up to the
717 * next 64-bit boundary is simple.. 717 * next 64-bit boundary is simple..
718 */ 718 */
719 ext3_grpblk_t end_goal = (start + 63) & ~63; 719 ext4_grpblk_t end_goal = (start + 63) & ~63;
720 if (end_goal > maxblocks) 720 if (end_goal > maxblocks)
721 end_goal = maxblocks; 721 end_goal = maxblocks;
722 here = ext3_find_next_zero_bit(bh->b_data, end_goal, start); 722 here = ext4_find_next_zero_bit(bh->b_data, end_goal, start);
723 if (here < end_goal && ext3_test_allocatable(here, bh)) 723 if (here < end_goal && ext4_test_allocatable(here, bh))
724 return here; 724 return here;
725 ext3_debug("Bit not found near goal\n"); 725 ext4_debug("Bit not found near goal\n");
726 } 726 }
727 727
728 here = start; 728 here = start;
@@ -733,7 +733,7 @@ find_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh,
733 r = memscan(p, 0, (maxblocks - here + 7) >> 3); 733 r = memscan(p, 0, (maxblocks - here + 7) >> 3);
734 next = (r - ((char *)bh->b_data)) << 3; 734 next = (r - ((char *)bh->b_data)) << 3;
735 735
736 if (next < maxblocks && next >= start && ext3_test_allocatable(next, bh)) 736 if (next < maxblocks && next >= start && ext4_test_allocatable(next, bh))
737 return next; 737 return next;
738 738
739 /* 739 /*
@@ -757,16 +757,16 @@ find_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh,
757 * zero (failure). 757 * zero (failure).
758 */ 758 */
759static inline int 759static inline int
760claim_block(spinlock_t *lock, ext3_grpblk_t block, struct buffer_head *bh) 760claim_block(spinlock_t *lock, ext4_grpblk_t block, struct buffer_head *bh)
761{ 761{
762 struct journal_head *jh = bh2jh(bh); 762 struct journal_head *jh = bh2jh(bh);
763 int ret; 763 int ret;
764 764
765 if (ext3_set_bit_atomic(lock, block, bh->b_data)) 765 if (ext4_set_bit_atomic(lock, block, bh->b_data))
766 return 0; 766 return 0;
767 jbd_lock_bh_state(bh); 767 jbd_lock_bh_state(bh);
768 if (jh->b_committed_data && ext3_test_bit(block,jh->b_committed_data)) { 768 if (jh->b_committed_data && ext4_test_bit(block,jh->b_committed_data)) {
769 ext3_clear_bit_atomic(lock, block, bh->b_data); 769 ext4_clear_bit_atomic(lock, block, bh->b_data);
770 ret = 0; 770 ret = 0;
771 } else { 771 } else {
772 ret = 1; 772 ret = 1;
@@ -776,7 +776,7 @@ claim_block(spinlock_t *lock, ext3_grpblk_t block, struct buffer_head *bh)
776} 776}
777 777
778/** 778/**
779 * ext3_try_to_allocate() 779 * ext4_try_to_allocate()
780 * @sb: superblock 780 * @sb: superblock
781 * @handle: handle to this transaction 781 * @handle: handle to this transaction
782 * @group: given allocation block group 782 * @group: given allocation block group
@@ -797,29 +797,29 @@ claim_block(spinlock_t *lock, ext3_grpblk_t block, struct buffer_head *bh)
797 * 797 *
798 * If we failed to allocate the desired block then we may end up crossing to a 798 * If we failed to allocate the desired block then we may end up crossing to a
799 * new bitmap. In that case we must release write access to the old one via 799 * new bitmap. In that case we must release write access to the old one via
800 * ext3_journal_release_buffer(), else we'll run out of credits. 800 * ext4_journal_release_buffer(), else we'll run out of credits.
801 */ 801 */
802static ext3_grpblk_t 802static ext4_grpblk_t
803ext3_try_to_allocate(struct super_block *sb, handle_t *handle, int group, 803ext4_try_to_allocate(struct super_block *sb, handle_t *handle, int group,
804 struct buffer_head *bitmap_bh, ext3_grpblk_t grp_goal, 804 struct buffer_head *bitmap_bh, ext4_grpblk_t grp_goal,
805 unsigned long *count, struct ext3_reserve_window *my_rsv) 805 unsigned long *count, struct ext4_reserve_window *my_rsv)
806{ 806{
807 ext3_fsblk_t group_first_block; 807 ext4_fsblk_t group_first_block;
808 ext3_grpblk_t start, end; 808 ext4_grpblk_t start, end;
809 unsigned long num = 0; 809 unsigned long num = 0;
810 810
811 /* we do allocation within the reservation window if we have a window */ 811 /* we do allocation within the reservation window if we have a window */
812 if (my_rsv) { 812 if (my_rsv) {
813 group_first_block = ext3_group_first_block_no(sb, group); 813 group_first_block = ext4_group_first_block_no(sb, group);
814 if (my_rsv->_rsv_start >= group_first_block) 814 if (my_rsv->_rsv_start >= group_first_block)
815 start = my_rsv->_rsv_start - group_first_block; 815 start = my_rsv->_rsv_start - group_first_block;
816 else 816 else
817 /* reservation window cross group boundary */ 817 /* reservation window cross group boundary */
818 start = 0; 818 start = 0;
819 end = my_rsv->_rsv_end - group_first_block + 1; 819 end = my_rsv->_rsv_end - group_first_block + 1;
820 if (end > EXT3_BLOCKS_PER_GROUP(sb)) 820 if (end > EXT4_BLOCKS_PER_GROUP(sb))
821 /* reservation window crosses group boundary */ 821 /* reservation window crosses group boundary */
822 end = EXT3_BLOCKS_PER_GROUP(sb); 822 end = EXT4_BLOCKS_PER_GROUP(sb);
823 if ((start <= grp_goal) && (grp_goal < end)) 823 if ((start <= grp_goal) && (grp_goal < end))
824 start = grp_goal; 824 start = grp_goal;
825 else 825 else
@@ -829,13 +829,13 @@ ext3_try_to_allocate(struct super_block *sb, handle_t *handle, int group,
829 start = grp_goal; 829 start = grp_goal;
830 else 830 else
831 start = 0; 831 start = 0;
832 end = EXT3_BLOCKS_PER_GROUP(sb); 832 end = EXT4_BLOCKS_PER_GROUP(sb);
833 } 833 }
834 834
835 BUG_ON(start > EXT3_BLOCKS_PER_GROUP(sb)); 835 BUG_ON(start > EXT4_BLOCKS_PER_GROUP(sb));
836 836
837repeat: 837repeat:
838 if (grp_goal < 0 || !ext3_test_allocatable(grp_goal, bitmap_bh)) { 838 if (grp_goal < 0 || !ext4_test_allocatable(grp_goal, bitmap_bh)) {
839 grp_goal = find_next_usable_block(start, bitmap_bh, end); 839 grp_goal = find_next_usable_block(start, bitmap_bh, end);
840 if (grp_goal < 0) 840 if (grp_goal < 0)
841 goto fail_access; 841 goto fail_access;
@@ -843,7 +843,7 @@ repeat:
843 int i; 843 int i;
844 844
845 for (i = 0; i < 7 && grp_goal > start && 845 for (i = 0; i < 7 && grp_goal > start &&
846 ext3_test_allocatable(grp_goal - 1, 846 ext4_test_allocatable(grp_goal - 1,
847 bitmap_bh); 847 bitmap_bh);
848 i++, grp_goal--) 848 i++, grp_goal--)
849 ; 849 ;
@@ -851,7 +851,7 @@ repeat:
851 } 851 }
852 start = grp_goal; 852 start = grp_goal;
853 853
854 if (!claim_block(sb_bgl_lock(EXT3_SB(sb), group), 854 if (!claim_block(sb_bgl_lock(EXT4_SB(sb), group),
855 grp_goal, bitmap_bh)) { 855 grp_goal, bitmap_bh)) {
856 /* 856 /*
857 * The block was allocated by another thread, or it was 857 * The block was allocated by another thread, or it was
@@ -866,8 +866,8 @@ repeat:
866 num++; 866 num++;
867 grp_goal++; 867 grp_goal++;
868 while (num < *count && grp_goal < end 868 while (num < *count && grp_goal < end
869 && ext3_test_allocatable(grp_goal, bitmap_bh) 869 && ext4_test_allocatable(grp_goal, bitmap_bh)
870 && claim_block(sb_bgl_lock(EXT3_SB(sb), group), 870 && claim_block(sb_bgl_lock(EXT4_SB(sb), group),
871 grp_goal, bitmap_bh)) { 871 grp_goal, bitmap_bh)) {
872 num++; 872 num++;
873 grp_goal++; 873 grp_goal++;
@@ -913,15 +913,15 @@ fail_access:
913 * 913 *
914 */ 914 */
915static int find_next_reservable_window( 915static int find_next_reservable_window(
916 struct ext3_reserve_window_node *search_head, 916 struct ext4_reserve_window_node *search_head,
917 struct ext3_reserve_window_node *my_rsv, 917 struct ext4_reserve_window_node *my_rsv,
918 struct super_block * sb, 918 struct super_block * sb,
919 ext3_fsblk_t start_block, 919 ext4_fsblk_t start_block,
920 ext3_fsblk_t last_block) 920 ext4_fsblk_t last_block)
921{ 921{
922 struct rb_node *next; 922 struct rb_node *next;
923 struct ext3_reserve_window_node *rsv, *prev; 923 struct ext4_reserve_window_node *rsv, *prev;
924 ext3_fsblk_t cur; 924 ext4_fsblk_t cur;
925 int size = my_rsv->rsv_goal_size; 925 int size = my_rsv->rsv_goal_size;
926 926
927 /* TODO: make the start of the reservation window byte-aligned */ 927 /* TODO: make the start of the reservation window byte-aligned */
@@ -949,7 +949,7 @@ static int find_next_reservable_window(
949 949
950 prev = rsv; 950 prev = rsv;
951 next = rb_next(&rsv->rsv_node); 951 next = rb_next(&rsv->rsv_node);
952 rsv = list_entry(next,struct ext3_reserve_window_node,rsv_node); 952 rsv = list_entry(next,struct ext4_reserve_window_node,rsv_node);
953 953
954 /* 954 /*
955 * Reached the last reservation, we can just append to the 955 * Reached the last reservation, we can just append to the
@@ -992,7 +992,7 @@ static int find_next_reservable_window(
992 my_rsv->rsv_alloc_hit = 0; 992 my_rsv->rsv_alloc_hit = 0;
993 993
994 if (prev != my_rsv) 994 if (prev != my_rsv)
995 ext3_rsv_window_add(sb, my_rsv); 995 ext4_rsv_window_add(sb, my_rsv);
996 996
997 return 0; 997 return 0;
998} 998}
@@ -1034,20 +1034,20 @@ static int find_next_reservable_window(
1034 * @bitmap_bh: the block group block bitmap 1034 * @bitmap_bh: the block group block bitmap
1035 * 1035 *
1036 */ 1036 */
1037static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv, 1037static int alloc_new_reservation(struct ext4_reserve_window_node *my_rsv,
1038 ext3_grpblk_t grp_goal, struct super_block *sb, 1038 ext4_grpblk_t grp_goal, struct super_block *sb,
1039 unsigned int group, struct buffer_head *bitmap_bh) 1039 unsigned int group, struct buffer_head *bitmap_bh)
1040{ 1040{
1041 struct ext3_reserve_window_node *search_head; 1041 struct ext4_reserve_window_node *search_head;
1042 ext3_fsblk_t group_first_block, group_end_block, start_block; 1042 ext4_fsblk_t group_first_block, group_end_block, start_block;
1043 ext3_grpblk_t first_free_block; 1043 ext4_grpblk_t first_free_block;
1044 struct rb_root *fs_rsv_root = &EXT3_SB(sb)->s_rsv_window_root; 1044 struct rb_root *fs_rsv_root = &EXT4_SB(sb)->s_rsv_window_root;
1045 unsigned long size; 1045 unsigned long size;
1046 int ret; 1046 int ret;
1047 spinlock_t *rsv_lock = &EXT3_SB(sb)->s_rsv_window_lock; 1047 spinlock_t *rsv_lock = &EXT4_SB(sb)->s_rsv_window_lock;
1048 1048
1049 group_first_block = ext3_group_first_block_no(sb, group); 1049 group_first_block = ext4_group_first_block_no(sb, group);
1050 group_end_block = group_first_block + (EXT3_BLOCKS_PER_GROUP(sb) - 1); 1050 group_end_block = group_first_block + (EXT4_BLOCKS_PER_GROUP(sb) - 1);
1051 1051
1052 if (grp_goal < 0) 1052 if (grp_goal < 0)
1053 start_block = group_first_block; 1053 start_block = group_first_block;
@@ -1085,8 +1085,8 @@ static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv,
1085 * otherwise we keep the same size window 1085 * otherwise we keep the same size window
1086 */ 1086 */
1087 size = size * 2; 1087 size = size * 2;
1088 if (size > EXT3_MAX_RESERVE_BLOCKS) 1088 if (size > EXT4_MAX_RESERVE_BLOCKS)
1089 size = EXT3_MAX_RESERVE_BLOCKS; 1089 size = EXT4_MAX_RESERVE_BLOCKS;
1090 my_rsv->rsv_goal_size= size; 1090 my_rsv->rsv_goal_size= size;
1091 } 1091 }
1092 } 1092 }
@@ -1170,20 +1170,20 @@ retry:
1170 * Attempt to expand the reservation window large enough to have 1170 * Attempt to expand the reservation window large enough to have
1171 * required number of free blocks 1171 * required number of free blocks
1172 * 1172 *
1173 * Since ext3_try_to_allocate() will always allocate blocks within 1173 * Since ext4_try_to_allocate() will always allocate blocks within
1174 * the reservation window range, if the window size is too small, 1174 * the reservation window range, if the window size is too small,
1175 * multiple blocks allocation has to stop at the end of the reservation 1175 * multiple blocks allocation has to stop at the end of the reservation
1176 * window. To make this more efficient, given the total number of 1176 * window. To make this more efficient, given the total number of
1177 * blocks needed and the current size of the window, we try to 1177 * blocks needed and the current size of the window, we try to
1178 * expand the reservation window size if necessary on a best-effort 1178 * expand the reservation window size if necessary on a best-effort
1179 * basis before ext3_new_blocks() tries to allocate blocks, 1179 * basis before ext4_new_blocks() tries to allocate blocks,
1180 */ 1180 */
1181static void try_to_extend_reservation(struct ext3_reserve_window_node *my_rsv, 1181static void try_to_extend_reservation(struct ext4_reserve_window_node *my_rsv,
1182 struct super_block *sb, int size) 1182 struct super_block *sb, int size)
1183{ 1183{
1184 struct ext3_reserve_window_node *next_rsv; 1184 struct ext4_reserve_window_node *next_rsv;
1185 struct rb_node *next; 1185 struct rb_node *next;
1186 spinlock_t *rsv_lock = &EXT3_SB(sb)->s_rsv_window_lock; 1186 spinlock_t *rsv_lock = &EXT4_SB(sb)->s_rsv_window_lock;
1187 1187
1188 if (!spin_trylock(rsv_lock)) 1188 if (!spin_trylock(rsv_lock))
1189 return; 1189 return;
@@ -1193,7 +1193,7 @@ static void try_to_extend_reservation(struct ext3_reserve_window_node *my_rsv,
1193 if (!next) 1193 if (!next)
1194 my_rsv->rsv_end += size; 1194 my_rsv->rsv_end += size;
1195 else { 1195 else {
1196 next_rsv = list_entry(next, struct ext3_reserve_window_node, rsv_node); 1196 next_rsv = list_entry(next, struct ext4_reserve_window_node, rsv_node);
1197 1197
1198 if ((next_rsv->rsv_start - my_rsv->rsv_end - 1) >= size) 1198 if ((next_rsv->rsv_start - my_rsv->rsv_end - 1) >= size)
1199 my_rsv->rsv_end += size; 1199 my_rsv->rsv_end += size;
@@ -1204,7 +1204,7 @@ static void try_to_extend_reservation(struct ext3_reserve_window_node *my_rsv,
1204} 1204}
1205 1205
1206/** 1206/**
1207 * ext3_try_to_allocate_with_rsv() 1207 * ext4_try_to_allocate_with_rsv()
1208 * @sb: superblock 1208 * @sb: superblock
1209 * @handle: handle to this transaction 1209 * @handle: handle to this transaction
1210 * @group: given allocation block group 1210 * @group: given allocation block group
@@ -1232,15 +1232,15 @@ static void try_to_extend_reservation(struct ext3_reserve_window_node *my_rsv,
1232 * We use a red-black tree for the per-filesystem reservation list. 1232 * We use a red-black tree for the per-filesystem reservation list.
1233 * 1233 *
1234 */ 1234 */
1235static ext3_grpblk_t 1235static ext4_grpblk_t
1236ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle, 1236ext4_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
1237 unsigned int group, struct buffer_head *bitmap_bh, 1237 unsigned int group, struct buffer_head *bitmap_bh,
1238 ext3_grpblk_t grp_goal, 1238 ext4_grpblk_t grp_goal,
1239 struct ext3_reserve_window_node * my_rsv, 1239 struct ext4_reserve_window_node * my_rsv,
1240 unsigned long *count, int *errp) 1240 unsigned long *count, int *errp)
1241{ 1241{
1242 ext3_fsblk_t group_first_block, group_last_block; 1242 ext4_fsblk_t group_first_block, group_last_block;
1243 ext3_grpblk_t ret = 0; 1243 ext4_grpblk_t ret = 0;
1244 int fatal; 1244 int fatal;
1245 unsigned long num = *count; 1245 unsigned long num = *count;
1246 1246
@@ -1252,7 +1252,7 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
1252 * if the buffer is in BJ_Forget state in the committing transaction. 1252 * if the buffer is in BJ_Forget state in the committing transaction.
1253 */ 1253 */
1254 BUFFER_TRACE(bitmap_bh, "get undo access for new block"); 1254 BUFFER_TRACE(bitmap_bh, "get undo access for new block");
1255 fatal = ext3_journal_get_undo_access(handle, bitmap_bh); 1255 fatal = ext4_journal_get_undo_access(handle, bitmap_bh);
1256 if (fatal) { 1256 if (fatal) {
1257 *errp = fatal; 1257 *errp = fatal;
1258 return -1; 1258 return -1;
@@ -1265,18 +1265,18 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
1265 * or last attempt to allocate a block with reservation turned on failed 1265 * or last attempt to allocate a block with reservation turned on failed
1266 */ 1266 */
1267 if (my_rsv == NULL ) { 1267 if (my_rsv == NULL ) {
1268 ret = ext3_try_to_allocate(sb, handle, group, bitmap_bh, 1268 ret = ext4_try_to_allocate(sb, handle, group, bitmap_bh,
1269 grp_goal, count, NULL); 1269 grp_goal, count, NULL);
1270 goto out; 1270 goto out;
1271 } 1271 }
1272 /* 1272 /*
1273 * grp_goal is a group relative block number (if there is a goal) 1273 * grp_goal is a group relative block number (if there is a goal)
1274 * 0 < grp_goal < EXT3_BLOCKS_PER_GROUP(sb) 1274 * 0 < grp_goal < EXT4_BLOCKS_PER_GROUP(sb)
1275 * first block is a filesystem wide block number 1275 * first block is a filesystem wide block number
1276 * first block is the block number of the first block in this group 1276 * first block is the block number of the first block in this group
1277 */ 1277 */
1278 group_first_block = ext3_group_first_block_no(sb, group); 1278 group_first_block = ext4_group_first_block_no(sb, group);
1279 group_last_block = group_first_block + (EXT3_BLOCKS_PER_GROUP(sb) - 1); 1279 group_last_block = group_first_block + (EXT4_BLOCKS_PER_GROUP(sb) - 1);
1280 1280
1281 /* 1281 /*
1282 * Basically we will allocate a new block from inode's reservation 1282 * Basically we will allocate a new block from inode's reservation
@@ -1314,10 +1314,10 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
1314 1314
1315 if ((my_rsv->rsv_start > group_last_block) || 1315 if ((my_rsv->rsv_start > group_last_block) ||
1316 (my_rsv->rsv_end < group_first_block)) { 1316 (my_rsv->rsv_end < group_first_block)) {
1317 rsv_window_dump(&EXT3_SB(sb)->s_rsv_window_root, 1); 1317 rsv_window_dump(&EXT4_SB(sb)->s_rsv_window_root, 1);
1318 BUG(); 1318 BUG();
1319 } 1319 }
1320 ret = ext3_try_to_allocate(sb, handle, group, bitmap_bh, 1320 ret = ext4_try_to_allocate(sb, handle, group, bitmap_bh,
1321 grp_goal, &num, &my_rsv->rsv_window); 1321 grp_goal, &num, &my_rsv->rsv_window);
1322 if (ret >= 0) { 1322 if (ret >= 0) {
1323 my_rsv->rsv_alloc_hit += num; 1323 my_rsv->rsv_alloc_hit += num;
@@ -1330,7 +1330,7 @@ out:
1330 if (ret >= 0) { 1330 if (ret >= 0) {
1331 BUFFER_TRACE(bitmap_bh, "journal_dirty_metadata for " 1331 BUFFER_TRACE(bitmap_bh, "journal_dirty_metadata for "
1332 "bitmap block"); 1332 "bitmap block");
1333 fatal = ext3_journal_dirty_metadata(handle, bitmap_bh); 1333 fatal = ext4_journal_dirty_metadata(handle, bitmap_bh);
1334 if (fatal) { 1334 if (fatal) {
1335 *errp = fatal; 1335 *errp = fatal;
1336 return -1; 1336 return -1;
@@ -1339,19 +1339,19 @@ out:
1339 } 1339 }
1340 1340
1341 BUFFER_TRACE(bitmap_bh, "journal_release_buffer"); 1341 BUFFER_TRACE(bitmap_bh, "journal_release_buffer");
1342 ext3_journal_release_buffer(handle, bitmap_bh); 1342 ext4_journal_release_buffer(handle, bitmap_bh);
1343 return ret; 1343 return ret;
1344} 1344}
1345 1345
1346/** 1346/**
1347 * ext3_has_free_blocks() 1347 * ext4_has_free_blocks()
1348 * @sbi: in-core super block structure. 1348 * @sbi: in-core super block structure.
1349 * 1349 *
1350 * Check if filesystem has at least 1 free block available for allocation. 1350 * Check if filesystem has at least 1 free block available for allocation.
1351 */ 1351 */
1352static int ext3_has_free_blocks(struct ext3_sb_info *sbi) 1352static int ext4_has_free_blocks(struct ext4_sb_info *sbi)
1353{ 1353{
1354 ext3_fsblk_t free_blocks, root_blocks; 1354 ext4_fsblk_t free_blocks, root_blocks;
1355 1355
1356 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter); 1356 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
1357 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count); 1357 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
@@ -1364,63 +1364,63 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
1364} 1364}
1365 1365
1366/** 1366/**
1367 * ext3_should_retry_alloc() 1367 * ext4_should_retry_alloc()
1368 * @sb: super block 1368 * @sb: super block
1369 * @retries number of attemps has been made 1369 * @retries number of attemps has been made
1370 * 1370 *
1371 * ext3_should_retry_alloc() is called when ENOSPC is returned, and if 1371 * ext4_should_retry_alloc() is called when ENOSPC is returned, and if
1372 * it is profitable to retry the operation, this function will wait 1372 * it is profitable to retry the operation, this function will wait
1373 * for the current or commiting transaction to complete, and then 1373 * for the current or commiting transaction to complete, and then
1374 * return TRUE. 1374 * return TRUE.
1375 * 1375 *
1376 * if the total number of retries exceed three times, return FALSE. 1376 * if the total number of retries exceed three times, return FALSE.
1377 */ 1377 */
1378int ext3_should_retry_alloc(struct super_block *sb, int *retries) 1378int ext4_should_retry_alloc(struct super_block *sb, int *retries)
1379{ 1379{
1380 if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3) 1380 if (!ext4_has_free_blocks(EXT4_SB(sb)) || (*retries)++ > 3)
1381 return 0; 1381 return 0;
1382 1382
1383 jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id); 1383 jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
1384 1384
1385 return journal_force_commit_nested(EXT3_SB(sb)->s_journal); 1385 return journal_force_commit_nested(EXT4_SB(sb)->s_journal);
1386} 1386}
1387 1387
1388/** 1388/**
1389 * ext3_new_blocks() -- core block(s) allocation function 1389 * ext4_new_blocks() -- core block(s) allocation function
1390 * @handle: handle to this transaction 1390 * @handle: handle to this transaction
1391 * @inode: file inode 1391 * @inode: file inode
1392 * @goal: given target block(filesystem wide) 1392 * @goal: given target block(filesystem wide)
1393 * @count: target number of blocks to allocate 1393 * @count: target number of blocks to allocate
1394 * @errp: error code 1394 * @errp: error code
1395 * 1395 *
1396 * ext3_new_blocks uses a goal block to assist allocation. It tries to 1396 * ext4_new_blocks uses a goal block to assist allocation. It tries to
1397 * allocate block(s) from the block group contains the goal block first. If that 1397 * allocate block(s) from the block group contains the goal block first. If that
1398 * fails, it will try to allocate block(s) from other block groups without 1398 * fails, it will try to allocate block(s) from other block groups without
1399 * any specific goal block. 1399 * any specific goal block.
1400 * 1400 *
1401 */ 1401 */
1402ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode, 1402ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
1403 ext3_fsblk_t goal, unsigned long *count, int *errp) 1403 ext4_fsblk_t goal, unsigned long *count, int *errp)
1404{ 1404{
1405 struct buffer_head *bitmap_bh = NULL; 1405 struct buffer_head *bitmap_bh = NULL;
1406 struct buffer_head *gdp_bh; 1406 struct buffer_head *gdp_bh;
1407 int group_no; 1407 int group_no;
1408 int goal_group; 1408 int goal_group;
1409 ext3_grpblk_t grp_target_blk; /* blockgroup relative goal block */ 1409 ext4_grpblk_t grp_target_blk; /* blockgroup relative goal block */
1410 ext3_grpblk_t grp_alloc_blk; /* blockgroup-relative allocated block*/ 1410 ext4_grpblk_t grp_alloc_blk; /* blockgroup-relative allocated block*/
1411 ext3_fsblk_t ret_block; /* filesyetem-wide allocated block */ 1411 ext4_fsblk_t ret_block; /* filesyetem-wide allocated block */
1412 int bgi; /* blockgroup iteration index */ 1412 int bgi; /* blockgroup iteration index */
1413 int fatal = 0, err; 1413 int fatal = 0, err;
1414 int performed_allocation = 0; 1414 int performed_allocation = 0;
1415 ext3_grpblk_t free_blocks; /* number of free blocks in a group */ 1415 ext4_grpblk_t free_blocks; /* number of free blocks in a group */
1416 struct super_block *sb; 1416 struct super_block *sb;
1417 struct ext3_group_desc *gdp; 1417 struct ext4_group_desc *gdp;
1418 struct ext3_super_block *es; 1418 struct ext4_super_block *es;
1419 struct ext3_sb_info *sbi; 1419 struct ext4_sb_info *sbi;
1420 struct ext3_reserve_window_node *my_rsv = NULL; 1420 struct ext4_reserve_window_node *my_rsv = NULL;
1421 struct ext3_block_alloc_info *block_i; 1421 struct ext4_block_alloc_info *block_i;
1422 unsigned short windowsz = 0; 1422 unsigned short windowsz = 0;
1423#ifdef EXT3FS_DEBUG 1423#ifdef EXT4FS_DEBUG
1424 static int goal_hits, goal_attempts; 1424 static int goal_hits, goal_attempts;
1425#endif 1425#endif
1426 unsigned long ngroups; 1426 unsigned long ngroups;
@@ -1429,7 +1429,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
1429 *errp = -ENOSPC; 1429 *errp = -ENOSPC;
1430 sb = inode->i_sb; 1430 sb = inode->i_sb;
1431 if (!sb) { 1431 if (!sb) {
1432 printk("ext3_new_block: nonexistent device"); 1432 printk("ext4_new_block: nonexistent device");
1433 return 0; 1433 return 0;
1434 } 1434 }
1435 1435
@@ -1441,22 +1441,22 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
1441 return 0; 1441 return 0;
1442 } 1442 }
1443 1443
1444 sbi = EXT3_SB(sb); 1444 sbi = EXT4_SB(sb);
1445 es = EXT3_SB(sb)->s_es; 1445 es = EXT4_SB(sb)->s_es;
1446 ext3_debug("goal=%lu.\n", goal); 1446 ext4_debug("goal=%lu.\n", goal);
1447 /* 1447 /*
1448 * Allocate a block from reservation only when 1448 * Allocate a block from reservation only when
1449 * filesystem is mounted with reservation(default,-o reservation), and 1449 * filesystem is mounted with reservation(default,-o reservation), and
1450 * it's a regular file, and 1450 * it's a regular file, and
1451 * the desired window size is greater than 0 (One could use ioctl 1451 * the desired window size is greater than 0 (One could use ioctl
1452 * command EXT3_IOC_SETRSVSZ to set the window size to 0 to turn off 1452 * command EXT4_IOC_SETRSVSZ to set the window size to 0 to turn off
1453 * reservation on that particular file) 1453 * reservation on that particular file)
1454 */ 1454 */
1455 block_i = EXT3_I(inode)->i_block_alloc_info; 1455 block_i = EXT4_I(inode)->i_block_alloc_info;
1456 if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0)) 1456 if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
1457 my_rsv = &block_i->rsv_window_node; 1457 my_rsv = &block_i->rsv_window_node;
1458 1458
1459 if (!ext3_has_free_blocks(sbi)) { 1459 if (!ext4_has_free_blocks(sbi)) {
1460 *errp = -ENOSPC; 1460 *errp = -ENOSPC;
1461 goto out; 1461 goto out;
1462 } 1462 }
@@ -1468,10 +1468,10 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
1468 goal >= le32_to_cpu(es->s_blocks_count)) 1468 goal >= le32_to_cpu(es->s_blocks_count))
1469 goal = le32_to_cpu(es->s_first_data_block); 1469 goal = le32_to_cpu(es->s_first_data_block);
1470 group_no = (goal - le32_to_cpu(es->s_first_data_block)) / 1470 group_no = (goal - le32_to_cpu(es->s_first_data_block)) /
1471 EXT3_BLOCKS_PER_GROUP(sb); 1471 EXT4_BLOCKS_PER_GROUP(sb);
1472 goal_group = group_no; 1472 goal_group = group_no;
1473retry_alloc: 1473retry_alloc:
1474 gdp = ext3_get_group_desc(sb, group_no, &gdp_bh); 1474 gdp = ext4_get_group_desc(sb, group_no, &gdp_bh);
1475 if (!gdp) 1475 if (!gdp)
1476 goto io_error; 1476 goto io_error;
1477 1477
@@ -1486,11 +1486,11 @@ retry_alloc:
1486 1486
1487 if (free_blocks > 0) { 1487 if (free_blocks > 0) {
1488 grp_target_blk = ((goal - le32_to_cpu(es->s_first_data_block)) % 1488 grp_target_blk = ((goal - le32_to_cpu(es->s_first_data_block)) %
1489 EXT3_BLOCKS_PER_GROUP(sb)); 1489 EXT4_BLOCKS_PER_GROUP(sb));
1490 bitmap_bh = read_block_bitmap(sb, group_no); 1490 bitmap_bh = read_block_bitmap(sb, group_no);
1491 if (!bitmap_bh) 1491 if (!bitmap_bh)
1492 goto io_error; 1492 goto io_error;
1493 grp_alloc_blk = ext3_try_to_allocate_with_rsv(sb, handle, 1493 grp_alloc_blk = ext4_try_to_allocate_with_rsv(sb, handle,
1494 group_no, bitmap_bh, grp_target_blk, 1494 group_no, bitmap_bh, grp_target_blk,
1495 my_rsv, &num, &fatal); 1495 my_rsv, &num, &fatal);
1496 if (fatal) 1496 if (fatal)
@@ -1499,7 +1499,7 @@ retry_alloc:
1499 goto allocated; 1499 goto allocated;
1500 } 1500 }
1501 1501
1502 ngroups = EXT3_SB(sb)->s_groups_count; 1502 ngroups = EXT4_SB(sb)->s_groups_count;
1503 smp_rmb(); 1503 smp_rmb();
1504 1504
1505 /* 1505 /*
@@ -1510,7 +1510,7 @@ retry_alloc:
1510 group_no++; 1510 group_no++;
1511 if (group_no >= ngroups) 1511 if (group_no >= ngroups)
1512 group_no = 0; 1512 group_no = 0;
1513 gdp = ext3_get_group_desc(sb, group_no, &gdp_bh); 1513 gdp = ext4_get_group_desc(sb, group_no, &gdp_bh);
1514 if (!gdp) { 1514 if (!gdp) {
1515 *errp = -EIO; 1515 *errp = -EIO;
1516 goto out; 1516 goto out;
@@ -1531,7 +1531,7 @@ retry_alloc:
1531 /* 1531 /*
1532 * try to allocate block(s) from this group, without a goal(-1). 1532 * try to allocate block(s) from this group, without a goal(-1).
1533 */ 1533 */
1534 grp_alloc_blk = ext3_try_to_allocate_with_rsv(sb, handle, 1534 grp_alloc_blk = ext4_try_to_allocate_with_rsv(sb, handle,
1535 group_no, bitmap_bh, -1, my_rsv, 1535 group_no, bitmap_bh, -1, my_rsv,
1536 &num, &fatal); 1536 &num, &fatal);
1537 if (fatal) 1537 if (fatal)
@@ -1557,23 +1557,23 @@ retry_alloc:
1557 1557
1558allocated: 1558allocated:
1559 1559
1560 ext3_debug("using block group %d(%d)\n", 1560 ext4_debug("using block group %d(%d)\n",
1561 group_no, gdp->bg_free_blocks_count); 1561 group_no, gdp->bg_free_blocks_count);
1562 1562
1563 BUFFER_TRACE(gdp_bh, "get_write_access"); 1563 BUFFER_TRACE(gdp_bh, "get_write_access");
1564 fatal = ext3_journal_get_write_access(handle, gdp_bh); 1564 fatal = ext4_journal_get_write_access(handle, gdp_bh);
1565 if (fatal) 1565 if (fatal)
1566 goto out; 1566 goto out;
1567 1567
1568 ret_block = grp_alloc_blk + ext3_group_first_block_no(sb, group_no); 1568 ret_block = grp_alloc_blk + ext4_group_first_block_no(sb, group_no);
1569 1569
1570 if (in_range(le32_to_cpu(gdp->bg_block_bitmap), ret_block, num) || 1570 if (in_range(le32_to_cpu(gdp->bg_block_bitmap), ret_block, num) ||
1571 in_range(le32_to_cpu(gdp->bg_inode_bitmap), ret_block, num) || 1571 in_range(le32_to_cpu(gdp->bg_inode_bitmap), ret_block, num) ||
1572 in_range(ret_block, le32_to_cpu(gdp->bg_inode_table), 1572 in_range(ret_block, le32_to_cpu(gdp->bg_inode_table),
1573 EXT3_SB(sb)->s_itb_per_group) || 1573 EXT4_SB(sb)->s_itb_per_group) ||
1574 in_range(ret_block + num - 1, le32_to_cpu(gdp->bg_inode_table), 1574 in_range(ret_block + num - 1, le32_to_cpu(gdp->bg_inode_table),
1575 EXT3_SB(sb)->s_itb_per_group)) 1575 EXT4_SB(sb)->s_itb_per_group))
1576 ext3_error(sb, "ext3_new_block", 1576 ext4_error(sb, "ext4_new_block",
1577 "Allocating block in system zone - " 1577 "Allocating block in system zone - "
1578 "blocks from "E3FSBLK", length %lu", 1578 "blocks from "E3FSBLK", length %lu",
1579 ret_block, num); 1579 ret_block, num);
@@ -1598,20 +1598,20 @@ allocated:
1598 int i; 1598 int i;
1599 1599
1600 for (i = 0; i < num; i++) { 1600 for (i = 0; i < num; i++) {
1601 if (ext3_test_bit(grp_alloc_blk+i, 1601 if (ext4_test_bit(grp_alloc_blk+i,
1602 bh2jh(bitmap_bh)->b_committed_data)) { 1602 bh2jh(bitmap_bh)->b_committed_data)) {
1603 printk("%s: block was unexpectedly set in " 1603 printk("%s: block was unexpectedly set in "
1604 "b_committed_data\n", __FUNCTION__); 1604 "b_committed_data\n", __FUNCTION__);
1605 } 1605 }
1606 } 1606 }
1607 } 1607 }
1608 ext3_debug("found bit %d\n", grp_alloc_blk); 1608 ext4_debug("found bit %d\n", grp_alloc_blk);
1609 spin_unlock(sb_bgl_lock(sbi, group_no)); 1609 spin_unlock(sb_bgl_lock(sbi, group_no));
1610 jbd_unlock_bh_state(bitmap_bh); 1610 jbd_unlock_bh_state(bitmap_bh);
1611#endif 1611#endif
1612 1612
1613 if (ret_block + num - 1 >= le32_to_cpu(es->s_blocks_count)) { 1613 if (ret_block + num - 1 >= le32_to_cpu(es->s_blocks_count)) {
1614 ext3_error(sb, "ext3_new_block", 1614 ext4_error(sb, "ext4_new_block",
1615 "block("E3FSBLK") >= blocks count(%d) - " 1615 "block("E3FSBLK") >= blocks count(%d) - "
1616 "block_group = %d, es == %p ", ret_block, 1616 "block_group = %d, es == %p ", ret_block,
1617 le32_to_cpu(es->s_blocks_count), group_no, es); 1617 le32_to_cpu(es->s_blocks_count), group_no, es);
@@ -1623,7 +1623,7 @@ allocated:
1623 * list of some description. We don't know in advance whether 1623 * list of some description. We don't know in advance whether
1624 * the caller wants to use it as metadata or data. 1624 * the caller wants to use it as metadata or data.
1625 */ 1625 */
1626 ext3_debug("allocating block %lu. Goal hits %d of %d.\n", 1626 ext4_debug("allocating block %lu. Goal hits %d of %d.\n",
1627 ret_block, goal_hits, goal_attempts); 1627 ret_block, goal_hits, goal_attempts);
1628 1628
1629 spin_lock(sb_bgl_lock(sbi, group_no)); 1629 spin_lock(sb_bgl_lock(sbi, group_no));
@@ -1633,7 +1633,7 @@ allocated:
1633 percpu_counter_mod(&sbi->s_freeblocks_counter, -num); 1633 percpu_counter_mod(&sbi->s_freeblocks_counter, -num);
1634 1634
1635 BUFFER_TRACE(gdp_bh, "journal_dirty_metadata for group descriptor"); 1635 BUFFER_TRACE(gdp_bh, "journal_dirty_metadata for group descriptor");
1636 err = ext3_journal_dirty_metadata(handle, gdp_bh); 1636 err = ext4_journal_dirty_metadata(handle, gdp_bh);
1637 if (!fatal) 1637 if (!fatal)
1638 fatal = err; 1638 fatal = err;
1639 1639
@@ -1652,7 +1652,7 @@ io_error:
1652out: 1652out:
1653 if (fatal) { 1653 if (fatal) {
1654 *errp = fatal; 1654 *errp = fatal;
1655 ext3_std_error(sb, fatal); 1655 ext4_std_error(sb, fatal);
1656 } 1656 }
1657 /* 1657 /*
1658 * Undo the block allocation 1658 * Undo the block allocation
@@ -1663,40 +1663,40 @@ out:
1663 return 0; 1663 return 0;
1664} 1664}
1665 1665
1666ext3_fsblk_t ext3_new_block(handle_t *handle, struct inode *inode, 1666ext4_fsblk_t ext4_new_block(handle_t *handle, struct inode *inode,
1667 ext3_fsblk_t goal, int *errp) 1667 ext4_fsblk_t goal, int *errp)
1668{ 1668{
1669 unsigned long count = 1; 1669 unsigned long count = 1;
1670 1670
1671 return ext3_new_blocks(handle, inode, goal, &count, errp); 1671 return ext4_new_blocks(handle, inode, goal, &count, errp);
1672} 1672}
1673 1673
1674/** 1674/**
1675 * ext3_count_free_blocks() -- count filesystem free blocks 1675 * ext4_count_free_blocks() -- count filesystem free blocks
1676 * @sb: superblock 1676 * @sb: superblock
1677 * 1677 *
1678 * Adds up the number of free blocks from each block group. 1678 * Adds up the number of free blocks from each block group.
1679 */ 1679 */
1680ext3_fsblk_t ext3_count_free_blocks(struct super_block *sb) 1680ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)
1681{ 1681{
1682 ext3_fsblk_t desc_count; 1682 ext4_fsblk_t desc_count;
1683 struct ext3_group_desc *gdp; 1683 struct ext4_group_desc *gdp;
1684 int i; 1684 int i;
1685 unsigned long ngroups = EXT3_SB(sb)->s_groups_count; 1685 unsigned long ngroups = EXT4_SB(sb)->s_groups_count;
1686#ifdef EXT3FS_DEBUG 1686#ifdef EXT4FS_DEBUG
1687 struct ext3_super_block *es; 1687 struct ext4_super_block *es;
1688 ext3_fsblk_t bitmap_count; 1688 ext4_fsblk_t bitmap_count;
1689 unsigned long x; 1689 unsigned long x;
1690 struct buffer_head *bitmap_bh = NULL; 1690 struct buffer_head *bitmap_bh = NULL;
1691 1691
1692 es = EXT3_SB(sb)->s_es; 1692 es = EXT4_SB(sb)->s_es;
1693 desc_count = 0; 1693 desc_count = 0;
1694 bitmap_count = 0; 1694 bitmap_count = 0;
1695 gdp = NULL; 1695 gdp = NULL;
1696 1696
1697 smp_rmb(); 1697 smp_rmb();
1698 for (i = 0; i < ngroups; i++) { 1698 for (i = 0; i < ngroups; i++) {
1699 gdp = ext3_get_group_desc(sb, i, NULL); 1699 gdp = ext4_get_group_desc(sb, i, NULL);
1700 if (!gdp) 1700 if (!gdp)
1701 continue; 1701 continue;
1702 desc_count += le16_to_cpu(gdp->bg_free_blocks_count); 1702 desc_count += le16_to_cpu(gdp->bg_free_blocks_count);
@@ -1705,13 +1705,13 @@ ext3_fsblk_t ext3_count_free_blocks(struct super_block *sb)
1705 if (bitmap_bh == NULL) 1705 if (bitmap_bh == NULL)
1706 continue; 1706 continue;
1707 1707
1708 x = ext3_count_free(bitmap_bh, sb->s_blocksize); 1708 x = ext4_count_free(bitmap_bh, sb->s_blocksize);
1709 printk("group %d: stored = %d, counted = %lu\n", 1709 printk("group %d: stored = %d, counted = %lu\n",
1710 i, le16_to_cpu(gdp->bg_free_blocks_count), x); 1710 i, le16_to_cpu(gdp->bg_free_blocks_count), x);
1711 bitmap_count += x; 1711 bitmap_count += x;
1712 } 1712 }
1713 brelse(bitmap_bh); 1713 brelse(bitmap_bh);
1714 printk("ext3_count_free_blocks: stored = "E3FSBLK 1714 printk("ext4_count_free_blocks: stored = "E3FSBLK
1715 ", computed = "E3FSBLK", "E3FSBLK"\n", 1715 ", computed = "E3FSBLK", "E3FSBLK"\n",
1716 le32_to_cpu(es->s_free_blocks_count), 1716 le32_to_cpu(es->s_free_blocks_count),
1717 desc_count, bitmap_count); 1717 desc_count, bitmap_count);
@@ -1720,7 +1720,7 @@ ext3_fsblk_t ext3_count_free_blocks(struct super_block *sb)
1720 desc_count = 0; 1720 desc_count = 0;
1721 smp_rmb(); 1721 smp_rmb();
1722 for (i = 0; i < ngroups; i++) { 1722 for (i = 0; i < ngroups; i++) {
1723 gdp = ext3_get_group_desc(sb, i, NULL); 1723 gdp = ext4_get_group_desc(sb, i, NULL);
1724 if (!gdp) 1724 if (!gdp)
1725 continue; 1725 continue;
1726 desc_count += le16_to_cpu(gdp->bg_free_blocks_count); 1726 desc_count += le16_to_cpu(gdp->bg_free_blocks_count);
@@ -1731,11 +1731,11 @@ ext3_fsblk_t ext3_count_free_blocks(struct super_block *sb)
1731} 1731}
1732 1732
1733static inline int 1733static inline int
1734block_in_use(ext3_fsblk_t block, struct super_block *sb, unsigned char *map) 1734block_in_use(ext4_fsblk_t block, struct super_block *sb, unsigned char *map)
1735{ 1735{
1736 return ext3_test_bit ((block - 1736 return ext4_test_bit ((block -
1737 le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block)) % 1737 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) %
1738 EXT3_BLOCKS_PER_GROUP(sb), map); 1738 EXT4_BLOCKS_PER_GROUP(sb), map);
1739} 1739}
1740 1740
1741static inline int test_root(int a, int b) 1741static inline int test_root(int a, int b)
@@ -1747,7 +1747,7 @@ static inline int test_root(int a, int b)
1747 return num == a; 1747 return num == a;
1748} 1748}
1749 1749
1750static int ext3_group_sparse(int group) 1750static int ext4_group_sparse(int group)
1751{ 1751{
1752 if (group <= 1) 1752 if (group <= 1)
1753 return 1; 1753 return 1;
@@ -1758,44 +1758,44 @@ static int ext3_group_sparse(int group)
1758} 1758}
1759 1759
1760/** 1760/**
1761 * ext3_bg_has_super - number of blocks used by the superblock in group 1761 * ext4_bg_has_super - number of blocks used by the superblock in group
1762 * @sb: superblock for filesystem 1762 * @sb: superblock for filesystem
1763 * @group: group number to check 1763 * @group: group number to check
1764 * 1764 *
1765 * Return the number of blocks used by the superblock (primary or backup) 1765 * Return the number of blocks used by the superblock (primary or backup)
1766 * in this group. Currently this will be only 0 or 1. 1766 * in this group. Currently this will be only 0 or 1.
1767 */ 1767 */
1768int ext3_bg_has_super(struct super_block *sb, int group) 1768int ext4_bg_has_super(struct super_block *sb, int group)
1769{ 1769{
1770 if (EXT3_HAS_RO_COMPAT_FEATURE(sb, 1770 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
1771 EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER) && 1771 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
1772 !ext3_group_sparse(group)) 1772 !ext4_group_sparse(group))
1773 return 0; 1773 return 0;
1774 return 1; 1774 return 1;
1775} 1775}
1776 1776
1777static unsigned long ext3_bg_num_gdb_meta(struct super_block *sb, int group) 1777static unsigned long ext4_bg_num_gdb_meta(struct super_block *sb, int group)
1778{ 1778{
1779 unsigned long metagroup = group / EXT3_DESC_PER_BLOCK(sb); 1779 unsigned long metagroup = group / EXT4_DESC_PER_BLOCK(sb);
1780 unsigned long first = metagroup * EXT3_DESC_PER_BLOCK(sb); 1780 unsigned long first = metagroup * EXT4_DESC_PER_BLOCK(sb);
1781 unsigned long last = first + EXT3_DESC_PER_BLOCK(sb) - 1; 1781 unsigned long last = first + EXT4_DESC_PER_BLOCK(sb) - 1;
1782 1782
1783 if (group == first || group == first + 1 || group == last) 1783 if (group == first || group == first + 1 || group == last)
1784 return 1; 1784 return 1;
1785 return 0; 1785 return 0;
1786} 1786}
1787 1787
1788static unsigned long ext3_bg_num_gdb_nometa(struct super_block *sb, int group) 1788static unsigned long ext4_bg_num_gdb_nometa(struct super_block *sb, int group)
1789{ 1789{
1790 if (EXT3_HAS_RO_COMPAT_FEATURE(sb, 1790 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
1791 EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER) && 1791 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
1792 !ext3_group_sparse(group)) 1792 !ext4_group_sparse(group))
1793 return 0; 1793 return 0;
1794 return EXT3_SB(sb)->s_gdb_count; 1794 return EXT4_SB(sb)->s_gdb_count;
1795} 1795}
1796 1796
1797/** 1797/**
1798 * ext3_bg_num_gdb - number of blocks used by the group table in group 1798 * ext4_bg_num_gdb - number of blocks used by the group table in group
1799 * @sb: superblock for filesystem 1799 * @sb: superblock for filesystem
1800 * @group: group number to check 1800 * @group: group number to check
1801 * 1801 *
@@ -1803,16 +1803,16 @@ static unsigned long ext3_bg_num_gdb_nometa(struct super_block *sb, int group)
1803 * (primary or backup) in this group. In the future there may be a 1803 * (primary or backup) in this group. In the future there may be a
1804 * different number of descriptor blocks in each group. 1804 * different number of descriptor blocks in each group.
1805 */ 1805 */
1806unsigned long ext3_bg_num_gdb(struct super_block *sb, int group) 1806unsigned long ext4_bg_num_gdb(struct super_block *sb, int group)
1807{ 1807{
1808 unsigned long first_meta_bg = 1808 unsigned long first_meta_bg =
1809 le32_to_cpu(EXT3_SB(sb)->s_es->s_first_meta_bg); 1809 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_meta_bg);
1810 unsigned long metagroup = group / EXT3_DESC_PER_BLOCK(sb); 1810 unsigned long metagroup = group / EXT4_DESC_PER_BLOCK(sb);
1811 1811
1812 if (!EXT3_HAS_INCOMPAT_FEATURE(sb,EXT3_FEATURE_INCOMPAT_META_BG) || 1812 if (!EXT4_HAS_INCOMPAT_FEATURE(sb,EXT4_FEATURE_INCOMPAT_META_BG) ||
1813 metagroup < first_meta_bg) 1813 metagroup < first_meta_bg)
1814 return ext3_bg_num_gdb_nometa(sb,group); 1814 return ext4_bg_num_gdb_nometa(sb,group);
1815 1815
1816 return ext3_bg_num_gdb_meta(sb,group); 1816 return ext4_bg_num_gdb_meta(sb,group);
1817 1817
1818} 1818}
diff --git a/fs/ext4/bitmap.c b/fs/ext4/bitmap.c
index b9176eed98d..f4b35706f39 100644
--- a/fs/ext4/bitmap.c
+++ b/fs/ext4/bitmap.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/bitmap.c 2 * linux/fs/ext4/bitmap.c
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -9,13 +9,13 @@
9 9
10#include <linux/buffer_head.h> 10#include <linux/buffer_head.h>
11#include <linux/jbd.h> 11#include <linux/jbd.h>
12#include <linux/ext3_fs.h> 12#include <linux/ext4_fs.h>
13 13
14#ifdef EXT3FS_DEBUG 14#ifdef EXT4FS_DEBUG
15 15
16static int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0}; 16static int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
17 17
18unsigned long ext3_count_free (struct buffer_head * map, unsigned int numchars) 18unsigned long ext4_count_free (struct buffer_head * map, unsigned int numchars)
19{ 19{
20 unsigned int i; 20 unsigned int i;
21 unsigned long sum = 0; 21 unsigned long sum = 0;
@@ -28,5 +28,5 @@ unsigned long ext3_count_free (struct buffer_head * map, unsigned int numchars)
28 return (sum); 28 return (sum);
29} 29}
30 30
31#endif /* EXT3FS_DEBUG */ 31#endif /* EXT4FS_DEBUG */
32 32
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index d0b54f30b91..ec114d7886c 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/dir.c 2 * linux/fs/ext4/dir.c
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -12,7 +12,7 @@
12 * 12 *
13 * Copyright (C) 1991, 1992 Linus Torvalds 13 * Copyright (C) 1991, 1992 Linus Torvalds
14 * 14 *
15 * ext3 directory handling functions 15 * ext4 directory handling functions
16 * 16 *
17 * Big-endian to little-endian byte-swapping/bitmaps by 17 * Big-endian to little-endian byte-swapping/bitmaps by
18 * David S. Miller (davem@caip.rutgers.edu), 1995 18 * David S. Miller (davem@caip.rutgers.edu), 1995
@@ -23,69 +23,69 @@
23 23
24#include <linux/fs.h> 24#include <linux/fs.h>
25#include <linux/jbd.h> 25#include <linux/jbd.h>
26#include <linux/ext3_fs.h> 26#include <linux/ext4_fs.h>
27#include <linux/buffer_head.h> 27#include <linux/buffer_head.h>
28#include <linux/smp_lock.h> 28#include <linux/smp_lock.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/rbtree.h> 30#include <linux/rbtree.h>
31 31
32static unsigned char ext3_filetype_table[] = { 32static unsigned char ext4_filetype_table[] = {
33 DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK 33 DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
34}; 34};
35 35
36static int ext3_readdir(struct file *, void *, filldir_t); 36static int ext4_readdir(struct file *, void *, filldir_t);
37static int ext3_dx_readdir(struct file * filp, 37static int ext4_dx_readdir(struct file * filp,
38 void * dirent, filldir_t filldir); 38 void * dirent, filldir_t filldir);
39static int ext3_release_dir (struct inode * inode, 39static int ext4_release_dir (struct inode * inode,
40 struct file * filp); 40 struct file * filp);
41 41
42const struct file_operations ext3_dir_operations = { 42const struct file_operations ext4_dir_operations = {
43 .llseek = generic_file_llseek, 43 .llseek = generic_file_llseek,
44 .read = generic_read_dir, 44 .read = generic_read_dir,
45 .readdir = ext3_readdir, /* we take BKL. needed?*/ 45 .readdir = ext4_readdir, /* we take BKL. needed?*/
46 .ioctl = ext3_ioctl, /* BKL held */ 46 .ioctl = ext4_ioctl, /* BKL held */
47#ifdef CONFIG_COMPAT 47#ifdef CONFIG_COMPAT
48 .compat_ioctl = ext3_compat_ioctl, 48 .compat_ioctl = ext4_compat_ioctl,
49#endif 49#endif
50 .fsync = ext3_sync_file, /* BKL held */ 50 .fsync = ext4_sync_file, /* BKL held */
51#ifdef CONFIG_EXT3_INDEX 51#ifdef CONFIG_EXT4_INDEX
52 .release = ext3_release_dir, 52 .release = ext4_release_dir,
53#endif 53#endif
54}; 54};
55 55
56 56
57static unsigned char get_dtype(struct super_block *sb, int filetype) 57static unsigned char get_dtype(struct super_block *sb, int filetype)
58{ 58{
59 if (!EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_FILETYPE) || 59 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FILETYPE) ||
60 (filetype >= EXT3_FT_MAX)) 60 (filetype >= EXT4_FT_MAX))
61 return DT_UNKNOWN; 61 return DT_UNKNOWN;
62 62
63 return (ext3_filetype_table[filetype]); 63 return (ext4_filetype_table[filetype]);
64} 64}
65 65
66 66
67int ext3_check_dir_entry (const char * function, struct inode * dir, 67int ext4_check_dir_entry (const char * function, struct inode * dir,
68 struct ext3_dir_entry_2 * de, 68 struct ext4_dir_entry_2 * de,
69 struct buffer_head * bh, 69 struct buffer_head * bh,
70 unsigned long offset) 70 unsigned long offset)
71{ 71{
72 const char * error_msg = NULL; 72 const char * error_msg = NULL;
73 const int rlen = le16_to_cpu(de->rec_len); 73 const int rlen = le16_to_cpu(de->rec_len);
74 74
75 if (rlen < EXT3_DIR_REC_LEN(1)) 75 if (rlen < EXT4_DIR_REC_LEN(1))
76 error_msg = "rec_len is smaller than minimal"; 76 error_msg = "rec_len is smaller than minimal";
77 else if (rlen % 4 != 0) 77 else if (rlen % 4 != 0)
78 error_msg = "rec_len % 4 != 0"; 78 error_msg = "rec_len % 4 != 0";
79 else if (rlen < EXT3_DIR_REC_LEN(de->name_len)) 79 else if (rlen < EXT4_DIR_REC_LEN(de->name_len))
80 error_msg = "rec_len is too small for name_len"; 80 error_msg = "rec_len is too small for name_len";
81 else if (((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize) 81 else if (((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize)
82 error_msg = "directory entry across blocks"; 82 error_msg = "directory entry across blocks";
83 else if (le32_to_cpu(de->inode) > 83 else if (le32_to_cpu(de->inode) >
84 le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count)) 84 le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count))
85 error_msg = "inode out of bounds"; 85 error_msg = "inode out of bounds";
86 86
87 if (error_msg != NULL) 87 if (error_msg != NULL)
88 ext3_error (dir->i_sb, function, 88 ext4_error (dir->i_sb, function,
89 "bad entry in directory #%lu: %s - " 89 "bad entry in directory #%lu: %s - "
90 "offset=%lu, inode=%lu, rec_len=%d, name_len=%d", 90 "offset=%lu, inode=%lu, rec_len=%d, name_len=%d",
91 dir->i_ino, error_msg, offset, 91 dir->i_ino, error_msg, offset,
@@ -94,13 +94,13 @@ int ext3_check_dir_entry (const char * function, struct inode * dir,
94 return error_msg == NULL ? 1 : 0; 94 return error_msg == NULL ? 1 : 0;
95} 95}
96 96
97static int ext3_readdir(struct file * filp, 97static int ext4_readdir(struct file * filp,
98 void * dirent, filldir_t filldir) 98 void * dirent, filldir_t filldir)
99{ 99{
100 int error = 0; 100 int error = 0;
101 unsigned long offset; 101 unsigned long offset;
102 int i, stored; 102 int i, stored;
103 struct ext3_dir_entry_2 *de; 103 struct ext4_dir_entry_2 *de;
104 struct super_block *sb; 104 struct super_block *sb;
105 int err; 105 int err;
106 struct inode *inode = filp->f_dentry->d_inode; 106 struct inode *inode = filp->f_dentry->d_inode;
@@ -108,12 +108,12 @@ static int ext3_readdir(struct file * filp,
108 108
109 sb = inode->i_sb; 109 sb = inode->i_sb;
110 110
111#ifdef CONFIG_EXT3_INDEX 111#ifdef CONFIG_EXT4_INDEX
112 if (EXT3_HAS_COMPAT_FEATURE(inode->i_sb, 112 if (EXT4_HAS_COMPAT_FEATURE(inode->i_sb,
113 EXT3_FEATURE_COMPAT_DIR_INDEX) && 113 EXT4_FEATURE_COMPAT_DIR_INDEX) &&
114 ((EXT3_I(inode)->i_flags & EXT3_INDEX_FL) || 114 ((EXT4_I(inode)->i_flags & EXT4_INDEX_FL) ||
115 ((inode->i_size >> sb->s_blocksize_bits) == 1))) { 115 ((inode->i_size >> sb->s_blocksize_bits) == 1))) {
116 err = ext3_dx_readdir(filp, dirent, filldir); 116 err = ext4_dx_readdir(filp, dirent, filldir);
117 if (err != ERR_BAD_DX_DIR) { 117 if (err != ERR_BAD_DX_DIR) {
118 ret = err; 118 ret = err;
119 goto out; 119 goto out;
@@ -122,19 +122,19 @@ static int ext3_readdir(struct file * filp,
122 * We don't set the inode dirty flag since it's not 122 * We don't set the inode dirty flag since it's not
123 * critical that it get flushed back to the disk. 123 * critical that it get flushed back to the disk.
124 */ 124 */
125 EXT3_I(filp->f_dentry->d_inode)->i_flags &= ~EXT3_INDEX_FL; 125 EXT4_I(filp->f_dentry->d_inode)->i_flags &= ~EXT4_INDEX_FL;
126 } 126 }
127#endif 127#endif
128 stored = 0; 128 stored = 0;
129 offset = filp->f_pos & (sb->s_blocksize - 1); 129 offset = filp->f_pos & (sb->s_blocksize - 1);
130 130
131 while (!error && !stored && filp->f_pos < inode->i_size) { 131 while (!error && !stored && filp->f_pos < inode->i_size) {
132 unsigned long blk = filp->f_pos >> EXT3_BLOCK_SIZE_BITS(sb); 132 unsigned long blk = filp->f_pos >> EXT4_BLOCK_SIZE_BITS(sb);
133 struct buffer_head map_bh; 133 struct buffer_head map_bh;
134 struct buffer_head *bh = NULL; 134 struct buffer_head *bh = NULL;
135 135
136 map_bh.b_state = 0; 136 map_bh.b_state = 0;
137 err = ext3_get_blocks_handle(NULL, inode, blk, 1, 137 err = ext4_get_blocks_handle(NULL, inode, blk, 1,
138 &map_bh, 0, 0); 138 &map_bh, 0, 0);
139 if (err > 0) { 139 if (err > 0) {
140 page_cache_readahead(sb->s_bdev->bd_inode->i_mapping, 140 page_cache_readahead(sb->s_bdev->bd_inode->i_mapping,
@@ -143,7 +143,7 @@ static int ext3_readdir(struct file * filp,
143 map_bh.b_blocknr >> 143 map_bh.b_blocknr >>
144 (PAGE_CACHE_SHIFT - inode->i_blkbits), 144 (PAGE_CACHE_SHIFT - inode->i_blkbits),
145 1); 145 1);
146 bh = ext3_bread(NULL, inode, blk, 0, &err); 146 bh = ext4_bread(NULL, inode, blk, 0, &err);
147 } 147 }
148 148
149 /* 149 /*
@@ -151,7 +151,7 @@ static int ext3_readdir(struct file * filp,
151 * of recovering data when there's a bad sector 151 * of recovering data when there's a bad sector
152 */ 152 */
153 if (!bh) { 153 if (!bh) {
154 ext3_error (sb, "ext3_readdir", 154 ext4_error (sb, "ext4_readdir",
155 "directory #%lu contains a hole at offset %lu", 155 "directory #%lu contains a hole at offset %lu",
156 inode->i_ino, (unsigned long)filp->f_pos); 156 inode->i_ino, (unsigned long)filp->f_pos);
157 filp->f_pos += sb->s_blocksize - offset; 157 filp->f_pos += sb->s_blocksize - offset;
@@ -165,7 +165,7 @@ revalidate:
165 * to make sure. */ 165 * to make sure. */
166 if (filp->f_version != inode->i_version) { 166 if (filp->f_version != inode->i_version) {
167 for (i = 0; i < sb->s_blocksize && i < offset; ) { 167 for (i = 0; i < sb->s_blocksize && i < offset; ) {
168 de = (struct ext3_dir_entry_2 *) 168 de = (struct ext4_dir_entry_2 *)
169 (bh->b_data + i); 169 (bh->b_data + i);
170 /* It's too expensive to do a full 170 /* It's too expensive to do a full
171 * dirent test each time round this 171 * dirent test each time round this
@@ -174,7 +174,7 @@ revalidate:
174 * failure will be detected in the 174 * failure will be detected in the
175 * dirent test below. */ 175 * dirent test below. */
176 if (le16_to_cpu(de->rec_len) < 176 if (le16_to_cpu(de->rec_len) <
177 EXT3_DIR_REC_LEN(1)) 177 EXT4_DIR_REC_LEN(1))
178 break; 178 break;
179 i += le16_to_cpu(de->rec_len); 179 i += le16_to_cpu(de->rec_len);
180 } 180 }
@@ -186,8 +186,8 @@ revalidate:
186 186
187 while (!error && filp->f_pos < inode->i_size 187 while (!error && filp->f_pos < inode->i_size
188 && offset < sb->s_blocksize) { 188 && offset < sb->s_blocksize) {
189 de = (struct ext3_dir_entry_2 *) (bh->b_data + offset); 189 de = (struct ext4_dir_entry_2 *) (bh->b_data + offset);
190 if (!ext3_check_dir_entry ("ext3_readdir", inode, de, 190 if (!ext4_check_dir_entry ("ext4_readdir", inode, de,
191 bh, offset)) { 191 bh, offset)) {
192 /* On error, skip the f_pos to the 192 /* On error, skip the f_pos to the
193 next block. */ 193 next block. */
@@ -228,7 +228,7 @@ out:
228 return ret; 228 return ret;
229} 229}
230 230
231#ifdef CONFIG_EXT3_INDEX 231#ifdef CONFIG_EXT4_INDEX
232/* 232/*
233 * These functions convert from the major/minor hash to an f_pos 233 * These functions convert from the major/minor hash to an f_pos
234 * value. 234 * value.
@@ -323,7 +323,7 @@ static struct dir_private_info *create_dir_info(loff_t pos)
323 return p; 323 return p;
324} 324}
325 325
326void ext3_htree_free_dir_info(struct dir_private_info *p) 326void ext4_htree_free_dir_info(struct dir_private_info *p)
327{ 327{
328 free_rb_tree_fname(&p->root); 328 free_rb_tree_fname(&p->root);
329 kfree(p); 329 kfree(p);
@@ -332,9 +332,9 @@ void ext3_htree_free_dir_info(struct dir_private_info *p)
332/* 332/*
333 * Given a directory entry, enter it into the fname rb tree. 333 * Given a directory entry, enter it into the fname rb tree.
334 */ 334 */
335int ext3_htree_store_dirent(struct file *dir_file, __u32 hash, 335int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
336 __u32 minor_hash, 336 __u32 minor_hash,
337 struct ext3_dir_entry_2 *dirent) 337 struct ext4_dir_entry_2 *dirent)
338{ 338{
339 struct rb_node **p, *parent = NULL; 339 struct rb_node **p, *parent = NULL;
340 struct fname * fname, *new_fn; 340 struct fname * fname, *new_fn;
@@ -390,7 +390,7 @@ int ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
390 390
391 391
392/* 392/*
393 * This is a helper function for ext3_dx_readdir. It calls filldir 393 * This is a helper function for ext4_dx_readdir. It calls filldir
394 * for all entres on the fname linked list. (Normally there is only 394 * for all entres on the fname linked list. (Normally there is only
395 * one entry on the linked list, unless there are 62 bit hash collisions.) 395 * one entry on the linked list, unless there are 62 bit hash collisions.)
396 */ 396 */
@@ -425,7 +425,7 @@ static int call_filldir(struct file * filp, void * dirent,
425 return 0; 425 return 0;
426} 426}
427 427
428static int ext3_dx_readdir(struct file * filp, 428static int ext4_dx_readdir(struct file * filp,
429 void * dirent, filldir_t filldir) 429 void * dirent, filldir_t filldir)
430{ 430{
431 struct dir_private_info *info = filp->private_data; 431 struct dir_private_info *info = filp->private_data;
@@ -440,7 +440,7 @@ static int ext3_dx_readdir(struct file * filp,
440 filp->private_data = info; 440 filp->private_data = info;
441 } 441 }
442 442
443 if (filp->f_pos == EXT3_HTREE_EOF) 443 if (filp->f_pos == EXT4_HTREE_EOF)
444 return 0; /* EOF */ 444 return 0; /* EOF */
445 445
446 /* Some one has messed with f_pos; reset the world */ 446 /* Some one has messed with f_pos; reset the world */
@@ -474,13 +474,13 @@ static int ext3_dx_readdir(struct file * filp,
474 info->curr_node = NULL; 474 info->curr_node = NULL;
475 free_rb_tree_fname(&info->root); 475 free_rb_tree_fname(&info->root);
476 filp->f_version = inode->i_version; 476 filp->f_version = inode->i_version;
477 ret = ext3_htree_fill_tree(filp, info->curr_hash, 477 ret = ext4_htree_fill_tree(filp, info->curr_hash,
478 info->curr_minor_hash, 478 info->curr_minor_hash,
479 &info->next_hash); 479 &info->next_hash);
480 if (ret < 0) 480 if (ret < 0)
481 return ret; 481 return ret;
482 if (ret == 0) { 482 if (ret == 0) {
483 filp->f_pos = EXT3_HTREE_EOF; 483 filp->f_pos = EXT4_HTREE_EOF;
484 break; 484 break;
485 } 485 }
486 info->curr_node = rb_first(&info->root); 486 info->curr_node = rb_first(&info->root);
@@ -495,7 +495,7 @@ static int ext3_dx_readdir(struct file * filp,
495 info->curr_node = rb_next(info->curr_node); 495 info->curr_node = rb_next(info->curr_node);
496 if (!info->curr_node) { 496 if (!info->curr_node) {
497 if (info->next_hash == ~0) { 497 if (info->next_hash == ~0) {
498 filp->f_pos = EXT3_HTREE_EOF; 498 filp->f_pos = EXT4_HTREE_EOF;
499 break; 499 break;
500 } 500 }
501 info->curr_hash = info->next_hash; 501 info->curr_hash = info->next_hash;
@@ -507,10 +507,10 @@ finished:
507 return 0; 507 return 0;
508} 508}
509 509
510static int ext3_release_dir (struct inode * inode, struct file * filp) 510static int ext4_release_dir (struct inode * inode, struct file * filp)
511{ 511{
512 if (filp->private_data) 512 if (filp->private_data)
513 ext3_htree_free_dir_info(filp->private_data); 513 ext4_htree_free_dir_info(filp->private_data);
514 514
515 return 0; 515 return 0;
516} 516}
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index e96c388047e..d938fbe1e08 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/file.c 2 * linux/fs/ext4/file.c
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -12,7 +12,7 @@
12 * 12 *
13 * Copyright (C) 1991, 1992 Linus Torvalds 13 * Copyright (C) 1991, 1992 Linus Torvalds
14 * 14 *
15 * ext3 fs regular file handling primitives 15 * ext4 fs regular file handling primitives
16 * 16 *
17 * 64-bit file support on 64-bit platforms by Jakub Jelinek 17 * 64-bit file support on 64-bit platforms by Jakub Jelinek
18 * (jj@sunsite.ms.mff.cuni.cz) 18 * (jj@sunsite.ms.mff.cuni.cz)
@@ -21,34 +21,34 @@
21#include <linux/time.h> 21#include <linux/time.h>
22#include <linux/fs.h> 22#include <linux/fs.h>
23#include <linux/jbd.h> 23#include <linux/jbd.h>
24#include <linux/ext3_fs.h> 24#include <linux/ext4_fs.h>
25#include <linux/ext3_jbd.h> 25#include <linux/ext4_jbd.h>
26#include "xattr.h" 26#include "xattr.h"
27#include "acl.h" 27#include "acl.h"
28 28
29/* 29/*
30 * Called when an inode is released. Note that this is different 30 * Called when an inode is released. Note that this is different
31 * from ext3_file_open: open gets called at every open, but release 31 * from ext4_file_open: open gets called at every open, but release
32 * gets called only when /all/ the files are closed. 32 * gets called only when /all/ the files are closed.
33 */ 33 */
34static int ext3_release_file (struct inode * inode, struct file * filp) 34static int ext4_release_file (struct inode * inode, struct file * filp)
35{ 35{
36 /* if we are the last writer on the inode, drop the block reservation */ 36 /* if we are the last writer on the inode, drop the block reservation */
37 if ((filp->f_mode & FMODE_WRITE) && 37 if ((filp->f_mode & FMODE_WRITE) &&
38 (atomic_read(&inode->i_writecount) == 1)) 38 (atomic_read(&inode->i_writecount) == 1))
39 { 39 {
40 mutex_lock(&EXT3_I(inode)->truncate_mutex); 40 mutex_lock(&EXT4_I(inode)->truncate_mutex);
41 ext3_discard_reservation(inode); 41 ext4_discard_reservation(inode);
42 mutex_unlock(&EXT3_I(inode)->truncate_mutex); 42 mutex_unlock(&EXT4_I(inode)->truncate_mutex);
43 } 43 }
44 if (is_dx(inode) && filp->private_data) 44 if (is_dx(inode) && filp->private_data)
45 ext3_htree_free_dir_info(filp->private_data); 45 ext4_htree_free_dir_info(filp->private_data);
46 46
47 return 0; 47 return 0;
48} 48}
49 49
50static ssize_t 50static ssize_t
51ext3_file_write(struct kiocb *iocb, const struct iovec *iov, 51ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
52 unsigned long nr_segs, loff_t pos) 52 unsigned long nr_segs, loff_t pos)
53{ 53{
54 struct file *file = iocb->ki_filp; 54 struct file *file = iocb->ki_filp;
@@ -79,7 +79,7 @@ ext3_file_write(struct kiocb *iocb, const struct iovec *iov,
79 * Open question --- do we care about flushing timestamps too 79 * Open question --- do we care about flushing timestamps too
80 * if the inode is IS_SYNC? 80 * if the inode is IS_SYNC?
81 */ 81 */
82 if (!ext3_should_journal_data(inode)) 82 if (!ext4_should_journal_data(inode))
83 return ret; 83 return ret;
84 84
85 goto force_commit; 85 goto force_commit;
@@ -100,40 +100,40 @@ ext3_file_write(struct kiocb *iocb, const struct iovec *iov,
100 */ 100 */
101 101
102force_commit: 102force_commit:
103 err = ext3_force_commit(inode->i_sb); 103 err = ext4_force_commit(inode->i_sb);
104 if (err) 104 if (err)
105 return err; 105 return err;
106 return ret; 106 return ret;
107} 107}
108 108
109const struct file_operations ext3_file_operations = { 109const struct file_operations ext4_file_operations = {
110 .llseek = generic_file_llseek, 110 .llseek = generic_file_llseek,
111 .read = do_sync_read, 111 .read = do_sync_read,
112 .write = do_sync_write, 112 .write = do_sync_write,
113 .aio_read = generic_file_aio_read, 113 .aio_read = generic_file_aio_read,
114 .aio_write = ext3_file_write, 114 .aio_write = ext4_file_write,
115 .ioctl = ext3_ioctl, 115 .ioctl = ext4_ioctl,
116#ifdef CONFIG_COMPAT 116#ifdef CONFIG_COMPAT
117 .compat_ioctl = ext3_compat_ioctl, 117 .compat_ioctl = ext4_compat_ioctl,
118#endif 118#endif
119 .mmap = generic_file_mmap, 119 .mmap = generic_file_mmap,
120 .open = generic_file_open, 120 .open = generic_file_open,
121 .release = ext3_release_file, 121 .release = ext4_release_file,
122 .fsync = ext3_sync_file, 122 .fsync = ext4_sync_file,
123 .sendfile = generic_file_sendfile, 123 .sendfile = generic_file_sendfile,
124 .splice_read = generic_file_splice_read, 124 .splice_read = generic_file_splice_read,
125 .splice_write = generic_file_splice_write, 125 .splice_write = generic_file_splice_write,
126}; 126};
127 127
128struct inode_operations ext3_file_inode_operations = { 128struct inode_operations ext4_file_inode_operations = {
129 .truncate = ext3_truncate, 129 .truncate = ext4_truncate,
130 .setattr = ext3_setattr, 130 .setattr = ext4_setattr,
131#ifdef CONFIG_EXT3_FS_XATTR 131#ifdef CONFIG_EXT4DEV_FS_XATTR
132 .setxattr = generic_setxattr, 132 .setxattr = generic_setxattr,
133 .getxattr = generic_getxattr, 133 .getxattr = generic_getxattr,
134 .listxattr = ext3_listxattr, 134 .listxattr = ext4_listxattr,
135 .removexattr = generic_removexattr, 135 .removexattr = generic_removexattr,
136#endif 136#endif
137 .permission = ext3_permission, 137 .permission = ext4_permission,
138}; 138};
139 139
diff --git a/fs/ext4/fsync.c b/fs/ext4/fsync.c
index dd1fd3c0fc0..272faa27761 100644
--- a/fs/ext4/fsync.c
+++ b/fs/ext4/fsync.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/fsync.c 2 * linux/fs/ext4/fsync.c
3 * 3 *
4 * Copyright (C) 1993 Stephen Tweedie (sct@redhat.com) 4 * Copyright (C) 1993 Stephen Tweedie (sct@redhat.com)
5 * from 5 * from
@@ -9,7 +9,7 @@
9 * from 9 * from
10 * linux/fs/minix/truncate.c Copyright (C) 1991, 1992 Linus Torvalds 10 * linux/fs/minix/truncate.c Copyright (C) 1991, 1992 Linus Torvalds
11 * 11 *
12 * ext3fs fsync primitive 12 * ext4fs fsync primitive
13 * 13 *
14 * Big-endian to little-endian byte-swapping/bitmaps by 14 * Big-endian to little-endian byte-swapping/bitmaps by
15 * David S. Miller (davem@caip.rutgers.edu), 1995 15 * David S. Miller (davem@caip.rutgers.edu), 1995
@@ -27,11 +27,11 @@
27#include <linux/sched.h> 27#include <linux/sched.h>
28#include <linux/writeback.h> 28#include <linux/writeback.h>
29#include <linux/jbd.h> 29#include <linux/jbd.h>
30#include <linux/ext3_fs.h> 30#include <linux/ext4_fs.h>
31#include <linux/ext3_jbd.h> 31#include <linux/ext4_jbd.h>
32 32
33/* 33/*
34 * akpm: A new design for ext3_sync_file(). 34 * akpm: A new design for ext4_sync_file().
35 * 35 *
36 * This is only called from sys_fsync(), sys_fdatasync() and sys_msync(). 36 * This is only called from sys_fsync(), sys_fdatasync() and sys_msync().
37 * There cannot be a transaction open by this task. 37 * There cannot be a transaction open by this task.
@@ -42,12 +42,12 @@
42 * inode to disk. 42 * inode to disk.
43 */ 43 */
44 44
45int ext3_sync_file(struct file * file, struct dentry *dentry, int datasync) 45int ext4_sync_file(struct file * file, struct dentry *dentry, int datasync)
46{ 46{
47 struct inode *inode = dentry->d_inode; 47 struct inode *inode = dentry->d_inode;
48 int ret = 0; 48 int ret = 0;
49 49
50 J_ASSERT(ext3_journal_current_handle() == 0); 50 J_ASSERT(ext4_journal_current_handle() == 0);
51 51
52 /* 52 /*
53 * data=writeback: 53 * data=writeback:
@@ -61,14 +61,14 @@ int ext3_sync_file(struct file * file, struct dentry *dentry, int datasync)
61 * 61 *
62 * data=journal: 62 * data=journal:
63 * filemap_fdatawrite won't do anything (the buffers are clean). 63 * filemap_fdatawrite won't do anything (the buffers are clean).
64 * ext3_force_commit will write the file data into the journal and 64 * ext4_force_commit will write the file data into the journal and
65 * will wait on that. 65 * will wait on that.
66 * filemap_fdatawait() will encounter a ton of newly-dirtied pages 66 * filemap_fdatawait() will encounter a ton of newly-dirtied pages
67 * (they were dirtied by commit). But that's OK - the blocks are 67 * (they were dirtied by commit). But that's OK - the blocks are
68 * safe in-journal, which is all fsync() needs to ensure. 68 * safe in-journal, which is all fsync() needs to ensure.
69 */ 69 */
70 if (ext3_should_journal_data(inode)) { 70 if (ext4_should_journal_data(inode)) {
71 ret = ext3_force_commit(inode->i_sb); 71 ret = ext4_force_commit(inode->i_sb);
72 goto out; 72 goto out;
73 } 73 }
74 74
diff --git a/fs/ext4/hash.c b/fs/ext4/hash.c
index deeb27b5ba8..d15bb427442 100644
--- a/fs/ext4/hash.c
+++ b/fs/ext4/hash.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/hash.c 2 * linux/fs/ext4/hash.c
3 * 3 *
4 * Copyright (C) 2002 by Theodore Ts'o 4 * Copyright (C) 2002 by Theodore Ts'o
5 * 5 *
@@ -12,7 +12,7 @@
12#include <linux/fs.h> 12#include <linux/fs.h>
13#include <linux/jbd.h> 13#include <linux/jbd.h>
14#include <linux/sched.h> 14#include <linux/sched.h>
15#include <linux/ext3_fs.h> 15#include <linux/ext4_fs.h>
16#include <linux/cryptohash.h> 16#include <linux/cryptohash.h>
17 17
18#define DELTA 0x9E3779B9 18#define DELTA 0x9E3779B9
@@ -89,7 +89,7 @@ static void str2hashbuf(const char *msg, int len, __u32 *buf, int num)
89 * represented, and whether or not the returned hash is 32 bits or 64 89 * represented, and whether or not the returned hash is 32 bits or 64
90 * bits. 32 bit hashes will return 0 for the minor hash. 90 * bits. 32 bit hashes will return 0 for the minor hash.
91 */ 91 */
92int ext3fs_dirhash(const char *name, int len, struct dx_hash_info *hinfo) 92int ext4fs_dirhash(const char *name, int len, struct dx_hash_info *hinfo)
93{ 93{
94 __u32 hash; 94 __u32 hash;
95 __u32 minor_hash = 0; 95 __u32 minor_hash = 0;
@@ -144,8 +144,8 @@ int ext3fs_dirhash(const char *name, int len, struct dx_hash_info *hinfo)
144 return -1; 144 return -1;
145 } 145 }
146 hash = hash & ~1; 146 hash = hash & ~1;
147 if (hash == (EXT3_HTREE_EOF << 1)) 147 if (hash == (EXT4_HTREE_EOF << 1))
148 hash = (EXT3_HTREE_EOF-1) << 1; 148 hash = (EXT4_HTREE_EOF-1) << 1;
149 hinfo->hash = hash; 149 hinfo->hash = hash;
150 hinfo->minor_hash = minor_hash; 150 hinfo->minor_hash = minor_hash;
151 return 0; 151 return 0;
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index e45dbd65173..4b92066ca08 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/ialloc.c 2 * linux/fs/ext4/ialloc.c
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -15,8 +15,8 @@
15#include <linux/time.h> 15#include <linux/time.h>
16#include <linux/fs.h> 16#include <linux/fs.h>
17#include <linux/jbd.h> 17#include <linux/jbd.h>
18#include <linux/ext3_fs.h> 18#include <linux/ext4_fs.h>
19#include <linux/ext3_jbd.h> 19#include <linux/ext4_jbd.h>
20#include <linux/stat.h> 20#include <linux/stat.h>
21#include <linux/string.h> 21#include <linux/string.h>
22#include <linux/quotaops.h> 22#include <linux/quotaops.h>
@@ -53,16 +53,16 @@
53static struct buffer_head * 53static struct buffer_head *
54read_inode_bitmap(struct super_block * sb, unsigned long block_group) 54read_inode_bitmap(struct super_block * sb, unsigned long block_group)
55{ 55{
56 struct ext3_group_desc *desc; 56 struct ext4_group_desc *desc;
57 struct buffer_head *bh = NULL; 57 struct buffer_head *bh = NULL;
58 58
59 desc = ext3_get_group_desc(sb, block_group, NULL); 59 desc = ext4_get_group_desc(sb, block_group, NULL);
60 if (!desc) 60 if (!desc)
61 goto error_out; 61 goto error_out;
62 62
63 bh = sb_bread(sb, le32_to_cpu(desc->bg_inode_bitmap)); 63 bh = sb_bread(sb, le32_to_cpu(desc->bg_inode_bitmap));
64 if (!bh) 64 if (!bh)
65 ext3_error(sb, "read_inode_bitmap", 65 ext4_error(sb, "read_inode_bitmap",
66 "Cannot read inode bitmap - " 66 "Cannot read inode bitmap - "
67 "block_group = %lu, inode_bitmap = %u", 67 "block_group = %lu, inode_bitmap = %u",
68 block_group, le32_to_cpu(desc->bg_inode_bitmap)); 68 block_group, le32_to_cpu(desc->bg_inode_bitmap));
@@ -86,7 +86,7 @@ error_out:
86 * though), and then we'd have two inodes sharing the 86 * though), and then we'd have two inodes sharing the
87 * same inode number and space on the harddisk. 87 * same inode number and space on the harddisk.
88 */ 88 */
89void ext3_free_inode (handle_t *handle, struct inode * inode) 89void ext4_free_inode (handle_t *handle, struct inode * inode)
90{ 90{
91 struct super_block * sb = inode->i_sb; 91 struct super_block * sb = inode->i_sb;
92 int is_directory; 92 int is_directory;
@@ -95,36 +95,36 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
95 struct buffer_head *bh2; 95 struct buffer_head *bh2;
96 unsigned long block_group; 96 unsigned long block_group;
97 unsigned long bit; 97 unsigned long bit;
98 struct ext3_group_desc * gdp; 98 struct ext4_group_desc * gdp;
99 struct ext3_super_block * es; 99 struct ext4_super_block * es;
100 struct ext3_sb_info *sbi; 100 struct ext4_sb_info *sbi;
101 int fatal = 0, err; 101 int fatal = 0, err;
102 102
103 if (atomic_read(&inode->i_count) > 1) { 103 if (atomic_read(&inode->i_count) > 1) {
104 printk ("ext3_free_inode: inode has count=%d\n", 104 printk ("ext4_free_inode: inode has count=%d\n",
105 atomic_read(&inode->i_count)); 105 atomic_read(&inode->i_count));
106 return; 106 return;
107 } 107 }
108 if (inode->i_nlink) { 108 if (inode->i_nlink) {
109 printk ("ext3_free_inode: inode has nlink=%d\n", 109 printk ("ext4_free_inode: inode has nlink=%d\n",
110 inode->i_nlink); 110 inode->i_nlink);
111 return; 111 return;
112 } 112 }
113 if (!sb) { 113 if (!sb) {
114 printk("ext3_free_inode: inode on nonexistent device\n"); 114 printk("ext4_free_inode: inode on nonexistent device\n");
115 return; 115 return;
116 } 116 }
117 sbi = EXT3_SB(sb); 117 sbi = EXT4_SB(sb);
118 118
119 ino = inode->i_ino; 119 ino = inode->i_ino;
120 ext3_debug ("freeing inode %lu\n", ino); 120 ext4_debug ("freeing inode %lu\n", ino);
121 121
122 /* 122 /*
123 * Note: we must free any quota before locking the superblock, 123 * Note: we must free any quota before locking the superblock,
124 * as writing the quota to disk may need the lock as well. 124 * as writing the quota to disk may need the lock as well.
125 */ 125 */
126 DQUOT_INIT(inode); 126 DQUOT_INIT(inode);
127 ext3_xattr_delete_inode(handle, inode); 127 ext4_xattr_delete_inode(handle, inode);
128 DQUOT_FREE_INODE(inode); 128 DQUOT_FREE_INODE(inode);
129 DQUOT_DROP(inode); 129 DQUOT_DROP(inode);
130 130
@@ -133,33 +133,33 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
133 /* Do this BEFORE marking the inode not in use or returning an error */ 133 /* Do this BEFORE marking the inode not in use or returning an error */
134 clear_inode (inode); 134 clear_inode (inode);
135 135
136 es = EXT3_SB(sb)->s_es; 136 es = EXT4_SB(sb)->s_es;
137 if (ino < EXT3_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) { 137 if (ino < EXT4_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) {
138 ext3_error (sb, "ext3_free_inode", 138 ext4_error (sb, "ext4_free_inode",
139 "reserved or nonexistent inode %lu", ino); 139 "reserved or nonexistent inode %lu", ino);
140 goto error_return; 140 goto error_return;
141 } 141 }
142 block_group = (ino - 1) / EXT3_INODES_PER_GROUP(sb); 142 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
143 bit = (ino - 1) % EXT3_INODES_PER_GROUP(sb); 143 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
144 bitmap_bh = read_inode_bitmap(sb, block_group); 144 bitmap_bh = read_inode_bitmap(sb, block_group);
145 if (!bitmap_bh) 145 if (!bitmap_bh)
146 goto error_return; 146 goto error_return;
147 147
148 BUFFER_TRACE(bitmap_bh, "get_write_access"); 148 BUFFER_TRACE(bitmap_bh, "get_write_access");
149 fatal = ext3_journal_get_write_access(handle, bitmap_bh); 149 fatal = ext4_journal_get_write_access(handle, bitmap_bh);
150 if (fatal) 150 if (fatal)
151 goto error_return; 151 goto error_return;
152 152
153 /* Ok, now we can actually update the inode bitmaps.. */ 153 /* Ok, now we can actually update the inode bitmaps.. */
154 if (!ext3_clear_bit_atomic(sb_bgl_lock(sbi, block_group), 154 if (!ext4_clear_bit_atomic(sb_bgl_lock(sbi, block_group),
155 bit, bitmap_bh->b_data)) 155 bit, bitmap_bh->b_data))
156 ext3_error (sb, "ext3_free_inode", 156 ext4_error (sb, "ext4_free_inode",
157 "bit already cleared for inode %lu", ino); 157 "bit already cleared for inode %lu", ino);
158 else { 158 else {
159 gdp = ext3_get_group_desc (sb, block_group, &bh2); 159 gdp = ext4_get_group_desc (sb, block_group, &bh2);
160 160
161 BUFFER_TRACE(bh2, "get_write_access"); 161 BUFFER_TRACE(bh2, "get_write_access");
162 fatal = ext3_journal_get_write_access(handle, bh2); 162 fatal = ext4_journal_get_write_access(handle, bh2);
163 if (fatal) goto error_return; 163 if (fatal) goto error_return;
164 164
165 if (gdp) { 165 if (gdp) {
@@ -175,18 +175,18 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
175 percpu_counter_dec(&sbi->s_dirs_counter); 175 percpu_counter_dec(&sbi->s_dirs_counter);
176 176
177 } 177 }
178 BUFFER_TRACE(bh2, "call ext3_journal_dirty_metadata"); 178 BUFFER_TRACE(bh2, "call ext4_journal_dirty_metadata");
179 err = ext3_journal_dirty_metadata(handle, bh2); 179 err = ext4_journal_dirty_metadata(handle, bh2);
180 if (!fatal) fatal = err; 180 if (!fatal) fatal = err;
181 } 181 }
182 BUFFER_TRACE(bitmap_bh, "call ext3_journal_dirty_metadata"); 182 BUFFER_TRACE(bitmap_bh, "call ext4_journal_dirty_metadata");
183 err = ext3_journal_dirty_metadata(handle, bitmap_bh); 183 err = ext4_journal_dirty_metadata(handle, bitmap_bh);
184 if (!fatal) 184 if (!fatal)
185 fatal = err; 185 fatal = err;
186 sb->s_dirt = 1; 186 sb->s_dirt = 1;
187error_return: 187error_return:
188 brelse(bitmap_bh); 188 brelse(bitmap_bh);
189 ext3_std_error(sb, fatal); 189 ext4_std_error(sb, fatal);
190} 190}
191 191
192/* 192/*
@@ -201,17 +201,17 @@ error_return:
201 */ 201 */
202static int find_group_dir(struct super_block *sb, struct inode *parent) 202static int find_group_dir(struct super_block *sb, struct inode *parent)
203{ 203{
204 int ngroups = EXT3_SB(sb)->s_groups_count; 204 int ngroups = EXT4_SB(sb)->s_groups_count;
205 unsigned int freei, avefreei; 205 unsigned int freei, avefreei;
206 struct ext3_group_desc *desc, *best_desc = NULL; 206 struct ext4_group_desc *desc, *best_desc = NULL;
207 struct buffer_head *bh; 207 struct buffer_head *bh;
208 int group, best_group = -1; 208 int group, best_group = -1;
209 209
210 freei = percpu_counter_read_positive(&EXT3_SB(sb)->s_freeinodes_counter); 210 freei = percpu_counter_read_positive(&EXT4_SB(sb)->s_freeinodes_counter);
211 avefreei = freei / ngroups; 211 avefreei = freei / ngroups;
212 212
213 for (group = 0; group < ngroups; group++) { 213 for (group = 0; group < ngroups; group++) {
214 desc = ext3_get_group_desc (sb, group, &bh); 214 desc = ext4_get_group_desc (sb, group, &bh);
215 if (!desc || !desc->bg_free_inodes_count) 215 if (!desc || !desc->bg_free_inodes_count)
216 continue; 216 continue;
217 if (le16_to_cpu(desc->bg_free_inodes_count) < avefreei) 217 if (le16_to_cpu(desc->bg_free_inodes_count) < avefreei)
@@ -256,19 +256,19 @@ static int find_group_dir(struct super_block *sb, struct inode *parent)
256 256
257static int find_group_orlov(struct super_block *sb, struct inode *parent) 257static int find_group_orlov(struct super_block *sb, struct inode *parent)
258{ 258{
259 int parent_group = EXT3_I(parent)->i_block_group; 259 int parent_group = EXT4_I(parent)->i_block_group;
260 struct ext3_sb_info *sbi = EXT3_SB(sb); 260 struct ext4_sb_info *sbi = EXT4_SB(sb);
261 struct ext3_super_block *es = sbi->s_es; 261 struct ext4_super_block *es = sbi->s_es;
262 int ngroups = sbi->s_groups_count; 262 int ngroups = sbi->s_groups_count;
263 int inodes_per_group = EXT3_INODES_PER_GROUP(sb); 263 int inodes_per_group = EXT4_INODES_PER_GROUP(sb);
264 unsigned int freei, avefreei; 264 unsigned int freei, avefreei;
265 ext3_fsblk_t freeb, avefreeb; 265 ext4_fsblk_t freeb, avefreeb;
266 ext3_fsblk_t blocks_per_dir; 266 ext4_fsblk_t blocks_per_dir;
267 unsigned int ndirs; 267 unsigned int ndirs;
268 int max_debt, max_dirs, min_inodes; 268 int max_debt, max_dirs, min_inodes;
269 ext3_grpblk_t min_blocks; 269 ext4_grpblk_t min_blocks;
270 int group = -1, i; 270 int group = -1, i;
271 struct ext3_group_desc *desc; 271 struct ext4_group_desc *desc;
272 struct buffer_head *bh; 272 struct buffer_head *bh;
273 273
274 freei = percpu_counter_read_positive(&sbi->s_freeinodes_counter); 274 freei = percpu_counter_read_positive(&sbi->s_freeinodes_counter);
@@ -278,7 +278,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
278 ndirs = percpu_counter_read_positive(&sbi->s_dirs_counter); 278 ndirs = percpu_counter_read_positive(&sbi->s_dirs_counter);
279 279
280 if ((parent == sb->s_root->d_inode) || 280 if ((parent == sb->s_root->d_inode) ||
281 (EXT3_I(parent)->i_flags & EXT3_TOPDIR_FL)) { 281 (EXT4_I(parent)->i_flags & EXT4_TOPDIR_FL)) {
282 int best_ndir = inodes_per_group; 282 int best_ndir = inodes_per_group;
283 int best_group = -1; 283 int best_group = -1;
284 284
@@ -286,7 +286,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
286 parent_group = (unsigned)group % ngroups; 286 parent_group = (unsigned)group % ngroups;
287 for (i = 0; i < ngroups; i++) { 287 for (i = 0; i < ngroups; i++) {
288 group = (parent_group + i) % ngroups; 288 group = (parent_group + i) % ngroups;
289 desc = ext3_get_group_desc (sb, group, &bh); 289 desc = ext4_get_group_desc (sb, group, &bh);
290 if (!desc || !desc->bg_free_inodes_count) 290 if (!desc || !desc->bg_free_inodes_count)
291 continue; 291 continue;
292 if (le16_to_cpu(desc->bg_used_dirs_count) >= best_ndir) 292 if (le16_to_cpu(desc->bg_used_dirs_count) >= best_ndir)
@@ -307,9 +307,9 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
307 307
308 max_dirs = ndirs / ngroups + inodes_per_group / 16; 308 max_dirs = ndirs / ngroups + inodes_per_group / 16;
309 min_inodes = avefreei - inodes_per_group / 4; 309 min_inodes = avefreei - inodes_per_group / 4;
310 min_blocks = avefreeb - EXT3_BLOCKS_PER_GROUP(sb) / 4; 310 min_blocks = avefreeb - EXT4_BLOCKS_PER_GROUP(sb) / 4;
311 311
312 max_debt = EXT3_BLOCKS_PER_GROUP(sb) / max(blocks_per_dir, (ext3_fsblk_t)BLOCK_COST); 312 max_debt = EXT4_BLOCKS_PER_GROUP(sb) / max(blocks_per_dir, (ext4_fsblk_t)BLOCK_COST);
313 if (max_debt * INODE_COST > inodes_per_group) 313 if (max_debt * INODE_COST > inodes_per_group)
314 max_debt = inodes_per_group / INODE_COST; 314 max_debt = inodes_per_group / INODE_COST;
315 if (max_debt > 255) 315 if (max_debt > 255)
@@ -319,7 +319,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
319 319
320 for (i = 0; i < ngroups; i++) { 320 for (i = 0; i < ngroups; i++) {
321 group = (parent_group + i) % ngroups; 321 group = (parent_group + i) % ngroups;
322 desc = ext3_get_group_desc (sb, group, &bh); 322 desc = ext4_get_group_desc (sb, group, &bh);
323 if (!desc || !desc->bg_free_inodes_count) 323 if (!desc || !desc->bg_free_inodes_count)
324 continue; 324 continue;
325 if (le16_to_cpu(desc->bg_used_dirs_count) >= max_dirs) 325 if (le16_to_cpu(desc->bg_used_dirs_count) >= max_dirs)
@@ -334,7 +334,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
334fallback: 334fallback:
335 for (i = 0; i < ngroups; i++) { 335 for (i = 0; i < ngroups; i++) {
336 group = (parent_group + i) % ngroups; 336 group = (parent_group + i) % ngroups;
337 desc = ext3_get_group_desc (sb, group, &bh); 337 desc = ext4_get_group_desc (sb, group, &bh);
338 if (!desc || !desc->bg_free_inodes_count) 338 if (!desc || !desc->bg_free_inodes_count)
339 continue; 339 continue;
340 if (le16_to_cpu(desc->bg_free_inodes_count) >= avefreei) 340 if (le16_to_cpu(desc->bg_free_inodes_count) >= avefreei)
@@ -355,9 +355,9 @@ fallback:
355 355
356static int find_group_other(struct super_block *sb, struct inode *parent) 356static int find_group_other(struct super_block *sb, struct inode *parent)
357{ 357{
358 int parent_group = EXT3_I(parent)->i_block_group; 358 int parent_group = EXT4_I(parent)->i_block_group;
359 int ngroups = EXT3_SB(sb)->s_groups_count; 359 int ngroups = EXT4_SB(sb)->s_groups_count;
360 struct ext3_group_desc *desc; 360 struct ext4_group_desc *desc;
361 struct buffer_head *bh; 361 struct buffer_head *bh;
362 int group, i; 362 int group, i;
363 363
@@ -365,7 +365,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
365 * Try to place the inode in its parent directory 365 * Try to place the inode in its parent directory
366 */ 366 */
367 group = parent_group; 367 group = parent_group;
368 desc = ext3_get_group_desc (sb, group, &bh); 368 desc = ext4_get_group_desc (sb, group, &bh);
369 if (desc && le16_to_cpu(desc->bg_free_inodes_count) && 369 if (desc && le16_to_cpu(desc->bg_free_inodes_count) &&
370 le16_to_cpu(desc->bg_free_blocks_count)) 370 le16_to_cpu(desc->bg_free_blocks_count))
371 return group; 371 return group;
@@ -389,7 +389,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
389 group += i; 389 group += i;
390 if (group >= ngroups) 390 if (group >= ngroups)
391 group -= ngroups; 391 group -= ngroups;
392 desc = ext3_get_group_desc (sb, group, &bh); 392 desc = ext4_get_group_desc (sb, group, &bh);
393 if (desc && le16_to_cpu(desc->bg_free_inodes_count) && 393 if (desc && le16_to_cpu(desc->bg_free_inodes_count) &&
394 le16_to_cpu(desc->bg_free_blocks_count)) 394 le16_to_cpu(desc->bg_free_blocks_count))
395 return group; 395 return group;
@@ -403,7 +403,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
403 for (i = 0; i < ngroups; i++) { 403 for (i = 0; i < ngroups; i++) {
404 if (++group >= ngroups) 404 if (++group >= ngroups)
405 group = 0; 405 group = 0;
406 desc = ext3_get_group_desc (sb, group, &bh); 406 desc = ext4_get_group_desc (sb, group, &bh);
407 if (desc && le16_to_cpu(desc->bg_free_inodes_count)) 407 if (desc && le16_to_cpu(desc->bg_free_inodes_count))
408 return group; 408 return group;
409 } 409 }
@@ -421,7 +421,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
421 * For other inodes, search forward from the parent directory's block 421 * For other inodes, search forward from the parent directory's block
422 * group to find a free inode. 422 * group to find a free inode.
423 */ 423 */
424struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) 424struct inode *ext4_new_inode(handle_t *handle, struct inode * dir, int mode)
425{ 425{
426 struct super_block *sb; 426 struct super_block *sb;
427 struct buffer_head *bitmap_bh = NULL; 427 struct buffer_head *bitmap_bh = NULL;
@@ -429,10 +429,10 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
429 int group; 429 int group;
430 unsigned long ino = 0; 430 unsigned long ino = 0;
431 struct inode * inode; 431 struct inode * inode;
432 struct ext3_group_desc * gdp = NULL; 432 struct ext4_group_desc * gdp = NULL;
433 struct ext3_super_block * es; 433 struct ext4_super_block * es;
434 struct ext3_inode_info *ei; 434 struct ext4_inode_info *ei;
435 struct ext3_sb_info *sbi; 435 struct ext4_sb_info *sbi;
436 int err = 0; 436 int err = 0;
437 struct inode *ret; 437 struct inode *ret;
438 int i; 438 int i;
@@ -445,9 +445,9 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
445 inode = new_inode(sb); 445 inode = new_inode(sb);
446 if (!inode) 446 if (!inode)
447 return ERR_PTR(-ENOMEM); 447 return ERR_PTR(-ENOMEM);
448 ei = EXT3_I(inode); 448 ei = EXT4_I(inode);
449 449
450 sbi = EXT3_SB(sb); 450 sbi = EXT4_SB(sb);
451 es = sbi->s_es; 451 es = sbi->s_es;
452 if (S_ISDIR(mode)) { 452 if (S_ISDIR(mode)) {
453 if (test_opt (sb, OLDALLOC)) 453 if (test_opt (sb, OLDALLOC))
@@ -464,7 +464,7 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
464 for (i = 0; i < sbi->s_groups_count; i++) { 464 for (i = 0; i < sbi->s_groups_count; i++) {
465 err = -EIO; 465 err = -EIO;
466 466
467 gdp = ext3_get_group_desc(sb, group, &bh2); 467 gdp = ext4_get_group_desc(sb, group, &bh2);
468 if (!gdp) 468 if (!gdp)
469 goto fail; 469 goto fail;
470 470
@@ -476,21 +476,21 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
476 ino = 0; 476 ino = 0;
477 477
478repeat_in_this_group: 478repeat_in_this_group:
479 ino = ext3_find_next_zero_bit((unsigned long *) 479 ino = ext4_find_next_zero_bit((unsigned long *)
480 bitmap_bh->b_data, EXT3_INODES_PER_GROUP(sb), ino); 480 bitmap_bh->b_data, EXT4_INODES_PER_GROUP(sb), ino);
481 if (ino < EXT3_INODES_PER_GROUP(sb)) { 481 if (ino < EXT4_INODES_PER_GROUP(sb)) {
482 482
483 BUFFER_TRACE(bitmap_bh, "get_write_access"); 483 BUFFER_TRACE(bitmap_bh, "get_write_access");
484 err = ext3_journal_get_write_access(handle, bitmap_bh); 484 err = ext4_journal_get_write_access(handle, bitmap_bh);
485 if (err) 485 if (err)
486 goto fail; 486 goto fail;
487 487
488 if (!ext3_set_bit_atomic(sb_bgl_lock(sbi, group), 488 if (!ext4_set_bit_atomic(sb_bgl_lock(sbi, group),
489 ino, bitmap_bh->b_data)) { 489 ino, bitmap_bh->b_data)) {
490 /* we won it */ 490 /* we won it */
491 BUFFER_TRACE(bitmap_bh, 491 BUFFER_TRACE(bitmap_bh,
492 "call ext3_journal_dirty_metadata"); 492 "call ext4_journal_dirty_metadata");
493 err = ext3_journal_dirty_metadata(handle, 493 err = ext4_journal_dirty_metadata(handle,
494 bitmap_bh); 494 bitmap_bh);
495 if (err) 495 if (err)
496 goto fail; 496 goto fail;
@@ -499,7 +499,7 @@ repeat_in_this_group:
499 /* we lost it */ 499 /* we lost it */
500 journal_release_buffer(handle, bitmap_bh); 500 journal_release_buffer(handle, bitmap_bh);
501 501
502 if (++ino < EXT3_INODES_PER_GROUP(sb)) 502 if (++ino < EXT4_INODES_PER_GROUP(sb))
503 goto repeat_in_this_group; 503 goto repeat_in_this_group;
504 } 504 }
505 505
@@ -517,9 +517,9 @@ repeat_in_this_group:
517 goto out; 517 goto out;
518 518
519got: 519got:
520 ino += group * EXT3_INODES_PER_GROUP(sb) + 1; 520 ino += group * EXT4_INODES_PER_GROUP(sb) + 1;
521 if (ino < EXT3_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) { 521 if (ino < EXT4_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) {
522 ext3_error (sb, "ext3_new_inode", 522 ext4_error (sb, "ext4_new_inode",
523 "reserved inode or inode > inodes count - " 523 "reserved inode or inode > inodes count - "
524 "block_group = %d, inode=%lu", group, ino); 524 "block_group = %d, inode=%lu", group, ino);
525 err = -EIO; 525 err = -EIO;
@@ -527,7 +527,7 @@ got:
527 } 527 }
528 528
529 BUFFER_TRACE(bh2, "get_write_access"); 529 BUFFER_TRACE(bh2, "get_write_access");
530 err = ext3_journal_get_write_access(handle, bh2); 530 err = ext4_journal_get_write_access(handle, bh2);
531 if (err) goto fail; 531 if (err) goto fail;
532 spin_lock(sb_bgl_lock(sbi, group)); 532 spin_lock(sb_bgl_lock(sbi, group));
533 gdp->bg_free_inodes_count = 533 gdp->bg_free_inodes_count =
@@ -537,8 +537,8 @@ got:
537 cpu_to_le16(le16_to_cpu(gdp->bg_used_dirs_count) + 1); 537 cpu_to_le16(le16_to_cpu(gdp->bg_used_dirs_count) + 1);
538 } 538 }
539 spin_unlock(sb_bgl_lock(sbi, group)); 539 spin_unlock(sb_bgl_lock(sbi, group));
540 BUFFER_TRACE(bh2, "call ext3_journal_dirty_metadata"); 540 BUFFER_TRACE(bh2, "call ext4_journal_dirty_metadata");
541 err = ext3_journal_dirty_metadata(handle, bh2); 541 err = ext4_journal_dirty_metadata(handle, bh2);
542 if (err) goto fail; 542 if (err) goto fail;
543 543
544 percpu_counter_dec(&sbi->s_freeinodes_counter); 544 percpu_counter_dec(&sbi->s_freeinodes_counter);
@@ -566,13 +566,13 @@ got:
566 ei->i_dir_start_lookup = 0; 566 ei->i_dir_start_lookup = 0;
567 ei->i_disksize = 0; 567 ei->i_disksize = 0;
568 568
569 ei->i_flags = EXT3_I(dir)->i_flags & ~EXT3_INDEX_FL; 569 ei->i_flags = EXT4_I(dir)->i_flags & ~EXT4_INDEX_FL;
570 if (S_ISLNK(mode)) 570 if (S_ISLNK(mode))
571 ei->i_flags &= ~(EXT3_IMMUTABLE_FL|EXT3_APPEND_FL); 571 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
572 /* dirsync only applies to directories */ 572 /* dirsync only applies to directories */
573 if (!S_ISDIR(mode)) 573 if (!S_ISDIR(mode))
574 ei->i_flags &= ~EXT3_DIRSYNC_FL; 574 ei->i_flags &= ~EXT4_DIRSYNC_FL;
575#ifdef EXT3_FRAGMENTS 575#ifdef EXT4_FRAGMENTS
576 ei->i_faddr = 0; 576 ei->i_faddr = 0;
577 ei->i_frag_no = 0; 577 ei->i_frag_no = 0;
578 ei->i_frag_size = 0; 578 ei->i_frag_size = 0;
@@ -583,7 +583,7 @@ got:
583 ei->i_block_alloc_info = NULL; 583 ei->i_block_alloc_info = NULL;
584 ei->i_block_group = group; 584 ei->i_block_group = group;
585 585
586 ext3_set_inode_flags(inode); 586 ext4_set_inode_flags(inode);
587 if (IS_DIRSYNC(inode)) 587 if (IS_DIRSYNC(inode))
588 handle->h_sync = 1; 588 handle->h_sync = 1;
589 insert_inode_hash(inode); 589 insert_inode_hash(inode);
@@ -591,10 +591,10 @@ got:
591 inode->i_generation = sbi->s_next_generation++; 591 inode->i_generation = sbi->s_next_generation++;
592 spin_unlock(&sbi->s_next_gen_lock); 592 spin_unlock(&sbi->s_next_gen_lock);
593 593
594 ei->i_state = EXT3_STATE_NEW; 594 ei->i_state = EXT4_STATE_NEW;
595 ei->i_extra_isize = 595 ei->i_extra_isize =
596 (EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE) ? 596 (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) ?
597 sizeof(struct ext3_inode) - EXT3_GOOD_OLD_INODE_SIZE : 0; 597 sizeof(struct ext4_inode) - EXT4_GOOD_OLD_INODE_SIZE : 0;
598 598
599 ret = inode; 599 ret = inode;
600 if(DQUOT_ALLOC_INODE(inode)) { 600 if(DQUOT_ALLOC_INODE(inode)) {
@@ -602,24 +602,24 @@ got:
602 goto fail_drop; 602 goto fail_drop;
603 } 603 }
604 604
605 err = ext3_init_acl(handle, inode, dir); 605 err = ext4_init_acl(handle, inode, dir);
606 if (err) 606 if (err)
607 goto fail_free_drop; 607 goto fail_free_drop;
608 608
609 err = ext3_init_security(handle,inode, dir); 609 err = ext4_init_security(handle,inode, dir);
610 if (err) 610 if (err)
611 goto fail_free_drop; 611 goto fail_free_drop;
612 612
613 err = ext3_mark_inode_dirty(handle, inode); 613 err = ext4_mark_inode_dirty(handle, inode);
614 if (err) { 614 if (err) {
615 ext3_std_error(sb, err); 615 ext4_std_error(sb, err);
616 goto fail_free_drop; 616 goto fail_free_drop;
617 } 617 }
618 618
619 ext3_debug("allocating inode %lu\n", inode->i_ino); 619 ext4_debug("allocating inode %lu\n", inode->i_ino);
620 goto really_out; 620 goto really_out;
621fail: 621fail:
622 ext3_std_error(sb, err); 622 ext4_std_error(sb, err);
623out: 623out:
624 iput(inode); 624 iput(inode);
625 ret = ERR_PTR(err); 625 ret = ERR_PTR(err);
@@ -640,9 +640,9 @@ fail_drop:
640} 640}
641 641
642/* Verify that we are loading a valid orphan from disk */ 642/* Verify that we are loading a valid orphan from disk */
643struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino) 643struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
644{ 644{
645 unsigned long max_ino = le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count); 645 unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count);
646 unsigned long block_group; 646 unsigned long block_group;
647 int bit; 647 int bit;
648 struct buffer_head *bitmap_bh = NULL; 648 struct buffer_head *bitmap_bh = NULL;
@@ -650,16 +650,16 @@ struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino)
650 650
651 /* Error cases - e2fsck has already cleaned up for us */ 651 /* Error cases - e2fsck has already cleaned up for us */
652 if (ino > max_ino) { 652 if (ino > max_ino) {
653 ext3_warning(sb, __FUNCTION__, 653 ext4_warning(sb, __FUNCTION__,
654 "bad orphan ino %lu! e2fsck was run?", ino); 654 "bad orphan ino %lu! e2fsck was run?", ino);
655 goto out; 655 goto out;
656 } 656 }
657 657
658 block_group = (ino - 1) / EXT3_INODES_PER_GROUP(sb); 658 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
659 bit = (ino - 1) % EXT3_INODES_PER_GROUP(sb); 659 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
660 bitmap_bh = read_inode_bitmap(sb, block_group); 660 bitmap_bh = read_inode_bitmap(sb, block_group);
661 if (!bitmap_bh) { 661 if (!bitmap_bh) {
662 ext3_warning(sb, __FUNCTION__, 662 ext4_warning(sb, __FUNCTION__,
663 "inode bitmap error for orphan %lu", ino); 663 "inode bitmap error for orphan %lu", ino);
664 goto out; 664 goto out;
665 } 665 }
@@ -668,14 +668,14 @@ struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino)
668 * is a valid orphan (no e2fsck run on fs). Orphans also include 668 * is a valid orphan (no e2fsck run on fs). Orphans also include
669 * inodes that were being truncated, so we can't check i_nlink==0. 669 * inodes that were being truncated, so we can't check i_nlink==0.
670 */ 670 */
671 if (!ext3_test_bit(bit, bitmap_bh->b_data) || 671 if (!ext4_test_bit(bit, bitmap_bh->b_data) ||
672 !(inode = iget(sb, ino)) || is_bad_inode(inode) || 672 !(inode = iget(sb, ino)) || is_bad_inode(inode) ||
673 NEXT_ORPHAN(inode) > max_ino) { 673 NEXT_ORPHAN(inode) > max_ino) {
674 ext3_warning(sb, __FUNCTION__, 674 ext4_warning(sb, __FUNCTION__,
675 "bad orphan inode %lu! e2fsck was run?", ino); 675 "bad orphan inode %lu! e2fsck was run?", ino);
676 printk(KERN_NOTICE "ext3_test_bit(bit=%d, block=%llu) = %d\n", 676 printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n",
677 bit, (unsigned long long)bitmap_bh->b_blocknr, 677 bit, (unsigned long long)bitmap_bh->b_blocknr,
678 ext3_test_bit(bit, bitmap_bh->b_data)); 678 ext4_test_bit(bit, bitmap_bh->b_data));
679 printk(KERN_NOTICE "inode=%p\n", inode); 679 printk(KERN_NOTICE "inode=%p\n", inode);
680 if (inode) { 680 if (inode) {
681 printk(KERN_NOTICE "is_bad_inode(inode)=%d\n", 681 printk(KERN_NOTICE "is_bad_inode(inode)=%d\n",
@@ -695,22 +695,22 @@ out:
695 return inode; 695 return inode;
696} 696}
697 697
698unsigned long ext3_count_free_inodes (struct super_block * sb) 698unsigned long ext4_count_free_inodes (struct super_block * sb)
699{ 699{
700 unsigned long desc_count; 700 unsigned long desc_count;
701 struct ext3_group_desc *gdp; 701 struct ext4_group_desc *gdp;
702 int i; 702 int i;
703#ifdef EXT3FS_DEBUG 703#ifdef EXT4FS_DEBUG
704 struct ext3_super_block *es; 704 struct ext4_super_block *es;
705 unsigned long bitmap_count, x; 705 unsigned long bitmap_count, x;
706 struct buffer_head *bitmap_bh = NULL; 706 struct buffer_head *bitmap_bh = NULL;
707 707
708 es = EXT3_SB(sb)->s_es; 708 es = EXT4_SB(sb)->s_es;
709 desc_count = 0; 709 desc_count = 0;
710 bitmap_count = 0; 710 bitmap_count = 0;
711 gdp = NULL; 711 gdp = NULL;
712 for (i = 0; i < EXT3_SB(sb)->s_groups_count; i++) { 712 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) {
713 gdp = ext3_get_group_desc (sb, i, NULL); 713 gdp = ext4_get_group_desc (sb, i, NULL);
714 if (!gdp) 714 if (!gdp)
715 continue; 715 continue;
716 desc_count += le16_to_cpu(gdp->bg_free_inodes_count); 716 desc_count += le16_to_cpu(gdp->bg_free_inodes_count);
@@ -719,19 +719,19 @@ unsigned long ext3_count_free_inodes (struct super_block * sb)
719 if (!bitmap_bh) 719 if (!bitmap_bh)
720 continue; 720 continue;
721 721
722 x = ext3_count_free(bitmap_bh, EXT3_INODES_PER_GROUP(sb) / 8); 722 x = ext4_count_free(bitmap_bh, EXT4_INODES_PER_GROUP(sb) / 8);
723 printk("group %d: stored = %d, counted = %lu\n", 723 printk("group %d: stored = %d, counted = %lu\n",
724 i, le16_to_cpu(gdp->bg_free_inodes_count), x); 724 i, le16_to_cpu(gdp->bg_free_inodes_count), x);
725 bitmap_count += x; 725 bitmap_count += x;
726 } 726 }
727 brelse(bitmap_bh); 727 brelse(bitmap_bh);
728 printk("ext3_count_free_inodes: stored = %u, computed = %lu, %lu\n", 728 printk("ext4_count_free_inodes: stored = %u, computed = %lu, %lu\n",
729 le32_to_cpu(es->s_free_inodes_count), desc_count, bitmap_count); 729 le32_to_cpu(es->s_free_inodes_count), desc_count, bitmap_count);
730 return desc_count; 730 return desc_count;
731#else 731#else
732 desc_count = 0; 732 desc_count = 0;
733 for (i = 0; i < EXT3_SB(sb)->s_groups_count; i++) { 733 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) {
734 gdp = ext3_get_group_desc (sb, i, NULL); 734 gdp = ext4_get_group_desc (sb, i, NULL);
735 if (!gdp) 735 if (!gdp)
736 continue; 736 continue;
737 desc_count += le16_to_cpu(gdp->bg_free_inodes_count); 737 desc_count += le16_to_cpu(gdp->bg_free_inodes_count);
@@ -742,13 +742,13 @@ unsigned long ext3_count_free_inodes (struct super_block * sb)
742} 742}
743 743
744/* Called at mount-time, super-block is locked */ 744/* Called at mount-time, super-block is locked */
745unsigned long ext3_count_dirs (struct super_block * sb) 745unsigned long ext4_count_dirs (struct super_block * sb)
746{ 746{
747 unsigned long count = 0; 747 unsigned long count = 0;
748 int i; 748 int i;
749 749
750 for (i = 0; i < EXT3_SB(sb)->s_groups_count; i++) { 750 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) {
751 struct ext3_group_desc *gdp = ext3_get_group_desc (sb, i, NULL); 751 struct ext4_group_desc *gdp = ext4_get_group_desc (sb, i, NULL);
752 if (!gdp) 752 if (!gdp)
753 continue; 753 continue;
754 count += le16_to_cpu(gdp->bg_used_dirs_count); 754 count += le16_to_cpu(gdp->bg_used_dirs_count);
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 03ba5bcab18..7275d60dcc5 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/inode.c 2 * linux/fs/ext4/inode.c
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -19,13 +19,13 @@
19 * 64-bit file support on 64-bit platforms by Jakub Jelinek 19 * 64-bit file support on 64-bit platforms by Jakub Jelinek
20 * (jj@sunsite.ms.mff.cuni.cz) 20 * (jj@sunsite.ms.mff.cuni.cz)
21 * 21 *
22 * Assorted race fixes, rewrite of ext3_get_block() by Al Viro, 2000 22 * Assorted race fixes, rewrite of ext4_get_block() by Al Viro, 2000
23 */ 23 */
24 24
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/fs.h> 26#include <linux/fs.h>
27#include <linux/time.h> 27#include <linux/time.h>
28#include <linux/ext3_jbd.h> 28#include <linux/ext4_jbd.h>
29#include <linux/jbd.h> 29#include <linux/jbd.h>
30#include <linux/smp_lock.h> 30#include <linux/smp_lock.h>
31#include <linux/highuid.h> 31#include <linux/highuid.h>
@@ -40,21 +40,21 @@
40#include "xattr.h" 40#include "xattr.h"
41#include "acl.h" 41#include "acl.h"
42 42
43static int ext3_writepage_trans_blocks(struct inode *inode); 43static int ext4_writepage_trans_blocks(struct inode *inode);
44 44
45/* 45/*
46 * Test whether an inode is a fast symlink. 46 * Test whether an inode is a fast symlink.
47 */ 47 */
48static int ext3_inode_is_fast_symlink(struct inode *inode) 48static int ext4_inode_is_fast_symlink(struct inode *inode)
49{ 49{
50 int ea_blocks = EXT3_I(inode)->i_file_acl ? 50 int ea_blocks = EXT4_I(inode)->i_file_acl ?
51 (inode->i_sb->s_blocksize >> 9) : 0; 51 (inode->i_sb->s_blocksize >> 9) : 0;
52 52
53 return (S_ISLNK(inode->i_mode) && inode->i_blocks - ea_blocks == 0); 53 return (S_ISLNK(inode->i_mode) && inode->i_blocks - ea_blocks == 0);
54} 54}
55 55
56/* 56/*
57 * The ext3 forget function must perform a revoke if we are freeing data 57 * The ext4 forget function must perform a revoke if we are freeing data
58 * which has been journaled. Metadata (eg. indirect blocks) must be 58 * which has been journaled. Metadata (eg. indirect blocks) must be
59 * revoked in all cases. 59 * revoked in all cases.
60 * 60 *
@@ -62,8 +62,8 @@ static int ext3_inode_is_fast_symlink(struct inode *inode)
62 * but there may still be a record of it in the journal, and that record 62 * but there may still be a record of it in the journal, and that record
63 * still needs to be revoked. 63 * still needs to be revoked.
64 */ 64 */
65int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode, 65int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode,
66 struct buffer_head *bh, ext3_fsblk_t blocknr) 66 struct buffer_head *bh, ext4_fsblk_t blocknr)
67{ 67{
68 int err; 68 int err;
69 69
@@ -81,11 +81,11 @@ int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode,
81 * support it. Otherwise, only skip the revoke on un-journaled 81 * support it. Otherwise, only skip the revoke on un-journaled
82 * data blocks. */ 82 * data blocks. */
83 83
84 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA || 84 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA ||
85 (!is_metadata && !ext3_should_journal_data(inode))) { 85 (!is_metadata && !ext4_should_journal_data(inode))) {
86 if (bh) { 86 if (bh) {
87 BUFFER_TRACE(bh, "call journal_forget"); 87 BUFFER_TRACE(bh, "call journal_forget");
88 return ext3_journal_forget(handle, bh); 88 return ext4_journal_forget(handle, bh);
89 } 89 }
90 return 0; 90 return 0;
91 } 91 }
@@ -93,10 +93,10 @@ int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode,
93 /* 93 /*
94 * data!=journal && (is_metadata || should_journal_data(inode)) 94 * data!=journal && (is_metadata || should_journal_data(inode))
95 */ 95 */
96 BUFFER_TRACE(bh, "call ext3_journal_revoke"); 96 BUFFER_TRACE(bh, "call ext4_journal_revoke");
97 err = ext3_journal_revoke(handle, blocknr, bh); 97 err = ext4_journal_revoke(handle, blocknr, bh);
98 if (err) 98 if (err)
99 ext3_abort(inode->i_sb, __FUNCTION__, 99 ext4_abort(inode->i_sb, __FUNCTION__,
100 "error %d when attempting revoke", err); 100 "error %d when attempting revoke", err);
101 BUFFER_TRACE(bh, "exit"); 101 BUFFER_TRACE(bh, "exit");
102 return err; 102 return err;
@@ -115,7 +115,7 @@ static unsigned long blocks_for_truncate(struct inode *inode)
115 /* Give ourselves just enough room to cope with inodes in which 115 /* Give ourselves just enough room to cope with inodes in which
116 * i_blocks is corrupt: we've seen disk corruptions in the past 116 * i_blocks is corrupt: we've seen disk corruptions in the past
117 * which resulted in random data in an inode which looked enough 117 * which resulted in random data in an inode which looked enough
118 * like a regular file for ext3 to try to delete it. Things 118 * like a regular file for ext4 to try to delete it. Things
119 * will go a bit crazy if that happens, but at least we should 119 * will go a bit crazy if that happens, but at least we should
120 * try not to panic the whole kernel. */ 120 * try not to panic the whole kernel. */
121 if (needed < 2) 121 if (needed < 2)
@@ -123,10 +123,10 @@ static unsigned long blocks_for_truncate(struct inode *inode)
123 123
124 /* But we need to bound the transaction so we don't overflow the 124 /* But we need to bound the transaction so we don't overflow the
125 * journal. */ 125 * journal. */
126 if (needed > EXT3_MAX_TRANS_DATA) 126 if (needed > EXT4_MAX_TRANS_DATA)
127 needed = EXT3_MAX_TRANS_DATA; 127 needed = EXT4_MAX_TRANS_DATA;
128 128
129 return EXT3_DATA_TRANS_BLOCKS(inode->i_sb) + needed; 129 return EXT4_DATA_TRANS_BLOCKS(inode->i_sb) + needed;
130} 130}
131 131
132/* 132/*
@@ -143,11 +143,11 @@ static handle_t *start_transaction(struct inode *inode)
143{ 143{
144 handle_t *result; 144 handle_t *result;
145 145
146 result = ext3_journal_start(inode, blocks_for_truncate(inode)); 146 result = ext4_journal_start(inode, blocks_for_truncate(inode));
147 if (!IS_ERR(result)) 147 if (!IS_ERR(result))
148 return result; 148 return result;
149 149
150 ext3_std_error(inode->i_sb, PTR_ERR(result)); 150 ext4_std_error(inode->i_sb, PTR_ERR(result));
151 return result; 151 return result;
152} 152}
153 153
@@ -159,9 +159,9 @@ static handle_t *start_transaction(struct inode *inode)
159 */ 159 */
160static int try_to_extend_transaction(handle_t *handle, struct inode *inode) 160static int try_to_extend_transaction(handle_t *handle, struct inode *inode)
161{ 161{
162 if (handle->h_buffer_credits > EXT3_RESERVE_TRANS_BLOCKS) 162 if (handle->h_buffer_credits > EXT4_RESERVE_TRANS_BLOCKS)
163 return 0; 163 return 0;
164 if (!ext3_journal_extend(handle, blocks_for_truncate(inode))) 164 if (!ext4_journal_extend(handle, blocks_for_truncate(inode)))
165 return 0; 165 return 0;
166 return 1; 166 return 1;
167} 167}
@@ -171,16 +171,16 @@ static int try_to_extend_transaction(handle_t *handle, struct inode *inode)
171 * so before we call here everything must be consistently dirtied against 171 * so before we call here everything must be consistently dirtied against
172 * this transaction. 172 * this transaction.
173 */ 173 */
174static int ext3_journal_test_restart(handle_t *handle, struct inode *inode) 174static int ext4_journal_test_restart(handle_t *handle, struct inode *inode)
175{ 175{
176 jbd_debug(2, "restarting handle %p\n", handle); 176 jbd_debug(2, "restarting handle %p\n", handle);
177 return ext3_journal_restart(handle, blocks_for_truncate(inode)); 177 return ext4_journal_restart(handle, blocks_for_truncate(inode));
178} 178}
179 179
180/* 180/*
181 * Called at the last iput() if i_nlink is zero. 181 * Called at the last iput() if i_nlink is zero.
182 */ 182 */
183void ext3_delete_inode (struct inode * inode) 183void ext4_delete_inode (struct inode * inode)
184{ 184{
185 handle_t *handle; 185 handle_t *handle;
186 186
@@ -196,7 +196,7 @@ void ext3_delete_inode (struct inode * inode)
196 * make sure that the in-core orphan linked list is properly 196 * make sure that the in-core orphan linked list is properly
197 * cleaned up. 197 * cleaned up.
198 */ 198 */
199 ext3_orphan_del(NULL, inode); 199 ext4_orphan_del(NULL, inode);
200 goto no_delete; 200 goto no_delete;
201 } 201 }
202 202
@@ -204,17 +204,17 @@ void ext3_delete_inode (struct inode * inode)
204 handle->h_sync = 1; 204 handle->h_sync = 1;
205 inode->i_size = 0; 205 inode->i_size = 0;
206 if (inode->i_blocks) 206 if (inode->i_blocks)
207 ext3_truncate(inode); 207 ext4_truncate(inode);
208 /* 208 /*
209 * Kill off the orphan record which ext3_truncate created. 209 * Kill off the orphan record which ext4_truncate created.
210 * AKPM: I think this can be inside the above `if'. 210 * AKPM: I think this can be inside the above `if'.
211 * Note that ext3_orphan_del() has to be able to cope with the 211 * Note that ext4_orphan_del() has to be able to cope with the
212 * deletion of a non-existent orphan - this is because we don't 212 * deletion of a non-existent orphan - this is because we don't
213 * know if ext3_truncate() actually created an orphan record. 213 * know if ext4_truncate() actually created an orphan record.
214 * (Well, we could do this if we need to, but heck - it works) 214 * (Well, we could do this if we need to, but heck - it works)
215 */ 215 */
216 ext3_orphan_del(handle, inode); 216 ext4_orphan_del(handle, inode);
217 EXT3_I(inode)->i_dtime = get_seconds(); 217 EXT4_I(inode)->i_dtime = get_seconds();
218 218
219 /* 219 /*
220 * One subtle ordering requirement: if anything has gone wrong 220 * One subtle ordering requirement: if anything has gone wrong
@@ -223,12 +223,12 @@ void ext3_delete_inode (struct inode * inode)
223 * having errors), but we can't free the inode if the mark_dirty 223 * having errors), but we can't free the inode if the mark_dirty
224 * fails. 224 * fails.
225 */ 225 */
226 if (ext3_mark_inode_dirty(handle, inode)) 226 if (ext4_mark_inode_dirty(handle, inode))
227 /* If that failed, just do the required in-core inode clear. */ 227 /* If that failed, just do the required in-core inode clear. */
228 clear_inode(inode); 228 clear_inode(inode);
229 else 229 else
230 ext3_free_inode(handle, inode); 230 ext4_free_inode(handle, inode);
231 ext3_journal_stop(handle); 231 ext4_journal_stop(handle);
232 return; 232 return;
233no_delete: 233no_delete:
234 clear_inode(inode); /* We must guarantee clearing of inode... */ 234 clear_inode(inode); /* We must guarantee clearing of inode... */
@@ -254,14 +254,14 @@ static int verify_chain(Indirect *from, Indirect *to)
254} 254}
255 255
256/** 256/**
257 * ext3_block_to_path - parse the block number into array of offsets 257 * ext4_block_to_path - parse the block number into array of offsets
258 * @inode: inode in question (we are only interested in its superblock) 258 * @inode: inode in question (we are only interested in its superblock)
259 * @i_block: block number to be parsed 259 * @i_block: block number to be parsed
260 * @offsets: array to store the offsets in 260 * @offsets: array to store the offsets in
261 * @boundary: set this non-zero if the referred-to block is likely to be 261 * @boundary: set this non-zero if the referred-to block is likely to be
262 * followed (on disk) by an indirect block. 262 * followed (on disk) by an indirect block.
263 * 263 *
264 * To store the locations of file's data ext3 uses a data structure common 264 * To store the locations of file's data ext4 uses a data structure common
265 * for UNIX filesystems - tree of pointers anchored in the inode, with 265 * for UNIX filesystems - tree of pointers anchored in the inode, with
266 * data blocks at leaves and indirect blocks in intermediate nodes. 266 * data blocks at leaves and indirect blocks in intermediate nodes.
267 * This function translates the block number into path in that tree - 267 * This function translates the block number into path in that tree -
@@ -284,39 +284,39 @@ static int verify_chain(Indirect *from, Indirect *to)
284 * get there at all. 284 * get there at all.
285 */ 285 */
286 286
287static int ext3_block_to_path(struct inode *inode, 287static int ext4_block_to_path(struct inode *inode,
288 long i_block, int offsets[4], int *boundary) 288 long i_block, int offsets[4], int *boundary)
289{ 289{
290 int ptrs = EXT3_ADDR_PER_BLOCK(inode->i_sb); 290 int ptrs = EXT4_ADDR_PER_BLOCK(inode->i_sb);
291 int ptrs_bits = EXT3_ADDR_PER_BLOCK_BITS(inode->i_sb); 291 int ptrs_bits = EXT4_ADDR_PER_BLOCK_BITS(inode->i_sb);
292 const long direct_blocks = EXT3_NDIR_BLOCKS, 292 const long direct_blocks = EXT4_NDIR_BLOCKS,
293 indirect_blocks = ptrs, 293 indirect_blocks = ptrs,
294 double_blocks = (1 << (ptrs_bits * 2)); 294 double_blocks = (1 << (ptrs_bits * 2));
295 int n = 0; 295 int n = 0;
296 int final = 0; 296 int final = 0;
297 297
298 if (i_block < 0) { 298 if (i_block < 0) {
299 ext3_warning (inode->i_sb, "ext3_block_to_path", "block < 0"); 299 ext4_warning (inode->i_sb, "ext4_block_to_path", "block < 0");
300 } else if (i_block < direct_blocks) { 300 } else if (i_block < direct_blocks) {
301 offsets[n++] = i_block; 301 offsets[n++] = i_block;
302 final = direct_blocks; 302 final = direct_blocks;
303 } else if ( (i_block -= direct_blocks) < indirect_blocks) { 303 } else if ( (i_block -= direct_blocks) < indirect_blocks) {
304 offsets[n++] = EXT3_IND_BLOCK; 304 offsets[n++] = EXT4_IND_BLOCK;
305 offsets[n++] = i_block; 305 offsets[n++] = i_block;
306 final = ptrs; 306 final = ptrs;
307 } else if ((i_block -= indirect_blocks) < double_blocks) { 307 } else if ((i_block -= indirect_blocks) < double_blocks) {
308 offsets[n++] = EXT3_DIND_BLOCK; 308 offsets[n++] = EXT4_DIND_BLOCK;
309 offsets[n++] = i_block >> ptrs_bits; 309 offsets[n++] = i_block >> ptrs_bits;
310 offsets[n++] = i_block & (ptrs - 1); 310 offsets[n++] = i_block & (ptrs - 1);
311 final = ptrs; 311 final = ptrs;
312 } else if (((i_block -= double_blocks) >> (ptrs_bits * 2)) < ptrs) { 312 } else if (((i_block -= double_blocks) >> (ptrs_bits * 2)) < ptrs) {
313 offsets[n++] = EXT3_TIND_BLOCK; 313 offsets[n++] = EXT4_TIND_BLOCK;
314 offsets[n++] = i_block >> (ptrs_bits * 2); 314 offsets[n++] = i_block >> (ptrs_bits * 2);
315 offsets[n++] = (i_block >> ptrs_bits) & (ptrs - 1); 315 offsets[n++] = (i_block >> ptrs_bits) & (ptrs - 1);
316 offsets[n++] = i_block & (ptrs - 1); 316 offsets[n++] = i_block & (ptrs - 1);
317 final = ptrs; 317 final = ptrs;
318 } else { 318 } else {
319 ext3_warning(inode->i_sb, "ext3_block_to_path", "block > big"); 319 ext4_warning(inode->i_sb, "ext4_block_to_path", "block > big");
320 } 320 }
321 if (boundary) 321 if (boundary)
322 *boundary = final - 1 - (i_block & (ptrs - 1)); 322 *boundary = final - 1 - (i_block & (ptrs - 1));
@@ -324,7 +324,7 @@ static int ext3_block_to_path(struct inode *inode,
324} 324}
325 325
326/** 326/**
327 * ext3_get_branch - read the chain of indirect blocks leading to data 327 * ext4_get_branch - read the chain of indirect blocks leading to data
328 * @inode: inode in question 328 * @inode: inode in question
329 * @depth: depth of the chain (1 - direct pointer, etc.) 329 * @depth: depth of the chain (1 - direct pointer, etc.)
330 * @offsets: offsets of pointers in inode/indirect blocks 330 * @offsets: offsets of pointers in inode/indirect blocks
@@ -352,7 +352,7 @@ static int ext3_block_to_path(struct inode *inode,
352 * or when it reads all @depth-1 indirect blocks successfully and finds 352 * or when it reads all @depth-1 indirect blocks successfully and finds
353 * the whole chain, all way to the data (returns %NULL, *err == 0). 353 * the whole chain, all way to the data (returns %NULL, *err == 0).
354 */ 354 */
355static Indirect *ext3_get_branch(struct inode *inode, int depth, int *offsets, 355static Indirect *ext4_get_branch(struct inode *inode, int depth, int *offsets,
356 Indirect chain[4], int *err) 356 Indirect chain[4], int *err)
357{ 357{
358 struct super_block *sb = inode->i_sb; 358 struct super_block *sb = inode->i_sb;
@@ -361,7 +361,7 @@ static Indirect *ext3_get_branch(struct inode *inode, int depth, int *offsets,
361 361
362 *err = 0; 362 *err = 0;
363 /* i_data is not going away, no lock needed */ 363 /* i_data is not going away, no lock needed */
364 add_chain (chain, NULL, EXT3_I(inode)->i_data + *offsets); 364 add_chain (chain, NULL, EXT4_I(inode)->i_data + *offsets);
365 if (!p->key) 365 if (!p->key)
366 goto no_block; 366 goto no_block;
367 while (--depth) { 367 while (--depth) {
@@ -389,7 +389,7 @@ no_block:
389} 389}
390 390
391/** 391/**
392 * ext3_find_near - find a place for allocation with sufficient locality 392 * ext4_find_near - find a place for allocation with sufficient locality
393 * @inode: owner 393 * @inode: owner
394 * @ind: descriptor of indirect block. 394 * @ind: descriptor of indirect block.
395 * 395 *
@@ -408,13 +408,13 @@ no_block:
408 * 408 *
409 * Caller must make sure that @ind is valid and will stay that way. 409 * Caller must make sure that @ind is valid and will stay that way.
410 */ 410 */
411static ext3_fsblk_t ext3_find_near(struct inode *inode, Indirect *ind) 411static ext4_fsblk_t ext4_find_near(struct inode *inode, Indirect *ind)
412{ 412{
413 struct ext3_inode_info *ei = EXT3_I(inode); 413 struct ext4_inode_info *ei = EXT4_I(inode);
414 __le32 *start = ind->bh ? (__le32*) ind->bh->b_data : ei->i_data; 414 __le32 *start = ind->bh ? (__le32*) ind->bh->b_data : ei->i_data;
415 __le32 *p; 415 __le32 *p;
416 ext3_fsblk_t bg_start; 416 ext4_fsblk_t bg_start;
417 ext3_grpblk_t colour; 417 ext4_grpblk_t colour;
418 418
419 /* Try to find previous block */ 419 /* Try to find previous block */
420 for (p = ind->p - 1; p >= start; p--) { 420 for (p = ind->p - 1; p >= start; p--) {
@@ -430,14 +430,14 @@ static ext3_fsblk_t ext3_find_near(struct inode *inode, Indirect *ind)
430 * It is going to be referred to from the inode itself? OK, just put it 430 * It is going to be referred to from the inode itself? OK, just put it
431 * into the same cylinder group then. 431 * into the same cylinder group then.
432 */ 432 */
433 bg_start = ext3_group_first_block_no(inode->i_sb, ei->i_block_group); 433 bg_start = ext4_group_first_block_no(inode->i_sb, ei->i_block_group);
434 colour = (current->pid % 16) * 434 colour = (current->pid % 16) *
435 (EXT3_BLOCKS_PER_GROUP(inode->i_sb) / 16); 435 (EXT4_BLOCKS_PER_GROUP(inode->i_sb) / 16);
436 return bg_start + colour; 436 return bg_start + colour;
437} 437}
438 438
439/** 439/**
440 * ext3_find_goal - find a prefered place for allocation. 440 * ext4_find_goal - find a prefered place for allocation.
441 * @inode: owner 441 * @inode: owner
442 * @block: block we want 442 * @block: block we want
443 * @chain: chain of indirect blocks 443 * @chain: chain of indirect blocks
@@ -448,12 +448,12 @@ static ext3_fsblk_t ext3_find_near(struct inode *inode, Indirect *ind)
448 * stores it in *@goal and returns zero. 448 * stores it in *@goal and returns zero.
449 */ 449 */
450 450
451static ext3_fsblk_t ext3_find_goal(struct inode *inode, long block, 451static ext4_fsblk_t ext4_find_goal(struct inode *inode, long block,
452 Indirect chain[4], Indirect *partial) 452 Indirect chain[4], Indirect *partial)
453{ 453{
454 struct ext3_block_alloc_info *block_i; 454 struct ext4_block_alloc_info *block_i;
455 455
456 block_i = EXT3_I(inode)->i_block_alloc_info; 456 block_i = EXT4_I(inode)->i_block_alloc_info;
457 457
458 /* 458 /*
459 * try the heuristic for sequential allocation, 459 * try the heuristic for sequential allocation,
@@ -464,11 +464,11 @@ static ext3_fsblk_t ext3_find_goal(struct inode *inode, long block,
464 return block_i->last_alloc_physical_block + 1; 464 return block_i->last_alloc_physical_block + 1;
465 } 465 }
466 466
467 return ext3_find_near(inode, partial); 467 return ext4_find_near(inode, partial);
468} 468}
469 469
470/** 470/**
471 * ext3_blks_to_allocate: Look up the block map and count the number 471 * ext4_blks_to_allocate: Look up the block map and count the number
472 * of direct blocks need to be allocated for the given branch. 472 * of direct blocks need to be allocated for the given branch.
473 * 473 *
474 * @branch: chain of indirect blocks 474 * @branch: chain of indirect blocks
@@ -479,7 +479,7 @@ static ext3_fsblk_t ext3_find_goal(struct inode *inode, long block,
479 * return the total number of blocks to be allocate, including the 479 * return the total number of blocks to be allocate, including the
480 * direct and indirect blocks. 480 * direct and indirect blocks.
481 */ 481 */
482static int ext3_blks_to_allocate(Indirect *branch, int k, unsigned long blks, 482static int ext4_blks_to_allocate(Indirect *branch, int k, unsigned long blks,
483 int blocks_to_boundary) 483 int blocks_to_boundary)
484{ 484{
485 unsigned long count = 0; 485 unsigned long count = 0;
@@ -506,7 +506,7 @@ static int ext3_blks_to_allocate(Indirect *branch, int k, unsigned long blks,
506} 506}
507 507
508/** 508/**
509 * ext3_alloc_blocks: multiple allocate blocks needed for a branch 509 * ext4_alloc_blocks: multiple allocate blocks needed for a branch
510 * @indirect_blks: the number of blocks need to allocate for indirect 510 * @indirect_blks: the number of blocks need to allocate for indirect
511 * blocks 511 * blocks
512 * 512 *
@@ -515,14 +515,14 @@ static int ext3_blks_to_allocate(Indirect *branch, int k, unsigned long blks,
515 * @blks: on return it will store the total number of allocated 515 * @blks: on return it will store the total number of allocated
516 * direct blocks 516 * direct blocks
517 */ 517 */
518static int ext3_alloc_blocks(handle_t *handle, struct inode *inode, 518static int ext4_alloc_blocks(handle_t *handle, struct inode *inode,
519 ext3_fsblk_t goal, int indirect_blks, int blks, 519 ext4_fsblk_t goal, int indirect_blks, int blks,
520 ext3_fsblk_t new_blocks[4], int *err) 520 ext4_fsblk_t new_blocks[4], int *err)
521{ 521{
522 int target, i; 522 int target, i;
523 unsigned long count = 0; 523 unsigned long count = 0;
524 int index = 0; 524 int index = 0;
525 ext3_fsblk_t current_block = 0; 525 ext4_fsblk_t current_block = 0;
526 int ret = 0; 526 int ret = 0;
527 527
528 /* 528 /*
@@ -538,7 +538,7 @@ static int ext3_alloc_blocks(handle_t *handle, struct inode *inode,
538 while (1) { 538 while (1) {
539 count = target; 539 count = target;
540 /* allocating blocks for indirect blocks and direct blocks */ 540 /* allocating blocks for indirect blocks and direct blocks */
541 current_block = ext3_new_blocks(handle,inode,goal,&count,err); 541 current_block = ext4_new_blocks(handle,inode,goal,&count,err);
542 if (*err) 542 if (*err)
543 goto failed_out; 543 goto failed_out;
544 544
@@ -562,12 +562,12 @@ static int ext3_alloc_blocks(handle_t *handle, struct inode *inode,
562 return ret; 562 return ret;
563failed_out: 563failed_out:
564 for (i = 0; i <index; i++) 564 for (i = 0; i <index; i++)
565 ext3_free_blocks(handle, inode, new_blocks[i], 1); 565 ext4_free_blocks(handle, inode, new_blocks[i], 1);
566 return ret; 566 return ret;
567} 567}
568 568
569/** 569/**
570 * ext3_alloc_branch - allocate and set up a chain of blocks. 570 * ext4_alloc_branch - allocate and set up a chain of blocks.
571 * @inode: owner 571 * @inode: owner
572 * @indirect_blks: number of allocated indirect blocks 572 * @indirect_blks: number of allocated indirect blocks
573 * @blks: number of allocated direct blocks 573 * @blks: number of allocated direct blocks
@@ -578,21 +578,21 @@ failed_out:
578 * links them into chain and (if we are synchronous) writes them to disk. 578 * links them into chain and (if we are synchronous) writes them to disk.
579 * In other words, it prepares a branch that can be spliced onto the 579 * In other words, it prepares a branch that can be spliced onto the
580 * inode. It stores the information about that chain in the branch[], in 580 * inode. It stores the information about that chain in the branch[], in
581 * the same format as ext3_get_branch() would do. We are calling it after 581 * the same format as ext4_get_branch() would do. We are calling it after
582 * we had read the existing part of chain and partial points to the last 582 * we had read the existing part of chain and partial points to the last
583 * triple of that (one with zero ->key). Upon the exit we have the same 583 * triple of that (one with zero ->key). Upon the exit we have the same
584 * picture as after the successful ext3_get_block(), except that in one 584 * picture as after the successful ext4_get_block(), except that in one
585 * place chain is disconnected - *branch->p is still zero (we did not 585 * place chain is disconnected - *branch->p is still zero (we did not
586 * set the last link), but branch->key contains the number that should 586 * set the last link), but branch->key contains the number that should
587 * be placed into *branch->p to fill that gap. 587 * be placed into *branch->p to fill that gap.
588 * 588 *
589 * If allocation fails we free all blocks we've allocated (and forget 589 * If allocation fails we free all blocks we've allocated (and forget
590 * their buffer_heads) and return the error value the from failed 590 * their buffer_heads) and return the error value the from failed
591 * ext3_alloc_block() (normally -ENOSPC). Otherwise we set the chain 591 * ext4_alloc_block() (normally -ENOSPC). Otherwise we set the chain
592 * as described above and return 0. 592 * as described above and return 0.
593 */ 593 */
594static int ext3_alloc_branch(handle_t *handle, struct inode *inode, 594static int ext4_alloc_branch(handle_t *handle, struct inode *inode,
595 int indirect_blks, int *blks, ext3_fsblk_t goal, 595 int indirect_blks, int *blks, ext4_fsblk_t goal,
596 int *offsets, Indirect *branch) 596 int *offsets, Indirect *branch)
597{ 597{
598 int blocksize = inode->i_sb->s_blocksize; 598 int blocksize = inode->i_sb->s_blocksize;
@@ -600,10 +600,10 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode,
600 int err = 0; 600 int err = 0;
601 struct buffer_head *bh; 601 struct buffer_head *bh;
602 int num; 602 int num;
603 ext3_fsblk_t new_blocks[4]; 603 ext4_fsblk_t new_blocks[4];
604 ext3_fsblk_t current_block; 604 ext4_fsblk_t current_block;
605 605
606 num = ext3_alloc_blocks(handle, inode, goal, indirect_blks, 606 num = ext4_alloc_blocks(handle, inode, goal, indirect_blks,
607 *blks, new_blocks, &err); 607 *blks, new_blocks, &err);
608 if (err) 608 if (err)
609 return err; 609 return err;
@@ -622,7 +622,7 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode,
622 branch[n].bh = bh; 622 branch[n].bh = bh;
623 lock_buffer(bh); 623 lock_buffer(bh);
624 BUFFER_TRACE(bh, "call get_create_access"); 624 BUFFER_TRACE(bh, "call get_create_access");
625 err = ext3_journal_get_create_access(handle, bh); 625 err = ext4_journal_get_create_access(handle, bh);
626 if (err) { 626 if (err) {
627 unlock_buffer(bh); 627 unlock_buffer(bh);
628 brelse(bh); 628 brelse(bh);
@@ -647,8 +647,8 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode,
647 set_buffer_uptodate(bh); 647 set_buffer_uptodate(bh);
648 unlock_buffer(bh); 648 unlock_buffer(bh);
649 649
650 BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata"); 650 BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
651 err = ext3_journal_dirty_metadata(handle, bh); 651 err = ext4_journal_dirty_metadata(handle, bh);
652 if (err) 652 if (err)
653 goto failed; 653 goto failed;
654 } 654 }
@@ -658,22 +658,22 @@ failed:
658 /* Allocation failed, free what we already allocated */ 658 /* Allocation failed, free what we already allocated */
659 for (i = 1; i <= n ; i++) { 659 for (i = 1; i <= n ; i++) {
660 BUFFER_TRACE(branch[i].bh, "call journal_forget"); 660 BUFFER_TRACE(branch[i].bh, "call journal_forget");
661 ext3_journal_forget(handle, branch[i].bh); 661 ext4_journal_forget(handle, branch[i].bh);
662 } 662 }
663 for (i = 0; i <indirect_blks; i++) 663 for (i = 0; i <indirect_blks; i++)
664 ext3_free_blocks(handle, inode, new_blocks[i], 1); 664 ext4_free_blocks(handle, inode, new_blocks[i], 1);
665 665
666 ext3_free_blocks(handle, inode, new_blocks[i], num); 666 ext4_free_blocks(handle, inode, new_blocks[i], num);
667 667
668 return err; 668 return err;
669} 669}
670 670
671/** 671/**
672 * ext3_splice_branch - splice the allocated branch onto inode. 672 * ext4_splice_branch - splice the allocated branch onto inode.
673 * @inode: owner 673 * @inode: owner
674 * @block: (logical) number of block we are adding 674 * @block: (logical) number of block we are adding
675 * @chain: chain of indirect blocks (with a missing link - see 675 * @chain: chain of indirect blocks (with a missing link - see
676 * ext3_alloc_branch) 676 * ext4_alloc_branch)
677 * @where: location of missing link 677 * @where: location of missing link
678 * @num: number of indirect blocks we are adding 678 * @num: number of indirect blocks we are adding
679 * @blks: number of direct blocks we are adding 679 * @blks: number of direct blocks we are adding
@@ -682,15 +682,15 @@ failed:
682 * inode (->i_blocks, etc.). In case of success we end up with the full 682 * inode (->i_blocks, etc.). In case of success we end up with the full
683 * chain to new block and return 0. 683 * chain to new block and return 0.
684 */ 684 */
685static int ext3_splice_branch(handle_t *handle, struct inode *inode, 685static int ext4_splice_branch(handle_t *handle, struct inode *inode,
686 long block, Indirect *where, int num, int blks) 686 long block, Indirect *where, int num, int blks)
687{ 687{
688 int i; 688 int i;
689 int err = 0; 689 int err = 0;
690 struct ext3_block_alloc_info *block_i; 690 struct ext4_block_alloc_info *block_i;
691 ext3_fsblk_t current_block; 691 ext4_fsblk_t current_block;
692 692
693 block_i = EXT3_I(inode)->i_block_alloc_info; 693 block_i = EXT4_I(inode)->i_block_alloc_info;
694 /* 694 /*
695 * If we're splicing into a [td]indirect block (as opposed to the 695 * If we're splicing into a [td]indirect block (as opposed to the
696 * inode) then we need to get write access to the [td]indirect block 696 * inode) then we need to get write access to the [td]indirect block
@@ -698,7 +698,7 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode,
698 */ 698 */
699 if (where->bh) { 699 if (where->bh) {
700 BUFFER_TRACE(where->bh, "get_write_access"); 700 BUFFER_TRACE(where->bh, "get_write_access");
701 err = ext3_journal_get_write_access(handle, where->bh); 701 err = ext4_journal_get_write_access(handle, where->bh);
702 if (err) 702 if (err)
703 goto err_out; 703 goto err_out;
704 } 704 }
@@ -730,7 +730,7 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode,
730 /* We are done with atomic stuff, now do the rest of housekeeping */ 730 /* We are done with atomic stuff, now do the rest of housekeeping */
731 731
732 inode->i_ctime = CURRENT_TIME_SEC; 732 inode->i_ctime = CURRENT_TIME_SEC;
733 ext3_mark_inode_dirty(handle, inode); 733 ext4_mark_inode_dirty(handle, inode);
734 734
735 /* had we spliced it onto indirect block? */ 735 /* had we spliced it onto indirect block? */
736 if (where->bh) { 736 if (where->bh) {
@@ -740,11 +740,11 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode,
740 * onto an indirect block at the very end of the file (the 740 * onto an indirect block at the very end of the file (the
741 * file is growing) then we *will* alter the inode to reflect 741 * file is growing) then we *will* alter the inode to reflect
742 * the new i_size. But that is not done here - it is done in 742 * the new i_size. But that is not done here - it is done in
743 * generic_commit_write->__mark_inode_dirty->ext3_dirty_inode. 743 * generic_commit_write->__mark_inode_dirty->ext4_dirty_inode.
744 */ 744 */
745 jbd_debug(5, "splicing indirect only\n"); 745 jbd_debug(5, "splicing indirect only\n");
746 BUFFER_TRACE(where->bh, "call ext3_journal_dirty_metadata"); 746 BUFFER_TRACE(where->bh, "call ext4_journal_dirty_metadata");
747 err = ext3_journal_dirty_metadata(handle, where->bh); 747 err = ext4_journal_dirty_metadata(handle, where->bh);
748 if (err) 748 if (err)
749 goto err_out; 749 goto err_out;
750 } else { 750 } else {
@@ -759,10 +759,10 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode,
759err_out: 759err_out:
760 for (i = 1; i <= num; i++) { 760 for (i = 1; i <= num; i++) {
761 BUFFER_TRACE(where[i].bh, "call journal_forget"); 761 BUFFER_TRACE(where[i].bh, "call journal_forget");
762 ext3_journal_forget(handle, where[i].bh); 762 ext4_journal_forget(handle, where[i].bh);
763 ext3_free_blocks(handle,inode,le32_to_cpu(where[i-1].key),1); 763 ext4_free_blocks(handle,inode,le32_to_cpu(where[i-1].key),1);
764 } 764 }
765 ext3_free_blocks(handle, inode, le32_to_cpu(where[num].key), blks); 765 ext4_free_blocks(handle, inode, le32_to_cpu(where[num].key), blks);
766 766
767 return err; 767 return err;
768} 768}
@@ -786,7 +786,7 @@ err_out:
786 * return = 0, if plain lookup failed. 786 * return = 0, if plain lookup failed.
787 * return < 0, error case. 787 * return < 0, error case.
788 */ 788 */
789int ext3_get_blocks_handle(handle_t *handle, struct inode *inode, 789int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
790 sector_t iblock, unsigned long maxblocks, 790 sector_t iblock, unsigned long maxblocks,
791 struct buffer_head *bh_result, 791 struct buffer_head *bh_result,
792 int create, int extend_disksize) 792 int create, int extend_disksize)
@@ -795,22 +795,22 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
795 int offsets[4]; 795 int offsets[4];
796 Indirect chain[4]; 796 Indirect chain[4];
797 Indirect *partial; 797 Indirect *partial;
798 ext3_fsblk_t goal; 798 ext4_fsblk_t goal;
799 int indirect_blks; 799 int indirect_blks;
800 int blocks_to_boundary = 0; 800 int blocks_to_boundary = 0;
801 int depth; 801 int depth;
802 struct ext3_inode_info *ei = EXT3_I(inode); 802 struct ext4_inode_info *ei = EXT4_I(inode);
803 int count = 0; 803 int count = 0;
804 ext3_fsblk_t first_block = 0; 804 ext4_fsblk_t first_block = 0;
805 805
806 806
807 J_ASSERT(handle != NULL || create == 0); 807 J_ASSERT(handle != NULL || create == 0);
808 depth = ext3_block_to_path(inode,iblock,offsets,&blocks_to_boundary); 808 depth = ext4_block_to_path(inode,iblock,offsets,&blocks_to_boundary);
809 809
810 if (depth == 0) 810 if (depth == 0)
811 goto out; 811 goto out;
812 812
813 partial = ext3_get_branch(inode, depth, offsets, chain, &err); 813 partial = ext4_get_branch(inode, depth, offsets, chain, &err);
814 814
815 /* Simplest case - block found, no allocation needed */ 815 /* Simplest case - block found, no allocation needed */
816 if (!partial) { 816 if (!partial) {
@@ -819,7 +819,7 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
819 count++; 819 count++;
820 /*map more blocks*/ 820 /*map more blocks*/
821 while (count < maxblocks && count <= blocks_to_boundary) { 821 while (count < maxblocks && count <= blocks_to_boundary) {
822 ext3_fsblk_t blk; 822 ext4_fsblk_t blk;
823 823
824 if (!verify_chain(chain, partial)) { 824 if (!verify_chain(chain, partial)) {
825 /* 825 /*
@@ -852,7 +852,7 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
852 852
853 /* 853 /*
854 * If the indirect block is missing while we are reading 854 * If the indirect block is missing while we are reading
855 * the chain(ext3_get_branch() returns -EAGAIN err), or 855 * the chain(ext4_get_branch() returns -EAGAIN err), or
856 * if the chain has been changed after we grab the semaphore, 856 * if the chain has been changed after we grab the semaphore,
857 * (either because another process truncated this branch, or 857 * (either because another process truncated this branch, or
858 * another get_block allocated this branch) re-grab the chain to see if 858 * another get_block allocated this branch) re-grab the chain to see if
@@ -867,7 +867,7 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
867 brelse(partial->bh); 867 brelse(partial->bh);
868 partial--; 868 partial--;
869 } 869 }
870 partial = ext3_get_branch(inode, depth, offsets, chain, &err); 870 partial = ext4_get_branch(inode, depth, offsets, chain, &err);
871 if (!partial) { 871 if (!partial) {
872 count++; 872 count++;
873 mutex_unlock(&ei->truncate_mutex); 873 mutex_unlock(&ei->truncate_mutex);
@@ -883,9 +883,9 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
883 * allocation info here if necessary 883 * allocation info here if necessary
884 */ 884 */
885 if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info)) 885 if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info))
886 ext3_init_block_alloc_info(inode); 886 ext4_init_block_alloc_info(inode);
887 887
888 goal = ext3_find_goal(inode, iblock, chain, partial); 888 goal = ext4_find_goal(inode, iblock, chain, partial);
889 889
890 /* the number of blocks need to allocate for [d,t]indirect blocks */ 890 /* the number of blocks need to allocate for [d,t]indirect blocks */
891 indirect_blks = (chain + depth) - partial - 1; 891 indirect_blks = (chain + depth) - partial - 1;
@@ -894,28 +894,28 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
894 * Next look up the indirect map to count the totoal number of 894 * Next look up the indirect map to count the totoal number of
895 * direct blocks to allocate for this branch. 895 * direct blocks to allocate for this branch.
896 */ 896 */
897 count = ext3_blks_to_allocate(partial, indirect_blks, 897 count = ext4_blks_to_allocate(partial, indirect_blks,
898 maxblocks, blocks_to_boundary); 898 maxblocks, blocks_to_boundary);
899 /* 899 /*
900 * Block out ext3_truncate while we alter the tree 900 * Block out ext4_truncate while we alter the tree
901 */ 901 */
902 err = ext3_alloc_branch(handle, inode, indirect_blks, &count, goal, 902 err = ext4_alloc_branch(handle, inode, indirect_blks, &count, goal,
903 offsets + (partial - chain), partial); 903 offsets + (partial - chain), partial);
904 904
905 /* 905 /*
906 * The ext3_splice_branch call will free and forget any buffers 906 * The ext4_splice_branch call will free and forget any buffers
907 * on the new chain if there is a failure, but that risks using 907 * on the new chain if there is a failure, but that risks using
908 * up transaction credits, especially for bitmaps where the 908 * up transaction credits, especially for bitmaps where the
909 * credits cannot be returned. Can we handle this somehow? We 909 * credits cannot be returned. Can we handle this somehow? We
910 * may need to return -EAGAIN upwards in the worst case. --sct 910 * may need to return -EAGAIN upwards in the worst case. --sct
911 */ 911 */
912 if (!err) 912 if (!err)
913 err = ext3_splice_branch(handle, inode, iblock, 913 err = ext4_splice_branch(handle, inode, iblock,
914 partial, indirect_blks, count); 914 partial, indirect_blks, count);
915 /* 915 /*
916 * i_disksize growing is protected by truncate_mutex. Don't forget to 916 * i_disksize growing is protected by truncate_mutex. Don't forget to
917 * protect it if you're about to implement concurrent 917 * protect it if you're about to implement concurrent
918 * ext3_get_block() -bzzz 918 * ext4_get_block() -bzzz
919 */ 919 */
920 if (!err && extend_disksize && inode->i_size > ei->i_disksize) 920 if (!err && extend_disksize && inode->i_size > ei->i_disksize)
921 ei->i_disksize = inode->i_size; 921 ei->i_disksize = inode->i_size;
@@ -942,9 +942,9 @@ out:
942 return err; 942 return err;
943} 943}
944 944
945#define DIO_CREDITS (EXT3_RESERVE_TRANS_BLOCKS + 32) 945#define DIO_CREDITS (EXT4_RESERVE_TRANS_BLOCKS + 32)
946 946
947static int ext3_get_block(struct inode *inode, sector_t iblock, 947static int ext4_get_block(struct inode *inode, sector_t iblock,
948 struct buffer_head *bh_result, int create) 948 struct buffer_head *bh_result, int create)
949{ 949{
950 handle_t *handle = journal_current_handle(); 950 handle_t *handle = journal_current_handle();
@@ -962,29 +962,29 @@ static int ext3_get_block(struct inode *inode, sector_t iblock,
962 * Huge direct-io writes can hold off commits for long 962 * Huge direct-io writes can hold off commits for long
963 * periods of time. Let this commit run. 963 * periods of time. Let this commit run.
964 */ 964 */
965 ext3_journal_stop(handle); 965 ext4_journal_stop(handle);
966 handle = ext3_journal_start(inode, DIO_CREDITS); 966 handle = ext4_journal_start(inode, DIO_CREDITS);
967 if (IS_ERR(handle)) 967 if (IS_ERR(handle))
968 ret = PTR_ERR(handle); 968 ret = PTR_ERR(handle);
969 goto get_block; 969 goto get_block;
970 } 970 }
971 971
972 if (handle->h_buffer_credits <= EXT3_RESERVE_TRANS_BLOCKS) { 972 if (handle->h_buffer_credits <= EXT4_RESERVE_TRANS_BLOCKS) {
973 /* 973 /*
974 * Getting low on buffer credits... 974 * Getting low on buffer credits...
975 */ 975 */
976 ret = ext3_journal_extend(handle, DIO_CREDITS); 976 ret = ext4_journal_extend(handle, DIO_CREDITS);
977 if (ret > 0) { 977 if (ret > 0) {
978 /* 978 /*
979 * Couldn't extend the transaction. Start a new one. 979 * Couldn't extend the transaction. Start a new one.
980 */ 980 */
981 ret = ext3_journal_restart(handle, DIO_CREDITS); 981 ret = ext4_journal_restart(handle, DIO_CREDITS);
982 } 982 }
983 } 983 }
984 984
985get_block: 985get_block:
986 if (ret == 0) { 986 if (ret == 0) {
987 ret = ext3_get_blocks_handle(handle, inode, iblock, 987 ret = ext4_get_blocks_handle(handle, inode, iblock,
988 max_blocks, bh_result, create, 0); 988 max_blocks, bh_result, create, 0);
989 if (ret > 0) { 989 if (ret > 0) {
990 bh_result->b_size = (ret << inode->i_blkbits); 990 bh_result->b_size = (ret << inode->i_blkbits);
@@ -997,7 +997,7 @@ get_block:
997/* 997/*
998 * `handle' can be NULL if create is zero 998 * `handle' can be NULL if create is zero
999 */ 999 */
1000struct buffer_head *ext3_getblk(handle_t *handle, struct inode *inode, 1000struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
1001 long block, int create, int *errp) 1001 long block, int create, int *errp)
1002{ 1002{
1003 struct buffer_head dummy; 1003 struct buffer_head dummy;
@@ -1008,10 +1008,10 @@ struct buffer_head *ext3_getblk(handle_t *handle, struct inode *inode,
1008 dummy.b_state = 0; 1008 dummy.b_state = 0;
1009 dummy.b_blocknr = -1000; 1009 dummy.b_blocknr = -1000;
1010 buffer_trace_init(&dummy.b_history); 1010 buffer_trace_init(&dummy.b_history);
1011 err = ext3_get_blocks_handle(handle, inode, block, 1, 1011 err = ext4_get_blocks_handle(handle, inode, block, 1,
1012 &dummy, create, 1); 1012 &dummy, create, 1);
1013 /* 1013 /*
1014 * ext3_get_blocks_handle() returns number of blocks 1014 * ext4_get_blocks_handle() returns number of blocks
1015 * mapped. 0 in case of a HOLE. 1015 * mapped. 0 in case of a HOLE.
1016 */ 1016 */
1017 if (err > 0) { 1017 if (err > 0) {
@@ -1035,19 +1035,19 @@ struct buffer_head *ext3_getblk(handle_t *handle, struct inode *inode,
1035 * Now that we do not always journal data, we should 1035 * Now that we do not always journal data, we should
1036 * keep in mind whether this should always journal the 1036 * keep in mind whether this should always journal the
1037 * new buffer as metadata. For now, regular file 1037 * new buffer as metadata. For now, regular file
1038 * writes use ext3_get_block instead, so it's not a 1038 * writes use ext4_get_block instead, so it's not a
1039 * problem. 1039 * problem.
1040 */ 1040 */
1041 lock_buffer(bh); 1041 lock_buffer(bh);
1042 BUFFER_TRACE(bh, "call get_create_access"); 1042 BUFFER_TRACE(bh, "call get_create_access");
1043 fatal = ext3_journal_get_create_access(handle, bh); 1043 fatal = ext4_journal_get_create_access(handle, bh);
1044 if (!fatal && !buffer_uptodate(bh)) { 1044 if (!fatal && !buffer_uptodate(bh)) {
1045 memset(bh->b_data,0,inode->i_sb->s_blocksize); 1045 memset(bh->b_data,0,inode->i_sb->s_blocksize);
1046 set_buffer_uptodate(bh); 1046 set_buffer_uptodate(bh);
1047 } 1047 }
1048 unlock_buffer(bh); 1048 unlock_buffer(bh);
1049 BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata"); 1049 BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
1050 err = ext3_journal_dirty_metadata(handle, bh); 1050 err = ext4_journal_dirty_metadata(handle, bh);
1051 if (!fatal) 1051 if (!fatal)
1052 fatal = err; 1052 fatal = err;
1053 } else { 1053 } else {
@@ -1064,12 +1064,12 @@ err:
1064 return NULL; 1064 return NULL;
1065} 1065}
1066 1066
1067struct buffer_head *ext3_bread(handle_t *handle, struct inode *inode, 1067struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode,
1068 int block, int create, int *err) 1068 int block, int create, int *err)
1069{ 1069{
1070 struct buffer_head * bh; 1070 struct buffer_head * bh;
1071 1071
1072 bh = ext3_getblk(handle, inode, block, create, err); 1072 bh = ext4_getblk(handle, inode, block, create, err);
1073 if (!bh) 1073 if (!bh)
1074 return bh; 1074 return bh;
1075 if (buffer_uptodate(bh)) 1075 if (buffer_uptodate(bh))
@@ -1118,17 +1118,17 @@ static int walk_page_buffers( handle_t *handle,
1118/* 1118/*
1119 * To preserve ordering, it is essential that the hole instantiation and 1119 * To preserve ordering, it is essential that the hole instantiation and
1120 * the data write be encapsulated in a single transaction. We cannot 1120 * the data write be encapsulated in a single transaction. We cannot
1121 * close off a transaction and start a new one between the ext3_get_block() 1121 * close off a transaction and start a new one between the ext4_get_block()
1122 * and the commit_write(). So doing the journal_start at the start of 1122 * and the commit_write(). So doing the journal_start at the start of
1123 * prepare_write() is the right place. 1123 * prepare_write() is the right place.
1124 * 1124 *
1125 * Also, this function can nest inside ext3_writepage() -> 1125 * Also, this function can nest inside ext4_writepage() ->
1126 * block_write_full_page(). In that case, we *know* that ext3_writepage() 1126 * block_write_full_page(). In that case, we *know* that ext4_writepage()
1127 * has generated enough buffer credits to do the whole page. So we won't 1127 * has generated enough buffer credits to do the whole page. So we won't
1128 * block on the journal in that case, which is good, because the caller may 1128 * block on the journal in that case, which is good, because the caller may
1129 * be PF_MEMALLOC. 1129 * be PF_MEMALLOC.
1130 * 1130 *
1131 * By accident, ext3 can be reentered when a transaction is open via 1131 * By accident, ext4 can be reentered when a transaction is open via
1132 * quota file writes. If we were to commit the transaction while thus 1132 * quota file writes. If we were to commit the transaction while thus
1133 * reentered, there can be a deadlock - we would be holding a quota 1133 * reentered, there can be a deadlock - we would be holding a quota
1134 * lock, and the commit would never complete if another thread had a 1134 * lock, and the commit would never complete if another thread had a
@@ -1145,48 +1145,48 @@ static int do_journal_get_write_access(handle_t *handle,
1145{ 1145{
1146 if (!buffer_mapped(bh) || buffer_freed(bh)) 1146 if (!buffer_mapped(bh) || buffer_freed(bh))
1147 return 0; 1147 return 0;
1148 return ext3_journal_get_write_access(handle, bh); 1148 return ext4_journal_get_write_access(handle, bh);
1149} 1149}
1150 1150
1151static int ext3_prepare_write(struct file *file, struct page *page, 1151static int ext4_prepare_write(struct file *file, struct page *page,
1152 unsigned from, unsigned to) 1152 unsigned from, unsigned to)
1153{ 1153{
1154 struct inode *inode = page->mapping->host; 1154 struct inode *inode = page->mapping->host;
1155 int ret, needed_blocks = ext3_writepage_trans_blocks(inode); 1155 int ret, needed_blocks = ext4_writepage_trans_blocks(inode);
1156 handle_t *handle; 1156 handle_t *handle;
1157 int retries = 0; 1157 int retries = 0;
1158 1158
1159retry: 1159retry:
1160 handle = ext3_journal_start(inode, needed_blocks); 1160 handle = ext4_journal_start(inode, needed_blocks);
1161 if (IS_ERR(handle)) { 1161 if (IS_ERR(handle)) {
1162 ret = PTR_ERR(handle); 1162 ret = PTR_ERR(handle);
1163 goto out; 1163 goto out;
1164 } 1164 }
1165 if (test_opt(inode->i_sb, NOBH) && ext3_should_writeback_data(inode)) 1165 if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode))
1166 ret = nobh_prepare_write(page, from, to, ext3_get_block); 1166 ret = nobh_prepare_write(page, from, to, ext4_get_block);
1167 else 1167 else
1168 ret = block_prepare_write(page, from, to, ext3_get_block); 1168 ret = block_prepare_write(page, from, to, ext4_get_block);
1169 if (ret) 1169 if (ret)
1170 goto prepare_write_failed; 1170 goto prepare_write_failed;
1171 1171
1172 if (ext3_should_journal_data(inode)) { 1172 if (ext4_should_journal_data(inode)) {
1173 ret = walk_page_buffers(handle, page_buffers(page), 1173 ret = walk_page_buffers(handle, page_buffers(page),
1174 from, to, NULL, do_journal_get_write_access); 1174 from, to, NULL, do_journal_get_write_access);
1175 } 1175 }
1176prepare_write_failed: 1176prepare_write_failed:
1177 if (ret) 1177 if (ret)
1178 ext3_journal_stop(handle); 1178 ext4_journal_stop(handle);
1179 if (ret == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries)) 1179 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
1180 goto retry; 1180 goto retry;
1181out: 1181out:
1182 return ret; 1182 return ret;
1183} 1183}
1184 1184
1185int ext3_journal_dirty_data(handle_t *handle, struct buffer_head *bh) 1185int ext4_journal_dirty_data(handle_t *handle, struct buffer_head *bh)
1186{ 1186{
1187 int err = journal_dirty_data(handle, bh); 1187 int err = journal_dirty_data(handle, bh);
1188 if (err) 1188 if (err)
1189 ext3_journal_abort_handle(__FUNCTION__, __FUNCTION__, 1189 ext4_journal_abort_handle(__FUNCTION__, __FUNCTION__,
1190 bh, handle,err); 1190 bh, handle,err);
1191 return err; 1191 return err;
1192} 1192}
@@ -1197,25 +1197,25 @@ static int commit_write_fn(handle_t *handle, struct buffer_head *bh)
1197 if (!buffer_mapped(bh) || buffer_freed(bh)) 1197 if (!buffer_mapped(bh) || buffer_freed(bh))
1198 return 0; 1198 return 0;
1199 set_buffer_uptodate(bh); 1199 set_buffer_uptodate(bh);
1200 return ext3_journal_dirty_metadata(handle, bh); 1200 return ext4_journal_dirty_metadata(handle, bh);
1201} 1201}
1202 1202
1203/* 1203/*
1204 * We need to pick up the new inode size which generic_commit_write gave us 1204 * We need to pick up the new inode size which generic_commit_write gave us
1205 * `file' can be NULL - eg, when called from page_symlink(). 1205 * `file' can be NULL - eg, when called from page_symlink().
1206 * 1206 *
1207 * ext3 never places buffers on inode->i_mapping->private_list. metadata 1207 * ext4 never places buffers on inode->i_mapping->private_list. metadata
1208 * buffers are managed internally. 1208 * buffers are managed internally.
1209 */ 1209 */
1210static int ext3_ordered_commit_write(struct file *file, struct page *page, 1210static int ext4_ordered_commit_write(struct file *file, struct page *page,
1211 unsigned from, unsigned to) 1211 unsigned from, unsigned to)
1212{ 1212{
1213 handle_t *handle = ext3_journal_current_handle(); 1213 handle_t *handle = ext4_journal_current_handle();
1214 struct inode *inode = page->mapping->host; 1214 struct inode *inode = page->mapping->host;
1215 int ret = 0, ret2; 1215 int ret = 0, ret2;
1216 1216
1217 ret = walk_page_buffers(handle, page_buffers(page), 1217 ret = walk_page_buffers(handle, page_buffers(page),
1218 from, to, NULL, ext3_journal_dirty_data); 1218 from, to, NULL, ext4_journal_dirty_data);
1219 1219
1220 if (ret == 0) { 1220 if (ret == 0) {
1221 /* 1221 /*
@@ -1226,43 +1226,43 @@ static int ext3_ordered_commit_write(struct file *file, struct page *page,
1226 loff_t new_i_size; 1226 loff_t new_i_size;
1227 1227
1228 new_i_size = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to; 1228 new_i_size = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
1229 if (new_i_size > EXT3_I(inode)->i_disksize) 1229 if (new_i_size > EXT4_I(inode)->i_disksize)
1230 EXT3_I(inode)->i_disksize = new_i_size; 1230 EXT4_I(inode)->i_disksize = new_i_size;
1231 ret = generic_commit_write(file, page, from, to); 1231 ret = generic_commit_write(file, page, from, to);
1232 } 1232 }
1233 ret2 = ext3_journal_stop(handle); 1233 ret2 = ext4_journal_stop(handle);
1234 if (!ret) 1234 if (!ret)
1235 ret = ret2; 1235 ret = ret2;
1236 return ret; 1236 return ret;
1237} 1237}
1238 1238
1239static int ext3_writeback_commit_write(struct file *file, struct page *page, 1239static int ext4_writeback_commit_write(struct file *file, struct page *page,
1240 unsigned from, unsigned to) 1240 unsigned from, unsigned to)
1241{ 1241{
1242 handle_t *handle = ext3_journal_current_handle(); 1242 handle_t *handle = ext4_journal_current_handle();
1243 struct inode *inode = page->mapping->host; 1243 struct inode *inode = page->mapping->host;
1244 int ret = 0, ret2; 1244 int ret = 0, ret2;
1245 loff_t new_i_size; 1245 loff_t new_i_size;
1246 1246
1247 new_i_size = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to; 1247 new_i_size = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
1248 if (new_i_size > EXT3_I(inode)->i_disksize) 1248 if (new_i_size > EXT4_I(inode)->i_disksize)
1249 EXT3_I(inode)->i_disksize = new_i_size; 1249 EXT4_I(inode)->i_disksize = new_i_size;
1250 1250
1251 if (test_opt(inode->i_sb, NOBH) && ext3_should_writeback_data(inode)) 1251 if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode))
1252 ret = nobh_commit_write(file, page, from, to); 1252 ret = nobh_commit_write(file, page, from, to);
1253 else 1253 else
1254 ret = generic_commit_write(file, page, from, to); 1254 ret = generic_commit_write(file, page, from, to);
1255 1255
1256 ret2 = ext3_journal_stop(handle); 1256 ret2 = ext4_journal_stop(handle);
1257 if (!ret) 1257 if (!ret)
1258 ret = ret2; 1258 ret = ret2;
1259 return ret; 1259 return ret;
1260} 1260}
1261 1261
1262static int ext3_journalled_commit_write(struct file *file, 1262static int ext4_journalled_commit_write(struct file *file,
1263 struct page *page, unsigned from, unsigned to) 1263 struct page *page, unsigned from, unsigned to)
1264{ 1264{
1265 handle_t *handle = ext3_journal_current_handle(); 1265 handle_t *handle = ext4_journal_current_handle();
1266 struct inode *inode = page->mapping->host; 1266 struct inode *inode = page->mapping->host;
1267 int ret = 0, ret2; 1267 int ret = 0, ret2;
1268 int partial = 0; 1268 int partial = 0;
@@ -1279,14 +1279,14 @@ static int ext3_journalled_commit_write(struct file *file,
1279 SetPageUptodate(page); 1279 SetPageUptodate(page);
1280 if (pos > inode->i_size) 1280 if (pos > inode->i_size)
1281 i_size_write(inode, pos); 1281 i_size_write(inode, pos);
1282 EXT3_I(inode)->i_state |= EXT3_STATE_JDATA; 1282 EXT4_I(inode)->i_state |= EXT4_STATE_JDATA;
1283 if (inode->i_size > EXT3_I(inode)->i_disksize) { 1283 if (inode->i_size > EXT4_I(inode)->i_disksize) {
1284 EXT3_I(inode)->i_disksize = inode->i_size; 1284 EXT4_I(inode)->i_disksize = inode->i_size;
1285 ret2 = ext3_mark_inode_dirty(handle, inode); 1285 ret2 = ext4_mark_inode_dirty(handle, inode);
1286 if (!ret) 1286 if (!ret)
1287 ret = ret2; 1287 ret = ret2;
1288 } 1288 }
1289 ret2 = ext3_journal_stop(handle); 1289 ret2 = ext4_journal_stop(handle);
1290 if (!ret) 1290 if (!ret)
1291 ret = ret2; 1291 ret = ret2;
1292 return ret; 1292 return ret;
@@ -1297,7 +1297,7 @@ static int ext3_journalled_commit_write(struct file *file,
1297 * the swapper to find the on-disk block of a specific piece of data. 1297 * the swapper to find the on-disk block of a specific piece of data.
1298 * 1298 *
1299 * Naturally, this is dangerous if the block concerned is still in the 1299 * Naturally, this is dangerous if the block concerned is still in the
1300 * journal. If somebody makes a swapfile on an ext3 data-journaling 1300 * journal. If somebody makes a swapfile on an ext4 data-journaling
1301 * filesystem and enables swap, then they may get a nasty shock when the 1301 * filesystem and enables swap, then they may get a nasty shock when the
1302 * data getting swapped to that swapfile suddenly gets overwritten by 1302 * data getting swapped to that swapfile suddenly gets overwritten by
1303 * the original zero's written out previously to the journal and 1303 * the original zero's written out previously to the journal and
@@ -1306,13 +1306,13 @@ static int ext3_journalled_commit_write(struct file *file,
1306 * So, if we see any bmap calls here on a modified, data-journaled file, 1306 * So, if we see any bmap calls here on a modified, data-journaled file,
1307 * take extra steps to flush any blocks which might be in the cache. 1307 * take extra steps to flush any blocks which might be in the cache.
1308 */ 1308 */
1309static sector_t ext3_bmap(struct address_space *mapping, sector_t block) 1309static sector_t ext4_bmap(struct address_space *mapping, sector_t block)
1310{ 1310{
1311 struct inode *inode = mapping->host; 1311 struct inode *inode = mapping->host;
1312 journal_t *journal; 1312 journal_t *journal;
1313 int err; 1313 int err;
1314 1314
1315 if (EXT3_I(inode)->i_state & EXT3_STATE_JDATA) { 1315 if (EXT4_I(inode)->i_state & EXT4_STATE_JDATA) {
1316 /* 1316 /*
1317 * This is a REALLY heavyweight approach, but the use of 1317 * This is a REALLY heavyweight approach, but the use of
1318 * bmap on dirty files is expected to be extremely rare: 1318 * bmap on dirty files is expected to be extremely rare:
@@ -1324,15 +1324,15 @@ static sector_t ext3_bmap(struct address_space *mapping, sector_t block)
1324 * in trouble if mortal users could trigger this path at 1324 * in trouble if mortal users could trigger this path at
1325 * will.) 1325 * will.)
1326 * 1326 *
1327 * NB. EXT3_STATE_JDATA is not set on files other than 1327 * NB. EXT4_STATE_JDATA is not set on files other than
1328 * regular files. If somebody wants to bmap a directory 1328 * regular files. If somebody wants to bmap a directory
1329 * or symlink and gets confused because the buffer 1329 * or symlink and gets confused because the buffer
1330 * hasn't yet been flushed to disk, they deserve 1330 * hasn't yet been flushed to disk, they deserve
1331 * everything they get. 1331 * everything they get.
1332 */ 1332 */
1333 1333
1334 EXT3_I(inode)->i_state &= ~EXT3_STATE_JDATA; 1334 EXT4_I(inode)->i_state &= ~EXT4_STATE_JDATA;
1335 journal = EXT3_JOURNAL(inode); 1335 journal = EXT4_JOURNAL(inode);
1336 journal_lock_updates(journal); 1336 journal_lock_updates(journal);
1337 err = journal_flush(journal); 1337 err = journal_flush(journal);
1338 journal_unlock_updates(journal); 1338 journal_unlock_updates(journal);
@@ -1341,7 +1341,7 @@ static sector_t ext3_bmap(struct address_space *mapping, sector_t block)
1341 return 0; 1341 return 0;
1342 } 1342 }
1343 1343
1344 return generic_block_bmap(mapping,block,ext3_get_block); 1344 return generic_block_bmap(mapping,block,ext4_get_block);
1345} 1345}
1346 1346
1347static int bget_one(handle_t *handle, struct buffer_head *bh) 1347static int bget_one(handle_t *handle, struct buffer_head *bh)
@@ -1359,14 +1359,14 @@ static int bput_one(handle_t *handle, struct buffer_head *bh)
1359static int journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh) 1359static int journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)
1360{ 1360{
1361 if (buffer_mapped(bh)) 1361 if (buffer_mapped(bh))
1362 return ext3_journal_dirty_data(handle, bh); 1362 return ext4_journal_dirty_data(handle, bh);
1363 return 0; 1363 return 0;
1364} 1364}
1365 1365
1366/* 1366/*
1367 * Note that we always start a transaction even if we're not journalling 1367 * Note that we always start a transaction even if we're not journalling
1368 * data. This is to preserve ordering: any hole instantiation within 1368 * data. This is to preserve ordering: any hole instantiation within
1369 * __block_write_full_page -> ext3_get_block() should be journalled 1369 * __block_write_full_page -> ext4_get_block() should be journalled
1370 * along with the data so we don't crash and then get metadata which 1370 * along with the data so we don't crash and then get metadata which
1371 * refers to old data. 1371 * refers to old data.
1372 * 1372 *
@@ -1374,14 +1374,14 @@ static int journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)
1374 * 1374 *
1375 * Problem: 1375 * Problem:
1376 * 1376 *
1377 * ext3_writepage() -> kmalloc() -> __alloc_pages() -> page_launder() -> 1377 * ext4_writepage() -> kmalloc() -> __alloc_pages() -> page_launder() ->
1378 * ext3_writepage() 1378 * ext4_writepage()
1379 * 1379 *
1380 * Similar for: 1380 * Similar for:
1381 * 1381 *
1382 * ext3_file_write() -> generic_file_write() -> __alloc_pages() -> ... 1382 * ext4_file_write() -> generic_file_write() -> __alloc_pages() -> ...
1383 * 1383 *
1384 * Same applies to ext3_get_block(). We will deadlock on various things like 1384 * Same applies to ext4_get_block(). We will deadlock on various things like
1385 * lock_journal and i_truncate_mutex. 1385 * lock_journal and i_truncate_mutex.
1386 * 1386 *
1387 * Setting PF_MEMALLOC here doesn't work - too many internal memory 1387 * Setting PF_MEMALLOC here doesn't work - too many internal memory
@@ -1415,7 +1415,7 @@ static int journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)
1415 * AKPM2: if all the page's buffers are mapped to disk and !data=journal, 1415 * AKPM2: if all the page's buffers are mapped to disk and !data=journal,
1416 * we don't need to open a transaction here. 1416 * we don't need to open a transaction here.
1417 */ 1417 */
1418static int ext3_ordered_writepage(struct page *page, 1418static int ext4_ordered_writepage(struct page *page,
1419 struct writeback_control *wbc) 1419 struct writeback_control *wbc)
1420{ 1420{
1421 struct inode *inode = page->mapping->host; 1421 struct inode *inode = page->mapping->host;
@@ -1430,10 +1430,10 @@ static int ext3_ordered_writepage(struct page *page,
1430 * We give up here if we're reentered, because it might be for a 1430 * We give up here if we're reentered, because it might be for a
1431 * different filesystem. 1431 * different filesystem.
1432 */ 1432 */
1433 if (ext3_journal_current_handle()) 1433 if (ext4_journal_current_handle())
1434 goto out_fail; 1434 goto out_fail;
1435 1435
1436 handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode)); 1436 handle = ext4_journal_start(inode, ext4_writepage_trans_blocks(inode));
1437 1437
1438 if (IS_ERR(handle)) { 1438 if (IS_ERR(handle)) {
1439 ret = PTR_ERR(handle); 1439 ret = PTR_ERR(handle);
@@ -1448,7 +1448,7 @@ static int ext3_ordered_writepage(struct page *page,
1448 walk_page_buffers(handle, page_bufs, 0, 1448 walk_page_buffers(handle, page_bufs, 0,
1449 PAGE_CACHE_SIZE, NULL, bget_one); 1449 PAGE_CACHE_SIZE, NULL, bget_one);
1450 1450
1451 ret = block_write_full_page(page, ext3_get_block, wbc); 1451 ret = block_write_full_page(page, ext4_get_block, wbc);
1452 1452
1453 /* 1453 /*
1454 * The page can become unlocked at any point now, and 1454 * The page can become unlocked at any point now, and
@@ -1470,7 +1470,7 @@ static int ext3_ordered_writepage(struct page *page,
1470 } 1470 }
1471 walk_page_buffers(handle, page_bufs, 0, 1471 walk_page_buffers(handle, page_bufs, 0,
1472 PAGE_CACHE_SIZE, NULL, bput_one); 1472 PAGE_CACHE_SIZE, NULL, bput_one);
1473 err = ext3_journal_stop(handle); 1473 err = ext4_journal_stop(handle);
1474 if (!ret) 1474 if (!ret)
1475 ret = err; 1475 ret = err;
1476 return ret; 1476 return ret;
@@ -1481,7 +1481,7 @@ out_fail:
1481 return ret; 1481 return ret;
1482} 1482}
1483 1483
1484static int ext3_writeback_writepage(struct page *page, 1484static int ext4_writeback_writepage(struct page *page,
1485 struct writeback_control *wbc) 1485 struct writeback_control *wbc)
1486{ 1486{
1487 struct inode *inode = page->mapping->host; 1487 struct inode *inode = page->mapping->host;
@@ -1489,21 +1489,21 @@ static int ext3_writeback_writepage(struct page *page,
1489 int ret = 0; 1489 int ret = 0;
1490 int err; 1490 int err;
1491 1491
1492 if (ext3_journal_current_handle()) 1492 if (ext4_journal_current_handle())
1493 goto out_fail; 1493 goto out_fail;
1494 1494
1495 handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode)); 1495 handle = ext4_journal_start(inode, ext4_writepage_trans_blocks(inode));
1496 if (IS_ERR(handle)) { 1496 if (IS_ERR(handle)) {
1497 ret = PTR_ERR(handle); 1497 ret = PTR_ERR(handle);
1498 goto out_fail; 1498 goto out_fail;
1499 } 1499 }
1500 1500
1501 if (test_opt(inode->i_sb, NOBH) && ext3_should_writeback_data(inode)) 1501 if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode))
1502 ret = nobh_writepage(page, ext3_get_block, wbc); 1502 ret = nobh_writepage(page, ext4_get_block, wbc);
1503 else 1503 else
1504 ret = block_write_full_page(page, ext3_get_block, wbc); 1504 ret = block_write_full_page(page, ext4_get_block, wbc);
1505 1505
1506 err = ext3_journal_stop(handle); 1506 err = ext4_journal_stop(handle);
1507 if (!ret) 1507 if (!ret)
1508 ret = err; 1508 ret = err;
1509 return ret; 1509 return ret;
@@ -1514,7 +1514,7 @@ out_fail:
1514 return ret; 1514 return ret;
1515} 1515}
1516 1516
1517static int ext3_journalled_writepage(struct page *page, 1517static int ext4_journalled_writepage(struct page *page,
1518 struct writeback_control *wbc) 1518 struct writeback_control *wbc)
1519{ 1519{
1520 struct inode *inode = page->mapping->host; 1520 struct inode *inode = page->mapping->host;
@@ -1522,10 +1522,10 @@ static int ext3_journalled_writepage(struct page *page,
1522 int ret = 0; 1522 int ret = 0;
1523 int err; 1523 int err;
1524 1524
1525 if (ext3_journal_current_handle()) 1525 if (ext4_journal_current_handle())
1526 goto no_write; 1526 goto no_write;
1527 1527
1528 handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode)); 1528 handle = ext4_journal_start(inode, ext4_writepage_trans_blocks(inode));
1529 if (IS_ERR(handle)) { 1529 if (IS_ERR(handle)) {
1530 ret = PTR_ERR(handle); 1530 ret = PTR_ERR(handle);
1531 goto no_write; 1531 goto no_write;
@@ -1538,9 +1538,9 @@ static int ext3_journalled_writepage(struct page *page,
1538 */ 1538 */
1539 ClearPageChecked(page); 1539 ClearPageChecked(page);
1540 ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE, 1540 ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE,
1541 ext3_get_block); 1541 ext4_get_block);
1542 if (ret != 0) { 1542 if (ret != 0) {
1543 ext3_journal_stop(handle); 1543 ext4_journal_stop(handle);
1544 goto out_unlock; 1544 goto out_unlock;
1545 } 1545 }
1546 ret = walk_page_buffers(handle, page_buffers(page), 0, 1546 ret = walk_page_buffers(handle, page_buffers(page), 0,
@@ -1550,7 +1550,7 @@ static int ext3_journalled_writepage(struct page *page,
1550 PAGE_CACHE_SIZE, NULL, commit_write_fn); 1550 PAGE_CACHE_SIZE, NULL, commit_write_fn);
1551 if (ret == 0) 1551 if (ret == 0)
1552 ret = err; 1552 ret = err;
1553 EXT3_I(inode)->i_state |= EXT3_STATE_JDATA; 1553 EXT4_I(inode)->i_state |= EXT4_STATE_JDATA;
1554 unlock_page(page); 1554 unlock_page(page);
1555 } else { 1555 } else {
1556 /* 1556 /*
@@ -1558,9 +1558,9 @@ static int ext3_journalled_writepage(struct page *page,
1558 * really know unless we go poke around in the buffer_heads. 1558 * really know unless we go poke around in the buffer_heads.
1559 * But block_write_full_page will do the right thing. 1559 * But block_write_full_page will do the right thing.
1560 */ 1560 */
1561 ret = block_write_full_page(page, ext3_get_block, wbc); 1561 ret = block_write_full_page(page, ext4_get_block, wbc);
1562 } 1562 }
1563 err = ext3_journal_stop(handle); 1563 err = ext4_journal_stop(handle);
1564 if (!ret) 1564 if (!ret)
1565 ret = err; 1565 ret = err;
1566out: 1566out:
@@ -1573,21 +1573,21 @@ out_unlock:
1573 goto out; 1573 goto out;
1574} 1574}
1575 1575
1576static int ext3_readpage(struct file *file, struct page *page) 1576static int ext4_readpage(struct file *file, struct page *page)
1577{ 1577{
1578 return mpage_readpage(page, ext3_get_block); 1578 return mpage_readpage(page, ext4_get_block);
1579} 1579}
1580 1580
1581static int 1581static int
1582ext3_readpages(struct file *file, struct address_space *mapping, 1582ext4_readpages(struct file *file, struct address_space *mapping,
1583 struct list_head *pages, unsigned nr_pages) 1583 struct list_head *pages, unsigned nr_pages)
1584{ 1584{
1585 return mpage_readpages(mapping, pages, nr_pages, ext3_get_block); 1585 return mpage_readpages(mapping, pages, nr_pages, ext4_get_block);
1586} 1586}
1587 1587
1588static void ext3_invalidatepage(struct page *page, unsigned long offset) 1588static void ext4_invalidatepage(struct page *page, unsigned long offset)
1589{ 1589{
1590 journal_t *journal = EXT3_JOURNAL(page->mapping->host); 1590 journal_t *journal = EXT4_JOURNAL(page->mapping->host);
1591 1591
1592 /* 1592 /*
1593 * If it's a full truncate we just forget about the pending dirtying 1593 * If it's a full truncate we just forget about the pending dirtying
@@ -1598,9 +1598,9 @@ static void ext3_invalidatepage(struct page *page, unsigned long offset)
1598 journal_invalidatepage(journal, page, offset); 1598 journal_invalidatepage(journal, page, offset);
1599} 1599}
1600 1600
1601static int ext3_releasepage(struct page *page, gfp_t wait) 1601static int ext4_releasepage(struct page *page, gfp_t wait)
1602{ 1602{
1603 journal_t *journal = EXT3_JOURNAL(page->mapping->host); 1603 journal_t *journal = EXT4_JOURNAL(page->mapping->host);
1604 1604
1605 WARN_ON(PageChecked(page)); 1605 WARN_ON(PageChecked(page));
1606 if (!page_has_buffers(page)) 1606 if (!page_has_buffers(page))
@@ -1616,13 +1616,13 @@ static int ext3_releasepage(struct page *page, gfp_t wait)
1616 * If the O_DIRECT write is intantiating holes inside i_size and the machine 1616 * If the O_DIRECT write is intantiating holes inside i_size and the machine
1617 * crashes then stale disk data _may_ be exposed inside the file. 1617 * crashes then stale disk data _may_ be exposed inside the file.
1618 */ 1618 */
1619static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, 1619static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb,
1620 const struct iovec *iov, loff_t offset, 1620 const struct iovec *iov, loff_t offset,
1621 unsigned long nr_segs) 1621 unsigned long nr_segs)
1622{ 1622{
1623 struct file *file = iocb->ki_filp; 1623 struct file *file = iocb->ki_filp;
1624 struct inode *inode = file->f_mapping->host; 1624 struct inode *inode = file->f_mapping->host;
1625 struct ext3_inode_info *ei = EXT3_I(inode); 1625 struct ext4_inode_info *ei = EXT4_I(inode);
1626 handle_t *handle = NULL; 1626 handle_t *handle = NULL;
1627 ssize_t ret; 1627 ssize_t ret;
1628 int orphan = 0; 1628 int orphan = 0;
@@ -1631,13 +1631,13 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
1631 if (rw == WRITE) { 1631 if (rw == WRITE) {
1632 loff_t final_size = offset + count; 1632 loff_t final_size = offset + count;
1633 1633
1634 handle = ext3_journal_start(inode, DIO_CREDITS); 1634 handle = ext4_journal_start(inode, DIO_CREDITS);
1635 if (IS_ERR(handle)) { 1635 if (IS_ERR(handle)) {
1636 ret = PTR_ERR(handle); 1636 ret = PTR_ERR(handle);
1637 goto out; 1637 goto out;
1638 } 1638 }
1639 if (final_size > inode->i_size) { 1639 if (final_size > inode->i_size) {
1640 ret = ext3_orphan_add(handle, inode); 1640 ret = ext4_orphan_add(handle, inode);
1641 if (ret) 1641 if (ret)
1642 goto out_stop; 1642 goto out_stop;
1643 orphan = 1; 1643 orphan = 1;
@@ -1647,10 +1647,10 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
1647 1647
1648 ret = blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, 1648 ret = blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov,
1649 offset, nr_segs, 1649 offset, nr_segs,
1650 ext3_get_block, NULL); 1650 ext4_get_block, NULL);
1651 1651
1652 /* 1652 /*
1653 * Reacquire the handle: ext3_get_block() can restart the transaction 1653 * Reacquire the handle: ext4_get_block() can restart the transaction
1654 */ 1654 */
1655 handle = journal_current_handle(); 1655 handle = journal_current_handle();
1656 1656
@@ -1659,7 +1659,7 @@ out_stop:
1659 int err; 1659 int err;
1660 1660
1661 if (orphan && inode->i_nlink) 1661 if (orphan && inode->i_nlink)
1662 ext3_orphan_del(handle, inode); 1662 ext4_orphan_del(handle, inode);
1663 if (orphan && ret > 0) { 1663 if (orphan && ret > 0) {
1664 loff_t end = offset + ret; 1664 loff_t end = offset + ret;
1665 if (end > inode->i_size) { 1665 if (end > inode->i_size) {
@@ -1669,13 +1669,13 @@ out_stop:
1669 * We're going to return a positive `ret' 1669 * We're going to return a positive `ret'
1670 * here due to non-zero-length I/O, so there's 1670 * here due to non-zero-length I/O, so there's
1671 * no way of reporting error returns from 1671 * no way of reporting error returns from
1672 * ext3_mark_inode_dirty() to userspace. So 1672 * ext4_mark_inode_dirty() to userspace. So
1673 * ignore it. 1673 * ignore it.
1674 */ 1674 */
1675 ext3_mark_inode_dirty(handle, inode); 1675 ext4_mark_inode_dirty(handle, inode);
1676 } 1676 }
1677 } 1677 }
1678 err = ext3_journal_stop(handle); 1678 err = ext4_journal_stop(handle);
1679 if (ret == 0) 1679 if (ret == 0)
1680 ret = err; 1680 ret = err;
1681 } 1681 }
@@ -1684,7 +1684,7 @@ out:
1684} 1684}
1685 1685
1686/* 1686/*
1687 * Pages can be marked dirty completely asynchronously from ext3's journalling 1687 * Pages can be marked dirty completely asynchronously from ext4's journalling
1688 * activity. By filemap_sync_pte(), try_to_unmap_one(), etc. We cannot do 1688 * activity. By filemap_sync_pte(), try_to_unmap_one(), etc. We cannot do
1689 * much here because ->set_page_dirty is called under VFS locks. The page is 1689 * much here because ->set_page_dirty is called under VFS locks. The page is
1690 * not necessarily locked. 1690 * not necessarily locked.
@@ -1696,73 +1696,73 @@ out:
1696 * So what we do is to mark the page "pending dirty" and next time writepage 1696 * So what we do is to mark the page "pending dirty" and next time writepage
1697 * is called, propagate that into the buffers appropriately. 1697 * is called, propagate that into the buffers appropriately.
1698 */ 1698 */
1699static int ext3_journalled_set_page_dirty(struct page *page) 1699static int ext4_journalled_set_page_dirty(struct page *page)
1700{ 1700{
1701 SetPageChecked(page); 1701 SetPageChecked(page);
1702 return __set_page_dirty_nobuffers(page); 1702 return __set_page_dirty_nobuffers(page);
1703} 1703}
1704 1704
1705static const struct address_space_operations ext3_ordered_aops = { 1705static const struct address_space_operations ext4_ordered_aops = {
1706 .readpage = ext3_readpage, 1706 .readpage = ext4_readpage,
1707 .readpages = ext3_readpages, 1707 .readpages = ext4_readpages,
1708 .writepage = ext3_ordered_writepage, 1708 .writepage = ext4_ordered_writepage,
1709 .sync_page = block_sync_page, 1709 .sync_page = block_sync_page,
1710 .prepare_write = ext3_prepare_write, 1710 .prepare_write = ext4_prepare_write,
1711 .commit_write = ext3_ordered_commit_write, 1711 .commit_write = ext4_ordered_commit_write,
1712 .bmap = ext3_bmap, 1712 .bmap = ext4_bmap,
1713 .invalidatepage = ext3_invalidatepage, 1713 .invalidatepage = ext4_invalidatepage,
1714 .releasepage = ext3_releasepage, 1714 .releasepage = ext4_releasepage,
1715 .direct_IO = ext3_direct_IO, 1715 .direct_IO = ext4_direct_IO,
1716 .migratepage = buffer_migrate_page, 1716 .migratepage = buffer_migrate_page,
1717}; 1717};
1718 1718
1719static const struct address_space_operations ext3_writeback_aops = { 1719static const struct address_space_operations ext4_writeback_aops = {
1720 .readpage = ext3_readpage, 1720 .readpage = ext4_readpage,
1721 .readpages = ext3_readpages, 1721 .readpages = ext4_readpages,
1722 .writepage = ext3_writeback_writepage, 1722 .writepage = ext4_writeback_writepage,
1723 .sync_page = block_sync_page, 1723 .sync_page = block_sync_page,
1724 .prepare_write = ext3_prepare_write, 1724 .prepare_write = ext4_prepare_write,
1725 .commit_write = ext3_writeback_commit_write, 1725 .commit_write = ext4_writeback_commit_write,
1726 .bmap = ext3_bmap, 1726 .bmap = ext4_bmap,
1727 .invalidatepage = ext3_invalidatepage, 1727 .invalidatepage = ext4_invalidatepage,
1728 .releasepage = ext3_releasepage, 1728 .releasepage = ext4_releasepage,
1729 .direct_IO = ext3_direct_IO, 1729 .direct_IO = ext4_direct_IO,
1730 .migratepage = buffer_migrate_page, 1730 .migratepage = buffer_migrate_page,
1731}; 1731};
1732 1732
1733static const struct address_space_operations ext3_journalled_aops = { 1733static const struct address_space_operations ext4_journalled_aops = {
1734 .readpage = ext3_readpage, 1734 .readpage = ext4_readpage,
1735 .readpages = ext3_readpages, 1735 .readpages = ext4_readpages,
1736 .writepage = ext3_journalled_writepage, 1736 .writepage = ext4_journalled_writepage,
1737 .sync_page = block_sync_page, 1737 .sync_page = block_sync_page,
1738 .prepare_write = ext3_prepare_write, 1738 .prepare_write = ext4_prepare_write,
1739 .commit_write = ext3_journalled_commit_write, 1739 .commit_write = ext4_journalled_commit_write,
1740 .set_page_dirty = ext3_journalled_set_page_dirty, 1740 .set_page_dirty = ext4_journalled_set_page_dirty,
1741 .bmap = ext3_bmap, 1741 .bmap = ext4_bmap,
1742 .invalidatepage = ext3_invalidatepage, 1742 .invalidatepage = ext4_invalidatepage,
1743 .releasepage = ext3_releasepage, 1743 .releasepage = ext4_releasepage,
1744}; 1744};
1745 1745
1746void ext3_set_aops(struct inode *inode) 1746void ext4_set_aops(struct inode *inode)
1747{ 1747{
1748 if (ext3_should_order_data(inode)) 1748 if (ext4_should_order_data(inode))
1749 inode->i_mapping->a_ops = &ext3_ordered_aops; 1749 inode->i_mapping->a_ops = &ext4_ordered_aops;
1750 else if (ext3_should_writeback_data(inode)) 1750 else if (ext4_should_writeback_data(inode))
1751 inode->i_mapping->a_ops = &ext3_writeback_aops; 1751 inode->i_mapping->a_ops = &ext4_writeback_aops;
1752 else 1752 else
1753 inode->i_mapping->a_ops = &ext3_journalled_aops; 1753 inode->i_mapping->a_ops = &ext4_journalled_aops;
1754} 1754}
1755 1755
1756/* 1756/*
1757 * ext3_block_truncate_page() zeroes out a mapping from file offset `from' 1757 * ext4_block_truncate_page() zeroes out a mapping from file offset `from'
1758 * up to the end of the block which corresponds to `from'. 1758 * up to the end of the block which corresponds to `from'.
1759 * This required during truncate. We need to physically zero the tail end 1759 * This required during truncate. We need to physically zero the tail end
1760 * of that block so it doesn't yield old data if the file is later grown. 1760 * of that block so it doesn't yield old data if the file is later grown.
1761 */ 1761 */
1762static int ext3_block_truncate_page(handle_t *handle, struct page *page, 1762static int ext4_block_truncate_page(handle_t *handle, struct page *page,
1763 struct address_space *mapping, loff_t from) 1763 struct address_space *mapping, loff_t from)
1764{ 1764{
1765 ext3_fsblk_t index = from >> PAGE_CACHE_SHIFT; 1765 ext4_fsblk_t index = from >> PAGE_CACHE_SHIFT;
1766 unsigned offset = from & (PAGE_CACHE_SIZE-1); 1766 unsigned offset = from & (PAGE_CACHE_SIZE-1);
1767 unsigned blocksize, iblock, length, pos; 1767 unsigned blocksize, iblock, length, pos;
1768 struct inode *inode = mapping->host; 1768 struct inode *inode = mapping->host;
@@ -1779,7 +1779,7 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page,
1779 * read-in the page - otherwise we create buffers to do the IO. 1779 * read-in the page - otherwise we create buffers to do the IO.
1780 */ 1780 */
1781 if (!page_has_buffers(page) && test_opt(inode->i_sb, NOBH) && 1781 if (!page_has_buffers(page) && test_opt(inode->i_sb, NOBH) &&
1782 ext3_should_writeback_data(inode) && PageUptodate(page)) { 1782 ext4_should_writeback_data(inode) && PageUptodate(page)) {
1783 kaddr = kmap_atomic(page, KM_USER0); 1783 kaddr = kmap_atomic(page, KM_USER0);
1784 memset(kaddr + offset, 0, length); 1784 memset(kaddr + offset, 0, length);
1785 flush_dcache_page(page); 1785 flush_dcache_page(page);
@@ -1808,7 +1808,7 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page,
1808 1808
1809 if (!buffer_mapped(bh)) { 1809 if (!buffer_mapped(bh)) {
1810 BUFFER_TRACE(bh, "unmapped"); 1810 BUFFER_TRACE(bh, "unmapped");
1811 ext3_get_block(inode, iblock, bh, 0); 1811 ext4_get_block(inode, iblock, bh, 0);
1812 /* unmapped? It's a hole - nothing to do */ 1812 /* unmapped? It's a hole - nothing to do */
1813 if (!buffer_mapped(bh)) { 1813 if (!buffer_mapped(bh)) {
1814 BUFFER_TRACE(bh, "still unmapped"); 1814 BUFFER_TRACE(bh, "still unmapped");
@@ -1829,9 +1829,9 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page,
1829 goto unlock; 1829 goto unlock;
1830 } 1830 }
1831 1831
1832 if (ext3_should_journal_data(inode)) { 1832 if (ext4_should_journal_data(inode)) {
1833 BUFFER_TRACE(bh, "get write access"); 1833 BUFFER_TRACE(bh, "get write access");
1834 err = ext3_journal_get_write_access(handle, bh); 1834 err = ext4_journal_get_write_access(handle, bh);
1835 if (err) 1835 if (err)
1836 goto unlock; 1836 goto unlock;
1837 } 1837 }
@@ -1844,11 +1844,11 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page,
1844 BUFFER_TRACE(bh, "zeroed end of block"); 1844 BUFFER_TRACE(bh, "zeroed end of block");
1845 1845
1846 err = 0; 1846 err = 0;
1847 if (ext3_should_journal_data(inode)) { 1847 if (ext4_should_journal_data(inode)) {
1848 err = ext3_journal_dirty_metadata(handle, bh); 1848 err = ext4_journal_dirty_metadata(handle, bh);
1849 } else { 1849 } else {
1850 if (ext3_should_order_data(inode)) 1850 if (ext4_should_order_data(inode))
1851 err = ext3_journal_dirty_data(handle, bh); 1851 err = ext4_journal_dirty_data(handle, bh);
1852 mark_buffer_dirty(bh); 1852 mark_buffer_dirty(bh);
1853 } 1853 }
1854 1854
@@ -1872,14 +1872,14 @@ static inline int all_zeroes(__le32 *p, __le32 *q)
1872} 1872}
1873 1873
1874/** 1874/**
1875 * ext3_find_shared - find the indirect blocks for partial truncation. 1875 * ext4_find_shared - find the indirect blocks for partial truncation.
1876 * @inode: inode in question 1876 * @inode: inode in question
1877 * @depth: depth of the affected branch 1877 * @depth: depth of the affected branch
1878 * @offsets: offsets of pointers in that branch (see ext3_block_to_path) 1878 * @offsets: offsets of pointers in that branch (see ext4_block_to_path)
1879 * @chain: place to store the pointers to partial indirect blocks 1879 * @chain: place to store the pointers to partial indirect blocks
1880 * @top: place to the (detached) top of branch 1880 * @top: place to the (detached) top of branch
1881 * 1881 *
1882 * This is a helper function used by ext3_truncate(). 1882 * This is a helper function used by ext4_truncate().
1883 * 1883 *
1884 * When we do truncate() we may have to clean the ends of several 1884 * When we do truncate() we may have to clean the ends of several
1885 * indirect blocks but leave the blocks themselves alive. Block is 1885 * indirect blocks but leave the blocks themselves alive. Block is
@@ -1887,7 +1887,7 @@ static inline int all_zeroes(__le32 *p, __le32 *q)
1887 * from it (and it is on the path to the first completely truncated 1887 * from it (and it is on the path to the first completely truncated
1888 * data block, indeed). We have to free the top of that path along 1888 * data block, indeed). We have to free the top of that path along
1889 * with everything to the right of the path. Since no allocation 1889 * with everything to the right of the path. Since no allocation
1890 * past the truncation point is possible until ext3_truncate() 1890 * past the truncation point is possible until ext4_truncate()
1891 * finishes, we may safely do the latter, but top of branch may 1891 * finishes, we may safely do the latter, but top of branch may
1892 * require special attention - pageout below the truncation point 1892 * require special attention - pageout below the truncation point
1893 * might try to populate it. 1893 * might try to populate it.
@@ -1906,7 +1906,7 @@ static inline int all_zeroes(__le32 *p, __le32 *q)
1906 * c) free the subtrees growing from the inode past the @chain[0]. 1906 * c) free the subtrees growing from the inode past the @chain[0].
1907 * (no partially truncated stuff there). */ 1907 * (no partially truncated stuff there). */
1908 1908
1909static Indirect *ext3_find_shared(struct inode *inode, int depth, 1909static Indirect *ext4_find_shared(struct inode *inode, int depth,
1910 int offsets[4], Indirect chain[4], __le32 *top) 1910 int offsets[4], Indirect chain[4], __le32 *top)
1911{ 1911{
1912 Indirect *partial, *p; 1912 Indirect *partial, *p;
@@ -1916,7 +1916,7 @@ static Indirect *ext3_find_shared(struct inode *inode, int depth,
1916 /* Make k index the deepest non-null offest + 1 */ 1916 /* Make k index the deepest non-null offest + 1 */
1917 for (k = depth; k > 1 && !offsets[k-1]; k--) 1917 for (k = depth; k > 1 && !offsets[k-1]; k--)
1918 ; 1918 ;
1919 partial = ext3_get_branch(inode, k, offsets, chain, &err); 1919 partial = ext4_get_branch(inode, k, offsets, chain, &err);
1920 /* Writer: pointers */ 1920 /* Writer: pointers */
1921 if (!partial) 1921 if (!partial)
1922 partial = chain + k-1; 1922 partial = chain + k-1;
@@ -1939,7 +1939,7 @@ static Indirect *ext3_find_shared(struct inode *inode, int depth,
1939 p->p--; 1939 p->p--;
1940 } else { 1940 } else {
1941 *top = *p->p; 1941 *top = *p->p;
1942 /* Nope, don't do this in ext3. Must leave the tree intact */ 1942 /* Nope, don't do this in ext4. Must leave the tree intact */
1943#if 0 1943#if 0
1944 *p->p = 0; 1944 *p->p = 0;
1945#endif 1945#endif
@@ -1962,21 +1962,21 @@ no_top:
1962 * We release `count' blocks on disk, but (last - first) may be greater 1962 * We release `count' blocks on disk, but (last - first) may be greater
1963 * than `count' because there can be holes in there. 1963 * than `count' because there can be holes in there.
1964 */ 1964 */
1965static void ext3_clear_blocks(handle_t *handle, struct inode *inode, 1965static void ext4_clear_blocks(handle_t *handle, struct inode *inode,
1966 struct buffer_head *bh, ext3_fsblk_t block_to_free, 1966 struct buffer_head *bh, ext4_fsblk_t block_to_free,
1967 unsigned long count, __le32 *first, __le32 *last) 1967 unsigned long count, __le32 *first, __le32 *last)
1968{ 1968{
1969 __le32 *p; 1969 __le32 *p;
1970 if (try_to_extend_transaction(handle, inode)) { 1970 if (try_to_extend_transaction(handle, inode)) {
1971 if (bh) { 1971 if (bh) {
1972 BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata"); 1972 BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
1973 ext3_journal_dirty_metadata(handle, bh); 1973 ext4_journal_dirty_metadata(handle, bh);
1974 } 1974 }
1975 ext3_mark_inode_dirty(handle, inode); 1975 ext4_mark_inode_dirty(handle, inode);
1976 ext3_journal_test_restart(handle, inode); 1976 ext4_journal_test_restart(handle, inode);
1977 if (bh) { 1977 if (bh) {
1978 BUFFER_TRACE(bh, "retaking write access"); 1978 BUFFER_TRACE(bh, "retaking write access");
1979 ext3_journal_get_write_access(handle, bh); 1979 ext4_journal_get_write_access(handle, bh);
1980 } 1980 }
1981 } 1981 }
1982 1982
@@ -1995,15 +1995,15 @@ static void ext3_clear_blocks(handle_t *handle, struct inode *inode,
1995 1995
1996 *p = 0; 1996 *p = 0;
1997 bh = sb_find_get_block(inode->i_sb, nr); 1997 bh = sb_find_get_block(inode->i_sb, nr);
1998 ext3_forget(handle, 0, inode, bh, nr); 1998 ext4_forget(handle, 0, inode, bh, nr);
1999 } 1999 }
2000 } 2000 }
2001 2001
2002 ext3_free_blocks(handle, inode, block_to_free, count); 2002 ext4_free_blocks(handle, inode, block_to_free, count);
2003} 2003}
2004 2004
2005/** 2005/**
2006 * ext3_free_data - free a list of data blocks 2006 * ext4_free_data - free a list of data blocks
2007 * @handle: handle for this transaction 2007 * @handle: handle for this transaction
2008 * @inode: inode we are dealing with 2008 * @inode: inode we are dealing with
2009 * @this_bh: indirect buffer_head which contains *@first and *@last 2009 * @this_bh: indirect buffer_head which contains *@first and *@last
@@ -2021,23 +2021,23 @@ static void ext3_clear_blocks(handle_t *handle, struct inode *inode,
2021 * @this_bh will be %NULL if @first and @last point into the inode's direct 2021 * @this_bh will be %NULL if @first and @last point into the inode's direct
2022 * block pointers. 2022 * block pointers.
2023 */ 2023 */
2024static void ext3_free_data(handle_t *handle, struct inode *inode, 2024static void ext4_free_data(handle_t *handle, struct inode *inode,
2025 struct buffer_head *this_bh, 2025 struct buffer_head *this_bh,
2026 __le32 *first, __le32 *last) 2026 __le32 *first, __le32 *last)
2027{ 2027{
2028 ext3_fsblk_t block_to_free = 0; /* Starting block # of a run */ 2028 ext4_fsblk_t block_to_free = 0; /* Starting block # of a run */
2029 unsigned long count = 0; /* Number of blocks in the run */ 2029 unsigned long count = 0; /* Number of blocks in the run */
2030 __le32 *block_to_free_p = NULL; /* Pointer into inode/ind 2030 __le32 *block_to_free_p = NULL; /* Pointer into inode/ind
2031 corresponding to 2031 corresponding to
2032 block_to_free */ 2032 block_to_free */
2033 ext3_fsblk_t nr; /* Current block # */ 2033 ext4_fsblk_t nr; /* Current block # */
2034 __le32 *p; /* Pointer into inode/ind 2034 __le32 *p; /* Pointer into inode/ind
2035 for current block */ 2035 for current block */
2036 int err; 2036 int err;
2037 2037
2038 if (this_bh) { /* For indirect block */ 2038 if (this_bh) { /* For indirect block */
2039 BUFFER_TRACE(this_bh, "get_write_access"); 2039 BUFFER_TRACE(this_bh, "get_write_access");
2040 err = ext3_journal_get_write_access(handle, this_bh); 2040 err = ext4_journal_get_write_access(handle, this_bh);
2041 /* Important: if we can't update the indirect pointers 2041 /* Important: if we can't update the indirect pointers
2042 * to the blocks, we can't free them. */ 2042 * to the blocks, we can't free them. */
2043 if (err) 2043 if (err)
@@ -2055,7 +2055,7 @@ static void ext3_free_data(handle_t *handle, struct inode *inode,
2055 } else if (nr == block_to_free + count) { 2055 } else if (nr == block_to_free + count) {
2056 count++; 2056 count++;
2057 } else { 2057 } else {
2058 ext3_clear_blocks(handle, inode, this_bh, 2058 ext4_clear_blocks(handle, inode, this_bh,
2059 block_to_free, 2059 block_to_free,
2060 count, block_to_free_p, p); 2060 count, block_to_free_p, p);
2061 block_to_free = nr; 2061 block_to_free = nr;
@@ -2066,17 +2066,17 @@ static void ext3_free_data(handle_t *handle, struct inode *inode,
2066 } 2066 }
2067 2067
2068 if (count > 0) 2068 if (count > 0)
2069 ext3_clear_blocks(handle, inode, this_bh, block_to_free, 2069 ext4_clear_blocks(handle, inode, this_bh, block_to_free,
2070 count, block_to_free_p, p); 2070 count, block_to_free_p, p);
2071 2071
2072 if (this_bh) { 2072 if (this_bh) {
2073 BUFFER_TRACE(this_bh, "call ext3_journal_dirty_metadata"); 2073 BUFFER_TRACE(this_bh, "call ext4_journal_dirty_metadata");
2074 ext3_journal_dirty_metadata(handle, this_bh); 2074 ext4_journal_dirty_metadata(handle, this_bh);
2075 } 2075 }
2076} 2076}
2077 2077
2078/** 2078/**
2079 * ext3_free_branches - free an array of branches 2079 * ext4_free_branches - free an array of branches
2080 * @handle: JBD handle for this transaction 2080 * @handle: JBD handle for this transaction
2081 * @inode: inode we are dealing with 2081 * @inode: inode we are dealing with
2082 * @parent_bh: the buffer_head which contains *@first and *@last 2082 * @parent_bh: the buffer_head which contains *@first and *@last
@@ -2088,11 +2088,11 @@ static void ext3_free_data(handle_t *handle, struct inode *inode,
2088 * stored as little-endian 32-bit) and updating @inode->i_blocks 2088 * stored as little-endian 32-bit) and updating @inode->i_blocks
2089 * appropriately. 2089 * appropriately.
2090 */ 2090 */
2091static void ext3_free_branches(handle_t *handle, struct inode *inode, 2091static void ext4_free_branches(handle_t *handle, struct inode *inode,
2092 struct buffer_head *parent_bh, 2092 struct buffer_head *parent_bh,
2093 __le32 *first, __le32 *last, int depth) 2093 __le32 *first, __le32 *last, int depth)
2094{ 2094{
2095 ext3_fsblk_t nr; 2095 ext4_fsblk_t nr;
2096 __le32 *p; 2096 __le32 *p;
2097 2097
2098 if (is_handle_aborted(handle)) 2098 if (is_handle_aborted(handle))
@@ -2100,7 +2100,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
2100 2100
2101 if (depth--) { 2101 if (depth--) {
2102 struct buffer_head *bh; 2102 struct buffer_head *bh;
2103 int addr_per_block = EXT3_ADDR_PER_BLOCK(inode->i_sb); 2103 int addr_per_block = EXT4_ADDR_PER_BLOCK(inode->i_sb);
2104 p = last; 2104 p = last;
2105 while (--p >= first) { 2105 while (--p >= first) {
2106 nr = le32_to_cpu(*p); 2106 nr = le32_to_cpu(*p);
@@ -2115,7 +2115,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
2115 * (should be rare). 2115 * (should be rare).
2116 */ 2116 */
2117 if (!bh) { 2117 if (!bh) {
2118 ext3_error(inode->i_sb, "ext3_free_branches", 2118 ext4_error(inode->i_sb, "ext4_free_branches",
2119 "Read failure, inode=%lu, block="E3FSBLK, 2119 "Read failure, inode=%lu, block="E3FSBLK,
2120 inode->i_ino, nr); 2120 inode->i_ino, nr);
2121 continue; 2121 continue;
@@ -2123,7 +2123,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
2123 2123
2124 /* This zaps the entire block. Bottom up. */ 2124 /* This zaps the entire block. Bottom up. */
2125 BUFFER_TRACE(bh, "free child branches"); 2125 BUFFER_TRACE(bh, "free child branches");
2126 ext3_free_branches(handle, inode, bh, 2126 ext4_free_branches(handle, inode, bh,
2127 (__le32*)bh->b_data, 2127 (__le32*)bh->b_data,
2128 (__le32*)bh->b_data + addr_per_block, 2128 (__le32*)bh->b_data + addr_per_block,
2129 depth); 2129 depth);
@@ -2138,7 +2138,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
2138 * transaction. But if it's part of the committing 2138 * transaction. But if it's part of the committing
2139 * transaction then journal_forget() will simply 2139 * transaction then journal_forget() will simply
2140 * brelse() it. That means that if the underlying 2140 * brelse() it. That means that if the underlying
2141 * block is reallocated in ext3_get_block(), 2141 * block is reallocated in ext4_get_block(),
2142 * unmap_underlying_metadata() will find this block 2142 * unmap_underlying_metadata() will find this block
2143 * and will try to get rid of it. damn, damn. 2143 * and will try to get rid of it. damn, damn.
2144 * 2144 *
@@ -2147,7 +2147,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
2147 * revoke records must be emitted *before* clearing 2147 * revoke records must be emitted *before* clearing
2148 * this block's bit in the bitmaps. 2148 * this block's bit in the bitmaps.
2149 */ 2149 */
2150 ext3_forget(handle, 1, inode, bh, bh->b_blocknr); 2150 ext4_forget(handle, 1, inode, bh, bh->b_blocknr);
2151 2151
2152 /* 2152 /*
2153 * Everything below this this pointer has been 2153 * Everything below this this pointer has been
@@ -2168,11 +2168,11 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
2168 if (is_handle_aborted(handle)) 2168 if (is_handle_aborted(handle))
2169 return; 2169 return;
2170 if (try_to_extend_transaction(handle, inode)) { 2170 if (try_to_extend_transaction(handle, inode)) {
2171 ext3_mark_inode_dirty(handle, inode); 2171 ext4_mark_inode_dirty(handle, inode);
2172 ext3_journal_test_restart(handle, inode); 2172 ext4_journal_test_restart(handle, inode);
2173 } 2173 }
2174 2174
2175 ext3_free_blocks(handle, inode, nr, 1); 2175 ext4_free_blocks(handle, inode, nr, 1);
2176 2176
2177 if (parent_bh) { 2177 if (parent_bh) {
2178 /* 2178 /*
@@ -2180,12 +2180,12 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
2180 * pointed to by an indirect block: journal it 2180 * pointed to by an indirect block: journal it
2181 */ 2181 */
2182 BUFFER_TRACE(parent_bh, "get_write_access"); 2182 BUFFER_TRACE(parent_bh, "get_write_access");
2183 if (!ext3_journal_get_write_access(handle, 2183 if (!ext4_journal_get_write_access(handle,
2184 parent_bh)){ 2184 parent_bh)){
2185 *p = 0; 2185 *p = 0;
2186 BUFFER_TRACE(parent_bh, 2186 BUFFER_TRACE(parent_bh,
2187 "call ext3_journal_dirty_metadata"); 2187 "call ext4_journal_dirty_metadata");
2188 ext3_journal_dirty_metadata(handle, 2188 ext4_journal_dirty_metadata(handle,
2189 parent_bh); 2189 parent_bh);
2190 } 2190 }
2191 } 2191 }
@@ -2193,15 +2193,15 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
2193 } else { 2193 } else {
2194 /* We have reached the bottom of the tree. */ 2194 /* We have reached the bottom of the tree. */
2195 BUFFER_TRACE(parent_bh, "free data blocks"); 2195 BUFFER_TRACE(parent_bh, "free data blocks");
2196 ext3_free_data(handle, inode, parent_bh, first, last); 2196 ext4_free_data(handle, inode, parent_bh, first, last);
2197 } 2197 }
2198} 2198}
2199 2199
2200/* 2200/*
2201 * ext3_truncate() 2201 * ext4_truncate()
2202 * 2202 *
2203 * We block out ext3_get_block() block instantiations across the entire 2203 * We block out ext4_get_block() block instantiations across the entire
2204 * transaction, and VFS/VM ensures that ext3_truncate() cannot run 2204 * transaction, and VFS/VM ensures that ext4_truncate() cannot run
2205 * simultaneously on behalf of the same inode. 2205 * simultaneously on behalf of the same inode.
2206 * 2206 *
2207 * As we work through the truncate and commmit bits of it to the journal there 2207 * As we work through the truncate and commmit bits of it to the journal there
@@ -2218,19 +2218,19 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
2218 * truncate against the orphan inode list. 2218 * truncate against the orphan inode list.
2219 * 2219 *
2220 * The committed inode has the new, desired i_size (which is the same as 2220 * The committed inode has the new, desired i_size (which is the same as
2221 * i_disksize in this case). After a crash, ext3_orphan_cleanup() will see 2221 * i_disksize in this case). After a crash, ext4_orphan_cleanup() will see
2222 * that this inode's truncate did not complete and it will again call 2222 * that this inode's truncate did not complete and it will again call
2223 * ext3_truncate() to have another go. So there will be instantiated blocks 2223 * ext4_truncate() to have another go. So there will be instantiated blocks
2224 * to the right of the truncation point in a crashed ext3 filesystem. But 2224 * to the right of the truncation point in a crashed ext4 filesystem. But
2225 * that's fine - as long as they are linked from the inode, the post-crash 2225 * that's fine - as long as they are linked from the inode, the post-crash
2226 * ext3_truncate() run will find them and release them. 2226 * ext4_truncate() run will find them and release them.
2227 */ 2227 */
2228void ext3_truncate(struct inode *inode) 2228void ext4_truncate(struct inode *inode)
2229{ 2229{
2230 handle_t *handle; 2230 handle_t *handle;
2231 struct ext3_inode_info *ei = EXT3_I(inode); 2231 struct ext4_inode_info *ei = EXT4_I(inode);
2232 __le32 *i_data = ei->i_data; 2232 __le32 *i_data = ei->i_data;
2233 int addr_per_block = EXT3_ADDR_PER_BLOCK(inode->i_sb); 2233 int addr_per_block = EXT4_ADDR_PER_BLOCK(inode->i_sb);
2234 struct address_space *mapping = inode->i_mapping; 2234 struct address_space *mapping = inode->i_mapping;
2235 int offsets[4]; 2235 int offsets[4];
2236 Indirect chain[4]; 2236 Indirect chain[4];
@@ -2244,7 +2244,7 @@ void ext3_truncate(struct inode *inode)
2244 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || 2244 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
2245 S_ISLNK(inode->i_mode))) 2245 S_ISLNK(inode->i_mode)))
2246 return; 2246 return;
2247 if (ext3_inode_is_fast_symlink(inode)) 2247 if (ext4_inode_is_fast_symlink(inode))
2248 return; 2248 return;
2249 if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) 2249 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2250 return; 2250 return;
@@ -2275,12 +2275,12 @@ void ext3_truncate(struct inode *inode)
2275 } 2275 }
2276 2276
2277 last_block = (inode->i_size + blocksize-1) 2277 last_block = (inode->i_size + blocksize-1)
2278 >> EXT3_BLOCK_SIZE_BITS(inode->i_sb); 2278 >> EXT4_BLOCK_SIZE_BITS(inode->i_sb);
2279 2279
2280 if (page) 2280 if (page)
2281 ext3_block_truncate_page(handle, page, mapping, inode->i_size); 2281 ext4_block_truncate_page(handle, page, mapping, inode->i_size);
2282 2282
2283 n = ext3_block_to_path(inode, last_block, offsets, NULL); 2283 n = ext4_block_to_path(inode, last_block, offsets, NULL);
2284 if (n == 0) 2284 if (n == 0)
2285 goto out_stop; /* error */ 2285 goto out_stop; /* error */
2286 2286
@@ -2293,7 +2293,7 @@ void ext3_truncate(struct inode *inode)
2293 * Implication: the file must always be in a sane, consistent 2293 * Implication: the file must always be in a sane, consistent
2294 * truncatable state while each transaction commits. 2294 * truncatable state while each transaction commits.
2295 */ 2295 */
2296 if (ext3_orphan_add(handle, inode)) 2296 if (ext4_orphan_add(handle, inode))
2297 goto out_stop; 2297 goto out_stop;
2298 2298
2299 /* 2299 /*
@@ -2301,28 +2301,28 @@ void ext3_truncate(struct inode *inode)
2301 * occurs before the truncate completes, so it is now safe to propagate 2301 * occurs before the truncate completes, so it is now safe to propagate
2302 * the new, shorter inode size (held for now in i_size) into the 2302 * the new, shorter inode size (held for now in i_size) into the
2303 * on-disk inode. We do this via i_disksize, which is the value which 2303 * on-disk inode. We do this via i_disksize, which is the value which
2304 * ext3 *really* writes onto the disk inode. 2304 * ext4 *really* writes onto the disk inode.
2305 */ 2305 */
2306 ei->i_disksize = inode->i_size; 2306 ei->i_disksize = inode->i_size;
2307 2307
2308 /* 2308 /*
2309 * From here we block out all ext3_get_block() callers who want to 2309 * From here we block out all ext4_get_block() callers who want to
2310 * modify the block allocation tree. 2310 * modify the block allocation tree.
2311 */ 2311 */
2312 mutex_lock(&ei->truncate_mutex); 2312 mutex_lock(&ei->truncate_mutex);
2313 2313
2314 if (n == 1) { /* direct blocks */ 2314 if (n == 1) { /* direct blocks */
2315 ext3_free_data(handle, inode, NULL, i_data+offsets[0], 2315 ext4_free_data(handle, inode, NULL, i_data+offsets[0],
2316 i_data + EXT3_NDIR_BLOCKS); 2316 i_data + EXT4_NDIR_BLOCKS);
2317 goto do_indirects; 2317 goto do_indirects;
2318 } 2318 }
2319 2319
2320 partial = ext3_find_shared(inode, n, offsets, chain, &nr); 2320 partial = ext4_find_shared(inode, n, offsets, chain, &nr);
2321 /* Kill the top of shared branch (not detached) */ 2321 /* Kill the top of shared branch (not detached) */
2322 if (nr) { 2322 if (nr) {
2323 if (partial == chain) { 2323 if (partial == chain) {
2324 /* Shared branch grows from the inode */ 2324 /* Shared branch grows from the inode */
2325 ext3_free_branches(handle, inode, NULL, 2325 ext4_free_branches(handle, inode, NULL,
2326 &nr, &nr+1, (chain+n-1) - partial); 2326 &nr, &nr+1, (chain+n-1) - partial);
2327 *partial->p = 0; 2327 *partial->p = 0;
2328 /* 2328 /*
@@ -2332,14 +2332,14 @@ void ext3_truncate(struct inode *inode)
2332 } else { 2332 } else {
2333 /* Shared branch grows from an indirect block */ 2333 /* Shared branch grows from an indirect block */
2334 BUFFER_TRACE(partial->bh, "get_write_access"); 2334 BUFFER_TRACE(partial->bh, "get_write_access");
2335 ext3_free_branches(handle, inode, partial->bh, 2335 ext4_free_branches(handle, inode, partial->bh,
2336 partial->p, 2336 partial->p,
2337 partial->p+1, (chain+n-1) - partial); 2337 partial->p+1, (chain+n-1) - partial);
2338 } 2338 }
2339 } 2339 }
2340 /* Clear the ends of indirect blocks on the shared branch */ 2340 /* Clear the ends of indirect blocks on the shared branch */
2341 while (partial > chain) { 2341 while (partial > chain) {
2342 ext3_free_branches(handle, inode, partial->bh, partial->p + 1, 2342 ext4_free_branches(handle, inode, partial->bh, partial->p + 1,
2343 (__le32*)partial->bh->b_data+addr_per_block, 2343 (__le32*)partial->bh->b_data+addr_per_block,
2344 (chain+n-1) - partial); 2344 (chain+n-1) - partial);
2345 BUFFER_TRACE(partial->bh, "call brelse"); 2345 BUFFER_TRACE(partial->bh, "call brelse");
@@ -2350,32 +2350,32 @@ do_indirects:
2350 /* Kill the remaining (whole) subtrees */ 2350 /* Kill the remaining (whole) subtrees */
2351 switch (offsets[0]) { 2351 switch (offsets[0]) {
2352 default: 2352 default:
2353 nr = i_data[EXT3_IND_BLOCK]; 2353 nr = i_data[EXT4_IND_BLOCK];
2354 if (nr) { 2354 if (nr) {
2355 ext3_free_branches(handle, inode, NULL, &nr, &nr+1, 1); 2355 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 1);
2356 i_data[EXT3_IND_BLOCK] = 0; 2356 i_data[EXT4_IND_BLOCK] = 0;
2357 } 2357 }
2358 case EXT3_IND_BLOCK: 2358 case EXT4_IND_BLOCK:
2359 nr = i_data[EXT3_DIND_BLOCK]; 2359 nr = i_data[EXT4_DIND_BLOCK];
2360 if (nr) { 2360 if (nr) {
2361 ext3_free_branches(handle, inode, NULL, &nr, &nr+1, 2); 2361 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 2);
2362 i_data[EXT3_DIND_BLOCK] = 0; 2362 i_data[EXT4_DIND_BLOCK] = 0;
2363 } 2363 }
2364 case EXT3_DIND_BLOCK: 2364 case EXT4_DIND_BLOCK:
2365 nr = i_data[EXT3_TIND_BLOCK]; 2365 nr = i_data[EXT4_TIND_BLOCK];
2366 if (nr) { 2366 if (nr) {
2367 ext3_free_branches(handle, inode, NULL, &nr, &nr+1, 3); 2367 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 3);
2368 i_data[EXT3_TIND_BLOCK] = 0; 2368 i_data[EXT4_TIND_BLOCK] = 0;
2369 } 2369 }
2370 case EXT3_TIND_BLOCK: 2370 case EXT4_TIND_BLOCK:
2371 ; 2371 ;
2372 } 2372 }
2373 2373
2374 ext3_discard_reservation(inode); 2374 ext4_discard_reservation(inode);
2375 2375
2376 mutex_unlock(&ei->truncate_mutex); 2376 mutex_unlock(&ei->truncate_mutex);
2377 inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC; 2377 inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
2378 ext3_mark_inode_dirty(handle, inode); 2378 ext4_mark_inode_dirty(handle, inode);
2379 2379
2380 /* 2380 /*
2381 * In a multi-transaction truncate, we only make the final transaction 2381 * In a multi-transaction truncate, we only make the final transaction
@@ -2388,25 +2388,25 @@ out_stop:
2388 * If this was a simple ftruncate(), and the file will remain alive 2388 * If this was a simple ftruncate(), and the file will remain alive
2389 * then we need to clear up the orphan record which we created above. 2389 * then we need to clear up the orphan record which we created above.
2390 * However, if this was a real unlink then we were called by 2390 * However, if this was a real unlink then we were called by
2391 * ext3_delete_inode(), and we allow that function to clean up the 2391 * ext4_delete_inode(), and we allow that function to clean up the
2392 * orphan info for us. 2392 * orphan info for us.
2393 */ 2393 */
2394 if (inode->i_nlink) 2394 if (inode->i_nlink)
2395 ext3_orphan_del(handle, inode); 2395 ext4_orphan_del(handle, inode);
2396 2396
2397 ext3_journal_stop(handle); 2397 ext4_journal_stop(handle);
2398} 2398}
2399 2399
2400static ext3_fsblk_t ext3_get_inode_block(struct super_block *sb, 2400static ext4_fsblk_t ext4_get_inode_block(struct super_block *sb,
2401 unsigned long ino, struct ext3_iloc *iloc) 2401 unsigned long ino, struct ext4_iloc *iloc)
2402{ 2402{
2403 unsigned long desc, group_desc, block_group; 2403 unsigned long desc, group_desc, block_group;
2404 unsigned long offset; 2404 unsigned long offset;
2405 ext3_fsblk_t block; 2405 ext4_fsblk_t block;
2406 struct buffer_head *bh; 2406 struct buffer_head *bh;
2407 struct ext3_group_desc * gdp; 2407 struct ext4_group_desc * gdp;
2408 2408
2409 if (!ext3_valid_inum(sb, ino)) { 2409 if (!ext4_valid_inum(sb, ino)) {
2410 /* 2410 /*
2411 * This error is already checked for in namei.c unless we are 2411 * This error is already checked for in namei.c unless we are
2412 * looking at an NFS filehandle, in which case no error 2412 * looking at an NFS filehandle, in which case no error
@@ -2415,54 +2415,54 @@ static ext3_fsblk_t ext3_get_inode_block(struct super_block *sb,
2415 return 0; 2415 return 0;
2416 } 2416 }
2417 2417
2418 block_group = (ino - 1) / EXT3_INODES_PER_GROUP(sb); 2418 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
2419 if (block_group >= EXT3_SB(sb)->s_groups_count) { 2419 if (block_group >= EXT4_SB(sb)->s_groups_count) {
2420 ext3_error(sb,"ext3_get_inode_block","group >= groups count"); 2420 ext4_error(sb,"ext4_get_inode_block","group >= groups count");
2421 return 0; 2421 return 0;
2422 } 2422 }
2423 smp_rmb(); 2423 smp_rmb();
2424 group_desc = block_group >> EXT3_DESC_PER_BLOCK_BITS(sb); 2424 group_desc = block_group >> EXT4_DESC_PER_BLOCK_BITS(sb);
2425 desc = block_group & (EXT3_DESC_PER_BLOCK(sb) - 1); 2425 desc = block_group & (EXT4_DESC_PER_BLOCK(sb) - 1);
2426 bh = EXT3_SB(sb)->s_group_desc[group_desc]; 2426 bh = EXT4_SB(sb)->s_group_desc[group_desc];
2427 if (!bh) { 2427 if (!bh) {
2428 ext3_error (sb, "ext3_get_inode_block", 2428 ext4_error (sb, "ext4_get_inode_block",
2429 "Descriptor not loaded"); 2429 "Descriptor not loaded");
2430 return 0; 2430 return 0;
2431 } 2431 }
2432 2432
2433 gdp = (struct ext3_group_desc *)bh->b_data; 2433 gdp = (struct ext4_group_desc *)bh->b_data;
2434 /* 2434 /*
2435 * Figure out the offset within the block group inode table 2435 * Figure out the offset within the block group inode table
2436 */ 2436 */
2437 offset = ((ino - 1) % EXT3_INODES_PER_GROUP(sb)) * 2437 offset = ((ino - 1) % EXT4_INODES_PER_GROUP(sb)) *
2438 EXT3_INODE_SIZE(sb); 2438 EXT4_INODE_SIZE(sb);
2439 block = le32_to_cpu(gdp[desc].bg_inode_table) + 2439 block = le32_to_cpu(gdp[desc].bg_inode_table) +
2440 (offset >> EXT3_BLOCK_SIZE_BITS(sb)); 2440 (offset >> EXT4_BLOCK_SIZE_BITS(sb));
2441 2441
2442 iloc->block_group = block_group; 2442 iloc->block_group = block_group;
2443 iloc->offset = offset & (EXT3_BLOCK_SIZE(sb) - 1); 2443 iloc->offset = offset & (EXT4_BLOCK_SIZE(sb) - 1);
2444 return block; 2444 return block;
2445} 2445}
2446 2446
2447/* 2447/*
2448 * ext3_get_inode_loc returns with an extra refcount against the inode's 2448 * ext4_get_inode_loc returns with an extra refcount against the inode's
2449 * underlying buffer_head on success. If 'in_mem' is true, we have all 2449 * underlying buffer_head on success. If 'in_mem' is true, we have all
2450 * data in memory that is needed to recreate the on-disk version of this 2450 * data in memory that is needed to recreate the on-disk version of this
2451 * inode. 2451 * inode.
2452 */ 2452 */
2453static int __ext3_get_inode_loc(struct inode *inode, 2453static int __ext4_get_inode_loc(struct inode *inode,
2454 struct ext3_iloc *iloc, int in_mem) 2454 struct ext4_iloc *iloc, int in_mem)
2455{ 2455{
2456 ext3_fsblk_t block; 2456 ext4_fsblk_t block;
2457 struct buffer_head *bh; 2457 struct buffer_head *bh;
2458 2458
2459 block = ext3_get_inode_block(inode->i_sb, inode->i_ino, iloc); 2459 block = ext4_get_inode_block(inode->i_sb, inode->i_ino, iloc);
2460 if (!block) 2460 if (!block)
2461 return -EIO; 2461 return -EIO;
2462 2462
2463 bh = sb_getblk(inode->i_sb, block); 2463 bh = sb_getblk(inode->i_sb, block);
2464 if (!bh) { 2464 if (!bh) {
2465 ext3_error (inode->i_sb, "ext3_get_inode_loc", 2465 ext4_error (inode->i_sb, "ext4_get_inode_loc",
2466 "unable to read inode block - " 2466 "unable to read inode block - "
2467 "inode=%lu, block="E3FSBLK, 2467 "inode=%lu, block="E3FSBLK,
2468 inode->i_ino, block); 2468 inode->i_ino, block);
@@ -2483,22 +2483,22 @@ static int __ext3_get_inode_loc(struct inode *inode,
2483 */ 2483 */
2484 if (in_mem) { 2484 if (in_mem) {
2485 struct buffer_head *bitmap_bh; 2485 struct buffer_head *bitmap_bh;
2486 struct ext3_group_desc *desc; 2486 struct ext4_group_desc *desc;
2487 int inodes_per_buffer; 2487 int inodes_per_buffer;
2488 int inode_offset, i; 2488 int inode_offset, i;
2489 int block_group; 2489 int block_group;
2490 int start; 2490 int start;
2491 2491
2492 block_group = (inode->i_ino - 1) / 2492 block_group = (inode->i_ino - 1) /
2493 EXT3_INODES_PER_GROUP(inode->i_sb); 2493 EXT4_INODES_PER_GROUP(inode->i_sb);
2494 inodes_per_buffer = bh->b_size / 2494 inodes_per_buffer = bh->b_size /
2495 EXT3_INODE_SIZE(inode->i_sb); 2495 EXT4_INODE_SIZE(inode->i_sb);
2496 inode_offset = ((inode->i_ino - 1) % 2496 inode_offset = ((inode->i_ino - 1) %
2497 EXT3_INODES_PER_GROUP(inode->i_sb)); 2497 EXT4_INODES_PER_GROUP(inode->i_sb));
2498 start = inode_offset & ~(inodes_per_buffer - 1); 2498 start = inode_offset & ~(inodes_per_buffer - 1);
2499 2499
2500 /* Is the inode bitmap in cache? */ 2500 /* Is the inode bitmap in cache? */
2501 desc = ext3_get_group_desc(inode->i_sb, 2501 desc = ext4_get_group_desc(inode->i_sb,
2502 block_group, NULL); 2502 block_group, NULL);
2503 if (!desc) 2503 if (!desc)
2504 goto make_io; 2504 goto make_io;
@@ -2520,7 +2520,7 @@ static int __ext3_get_inode_loc(struct inode *inode,
2520 for (i = start; i < start + inodes_per_buffer; i++) { 2520 for (i = start; i < start + inodes_per_buffer; i++) {
2521 if (i == inode_offset) 2521 if (i == inode_offset)
2522 continue; 2522 continue;
2523 if (ext3_test_bit(i, bitmap_bh->b_data)) 2523 if (ext4_test_bit(i, bitmap_bh->b_data))
2524 break; 2524 break;
2525 } 2525 }
2526 brelse(bitmap_bh); 2526 brelse(bitmap_bh);
@@ -2544,7 +2544,7 @@ make_io:
2544 submit_bh(READ_META, bh); 2544 submit_bh(READ_META, bh);
2545 wait_on_buffer(bh); 2545 wait_on_buffer(bh);
2546 if (!buffer_uptodate(bh)) { 2546 if (!buffer_uptodate(bh)) {
2547 ext3_error(inode->i_sb, "ext3_get_inode_loc", 2547 ext4_error(inode->i_sb, "ext4_get_inode_loc",
2548 "unable to read inode block - " 2548 "unable to read inode block - "
2549 "inode=%lu, block="E3FSBLK, 2549 "inode=%lu, block="E3FSBLK,
2550 inode->i_ino, block); 2550 inode->i_ino, block);
@@ -2557,48 +2557,48 @@ has_buffer:
2557 return 0; 2557 return 0;
2558} 2558}
2559 2559
2560int ext3_get_inode_loc(struct inode *inode, struct ext3_iloc *iloc) 2560int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc)
2561{ 2561{
2562 /* We have all inode data except xattrs in memory here. */ 2562 /* We have all inode data except xattrs in memory here. */
2563 return __ext3_get_inode_loc(inode, iloc, 2563 return __ext4_get_inode_loc(inode, iloc,
2564 !(EXT3_I(inode)->i_state & EXT3_STATE_XATTR)); 2564 !(EXT4_I(inode)->i_state & EXT4_STATE_XATTR));
2565} 2565}
2566 2566
2567void ext3_set_inode_flags(struct inode *inode) 2567void ext4_set_inode_flags(struct inode *inode)
2568{ 2568{
2569 unsigned int flags = EXT3_I(inode)->i_flags; 2569 unsigned int flags = EXT4_I(inode)->i_flags;
2570 2570
2571 inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC); 2571 inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2572 if (flags & EXT3_SYNC_FL) 2572 if (flags & EXT4_SYNC_FL)
2573 inode->i_flags |= S_SYNC; 2573 inode->i_flags |= S_SYNC;
2574 if (flags & EXT3_APPEND_FL) 2574 if (flags & EXT4_APPEND_FL)
2575 inode->i_flags |= S_APPEND; 2575 inode->i_flags |= S_APPEND;
2576 if (flags & EXT3_IMMUTABLE_FL) 2576 if (flags & EXT4_IMMUTABLE_FL)
2577 inode->i_flags |= S_IMMUTABLE; 2577 inode->i_flags |= S_IMMUTABLE;
2578 if (flags & EXT3_NOATIME_FL) 2578 if (flags & EXT4_NOATIME_FL)
2579 inode->i_flags |= S_NOATIME; 2579 inode->i_flags |= S_NOATIME;
2580 if (flags & EXT3_DIRSYNC_FL) 2580 if (flags & EXT4_DIRSYNC_FL)
2581 inode->i_flags |= S_DIRSYNC; 2581 inode->i_flags |= S_DIRSYNC;
2582} 2582}
2583 2583
2584void ext3_read_inode(struct inode * inode) 2584void ext4_read_inode(struct inode * inode)
2585{ 2585{
2586 struct ext3_iloc iloc; 2586 struct ext4_iloc iloc;
2587 struct ext3_inode *raw_inode; 2587 struct ext4_inode *raw_inode;
2588 struct ext3_inode_info *ei = EXT3_I(inode); 2588 struct ext4_inode_info *ei = EXT4_I(inode);
2589 struct buffer_head *bh; 2589 struct buffer_head *bh;
2590 int block; 2590 int block;
2591 2591
2592#ifdef CONFIG_EXT3_FS_POSIX_ACL 2592#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
2593 ei->i_acl = EXT3_ACL_NOT_CACHED; 2593 ei->i_acl = EXT4_ACL_NOT_CACHED;
2594 ei->i_default_acl = EXT3_ACL_NOT_CACHED; 2594 ei->i_default_acl = EXT4_ACL_NOT_CACHED;
2595#endif 2595#endif
2596 ei->i_block_alloc_info = NULL; 2596 ei->i_block_alloc_info = NULL;
2597 2597
2598 if (__ext3_get_inode_loc(inode, &iloc, 0)) 2598 if (__ext4_get_inode_loc(inode, &iloc, 0))
2599 goto bad_inode; 2599 goto bad_inode;
2600 bh = iloc.bh; 2600 bh = iloc.bh;
2601 raw_inode = ext3_raw_inode(&iloc); 2601 raw_inode = ext4_raw_inode(&iloc);
2602 inode->i_mode = le16_to_cpu(raw_inode->i_mode); 2602 inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2603 inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low); 2603 inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2604 inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low); 2604 inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
@@ -2623,7 +2623,7 @@ void ext3_read_inode(struct inode * inode)
2623 */ 2623 */
2624 if (inode->i_nlink == 0) { 2624 if (inode->i_nlink == 0) {
2625 if (inode->i_mode == 0 || 2625 if (inode->i_mode == 0 ||
2626 !(EXT3_SB(inode->i_sb)->s_mount_state & EXT3_ORPHAN_FS)) { 2626 !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS)) {
2627 /* this inode is deleted */ 2627 /* this inode is deleted */
2628 brelse (bh); 2628 brelse (bh);
2629 goto bad_inode; 2629 goto bad_inode;
@@ -2635,7 +2635,7 @@ void ext3_read_inode(struct inode * inode)
2635 } 2635 }
2636 inode->i_blocks = le32_to_cpu(raw_inode->i_blocks); 2636 inode->i_blocks = le32_to_cpu(raw_inode->i_blocks);
2637 ei->i_flags = le32_to_cpu(raw_inode->i_flags); 2637 ei->i_flags = le32_to_cpu(raw_inode->i_flags);
2638#ifdef EXT3_FRAGMENTS 2638#ifdef EXT4_FRAGMENTS
2639 ei->i_faddr = le32_to_cpu(raw_inode->i_faddr); 2639 ei->i_faddr = le32_to_cpu(raw_inode->i_faddr);
2640 ei->i_frag_no = raw_inode->i_frag; 2640 ei->i_frag_no = raw_inode->i_frag;
2641 ei->i_frag_size = raw_inode->i_fsize; 2641 ei->i_frag_size = raw_inode->i_fsize;
@@ -2654,51 +2654,51 @@ void ext3_read_inode(struct inode * inode)
2654 * NOTE! The in-memory inode i_data array is in little-endian order 2654 * NOTE! The in-memory inode i_data array is in little-endian order
2655 * even on big-endian machines: we do NOT byteswap the block numbers! 2655 * even on big-endian machines: we do NOT byteswap the block numbers!
2656 */ 2656 */
2657 for (block = 0; block < EXT3_N_BLOCKS; block++) 2657 for (block = 0; block < EXT4_N_BLOCKS; block++)
2658 ei->i_data[block] = raw_inode->i_block[block]; 2658 ei->i_data[block] = raw_inode->i_block[block];
2659 INIT_LIST_HEAD(&ei->i_orphan); 2659 INIT_LIST_HEAD(&ei->i_orphan);
2660 2660
2661 if (inode->i_ino >= EXT3_FIRST_INO(inode->i_sb) + 1 && 2661 if (inode->i_ino >= EXT4_FIRST_INO(inode->i_sb) + 1 &&
2662 EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE) { 2662 EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) {
2663 /* 2663 /*
2664 * When mke2fs creates big inodes it does not zero out 2664 * When mke2fs creates big inodes it does not zero out
2665 * the unused bytes above EXT3_GOOD_OLD_INODE_SIZE, 2665 * the unused bytes above EXT4_GOOD_OLD_INODE_SIZE,
2666 * so ignore those first few inodes. 2666 * so ignore those first few inodes.
2667 */ 2667 */
2668 ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize); 2668 ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize);
2669 if (EXT3_GOOD_OLD_INODE_SIZE + ei->i_extra_isize > 2669 if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize >
2670 EXT3_INODE_SIZE(inode->i_sb)) 2670 EXT4_INODE_SIZE(inode->i_sb))
2671 goto bad_inode; 2671 goto bad_inode;
2672 if (ei->i_extra_isize == 0) { 2672 if (ei->i_extra_isize == 0) {
2673 /* The extra space is currently unused. Use it. */ 2673 /* The extra space is currently unused. Use it. */
2674 ei->i_extra_isize = sizeof(struct ext3_inode) - 2674 ei->i_extra_isize = sizeof(struct ext4_inode) -
2675 EXT3_GOOD_OLD_INODE_SIZE; 2675 EXT4_GOOD_OLD_INODE_SIZE;
2676 } else { 2676 } else {
2677 __le32 *magic = (void *)raw_inode + 2677 __le32 *magic = (void *)raw_inode +
2678 EXT3_GOOD_OLD_INODE_SIZE + 2678 EXT4_GOOD_OLD_INODE_SIZE +
2679 ei->i_extra_isize; 2679 ei->i_extra_isize;
2680 if (*magic == cpu_to_le32(EXT3_XATTR_MAGIC)) 2680 if (*magic == cpu_to_le32(EXT4_XATTR_MAGIC))
2681 ei->i_state |= EXT3_STATE_XATTR; 2681 ei->i_state |= EXT4_STATE_XATTR;
2682 } 2682 }
2683 } else 2683 } else
2684 ei->i_extra_isize = 0; 2684 ei->i_extra_isize = 0;
2685 2685
2686 if (S_ISREG(inode->i_mode)) { 2686 if (S_ISREG(inode->i_mode)) {
2687 inode->i_op = &ext3_file_inode_operations; 2687 inode->i_op = &ext4_file_inode_operations;
2688 inode->i_fop = &ext3_file_operations; 2688 inode->i_fop = &ext4_file_operations;
2689 ext3_set_aops(inode); 2689 ext4_set_aops(inode);
2690 } else if (S_ISDIR(inode->i_mode)) { 2690 } else if (S_ISDIR(inode->i_mode)) {
2691 inode->i_op = &ext3_dir_inode_operations; 2691 inode->i_op = &ext4_dir_inode_operations;
2692 inode->i_fop = &ext3_dir_operations; 2692 inode->i_fop = &ext4_dir_operations;
2693 } else if (S_ISLNK(inode->i_mode)) { 2693 } else if (S_ISLNK(inode->i_mode)) {
2694 if (ext3_inode_is_fast_symlink(inode)) 2694 if (ext4_inode_is_fast_symlink(inode))
2695 inode->i_op = &ext3_fast_symlink_inode_operations; 2695 inode->i_op = &ext4_fast_symlink_inode_operations;
2696 else { 2696 else {
2697 inode->i_op = &ext3_symlink_inode_operations; 2697 inode->i_op = &ext4_symlink_inode_operations;
2698 ext3_set_aops(inode); 2698 ext4_set_aops(inode);
2699 } 2699 }
2700 } else { 2700 } else {
2701 inode->i_op = &ext3_special_inode_operations; 2701 inode->i_op = &ext4_special_inode_operations;
2702 if (raw_inode->i_block[0]) 2702 if (raw_inode->i_block[0])
2703 init_special_inode(inode, inode->i_mode, 2703 init_special_inode(inode, inode->i_mode,
2704 old_decode_dev(le32_to_cpu(raw_inode->i_block[0]))); 2704 old_decode_dev(le32_to_cpu(raw_inode->i_block[0])));
@@ -2707,7 +2707,7 @@ void ext3_read_inode(struct inode * inode)
2707 new_decode_dev(le32_to_cpu(raw_inode->i_block[1]))); 2707 new_decode_dev(le32_to_cpu(raw_inode->i_block[1])));
2708 } 2708 }
2709 brelse (iloc.bh); 2709 brelse (iloc.bh);
2710 ext3_set_inode_flags(inode); 2710 ext4_set_inode_flags(inode);
2711 return; 2711 return;
2712 2712
2713bad_inode: 2713bad_inode:
@@ -2722,19 +2722,19 @@ bad_inode:
2722 * 2722 *
2723 * The caller must have write access to iloc->bh. 2723 * The caller must have write access to iloc->bh.
2724 */ 2724 */
2725static int ext3_do_update_inode(handle_t *handle, 2725static int ext4_do_update_inode(handle_t *handle,
2726 struct inode *inode, 2726 struct inode *inode,
2727 struct ext3_iloc *iloc) 2727 struct ext4_iloc *iloc)
2728{ 2728{
2729 struct ext3_inode *raw_inode = ext3_raw_inode(iloc); 2729 struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
2730 struct ext3_inode_info *ei = EXT3_I(inode); 2730 struct ext4_inode_info *ei = EXT4_I(inode);
2731 struct buffer_head *bh = iloc->bh; 2731 struct buffer_head *bh = iloc->bh;
2732 int err = 0, rc, block; 2732 int err = 0, rc, block;
2733 2733
2734 /* For fields not not tracking in the in-memory inode, 2734 /* For fields not not tracking in the in-memory inode,
2735 * initialise them to zero for new inodes. */ 2735 * initialise them to zero for new inodes. */
2736 if (ei->i_state & EXT3_STATE_NEW) 2736 if (ei->i_state & EXT4_STATE_NEW)
2737 memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size); 2737 memset(raw_inode, 0, EXT4_SB(inode->i_sb)->s_inode_size);
2738 2738
2739 raw_inode->i_mode = cpu_to_le16(inode->i_mode); 2739 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2740 if(!(test_opt(inode->i_sb, NO_UID32))) { 2740 if(!(test_opt(inode->i_sb, NO_UID32))) {
@@ -2769,7 +2769,7 @@ static int ext3_do_update_inode(handle_t *handle,
2769 raw_inode->i_blocks = cpu_to_le32(inode->i_blocks); 2769 raw_inode->i_blocks = cpu_to_le32(inode->i_blocks);
2770 raw_inode->i_dtime = cpu_to_le32(ei->i_dtime); 2770 raw_inode->i_dtime = cpu_to_le32(ei->i_dtime);
2771 raw_inode->i_flags = cpu_to_le32(ei->i_flags); 2771 raw_inode->i_flags = cpu_to_le32(ei->i_flags);
2772#ifdef EXT3_FRAGMENTS 2772#ifdef EXT4_FRAGMENTS
2773 raw_inode->i_faddr = cpu_to_le32(ei->i_faddr); 2773 raw_inode->i_faddr = cpu_to_le32(ei->i_faddr);
2774 raw_inode->i_frag = ei->i_frag_no; 2774 raw_inode->i_frag = ei->i_frag_no;
2775 raw_inode->i_fsize = ei->i_frag_size; 2775 raw_inode->i_fsize = ei->i_frag_size;
@@ -2782,24 +2782,24 @@ static int ext3_do_update_inode(handle_t *handle,
2782 cpu_to_le32(ei->i_disksize >> 32); 2782 cpu_to_le32(ei->i_disksize >> 32);
2783 if (ei->i_disksize > 0x7fffffffULL) { 2783 if (ei->i_disksize > 0x7fffffffULL) {
2784 struct super_block *sb = inode->i_sb; 2784 struct super_block *sb = inode->i_sb;
2785 if (!EXT3_HAS_RO_COMPAT_FEATURE(sb, 2785 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
2786 EXT3_FEATURE_RO_COMPAT_LARGE_FILE) || 2786 EXT4_FEATURE_RO_COMPAT_LARGE_FILE) ||
2787 EXT3_SB(sb)->s_es->s_rev_level == 2787 EXT4_SB(sb)->s_es->s_rev_level ==
2788 cpu_to_le32(EXT3_GOOD_OLD_REV)) { 2788 cpu_to_le32(EXT4_GOOD_OLD_REV)) {
2789 /* If this is the first large file 2789 /* If this is the first large file
2790 * created, add a flag to the superblock. 2790 * created, add a flag to the superblock.
2791 */ 2791 */
2792 err = ext3_journal_get_write_access(handle, 2792 err = ext4_journal_get_write_access(handle,
2793 EXT3_SB(sb)->s_sbh); 2793 EXT4_SB(sb)->s_sbh);
2794 if (err) 2794 if (err)
2795 goto out_brelse; 2795 goto out_brelse;
2796 ext3_update_dynamic_rev(sb); 2796 ext4_update_dynamic_rev(sb);
2797 EXT3_SET_RO_COMPAT_FEATURE(sb, 2797 EXT4_SET_RO_COMPAT_FEATURE(sb,
2798 EXT3_FEATURE_RO_COMPAT_LARGE_FILE); 2798 EXT4_FEATURE_RO_COMPAT_LARGE_FILE);
2799 sb->s_dirt = 1; 2799 sb->s_dirt = 1;
2800 handle->h_sync = 1; 2800 handle->h_sync = 1;
2801 err = ext3_journal_dirty_metadata(handle, 2801 err = ext4_journal_dirty_metadata(handle,
2802 EXT3_SB(sb)->s_sbh); 2802 EXT4_SB(sb)->s_sbh);
2803 } 2803 }
2804 } 2804 }
2805 } 2805 }
@@ -2815,26 +2815,26 @@ static int ext3_do_update_inode(handle_t *handle,
2815 cpu_to_le32(new_encode_dev(inode->i_rdev)); 2815 cpu_to_le32(new_encode_dev(inode->i_rdev));
2816 raw_inode->i_block[2] = 0; 2816 raw_inode->i_block[2] = 0;
2817 } 2817 }
2818 } else for (block = 0; block < EXT3_N_BLOCKS; block++) 2818 } else for (block = 0; block < EXT4_N_BLOCKS; block++)
2819 raw_inode->i_block[block] = ei->i_data[block]; 2819 raw_inode->i_block[block] = ei->i_data[block];
2820 2820
2821 if (ei->i_extra_isize) 2821 if (ei->i_extra_isize)
2822 raw_inode->i_extra_isize = cpu_to_le16(ei->i_extra_isize); 2822 raw_inode->i_extra_isize = cpu_to_le16(ei->i_extra_isize);
2823 2823
2824 BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata"); 2824 BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
2825 rc = ext3_journal_dirty_metadata(handle, bh); 2825 rc = ext4_journal_dirty_metadata(handle, bh);
2826 if (!err) 2826 if (!err)
2827 err = rc; 2827 err = rc;
2828 ei->i_state &= ~EXT3_STATE_NEW; 2828 ei->i_state &= ~EXT4_STATE_NEW;
2829 2829
2830out_brelse: 2830out_brelse:
2831 brelse (bh); 2831 brelse (bh);
2832 ext3_std_error(inode->i_sb, err); 2832 ext4_std_error(inode->i_sb, err);
2833 return err; 2833 return err;
2834} 2834}
2835 2835
2836/* 2836/*
2837 * ext3_write_inode() 2837 * ext4_write_inode()
2838 * 2838 *
2839 * We are called from a few places: 2839 * We are called from a few places:
2840 * 2840 *
@@ -2851,7 +2851,7 @@ out_brelse:
2851 * 2851 *
2852 * In all cases it is actually safe for us to return without doing anything, 2852 * In all cases it is actually safe for us to return without doing anything,
2853 * because the inode has been copied into a raw inode buffer in 2853 * because the inode has been copied into a raw inode buffer in
2854 * ext3_mark_inode_dirty(). This is a correctness thing for O_SYNC and for 2854 * ext4_mark_inode_dirty(). This is a correctness thing for O_SYNC and for
2855 * knfsd. 2855 * knfsd.
2856 * 2856 *
2857 * Note that we are absolutely dependent upon all inode dirtiers doing the 2857 * Note that we are absolutely dependent upon all inode dirtiers doing the
@@ -2868,12 +2868,12 @@ out_brelse:
2868 * `stuff()' is running, and the new i_size will be lost. Plus the inode 2868 * `stuff()' is running, and the new i_size will be lost. Plus the inode
2869 * will no longer be on the superblock's dirty inode list. 2869 * will no longer be on the superblock's dirty inode list.
2870 */ 2870 */
2871int ext3_write_inode(struct inode *inode, int wait) 2871int ext4_write_inode(struct inode *inode, int wait)
2872{ 2872{
2873 if (current->flags & PF_MEMALLOC) 2873 if (current->flags & PF_MEMALLOC)
2874 return 0; 2874 return 0;
2875 2875
2876 if (ext3_journal_current_handle()) { 2876 if (ext4_journal_current_handle()) {
2877 jbd_debug(0, "called recursively, non-PF_MEMALLOC!\n"); 2877 jbd_debug(0, "called recursively, non-PF_MEMALLOC!\n");
2878 dump_stack(); 2878 dump_stack();
2879 return -EIO; 2879 return -EIO;
@@ -2882,11 +2882,11 @@ int ext3_write_inode(struct inode *inode, int wait)
2882 if (!wait) 2882 if (!wait)
2883 return 0; 2883 return 0;
2884 2884
2885 return ext3_force_commit(inode->i_sb); 2885 return ext4_force_commit(inode->i_sb);
2886} 2886}
2887 2887
2888/* 2888/*
2889 * ext3_setattr() 2889 * ext4_setattr()
2890 * 2890 *
2891 * Called from notify_change. 2891 * Called from notify_change.
2892 * 2892 *
@@ -2902,7 +2902,7 @@ int ext3_write_inode(struct inode *inode, int wait)
2902 * 2902 *
2903 * Called with inode->sem down. 2903 * Called with inode->sem down.
2904 */ 2904 */
2905int ext3_setattr(struct dentry *dentry, struct iattr *attr) 2905int ext4_setattr(struct dentry *dentry, struct iattr *attr)
2906{ 2906{
2907 struct inode *inode = dentry->d_inode; 2907 struct inode *inode = dentry->d_inode;
2908 int error, rc = 0; 2908 int error, rc = 0;
@@ -2918,15 +2918,15 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
2918 2918
2919 /* (user+group)*(old+new) structure, inode write (sb, 2919 /* (user+group)*(old+new) structure, inode write (sb,
2920 * inode block, ? - but truncate inode update has it) */ 2920 * inode block, ? - but truncate inode update has it) */
2921 handle = ext3_journal_start(inode, 2*(EXT3_QUOTA_INIT_BLOCKS(inode->i_sb)+ 2921 handle = ext4_journal_start(inode, 2*(EXT4_QUOTA_INIT_BLOCKS(inode->i_sb)+
2922 EXT3_QUOTA_DEL_BLOCKS(inode->i_sb))+3); 2922 EXT4_QUOTA_DEL_BLOCKS(inode->i_sb))+3);
2923 if (IS_ERR(handle)) { 2923 if (IS_ERR(handle)) {
2924 error = PTR_ERR(handle); 2924 error = PTR_ERR(handle);
2925 goto err_out; 2925 goto err_out;
2926 } 2926 }
2927 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0; 2927 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
2928 if (error) { 2928 if (error) {
2929 ext3_journal_stop(handle); 2929 ext4_journal_stop(handle);
2930 return error; 2930 return error;
2931 } 2931 }
2932 /* Update corresponding info in inode so that everything is in 2932 /* Update corresponding info in inode so that everything is in
@@ -2935,41 +2935,41 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
2935 inode->i_uid = attr->ia_uid; 2935 inode->i_uid = attr->ia_uid;
2936 if (attr->ia_valid & ATTR_GID) 2936 if (attr->ia_valid & ATTR_GID)
2937 inode->i_gid = attr->ia_gid; 2937 inode->i_gid = attr->ia_gid;
2938 error = ext3_mark_inode_dirty(handle, inode); 2938 error = ext4_mark_inode_dirty(handle, inode);
2939 ext3_journal_stop(handle); 2939 ext4_journal_stop(handle);
2940 } 2940 }
2941 2941
2942 if (S_ISREG(inode->i_mode) && 2942 if (S_ISREG(inode->i_mode) &&
2943 attr->ia_valid & ATTR_SIZE && attr->ia_size < inode->i_size) { 2943 attr->ia_valid & ATTR_SIZE && attr->ia_size < inode->i_size) {
2944 handle_t *handle; 2944 handle_t *handle;
2945 2945
2946 handle = ext3_journal_start(inode, 3); 2946 handle = ext4_journal_start(inode, 3);
2947 if (IS_ERR(handle)) { 2947 if (IS_ERR(handle)) {
2948 error = PTR_ERR(handle); 2948 error = PTR_ERR(handle);
2949 goto err_out; 2949 goto err_out;
2950 } 2950 }
2951 2951
2952 error = ext3_orphan_add(handle, inode); 2952 error = ext4_orphan_add(handle, inode);
2953 EXT3_I(inode)->i_disksize = attr->ia_size; 2953 EXT4_I(inode)->i_disksize = attr->ia_size;
2954 rc = ext3_mark_inode_dirty(handle, inode); 2954 rc = ext4_mark_inode_dirty(handle, inode);
2955 if (!error) 2955 if (!error)
2956 error = rc; 2956 error = rc;
2957 ext3_journal_stop(handle); 2957 ext4_journal_stop(handle);
2958 } 2958 }
2959 2959
2960 rc = inode_setattr(inode, attr); 2960 rc = inode_setattr(inode, attr);
2961 2961
2962 /* If inode_setattr's call to ext3_truncate failed to get a 2962 /* If inode_setattr's call to ext4_truncate failed to get a
2963 * transaction handle at all, we need to clean up the in-core 2963 * transaction handle at all, we need to clean up the in-core
2964 * orphan list manually. */ 2964 * orphan list manually. */
2965 if (inode->i_nlink) 2965 if (inode->i_nlink)
2966 ext3_orphan_del(NULL, inode); 2966 ext4_orphan_del(NULL, inode);
2967 2967
2968 if (!rc && (ia_valid & ATTR_MODE)) 2968 if (!rc && (ia_valid & ATTR_MODE))
2969 rc = ext3_acl_chmod(inode); 2969 rc = ext4_acl_chmod(inode);
2970 2970
2971err_out: 2971err_out:
2972 ext3_std_error(inode->i_sb, error); 2972 ext4_std_error(inode->i_sb, error);
2973 if (!error) 2973 if (!error)
2974 error = rc; 2974 error = rc;
2975 return error; 2975 return error;
@@ -2988,9 +2988,9 @@ err_out:
2988 * N+5 group descriptor summary blocks 2988 * N+5 group descriptor summary blocks
2989 * 1 inode block 2989 * 1 inode block
2990 * 1 superblock. 2990 * 1 superblock.
2991 * 2 * EXT3_SINGLEDATA_TRANS_BLOCKS for the quote files 2991 * 2 * EXT4_SINGLEDATA_TRANS_BLOCKS for the quote files
2992 * 2992 *
2993 * 3 * (N + 5) + 2 + 2 * EXT3_SINGLEDATA_TRANS_BLOCKS 2993 * 3 * (N + 5) + 2 + 2 * EXT4_SINGLEDATA_TRANS_BLOCKS
2994 * 2994 *
2995 * With ordered or writeback data it's the same, less the N data blocks. 2995 * With ordered or writeback data it's the same, less the N data blocks.
2996 * 2996 *
@@ -3003,13 +3003,13 @@ err_out:
3003 * block and work out the exact number of indirects which are touched. Pah. 3003 * block and work out the exact number of indirects which are touched. Pah.
3004 */ 3004 */
3005 3005
3006static int ext3_writepage_trans_blocks(struct inode *inode) 3006static int ext4_writepage_trans_blocks(struct inode *inode)
3007{ 3007{
3008 int bpp = ext3_journal_blocks_per_page(inode); 3008 int bpp = ext4_journal_blocks_per_page(inode);
3009 int indirects = (EXT3_NDIR_BLOCKS % bpp) ? 5 : 3; 3009 int indirects = (EXT4_NDIR_BLOCKS % bpp) ? 5 : 3;
3010 int ret; 3010 int ret;
3011 3011
3012 if (ext3_should_journal_data(inode)) 3012 if (ext4_should_journal_data(inode))
3013 ret = 3 * (bpp + indirects) + 2; 3013 ret = 3 * (bpp + indirects) + 2;
3014 else 3014 else
3015 ret = 2 * (bpp + indirects) + 2; 3015 ret = 2 * (bpp + indirects) + 2;
@@ -3017,26 +3017,26 @@ static int ext3_writepage_trans_blocks(struct inode *inode)
3017#ifdef CONFIG_QUOTA 3017#ifdef CONFIG_QUOTA
3018 /* We know that structure was already allocated during DQUOT_INIT so 3018 /* We know that structure was already allocated during DQUOT_INIT so
3019 * we will be updating only the data blocks + inodes */ 3019 * we will be updating only the data blocks + inodes */
3020 ret += 2*EXT3_QUOTA_TRANS_BLOCKS(inode->i_sb); 3020 ret += 2*EXT4_QUOTA_TRANS_BLOCKS(inode->i_sb);
3021#endif 3021#endif
3022 3022
3023 return ret; 3023 return ret;
3024} 3024}
3025 3025
3026/* 3026/*
3027 * The caller must have previously called ext3_reserve_inode_write(). 3027 * The caller must have previously called ext4_reserve_inode_write().
3028 * Give this, we know that the caller already has write access to iloc->bh. 3028 * Give this, we know that the caller already has write access to iloc->bh.
3029 */ 3029 */
3030int ext3_mark_iloc_dirty(handle_t *handle, 3030int ext4_mark_iloc_dirty(handle_t *handle,
3031 struct inode *inode, struct ext3_iloc *iloc) 3031 struct inode *inode, struct ext4_iloc *iloc)
3032{ 3032{
3033 int err = 0; 3033 int err = 0;
3034 3034
3035 /* the do_update_inode consumes one bh->b_count */ 3035 /* the do_update_inode consumes one bh->b_count */
3036 get_bh(iloc->bh); 3036 get_bh(iloc->bh);
3037 3037
3038 /* ext3_do_update_inode() does journal_dirty_metadata */ 3038 /* ext4_do_update_inode() does journal_dirty_metadata */
3039 err = ext3_do_update_inode(handle, inode, iloc); 3039 err = ext4_do_update_inode(handle, inode, iloc);
3040 put_bh(iloc->bh); 3040 put_bh(iloc->bh);
3041 return err; 3041 return err;
3042} 3042}
@@ -3047,22 +3047,22 @@ int ext3_mark_iloc_dirty(handle_t *handle,
3047 */ 3047 */
3048 3048
3049int 3049int
3050ext3_reserve_inode_write(handle_t *handle, struct inode *inode, 3050ext4_reserve_inode_write(handle_t *handle, struct inode *inode,
3051 struct ext3_iloc *iloc) 3051 struct ext4_iloc *iloc)
3052{ 3052{
3053 int err = 0; 3053 int err = 0;
3054 if (handle) { 3054 if (handle) {
3055 err = ext3_get_inode_loc(inode, iloc); 3055 err = ext4_get_inode_loc(inode, iloc);
3056 if (!err) { 3056 if (!err) {
3057 BUFFER_TRACE(iloc->bh, "get_write_access"); 3057 BUFFER_TRACE(iloc->bh, "get_write_access");
3058 err = ext3_journal_get_write_access(handle, iloc->bh); 3058 err = ext4_journal_get_write_access(handle, iloc->bh);
3059 if (err) { 3059 if (err) {
3060 brelse(iloc->bh); 3060 brelse(iloc->bh);
3061 iloc->bh = NULL; 3061 iloc->bh = NULL;
3062 } 3062 }
3063 } 3063 }
3064 } 3064 }
3065 ext3_std_error(inode->i_sb, err); 3065 ext4_std_error(inode->i_sb, err);
3066 return err; 3066 return err;
3067} 3067}
3068 3068
@@ -3087,20 +3087,20 @@ ext3_reserve_inode_write(handle_t *handle, struct inode *inode,
3087 * to do a write_super() to free up some memory. It has the desired 3087 * to do a write_super() to free up some memory. It has the desired
3088 * effect. 3088 * effect.
3089 */ 3089 */
3090int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode) 3090int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode)
3091{ 3091{
3092 struct ext3_iloc iloc; 3092 struct ext4_iloc iloc;
3093 int err; 3093 int err;
3094 3094
3095 might_sleep(); 3095 might_sleep();
3096 err = ext3_reserve_inode_write(handle, inode, &iloc); 3096 err = ext4_reserve_inode_write(handle, inode, &iloc);
3097 if (!err) 3097 if (!err)
3098 err = ext3_mark_iloc_dirty(handle, inode, &iloc); 3098 err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3099 return err; 3099 return err;
3100} 3100}
3101 3101
3102/* 3102/*
3103 * ext3_dirty_inode() is called from __mark_inode_dirty() 3103 * ext4_dirty_inode() is called from __mark_inode_dirty()
3104 * 3104 *
3105 * We're really interested in the case where a file is being extended. 3105 * We're really interested in the case where a file is being extended.
3106 * i_size has been changed by generic_commit_write() and we thus need 3106 * i_size has been changed by generic_commit_write() and we thus need
@@ -3113,12 +3113,12 @@ int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode)
3113 * so would cause a commit on atime updates, which we don't bother doing. 3113 * so would cause a commit on atime updates, which we don't bother doing.
3114 * We handle synchronous inodes at the highest possible level. 3114 * We handle synchronous inodes at the highest possible level.
3115 */ 3115 */
3116void ext3_dirty_inode(struct inode *inode) 3116void ext4_dirty_inode(struct inode *inode)
3117{ 3117{
3118 handle_t *current_handle = ext3_journal_current_handle(); 3118 handle_t *current_handle = ext4_journal_current_handle();
3119 handle_t *handle; 3119 handle_t *handle;
3120 3120
3121 handle = ext3_journal_start(inode, 2); 3121 handle = ext4_journal_start(inode, 2);
3122 if (IS_ERR(handle)) 3122 if (IS_ERR(handle))
3123 goto out; 3123 goto out;
3124 if (current_handle && 3124 if (current_handle &&
@@ -3129,9 +3129,9 @@ void ext3_dirty_inode(struct inode *inode)
3129 } else { 3129 } else {
3130 jbd_debug(5, "marking dirty. outer handle=%p\n", 3130 jbd_debug(5, "marking dirty. outer handle=%p\n",
3131 current_handle); 3131 current_handle);
3132 ext3_mark_inode_dirty(handle, inode); 3132 ext4_mark_inode_dirty(handle, inode);
3133 } 3133 }
3134 ext3_journal_stop(handle); 3134 ext4_journal_stop(handle);
3135out: 3135out:
3136 return; 3136 return;
3137} 3137}
@@ -3140,32 +3140,32 @@ out:
3140/* 3140/*
3141 * Bind an inode's backing buffer_head into this transaction, to prevent 3141 * Bind an inode's backing buffer_head into this transaction, to prevent
3142 * it from being flushed to disk early. Unlike 3142 * it from being flushed to disk early. Unlike
3143 * ext3_reserve_inode_write, this leaves behind no bh reference and 3143 * ext4_reserve_inode_write, this leaves behind no bh reference and
3144 * returns no iloc structure, so the caller needs to repeat the iloc 3144 * returns no iloc structure, so the caller needs to repeat the iloc
3145 * lookup to mark the inode dirty later. 3145 * lookup to mark the inode dirty later.
3146 */ 3146 */
3147static int ext3_pin_inode(handle_t *handle, struct inode *inode) 3147static int ext4_pin_inode(handle_t *handle, struct inode *inode)
3148{ 3148{
3149 struct ext3_iloc iloc; 3149 struct ext4_iloc iloc;
3150 3150
3151 int err = 0; 3151 int err = 0;
3152 if (handle) { 3152 if (handle) {
3153 err = ext3_get_inode_loc(inode, &iloc); 3153 err = ext4_get_inode_loc(inode, &iloc);
3154 if (!err) { 3154 if (!err) {
3155 BUFFER_TRACE(iloc.bh, "get_write_access"); 3155 BUFFER_TRACE(iloc.bh, "get_write_access");
3156 err = journal_get_write_access(handle, iloc.bh); 3156 err = journal_get_write_access(handle, iloc.bh);
3157 if (!err) 3157 if (!err)
3158 err = ext3_journal_dirty_metadata(handle, 3158 err = ext4_journal_dirty_metadata(handle,
3159 iloc.bh); 3159 iloc.bh);
3160 brelse(iloc.bh); 3160 brelse(iloc.bh);
3161 } 3161 }
3162 } 3162 }
3163 ext3_std_error(inode->i_sb, err); 3163 ext4_std_error(inode->i_sb, err);
3164 return err; 3164 return err;
3165} 3165}
3166#endif 3166#endif
3167 3167
3168int ext3_change_inode_journal_flag(struct inode *inode, int val) 3168int ext4_change_inode_journal_flag(struct inode *inode, int val)
3169{ 3169{
3170 journal_t *journal; 3170 journal_t *journal;
3171 handle_t *handle; 3171 handle_t *handle;
@@ -3181,7 +3181,7 @@ int ext3_change_inode_journal_flag(struct inode *inode, int val)
3181 * nobody is changing anything. 3181 * nobody is changing anything.
3182 */ 3182 */
3183 3183
3184 journal = EXT3_JOURNAL(inode); 3184 journal = EXT4_JOURNAL(inode);
3185 if (is_journal_aborted(journal) || IS_RDONLY(inode)) 3185 if (is_journal_aborted(journal) || IS_RDONLY(inode))
3186 return -EROFS; 3186 return -EROFS;
3187 3187
@@ -3197,23 +3197,23 @@ int ext3_change_inode_journal_flag(struct inode *inode, int val)
3197 */ 3197 */
3198 3198
3199 if (val) 3199 if (val)
3200 EXT3_I(inode)->i_flags |= EXT3_JOURNAL_DATA_FL; 3200 EXT4_I(inode)->i_flags |= EXT4_JOURNAL_DATA_FL;
3201 else 3201 else
3202 EXT3_I(inode)->i_flags &= ~EXT3_JOURNAL_DATA_FL; 3202 EXT4_I(inode)->i_flags &= ~EXT4_JOURNAL_DATA_FL;
3203 ext3_set_aops(inode); 3203 ext4_set_aops(inode);
3204 3204
3205 journal_unlock_updates(journal); 3205 journal_unlock_updates(journal);
3206 3206
3207 /* Finally we can mark the inode as dirty. */ 3207 /* Finally we can mark the inode as dirty. */
3208 3208
3209 handle = ext3_journal_start(inode, 1); 3209 handle = ext4_journal_start(inode, 1);
3210 if (IS_ERR(handle)) 3210 if (IS_ERR(handle))
3211 return PTR_ERR(handle); 3211 return PTR_ERR(handle);
3212 3212
3213 err = ext3_mark_inode_dirty(handle, inode); 3213 err = ext4_mark_inode_dirty(handle, inode);
3214 handle->h_sync = 1; 3214 handle->h_sync = 1;
3215 ext3_journal_stop(handle); 3215 ext4_journal_stop(handle);
3216 ext3_std_error(inode->i_sb, err); 3216 ext4_std_error(inode->i_sb, err);
3217 3217
3218 return err; 3218 return err;
3219} 3219}
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 12daa686957..a567af161b0 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/ioctl.c 2 * linux/fs/ext4/ioctl.c
3 * 3 *
4 * Copyright (C) 1993, 1994, 1995 4 * Copyright (C) 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -10,30 +10,30 @@
10#include <linux/fs.h> 10#include <linux/fs.h>
11#include <linux/jbd.h> 11#include <linux/jbd.h>
12#include <linux/capability.h> 12#include <linux/capability.h>
13#include <linux/ext3_fs.h> 13#include <linux/ext4_fs.h>
14#include <linux/ext3_jbd.h> 14#include <linux/ext4_jbd.h>
15#include <linux/time.h> 15#include <linux/time.h>
16#include <linux/compat.h> 16#include <linux/compat.h>
17#include <linux/smp_lock.h> 17#include <linux/smp_lock.h>
18#include <asm/uaccess.h> 18#include <asm/uaccess.h>
19 19
20int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, 20int ext4_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
21 unsigned long arg) 21 unsigned long arg)
22{ 22{
23 struct ext3_inode_info *ei = EXT3_I(inode); 23 struct ext4_inode_info *ei = EXT4_I(inode);
24 unsigned int flags; 24 unsigned int flags;
25 unsigned short rsv_window_size; 25 unsigned short rsv_window_size;
26 26
27 ext3_debug ("cmd = %u, arg = %lu\n", cmd, arg); 27 ext4_debug ("cmd = %u, arg = %lu\n", cmd, arg);
28 28
29 switch (cmd) { 29 switch (cmd) {
30 case EXT3_IOC_GETFLAGS: 30 case EXT4_IOC_GETFLAGS:
31 flags = ei->i_flags & EXT3_FL_USER_VISIBLE; 31 flags = ei->i_flags & EXT4_FL_USER_VISIBLE;
32 return put_user(flags, (int __user *) arg); 32 return put_user(flags, (int __user *) arg);
33 case EXT3_IOC_SETFLAGS: { 33 case EXT4_IOC_SETFLAGS: {
34 handle_t *handle = NULL; 34 handle_t *handle = NULL;
35 int err; 35 int err;
36 struct ext3_iloc iloc; 36 struct ext4_iloc iloc;
37 unsigned int oldflags; 37 unsigned int oldflags;
38 unsigned int jflag; 38 unsigned int jflag;
39 39
@@ -47,13 +47,13 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
47 return -EFAULT; 47 return -EFAULT;
48 48
49 if (!S_ISDIR(inode->i_mode)) 49 if (!S_ISDIR(inode->i_mode))
50 flags &= ~EXT3_DIRSYNC_FL; 50 flags &= ~EXT4_DIRSYNC_FL;
51 51
52 mutex_lock(&inode->i_mutex); 52 mutex_lock(&inode->i_mutex);
53 oldflags = ei->i_flags; 53 oldflags = ei->i_flags;
54 54
55 /* The JOURNAL_DATA flag is modifiable only by root */ 55 /* The JOURNAL_DATA flag is modifiable only by root */
56 jflag = flags & EXT3_JOURNAL_DATA_FL; 56 jflag = flags & EXT4_JOURNAL_DATA_FL;
57 57
58 /* 58 /*
59 * The IMMUTABLE and APPEND_ONLY flags can only be changed by 59 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
@@ -61,7 +61,7 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
61 * 61 *
62 * This test looks nicer. Thanks to Pauline Middelink 62 * This test looks nicer. Thanks to Pauline Middelink
63 */ 63 */
64 if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) { 64 if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
65 if (!capable(CAP_LINUX_IMMUTABLE)) { 65 if (!capable(CAP_LINUX_IMMUTABLE)) {
66 mutex_unlock(&inode->i_mutex); 66 mutex_unlock(&inode->i_mutex);
67 return -EPERM; 67 return -EPERM;
@@ -72,7 +72,7 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
72 * The JOURNAL_DATA flag can only be changed by 72 * The JOURNAL_DATA flag can only be changed by
73 * the relevant capability. 73 * the relevant capability.
74 */ 74 */
75 if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL)) { 75 if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) {
76 if (!capable(CAP_SYS_RESOURCE)) { 76 if (!capable(CAP_SYS_RESOURCE)) {
77 mutex_unlock(&inode->i_mutex); 77 mutex_unlock(&inode->i_mutex);
78 return -EPERM; 78 return -EPERM;
@@ -80,44 +80,44 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
80 } 80 }
81 81
82 82
83 handle = ext3_journal_start(inode, 1); 83 handle = ext4_journal_start(inode, 1);
84 if (IS_ERR(handle)) { 84 if (IS_ERR(handle)) {
85 mutex_unlock(&inode->i_mutex); 85 mutex_unlock(&inode->i_mutex);
86 return PTR_ERR(handle); 86 return PTR_ERR(handle);
87 } 87 }
88 if (IS_SYNC(inode)) 88 if (IS_SYNC(inode))
89 handle->h_sync = 1; 89 handle->h_sync = 1;
90 err = ext3_reserve_inode_write(handle, inode, &iloc); 90 err = ext4_reserve_inode_write(handle, inode, &iloc);
91 if (err) 91 if (err)
92 goto flags_err; 92 goto flags_err;
93 93
94 flags = flags & EXT3_FL_USER_MODIFIABLE; 94 flags = flags & EXT4_FL_USER_MODIFIABLE;
95 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE; 95 flags |= oldflags & ~EXT4_FL_USER_MODIFIABLE;
96 ei->i_flags = flags; 96 ei->i_flags = flags;
97 97
98 ext3_set_inode_flags(inode); 98 ext4_set_inode_flags(inode);
99 inode->i_ctime = CURRENT_TIME_SEC; 99 inode->i_ctime = CURRENT_TIME_SEC;
100 100
101 err = ext3_mark_iloc_dirty(handle, inode, &iloc); 101 err = ext4_mark_iloc_dirty(handle, inode, &iloc);
102flags_err: 102flags_err:
103 ext3_journal_stop(handle); 103 ext4_journal_stop(handle);
104 if (err) { 104 if (err) {
105 mutex_unlock(&inode->i_mutex); 105 mutex_unlock(&inode->i_mutex);
106 return err; 106 return err;
107 } 107 }
108 108
109 if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL)) 109 if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL))
110 err = ext3_change_inode_journal_flag(inode, jflag); 110 err = ext4_change_inode_journal_flag(inode, jflag);
111 mutex_unlock(&inode->i_mutex); 111 mutex_unlock(&inode->i_mutex);
112 return err; 112 return err;
113 } 113 }
114 case EXT3_IOC_GETVERSION: 114 case EXT4_IOC_GETVERSION:
115 case EXT3_IOC_GETVERSION_OLD: 115 case EXT4_IOC_GETVERSION_OLD:
116 return put_user(inode->i_generation, (int __user *) arg); 116 return put_user(inode->i_generation, (int __user *) arg);
117 case EXT3_IOC_SETVERSION: 117 case EXT4_IOC_SETVERSION:
118 case EXT3_IOC_SETVERSION_OLD: { 118 case EXT4_IOC_SETVERSION_OLD: {
119 handle_t *handle; 119 handle_t *handle;
120 struct ext3_iloc iloc; 120 struct ext4_iloc iloc;
121 __u32 generation; 121 __u32 generation;
122 int err; 122 int err;
123 123
@@ -128,20 +128,20 @@ flags_err:
128 if (get_user(generation, (int __user *) arg)) 128 if (get_user(generation, (int __user *) arg))
129 return -EFAULT; 129 return -EFAULT;
130 130
131 handle = ext3_journal_start(inode, 1); 131 handle = ext4_journal_start(inode, 1);
132 if (IS_ERR(handle)) 132 if (IS_ERR(handle))
133 return PTR_ERR(handle); 133 return PTR_ERR(handle);
134 err = ext3_reserve_inode_write(handle, inode, &iloc); 134 err = ext4_reserve_inode_write(handle, inode, &iloc);
135 if (err == 0) { 135 if (err == 0) {
136 inode->i_ctime = CURRENT_TIME_SEC; 136 inode->i_ctime = CURRENT_TIME_SEC;
137 inode->i_generation = generation; 137 inode->i_generation = generation;
138 err = ext3_mark_iloc_dirty(handle, inode, &iloc); 138 err = ext4_mark_iloc_dirty(handle, inode, &iloc);
139 } 139 }
140 ext3_journal_stop(handle); 140 ext4_journal_stop(handle);
141 return err; 141 return err;
142 } 142 }
143#ifdef CONFIG_JBD_DEBUG 143#ifdef CONFIG_JBD_DEBUG
144 case EXT3_IOC_WAIT_FOR_READONLY: 144 case EXT4_IOC_WAIT_FOR_READONLY:
145 /* 145 /*
146 * This is racy - by the time we're woken up and running, 146 * This is racy - by the time we're woken up and running,
147 * the superblock could be released. And the module could 147 * the superblock could be released. And the module could
@@ -155,16 +155,16 @@ flags_err:
155 int ret = 0; 155 int ret = 0;
156 156
157 set_current_state(TASK_INTERRUPTIBLE); 157 set_current_state(TASK_INTERRUPTIBLE);
158 add_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait); 158 add_wait_queue(&EXT4_SB(sb)->ro_wait_queue, &wait);
159 if (timer_pending(&EXT3_SB(sb)->turn_ro_timer)) { 159 if (timer_pending(&EXT4_SB(sb)->turn_ro_timer)) {
160 schedule(); 160 schedule();
161 ret = 1; 161 ret = 1;
162 } 162 }
163 remove_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait); 163 remove_wait_queue(&EXT4_SB(sb)->ro_wait_queue, &wait);
164 return ret; 164 return ret;
165 } 165 }
166#endif 166#endif
167 case EXT3_IOC_GETRSVSZ: 167 case EXT4_IOC_GETRSVSZ:
168 if (test_opt(inode->i_sb, RESERVATION) 168 if (test_opt(inode->i_sb, RESERVATION)
169 && S_ISREG(inode->i_mode) 169 && S_ISREG(inode->i_mode)
170 && ei->i_block_alloc_info) { 170 && ei->i_block_alloc_info) {
@@ -172,7 +172,7 @@ flags_err:
172 return put_user(rsv_window_size, (int __user *)arg); 172 return put_user(rsv_window_size, (int __user *)arg);
173 } 173 }
174 return -ENOTTY; 174 return -ENOTTY;
175 case EXT3_IOC_SETRSVSZ: { 175 case EXT4_IOC_SETRSVSZ: {
176 176
177 if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode)) 177 if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
178 return -ENOTTY; 178 return -ENOTTY;
@@ -186,8 +186,8 @@ flags_err:
186 if (get_user(rsv_window_size, (int __user *)arg)) 186 if (get_user(rsv_window_size, (int __user *)arg))
187 return -EFAULT; 187 return -EFAULT;
188 188
189 if (rsv_window_size > EXT3_MAX_RESERVE_BLOCKS) 189 if (rsv_window_size > EXT4_MAX_RESERVE_BLOCKS)
190 rsv_window_size = EXT3_MAX_RESERVE_BLOCKS; 190 rsv_window_size = EXT4_MAX_RESERVE_BLOCKS;
191 191
192 /* 192 /*
193 * need to allocate reservation structure for this inode 193 * need to allocate reservation structure for this inode
@@ -195,17 +195,17 @@ flags_err:
195 */ 195 */
196 mutex_lock(&ei->truncate_mutex); 196 mutex_lock(&ei->truncate_mutex);
197 if (!ei->i_block_alloc_info) 197 if (!ei->i_block_alloc_info)
198 ext3_init_block_alloc_info(inode); 198 ext4_init_block_alloc_info(inode);
199 199
200 if (ei->i_block_alloc_info){ 200 if (ei->i_block_alloc_info){
201 struct ext3_reserve_window_node *rsv = &ei->i_block_alloc_info->rsv_window_node; 201 struct ext4_reserve_window_node *rsv = &ei->i_block_alloc_info->rsv_window_node;
202 rsv->rsv_goal_size = rsv_window_size; 202 rsv->rsv_goal_size = rsv_window_size;
203 } 203 }
204 mutex_unlock(&ei->truncate_mutex); 204 mutex_unlock(&ei->truncate_mutex);
205 return 0; 205 return 0;
206 } 206 }
207 case EXT3_IOC_GROUP_EXTEND: { 207 case EXT4_IOC_GROUP_EXTEND: {
208 ext3_fsblk_t n_blocks_count; 208 ext4_fsblk_t n_blocks_count;
209 struct super_block *sb = inode->i_sb; 209 struct super_block *sb = inode->i_sb;
210 int err; 210 int err;
211 211
@@ -218,15 +218,15 @@ flags_err:
218 if (get_user(n_blocks_count, (__u32 __user *)arg)) 218 if (get_user(n_blocks_count, (__u32 __user *)arg))
219 return -EFAULT; 219 return -EFAULT;
220 220
221 err = ext3_group_extend(sb, EXT3_SB(sb)->s_es, n_blocks_count); 221 err = ext4_group_extend(sb, EXT4_SB(sb)->s_es, n_blocks_count);
222 journal_lock_updates(EXT3_SB(sb)->s_journal); 222 journal_lock_updates(EXT4_SB(sb)->s_journal);
223 journal_flush(EXT3_SB(sb)->s_journal); 223 journal_flush(EXT4_SB(sb)->s_journal);
224 journal_unlock_updates(EXT3_SB(sb)->s_journal); 224 journal_unlock_updates(EXT4_SB(sb)->s_journal);
225 225
226 return err; 226 return err;
227 } 227 }
228 case EXT3_IOC_GROUP_ADD: { 228 case EXT4_IOC_GROUP_ADD: {
229 struct ext3_new_group_data input; 229 struct ext4_new_group_data input;
230 struct super_block *sb = inode->i_sb; 230 struct super_block *sb = inode->i_sb;
231 int err; 231 int err;
232 232
@@ -236,14 +236,14 @@ flags_err:
236 if (IS_RDONLY(inode)) 236 if (IS_RDONLY(inode))
237 return -EROFS; 237 return -EROFS;
238 238
239 if (copy_from_user(&input, (struct ext3_new_group_input __user *)arg, 239 if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
240 sizeof(input))) 240 sizeof(input)))
241 return -EFAULT; 241 return -EFAULT;
242 242
243 err = ext3_group_add(sb, &input); 243 err = ext4_group_add(sb, &input);
244 journal_lock_updates(EXT3_SB(sb)->s_journal); 244 journal_lock_updates(EXT4_SB(sb)->s_journal);
245 journal_flush(EXT3_SB(sb)->s_journal); 245 journal_flush(EXT4_SB(sb)->s_journal);
246 journal_unlock_updates(EXT3_SB(sb)->s_journal); 246 journal_unlock_updates(EXT4_SB(sb)->s_journal);
247 247
248 return err; 248 return err;
249 } 249 }
@@ -255,52 +255,52 @@ flags_err:
255} 255}
256 256
257#ifdef CONFIG_COMPAT 257#ifdef CONFIG_COMPAT
258long ext3_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 258long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
259{ 259{
260 struct inode *inode = file->f_dentry->d_inode; 260 struct inode *inode = file->f_dentry->d_inode;
261 int ret; 261 int ret;
262 262
263 /* These are just misnamed, they actually get/put from/to user an int */ 263 /* These are just misnamed, they actually get/put from/to user an int */
264 switch (cmd) { 264 switch (cmd) {
265 case EXT3_IOC32_GETFLAGS: 265 case EXT4_IOC32_GETFLAGS:
266 cmd = EXT3_IOC_GETFLAGS; 266 cmd = EXT4_IOC_GETFLAGS;
267 break; 267 break;
268 case EXT3_IOC32_SETFLAGS: 268 case EXT4_IOC32_SETFLAGS:
269 cmd = EXT3_IOC_SETFLAGS; 269 cmd = EXT4_IOC_SETFLAGS;
270 break; 270 break;
271 case EXT3_IOC32_GETVERSION: 271 case EXT4_IOC32_GETVERSION:
272 cmd = EXT3_IOC_GETVERSION; 272 cmd = EXT4_IOC_GETVERSION;
273 break; 273 break;
274 case EXT3_IOC32_SETVERSION: 274 case EXT4_IOC32_SETVERSION:
275 cmd = EXT3_IOC_SETVERSION; 275 cmd = EXT4_IOC_SETVERSION;
276 break; 276 break;
277 case EXT3_IOC32_GROUP_EXTEND: 277 case EXT4_IOC32_GROUP_EXTEND:
278 cmd = EXT3_IOC_GROUP_EXTEND; 278 cmd = EXT4_IOC_GROUP_EXTEND;
279 break; 279 break;
280 case EXT3_IOC32_GETVERSION_OLD: 280 case EXT4_IOC32_GETVERSION_OLD:
281 cmd = EXT3_IOC_GETVERSION_OLD; 281 cmd = EXT4_IOC_GETVERSION_OLD;
282 break; 282 break;
283 case EXT3_IOC32_SETVERSION_OLD: 283 case EXT4_IOC32_SETVERSION_OLD:
284 cmd = EXT3_IOC_SETVERSION_OLD; 284 cmd = EXT4_IOC_SETVERSION_OLD;
285 break; 285 break;
286#ifdef CONFIG_JBD_DEBUG 286#ifdef CONFIG_JBD_DEBUG
287 case EXT3_IOC32_WAIT_FOR_READONLY: 287 case EXT4_IOC32_WAIT_FOR_READONLY:
288 cmd = EXT3_IOC_WAIT_FOR_READONLY; 288 cmd = EXT4_IOC_WAIT_FOR_READONLY;
289 break; 289 break;
290#endif 290#endif
291 case EXT3_IOC32_GETRSVSZ: 291 case EXT4_IOC32_GETRSVSZ:
292 cmd = EXT3_IOC_GETRSVSZ; 292 cmd = EXT4_IOC_GETRSVSZ;
293 break; 293 break;
294 case EXT3_IOC32_SETRSVSZ: 294 case EXT4_IOC32_SETRSVSZ:
295 cmd = EXT3_IOC_SETRSVSZ; 295 cmd = EXT4_IOC_SETRSVSZ;
296 break; 296 break;
297 case EXT3_IOC_GROUP_ADD: 297 case EXT4_IOC_GROUP_ADD:
298 break; 298 break;
299 default: 299 default:
300 return -ENOIOCTLCMD; 300 return -ENOIOCTLCMD;
301 } 301 }
302 lock_kernel(); 302 lock_kernel();
303 ret = ext3_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg)); 303 ret = ext4_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));
304 unlock_kernel(); 304 unlock_kernel();
305 return ret; 305 return ret;
306} 306}
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 906731a20f1..956b38113f6 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/namei.c 2 * linux/fs/ext4/namei.c
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -28,8 +28,8 @@
28#include <linux/pagemap.h> 28#include <linux/pagemap.h>
29#include <linux/jbd.h> 29#include <linux/jbd.h>
30#include <linux/time.h> 30#include <linux/time.h>
31#include <linux/ext3_fs.h> 31#include <linux/ext4_fs.h>
32#include <linux/ext3_jbd.h> 32#include <linux/ext4_jbd.h>
33#include <linux/fcntl.h> 33#include <linux/fcntl.h>
34#include <linux/stat.h> 34#include <linux/stat.h>
35#include <linux/string.h> 35#include <linux/string.h>
@@ -50,7 +50,7 @@
50#define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS) 50#define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS)
51#define NAMEI_RA_INDEX(c,b) (((c) * NAMEI_RA_BLOCKS) + (b)) 51#define NAMEI_RA_INDEX(c,b) (((c) * NAMEI_RA_BLOCKS) + (b))
52 52
53static struct buffer_head *ext3_append(handle_t *handle, 53static struct buffer_head *ext4_append(handle_t *handle,
54 struct inode *inode, 54 struct inode *inode,
55 u32 *block, int *err) 55 u32 *block, int *err)
56{ 56{
@@ -58,10 +58,10 @@ static struct buffer_head *ext3_append(handle_t *handle,
58 58
59 *block = inode->i_size >> inode->i_sb->s_blocksize_bits; 59 *block = inode->i_size >> inode->i_sb->s_blocksize_bits;
60 60
61 if ((bh = ext3_bread(handle, inode, *block, 1, err))) { 61 if ((bh = ext4_bread(handle, inode, *block, 1, err))) {
62 inode->i_size += inode->i_sb->s_blocksize; 62 inode->i_size += inode->i_sb->s_blocksize;
63 EXT3_I(inode)->i_disksize = inode->i_size; 63 EXT4_I(inode)->i_disksize = inode->i_size;
64 ext3_journal_get_write_access(handle,bh); 64 ext4_journal_get_write_access(handle,bh);
65 } 65 }
66 return bh; 66 return bh;
67} 67}
@@ -144,7 +144,7 @@ struct dx_map_entry
144 u32 offs; 144 u32 offs;
145}; 145};
146 146
147#ifdef CONFIG_EXT3_INDEX 147#ifdef CONFIG_EXT4_INDEX
148static inline unsigned dx_get_block (struct dx_entry *entry); 148static inline unsigned dx_get_block (struct dx_entry *entry);
149static void dx_set_block (struct dx_entry *entry, unsigned value); 149static void dx_set_block (struct dx_entry *entry, unsigned value);
150static inline unsigned dx_get_hash (struct dx_entry *entry); 150static inline unsigned dx_get_hash (struct dx_entry *entry);
@@ -161,20 +161,20 @@ static struct dx_frame *dx_probe(struct dentry *dentry,
161 struct dx_frame *frame, 161 struct dx_frame *frame,
162 int *err); 162 int *err);
163static void dx_release (struct dx_frame *frames); 163static void dx_release (struct dx_frame *frames);
164static int dx_make_map (struct ext3_dir_entry_2 *de, int size, 164static int dx_make_map (struct ext4_dir_entry_2 *de, int size,
165 struct dx_hash_info *hinfo, struct dx_map_entry map[]); 165 struct dx_hash_info *hinfo, struct dx_map_entry map[]);
166static void dx_sort_map(struct dx_map_entry *map, unsigned count); 166static void dx_sort_map(struct dx_map_entry *map, unsigned count);
167static struct ext3_dir_entry_2 *dx_move_dirents (char *from, char *to, 167static struct ext4_dir_entry_2 *dx_move_dirents (char *from, char *to,
168 struct dx_map_entry *offsets, int count); 168 struct dx_map_entry *offsets, int count);
169static struct ext3_dir_entry_2* dx_pack_dirents (char *base, int size); 169static struct ext4_dir_entry_2* dx_pack_dirents (char *base, int size);
170static void dx_insert_block (struct dx_frame *frame, u32 hash, u32 block); 170static void dx_insert_block (struct dx_frame *frame, u32 hash, u32 block);
171static int ext3_htree_next_block(struct inode *dir, __u32 hash, 171static int ext4_htree_next_block(struct inode *dir, __u32 hash,
172 struct dx_frame *frame, 172 struct dx_frame *frame,
173 struct dx_frame *frames, 173 struct dx_frame *frames,
174 __u32 *start_hash); 174 __u32 *start_hash);
175static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry, 175static struct buffer_head * ext4_dx_find_entry(struct dentry *dentry,
176 struct ext3_dir_entry_2 **res_dir, int *err); 176 struct ext4_dir_entry_2 **res_dir, int *err);
177static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, 177static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
178 struct inode *inode); 178 struct inode *inode);
179 179
180/* 180/*
@@ -224,14 +224,14 @@ static inline void dx_set_limit (struct dx_entry *entries, unsigned value)
224 224
225static inline unsigned dx_root_limit (struct inode *dir, unsigned infosize) 225static inline unsigned dx_root_limit (struct inode *dir, unsigned infosize)
226{ 226{
227 unsigned entry_space = dir->i_sb->s_blocksize - EXT3_DIR_REC_LEN(1) - 227 unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(1) -
228 EXT3_DIR_REC_LEN(2) - infosize; 228 EXT4_DIR_REC_LEN(2) - infosize;
229 return 0? 20: entry_space / sizeof(struct dx_entry); 229 return 0? 20: entry_space / sizeof(struct dx_entry);
230} 230}
231 231
232static inline unsigned dx_node_limit (struct inode *dir) 232static inline unsigned dx_node_limit (struct inode *dir)
233{ 233{
234 unsigned entry_space = dir->i_sb->s_blocksize - EXT3_DIR_REC_LEN(0); 234 unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(0);
235 return 0? 22: entry_space / sizeof(struct dx_entry); 235 return 0? 22: entry_space / sizeof(struct dx_entry);
236} 236}
237 237
@@ -257,7 +257,7 @@ struct stats
257 unsigned bcount; 257 unsigned bcount;
258}; 258};
259 259
260static struct stats dx_show_leaf(struct dx_hash_info *hinfo, struct ext3_dir_entry_2 *de, 260static struct stats dx_show_leaf(struct dx_hash_info *hinfo, struct ext4_dir_entry_2 *de,
261 int size, int show_names) 261 int size, int show_names)
262{ 262{
263 unsigned names = 0, space = 0; 263 unsigned names = 0, space = 0;
@@ -274,14 +274,14 @@ static struct stats dx_show_leaf(struct dx_hash_info *hinfo, struct ext3_dir_ent
274 int len = de->name_len; 274 int len = de->name_len;
275 char *name = de->name; 275 char *name = de->name;
276 while (len--) printk("%c", *name++); 276 while (len--) printk("%c", *name++);
277 ext3fs_dirhash(de->name, de->name_len, &h); 277 ext4fs_dirhash(de->name, de->name_len, &h);
278 printk(":%x.%u ", h.hash, 278 printk(":%x.%u ", h.hash,
279 ((char *) de - base)); 279 ((char *) de - base));
280 } 280 }
281 space += EXT3_DIR_REC_LEN(de->name_len); 281 space += EXT4_DIR_REC_LEN(de->name_len);
282 names++; 282 names++;
283 } 283 }
284 de = (struct ext3_dir_entry_2 *) ((char *) de + le16_to_cpu(de->rec_len)); 284 de = (struct ext4_dir_entry_2 *) ((char *) de + le16_to_cpu(de->rec_len));
285 } 285 }
286 printk("(%i)\n", names); 286 printk("(%i)\n", names);
287 return (struct stats) { names, space, 1 }; 287 return (struct stats) { names, space, 1 };
@@ -302,10 +302,10 @@ struct stats dx_show_entries(struct dx_hash_info *hinfo, struct inode *dir,
302 u32 range = i < count - 1? (dx_get_hash(entries + 1) - hash): ~hash; 302 u32 range = i < count - 1? (dx_get_hash(entries + 1) - hash): ~hash;
303 struct stats stats; 303 struct stats stats;
304 printk("%s%3u:%03u hash %8x/%8x ",levels?"":" ", i, block, hash, range); 304 printk("%s%3u:%03u hash %8x/%8x ",levels?"":" ", i, block, hash, range);
305 if (!(bh = ext3_bread (NULL,dir, block, 0,&err))) continue; 305 if (!(bh = ext4_bread (NULL,dir, block, 0,&err))) continue;
306 stats = levels? 306 stats = levels?
307 dx_show_entries(hinfo, dir, ((struct dx_node *) bh->b_data)->entries, levels - 1): 307 dx_show_entries(hinfo, dir, ((struct dx_node *) bh->b_data)->entries, levels - 1):
308 dx_show_leaf(hinfo, (struct ext3_dir_entry_2 *) bh->b_data, blocksize, 0); 308 dx_show_leaf(hinfo, (struct ext4_dir_entry_2 *) bh->b_data, blocksize, 0);
309 names += stats.names; 309 names += stats.names;
310 space += stats.space; 310 space += stats.space;
311 bcount += stats.bcount; 311 bcount += stats.bcount;
@@ -341,13 +341,13 @@ dx_probe(struct dentry *dentry, struct inode *dir,
341 frame->bh = NULL; 341 frame->bh = NULL;
342 if (dentry) 342 if (dentry)
343 dir = dentry->d_parent->d_inode; 343 dir = dentry->d_parent->d_inode;
344 if (!(bh = ext3_bread (NULL,dir, 0, 0, err))) 344 if (!(bh = ext4_bread (NULL,dir, 0, 0, err)))
345 goto fail; 345 goto fail;
346 root = (struct dx_root *) bh->b_data; 346 root = (struct dx_root *) bh->b_data;
347 if (root->info.hash_version != DX_HASH_TEA && 347 if (root->info.hash_version != DX_HASH_TEA &&
348 root->info.hash_version != DX_HASH_HALF_MD4 && 348 root->info.hash_version != DX_HASH_HALF_MD4 &&
349 root->info.hash_version != DX_HASH_LEGACY) { 349 root->info.hash_version != DX_HASH_LEGACY) {
350 ext3_warning(dir->i_sb, __FUNCTION__, 350 ext4_warning(dir->i_sb, __FUNCTION__,
351 "Unrecognised inode hash code %d", 351 "Unrecognised inode hash code %d",
352 root->info.hash_version); 352 root->info.hash_version);
353 brelse(bh); 353 brelse(bh);
@@ -355,13 +355,13 @@ dx_probe(struct dentry *dentry, struct inode *dir,
355 goto fail; 355 goto fail;
356 } 356 }
357 hinfo->hash_version = root->info.hash_version; 357 hinfo->hash_version = root->info.hash_version;
358 hinfo->seed = EXT3_SB(dir->i_sb)->s_hash_seed; 358 hinfo->seed = EXT4_SB(dir->i_sb)->s_hash_seed;
359 if (dentry) 359 if (dentry)
360 ext3fs_dirhash(dentry->d_name.name, dentry->d_name.len, hinfo); 360 ext4fs_dirhash(dentry->d_name.name, dentry->d_name.len, hinfo);
361 hash = hinfo->hash; 361 hash = hinfo->hash;
362 362
363 if (root->info.unused_flags & 1) { 363 if (root->info.unused_flags & 1) {
364 ext3_warning(dir->i_sb, __FUNCTION__, 364 ext4_warning(dir->i_sb, __FUNCTION__,
365 "Unimplemented inode hash flags: %#06x", 365 "Unimplemented inode hash flags: %#06x",
366 root->info.unused_flags); 366 root->info.unused_flags);
367 brelse(bh); 367 brelse(bh);
@@ -370,7 +370,7 @@ dx_probe(struct dentry *dentry, struct inode *dir,
370 } 370 }
371 371
372 if ((indirect = root->info.indirect_levels) > 1) { 372 if ((indirect = root->info.indirect_levels) > 1) {
373 ext3_warning(dir->i_sb, __FUNCTION__, 373 ext4_warning(dir->i_sb, __FUNCTION__,
374 "Unimplemented inode hash depth: %#06x", 374 "Unimplemented inode hash depth: %#06x",
375 root->info.indirect_levels); 375 root->info.indirect_levels);
376 brelse(bh); 376 brelse(bh);
@@ -421,7 +421,7 @@ dx_probe(struct dentry *dentry, struct inode *dir,
421 frame->entries = entries; 421 frame->entries = entries;
422 frame->at = at; 422 frame->at = at;
423 if (!indirect--) return frame; 423 if (!indirect--) return frame;
424 if (!(bh = ext3_bread (NULL,dir, dx_get_block(at), 0, err))) 424 if (!(bh = ext4_bread (NULL,dir, dx_get_block(at), 0, err)))
425 goto fail2; 425 goto fail2;
426 at = entries = ((struct dx_node *) bh->b_data)->entries; 426 at = entries = ((struct dx_node *) bh->b_data)->entries;
427 assert (dx_get_limit(entries) == dx_node_limit (dir)); 427 assert (dx_get_limit(entries) == dx_node_limit (dir));
@@ -463,7 +463,7 @@ static void dx_release (struct dx_frame *frames)
463 * If start_hash is non-null, it will be filled in with the starting 463 * If start_hash is non-null, it will be filled in with the starting
464 * hash of the next page. 464 * hash of the next page.
465 */ 465 */
466static int ext3_htree_next_block(struct inode *dir, __u32 hash, 466static int ext4_htree_next_block(struct inode *dir, __u32 hash,
467 struct dx_frame *frame, 467 struct dx_frame *frame,
468 struct dx_frame *frames, 468 struct dx_frame *frames,
469 __u32 *start_hash) 469 __u32 *start_hash)
@@ -509,7 +509,7 @@ static int ext3_htree_next_block(struct inode *dir, __u32 hash,
509 * block so no check is necessary 509 * block so no check is necessary
510 */ 510 */
511 while (num_frames--) { 511 while (num_frames--) {
512 if (!(bh = ext3_bread(NULL, dir, dx_get_block(p->at), 512 if (!(bh = ext4_bread(NULL, dir, dx_get_block(p->at),
513 0, &err))) 513 0, &err)))
514 return err; /* Failure */ 514 return err; /* Failure */
515 p++; 515 p++;
@@ -524,9 +524,9 @@ static int ext3_htree_next_block(struct inode *dir, __u32 hash,
524/* 524/*
525 * p is at least 6 bytes before the end of page 525 * p is at least 6 bytes before the end of page
526 */ 526 */
527static inline struct ext3_dir_entry_2 *ext3_next_entry(struct ext3_dir_entry_2 *p) 527static inline struct ext4_dir_entry_2 *ext4_next_entry(struct ext4_dir_entry_2 *p)
528{ 528{
529 return (struct ext3_dir_entry_2 *)((char*)p + le16_to_cpu(p->rec_len)); 529 return (struct ext4_dir_entry_2 *)((char*)p + le16_to_cpu(p->rec_len));
530} 530}
531 531
532/* 532/*
@@ -540,26 +540,26 @@ static int htree_dirblock_to_tree(struct file *dir_file,
540 __u32 start_hash, __u32 start_minor_hash) 540 __u32 start_hash, __u32 start_minor_hash)
541{ 541{
542 struct buffer_head *bh; 542 struct buffer_head *bh;
543 struct ext3_dir_entry_2 *de, *top; 543 struct ext4_dir_entry_2 *de, *top;
544 int err, count = 0; 544 int err, count = 0;
545 545
546 dxtrace(printk("In htree dirblock_to_tree: block %d\n", block)); 546 dxtrace(printk("In htree dirblock_to_tree: block %d\n", block));
547 if (!(bh = ext3_bread (NULL, dir, block, 0, &err))) 547 if (!(bh = ext4_bread (NULL, dir, block, 0, &err)))
548 return err; 548 return err;
549 549
550 de = (struct ext3_dir_entry_2 *) bh->b_data; 550 de = (struct ext4_dir_entry_2 *) bh->b_data;
551 top = (struct ext3_dir_entry_2 *) ((char *) de + 551 top = (struct ext4_dir_entry_2 *) ((char *) de +
552 dir->i_sb->s_blocksize - 552 dir->i_sb->s_blocksize -
553 EXT3_DIR_REC_LEN(0)); 553 EXT4_DIR_REC_LEN(0));
554 for (; de < top; de = ext3_next_entry(de)) { 554 for (; de < top; de = ext4_next_entry(de)) {
555 ext3fs_dirhash(de->name, de->name_len, hinfo); 555 ext4fs_dirhash(de->name, de->name_len, hinfo);
556 if ((hinfo->hash < start_hash) || 556 if ((hinfo->hash < start_hash) ||
557 ((hinfo->hash == start_hash) && 557 ((hinfo->hash == start_hash) &&
558 (hinfo->minor_hash < start_minor_hash))) 558 (hinfo->minor_hash < start_minor_hash)))
559 continue; 559 continue;
560 if (de->inode == 0) 560 if (de->inode == 0)
561 continue; 561 continue;
562 if ((err = ext3_htree_store_dirent(dir_file, 562 if ((err = ext4_htree_store_dirent(dir_file,
563 hinfo->hash, hinfo->minor_hash, de)) != 0) { 563 hinfo->hash, hinfo->minor_hash, de)) != 0) {
564 brelse(bh); 564 brelse(bh);
565 return err; 565 return err;
@@ -579,11 +579,11 @@ static int htree_dirblock_to_tree(struct file *dir_file,
579 * This function returns the number of entries inserted into the tree, 579 * This function returns the number of entries inserted into the tree,
580 * or a negative error code. 580 * or a negative error code.
581 */ 581 */
582int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash, 582int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
583 __u32 start_minor_hash, __u32 *next_hash) 583 __u32 start_minor_hash, __u32 *next_hash)
584{ 584{
585 struct dx_hash_info hinfo; 585 struct dx_hash_info hinfo;
586 struct ext3_dir_entry_2 *de; 586 struct ext4_dir_entry_2 *de;
587 struct dx_frame frames[2], *frame; 587 struct dx_frame frames[2], *frame;
588 struct inode *dir; 588 struct inode *dir;
589 int block, err; 589 int block, err;
@@ -594,9 +594,9 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
594 dxtrace(printk("In htree_fill_tree, start hash: %x:%x\n", start_hash, 594 dxtrace(printk("In htree_fill_tree, start hash: %x:%x\n", start_hash,
595 start_minor_hash)); 595 start_minor_hash));
596 dir = dir_file->f_dentry->d_inode; 596 dir = dir_file->f_dentry->d_inode;
597 if (!(EXT3_I(dir)->i_flags & EXT3_INDEX_FL)) { 597 if (!(EXT4_I(dir)->i_flags & EXT4_INDEX_FL)) {
598 hinfo.hash_version = EXT3_SB(dir->i_sb)->s_def_hash_version; 598 hinfo.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
599 hinfo.seed = EXT3_SB(dir->i_sb)->s_hash_seed; 599 hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
600 count = htree_dirblock_to_tree(dir_file, dir, 0, &hinfo, 600 count = htree_dirblock_to_tree(dir_file, dir, 0, &hinfo,
601 start_hash, start_minor_hash); 601 start_hash, start_minor_hash);
602 *next_hash = ~0; 602 *next_hash = ~0;
@@ -610,15 +610,15 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
610 610
611 /* Add '.' and '..' from the htree header */ 611 /* Add '.' and '..' from the htree header */
612 if (!start_hash && !start_minor_hash) { 612 if (!start_hash && !start_minor_hash) {
613 de = (struct ext3_dir_entry_2 *) frames[0].bh->b_data; 613 de = (struct ext4_dir_entry_2 *) frames[0].bh->b_data;
614 if ((err = ext3_htree_store_dirent(dir_file, 0, 0, de)) != 0) 614 if ((err = ext4_htree_store_dirent(dir_file, 0, 0, de)) != 0)
615 goto errout; 615 goto errout;
616 count++; 616 count++;
617 } 617 }
618 if (start_hash < 2 || (start_hash ==2 && start_minor_hash==0)) { 618 if (start_hash < 2 || (start_hash ==2 && start_minor_hash==0)) {
619 de = (struct ext3_dir_entry_2 *) frames[0].bh->b_data; 619 de = (struct ext4_dir_entry_2 *) frames[0].bh->b_data;
620 de = ext3_next_entry(de); 620 de = ext4_next_entry(de);
621 if ((err = ext3_htree_store_dirent(dir_file, 2, 0, de)) != 0) 621 if ((err = ext4_htree_store_dirent(dir_file, 2, 0, de)) != 0)
622 goto errout; 622 goto errout;
623 count++; 623 count++;
624 } 624 }
@@ -633,7 +633,7 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
633 } 633 }
634 count += ret; 634 count += ret;
635 hashval = ~0; 635 hashval = ~0;
636 ret = ext3_htree_next_block(dir, HASH_NB_ALWAYS, 636 ret = ext4_htree_next_block(dir, HASH_NB_ALWAYS,
637 frame, frames, &hashval); 637 frame, frames, &hashval);
638 *next_hash = hashval; 638 *next_hash = hashval;
639 if (ret < 0) { 639 if (ret < 0) {
@@ -663,7 +663,7 @@ errout:
663 * Directory block splitting, compacting 663 * Directory block splitting, compacting
664 */ 664 */
665 665
666static int dx_make_map (struct ext3_dir_entry_2 *de, int size, 666static int dx_make_map (struct ext4_dir_entry_2 *de, int size,
667 struct dx_hash_info *hinfo, struct dx_map_entry *map_tail) 667 struct dx_hash_info *hinfo, struct dx_map_entry *map_tail)
668{ 668{
669 int count = 0; 669 int count = 0;
@@ -673,7 +673,7 @@ static int dx_make_map (struct ext3_dir_entry_2 *de, int size,
673 while ((char *) de < base + size) 673 while ((char *) de < base + size)
674 { 674 {
675 if (de->name_len && de->inode) { 675 if (de->name_len && de->inode) {
676 ext3fs_dirhash(de->name, de->name_len, &h); 676 ext4fs_dirhash(de->name, de->name_len, &h);
677 map_tail--; 677 map_tail--;
678 map_tail->hash = h.hash; 678 map_tail->hash = h.hash;
679 map_tail->offs = (u32) ((char *) de - base); 679 map_tail->offs = (u32) ((char *) de - base);
@@ -681,7 +681,7 @@ static int dx_make_map (struct ext3_dir_entry_2 *de, int size,
681 cond_resched(); 681 cond_resched();
682 } 682 }
683 /* XXX: do we need to check rec_len == 0 case? -Chris */ 683 /* XXX: do we need to check rec_len == 0 case? -Chris */
684 de = (struct ext3_dir_entry_2 *) ((char *) de + le16_to_cpu(de->rec_len)); 684 de = (struct ext4_dir_entry_2 *) ((char *) de + le16_to_cpu(de->rec_len));
685 } 685 }
686 return count; 686 return count;
687} 687}
@@ -730,21 +730,21 @@ static void dx_insert_block(struct dx_frame *frame, u32 hash, u32 block)
730#endif 730#endif
731 731
732 732
733static void ext3_update_dx_flag(struct inode *inode) 733static void ext4_update_dx_flag(struct inode *inode)
734{ 734{
735 if (!EXT3_HAS_COMPAT_FEATURE(inode->i_sb, 735 if (!EXT4_HAS_COMPAT_FEATURE(inode->i_sb,
736 EXT3_FEATURE_COMPAT_DIR_INDEX)) 736 EXT4_FEATURE_COMPAT_DIR_INDEX))
737 EXT3_I(inode)->i_flags &= ~EXT3_INDEX_FL; 737 EXT4_I(inode)->i_flags &= ~EXT4_INDEX_FL;
738} 738}
739 739
740/* 740/*
741 * NOTE! unlike strncmp, ext3_match returns 1 for success, 0 for failure. 741 * NOTE! unlike strncmp, ext4_match returns 1 for success, 0 for failure.
742 * 742 *
743 * `len <= EXT3_NAME_LEN' is guaranteed by caller. 743 * `len <= EXT4_NAME_LEN' is guaranteed by caller.
744 * `de != NULL' is guaranteed by caller. 744 * `de != NULL' is guaranteed by caller.
745 */ 745 */
746static inline int ext3_match (int len, const char * const name, 746static inline int ext4_match (int len, const char * const name,
747 struct ext3_dir_entry_2 * de) 747 struct ext4_dir_entry_2 * de)
748{ 748{
749 if (len != de->name_len) 749 if (len != de->name_len)
750 return 0; 750 return 0;
@@ -760,24 +760,24 @@ static inline int search_dirblock(struct buffer_head * bh,
760 struct inode *dir, 760 struct inode *dir,
761 struct dentry *dentry, 761 struct dentry *dentry,
762 unsigned long offset, 762 unsigned long offset,
763 struct ext3_dir_entry_2 ** res_dir) 763 struct ext4_dir_entry_2 ** res_dir)
764{ 764{
765 struct ext3_dir_entry_2 * de; 765 struct ext4_dir_entry_2 * de;
766 char * dlimit; 766 char * dlimit;
767 int de_len; 767 int de_len;
768 const char *name = dentry->d_name.name; 768 const char *name = dentry->d_name.name;
769 int namelen = dentry->d_name.len; 769 int namelen = dentry->d_name.len;
770 770
771 de = (struct ext3_dir_entry_2 *) bh->b_data; 771 de = (struct ext4_dir_entry_2 *) bh->b_data;
772 dlimit = bh->b_data + dir->i_sb->s_blocksize; 772 dlimit = bh->b_data + dir->i_sb->s_blocksize;
773 while ((char *) de < dlimit) { 773 while ((char *) de < dlimit) {
774 /* this code is executed quadratically often */ 774 /* this code is executed quadratically often */
775 /* do minimal checking `by hand' */ 775 /* do minimal checking `by hand' */
776 776
777 if ((char *) de + namelen <= dlimit && 777 if ((char *) de + namelen <= dlimit &&
778 ext3_match (namelen, name, de)) { 778 ext4_match (namelen, name, de)) {
779 /* found a match - just to be sure, do a full check */ 779 /* found a match - just to be sure, do a full check */
780 if (!ext3_check_dir_entry("ext3_find_entry", 780 if (!ext4_check_dir_entry("ext4_find_entry",
781 dir, de, bh, offset)) 781 dir, de, bh, offset))
782 return -1; 782 return -1;
783 *res_dir = de; 783 *res_dir = de;
@@ -788,14 +788,14 @@ static inline int search_dirblock(struct buffer_head * bh,
788 if (de_len <= 0) 788 if (de_len <= 0)
789 return -1; 789 return -1;
790 offset += de_len; 790 offset += de_len;
791 de = (struct ext3_dir_entry_2 *) ((char *) de + de_len); 791 de = (struct ext4_dir_entry_2 *) ((char *) de + de_len);
792 } 792 }
793 return 0; 793 return 0;
794} 794}
795 795
796 796
797/* 797/*
798 * ext3_find_entry() 798 * ext4_find_entry()
799 * 799 *
800 * finds an entry in the specified directory with the wanted name. It 800 * finds an entry in the specified directory with the wanted name. It
801 * returns the cache buffer in which the entry was found, and the entry 801 * returns the cache buffer in which the entry was found, and the entry
@@ -805,8 +805,8 @@ static inline int search_dirblock(struct buffer_head * bh,
805 * The returned buffer_head has ->b_count elevated. The caller is expected 805 * The returned buffer_head has ->b_count elevated. The caller is expected
806 * to brelse() it when appropriate. 806 * to brelse() it when appropriate.
807 */ 807 */
808static struct buffer_head * ext3_find_entry (struct dentry *dentry, 808static struct buffer_head * ext4_find_entry (struct dentry *dentry,
809 struct ext3_dir_entry_2 ** res_dir) 809 struct ext4_dir_entry_2 ** res_dir)
810{ 810{
811 struct super_block * sb; 811 struct super_block * sb;
812 struct buffer_head * bh_use[NAMEI_RA_SIZE]; 812 struct buffer_head * bh_use[NAMEI_RA_SIZE];
@@ -828,11 +828,11 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry,
828 blocksize = sb->s_blocksize; 828 blocksize = sb->s_blocksize;
829 namelen = dentry->d_name.len; 829 namelen = dentry->d_name.len;
830 name = dentry->d_name.name; 830 name = dentry->d_name.name;
831 if (namelen > EXT3_NAME_LEN) 831 if (namelen > EXT4_NAME_LEN)
832 return NULL; 832 return NULL;
833#ifdef CONFIG_EXT3_INDEX 833#ifdef CONFIG_EXT4_INDEX
834 if (is_dx(dir)) { 834 if (is_dx(dir)) {
835 bh = ext3_dx_find_entry(dentry, res_dir, &err); 835 bh = ext4_dx_find_entry(dentry, res_dir, &err);
836 /* 836 /*
837 * On success, or if the error was file not found, 837 * On success, or if the error was file not found,
838 * return. Otherwise, fall back to doing a search the 838 * return. Otherwise, fall back to doing a search the
@@ -840,11 +840,11 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry,
840 */ 840 */
841 if (bh || (err != ERR_BAD_DX_DIR)) 841 if (bh || (err != ERR_BAD_DX_DIR))
842 return bh; 842 return bh;
843 dxtrace(printk("ext3_find_entry: dx failed, falling back\n")); 843 dxtrace(printk("ext4_find_entry: dx failed, falling back\n"));
844 } 844 }
845#endif 845#endif
846 nblocks = dir->i_size >> EXT3_BLOCK_SIZE_BITS(sb); 846 nblocks = dir->i_size >> EXT4_BLOCK_SIZE_BITS(sb);
847 start = EXT3_I(dir)->i_dir_start_lookup; 847 start = EXT4_I(dir)->i_dir_start_lookup;
848 if (start >= nblocks) 848 if (start >= nblocks)
849 start = 0; 849 start = 0;
850 block = start; 850 block = start;
@@ -868,7 +868,7 @@ restart:
868 break; 868 break;
869 } 869 }
870 num++; 870 num++;
871 bh = ext3_getblk(NULL, dir, b++, 0, &err); 871 bh = ext4_getblk(NULL, dir, b++, 0, &err);
872 bh_use[ra_max] = bh; 872 bh_use[ra_max] = bh;
873 if (bh) 873 if (bh)
874 ll_rw_block(READ_META, 1, &bh); 874 ll_rw_block(READ_META, 1, &bh);
@@ -879,15 +879,15 @@ restart:
879 wait_on_buffer(bh); 879 wait_on_buffer(bh);
880 if (!buffer_uptodate(bh)) { 880 if (!buffer_uptodate(bh)) {
881 /* read error, skip block & hope for the best */ 881 /* read error, skip block & hope for the best */
882 ext3_error(sb, __FUNCTION__, "reading directory #%lu " 882 ext4_error(sb, __FUNCTION__, "reading directory #%lu "
883 "offset %lu", dir->i_ino, block); 883 "offset %lu", dir->i_ino, block);
884 brelse(bh); 884 brelse(bh);
885 goto next; 885 goto next;
886 } 886 }
887 i = search_dirblock(bh, dir, dentry, 887 i = search_dirblock(bh, dir, dentry,
888 block << EXT3_BLOCK_SIZE_BITS(sb), res_dir); 888 block << EXT4_BLOCK_SIZE_BITS(sb), res_dir);
889 if (i == 1) { 889 if (i == 1) {
890 EXT3_I(dir)->i_dir_start_lookup = block; 890 EXT4_I(dir)->i_dir_start_lookup = block;
891 ret = bh; 891 ret = bh;
892 goto cleanup_and_exit; 892 goto cleanup_and_exit;
893 } else { 893 } else {
@@ -905,7 +905,7 @@ restart:
905 * search the last part of the directory before giving up. 905 * search the last part of the directory before giving up.
906 */ 906 */
907 block = nblocks; 907 block = nblocks;
908 nblocks = dir->i_size >> EXT3_BLOCK_SIZE_BITS(sb); 908 nblocks = dir->i_size >> EXT4_BLOCK_SIZE_BITS(sb);
909 if (block < nblocks) { 909 if (block < nblocks) {
910 start = 0; 910 start = 0;
911 goto restart; 911 goto restart;
@@ -918,15 +918,15 @@ cleanup_and_exit:
918 return ret; 918 return ret;
919} 919}
920 920
921#ifdef CONFIG_EXT3_INDEX 921#ifdef CONFIG_EXT4_INDEX
922static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry, 922static struct buffer_head * ext4_dx_find_entry(struct dentry *dentry,
923 struct ext3_dir_entry_2 **res_dir, int *err) 923 struct ext4_dir_entry_2 **res_dir, int *err)
924{ 924{
925 struct super_block * sb; 925 struct super_block * sb;
926 struct dx_hash_info hinfo; 926 struct dx_hash_info hinfo;
927 u32 hash; 927 u32 hash;
928 struct dx_frame frames[2], *frame; 928 struct dx_frame frames[2], *frame;
929 struct ext3_dir_entry_2 *de, *top; 929 struct ext4_dir_entry_2 *de, *top;
930 struct buffer_head *bh; 930 struct buffer_head *bh;
931 unsigned long block; 931 unsigned long block;
932 int retval; 932 int retval;
@@ -948,16 +948,16 @@ static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry,
948 hash = hinfo.hash; 948 hash = hinfo.hash;
949 do { 949 do {
950 block = dx_get_block(frame->at); 950 block = dx_get_block(frame->at);
951 if (!(bh = ext3_bread (NULL,dir, block, 0, err))) 951 if (!(bh = ext4_bread (NULL,dir, block, 0, err)))
952 goto errout; 952 goto errout;
953 de = (struct ext3_dir_entry_2 *) bh->b_data; 953 de = (struct ext4_dir_entry_2 *) bh->b_data;
954 top = (struct ext3_dir_entry_2 *) ((char *) de + sb->s_blocksize - 954 top = (struct ext4_dir_entry_2 *) ((char *) de + sb->s_blocksize -
955 EXT3_DIR_REC_LEN(0)); 955 EXT4_DIR_REC_LEN(0));
956 for (; de < top; de = ext3_next_entry(de)) 956 for (; de < top; de = ext4_next_entry(de))
957 if (ext3_match (namelen, name, de)) { 957 if (ext4_match (namelen, name, de)) {
958 if (!ext3_check_dir_entry("ext3_find_entry", 958 if (!ext4_check_dir_entry("ext4_find_entry",
959 dir, de, bh, 959 dir, de, bh,
960 (block<<EXT3_BLOCK_SIZE_BITS(sb)) 960 (block<<EXT4_BLOCK_SIZE_BITS(sb))
961 +((char *)de - bh->b_data))) { 961 +((char *)de - bh->b_data))) {
962 brelse (bh); 962 brelse (bh);
963 goto errout; 963 goto errout;
@@ -968,10 +968,10 @@ static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry,
968 } 968 }
969 brelse (bh); 969 brelse (bh);
970 /* Check to see if we should continue to search */ 970 /* Check to see if we should continue to search */
971 retval = ext3_htree_next_block(dir, hash, frame, 971 retval = ext4_htree_next_block(dir, hash, frame,
972 frames, NULL); 972 frames, NULL);
973 if (retval < 0) { 973 if (retval < 0) {
974 ext3_warning(sb, __FUNCTION__, 974 ext4_warning(sb, __FUNCTION__,
975 "error reading index page in directory #%lu", 975 "error reading index page in directory #%lu",
976 dir->i_ino); 976 dir->i_ino);
977 *err = retval; 977 *err = retval;
@@ -987,22 +987,22 @@ errout:
987} 987}
988#endif 988#endif
989 989
990static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd) 990static struct dentry *ext4_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
991{ 991{
992 struct inode * inode; 992 struct inode * inode;
993 struct ext3_dir_entry_2 * de; 993 struct ext4_dir_entry_2 * de;
994 struct buffer_head * bh; 994 struct buffer_head * bh;
995 995
996 if (dentry->d_name.len > EXT3_NAME_LEN) 996 if (dentry->d_name.len > EXT4_NAME_LEN)
997 return ERR_PTR(-ENAMETOOLONG); 997 return ERR_PTR(-ENAMETOOLONG);
998 998
999 bh = ext3_find_entry(dentry, &de); 999 bh = ext4_find_entry(dentry, &de);
1000 inode = NULL; 1000 inode = NULL;
1001 if (bh) { 1001 if (bh) {
1002 unsigned long ino = le32_to_cpu(de->inode); 1002 unsigned long ino = le32_to_cpu(de->inode);
1003 brelse (bh); 1003 brelse (bh);
1004 if (!ext3_valid_inum(dir->i_sb, ino)) { 1004 if (!ext4_valid_inum(dir->i_sb, ino)) {
1005 ext3_error(dir->i_sb, "ext3_lookup", 1005 ext4_error(dir->i_sb, "ext4_lookup",
1006 "bad inode number: %lu", ino); 1006 "bad inode number: %lu", ino);
1007 inode = NULL; 1007 inode = NULL;
1008 } else 1008 } else
@@ -1015,28 +1015,28 @@ static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, str
1015} 1015}
1016 1016
1017 1017
1018struct dentry *ext3_get_parent(struct dentry *child) 1018struct dentry *ext4_get_parent(struct dentry *child)
1019{ 1019{
1020 unsigned long ino; 1020 unsigned long ino;
1021 struct dentry *parent; 1021 struct dentry *parent;
1022 struct inode *inode; 1022 struct inode *inode;
1023 struct dentry dotdot; 1023 struct dentry dotdot;
1024 struct ext3_dir_entry_2 * de; 1024 struct ext4_dir_entry_2 * de;
1025 struct buffer_head *bh; 1025 struct buffer_head *bh;
1026 1026
1027 dotdot.d_name.name = ".."; 1027 dotdot.d_name.name = "..";
1028 dotdot.d_name.len = 2; 1028 dotdot.d_name.len = 2;
1029 dotdot.d_parent = child; /* confusing, isn't it! */ 1029 dotdot.d_parent = child; /* confusing, isn't it! */
1030 1030
1031 bh = ext3_find_entry(&dotdot, &de); 1031 bh = ext4_find_entry(&dotdot, &de);
1032 inode = NULL; 1032 inode = NULL;
1033 if (!bh) 1033 if (!bh)
1034 return ERR_PTR(-ENOENT); 1034 return ERR_PTR(-ENOENT);
1035 ino = le32_to_cpu(de->inode); 1035 ino = le32_to_cpu(de->inode);
1036 brelse(bh); 1036 brelse(bh);
1037 1037
1038 if (!ext3_valid_inum(child->d_inode->i_sb, ino)) { 1038 if (!ext4_valid_inum(child->d_inode->i_sb, ino)) {
1039 ext3_error(child->d_inode->i_sb, "ext3_get_parent", 1039 ext4_error(child->d_inode->i_sb, "ext4_get_parent",
1040 "bad inode number: %lu", ino); 1040 "bad inode number: %lu", ino);
1041 inode = NULL; 1041 inode = NULL;
1042 } else 1042 } else
@@ -1054,65 +1054,65 @@ struct dentry *ext3_get_parent(struct dentry *child)
1054} 1054}
1055 1055
1056#define S_SHIFT 12 1056#define S_SHIFT 12
1057static unsigned char ext3_type_by_mode[S_IFMT >> S_SHIFT] = { 1057static unsigned char ext4_type_by_mode[S_IFMT >> S_SHIFT] = {
1058 [S_IFREG >> S_SHIFT] = EXT3_FT_REG_FILE, 1058 [S_IFREG >> S_SHIFT] = EXT4_FT_REG_FILE,
1059 [S_IFDIR >> S_SHIFT] = EXT3_FT_DIR, 1059 [S_IFDIR >> S_SHIFT] = EXT4_FT_DIR,
1060 [S_IFCHR >> S_SHIFT] = EXT3_FT_CHRDEV, 1060 [S_IFCHR >> S_SHIFT] = EXT4_FT_CHRDEV,
1061 [S_IFBLK >> S_SHIFT] = EXT3_FT_BLKDEV, 1061 [S_IFBLK >> S_SHIFT] = EXT4_FT_BLKDEV,
1062 [S_IFIFO >> S_SHIFT] = EXT3_FT_FIFO, 1062 [S_IFIFO >> S_SHIFT] = EXT4_FT_FIFO,
1063 [S_IFSOCK >> S_SHIFT] = EXT3_FT_SOCK, 1063 [S_IFSOCK >> S_SHIFT] = EXT4_FT_SOCK,
1064 [S_IFLNK >> S_SHIFT] = EXT3_FT_SYMLINK, 1064 [S_IFLNK >> S_SHIFT] = EXT4_FT_SYMLINK,
1065}; 1065};
1066 1066
1067static inline void ext3_set_de_type(struct super_block *sb, 1067static inline void ext4_set_de_type(struct super_block *sb,
1068 struct ext3_dir_entry_2 *de, 1068 struct ext4_dir_entry_2 *de,
1069 umode_t mode) { 1069 umode_t mode) {
1070 if (EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_FILETYPE)) 1070 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FILETYPE))
1071 de->file_type = ext3_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; 1071 de->file_type = ext4_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1072} 1072}
1073 1073
1074#ifdef CONFIG_EXT3_INDEX 1074#ifdef CONFIG_EXT4_INDEX
1075static struct ext3_dir_entry_2 * 1075static struct ext4_dir_entry_2 *
1076dx_move_dirents(char *from, char *to, struct dx_map_entry *map, int count) 1076dx_move_dirents(char *from, char *to, struct dx_map_entry *map, int count)
1077{ 1077{
1078 unsigned rec_len = 0; 1078 unsigned rec_len = 0;
1079 1079
1080 while (count--) { 1080 while (count--) {
1081 struct ext3_dir_entry_2 *de = (struct ext3_dir_entry_2 *) (from + map->offs); 1081 struct ext4_dir_entry_2 *de = (struct ext4_dir_entry_2 *) (from + map->offs);
1082 rec_len = EXT3_DIR_REC_LEN(de->name_len); 1082 rec_len = EXT4_DIR_REC_LEN(de->name_len);
1083 memcpy (to, de, rec_len); 1083 memcpy (to, de, rec_len);
1084 ((struct ext3_dir_entry_2 *) to)->rec_len = 1084 ((struct ext4_dir_entry_2 *) to)->rec_len =
1085 cpu_to_le16(rec_len); 1085 cpu_to_le16(rec_len);
1086 de->inode = 0; 1086 de->inode = 0;
1087 map++; 1087 map++;
1088 to += rec_len; 1088 to += rec_len;
1089 } 1089 }
1090 return (struct ext3_dir_entry_2 *) (to - rec_len); 1090 return (struct ext4_dir_entry_2 *) (to - rec_len);
1091} 1091}
1092 1092
1093static struct ext3_dir_entry_2* dx_pack_dirents(char *base, int size) 1093static struct ext4_dir_entry_2* dx_pack_dirents(char *base, int size)
1094{ 1094{
1095 struct ext3_dir_entry_2 *next, *to, *prev, *de = (struct ext3_dir_entry_2 *) base; 1095 struct ext4_dir_entry_2 *next, *to, *prev, *de = (struct ext4_dir_entry_2 *) base;
1096 unsigned rec_len = 0; 1096 unsigned rec_len = 0;
1097 1097
1098 prev = to = de; 1098 prev = to = de;
1099 while ((char*)de < base + size) { 1099 while ((char*)de < base + size) {
1100 next = (struct ext3_dir_entry_2 *) ((char *) de + 1100 next = (struct ext4_dir_entry_2 *) ((char *) de +
1101 le16_to_cpu(de->rec_len)); 1101 le16_to_cpu(de->rec_len));
1102 if (de->inode && de->name_len) { 1102 if (de->inode && de->name_len) {
1103 rec_len = EXT3_DIR_REC_LEN(de->name_len); 1103 rec_len = EXT4_DIR_REC_LEN(de->name_len);
1104 if (de > to) 1104 if (de > to)
1105 memmove(to, de, rec_len); 1105 memmove(to, de, rec_len);
1106 to->rec_len = cpu_to_le16(rec_len); 1106 to->rec_len = cpu_to_le16(rec_len);
1107 prev = to; 1107 prev = to;
1108 to = (struct ext3_dir_entry_2 *) (((char *) to) + rec_len); 1108 to = (struct ext4_dir_entry_2 *) (((char *) to) + rec_len);
1109 } 1109 }
1110 de = next; 1110 de = next;
1111 } 1111 }
1112 return prev; 1112 return prev;
1113} 1113}
1114 1114
1115static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir, 1115static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
1116 struct buffer_head **bh,struct dx_frame *frame, 1116 struct buffer_head **bh,struct dx_frame *frame,
1117 struct dx_hash_info *hinfo, int *error) 1117 struct dx_hash_info *hinfo, int *error)
1118{ 1118{
@@ -1124,10 +1124,10 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
1124 struct dx_map_entry *map; 1124 struct dx_map_entry *map;
1125 char *data1 = (*bh)->b_data, *data2; 1125 char *data1 = (*bh)->b_data, *data2;
1126 unsigned split; 1126 unsigned split;
1127 struct ext3_dir_entry_2 *de = NULL, *de2; 1127 struct ext4_dir_entry_2 *de = NULL, *de2;
1128 int err; 1128 int err;
1129 1129
1130 bh2 = ext3_append (handle, dir, &newblock, error); 1130 bh2 = ext4_append (handle, dir, &newblock, error);
1131 if (!(bh2)) { 1131 if (!(bh2)) {
1132 brelse(*bh); 1132 brelse(*bh);
1133 *bh = NULL; 1133 *bh = NULL;
@@ -1135,17 +1135,17 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
1135 } 1135 }
1136 1136
1137 BUFFER_TRACE(*bh, "get_write_access"); 1137 BUFFER_TRACE(*bh, "get_write_access");
1138 err = ext3_journal_get_write_access(handle, *bh); 1138 err = ext4_journal_get_write_access(handle, *bh);
1139 if (err) { 1139 if (err) {
1140 journal_error: 1140 journal_error:
1141 brelse(*bh); 1141 brelse(*bh);
1142 brelse(bh2); 1142 brelse(bh2);
1143 *bh = NULL; 1143 *bh = NULL;
1144 ext3_std_error(dir->i_sb, err); 1144 ext4_std_error(dir->i_sb, err);
1145 goto errout; 1145 goto errout;
1146 } 1146 }
1147 BUFFER_TRACE(frame->bh, "get_write_access"); 1147 BUFFER_TRACE(frame->bh, "get_write_access");
1148 err = ext3_journal_get_write_access(handle, frame->bh); 1148 err = ext4_journal_get_write_access(handle, frame->bh);
1149 if (err) 1149 if (err)
1150 goto journal_error; 1150 goto journal_error;
1151 1151
@@ -1153,7 +1153,7 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
1153 1153
1154 /* create map in the end of data2 block */ 1154 /* create map in the end of data2 block */
1155 map = (struct dx_map_entry *) (data2 + blocksize); 1155 map = (struct dx_map_entry *) (data2 + blocksize);
1156 count = dx_make_map ((struct ext3_dir_entry_2 *) data1, 1156 count = dx_make_map ((struct ext4_dir_entry_2 *) data1,
1157 blocksize, hinfo, map); 1157 blocksize, hinfo, map);
1158 map -= count; 1158 map -= count;
1159 split = count/2; // need to adjust to actual middle 1159 split = count/2; // need to adjust to actual middle
@@ -1168,8 +1168,8 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
1168 de = dx_pack_dirents(data1,blocksize); 1168 de = dx_pack_dirents(data1,blocksize);
1169 de->rec_len = cpu_to_le16(data1 + blocksize - (char *) de); 1169 de->rec_len = cpu_to_le16(data1 + blocksize - (char *) de);
1170 de2->rec_len = cpu_to_le16(data2 + blocksize - (char *) de2); 1170 de2->rec_len = cpu_to_le16(data2 + blocksize - (char *) de2);
1171 dxtrace(dx_show_leaf (hinfo, (struct ext3_dir_entry_2 *) data1, blocksize, 1)); 1171 dxtrace(dx_show_leaf (hinfo, (struct ext4_dir_entry_2 *) data1, blocksize, 1));
1172 dxtrace(dx_show_leaf (hinfo, (struct ext3_dir_entry_2 *) data2, blocksize, 1)); 1172 dxtrace(dx_show_leaf (hinfo, (struct ext4_dir_entry_2 *) data2, blocksize, 1));
1173 1173
1174 /* Which block gets the new entry? */ 1174 /* Which block gets the new entry? */
1175 if (hinfo->hash >= hash2) 1175 if (hinfo->hash >= hash2)
@@ -1178,10 +1178,10 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
1178 de = de2; 1178 de = de2;
1179 } 1179 }
1180 dx_insert_block (frame, hash2 + continued, newblock); 1180 dx_insert_block (frame, hash2 + continued, newblock);
1181 err = ext3_journal_dirty_metadata (handle, bh2); 1181 err = ext4_journal_dirty_metadata (handle, bh2);
1182 if (err) 1182 if (err)
1183 goto journal_error; 1183 goto journal_error;
1184 err = ext3_journal_dirty_metadata (handle, frame->bh); 1184 err = ext4_journal_dirty_metadata (handle, frame->bh);
1185 if (err) 1185 if (err)
1186 goto journal_error; 1186 goto journal_error;
1187 brelse (bh2); 1187 brelse (bh2);
@@ -1204,7 +1204,7 @@ errout:
1204 * all other cases bh is released. 1204 * all other cases bh is released.
1205 */ 1205 */
1206static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry, 1206static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1207 struct inode *inode, struct ext3_dir_entry_2 *de, 1207 struct inode *inode, struct ext4_dir_entry_2 *de,
1208 struct buffer_head * bh) 1208 struct buffer_head * bh)
1209{ 1209{
1210 struct inode *dir = dentry->d_parent->d_inode; 1210 struct inode *dir = dentry->d_parent->d_inode;
@@ -1215,51 +1215,51 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1215 int nlen, rlen, err; 1215 int nlen, rlen, err;
1216 char *top; 1216 char *top;
1217 1217
1218 reclen = EXT3_DIR_REC_LEN(namelen); 1218 reclen = EXT4_DIR_REC_LEN(namelen);
1219 if (!de) { 1219 if (!de) {
1220 de = (struct ext3_dir_entry_2 *)bh->b_data; 1220 de = (struct ext4_dir_entry_2 *)bh->b_data;
1221 top = bh->b_data + dir->i_sb->s_blocksize - reclen; 1221 top = bh->b_data + dir->i_sb->s_blocksize - reclen;
1222 while ((char *) de <= top) { 1222 while ((char *) de <= top) {
1223 if (!ext3_check_dir_entry("ext3_add_entry", dir, de, 1223 if (!ext4_check_dir_entry("ext4_add_entry", dir, de,
1224 bh, offset)) { 1224 bh, offset)) {
1225 brelse (bh); 1225 brelse (bh);
1226 return -EIO; 1226 return -EIO;
1227 } 1227 }
1228 if (ext3_match (namelen, name, de)) { 1228 if (ext4_match (namelen, name, de)) {
1229 brelse (bh); 1229 brelse (bh);
1230 return -EEXIST; 1230 return -EEXIST;
1231 } 1231 }
1232 nlen = EXT3_DIR_REC_LEN(de->name_len); 1232 nlen = EXT4_DIR_REC_LEN(de->name_len);
1233 rlen = le16_to_cpu(de->rec_len); 1233 rlen = le16_to_cpu(de->rec_len);
1234 if ((de->inode? rlen - nlen: rlen) >= reclen) 1234 if ((de->inode? rlen - nlen: rlen) >= reclen)
1235 break; 1235 break;
1236 de = (struct ext3_dir_entry_2 *)((char *)de + rlen); 1236 de = (struct ext4_dir_entry_2 *)((char *)de + rlen);
1237 offset += rlen; 1237 offset += rlen;
1238 } 1238 }
1239 if ((char *) de > top) 1239 if ((char *) de > top)
1240 return -ENOSPC; 1240 return -ENOSPC;
1241 } 1241 }
1242 BUFFER_TRACE(bh, "get_write_access"); 1242 BUFFER_TRACE(bh, "get_write_access");
1243 err = ext3_journal_get_write_access(handle, bh); 1243 err = ext4_journal_get_write_access(handle, bh);
1244 if (err) { 1244 if (err) {
1245 ext3_std_error(dir->i_sb, err); 1245 ext4_std_error(dir->i_sb, err);
1246 brelse(bh); 1246 brelse(bh);
1247 return err; 1247 return err;
1248 } 1248 }
1249 1249
1250 /* By now the buffer is marked for journaling */ 1250 /* By now the buffer is marked for journaling */
1251 nlen = EXT3_DIR_REC_LEN(de->name_len); 1251 nlen = EXT4_DIR_REC_LEN(de->name_len);
1252 rlen = le16_to_cpu(de->rec_len); 1252 rlen = le16_to_cpu(de->rec_len);
1253 if (de->inode) { 1253 if (de->inode) {
1254 struct ext3_dir_entry_2 *de1 = (struct ext3_dir_entry_2 *)((char *)de + nlen); 1254 struct ext4_dir_entry_2 *de1 = (struct ext4_dir_entry_2 *)((char *)de + nlen);
1255 de1->rec_len = cpu_to_le16(rlen - nlen); 1255 de1->rec_len = cpu_to_le16(rlen - nlen);
1256 de->rec_len = cpu_to_le16(nlen); 1256 de->rec_len = cpu_to_le16(nlen);
1257 de = de1; 1257 de = de1;
1258 } 1258 }
1259 de->file_type = EXT3_FT_UNKNOWN; 1259 de->file_type = EXT4_FT_UNKNOWN;
1260 if (inode) { 1260 if (inode) {
1261 de->inode = cpu_to_le32(inode->i_ino); 1261 de->inode = cpu_to_le32(inode->i_ino);
1262 ext3_set_de_type(dir->i_sb, de, inode->i_mode); 1262 ext4_set_de_type(dir->i_sb, de, inode->i_mode);
1263 } else 1263 } else
1264 de->inode = 0; 1264 de->inode = 0;
1265 de->name_len = namelen; 1265 de->name_len = namelen;
@@ -1270,24 +1270,24 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1270 * on this. 1270 * on this.
1271 * 1271 *
1272 * XXX similarly, too many callers depend on 1272 * XXX similarly, too many callers depend on
1273 * ext3_new_inode() setting the times, but error 1273 * ext4_new_inode() setting the times, but error
1274 * recovery deletes the inode, so the worst that can 1274 * recovery deletes the inode, so the worst that can
1275 * happen is that the times are slightly out of date 1275 * happen is that the times are slightly out of date
1276 * and/or different from the directory change time. 1276 * and/or different from the directory change time.
1277 */ 1277 */
1278 dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC; 1278 dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
1279 ext3_update_dx_flag(dir); 1279 ext4_update_dx_flag(dir);
1280 dir->i_version++; 1280 dir->i_version++;
1281 ext3_mark_inode_dirty(handle, dir); 1281 ext4_mark_inode_dirty(handle, dir);
1282 BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata"); 1282 BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
1283 err = ext3_journal_dirty_metadata(handle, bh); 1283 err = ext4_journal_dirty_metadata(handle, bh);
1284 if (err) 1284 if (err)
1285 ext3_std_error(dir->i_sb, err); 1285 ext4_std_error(dir->i_sb, err);
1286 brelse(bh); 1286 brelse(bh);
1287 return 0; 1287 return 0;
1288} 1288}
1289 1289
1290#ifdef CONFIG_EXT3_INDEX 1290#ifdef CONFIG_EXT4_INDEX
1291/* 1291/*
1292 * This converts a one block unindexed directory to a 3 block indexed 1292 * This converts a one block unindexed directory to a 3 block indexed
1293 * directory, and adds the dentry to the indexed directory. 1293 * directory, and adds the dentry to the indexed directory.
@@ -1302,7 +1302,7 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1302 struct dx_root *root; 1302 struct dx_root *root;
1303 struct dx_frame frames[2], *frame; 1303 struct dx_frame frames[2], *frame;
1304 struct dx_entry *entries; 1304 struct dx_entry *entries;
1305 struct ext3_dir_entry_2 *de, *de2; 1305 struct ext4_dir_entry_2 *de, *de2;
1306 char *data1, *top; 1306 char *data1, *top;
1307 unsigned len; 1307 unsigned len;
1308 int retval; 1308 int retval;
@@ -1313,38 +1313,38 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1313 1313
1314 blocksize = dir->i_sb->s_blocksize; 1314 blocksize = dir->i_sb->s_blocksize;
1315 dxtrace(printk("Creating index\n")); 1315 dxtrace(printk("Creating index\n"));
1316 retval = ext3_journal_get_write_access(handle, bh); 1316 retval = ext4_journal_get_write_access(handle, bh);
1317 if (retval) { 1317 if (retval) {
1318 ext3_std_error(dir->i_sb, retval); 1318 ext4_std_error(dir->i_sb, retval);
1319 brelse(bh); 1319 brelse(bh);
1320 return retval; 1320 return retval;
1321 } 1321 }
1322 root = (struct dx_root *) bh->b_data; 1322 root = (struct dx_root *) bh->b_data;
1323 1323
1324 bh2 = ext3_append (handle, dir, &block, &retval); 1324 bh2 = ext4_append (handle, dir, &block, &retval);
1325 if (!(bh2)) { 1325 if (!(bh2)) {
1326 brelse(bh); 1326 brelse(bh);
1327 return retval; 1327 return retval;
1328 } 1328 }
1329 EXT3_I(dir)->i_flags |= EXT3_INDEX_FL; 1329 EXT4_I(dir)->i_flags |= EXT4_INDEX_FL;
1330 data1 = bh2->b_data; 1330 data1 = bh2->b_data;
1331 1331
1332 /* The 0th block becomes the root, move the dirents out */ 1332 /* The 0th block becomes the root, move the dirents out */
1333 fde = &root->dotdot; 1333 fde = &root->dotdot;
1334 de = (struct ext3_dir_entry_2 *)((char *)fde + le16_to_cpu(fde->rec_len)); 1334 de = (struct ext4_dir_entry_2 *)((char *)fde + le16_to_cpu(fde->rec_len));
1335 len = ((char *) root) + blocksize - (char *) de; 1335 len = ((char *) root) + blocksize - (char *) de;
1336 memcpy (data1, de, len); 1336 memcpy (data1, de, len);
1337 de = (struct ext3_dir_entry_2 *) data1; 1337 de = (struct ext4_dir_entry_2 *) data1;
1338 top = data1 + len; 1338 top = data1 + len;
1339 while ((char *)(de2=(void*)de+le16_to_cpu(de->rec_len)) < top) 1339 while ((char *)(de2=(void*)de+le16_to_cpu(de->rec_len)) < top)
1340 de = de2; 1340 de = de2;
1341 de->rec_len = cpu_to_le16(data1 + blocksize - (char *) de); 1341 de->rec_len = cpu_to_le16(data1 + blocksize - (char *) de);
1342 /* Initialize the root; the dot dirents already exist */ 1342 /* Initialize the root; the dot dirents already exist */
1343 de = (struct ext3_dir_entry_2 *) (&root->dotdot); 1343 de = (struct ext4_dir_entry_2 *) (&root->dotdot);
1344 de->rec_len = cpu_to_le16(blocksize - EXT3_DIR_REC_LEN(2)); 1344 de->rec_len = cpu_to_le16(blocksize - EXT4_DIR_REC_LEN(2));
1345 memset (&root->info, 0, sizeof(root->info)); 1345 memset (&root->info, 0, sizeof(root->info));
1346 root->info.info_length = sizeof(root->info); 1346 root->info.info_length = sizeof(root->info);
1347 root->info.hash_version = EXT3_SB(dir->i_sb)->s_def_hash_version; 1347 root->info.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
1348 entries = root->entries; 1348 entries = root->entries;
1349 dx_set_block (entries, 1); 1349 dx_set_block (entries, 1);
1350 dx_set_count (entries, 1); 1350 dx_set_count (entries, 1);
@@ -1352,8 +1352,8 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1352 1352
1353 /* Initialize as for dx_probe */ 1353 /* Initialize as for dx_probe */
1354 hinfo.hash_version = root->info.hash_version; 1354 hinfo.hash_version = root->info.hash_version;
1355 hinfo.seed = EXT3_SB(dir->i_sb)->s_hash_seed; 1355 hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
1356 ext3fs_dirhash(name, namelen, &hinfo); 1356 ext4fs_dirhash(name, namelen, &hinfo);
1357 frame = frames; 1357 frame = frames;
1358 frame->entries = entries; 1358 frame->entries = entries;
1359 frame->at = entries; 1359 frame->at = entries;
@@ -1369,25 +1369,25 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1369#endif 1369#endif
1370 1370
1371/* 1371/*
1372 * ext3_add_entry() 1372 * ext4_add_entry()
1373 * 1373 *
1374 * adds a file entry to the specified directory, using the same 1374 * adds a file entry to the specified directory, using the same
1375 * semantics as ext3_find_entry(). It returns NULL if it failed. 1375 * semantics as ext4_find_entry(). It returns NULL if it failed.
1376 * 1376 *
1377 * NOTE!! The inode part of 'de' is left at 0 - which means you 1377 * NOTE!! The inode part of 'de' is left at 0 - which means you
1378 * may not sleep between calling this and putting something into 1378 * may not sleep between calling this and putting something into
1379 * the entry, as someone else might have used it while you slept. 1379 * the entry, as someone else might have used it while you slept.
1380 */ 1380 */
1381static int ext3_add_entry (handle_t *handle, struct dentry *dentry, 1381static int ext4_add_entry (handle_t *handle, struct dentry *dentry,
1382 struct inode *inode) 1382 struct inode *inode)
1383{ 1383{
1384 struct inode *dir = dentry->d_parent->d_inode; 1384 struct inode *dir = dentry->d_parent->d_inode;
1385 unsigned long offset; 1385 unsigned long offset;
1386 struct buffer_head * bh; 1386 struct buffer_head * bh;
1387 struct ext3_dir_entry_2 *de; 1387 struct ext4_dir_entry_2 *de;
1388 struct super_block * sb; 1388 struct super_block * sb;
1389 int retval; 1389 int retval;
1390#ifdef CONFIG_EXT3_INDEX 1390#ifdef CONFIG_EXT4_INDEX
1391 int dx_fallback=0; 1391 int dx_fallback=0;
1392#endif 1392#endif
1393 unsigned blocksize; 1393 unsigned blocksize;
@@ -1397,46 +1397,46 @@ static int ext3_add_entry (handle_t *handle, struct dentry *dentry,
1397 blocksize = sb->s_blocksize; 1397 blocksize = sb->s_blocksize;
1398 if (!dentry->d_name.len) 1398 if (!dentry->d_name.len)
1399 return -EINVAL; 1399 return -EINVAL;
1400#ifdef CONFIG_EXT3_INDEX 1400#ifdef CONFIG_EXT4_INDEX
1401 if (is_dx(dir)) { 1401 if (is_dx(dir)) {
1402 retval = ext3_dx_add_entry(handle, dentry, inode); 1402 retval = ext4_dx_add_entry(handle, dentry, inode);
1403 if (!retval || (retval != ERR_BAD_DX_DIR)) 1403 if (!retval || (retval != ERR_BAD_DX_DIR))
1404 return retval; 1404 return retval;
1405 EXT3_I(dir)->i_flags &= ~EXT3_INDEX_FL; 1405 EXT4_I(dir)->i_flags &= ~EXT4_INDEX_FL;
1406 dx_fallback++; 1406 dx_fallback++;
1407 ext3_mark_inode_dirty(handle, dir); 1407 ext4_mark_inode_dirty(handle, dir);
1408 } 1408 }
1409#endif 1409#endif
1410 blocks = dir->i_size >> sb->s_blocksize_bits; 1410 blocks = dir->i_size >> sb->s_blocksize_bits;
1411 for (block = 0, offset = 0; block < blocks; block++) { 1411 for (block = 0, offset = 0; block < blocks; block++) {
1412 bh = ext3_bread(handle, dir, block, 0, &retval); 1412 bh = ext4_bread(handle, dir, block, 0, &retval);
1413 if(!bh) 1413 if(!bh)
1414 return retval; 1414 return retval;
1415 retval = add_dirent_to_buf(handle, dentry, inode, NULL, bh); 1415 retval = add_dirent_to_buf(handle, dentry, inode, NULL, bh);
1416 if (retval != -ENOSPC) 1416 if (retval != -ENOSPC)
1417 return retval; 1417 return retval;
1418 1418
1419#ifdef CONFIG_EXT3_INDEX 1419#ifdef CONFIG_EXT4_INDEX
1420 if (blocks == 1 && !dx_fallback && 1420 if (blocks == 1 && !dx_fallback &&
1421 EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_DIR_INDEX)) 1421 EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_DIR_INDEX))
1422 return make_indexed_dir(handle, dentry, inode, bh); 1422 return make_indexed_dir(handle, dentry, inode, bh);
1423#endif 1423#endif
1424 brelse(bh); 1424 brelse(bh);
1425 } 1425 }
1426 bh = ext3_append(handle, dir, &block, &retval); 1426 bh = ext4_append(handle, dir, &block, &retval);
1427 if (!bh) 1427 if (!bh)
1428 return retval; 1428 return retval;
1429 de = (struct ext3_dir_entry_2 *) bh->b_data; 1429 de = (struct ext4_dir_entry_2 *) bh->b_data;
1430 de->inode = 0; 1430 de->inode = 0;
1431 de->rec_len = cpu_to_le16(blocksize); 1431 de->rec_len = cpu_to_le16(blocksize);
1432 return add_dirent_to_buf(handle, dentry, inode, de, bh); 1432 return add_dirent_to_buf(handle, dentry, inode, de, bh);
1433} 1433}
1434 1434
1435#ifdef CONFIG_EXT3_INDEX 1435#ifdef CONFIG_EXT4_INDEX
1436/* 1436/*
1437 * Returns 0 for success, or a negative error value 1437 * Returns 0 for success, or a negative error value
1438 */ 1438 */
1439static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, 1439static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
1440 struct inode *inode) 1440 struct inode *inode)
1441{ 1441{
1442 struct dx_frame frames[2], *frame; 1442 struct dx_frame frames[2], *frame;
@@ -1445,7 +1445,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
1445 struct buffer_head * bh; 1445 struct buffer_head * bh;
1446 struct inode *dir = dentry->d_parent->d_inode; 1446 struct inode *dir = dentry->d_parent->d_inode;
1447 struct super_block * sb = dir->i_sb; 1447 struct super_block * sb = dir->i_sb;
1448 struct ext3_dir_entry_2 *de; 1448 struct ext4_dir_entry_2 *de;
1449 int err; 1449 int err;
1450 1450
1451 frame = dx_probe(dentry, NULL, &hinfo, frames, &err); 1451 frame = dx_probe(dentry, NULL, &hinfo, frames, &err);
@@ -1454,11 +1454,11 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
1454 entries = frame->entries; 1454 entries = frame->entries;
1455 at = frame->at; 1455 at = frame->at;
1456 1456
1457 if (!(bh = ext3_bread(handle,dir, dx_get_block(frame->at), 0, &err))) 1457 if (!(bh = ext4_bread(handle,dir, dx_get_block(frame->at), 0, &err)))
1458 goto cleanup; 1458 goto cleanup;
1459 1459
1460 BUFFER_TRACE(bh, "get_write_access"); 1460 BUFFER_TRACE(bh, "get_write_access");
1461 err = ext3_journal_get_write_access(handle, bh); 1461 err = ext4_journal_get_write_access(handle, bh);
1462 if (err) 1462 if (err)
1463 goto journal_error; 1463 goto journal_error;
1464 1464
@@ -1482,12 +1482,12 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
1482 1482
1483 if (levels && (dx_get_count(frames->entries) == 1483 if (levels && (dx_get_count(frames->entries) ==
1484 dx_get_limit(frames->entries))) { 1484 dx_get_limit(frames->entries))) {
1485 ext3_warning(sb, __FUNCTION__, 1485 ext4_warning(sb, __FUNCTION__,
1486 "Directory index full!"); 1486 "Directory index full!");
1487 err = -ENOSPC; 1487 err = -ENOSPC;
1488 goto cleanup; 1488 goto cleanup;
1489 } 1489 }
1490 bh2 = ext3_append (handle, dir, &newblock, &err); 1490 bh2 = ext4_append (handle, dir, &newblock, &err);
1491 if (!(bh2)) 1491 if (!(bh2))
1492 goto cleanup; 1492 goto cleanup;
1493 node2 = (struct dx_node *)(bh2->b_data); 1493 node2 = (struct dx_node *)(bh2->b_data);
@@ -1495,7 +1495,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
1495 node2->fake.rec_len = cpu_to_le16(sb->s_blocksize); 1495 node2->fake.rec_len = cpu_to_le16(sb->s_blocksize);
1496 node2->fake.inode = 0; 1496 node2->fake.inode = 0;
1497 BUFFER_TRACE(frame->bh, "get_write_access"); 1497 BUFFER_TRACE(frame->bh, "get_write_access");
1498 err = ext3_journal_get_write_access(handle, frame->bh); 1498 err = ext4_journal_get_write_access(handle, frame->bh);
1499 if (err) 1499 if (err)
1500 goto journal_error; 1500 goto journal_error;
1501 if (levels) { 1501 if (levels) {
@@ -1504,7 +1504,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
1504 dxtrace(printk("Split index %i/%i\n", icount1, icount2)); 1504 dxtrace(printk("Split index %i/%i\n", icount1, icount2));
1505 1505
1506 BUFFER_TRACE(frame->bh, "get_write_access"); /* index root */ 1506 BUFFER_TRACE(frame->bh, "get_write_access"); /* index root */
1507 err = ext3_journal_get_write_access(handle, 1507 err = ext4_journal_get_write_access(handle,
1508 frames[0].bh); 1508 frames[0].bh);
1509 if (err) 1509 if (err)
1510 goto journal_error; 1510 goto journal_error;
@@ -1525,7 +1525,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
1525 dxtrace(dx_show_index ("node", frames[1].entries)); 1525 dxtrace(dx_show_index ("node", frames[1].entries));
1526 dxtrace(dx_show_index ("node", 1526 dxtrace(dx_show_index ("node",
1527 ((struct dx_node *) bh2->b_data)->entries)); 1527 ((struct dx_node *) bh2->b_data)->entries));
1528 err = ext3_journal_dirty_metadata(handle, bh2); 1528 err = ext4_journal_dirty_metadata(handle, bh2);
1529 if (err) 1529 if (err)
1530 goto journal_error; 1530 goto journal_error;
1531 brelse (bh2); 1531 brelse (bh2);
@@ -1545,12 +1545,12 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
1545 frame->at = at = at - entries + entries2; 1545 frame->at = at = at - entries + entries2;
1546 frame->entries = entries = entries2; 1546 frame->entries = entries = entries2;
1547 frame->bh = bh2; 1547 frame->bh = bh2;
1548 err = ext3_journal_get_write_access(handle, 1548 err = ext4_journal_get_write_access(handle,
1549 frame->bh); 1549 frame->bh);
1550 if (err) 1550 if (err)
1551 goto journal_error; 1551 goto journal_error;
1552 } 1552 }
1553 ext3_journal_dirty_metadata(handle, frames[0].bh); 1553 ext4_journal_dirty_metadata(handle, frames[0].bh);
1554 } 1554 }
1555 de = do_split(handle, dir, &bh, frame, &hinfo, &err); 1555 de = do_split(handle, dir, &bh, frame, &hinfo, &err);
1556 if (!de) 1556 if (!de)
@@ -1560,7 +1560,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
1560 goto cleanup; 1560 goto cleanup;
1561 1561
1562journal_error: 1562journal_error:
1563 ext3_std_error(dir->i_sb, err); 1563 ext4_std_error(dir->i_sb, err);
1564cleanup: 1564cleanup:
1565 if (bh) 1565 if (bh)
1566 brelse(bh); 1566 brelse(bh);
@@ -1570,26 +1570,26 @@ cleanup:
1570#endif 1570#endif
1571 1571
1572/* 1572/*
1573 * ext3_delete_entry deletes a directory entry by merging it with the 1573 * ext4_delete_entry deletes a directory entry by merging it with the
1574 * previous entry 1574 * previous entry
1575 */ 1575 */
1576static int ext3_delete_entry (handle_t *handle, 1576static int ext4_delete_entry (handle_t *handle,
1577 struct inode * dir, 1577 struct inode * dir,
1578 struct ext3_dir_entry_2 * de_del, 1578 struct ext4_dir_entry_2 * de_del,
1579 struct buffer_head * bh) 1579 struct buffer_head * bh)
1580{ 1580{
1581 struct ext3_dir_entry_2 * de, * pde; 1581 struct ext4_dir_entry_2 * de, * pde;
1582 int i; 1582 int i;
1583 1583
1584 i = 0; 1584 i = 0;
1585 pde = NULL; 1585 pde = NULL;
1586 de = (struct ext3_dir_entry_2 *) bh->b_data; 1586 de = (struct ext4_dir_entry_2 *) bh->b_data;
1587 while (i < bh->b_size) { 1587 while (i < bh->b_size) {
1588 if (!ext3_check_dir_entry("ext3_delete_entry", dir, de, bh, i)) 1588 if (!ext4_check_dir_entry("ext4_delete_entry", dir, de, bh, i))
1589 return -EIO; 1589 return -EIO;
1590 if (de == de_del) { 1590 if (de == de_del) {
1591 BUFFER_TRACE(bh, "get_write_access"); 1591 BUFFER_TRACE(bh, "get_write_access");
1592 ext3_journal_get_write_access(handle, bh); 1592 ext4_journal_get_write_access(handle, bh);
1593 if (pde) 1593 if (pde)
1594 pde->rec_len = 1594 pde->rec_len =
1595 cpu_to_le16(le16_to_cpu(pde->rec_len) + 1595 cpu_to_le16(le16_to_cpu(pde->rec_len) +
@@ -1597,43 +1597,43 @@ static int ext3_delete_entry (handle_t *handle,
1597 else 1597 else
1598 de->inode = 0; 1598 de->inode = 0;
1599 dir->i_version++; 1599 dir->i_version++;
1600 BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata"); 1600 BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
1601 ext3_journal_dirty_metadata(handle, bh); 1601 ext4_journal_dirty_metadata(handle, bh);
1602 return 0; 1602 return 0;
1603 } 1603 }
1604 i += le16_to_cpu(de->rec_len); 1604 i += le16_to_cpu(de->rec_len);
1605 pde = de; 1605 pde = de;
1606 de = (struct ext3_dir_entry_2 *) 1606 de = (struct ext4_dir_entry_2 *)
1607 ((char *) de + le16_to_cpu(de->rec_len)); 1607 ((char *) de + le16_to_cpu(de->rec_len));
1608 } 1608 }
1609 return -ENOENT; 1609 return -ENOENT;
1610} 1610}
1611 1611
1612/* 1612/*
1613 * ext3_mark_inode_dirty is somewhat expensive, so unlike ext2 we 1613 * ext4_mark_inode_dirty is somewhat expensive, so unlike ext2 we
1614 * do not perform it in these functions. We perform it at the call site, 1614 * do not perform it in these functions. We perform it at the call site,
1615 * if it is needed. 1615 * if it is needed.
1616 */ 1616 */
1617static inline void ext3_inc_count(handle_t *handle, struct inode *inode) 1617static inline void ext4_inc_count(handle_t *handle, struct inode *inode)
1618{ 1618{
1619 inc_nlink(inode); 1619 inc_nlink(inode);
1620} 1620}
1621 1621
1622static inline void ext3_dec_count(handle_t *handle, struct inode *inode) 1622static inline void ext4_dec_count(handle_t *handle, struct inode *inode)
1623{ 1623{
1624 drop_nlink(inode); 1624 drop_nlink(inode);
1625} 1625}
1626 1626
1627static int ext3_add_nondir(handle_t *handle, 1627static int ext4_add_nondir(handle_t *handle,
1628 struct dentry *dentry, struct inode *inode) 1628 struct dentry *dentry, struct inode *inode)
1629{ 1629{
1630 int err = ext3_add_entry(handle, dentry, inode); 1630 int err = ext4_add_entry(handle, dentry, inode);
1631 if (!err) { 1631 if (!err) {
1632 ext3_mark_inode_dirty(handle, inode); 1632 ext4_mark_inode_dirty(handle, inode);
1633 d_instantiate(dentry, inode); 1633 d_instantiate(dentry, inode);
1634 return 0; 1634 return 0;
1635 } 1635 }
1636 ext3_dec_count(handle, inode); 1636 ext4_dec_count(handle, inode);
1637 iput(inode); 1637 iput(inode);
1638 return err; 1638 return err;
1639} 1639}
@@ -1646,7 +1646,7 @@ static int ext3_add_nondir(handle_t *handle,
1646 * If the create succeeds, we fill in the inode information 1646 * If the create succeeds, we fill in the inode information
1647 * with d_instantiate(). 1647 * with d_instantiate().
1648 */ 1648 */
1649static int ext3_create (struct inode * dir, struct dentry * dentry, int mode, 1649static int ext4_create (struct inode * dir, struct dentry * dentry, int mode,
1650 struct nameidata *nd) 1650 struct nameidata *nd)
1651{ 1651{
1652 handle_t *handle; 1652 handle_t *handle;
@@ -1654,30 +1654,30 @@ static int ext3_create (struct inode * dir, struct dentry * dentry, int mode,
1654 int err, retries = 0; 1654 int err, retries = 0;
1655 1655
1656retry: 1656retry:
1657 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + 1657 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
1658 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + 1658 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
1659 2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); 1659 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
1660 if (IS_ERR(handle)) 1660 if (IS_ERR(handle))
1661 return PTR_ERR(handle); 1661 return PTR_ERR(handle);
1662 1662
1663 if (IS_DIRSYNC(dir)) 1663 if (IS_DIRSYNC(dir))
1664 handle->h_sync = 1; 1664 handle->h_sync = 1;
1665 1665
1666 inode = ext3_new_inode (handle, dir, mode); 1666 inode = ext4_new_inode (handle, dir, mode);
1667 err = PTR_ERR(inode); 1667 err = PTR_ERR(inode);
1668 if (!IS_ERR(inode)) { 1668 if (!IS_ERR(inode)) {
1669 inode->i_op = &ext3_file_inode_operations; 1669 inode->i_op = &ext4_file_inode_operations;
1670 inode->i_fop = &ext3_file_operations; 1670 inode->i_fop = &ext4_file_operations;
1671 ext3_set_aops(inode); 1671 ext4_set_aops(inode);
1672 err = ext3_add_nondir(handle, dentry, inode); 1672 err = ext4_add_nondir(handle, dentry, inode);
1673 } 1673 }
1674 ext3_journal_stop(handle); 1674 ext4_journal_stop(handle);
1675 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries)) 1675 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
1676 goto retry; 1676 goto retry;
1677 return err; 1677 return err;
1678} 1678}
1679 1679
1680static int ext3_mknod (struct inode * dir, struct dentry *dentry, 1680static int ext4_mknod (struct inode * dir, struct dentry *dentry,
1681 int mode, dev_t rdev) 1681 int mode, dev_t rdev)
1682{ 1682{
1683 handle_t *handle; 1683 handle_t *handle;
@@ -1688,100 +1688,100 @@ static int ext3_mknod (struct inode * dir, struct dentry *dentry,
1688 return -EINVAL; 1688 return -EINVAL;
1689 1689
1690retry: 1690retry:
1691 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + 1691 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
1692 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + 1692 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
1693 2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); 1693 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
1694 if (IS_ERR(handle)) 1694 if (IS_ERR(handle))
1695 return PTR_ERR(handle); 1695 return PTR_ERR(handle);
1696 1696
1697 if (IS_DIRSYNC(dir)) 1697 if (IS_DIRSYNC(dir))
1698 handle->h_sync = 1; 1698 handle->h_sync = 1;
1699 1699
1700 inode = ext3_new_inode (handle, dir, mode); 1700 inode = ext4_new_inode (handle, dir, mode);
1701 err = PTR_ERR(inode); 1701 err = PTR_ERR(inode);
1702 if (!IS_ERR(inode)) { 1702 if (!IS_ERR(inode)) {
1703 init_special_inode(inode, inode->i_mode, rdev); 1703 init_special_inode(inode, inode->i_mode, rdev);
1704#ifdef CONFIG_EXT3_FS_XATTR 1704#ifdef CONFIG_EXT4DEV_FS_XATTR
1705 inode->i_op = &ext3_special_inode_operations; 1705 inode->i_op = &ext4_special_inode_operations;
1706#endif 1706#endif
1707 err = ext3_add_nondir(handle, dentry, inode); 1707 err = ext4_add_nondir(handle, dentry, inode);
1708 } 1708 }
1709 ext3_journal_stop(handle); 1709 ext4_journal_stop(handle);
1710 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries)) 1710 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
1711 goto retry; 1711 goto retry;
1712 return err; 1712 return err;
1713} 1713}
1714 1714
1715static int ext3_mkdir(struct inode * dir, struct dentry * dentry, int mode) 1715static int ext4_mkdir(struct inode * dir, struct dentry * dentry, int mode)
1716{ 1716{
1717 handle_t *handle; 1717 handle_t *handle;
1718 struct inode * inode; 1718 struct inode * inode;
1719 struct buffer_head * dir_block; 1719 struct buffer_head * dir_block;
1720 struct ext3_dir_entry_2 * de; 1720 struct ext4_dir_entry_2 * de;
1721 int err, retries = 0; 1721 int err, retries = 0;
1722 1722
1723 if (dir->i_nlink >= EXT3_LINK_MAX) 1723 if (dir->i_nlink >= EXT4_LINK_MAX)
1724 return -EMLINK; 1724 return -EMLINK;
1725 1725
1726retry: 1726retry:
1727 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + 1727 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
1728 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + 1728 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
1729 2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); 1729 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
1730 if (IS_ERR(handle)) 1730 if (IS_ERR(handle))
1731 return PTR_ERR(handle); 1731 return PTR_ERR(handle);
1732 1732
1733 if (IS_DIRSYNC(dir)) 1733 if (IS_DIRSYNC(dir))
1734 handle->h_sync = 1; 1734 handle->h_sync = 1;
1735 1735
1736 inode = ext3_new_inode (handle, dir, S_IFDIR | mode); 1736 inode = ext4_new_inode (handle, dir, S_IFDIR | mode);
1737 err = PTR_ERR(inode); 1737 err = PTR_ERR(inode);
1738 if (IS_ERR(inode)) 1738 if (IS_ERR(inode))
1739 goto out_stop; 1739 goto out_stop;
1740 1740
1741 inode->i_op = &ext3_dir_inode_operations; 1741 inode->i_op = &ext4_dir_inode_operations;
1742 inode->i_fop = &ext3_dir_operations; 1742 inode->i_fop = &ext4_dir_operations;
1743 inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize; 1743 inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
1744 dir_block = ext3_bread (handle, inode, 0, 1, &err); 1744 dir_block = ext4_bread (handle, inode, 0, 1, &err);
1745 if (!dir_block) { 1745 if (!dir_block) {
1746 drop_nlink(inode); /* is this nlink == 0? */ 1746 drop_nlink(inode); /* is this nlink == 0? */
1747 ext3_mark_inode_dirty(handle, inode); 1747 ext4_mark_inode_dirty(handle, inode);
1748 iput (inode); 1748 iput (inode);
1749 goto out_stop; 1749 goto out_stop;
1750 } 1750 }
1751 BUFFER_TRACE(dir_block, "get_write_access"); 1751 BUFFER_TRACE(dir_block, "get_write_access");
1752 ext3_journal_get_write_access(handle, dir_block); 1752 ext4_journal_get_write_access(handle, dir_block);
1753 de = (struct ext3_dir_entry_2 *) dir_block->b_data; 1753 de = (struct ext4_dir_entry_2 *) dir_block->b_data;
1754 de->inode = cpu_to_le32(inode->i_ino); 1754 de->inode = cpu_to_le32(inode->i_ino);
1755 de->name_len = 1; 1755 de->name_len = 1;
1756 de->rec_len = cpu_to_le16(EXT3_DIR_REC_LEN(de->name_len)); 1756 de->rec_len = cpu_to_le16(EXT4_DIR_REC_LEN(de->name_len));
1757 strcpy (de->name, "."); 1757 strcpy (de->name, ".");
1758 ext3_set_de_type(dir->i_sb, de, S_IFDIR); 1758 ext4_set_de_type(dir->i_sb, de, S_IFDIR);
1759 de = (struct ext3_dir_entry_2 *) 1759 de = (struct ext4_dir_entry_2 *)
1760 ((char *) de + le16_to_cpu(de->rec_len)); 1760 ((char *) de + le16_to_cpu(de->rec_len));
1761 de->inode = cpu_to_le32(dir->i_ino); 1761 de->inode = cpu_to_le32(dir->i_ino);
1762 de->rec_len = cpu_to_le16(inode->i_sb->s_blocksize-EXT3_DIR_REC_LEN(1)); 1762 de->rec_len = cpu_to_le16(inode->i_sb->s_blocksize-EXT4_DIR_REC_LEN(1));
1763 de->name_len = 2; 1763 de->name_len = 2;
1764 strcpy (de->name, ".."); 1764 strcpy (de->name, "..");
1765 ext3_set_de_type(dir->i_sb, de, S_IFDIR); 1765 ext4_set_de_type(dir->i_sb, de, S_IFDIR);
1766 inode->i_nlink = 2; 1766 inode->i_nlink = 2;
1767 BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata"); 1767 BUFFER_TRACE(dir_block, "call ext4_journal_dirty_metadata");
1768 ext3_journal_dirty_metadata(handle, dir_block); 1768 ext4_journal_dirty_metadata(handle, dir_block);
1769 brelse (dir_block); 1769 brelse (dir_block);
1770 ext3_mark_inode_dirty(handle, inode); 1770 ext4_mark_inode_dirty(handle, inode);
1771 err = ext3_add_entry (handle, dentry, inode); 1771 err = ext4_add_entry (handle, dentry, inode);
1772 if (err) { 1772 if (err) {
1773 inode->i_nlink = 0; 1773 inode->i_nlink = 0;
1774 ext3_mark_inode_dirty(handle, inode); 1774 ext4_mark_inode_dirty(handle, inode);
1775 iput (inode); 1775 iput (inode);
1776 goto out_stop; 1776 goto out_stop;
1777 } 1777 }
1778 inc_nlink(dir); 1778 inc_nlink(dir);
1779 ext3_update_dx_flag(dir); 1779 ext4_update_dx_flag(dir);
1780 ext3_mark_inode_dirty(handle, dir); 1780 ext4_mark_inode_dirty(handle, dir);
1781 d_instantiate(dentry, inode); 1781 d_instantiate(dentry, inode);
1782out_stop: 1782out_stop:
1783 ext3_journal_stop(handle); 1783 ext4_journal_stop(handle);
1784 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries)) 1784 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
1785 goto retry; 1785 goto retry;
1786 return err; 1786 return err;
1787} 1787}
@@ -1793,59 +1793,59 @@ static int empty_dir (struct inode * inode)
1793{ 1793{
1794 unsigned long offset; 1794 unsigned long offset;
1795 struct buffer_head * bh; 1795 struct buffer_head * bh;
1796 struct ext3_dir_entry_2 * de, * de1; 1796 struct ext4_dir_entry_2 * de, * de1;
1797 struct super_block * sb; 1797 struct super_block * sb;
1798 int err = 0; 1798 int err = 0;
1799 1799
1800 sb = inode->i_sb; 1800 sb = inode->i_sb;
1801 if (inode->i_size < EXT3_DIR_REC_LEN(1) + EXT3_DIR_REC_LEN(2) || 1801 if (inode->i_size < EXT4_DIR_REC_LEN(1) + EXT4_DIR_REC_LEN(2) ||
1802 !(bh = ext3_bread (NULL, inode, 0, 0, &err))) { 1802 !(bh = ext4_bread (NULL, inode, 0, 0, &err))) {
1803 if (err) 1803 if (err)
1804 ext3_error(inode->i_sb, __FUNCTION__, 1804 ext4_error(inode->i_sb, __FUNCTION__,
1805 "error %d reading directory #%lu offset 0", 1805 "error %d reading directory #%lu offset 0",
1806 err, inode->i_ino); 1806 err, inode->i_ino);
1807 else 1807 else
1808 ext3_warning(inode->i_sb, __FUNCTION__, 1808 ext4_warning(inode->i_sb, __FUNCTION__,
1809 "bad directory (dir #%lu) - no data block", 1809 "bad directory (dir #%lu) - no data block",
1810 inode->i_ino); 1810 inode->i_ino);
1811 return 1; 1811 return 1;
1812 } 1812 }
1813 de = (struct ext3_dir_entry_2 *) bh->b_data; 1813 de = (struct ext4_dir_entry_2 *) bh->b_data;
1814 de1 = (struct ext3_dir_entry_2 *) 1814 de1 = (struct ext4_dir_entry_2 *)
1815 ((char *) de + le16_to_cpu(de->rec_len)); 1815 ((char *) de + le16_to_cpu(de->rec_len));
1816 if (le32_to_cpu(de->inode) != inode->i_ino || 1816 if (le32_to_cpu(de->inode) != inode->i_ino ||
1817 !le32_to_cpu(de1->inode) || 1817 !le32_to_cpu(de1->inode) ||
1818 strcmp (".", de->name) || 1818 strcmp (".", de->name) ||
1819 strcmp ("..", de1->name)) { 1819 strcmp ("..", de1->name)) {
1820 ext3_warning (inode->i_sb, "empty_dir", 1820 ext4_warning (inode->i_sb, "empty_dir",
1821 "bad directory (dir #%lu) - no `.' or `..'", 1821 "bad directory (dir #%lu) - no `.' or `..'",
1822 inode->i_ino); 1822 inode->i_ino);
1823 brelse (bh); 1823 brelse (bh);
1824 return 1; 1824 return 1;
1825 } 1825 }
1826 offset = le16_to_cpu(de->rec_len) + le16_to_cpu(de1->rec_len); 1826 offset = le16_to_cpu(de->rec_len) + le16_to_cpu(de1->rec_len);
1827 de = (struct ext3_dir_entry_2 *) 1827 de = (struct ext4_dir_entry_2 *)
1828 ((char *) de1 + le16_to_cpu(de1->rec_len)); 1828 ((char *) de1 + le16_to_cpu(de1->rec_len));
1829 while (offset < inode->i_size ) { 1829 while (offset < inode->i_size ) {
1830 if (!bh || 1830 if (!bh ||
1831 (void *) de >= (void *) (bh->b_data+sb->s_blocksize)) { 1831 (void *) de >= (void *) (bh->b_data+sb->s_blocksize)) {
1832 err = 0; 1832 err = 0;
1833 brelse (bh); 1833 brelse (bh);
1834 bh = ext3_bread (NULL, inode, 1834 bh = ext4_bread (NULL, inode,
1835 offset >> EXT3_BLOCK_SIZE_BITS(sb), 0, &err); 1835 offset >> EXT4_BLOCK_SIZE_BITS(sb), 0, &err);
1836 if (!bh) { 1836 if (!bh) {
1837 if (err) 1837 if (err)
1838 ext3_error(sb, __FUNCTION__, 1838 ext4_error(sb, __FUNCTION__,
1839 "error %d reading directory" 1839 "error %d reading directory"
1840 " #%lu offset %lu", 1840 " #%lu offset %lu",
1841 err, inode->i_ino, offset); 1841 err, inode->i_ino, offset);
1842 offset += sb->s_blocksize; 1842 offset += sb->s_blocksize;
1843 continue; 1843 continue;
1844 } 1844 }
1845 de = (struct ext3_dir_entry_2 *) bh->b_data; 1845 de = (struct ext4_dir_entry_2 *) bh->b_data;
1846 } 1846 }
1847 if (!ext3_check_dir_entry("empty_dir", inode, de, bh, offset)) { 1847 if (!ext4_check_dir_entry("empty_dir", inode, de, bh, offset)) {
1848 de = (struct ext3_dir_entry_2 *)(bh->b_data + 1848 de = (struct ext4_dir_entry_2 *)(bh->b_data +
1849 sb->s_blocksize); 1849 sb->s_blocksize);
1850 offset = (offset | (sb->s_blocksize - 1)) + 1; 1850 offset = (offset | (sb->s_blocksize - 1)) + 1;
1851 continue; 1851 continue;
@@ -1855,57 +1855,57 @@ static int empty_dir (struct inode * inode)
1855 return 0; 1855 return 0;
1856 } 1856 }
1857 offset += le16_to_cpu(de->rec_len); 1857 offset += le16_to_cpu(de->rec_len);
1858 de = (struct ext3_dir_entry_2 *) 1858 de = (struct ext4_dir_entry_2 *)
1859 ((char *) de + le16_to_cpu(de->rec_len)); 1859 ((char *) de + le16_to_cpu(de->rec_len));
1860 } 1860 }
1861 brelse (bh); 1861 brelse (bh);
1862 return 1; 1862 return 1;
1863} 1863}
1864 1864
1865/* ext3_orphan_add() links an unlinked or truncated inode into a list of 1865/* ext4_orphan_add() links an unlinked or truncated inode into a list of
1866 * such inodes, starting at the superblock, in case we crash before the 1866 * such inodes, starting at the superblock, in case we crash before the
1867 * file is closed/deleted, or in case the inode truncate spans multiple 1867 * file is closed/deleted, or in case the inode truncate spans multiple
1868 * transactions and the last transaction is not recovered after a crash. 1868 * transactions and the last transaction is not recovered after a crash.
1869 * 1869 *
1870 * At filesystem recovery time, we walk this list deleting unlinked 1870 * At filesystem recovery time, we walk this list deleting unlinked
1871 * inodes and truncating linked inodes in ext3_orphan_cleanup(). 1871 * inodes and truncating linked inodes in ext4_orphan_cleanup().
1872 */ 1872 */
1873int ext3_orphan_add(handle_t *handle, struct inode *inode) 1873int ext4_orphan_add(handle_t *handle, struct inode *inode)
1874{ 1874{
1875 struct super_block *sb = inode->i_sb; 1875 struct super_block *sb = inode->i_sb;
1876 struct ext3_iloc iloc; 1876 struct ext4_iloc iloc;
1877 int err = 0, rc; 1877 int err = 0, rc;
1878 1878
1879 lock_super(sb); 1879 lock_super(sb);
1880 if (!list_empty(&EXT3_I(inode)->i_orphan)) 1880 if (!list_empty(&EXT4_I(inode)->i_orphan))
1881 goto out_unlock; 1881 goto out_unlock;
1882 1882
1883 /* Orphan handling is only valid for files with data blocks 1883 /* Orphan handling is only valid for files with data blocks
1884 * being truncated, or files being unlinked. */ 1884 * being truncated, or files being unlinked. */
1885 1885
1886 /* @@@ FIXME: Observation from aviro: 1886 /* @@@ FIXME: Observation from aviro:
1887 * I think I can trigger J_ASSERT in ext3_orphan_add(). We block 1887 * I think I can trigger J_ASSERT in ext4_orphan_add(). We block
1888 * here (on lock_super()), so race with ext3_link() which might bump 1888 * here (on lock_super()), so race with ext4_link() which might bump
1889 * ->i_nlink. For, say it, character device. Not a regular file, 1889 * ->i_nlink. For, say it, character device. Not a regular file,
1890 * not a directory, not a symlink and ->i_nlink > 0. 1890 * not a directory, not a symlink and ->i_nlink > 0.
1891 */ 1891 */
1892 J_ASSERT ((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || 1892 J_ASSERT ((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1893 S_ISLNK(inode->i_mode)) || inode->i_nlink == 0); 1893 S_ISLNK(inode->i_mode)) || inode->i_nlink == 0);
1894 1894
1895 BUFFER_TRACE(EXT3_SB(sb)->s_sbh, "get_write_access"); 1895 BUFFER_TRACE(EXT4_SB(sb)->s_sbh, "get_write_access");
1896 err = ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh); 1896 err = ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh);
1897 if (err) 1897 if (err)
1898 goto out_unlock; 1898 goto out_unlock;
1899 1899
1900 err = ext3_reserve_inode_write(handle, inode, &iloc); 1900 err = ext4_reserve_inode_write(handle, inode, &iloc);
1901 if (err) 1901 if (err)
1902 goto out_unlock; 1902 goto out_unlock;
1903 1903
1904 /* Insert this inode at the head of the on-disk orphan list... */ 1904 /* Insert this inode at the head of the on-disk orphan list... */
1905 NEXT_ORPHAN(inode) = le32_to_cpu(EXT3_SB(sb)->s_es->s_last_orphan); 1905 NEXT_ORPHAN(inode) = le32_to_cpu(EXT4_SB(sb)->s_es->s_last_orphan);
1906 EXT3_SB(sb)->s_es->s_last_orphan = cpu_to_le32(inode->i_ino); 1906 EXT4_SB(sb)->s_es->s_last_orphan = cpu_to_le32(inode->i_ino);
1907 err = ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); 1907 err = ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh);
1908 rc = ext3_mark_iloc_dirty(handle, inode, &iloc); 1908 rc = ext4_mark_iloc_dirty(handle, inode, &iloc);
1909 if (!err) 1909 if (!err)
1910 err = rc; 1910 err = rc;
1911 1911
@@ -1918,28 +1918,28 @@ int ext3_orphan_add(handle_t *handle, struct inode *inode)
1918 * This is safe: on error we're going to ignore the orphan list 1918 * This is safe: on error we're going to ignore the orphan list
1919 * anyway on the next recovery. */ 1919 * anyway on the next recovery. */
1920 if (!err) 1920 if (!err)
1921 list_add(&EXT3_I(inode)->i_orphan, &EXT3_SB(sb)->s_orphan); 1921 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
1922 1922
1923 jbd_debug(4, "superblock will point to %lu\n", inode->i_ino); 1923 jbd_debug(4, "superblock will point to %lu\n", inode->i_ino);
1924 jbd_debug(4, "orphan inode %lu will point to %d\n", 1924 jbd_debug(4, "orphan inode %lu will point to %d\n",
1925 inode->i_ino, NEXT_ORPHAN(inode)); 1925 inode->i_ino, NEXT_ORPHAN(inode));
1926out_unlock: 1926out_unlock:
1927 unlock_super(sb); 1927 unlock_super(sb);
1928 ext3_std_error(inode->i_sb, err); 1928 ext4_std_error(inode->i_sb, err);
1929 return err; 1929 return err;
1930} 1930}
1931 1931
1932/* 1932/*
1933 * ext3_orphan_del() removes an unlinked or truncated inode from the list 1933 * ext4_orphan_del() removes an unlinked or truncated inode from the list
1934 * of such inodes stored on disk, because it is finally being cleaned up. 1934 * of such inodes stored on disk, because it is finally being cleaned up.
1935 */ 1935 */
1936int ext3_orphan_del(handle_t *handle, struct inode *inode) 1936int ext4_orphan_del(handle_t *handle, struct inode *inode)
1937{ 1937{
1938 struct list_head *prev; 1938 struct list_head *prev;
1939 struct ext3_inode_info *ei = EXT3_I(inode); 1939 struct ext4_inode_info *ei = EXT4_I(inode);
1940 struct ext3_sb_info *sbi; 1940 struct ext4_sb_info *sbi;
1941 unsigned long ino_next; 1941 unsigned long ino_next;
1942 struct ext3_iloc iloc; 1942 struct ext4_iloc iloc;
1943 int err = 0; 1943 int err = 0;
1944 1944
1945 lock_super(inode->i_sb); 1945 lock_super(inode->i_sb);
@@ -1950,7 +1950,7 @@ int ext3_orphan_del(handle_t *handle, struct inode *inode)
1950 1950
1951 ino_next = NEXT_ORPHAN(inode); 1951 ino_next = NEXT_ORPHAN(inode);
1952 prev = ei->i_orphan.prev; 1952 prev = ei->i_orphan.prev;
1953 sbi = EXT3_SB(inode->i_sb); 1953 sbi = EXT4_SB(inode->i_sb);
1954 1954
1955 jbd_debug(4, "remove inode %lu from orphan list\n", inode->i_ino); 1955 jbd_debug(4, "remove inode %lu from orphan list\n", inode->i_ino);
1956 1956
@@ -1963,38 +1963,38 @@ int ext3_orphan_del(handle_t *handle, struct inode *inode)
1963 if (!handle) 1963 if (!handle)
1964 goto out; 1964 goto out;
1965 1965
1966 err = ext3_reserve_inode_write(handle, inode, &iloc); 1966 err = ext4_reserve_inode_write(handle, inode, &iloc);
1967 if (err) 1967 if (err)
1968 goto out_err; 1968 goto out_err;
1969 1969
1970 if (prev == &sbi->s_orphan) { 1970 if (prev == &sbi->s_orphan) {
1971 jbd_debug(4, "superblock will point to %lu\n", ino_next); 1971 jbd_debug(4, "superblock will point to %lu\n", ino_next);
1972 BUFFER_TRACE(sbi->s_sbh, "get_write_access"); 1972 BUFFER_TRACE(sbi->s_sbh, "get_write_access");
1973 err = ext3_journal_get_write_access(handle, sbi->s_sbh); 1973 err = ext4_journal_get_write_access(handle, sbi->s_sbh);
1974 if (err) 1974 if (err)
1975 goto out_brelse; 1975 goto out_brelse;
1976 sbi->s_es->s_last_orphan = cpu_to_le32(ino_next); 1976 sbi->s_es->s_last_orphan = cpu_to_le32(ino_next);
1977 err = ext3_journal_dirty_metadata(handle, sbi->s_sbh); 1977 err = ext4_journal_dirty_metadata(handle, sbi->s_sbh);
1978 } else { 1978 } else {
1979 struct ext3_iloc iloc2; 1979 struct ext4_iloc iloc2;
1980 struct inode *i_prev = 1980 struct inode *i_prev =
1981 &list_entry(prev, struct ext3_inode_info, i_orphan)->vfs_inode; 1981 &list_entry(prev, struct ext4_inode_info, i_orphan)->vfs_inode;
1982 1982
1983 jbd_debug(4, "orphan inode %lu will point to %lu\n", 1983 jbd_debug(4, "orphan inode %lu will point to %lu\n",
1984 i_prev->i_ino, ino_next); 1984 i_prev->i_ino, ino_next);
1985 err = ext3_reserve_inode_write(handle, i_prev, &iloc2); 1985 err = ext4_reserve_inode_write(handle, i_prev, &iloc2);
1986 if (err) 1986 if (err)
1987 goto out_brelse; 1987 goto out_brelse;
1988 NEXT_ORPHAN(i_prev) = ino_next; 1988 NEXT_ORPHAN(i_prev) = ino_next;
1989 err = ext3_mark_iloc_dirty(handle, i_prev, &iloc2); 1989 err = ext4_mark_iloc_dirty(handle, i_prev, &iloc2);
1990 } 1990 }
1991 if (err) 1991 if (err)
1992 goto out_brelse; 1992 goto out_brelse;
1993 NEXT_ORPHAN(inode) = 0; 1993 NEXT_ORPHAN(inode) = 0;
1994 err = ext3_mark_iloc_dirty(handle, inode, &iloc); 1994 err = ext4_mark_iloc_dirty(handle, inode, &iloc);
1995 1995
1996out_err: 1996out_err:
1997 ext3_std_error(inode->i_sb, err); 1997 ext4_std_error(inode->i_sb, err);
1998out: 1998out:
1999 unlock_super(inode->i_sb); 1999 unlock_super(inode->i_sb);
2000 return err; 2000 return err;
@@ -2004,23 +2004,23 @@ out_brelse:
2004 goto out_err; 2004 goto out_err;
2005} 2005}
2006 2006
2007static int ext3_rmdir (struct inode * dir, struct dentry *dentry) 2007static int ext4_rmdir (struct inode * dir, struct dentry *dentry)
2008{ 2008{
2009 int retval; 2009 int retval;
2010 struct inode * inode; 2010 struct inode * inode;
2011 struct buffer_head * bh; 2011 struct buffer_head * bh;
2012 struct ext3_dir_entry_2 * de; 2012 struct ext4_dir_entry_2 * de;
2013 handle_t *handle; 2013 handle_t *handle;
2014 2014
2015 /* Initialize quotas before so that eventual writes go in 2015 /* Initialize quotas before so that eventual writes go in
2016 * separate transaction */ 2016 * separate transaction */
2017 DQUOT_INIT(dentry->d_inode); 2017 DQUOT_INIT(dentry->d_inode);
2018 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb)); 2018 handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb));
2019 if (IS_ERR(handle)) 2019 if (IS_ERR(handle))
2020 return PTR_ERR(handle); 2020 return PTR_ERR(handle);
2021 2021
2022 retval = -ENOENT; 2022 retval = -ENOENT;
2023 bh = ext3_find_entry (dentry, &de); 2023 bh = ext4_find_entry (dentry, &de);
2024 if (!bh) 2024 if (!bh)
2025 goto end_rmdir; 2025 goto end_rmdir;
2026 2026
@@ -2037,11 +2037,11 @@ static int ext3_rmdir (struct inode * dir, struct dentry *dentry)
2037 if (!empty_dir (inode)) 2037 if (!empty_dir (inode))
2038 goto end_rmdir; 2038 goto end_rmdir;
2039 2039
2040 retval = ext3_delete_entry(handle, dir, de, bh); 2040 retval = ext4_delete_entry(handle, dir, de, bh);
2041 if (retval) 2041 if (retval)
2042 goto end_rmdir; 2042 goto end_rmdir;
2043 if (inode->i_nlink != 2) 2043 if (inode->i_nlink != 2)
2044 ext3_warning (inode->i_sb, "ext3_rmdir", 2044 ext4_warning (inode->i_sb, "ext4_rmdir",
2045 "empty directory has nlink!=2 (%d)", 2045 "empty directory has nlink!=2 (%d)",
2046 inode->i_nlink); 2046 inode->i_nlink);
2047 inode->i_version++; 2047 inode->i_version++;
@@ -2050,31 +2050,31 @@ static int ext3_rmdir (struct inode * dir, struct dentry *dentry)
2050 * zero will ensure that the right thing happens during any 2050 * zero will ensure that the right thing happens during any
2051 * recovery. */ 2051 * recovery. */
2052 inode->i_size = 0; 2052 inode->i_size = 0;
2053 ext3_orphan_add(handle, inode); 2053 ext4_orphan_add(handle, inode);
2054 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC; 2054 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
2055 ext3_mark_inode_dirty(handle, inode); 2055 ext4_mark_inode_dirty(handle, inode);
2056 drop_nlink(dir); 2056 drop_nlink(dir);
2057 ext3_update_dx_flag(dir); 2057 ext4_update_dx_flag(dir);
2058 ext3_mark_inode_dirty(handle, dir); 2058 ext4_mark_inode_dirty(handle, dir);
2059 2059
2060end_rmdir: 2060end_rmdir:
2061 ext3_journal_stop(handle); 2061 ext4_journal_stop(handle);
2062 brelse (bh); 2062 brelse (bh);
2063 return retval; 2063 return retval;
2064} 2064}
2065 2065
2066static int ext3_unlink(struct inode * dir, struct dentry *dentry) 2066static int ext4_unlink(struct inode * dir, struct dentry *dentry)
2067{ 2067{
2068 int retval; 2068 int retval;
2069 struct inode * inode; 2069 struct inode * inode;
2070 struct buffer_head * bh; 2070 struct buffer_head * bh;
2071 struct ext3_dir_entry_2 * de; 2071 struct ext4_dir_entry_2 * de;
2072 handle_t *handle; 2072 handle_t *handle;
2073 2073
2074 /* Initialize quotas before so that eventual writes go 2074 /* Initialize quotas before so that eventual writes go
2075 * in separate transaction */ 2075 * in separate transaction */
2076 DQUOT_INIT(dentry->d_inode); 2076 DQUOT_INIT(dentry->d_inode);
2077 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb)); 2077 handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb));
2078 if (IS_ERR(handle)) 2078 if (IS_ERR(handle))
2079 return PTR_ERR(handle); 2079 return PTR_ERR(handle);
2080 2080
@@ -2082,7 +2082,7 @@ static int ext3_unlink(struct inode * dir, struct dentry *dentry)
2082 handle->h_sync = 1; 2082 handle->h_sync = 1;
2083 2083
2084 retval = -ENOENT; 2084 retval = -ENOENT;
2085 bh = ext3_find_entry (dentry, &de); 2085 bh = ext4_find_entry (dentry, &de);
2086 if (!bh) 2086 if (!bh)
2087 goto end_unlink; 2087 goto end_unlink;
2088 2088
@@ -2093,31 +2093,31 @@ static int ext3_unlink(struct inode * dir, struct dentry *dentry)
2093 goto end_unlink; 2093 goto end_unlink;
2094 2094
2095 if (!inode->i_nlink) { 2095 if (!inode->i_nlink) {
2096 ext3_warning (inode->i_sb, "ext3_unlink", 2096 ext4_warning (inode->i_sb, "ext4_unlink",
2097 "Deleting nonexistent file (%lu), %d", 2097 "Deleting nonexistent file (%lu), %d",
2098 inode->i_ino, inode->i_nlink); 2098 inode->i_ino, inode->i_nlink);
2099 inode->i_nlink = 1; 2099 inode->i_nlink = 1;
2100 } 2100 }
2101 retval = ext3_delete_entry(handle, dir, de, bh); 2101 retval = ext4_delete_entry(handle, dir, de, bh);
2102 if (retval) 2102 if (retval)
2103 goto end_unlink; 2103 goto end_unlink;
2104 dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC; 2104 dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
2105 ext3_update_dx_flag(dir); 2105 ext4_update_dx_flag(dir);
2106 ext3_mark_inode_dirty(handle, dir); 2106 ext4_mark_inode_dirty(handle, dir);
2107 drop_nlink(inode); 2107 drop_nlink(inode);
2108 if (!inode->i_nlink) 2108 if (!inode->i_nlink)
2109 ext3_orphan_add(handle, inode); 2109 ext4_orphan_add(handle, inode);
2110 inode->i_ctime = dir->i_ctime; 2110 inode->i_ctime = dir->i_ctime;
2111 ext3_mark_inode_dirty(handle, inode); 2111 ext4_mark_inode_dirty(handle, inode);
2112 retval = 0; 2112 retval = 0;
2113 2113
2114end_unlink: 2114end_unlink:
2115 ext3_journal_stop(handle); 2115 ext4_journal_stop(handle);
2116 brelse (bh); 2116 brelse (bh);
2117 return retval; 2117 return retval;
2118} 2118}
2119 2119
2120static int ext3_symlink (struct inode * dir, 2120static int ext4_symlink (struct inode * dir,
2121 struct dentry *dentry, const char * symname) 2121 struct dentry *dentry, const char * symname)
2122{ 2122{
2123 handle_t *handle; 2123 handle_t *handle;
@@ -2129,63 +2129,63 @@ static int ext3_symlink (struct inode * dir,
2129 return -ENAMETOOLONG; 2129 return -ENAMETOOLONG;
2130 2130
2131retry: 2131retry:
2132 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + 2132 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
2133 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 5 + 2133 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 5 +
2134 2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); 2134 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
2135 if (IS_ERR(handle)) 2135 if (IS_ERR(handle))
2136 return PTR_ERR(handle); 2136 return PTR_ERR(handle);
2137 2137
2138 if (IS_DIRSYNC(dir)) 2138 if (IS_DIRSYNC(dir))
2139 handle->h_sync = 1; 2139 handle->h_sync = 1;
2140 2140
2141 inode = ext3_new_inode (handle, dir, S_IFLNK|S_IRWXUGO); 2141 inode = ext4_new_inode (handle, dir, S_IFLNK|S_IRWXUGO);
2142 err = PTR_ERR(inode); 2142 err = PTR_ERR(inode);
2143 if (IS_ERR(inode)) 2143 if (IS_ERR(inode))
2144 goto out_stop; 2144 goto out_stop;
2145 2145
2146 if (l > sizeof (EXT3_I(inode)->i_data)) { 2146 if (l > sizeof (EXT4_I(inode)->i_data)) {
2147 inode->i_op = &ext3_symlink_inode_operations; 2147 inode->i_op = &ext4_symlink_inode_operations;
2148 ext3_set_aops(inode); 2148 ext4_set_aops(inode);
2149 /* 2149 /*
2150 * page_symlink() calls into ext3_prepare/commit_write. 2150 * page_symlink() calls into ext4_prepare/commit_write.
2151 * We have a transaction open. All is sweetness. It also sets 2151 * We have a transaction open. All is sweetness. It also sets
2152 * i_size in generic_commit_write(). 2152 * i_size in generic_commit_write().
2153 */ 2153 */
2154 err = __page_symlink(inode, symname, l, 2154 err = __page_symlink(inode, symname, l,
2155 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS); 2155 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS);
2156 if (err) { 2156 if (err) {
2157 ext3_dec_count(handle, inode); 2157 ext4_dec_count(handle, inode);
2158 ext3_mark_inode_dirty(handle, inode); 2158 ext4_mark_inode_dirty(handle, inode);
2159 iput (inode); 2159 iput (inode);
2160 goto out_stop; 2160 goto out_stop;
2161 } 2161 }
2162 } else { 2162 } else {
2163 inode->i_op = &ext3_fast_symlink_inode_operations; 2163 inode->i_op = &ext4_fast_symlink_inode_operations;
2164 memcpy((char*)&EXT3_I(inode)->i_data,symname,l); 2164 memcpy((char*)&EXT4_I(inode)->i_data,symname,l);
2165 inode->i_size = l-1; 2165 inode->i_size = l-1;
2166 } 2166 }
2167 EXT3_I(inode)->i_disksize = inode->i_size; 2167 EXT4_I(inode)->i_disksize = inode->i_size;
2168 err = ext3_add_nondir(handle, dentry, inode); 2168 err = ext4_add_nondir(handle, dentry, inode);
2169out_stop: 2169out_stop:
2170 ext3_journal_stop(handle); 2170 ext4_journal_stop(handle);
2171 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries)) 2171 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
2172 goto retry; 2172 goto retry;
2173 return err; 2173 return err;
2174} 2174}
2175 2175
2176static int ext3_link (struct dentry * old_dentry, 2176static int ext4_link (struct dentry * old_dentry,
2177 struct inode * dir, struct dentry *dentry) 2177 struct inode * dir, struct dentry *dentry)
2178{ 2178{
2179 handle_t *handle; 2179 handle_t *handle;
2180 struct inode *inode = old_dentry->d_inode; 2180 struct inode *inode = old_dentry->d_inode;
2181 int err, retries = 0; 2181 int err, retries = 0;
2182 2182
2183 if (inode->i_nlink >= EXT3_LINK_MAX) 2183 if (inode->i_nlink >= EXT4_LINK_MAX)
2184 return -EMLINK; 2184 return -EMLINK;
2185 2185
2186retry: 2186retry:
2187 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + 2187 handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
2188 EXT3_INDEX_EXTRA_TRANS_BLOCKS); 2188 EXT4_INDEX_EXTRA_TRANS_BLOCKS);
2189 if (IS_ERR(handle)) 2189 if (IS_ERR(handle))
2190 return PTR_ERR(handle); 2190 return PTR_ERR(handle);
2191 2191
@@ -2193,31 +2193,31 @@ retry:
2193 handle->h_sync = 1; 2193 handle->h_sync = 1;
2194 2194
2195 inode->i_ctime = CURRENT_TIME_SEC; 2195 inode->i_ctime = CURRENT_TIME_SEC;
2196 ext3_inc_count(handle, inode); 2196 ext4_inc_count(handle, inode);
2197 atomic_inc(&inode->i_count); 2197 atomic_inc(&inode->i_count);
2198 2198
2199 err = ext3_add_nondir(handle, dentry, inode); 2199 err = ext4_add_nondir(handle, dentry, inode);
2200 ext3_journal_stop(handle); 2200 ext4_journal_stop(handle);
2201 if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries)) 2201 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
2202 goto retry; 2202 goto retry;
2203 return err; 2203 return err;
2204} 2204}
2205 2205
2206#define PARENT_INO(buffer) \ 2206#define PARENT_INO(buffer) \
2207 ((struct ext3_dir_entry_2 *) ((char *) buffer + \ 2207 ((struct ext4_dir_entry_2 *) ((char *) buffer + \
2208 le16_to_cpu(((struct ext3_dir_entry_2 *) buffer)->rec_len)))->inode 2208 le16_to_cpu(((struct ext4_dir_entry_2 *) buffer)->rec_len)))->inode
2209 2209
2210/* 2210/*
2211 * Anybody can rename anything with this: the permission checks are left to the 2211 * Anybody can rename anything with this: the permission checks are left to the
2212 * higher-level routines. 2212 * higher-level routines.
2213 */ 2213 */
2214static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry, 2214static int ext4_rename (struct inode * old_dir, struct dentry *old_dentry,
2215 struct inode * new_dir,struct dentry *new_dentry) 2215 struct inode * new_dir,struct dentry *new_dentry)
2216{ 2216{
2217 handle_t *handle; 2217 handle_t *handle;
2218 struct inode * old_inode, * new_inode; 2218 struct inode * old_inode, * new_inode;
2219 struct buffer_head * old_bh, * new_bh, * dir_bh; 2219 struct buffer_head * old_bh, * new_bh, * dir_bh;
2220 struct ext3_dir_entry_2 * old_de, * new_de; 2220 struct ext4_dir_entry_2 * old_de, * new_de;
2221 int retval; 2221 int retval;
2222 2222
2223 old_bh = new_bh = dir_bh = NULL; 2223 old_bh = new_bh = dir_bh = NULL;
@@ -2226,16 +2226,16 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
2226 * in separate transaction */ 2226 * in separate transaction */
2227 if (new_dentry->d_inode) 2227 if (new_dentry->d_inode)
2228 DQUOT_INIT(new_dentry->d_inode); 2228 DQUOT_INIT(new_dentry->d_inode);
2229 handle = ext3_journal_start(old_dir, 2 * 2229 handle = ext4_journal_start(old_dir, 2 *
2230 EXT3_DATA_TRANS_BLOCKS(old_dir->i_sb) + 2230 EXT4_DATA_TRANS_BLOCKS(old_dir->i_sb) +
2231 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 2); 2231 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 2);
2232 if (IS_ERR(handle)) 2232 if (IS_ERR(handle))
2233 return PTR_ERR(handle); 2233 return PTR_ERR(handle);
2234 2234
2235 if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir)) 2235 if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
2236 handle->h_sync = 1; 2236 handle->h_sync = 1;
2237 2237
2238 old_bh = ext3_find_entry (old_dentry, &old_de); 2238 old_bh = ext4_find_entry (old_dentry, &old_de);
2239 /* 2239 /*
2240 * Check for inode number is _not_ due to possible IO errors. 2240 * Check for inode number is _not_ due to possible IO errors.
2241 * We might rmdir the source, keep it as pwd of some process 2241 * We might rmdir the source, keep it as pwd of some process
@@ -2248,7 +2248,7 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
2248 goto end_rename; 2248 goto end_rename;
2249 2249
2250 new_inode = new_dentry->d_inode; 2250 new_inode = new_dentry->d_inode;
2251 new_bh = ext3_find_entry (new_dentry, &new_de); 2251 new_bh = ext4_find_entry (new_dentry, &new_de);
2252 if (new_bh) { 2252 if (new_bh) {
2253 if (!new_inode) { 2253 if (!new_inode) {
2254 brelse (new_bh); 2254 brelse (new_bh);
@@ -2262,30 +2262,30 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
2262 goto end_rename; 2262 goto end_rename;
2263 } 2263 }
2264 retval = -EIO; 2264 retval = -EIO;
2265 dir_bh = ext3_bread (handle, old_inode, 0, 0, &retval); 2265 dir_bh = ext4_bread (handle, old_inode, 0, 0, &retval);
2266 if (!dir_bh) 2266 if (!dir_bh)
2267 goto end_rename; 2267 goto end_rename;
2268 if (le32_to_cpu(PARENT_INO(dir_bh->b_data)) != old_dir->i_ino) 2268 if (le32_to_cpu(PARENT_INO(dir_bh->b_data)) != old_dir->i_ino)
2269 goto end_rename; 2269 goto end_rename;
2270 retval = -EMLINK; 2270 retval = -EMLINK;
2271 if (!new_inode && new_dir!=old_dir && 2271 if (!new_inode && new_dir!=old_dir &&
2272 new_dir->i_nlink >= EXT3_LINK_MAX) 2272 new_dir->i_nlink >= EXT4_LINK_MAX)
2273 goto end_rename; 2273 goto end_rename;
2274 } 2274 }
2275 if (!new_bh) { 2275 if (!new_bh) {
2276 retval = ext3_add_entry (handle, new_dentry, old_inode); 2276 retval = ext4_add_entry (handle, new_dentry, old_inode);
2277 if (retval) 2277 if (retval)
2278 goto end_rename; 2278 goto end_rename;
2279 } else { 2279 } else {
2280 BUFFER_TRACE(new_bh, "get write access"); 2280 BUFFER_TRACE(new_bh, "get write access");
2281 ext3_journal_get_write_access(handle, new_bh); 2281 ext4_journal_get_write_access(handle, new_bh);
2282 new_de->inode = cpu_to_le32(old_inode->i_ino); 2282 new_de->inode = cpu_to_le32(old_inode->i_ino);
2283 if (EXT3_HAS_INCOMPAT_FEATURE(new_dir->i_sb, 2283 if (EXT4_HAS_INCOMPAT_FEATURE(new_dir->i_sb,
2284 EXT3_FEATURE_INCOMPAT_FILETYPE)) 2284 EXT4_FEATURE_INCOMPAT_FILETYPE))
2285 new_de->file_type = old_de->file_type; 2285 new_de->file_type = old_de->file_type;
2286 new_dir->i_version++; 2286 new_dir->i_version++;
2287 BUFFER_TRACE(new_bh, "call ext3_journal_dirty_metadata"); 2287 BUFFER_TRACE(new_bh, "call ext4_journal_dirty_metadata");
2288 ext3_journal_dirty_metadata(handle, new_bh); 2288 ext4_journal_dirty_metadata(handle, new_bh);
2289 brelse(new_bh); 2289 brelse(new_bh);
2290 new_bh = NULL; 2290 new_bh = NULL;
2291 } 2291 }
@@ -2295,7 +2295,7 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
2295 * rename. 2295 * rename.
2296 */ 2296 */
2297 old_inode->i_ctime = CURRENT_TIME_SEC; 2297 old_inode->i_ctime = CURRENT_TIME_SEC;
2298 ext3_mark_inode_dirty(handle, old_inode); 2298 ext4_mark_inode_dirty(handle, old_inode);
2299 2299
2300 /* 2300 /*
2301 * ok, that's it 2301 * ok, that's it
@@ -2303,24 +2303,24 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
2303 if (le32_to_cpu(old_de->inode) != old_inode->i_ino || 2303 if (le32_to_cpu(old_de->inode) != old_inode->i_ino ||
2304 old_de->name_len != old_dentry->d_name.len || 2304 old_de->name_len != old_dentry->d_name.len ||
2305 strncmp(old_de->name, old_dentry->d_name.name, old_de->name_len) || 2305 strncmp(old_de->name, old_dentry->d_name.name, old_de->name_len) ||
2306 (retval = ext3_delete_entry(handle, old_dir, 2306 (retval = ext4_delete_entry(handle, old_dir,
2307 old_de, old_bh)) == -ENOENT) { 2307 old_de, old_bh)) == -ENOENT) {
2308 /* old_de could have moved from under us during htree split, so 2308 /* old_de could have moved from under us during htree split, so
2309 * make sure that we are deleting the right entry. We might 2309 * make sure that we are deleting the right entry. We might
2310 * also be pointing to a stale entry in the unused part of 2310 * also be pointing to a stale entry in the unused part of
2311 * old_bh so just checking inum and the name isn't enough. */ 2311 * old_bh so just checking inum and the name isn't enough. */
2312 struct buffer_head *old_bh2; 2312 struct buffer_head *old_bh2;
2313 struct ext3_dir_entry_2 *old_de2; 2313 struct ext4_dir_entry_2 *old_de2;
2314 2314
2315 old_bh2 = ext3_find_entry(old_dentry, &old_de2); 2315 old_bh2 = ext4_find_entry(old_dentry, &old_de2);
2316 if (old_bh2) { 2316 if (old_bh2) {
2317 retval = ext3_delete_entry(handle, old_dir, 2317 retval = ext4_delete_entry(handle, old_dir,
2318 old_de2, old_bh2); 2318 old_de2, old_bh2);
2319 brelse(old_bh2); 2319 brelse(old_bh2);
2320 } 2320 }
2321 } 2321 }
2322 if (retval) { 2322 if (retval) {
2323 ext3_warning(old_dir->i_sb, "ext3_rename", 2323 ext4_warning(old_dir->i_sb, "ext4_rename",
2324 "Deleting old file (%lu), %d, error=%d", 2324 "Deleting old file (%lu), %d, error=%d",
2325 old_dir->i_ino, old_dir->i_nlink, retval); 2325 old_dir->i_ino, old_dir->i_nlink, retval);
2326 } 2326 }
@@ -2330,27 +2330,27 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
2330 new_inode->i_ctime = CURRENT_TIME_SEC; 2330 new_inode->i_ctime = CURRENT_TIME_SEC;
2331 } 2331 }
2332 old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC; 2332 old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC;
2333 ext3_update_dx_flag(old_dir); 2333 ext4_update_dx_flag(old_dir);
2334 if (dir_bh) { 2334 if (dir_bh) {
2335 BUFFER_TRACE(dir_bh, "get_write_access"); 2335 BUFFER_TRACE(dir_bh, "get_write_access");
2336 ext3_journal_get_write_access(handle, dir_bh); 2336 ext4_journal_get_write_access(handle, dir_bh);
2337 PARENT_INO(dir_bh->b_data) = cpu_to_le32(new_dir->i_ino); 2337 PARENT_INO(dir_bh->b_data) = cpu_to_le32(new_dir->i_ino);
2338 BUFFER_TRACE(dir_bh, "call ext3_journal_dirty_metadata"); 2338 BUFFER_TRACE(dir_bh, "call ext4_journal_dirty_metadata");
2339 ext3_journal_dirty_metadata(handle, dir_bh); 2339 ext4_journal_dirty_metadata(handle, dir_bh);
2340 drop_nlink(old_dir); 2340 drop_nlink(old_dir);
2341 if (new_inode) { 2341 if (new_inode) {
2342 drop_nlink(new_inode); 2342 drop_nlink(new_inode);
2343 } else { 2343 } else {
2344 inc_nlink(new_dir); 2344 inc_nlink(new_dir);
2345 ext3_update_dx_flag(new_dir); 2345 ext4_update_dx_flag(new_dir);
2346 ext3_mark_inode_dirty(handle, new_dir); 2346 ext4_mark_inode_dirty(handle, new_dir);
2347 } 2347 }
2348 } 2348 }
2349 ext3_mark_inode_dirty(handle, old_dir); 2349 ext4_mark_inode_dirty(handle, old_dir);
2350 if (new_inode) { 2350 if (new_inode) {
2351 ext3_mark_inode_dirty(handle, new_inode); 2351 ext4_mark_inode_dirty(handle, new_inode);
2352 if (!new_inode->i_nlink) 2352 if (!new_inode->i_nlink)
2353 ext3_orphan_add(handle, new_inode); 2353 ext4_orphan_add(handle, new_inode);
2354 } 2354 }
2355 retval = 0; 2355 retval = 0;
2356 2356
@@ -2358,40 +2358,40 @@ end_rename:
2358 brelse (dir_bh); 2358 brelse (dir_bh);
2359 brelse (old_bh); 2359 brelse (old_bh);
2360 brelse (new_bh); 2360 brelse (new_bh);
2361 ext3_journal_stop(handle); 2361 ext4_journal_stop(handle);
2362 return retval; 2362 return retval;
2363} 2363}
2364 2364
2365/* 2365/*
2366 * directories can handle most operations... 2366 * directories can handle most operations...
2367 */ 2367 */
2368struct inode_operations ext3_dir_inode_operations = { 2368struct inode_operations ext4_dir_inode_operations = {
2369 .create = ext3_create, 2369 .create = ext4_create,
2370 .lookup = ext3_lookup, 2370 .lookup = ext4_lookup,
2371 .link = ext3_link, 2371 .link = ext4_link,
2372 .unlink = ext3_unlink, 2372 .unlink = ext4_unlink,
2373 .symlink = ext3_symlink, 2373 .symlink = ext4_symlink,
2374 .mkdir = ext3_mkdir, 2374 .mkdir = ext4_mkdir,
2375 .rmdir = ext3_rmdir, 2375 .rmdir = ext4_rmdir,
2376 .mknod = ext3_mknod, 2376 .mknod = ext4_mknod,
2377 .rename = ext3_rename, 2377 .rename = ext4_rename,
2378 .setattr = ext3_setattr, 2378 .setattr = ext4_setattr,
2379#ifdef CONFIG_EXT3_FS_XATTR 2379#ifdef CONFIG_EXT4DEV_FS_XATTR
2380 .setxattr = generic_setxattr, 2380 .setxattr = generic_setxattr,
2381 .getxattr = generic_getxattr, 2381 .getxattr = generic_getxattr,
2382 .listxattr = ext3_listxattr, 2382 .listxattr = ext4_listxattr,
2383 .removexattr = generic_removexattr, 2383 .removexattr = generic_removexattr,
2384#endif 2384#endif
2385 .permission = ext3_permission, 2385 .permission = ext4_permission,
2386}; 2386};
2387 2387
2388struct inode_operations ext3_special_inode_operations = { 2388struct inode_operations ext4_special_inode_operations = {
2389 .setattr = ext3_setattr, 2389 .setattr = ext4_setattr,
2390#ifdef CONFIG_EXT3_FS_XATTR 2390#ifdef CONFIG_EXT4DEV_FS_XATTR
2391 .setxattr = generic_setxattr, 2391 .setxattr = generic_setxattr,
2392 .getxattr = generic_getxattr, 2392 .getxattr = generic_getxattr,
2393 .listxattr = ext3_listxattr, 2393 .listxattr = ext4_listxattr,
2394 .removexattr = generic_removexattr, 2394 .removexattr = generic_removexattr,
2395#endif 2395#endif
2396 .permission = ext3_permission, 2396 .permission = ext4_permission,
2397}; 2397};
diff --git a/fs/ext4/namei.h b/fs/ext4/namei.h
index f2ce2b0065c..5e4dfff36a0 100644
--- a/fs/ext4/namei.h
+++ b/fs/ext4/namei.h
@@ -1,8 +1,8 @@
1/* linux/fs/ext3/namei.h 1/* linux/fs/ext4/namei.h
2 * 2 *
3 * Copyright (C) 2005 Simtec Electronics 3 * Copyright (C) 2005 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk> 4 * Ben Dooks <ben@simtec.co.uk>
5 * 5 *
6*/ 6*/
7 7
8extern struct dentry *ext3_get_parent(struct dentry *child); 8extern struct dentry *ext4_get_parent(struct dentry *child);
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index b73cba12f79..4a47895d9d6 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * linux/fs/ext3/resize.c 2 * linux/fs/ext4/resize.c
3 * 3 *
4 * Support for resizing an ext3 filesystem while it is mounted. 4 * Support for resizing an ext4 filesystem while it is mounted.
5 * 5 *
6 * Copyright (C) 2001, 2002 Andreas Dilger <adilger@clusterfs.com> 6 * Copyright (C) 2001, 2002 Andreas Dilger <adilger@clusterfs.com>
7 * 7 *
@@ -9,11 +9,11 @@
9 */ 9 */
10 10
11 11
12#define EXT3FS_DEBUG 12#define EXT4FS_DEBUG
13 13
14#include <linux/sched.h> 14#include <linux/sched.h>
15#include <linux/smp_lock.h> 15#include <linux/smp_lock.h>
16#include <linux/ext3_jbd.h> 16#include <linux/ext4_jbd.h>
17 17
18#include <linux/errno.h> 18#include <linux/errno.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
@@ -23,87 +23,87 @@
23#define inside(b, first, last) ((b) >= (first) && (b) < (last)) 23#define inside(b, first, last) ((b) >= (first) && (b) < (last))
24 24
25static int verify_group_input(struct super_block *sb, 25static int verify_group_input(struct super_block *sb,
26 struct ext3_new_group_data *input) 26 struct ext4_new_group_data *input)
27{ 27{
28 struct ext3_sb_info *sbi = EXT3_SB(sb); 28 struct ext4_sb_info *sbi = EXT4_SB(sb);
29 struct ext3_super_block *es = sbi->s_es; 29 struct ext4_super_block *es = sbi->s_es;
30 ext3_fsblk_t start = le32_to_cpu(es->s_blocks_count); 30 ext4_fsblk_t start = le32_to_cpu(es->s_blocks_count);
31 ext3_fsblk_t end = start + input->blocks_count; 31 ext4_fsblk_t end = start + input->blocks_count;
32 unsigned group = input->group; 32 unsigned group = input->group;
33 ext3_fsblk_t itend = input->inode_table + sbi->s_itb_per_group; 33 ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
34 unsigned overhead = ext3_bg_has_super(sb, group) ? 34 unsigned overhead = ext4_bg_has_super(sb, group) ?
35 (1 + ext3_bg_num_gdb(sb, group) + 35 (1 + ext4_bg_num_gdb(sb, group) +
36 le16_to_cpu(es->s_reserved_gdt_blocks)) : 0; 36 le16_to_cpu(es->s_reserved_gdt_blocks)) : 0;
37 ext3_fsblk_t metaend = start + overhead; 37 ext4_fsblk_t metaend = start + overhead;
38 struct buffer_head *bh = NULL; 38 struct buffer_head *bh = NULL;
39 ext3_grpblk_t free_blocks_count; 39 ext4_grpblk_t free_blocks_count;
40 int err = -EINVAL; 40 int err = -EINVAL;
41 41
42 input->free_blocks_count = free_blocks_count = 42 input->free_blocks_count = free_blocks_count =
43 input->blocks_count - 2 - overhead - sbi->s_itb_per_group; 43 input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
44 44
45 if (test_opt(sb, DEBUG)) 45 if (test_opt(sb, DEBUG))
46 printk(KERN_DEBUG "EXT3-fs: adding %s group %u: %u blocks " 46 printk(KERN_DEBUG "EXT4-fs: adding %s group %u: %u blocks "
47 "(%d free, %u reserved)\n", 47 "(%d free, %u reserved)\n",
48 ext3_bg_has_super(sb, input->group) ? "normal" : 48 ext4_bg_has_super(sb, input->group) ? "normal" :
49 "no-super", input->group, input->blocks_count, 49 "no-super", input->group, input->blocks_count,
50 free_blocks_count, input->reserved_blocks); 50 free_blocks_count, input->reserved_blocks);
51 51
52 if (group != sbi->s_groups_count) 52 if (group != sbi->s_groups_count)
53 ext3_warning(sb, __FUNCTION__, 53 ext4_warning(sb, __FUNCTION__,
54 "Cannot add at group %u (only %lu groups)", 54 "Cannot add at group %u (only %lu groups)",
55 input->group, sbi->s_groups_count); 55 input->group, sbi->s_groups_count);
56 else if ((start - le32_to_cpu(es->s_first_data_block)) % 56 else if ((start - le32_to_cpu(es->s_first_data_block)) %
57 EXT3_BLOCKS_PER_GROUP(sb)) 57 EXT4_BLOCKS_PER_GROUP(sb))
58 ext3_warning(sb, __FUNCTION__, "Last group not full"); 58 ext4_warning(sb, __FUNCTION__, "Last group not full");
59 else if (input->reserved_blocks > input->blocks_count / 5) 59 else if (input->reserved_blocks > input->blocks_count / 5)
60 ext3_warning(sb, __FUNCTION__, "Reserved blocks too high (%u)", 60 ext4_warning(sb, __FUNCTION__, "Reserved blocks too high (%u)",
61 input->reserved_blocks); 61 input->reserved_blocks);
62 else if (free_blocks_count < 0) 62 else if (free_blocks_count < 0)
63 ext3_warning(sb, __FUNCTION__, "Bad blocks count %u", 63 ext4_warning(sb, __FUNCTION__, "Bad blocks count %u",
64 input->blocks_count); 64 input->blocks_count);
65 else if (!(bh = sb_bread(sb, end - 1))) 65 else if (!(bh = sb_bread(sb, end - 1)))
66 ext3_warning(sb, __FUNCTION__, 66 ext4_warning(sb, __FUNCTION__,
67 "Cannot read last block ("E3FSBLK")", 67 "Cannot read last block ("E3FSBLK")",
68 end - 1); 68 end - 1);
69 else if (outside(input->block_bitmap, start, end)) 69 else if (outside(input->block_bitmap, start, end))
70 ext3_warning(sb, __FUNCTION__, 70 ext4_warning(sb, __FUNCTION__,
71 "Block bitmap not in group (block %u)", 71 "Block bitmap not in group (block %u)",
72 input->block_bitmap); 72 input->block_bitmap);
73 else if (outside(input->inode_bitmap, start, end)) 73 else if (outside(input->inode_bitmap, start, end))
74 ext3_warning(sb, __FUNCTION__, 74 ext4_warning(sb, __FUNCTION__,
75 "Inode bitmap not in group (block %u)", 75 "Inode bitmap not in group (block %u)",
76 input->inode_bitmap); 76 input->inode_bitmap);
77 else if (outside(input->inode_table, start, end) || 77 else if (outside(input->inode_table, start, end) ||
78 outside(itend - 1, start, end)) 78 outside(itend - 1, start, end))
79 ext3_warning(sb, __FUNCTION__, 79 ext4_warning(sb, __FUNCTION__,
80 "Inode table not in group (blocks %u-"E3FSBLK")", 80 "Inode table not in group (blocks %u-"E3FSBLK")",
81 input->inode_table, itend - 1); 81 input->inode_table, itend - 1);
82 else if (input->inode_bitmap == input->block_bitmap) 82 else if (input->inode_bitmap == input->block_bitmap)
83 ext3_warning(sb, __FUNCTION__, 83 ext4_warning(sb, __FUNCTION__,
84 "Block bitmap same as inode bitmap (%u)", 84 "Block bitmap same as inode bitmap (%u)",
85 input->block_bitmap); 85 input->block_bitmap);
86 else if (inside(input->block_bitmap, input->inode_table, itend)) 86 else if (inside(input->block_bitmap, input->inode_table, itend))
87 ext3_warning(sb, __FUNCTION__, 87 ext4_warning(sb, __FUNCTION__,
88 "Block bitmap (%u) in inode table (%u-"E3FSBLK")", 88 "Block bitmap (%u) in inode table (%u-"E3FSBLK")",
89 input->block_bitmap, input->inode_table, itend-1); 89 input->block_bitmap, input->inode_table, itend-1);
90 else if (inside(input->inode_bitmap, input->inode_table, itend)) 90 else if (inside(input->inode_bitmap, input->inode_table, itend))
91 ext3_warning(sb, __FUNCTION__, 91 ext4_warning(sb, __FUNCTION__,
92 "Inode bitmap (%u) in inode table (%u-"E3FSBLK")", 92 "Inode bitmap (%u) in inode table (%u-"E3FSBLK")",
93 input->inode_bitmap, input->inode_table, itend-1); 93 input->inode_bitmap, input->inode_table, itend-1);
94 else if (inside(input->block_bitmap, start, metaend)) 94 else if (inside(input->block_bitmap, start, metaend))
95 ext3_warning(sb, __FUNCTION__, 95 ext4_warning(sb, __FUNCTION__,
96 "Block bitmap (%u) in GDT table" 96 "Block bitmap (%u) in GDT table"
97 " ("E3FSBLK"-"E3FSBLK")", 97 " ("E3FSBLK"-"E3FSBLK")",
98 input->block_bitmap, start, metaend - 1); 98 input->block_bitmap, start, metaend - 1);
99 else if (inside(input->inode_bitmap, start, metaend)) 99 else if (inside(input->inode_bitmap, start, metaend))
100 ext3_warning(sb, __FUNCTION__, 100 ext4_warning(sb, __FUNCTION__,
101 "Inode bitmap (%u) in GDT table" 101 "Inode bitmap (%u) in GDT table"
102 " ("E3FSBLK"-"E3FSBLK")", 102 " ("E3FSBLK"-"E3FSBLK")",
103 input->inode_bitmap, start, metaend - 1); 103 input->inode_bitmap, start, metaend - 1);
104 else if (inside(input->inode_table, start, metaend) || 104 else if (inside(input->inode_table, start, metaend) ||
105 inside(itend - 1, start, metaend)) 105 inside(itend - 1, start, metaend))
106 ext3_warning(sb, __FUNCTION__, 106 ext4_warning(sb, __FUNCTION__,
107 "Inode table (%u-"E3FSBLK") overlaps" 107 "Inode table (%u-"E3FSBLK") overlaps"
108 "GDT table ("E3FSBLK"-"E3FSBLK")", 108 "GDT table ("E3FSBLK"-"E3FSBLK")",
109 input->inode_table, itend - 1, start, metaend - 1); 109 input->inode_table, itend - 1, start, metaend - 1);
@@ -115,7 +115,7 @@ static int verify_group_input(struct super_block *sb,
115} 115}
116 116
117static struct buffer_head *bclean(handle_t *handle, struct super_block *sb, 117static struct buffer_head *bclean(handle_t *handle, struct super_block *sb,
118 ext3_fsblk_t blk) 118 ext4_fsblk_t blk)
119{ 119{
120 struct buffer_head *bh; 120 struct buffer_head *bh;
121 int err; 121 int err;
@@ -123,7 +123,7 @@ static struct buffer_head *bclean(handle_t *handle, struct super_block *sb,
123 bh = sb_getblk(sb, blk); 123 bh = sb_getblk(sb, blk);
124 if (!bh) 124 if (!bh)
125 return ERR_PTR(-EIO); 125 return ERR_PTR(-EIO);
126 if ((err = ext3_journal_get_write_access(handle, bh))) { 126 if ((err = ext4_journal_get_write_access(handle, bh))) {
127 brelse(bh); 127 brelse(bh);
128 bh = ERR_PTR(err); 128 bh = ERR_PTR(err);
129 } else { 129 } else {
@@ -148,9 +148,9 @@ static void mark_bitmap_end(int start_bit, int end_bit, char *bitmap)
148 if (start_bit >= end_bit) 148 if (start_bit >= end_bit)
149 return; 149 return;
150 150
151 ext3_debug("mark end bits +%d through +%d used\n", start_bit, end_bit); 151 ext4_debug("mark end bits +%d through +%d used\n", start_bit, end_bit);
152 for (i = start_bit; i < ((start_bit + 7) & ~7UL); i++) 152 for (i = start_bit; i < ((start_bit + 7) & ~7UL); i++)
153 ext3_set_bit(i, bitmap); 153 ext4_set_bit(i, bitmap);
154 if (i < end_bit) 154 if (i < end_bit)
155 memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3); 155 memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3);
156} 156}
@@ -163,21 +163,21 @@ static void mark_bitmap_end(int start_bit, int end_bit, char *bitmap)
163 * If any part of this fails, we simply abort the resize. 163 * If any part of this fails, we simply abort the resize.
164 */ 164 */
165static int setup_new_group_blocks(struct super_block *sb, 165static int setup_new_group_blocks(struct super_block *sb,
166 struct ext3_new_group_data *input) 166 struct ext4_new_group_data *input)
167{ 167{
168 struct ext3_sb_info *sbi = EXT3_SB(sb); 168 struct ext4_sb_info *sbi = EXT4_SB(sb);
169 ext3_fsblk_t start = ext3_group_first_block_no(sb, input->group); 169 ext4_fsblk_t start = ext4_group_first_block_no(sb, input->group);
170 int reserved_gdb = ext3_bg_has_super(sb, input->group) ? 170 int reserved_gdb = ext4_bg_has_super(sb, input->group) ?
171 le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) : 0; 171 le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) : 0;
172 unsigned long gdblocks = ext3_bg_num_gdb(sb, input->group); 172 unsigned long gdblocks = ext4_bg_num_gdb(sb, input->group);
173 struct buffer_head *bh; 173 struct buffer_head *bh;
174 handle_t *handle; 174 handle_t *handle;
175 ext3_fsblk_t block; 175 ext4_fsblk_t block;
176 ext3_grpblk_t bit; 176 ext4_grpblk_t bit;
177 int i; 177 int i;
178 int err = 0, err2; 178 int err = 0, err2;
179 179
180 handle = ext3_journal_start_sb(sb, reserved_gdb + gdblocks + 180 handle = ext4_journal_start_sb(sb, reserved_gdb + gdblocks +
181 2 + sbi->s_itb_per_group); 181 2 + sbi->s_itb_per_group);
182 if (IS_ERR(handle)) 182 if (IS_ERR(handle))
183 return PTR_ERR(handle); 183 return PTR_ERR(handle);
@@ -193,9 +193,9 @@ static int setup_new_group_blocks(struct super_block *sb,
193 goto exit_journal; 193 goto exit_journal;
194 } 194 }
195 195
196 if (ext3_bg_has_super(sb, input->group)) { 196 if (ext4_bg_has_super(sb, input->group)) {
197 ext3_debug("mark backup superblock %#04lx (+0)\n", start); 197 ext4_debug("mark backup superblock %#04lx (+0)\n", start);
198 ext3_set_bit(0, bh->b_data); 198 ext4_set_bit(0, bh->b_data);
199 } 199 }
200 200
201 /* Copy all of the GDT blocks into the backup in this group */ 201 /* Copy all of the GDT blocks into the backup in this group */
@@ -203,14 +203,14 @@ static int setup_new_group_blocks(struct super_block *sb,
203 i < gdblocks; i++, block++, bit++) { 203 i < gdblocks; i++, block++, bit++) {
204 struct buffer_head *gdb; 204 struct buffer_head *gdb;
205 205
206 ext3_debug("update backup group %#04lx (+%d)\n", block, bit); 206 ext4_debug("update backup group %#04lx (+%d)\n", block, bit);
207 207
208 gdb = sb_getblk(sb, block); 208 gdb = sb_getblk(sb, block);
209 if (!gdb) { 209 if (!gdb) {
210 err = -EIO; 210 err = -EIO;
211 goto exit_bh; 211 goto exit_bh;
212 } 212 }
213 if ((err = ext3_journal_get_write_access(handle, gdb))) { 213 if ((err = ext4_journal_get_write_access(handle, gdb))) {
214 brelse(gdb); 214 brelse(gdb);
215 goto exit_bh; 215 goto exit_bh;
216 } 216 }
@@ -218,8 +218,8 @@ static int setup_new_group_blocks(struct super_block *sb,
218 memcpy(gdb->b_data, sbi->s_group_desc[i]->b_data, bh->b_size); 218 memcpy(gdb->b_data, sbi->s_group_desc[i]->b_data, bh->b_size);
219 set_buffer_uptodate(gdb); 219 set_buffer_uptodate(gdb);
220 unlock_buffer(bh); 220 unlock_buffer(bh);
221 ext3_journal_dirty_metadata(handle, gdb); 221 ext4_journal_dirty_metadata(handle, gdb);
222 ext3_set_bit(bit, bh->b_data); 222 ext4_set_bit(bit, bh->b_data);
223 brelse(gdb); 223 brelse(gdb);
224 } 224 }
225 225
@@ -228,59 +228,59 @@ static int setup_new_group_blocks(struct super_block *sb,
228 i < reserved_gdb; i++, block++, bit++) { 228 i < reserved_gdb; i++, block++, bit++) {
229 struct buffer_head *gdb; 229 struct buffer_head *gdb;
230 230
231 ext3_debug("clear reserved block %#04lx (+%d)\n", block, bit); 231 ext4_debug("clear reserved block %#04lx (+%d)\n", block, bit);
232 232
233 if (IS_ERR(gdb = bclean(handle, sb, block))) { 233 if (IS_ERR(gdb = bclean(handle, sb, block))) {
234 err = PTR_ERR(bh); 234 err = PTR_ERR(bh);
235 goto exit_bh; 235 goto exit_bh;
236 } 236 }
237 ext3_journal_dirty_metadata(handle, gdb); 237 ext4_journal_dirty_metadata(handle, gdb);
238 ext3_set_bit(bit, bh->b_data); 238 ext4_set_bit(bit, bh->b_data);
239 brelse(gdb); 239 brelse(gdb);
240 } 240 }
241 ext3_debug("mark block bitmap %#04x (+%ld)\n", input->block_bitmap, 241 ext4_debug("mark block bitmap %#04x (+%ld)\n", input->block_bitmap,
242 input->block_bitmap - start); 242 input->block_bitmap - start);
243 ext3_set_bit(input->block_bitmap - start, bh->b_data); 243 ext4_set_bit(input->block_bitmap - start, bh->b_data);
244 ext3_debug("mark inode bitmap %#04x (+%ld)\n", input->inode_bitmap, 244 ext4_debug("mark inode bitmap %#04x (+%ld)\n", input->inode_bitmap,
245 input->inode_bitmap - start); 245 input->inode_bitmap - start);
246 ext3_set_bit(input->inode_bitmap - start, bh->b_data); 246 ext4_set_bit(input->inode_bitmap - start, bh->b_data);
247 247
248 /* Zero out all of the inode table blocks */ 248 /* Zero out all of the inode table blocks */
249 for (i = 0, block = input->inode_table, bit = block - start; 249 for (i = 0, block = input->inode_table, bit = block - start;
250 i < sbi->s_itb_per_group; i++, bit++, block++) { 250 i < sbi->s_itb_per_group; i++, bit++, block++) {
251 struct buffer_head *it; 251 struct buffer_head *it;
252 252
253 ext3_debug("clear inode block %#04lx (+%d)\n", block, bit); 253 ext4_debug("clear inode block %#04lx (+%d)\n", block, bit);
254 if (IS_ERR(it = bclean(handle, sb, block))) { 254 if (IS_ERR(it = bclean(handle, sb, block))) {
255 err = PTR_ERR(it); 255 err = PTR_ERR(it);
256 goto exit_bh; 256 goto exit_bh;
257 } 257 }
258 ext3_journal_dirty_metadata(handle, it); 258 ext4_journal_dirty_metadata(handle, it);
259 brelse(it); 259 brelse(it);
260 ext3_set_bit(bit, bh->b_data); 260 ext4_set_bit(bit, bh->b_data);
261 } 261 }
262 mark_bitmap_end(input->blocks_count, EXT3_BLOCKS_PER_GROUP(sb), 262 mark_bitmap_end(input->blocks_count, EXT4_BLOCKS_PER_GROUP(sb),
263 bh->b_data); 263 bh->b_data);
264 ext3_journal_dirty_metadata(handle, bh); 264 ext4_journal_dirty_metadata(handle, bh);
265 brelse(bh); 265 brelse(bh);
266 266
267 /* Mark unused entries in inode bitmap used */ 267 /* Mark unused entries in inode bitmap used */
268 ext3_debug("clear inode bitmap %#04x (+%ld)\n", 268 ext4_debug("clear inode bitmap %#04x (+%ld)\n",
269 input->inode_bitmap, input->inode_bitmap - start); 269 input->inode_bitmap, input->inode_bitmap - start);
270 if (IS_ERR(bh = bclean(handle, sb, input->inode_bitmap))) { 270 if (IS_ERR(bh = bclean(handle, sb, input->inode_bitmap))) {
271 err = PTR_ERR(bh); 271 err = PTR_ERR(bh);
272 goto exit_journal; 272 goto exit_journal;
273 } 273 }
274 274
275 mark_bitmap_end(EXT3_INODES_PER_GROUP(sb), EXT3_BLOCKS_PER_GROUP(sb), 275 mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), EXT4_BLOCKS_PER_GROUP(sb),
276 bh->b_data); 276 bh->b_data);
277 ext3_journal_dirty_metadata(handle, bh); 277 ext4_journal_dirty_metadata(handle, bh);
278exit_bh: 278exit_bh:
279 brelse(bh); 279 brelse(bh);
280 280
281exit_journal: 281exit_journal:
282 unlock_super(sb); 282 unlock_super(sb);
283 if ((err2 = ext3_journal_stop(handle)) && !err) 283 if ((err2 = ext4_journal_stop(handle)) && !err)
284 err = err2; 284 err = err2;
285 285
286 return err; 286 return err;
@@ -288,20 +288,20 @@ exit_journal:
288 288
289/* 289/*
290 * Iterate through the groups which hold BACKUP superblock/GDT copies in an 290 * Iterate through the groups which hold BACKUP superblock/GDT copies in an
291 * ext3 filesystem. The counters should be initialized to 1, 5, and 7 before 291 * ext4 filesystem. The counters should be initialized to 1, 5, and 7 before
292 * calling this for the first time. In a sparse filesystem it will be the 292 * calling this for the first time. In a sparse filesystem it will be the
293 * sequence of powers of 3, 5, and 7: 1, 3, 5, 7, 9, 25, 27, 49, 81, ... 293 * sequence of powers of 3, 5, and 7: 1, 3, 5, 7, 9, 25, 27, 49, 81, ...
294 * For a non-sparse filesystem it will be every group: 1, 2, 3, 4, ... 294 * For a non-sparse filesystem it will be every group: 1, 2, 3, 4, ...
295 */ 295 */
296static unsigned ext3_list_backups(struct super_block *sb, unsigned *three, 296static unsigned ext4_list_backups(struct super_block *sb, unsigned *three,
297 unsigned *five, unsigned *seven) 297 unsigned *five, unsigned *seven)
298{ 298{
299 unsigned *min = three; 299 unsigned *min = three;
300 int mult = 3; 300 int mult = 3;
301 unsigned ret; 301 unsigned ret;
302 302
303 if (!EXT3_HAS_RO_COMPAT_FEATURE(sb, 303 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
304 EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)) { 304 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
305 ret = *min; 305 ret = *min;
306 *min += 1; 306 *min += 1;
307 return ret; 307 return ret;
@@ -330,8 +330,8 @@ static unsigned ext3_list_backups(struct super_block *sb, unsigned *three,
330static int verify_reserved_gdb(struct super_block *sb, 330static int verify_reserved_gdb(struct super_block *sb,
331 struct buffer_head *primary) 331 struct buffer_head *primary)
332{ 332{
333 const ext3_fsblk_t blk = primary->b_blocknr; 333 const ext4_fsblk_t blk = primary->b_blocknr;
334 const unsigned long end = EXT3_SB(sb)->s_groups_count; 334 const unsigned long end = EXT4_SB(sb)->s_groups_count;
335 unsigned three = 1; 335 unsigned three = 1;
336 unsigned five = 5; 336 unsigned five = 5;
337 unsigned seven = 7; 337 unsigned seven = 7;
@@ -339,16 +339,16 @@ static int verify_reserved_gdb(struct super_block *sb,
339 __le32 *p = (__le32 *)primary->b_data; 339 __le32 *p = (__le32 *)primary->b_data;
340 int gdbackups = 0; 340 int gdbackups = 0;
341 341
342 while ((grp = ext3_list_backups(sb, &three, &five, &seven)) < end) { 342 while ((grp = ext4_list_backups(sb, &three, &five, &seven)) < end) {
343 if (le32_to_cpu(*p++) != grp * EXT3_BLOCKS_PER_GROUP(sb) + blk){ 343 if (le32_to_cpu(*p++) != grp * EXT4_BLOCKS_PER_GROUP(sb) + blk){
344 ext3_warning(sb, __FUNCTION__, 344 ext4_warning(sb, __FUNCTION__,
345 "reserved GDT "E3FSBLK 345 "reserved GDT "E3FSBLK
346 " missing grp %d ("E3FSBLK")", 346 " missing grp %d ("E3FSBLK")",
347 blk, grp, 347 blk, grp,
348 grp * EXT3_BLOCKS_PER_GROUP(sb) + blk); 348 grp * EXT4_BLOCKS_PER_GROUP(sb) + blk);
349 return -EINVAL; 349 return -EINVAL;
350 } 350 }
351 if (++gdbackups > EXT3_ADDR_PER_BLOCK(sb)) 351 if (++gdbackups > EXT4_ADDR_PER_BLOCK(sb))
352 return -EFBIG; 352 return -EFBIG;
353 } 353 }
354 354
@@ -369,23 +369,23 @@ static int verify_reserved_gdb(struct super_block *sb,
369 * fail once we start modifying the data on disk, because JBD has no rollback. 369 * fail once we start modifying the data on disk, because JBD has no rollback.
370 */ 370 */
371static int add_new_gdb(handle_t *handle, struct inode *inode, 371static int add_new_gdb(handle_t *handle, struct inode *inode,
372 struct ext3_new_group_data *input, 372 struct ext4_new_group_data *input,
373 struct buffer_head **primary) 373 struct buffer_head **primary)
374{ 374{
375 struct super_block *sb = inode->i_sb; 375 struct super_block *sb = inode->i_sb;
376 struct ext3_super_block *es = EXT3_SB(sb)->s_es; 376 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
377 unsigned long gdb_num = input->group / EXT3_DESC_PER_BLOCK(sb); 377 unsigned long gdb_num = input->group / EXT4_DESC_PER_BLOCK(sb);
378 ext3_fsblk_t gdblock = EXT3_SB(sb)->s_sbh->b_blocknr + 1 + gdb_num; 378 ext4_fsblk_t gdblock = EXT4_SB(sb)->s_sbh->b_blocknr + 1 + gdb_num;
379 struct buffer_head **o_group_desc, **n_group_desc; 379 struct buffer_head **o_group_desc, **n_group_desc;
380 struct buffer_head *dind; 380 struct buffer_head *dind;
381 int gdbackups; 381 int gdbackups;
382 struct ext3_iloc iloc; 382 struct ext4_iloc iloc;
383 __le32 *data; 383 __le32 *data;
384 int err; 384 int err;
385 385
386 if (test_opt(sb, DEBUG)) 386 if (test_opt(sb, DEBUG))
387 printk(KERN_DEBUG 387 printk(KERN_DEBUG
388 "EXT3-fs: ext3_add_new_gdb: adding group block %lu\n", 388 "EXT4-fs: ext4_add_new_gdb: adding group block %lu\n",
389 gdb_num); 389 gdb_num);
390 390
391 /* 391 /*
@@ -393,11 +393,11 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
393 * because the user tools have no way of handling this. Probably a 393 * because the user tools have no way of handling this. Probably a
394 * bad time to do it anyways. 394 * bad time to do it anyways.
395 */ 395 */
396 if (EXT3_SB(sb)->s_sbh->b_blocknr != 396 if (EXT4_SB(sb)->s_sbh->b_blocknr !=
397 le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block)) { 397 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) {
398 ext3_warning(sb, __FUNCTION__, 398 ext4_warning(sb, __FUNCTION__,
399 "won't resize using backup superblock at %llu", 399 "won't resize using backup superblock at %llu",
400 (unsigned long long)EXT3_SB(sb)->s_sbh->b_blocknr); 400 (unsigned long long)EXT4_SB(sb)->s_sbh->b_blocknr);
401 return -EPERM; 401 return -EPERM;
402 } 402 }
403 403
@@ -410,7 +410,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
410 goto exit_bh; 410 goto exit_bh;
411 } 411 }
412 412
413 data = EXT3_I(inode)->i_data + EXT3_DIND_BLOCK; 413 data = EXT4_I(inode)->i_data + EXT4_DIND_BLOCK;
414 dind = sb_bread(sb, le32_to_cpu(*data)); 414 dind = sb_bread(sb, le32_to_cpu(*data));
415 if (!dind) { 415 if (!dind) {
416 err = -EIO; 416 err = -EIO;
@@ -418,32 +418,32 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
418 } 418 }
419 419
420 data = (__le32 *)dind->b_data; 420 data = (__le32 *)dind->b_data;
421 if (le32_to_cpu(data[gdb_num % EXT3_ADDR_PER_BLOCK(sb)]) != gdblock) { 421 if (le32_to_cpu(data[gdb_num % EXT4_ADDR_PER_BLOCK(sb)]) != gdblock) {
422 ext3_warning(sb, __FUNCTION__, 422 ext4_warning(sb, __FUNCTION__,
423 "new group %u GDT block "E3FSBLK" not reserved", 423 "new group %u GDT block "E3FSBLK" not reserved",
424 input->group, gdblock); 424 input->group, gdblock);
425 err = -EINVAL; 425 err = -EINVAL;
426 goto exit_dind; 426 goto exit_dind;
427 } 427 }
428 428
429 if ((err = ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh))) 429 if ((err = ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh)))
430 goto exit_dind; 430 goto exit_dind;
431 431
432 if ((err = ext3_journal_get_write_access(handle, *primary))) 432 if ((err = ext4_journal_get_write_access(handle, *primary)))
433 goto exit_sbh; 433 goto exit_sbh;
434 434
435 if ((err = ext3_journal_get_write_access(handle, dind))) 435 if ((err = ext4_journal_get_write_access(handle, dind)))
436 goto exit_primary; 436 goto exit_primary;
437 437
438 /* ext3_reserve_inode_write() gets a reference on the iloc */ 438 /* ext4_reserve_inode_write() gets a reference on the iloc */
439 if ((err = ext3_reserve_inode_write(handle, inode, &iloc))) 439 if ((err = ext4_reserve_inode_write(handle, inode, &iloc)))
440 goto exit_dindj; 440 goto exit_dindj;
441 441
442 n_group_desc = kmalloc((gdb_num + 1) * sizeof(struct buffer_head *), 442 n_group_desc = kmalloc((gdb_num + 1) * sizeof(struct buffer_head *),
443 GFP_KERNEL); 443 GFP_KERNEL);
444 if (!n_group_desc) { 444 if (!n_group_desc) {
445 err = -ENOMEM; 445 err = -ENOMEM;
446 ext3_warning (sb, __FUNCTION__, 446 ext4_warning (sb, __FUNCTION__,
447 "not enough memory for %lu groups", gdb_num + 1); 447 "not enough memory for %lu groups", gdb_num + 1);
448 goto exit_inode; 448 goto exit_inode;
449 } 449 }
@@ -457,43 +457,43 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
457 * these blocks, because they are marked as in-use from being in the 457 * these blocks, because they are marked as in-use from being in the
458 * reserved inode, and will become GDT blocks (primary and backup). 458 * reserved inode, and will become GDT blocks (primary and backup).
459 */ 459 */
460 data[gdb_num % EXT3_ADDR_PER_BLOCK(sb)] = 0; 460 data[gdb_num % EXT4_ADDR_PER_BLOCK(sb)] = 0;
461 ext3_journal_dirty_metadata(handle, dind); 461 ext4_journal_dirty_metadata(handle, dind);
462 brelse(dind); 462 brelse(dind);
463 inode->i_blocks -= (gdbackups + 1) * sb->s_blocksize >> 9; 463 inode->i_blocks -= (gdbackups + 1) * sb->s_blocksize >> 9;
464 ext3_mark_iloc_dirty(handle, inode, &iloc); 464 ext4_mark_iloc_dirty(handle, inode, &iloc);
465 memset((*primary)->b_data, 0, sb->s_blocksize); 465 memset((*primary)->b_data, 0, sb->s_blocksize);
466 ext3_journal_dirty_metadata(handle, *primary); 466 ext4_journal_dirty_metadata(handle, *primary);
467 467
468 o_group_desc = EXT3_SB(sb)->s_group_desc; 468 o_group_desc = EXT4_SB(sb)->s_group_desc;
469 memcpy(n_group_desc, o_group_desc, 469 memcpy(n_group_desc, o_group_desc,
470 EXT3_SB(sb)->s_gdb_count * sizeof(struct buffer_head *)); 470 EXT4_SB(sb)->s_gdb_count * sizeof(struct buffer_head *));
471 n_group_desc[gdb_num] = *primary; 471 n_group_desc[gdb_num] = *primary;
472 EXT3_SB(sb)->s_group_desc = n_group_desc; 472 EXT4_SB(sb)->s_group_desc = n_group_desc;
473 EXT3_SB(sb)->s_gdb_count++; 473 EXT4_SB(sb)->s_gdb_count++;
474 kfree(o_group_desc); 474 kfree(o_group_desc);
475 475
476 es->s_reserved_gdt_blocks = 476 es->s_reserved_gdt_blocks =
477 cpu_to_le16(le16_to_cpu(es->s_reserved_gdt_blocks) - 1); 477 cpu_to_le16(le16_to_cpu(es->s_reserved_gdt_blocks) - 1);
478 ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); 478 ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh);
479 479
480 return 0; 480 return 0;
481 481
482exit_inode: 482exit_inode:
483 //ext3_journal_release_buffer(handle, iloc.bh); 483 //ext4_journal_release_buffer(handle, iloc.bh);
484 brelse(iloc.bh); 484 brelse(iloc.bh);
485exit_dindj: 485exit_dindj:
486 //ext3_journal_release_buffer(handle, dind); 486 //ext4_journal_release_buffer(handle, dind);
487exit_primary: 487exit_primary:
488 //ext3_journal_release_buffer(handle, *primary); 488 //ext4_journal_release_buffer(handle, *primary);
489exit_sbh: 489exit_sbh:
490 //ext3_journal_release_buffer(handle, *primary); 490 //ext4_journal_release_buffer(handle, *primary);
491exit_dind: 491exit_dind:
492 brelse(dind); 492 brelse(dind);
493exit_bh: 493exit_bh:
494 brelse(*primary); 494 brelse(*primary);
495 495
496 ext3_debug("leaving with error %d\n", err); 496 ext4_debug("leaving with error %d\n", err);
497 return err; 497 return err;
498} 498}
499 499
@@ -511,14 +511,14 @@ exit_bh:
511 * backup GDT blocks are stored in their reserved primary GDT block. 511 * backup GDT blocks are stored in their reserved primary GDT block.
512 */ 512 */
513static int reserve_backup_gdb(handle_t *handle, struct inode *inode, 513static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
514 struct ext3_new_group_data *input) 514 struct ext4_new_group_data *input)
515{ 515{
516 struct super_block *sb = inode->i_sb; 516 struct super_block *sb = inode->i_sb;
517 int reserved_gdb =le16_to_cpu(EXT3_SB(sb)->s_es->s_reserved_gdt_blocks); 517 int reserved_gdb =le16_to_cpu(EXT4_SB(sb)->s_es->s_reserved_gdt_blocks);
518 struct buffer_head **primary; 518 struct buffer_head **primary;
519 struct buffer_head *dind; 519 struct buffer_head *dind;
520 struct ext3_iloc iloc; 520 struct ext4_iloc iloc;
521 ext3_fsblk_t blk; 521 ext4_fsblk_t blk;
522 __le32 *data, *end; 522 __le32 *data, *end;
523 int gdbackups = 0; 523 int gdbackups = 0;
524 int res, i; 524 int res, i;
@@ -528,21 +528,21 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
528 if (!primary) 528 if (!primary)
529 return -ENOMEM; 529 return -ENOMEM;
530 530
531 data = EXT3_I(inode)->i_data + EXT3_DIND_BLOCK; 531 data = EXT4_I(inode)->i_data + EXT4_DIND_BLOCK;
532 dind = sb_bread(sb, le32_to_cpu(*data)); 532 dind = sb_bread(sb, le32_to_cpu(*data));
533 if (!dind) { 533 if (!dind) {
534 err = -EIO; 534 err = -EIO;
535 goto exit_free; 535 goto exit_free;
536 } 536 }
537 537
538 blk = EXT3_SB(sb)->s_sbh->b_blocknr + 1 + EXT3_SB(sb)->s_gdb_count; 538 blk = EXT4_SB(sb)->s_sbh->b_blocknr + 1 + EXT4_SB(sb)->s_gdb_count;
539 data = (__le32 *)dind->b_data + EXT3_SB(sb)->s_gdb_count; 539 data = (__le32 *)dind->b_data + EXT4_SB(sb)->s_gdb_count;
540 end = (__le32 *)dind->b_data + EXT3_ADDR_PER_BLOCK(sb); 540 end = (__le32 *)dind->b_data + EXT4_ADDR_PER_BLOCK(sb);
541 541
542 /* Get each reserved primary GDT block and verify it holds backups */ 542 /* Get each reserved primary GDT block and verify it holds backups */
543 for (res = 0; res < reserved_gdb; res++, blk++) { 543 for (res = 0; res < reserved_gdb; res++, blk++) {
544 if (le32_to_cpu(*data) != blk) { 544 if (le32_to_cpu(*data) != blk) {
545 ext3_warning(sb, __FUNCTION__, 545 ext4_warning(sb, __FUNCTION__,
546 "reserved block "E3FSBLK 546 "reserved block "E3FSBLK
547 " not at offset %ld", 547 " not at offset %ld",
548 blk, 548 blk,
@@ -565,24 +565,24 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
565 } 565 }
566 566
567 for (i = 0; i < reserved_gdb; i++) { 567 for (i = 0; i < reserved_gdb; i++) {
568 if ((err = ext3_journal_get_write_access(handle, primary[i]))) { 568 if ((err = ext4_journal_get_write_access(handle, primary[i]))) {
569 /* 569 /*
570 int j; 570 int j;
571 for (j = 0; j < i; j++) 571 for (j = 0; j < i; j++)
572 ext3_journal_release_buffer(handle, primary[j]); 572 ext4_journal_release_buffer(handle, primary[j]);
573 */ 573 */
574 goto exit_bh; 574 goto exit_bh;
575 } 575 }
576 } 576 }
577 577
578 if ((err = ext3_reserve_inode_write(handle, inode, &iloc))) 578 if ((err = ext4_reserve_inode_write(handle, inode, &iloc)))
579 goto exit_bh; 579 goto exit_bh;
580 580
581 /* 581 /*
582 * Finally we can add each of the reserved backup GDT blocks from 582 * Finally we can add each of the reserved backup GDT blocks from
583 * the new group to its reserved primary GDT block. 583 * the new group to its reserved primary GDT block.
584 */ 584 */
585 blk = input->group * EXT3_BLOCKS_PER_GROUP(sb); 585 blk = input->group * EXT4_BLOCKS_PER_GROUP(sb);
586 for (i = 0; i < reserved_gdb; i++) { 586 for (i = 0; i < reserved_gdb; i++) {
587 int err2; 587 int err2;
588 data = (__le32 *)primary[i]->b_data; 588 data = (__le32 *)primary[i]->b_data;
@@ -590,12 +590,12 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
590 primary[i]->b_blocknr, gdbackups, 590 primary[i]->b_blocknr, gdbackups,
591 blk + primary[i]->b_blocknr); */ 591 blk + primary[i]->b_blocknr); */
592 data[gdbackups] = cpu_to_le32(blk + primary[i]->b_blocknr); 592 data[gdbackups] = cpu_to_le32(blk + primary[i]->b_blocknr);
593 err2 = ext3_journal_dirty_metadata(handle, primary[i]); 593 err2 = ext4_journal_dirty_metadata(handle, primary[i]);
594 if (!err) 594 if (!err)
595 err = err2; 595 err = err2;
596 } 596 }
597 inode->i_blocks += reserved_gdb * sb->s_blocksize >> 9; 597 inode->i_blocks += reserved_gdb * sb->s_blocksize >> 9;
598 ext3_mark_iloc_dirty(handle, inode, &iloc); 598 ext4_mark_iloc_dirty(handle, inode, &iloc);
599 599
600exit_bh: 600exit_bh:
601 while (--res >= 0) 601 while (--res >= 0)
@@ -609,7 +609,7 @@ exit_free:
609} 609}
610 610
611/* 611/*
612 * Update the backup copies of the ext3 metadata. These don't need to be part 612 * Update the backup copies of the ext4 metadata. These don't need to be part
613 * of the main resize transaction, because e2fsck will re-write them if there 613 * of the main resize transaction, because e2fsck will re-write them if there
614 * is a problem (basically only OOM will cause a problem). However, we 614 * is a problem (basically only OOM will cause a problem). However, we
615 * _should_ update the backups if possible, in case the primary gets trashed 615 * _should_ update the backups if possible, in case the primary gets trashed
@@ -626,9 +626,9 @@ exit_free:
626static void update_backups(struct super_block *sb, 626static void update_backups(struct super_block *sb,
627 int blk_off, char *data, int size) 627 int blk_off, char *data, int size)
628{ 628{
629 struct ext3_sb_info *sbi = EXT3_SB(sb); 629 struct ext4_sb_info *sbi = EXT4_SB(sb);
630 const unsigned long last = sbi->s_groups_count; 630 const unsigned long last = sbi->s_groups_count;
631 const int bpg = EXT3_BLOCKS_PER_GROUP(sb); 631 const int bpg = EXT4_BLOCKS_PER_GROUP(sb);
632 unsigned three = 1; 632 unsigned three = 1;
633 unsigned five = 5; 633 unsigned five = 5;
634 unsigned seven = 7; 634 unsigned seven = 7;
@@ -637,20 +637,20 @@ static void update_backups(struct super_block *sb,
637 handle_t *handle; 637 handle_t *handle;
638 int err = 0, err2; 638 int err = 0, err2;
639 639
640 handle = ext3_journal_start_sb(sb, EXT3_MAX_TRANS_DATA); 640 handle = ext4_journal_start_sb(sb, EXT4_MAX_TRANS_DATA);
641 if (IS_ERR(handle)) { 641 if (IS_ERR(handle)) {
642 group = 1; 642 group = 1;
643 err = PTR_ERR(handle); 643 err = PTR_ERR(handle);
644 goto exit_err; 644 goto exit_err;
645 } 645 }
646 646
647 while ((group = ext3_list_backups(sb, &three, &five, &seven)) < last) { 647 while ((group = ext4_list_backups(sb, &three, &five, &seven)) < last) {
648 struct buffer_head *bh; 648 struct buffer_head *bh;
649 649
650 /* Out of journal space, and can't get more - abort - so sad */ 650 /* Out of journal space, and can't get more - abort - so sad */
651 if (handle->h_buffer_credits == 0 && 651 if (handle->h_buffer_credits == 0 &&
652 ext3_journal_extend(handle, EXT3_MAX_TRANS_DATA) && 652 ext4_journal_extend(handle, EXT4_MAX_TRANS_DATA) &&
653 (err = ext3_journal_restart(handle, EXT3_MAX_TRANS_DATA))) 653 (err = ext4_journal_restart(handle, EXT4_MAX_TRANS_DATA)))
654 break; 654 break;
655 655
656 bh = sb_getblk(sb, group * bpg + blk_off); 656 bh = sb_getblk(sb, group * bpg + blk_off);
@@ -658,9 +658,9 @@ static void update_backups(struct super_block *sb,
658 err = -EIO; 658 err = -EIO;
659 break; 659 break;
660 } 660 }
661 ext3_debug("update metadata backup %#04lx\n", 661 ext4_debug("update metadata backup %#04lx\n",
662 (unsigned long)bh->b_blocknr); 662 (unsigned long)bh->b_blocknr);
663 if ((err = ext3_journal_get_write_access(handle, bh))) 663 if ((err = ext4_journal_get_write_access(handle, bh)))
664 break; 664 break;
665 lock_buffer(bh); 665 lock_buffer(bh);
666 memcpy(bh->b_data, data, size); 666 memcpy(bh->b_data, data, size);
@@ -668,10 +668,10 @@ static void update_backups(struct super_block *sb,
668 memset(bh->b_data + size, 0, rest); 668 memset(bh->b_data + size, 0, rest);
669 set_buffer_uptodate(bh); 669 set_buffer_uptodate(bh);
670 unlock_buffer(bh); 670 unlock_buffer(bh);
671 ext3_journal_dirty_metadata(handle, bh); 671 ext4_journal_dirty_metadata(handle, bh);
672 brelse(bh); 672 brelse(bh);
673 } 673 }
674 if ((err2 = ext3_journal_stop(handle)) && !err) 674 if ((err2 = ext4_journal_stop(handle)) && !err)
675 err = err2; 675 err = err2;
676 676
677 /* 677 /*
@@ -686,11 +686,11 @@ static void update_backups(struct super_block *sb,
686 */ 686 */
687exit_err: 687exit_err:
688 if (err) { 688 if (err) {
689 ext3_warning(sb, __FUNCTION__, 689 ext4_warning(sb, __FUNCTION__,
690 "can't update backup for group %d (err %d), " 690 "can't update backup for group %d (err %d), "
691 "forcing fsck on next reboot", group, err); 691 "forcing fsck on next reboot", group, err);
692 sbi->s_mount_state &= ~EXT3_VALID_FS; 692 sbi->s_mount_state &= ~EXT4_VALID_FS;
693 sbi->s_es->s_state &= cpu_to_le16(~EXT3_VALID_FS); 693 sbi->s_es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
694 mark_buffer_dirty(sbi->s_sbh); 694 mark_buffer_dirty(sbi->s_sbh);
695 } 695 }
696} 696}
@@ -708,51 +708,51 @@ exit_err:
708 * not really "added" the group at all. We re-check that we are still 708 * not really "added" the group at all. We re-check that we are still
709 * adding in the last group in case things have changed since verifying. 709 * adding in the last group in case things have changed since verifying.
710 */ 710 */
711int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) 711int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
712{ 712{
713 struct ext3_sb_info *sbi = EXT3_SB(sb); 713 struct ext4_sb_info *sbi = EXT4_SB(sb);
714 struct ext3_super_block *es = sbi->s_es; 714 struct ext4_super_block *es = sbi->s_es;
715 int reserved_gdb = ext3_bg_has_super(sb, input->group) ? 715 int reserved_gdb = ext4_bg_has_super(sb, input->group) ?
716 le16_to_cpu(es->s_reserved_gdt_blocks) : 0; 716 le16_to_cpu(es->s_reserved_gdt_blocks) : 0;
717 struct buffer_head *primary = NULL; 717 struct buffer_head *primary = NULL;
718 struct ext3_group_desc *gdp; 718 struct ext4_group_desc *gdp;
719 struct inode *inode = NULL; 719 struct inode *inode = NULL;
720 handle_t *handle; 720 handle_t *handle;
721 int gdb_off, gdb_num; 721 int gdb_off, gdb_num;
722 int err, err2; 722 int err, err2;
723 723
724 gdb_num = input->group / EXT3_DESC_PER_BLOCK(sb); 724 gdb_num = input->group / EXT4_DESC_PER_BLOCK(sb);
725 gdb_off = input->group % EXT3_DESC_PER_BLOCK(sb); 725 gdb_off = input->group % EXT4_DESC_PER_BLOCK(sb);
726 726
727 if (gdb_off == 0 && !EXT3_HAS_RO_COMPAT_FEATURE(sb, 727 if (gdb_off == 0 && !EXT4_HAS_RO_COMPAT_FEATURE(sb,
728 EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)) { 728 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
729 ext3_warning(sb, __FUNCTION__, 729 ext4_warning(sb, __FUNCTION__,
730 "Can't resize non-sparse filesystem further"); 730 "Can't resize non-sparse filesystem further");
731 return -EPERM; 731 return -EPERM;
732 } 732 }
733 733
734 if (le32_to_cpu(es->s_blocks_count) + input->blocks_count < 734 if (le32_to_cpu(es->s_blocks_count) + input->blocks_count <
735 le32_to_cpu(es->s_blocks_count)) { 735 le32_to_cpu(es->s_blocks_count)) {
736 ext3_warning(sb, __FUNCTION__, "blocks_count overflow\n"); 736 ext4_warning(sb, __FUNCTION__, "blocks_count overflow\n");
737 return -EINVAL; 737 return -EINVAL;
738 } 738 }
739 739
740 if (le32_to_cpu(es->s_inodes_count) + EXT3_INODES_PER_GROUP(sb) < 740 if (le32_to_cpu(es->s_inodes_count) + EXT4_INODES_PER_GROUP(sb) <
741 le32_to_cpu(es->s_inodes_count)) { 741 le32_to_cpu(es->s_inodes_count)) {
742 ext3_warning(sb, __FUNCTION__, "inodes_count overflow\n"); 742 ext4_warning(sb, __FUNCTION__, "inodes_count overflow\n");
743 return -EINVAL; 743 return -EINVAL;
744 } 744 }
745 745
746 if (reserved_gdb || gdb_off == 0) { 746 if (reserved_gdb || gdb_off == 0) {
747 if (!EXT3_HAS_COMPAT_FEATURE(sb, 747 if (!EXT4_HAS_COMPAT_FEATURE(sb,
748 EXT3_FEATURE_COMPAT_RESIZE_INODE)){ 748 EXT4_FEATURE_COMPAT_RESIZE_INODE)){
749 ext3_warning(sb, __FUNCTION__, 749 ext4_warning(sb, __FUNCTION__,
750 "No reserved GDT blocks, can't resize"); 750 "No reserved GDT blocks, can't resize");
751 return -EPERM; 751 return -EPERM;
752 } 752 }
753 inode = iget(sb, EXT3_RESIZE_INO); 753 inode = iget(sb, EXT4_RESIZE_INO);
754 if (!inode || is_bad_inode(inode)) { 754 if (!inode || is_bad_inode(inode)) {
755 ext3_warning(sb, __FUNCTION__, 755 ext4_warning(sb, __FUNCTION__,
756 "Error opening resize inode"); 756 "Error opening resize inode");
757 iput(inode); 757 iput(inode);
758 return -ENOENT; 758 return -ENOENT;
@@ -772,8 +772,8 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
772 * are adding a group with superblock/GDT backups we will also 772 * are adding a group with superblock/GDT backups we will also
773 * modify each of the reserved GDT dindirect blocks. 773 * modify each of the reserved GDT dindirect blocks.
774 */ 774 */
775 handle = ext3_journal_start_sb(sb, 775 handle = ext4_journal_start_sb(sb,
776 ext3_bg_has_super(sb, input->group) ? 776 ext4_bg_has_super(sb, input->group) ?
777 3 + reserved_gdb : 4); 777 3 + reserved_gdb : 4);
778 if (IS_ERR(handle)) { 778 if (IS_ERR(handle)) {
779 err = PTR_ERR(handle); 779 err = PTR_ERR(handle);
@@ -782,13 +782,13 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
782 782
783 lock_super(sb); 783 lock_super(sb);
784 if (input->group != sbi->s_groups_count) { 784 if (input->group != sbi->s_groups_count) {
785 ext3_warning(sb, __FUNCTION__, 785 ext4_warning(sb, __FUNCTION__,
786 "multiple resizers run on filesystem!"); 786 "multiple resizers run on filesystem!");
787 err = -EBUSY; 787 err = -EBUSY;
788 goto exit_journal; 788 goto exit_journal;
789 } 789 }
790 790
791 if ((err = ext3_journal_get_write_access(handle, sbi->s_sbh))) 791 if ((err = ext4_journal_get_write_access(handle, sbi->s_sbh)))
792 goto exit_journal; 792 goto exit_journal;
793 793
794 /* 794 /*
@@ -799,10 +799,10 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
799 */ 799 */
800 if (gdb_off) { 800 if (gdb_off) {
801 primary = sbi->s_group_desc[gdb_num]; 801 primary = sbi->s_group_desc[gdb_num];
802 if ((err = ext3_journal_get_write_access(handle, primary))) 802 if ((err = ext4_journal_get_write_access(handle, primary)))
803 goto exit_journal; 803 goto exit_journal;
804 804
805 if (reserved_gdb && ext3_bg_num_gdb(sb, input->group) && 805 if (reserved_gdb && ext4_bg_num_gdb(sb, input->group) &&
806 (err = reserve_backup_gdb(handle, inode, input))) 806 (err = reserve_backup_gdb(handle, inode, input)))
807 goto exit_journal; 807 goto exit_journal;
808 } else if ((err = add_new_gdb(handle, inode, input, &primary))) 808 } else if ((err = add_new_gdb(handle, inode, input, &primary)))
@@ -828,13 +828,13 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
828 */ 828 */
829 829
830 /* Update group descriptor block for new group */ 830 /* Update group descriptor block for new group */
831 gdp = (struct ext3_group_desc *)primary->b_data + gdb_off; 831 gdp = (struct ext4_group_desc *)primary->b_data + gdb_off;
832 832
833 gdp->bg_block_bitmap = cpu_to_le32(input->block_bitmap); 833 gdp->bg_block_bitmap = cpu_to_le32(input->block_bitmap);
834 gdp->bg_inode_bitmap = cpu_to_le32(input->inode_bitmap); 834 gdp->bg_inode_bitmap = cpu_to_le32(input->inode_bitmap);
835 gdp->bg_inode_table = cpu_to_le32(input->inode_table); 835 gdp->bg_inode_table = cpu_to_le32(input->inode_table);
836 gdp->bg_free_blocks_count = cpu_to_le16(input->free_blocks_count); 836 gdp->bg_free_blocks_count = cpu_to_le16(input->free_blocks_count);
837 gdp->bg_free_inodes_count = cpu_to_le16(EXT3_INODES_PER_GROUP(sb)); 837 gdp->bg_free_inodes_count = cpu_to_le16(EXT4_INODES_PER_GROUP(sb));
838 838
839 /* 839 /*
840 * Make the new blocks and inodes valid next. We do this before 840 * Make the new blocks and inodes valid next. We do this before
@@ -849,7 +849,7 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
849 es->s_blocks_count = cpu_to_le32(le32_to_cpu(es->s_blocks_count) + 849 es->s_blocks_count = cpu_to_le32(le32_to_cpu(es->s_blocks_count) +
850 input->blocks_count); 850 input->blocks_count);
851 es->s_inodes_count = cpu_to_le32(le32_to_cpu(es->s_inodes_count) + 851 es->s_inodes_count = cpu_to_le32(le32_to_cpu(es->s_inodes_count) +
852 EXT3_INODES_PER_GROUP(sb)); 852 EXT4_INODES_PER_GROUP(sb));
853 853
854 /* 854 /*
855 * We need to protect s_groups_count against other CPUs seeing 855 * We need to protect s_groups_count against other CPUs seeing
@@ -878,7 +878,7 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
878 /* Update the global fs size fields */ 878 /* Update the global fs size fields */
879 sbi->s_groups_count++; 879 sbi->s_groups_count++;
880 880
881 ext3_journal_dirty_metadata(handle, primary); 881 ext4_journal_dirty_metadata(handle, primary);
882 882
883 /* Update the reserved block counts only once the new group is 883 /* Update the reserved block counts only once the new group is
884 * active. */ 884 * active. */
@@ -889,42 +889,42 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
889 percpu_counter_mod(&sbi->s_freeblocks_counter, 889 percpu_counter_mod(&sbi->s_freeblocks_counter,
890 input->free_blocks_count); 890 input->free_blocks_count);
891 percpu_counter_mod(&sbi->s_freeinodes_counter, 891 percpu_counter_mod(&sbi->s_freeinodes_counter,
892 EXT3_INODES_PER_GROUP(sb)); 892 EXT4_INODES_PER_GROUP(sb));
893 893
894 ext3_journal_dirty_metadata(handle, sbi->s_sbh); 894 ext4_journal_dirty_metadata(handle, sbi->s_sbh);
895 sb->s_dirt = 1; 895 sb->s_dirt = 1;
896 896
897exit_journal: 897exit_journal:
898 unlock_super(sb); 898 unlock_super(sb);
899 if ((err2 = ext3_journal_stop(handle)) && !err) 899 if ((err2 = ext4_journal_stop(handle)) && !err)
900 err = err2; 900 err = err2;
901 if (!err) { 901 if (!err) {
902 update_backups(sb, sbi->s_sbh->b_blocknr, (char *)es, 902 update_backups(sb, sbi->s_sbh->b_blocknr, (char *)es,
903 sizeof(struct ext3_super_block)); 903 sizeof(struct ext4_super_block));
904 update_backups(sb, primary->b_blocknr, primary->b_data, 904 update_backups(sb, primary->b_blocknr, primary->b_data,
905 primary->b_size); 905 primary->b_size);
906 } 906 }
907exit_put: 907exit_put:
908 iput(inode); 908 iput(inode);
909 return err; 909 return err;
910} /* ext3_group_add */ 910} /* ext4_group_add */
911 911
912/* Extend the filesystem to the new number of blocks specified. This entry 912/* Extend the filesystem to the new number of blocks specified. This entry
913 * point is only used to extend the current filesystem to the end of the last 913 * point is only used to extend the current filesystem to the end of the last
914 * existing group. It can be accessed via ioctl, or by "remount,resize=<size>" 914 * existing group. It can be accessed via ioctl, or by "remount,resize=<size>"
915 * for emergencies (because it has no dependencies on reserved blocks). 915 * for emergencies (because it has no dependencies on reserved blocks).
916 * 916 *
917 * If we _really_ wanted, we could use default values to call ext3_group_add() 917 * If we _really_ wanted, we could use default values to call ext4_group_add()
918 * allow the "remount" trick to work for arbitrary resizing, assuming enough 918 * allow the "remount" trick to work for arbitrary resizing, assuming enough
919 * GDT blocks are reserved to grow to the desired size. 919 * GDT blocks are reserved to grow to the desired size.
920 */ 920 */
921int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es, 921int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
922 ext3_fsblk_t n_blocks_count) 922 ext4_fsblk_t n_blocks_count)
923{ 923{
924 ext3_fsblk_t o_blocks_count; 924 ext4_fsblk_t o_blocks_count;
925 unsigned long o_groups_count; 925 unsigned long o_groups_count;
926 ext3_grpblk_t last; 926 ext4_grpblk_t last;
927 ext3_grpblk_t add; 927 ext4_grpblk_t add;
928 struct buffer_head * bh; 928 struct buffer_head * bh;
929 handle_t *handle; 929 handle_t *handle;
930 int err; 930 int err;
@@ -934,45 +934,45 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
934 * yet: we're going to revalidate es->s_blocks_count after 934 * yet: we're going to revalidate es->s_blocks_count after
935 * taking lock_super() below. */ 935 * taking lock_super() below. */
936 o_blocks_count = le32_to_cpu(es->s_blocks_count); 936 o_blocks_count = le32_to_cpu(es->s_blocks_count);
937 o_groups_count = EXT3_SB(sb)->s_groups_count; 937 o_groups_count = EXT4_SB(sb)->s_groups_count;
938 938
939 if (test_opt(sb, DEBUG)) 939 if (test_opt(sb, DEBUG))
940 printk(KERN_DEBUG "EXT3-fs: extending last group from "E3FSBLK" uto "E3FSBLK" blocks\n", 940 printk(KERN_DEBUG "EXT4-fs: extending last group from "E3FSBLK" uto "E3FSBLK" blocks\n",
941 o_blocks_count, n_blocks_count); 941 o_blocks_count, n_blocks_count);
942 942
943 if (n_blocks_count == 0 || n_blocks_count == o_blocks_count) 943 if (n_blocks_count == 0 || n_blocks_count == o_blocks_count)
944 return 0; 944 return 0;
945 945
946 if (n_blocks_count > (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) { 946 if (n_blocks_count > (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
947 printk(KERN_ERR "EXT3-fs: filesystem on %s:" 947 printk(KERN_ERR "EXT4-fs: filesystem on %s:"
948 " too large to resize to %lu blocks safely\n", 948 " too large to resize to %lu blocks safely\n",
949 sb->s_id, n_blocks_count); 949 sb->s_id, n_blocks_count);
950 if (sizeof(sector_t) < 8) 950 if (sizeof(sector_t) < 8)
951 ext3_warning(sb, __FUNCTION__, 951 ext4_warning(sb, __FUNCTION__,
952 "CONFIG_LBD not enabled\n"); 952 "CONFIG_LBD not enabled\n");
953 return -EINVAL; 953 return -EINVAL;
954 } 954 }
955 955
956 if (n_blocks_count < o_blocks_count) { 956 if (n_blocks_count < o_blocks_count) {
957 ext3_warning(sb, __FUNCTION__, 957 ext4_warning(sb, __FUNCTION__,
958 "can't shrink FS - resize aborted"); 958 "can't shrink FS - resize aborted");
959 return -EBUSY; 959 return -EBUSY;
960 } 960 }
961 961
962 /* Handle the remaining blocks in the last group only. */ 962 /* Handle the remaining blocks in the last group only. */
963 last = (o_blocks_count - le32_to_cpu(es->s_first_data_block)) % 963 last = (o_blocks_count - le32_to_cpu(es->s_first_data_block)) %
964 EXT3_BLOCKS_PER_GROUP(sb); 964 EXT4_BLOCKS_PER_GROUP(sb);
965 965
966 if (last == 0) { 966 if (last == 0) {
967 ext3_warning(sb, __FUNCTION__, 967 ext4_warning(sb, __FUNCTION__,
968 "need to use ext2online to resize further"); 968 "need to use ext2online to resize further");
969 return -EPERM; 969 return -EPERM;
970 } 970 }
971 971
972 add = EXT3_BLOCKS_PER_GROUP(sb) - last; 972 add = EXT4_BLOCKS_PER_GROUP(sb) - last;
973 973
974 if (o_blocks_count + add < o_blocks_count) { 974 if (o_blocks_count + add < o_blocks_count) {
975 ext3_warning(sb, __FUNCTION__, "blocks_count overflow"); 975 ext4_warning(sb, __FUNCTION__, "blocks_count overflow");
976 return -EINVAL; 976 return -EINVAL;
977 } 977 }
978 978
@@ -980,7 +980,7 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
980 add = n_blocks_count - o_blocks_count; 980 add = n_blocks_count - o_blocks_count;
981 981
982 if (o_blocks_count + add < n_blocks_count) 982 if (o_blocks_count + add < n_blocks_count)
983 ext3_warning(sb, __FUNCTION__, 983 ext4_warning(sb, __FUNCTION__,
984 "will only finish group ("E3FSBLK 984 "will only finish group ("E3FSBLK
985 " blocks, %u new)", 985 " blocks, %u new)",
986 o_blocks_count + add, add); 986 o_blocks_count + add, add);
@@ -988,55 +988,55 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
988 /* See if the device is actually as big as what was requested */ 988 /* See if the device is actually as big as what was requested */
989 bh = sb_bread(sb, o_blocks_count + add -1); 989 bh = sb_bread(sb, o_blocks_count + add -1);
990 if (!bh) { 990 if (!bh) {
991 ext3_warning(sb, __FUNCTION__, 991 ext4_warning(sb, __FUNCTION__,
992 "can't read last block, resize aborted"); 992 "can't read last block, resize aborted");
993 return -ENOSPC; 993 return -ENOSPC;
994 } 994 }
995 brelse(bh); 995 brelse(bh);
996 996
997 /* We will update the superblock, one block bitmap, and 997 /* We will update the superblock, one block bitmap, and
998 * one group descriptor via ext3_free_blocks(). 998 * one group descriptor via ext4_free_blocks().
999 */ 999 */
1000 handle = ext3_journal_start_sb(sb, 3); 1000 handle = ext4_journal_start_sb(sb, 3);
1001 if (IS_ERR(handle)) { 1001 if (IS_ERR(handle)) {
1002 err = PTR_ERR(handle); 1002 err = PTR_ERR(handle);
1003 ext3_warning(sb, __FUNCTION__, "error %d on journal start",err); 1003 ext4_warning(sb, __FUNCTION__, "error %d on journal start",err);
1004 goto exit_put; 1004 goto exit_put;
1005 } 1005 }
1006 1006
1007 lock_super(sb); 1007 lock_super(sb);
1008 if (o_blocks_count != le32_to_cpu(es->s_blocks_count)) { 1008 if (o_blocks_count != le32_to_cpu(es->s_blocks_count)) {
1009 ext3_warning(sb, __FUNCTION__, 1009 ext4_warning(sb, __FUNCTION__,
1010 "multiple resizers run on filesystem!"); 1010 "multiple resizers run on filesystem!");
1011 unlock_super(sb); 1011 unlock_super(sb);
1012 err = -EBUSY; 1012 err = -EBUSY;
1013 goto exit_put; 1013 goto exit_put;
1014 } 1014 }
1015 1015
1016 if ((err = ext3_journal_get_write_access(handle, 1016 if ((err = ext4_journal_get_write_access(handle,
1017 EXT3_SB(sb)->s_sbh))) { 1017 EXT4_SB(sb)->s_sbh))) {
1018 ext3_warning(sb, __FUNCTION__, 1018 ext4_warning(sb, __FUNCTION__,
1019 "error %d on journal write access", err); 1019 "error %d on journal write access", err);
1020 unlock_super(sb); 1020 unlock_super(sb);
1021 ext3_journal_stop(handle); 1021 ext4_journal_stop(handle);
1022 goto exit_put; 1022 goto exit_put;
1023 } 1023 }
1024 es->s_blocks_count = cpu_to_le32(o_blocks_count + add); 1024 es->s_blocks_count = cpu_to_le32(o_blocks_count + add);
1025 ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); 1025 ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh);
1026 sb->s_dirt = 1; 1026 sb->s_dirt = 1;
1027 unlock_super(sb); 1027 unlock_super(sb);
1028 ext3_debug("freeing blocks %lu through "E3FSBLK"\n", o_blocks_count, 1028 ext4_debug("freeing blocks %lu through "E3FSBLK"\n", o_blocks_count,
1029 o_blocks_count + add); 1029 o_blocks_count + add);
1030 ext3_free_blocks_sb(handle, sb, o_blocks_count, add, &freed_blocks); 1030 ext4_free_blocks_sb(handle, sb, o_blocks_count, add, &freed_blocks);
1031 ext3_debug("freed blocks "E3FSBLK" through "E3FSBLK"\n", o_blocks_count, 1031 ext4_debug("freed blocks "E3FSBLK" through "E3FSBLK"\n", o_blocks_count,
1032 o_blocks_count + add); 1032 o_blocks_count + add);
1033 if ((err = ext3_journal_stop(handle))) 1033 if ((err = ext4_journal_stop(handle)))
1034 goto exit_put; 1034 goto exit_put;
1035 if (test_opt(sb, DEBUG)) 1035 if (test_opt(sb, DEBUG))
1036 printk(KERN_DEBUG "EXT3-fs: extended group to %u blocks\n", 1036 printk(KERN_DEBUG "EXT4-fs: extended group to %u blocks\n",
1037 le32_to_cpu(es->s_blocks_count)); 1037 le32_to_cpu(es->s_blocks_count));
1038 update_backups(sb, EXT3_SB(sb)->s_sbh->b_blocknr, (char *)es, 1038 update_backups(sb, EXT4_SB(sb)->s_sbh->b_blocknr, (char *)es,
1039 sizeof(struct ext3_super_block)); 1039 sizeof(struct ext4_super_block));
1040exit_put: 1040exit_put:
1041 return err; 1041 return err;
1042} /* ext3_group_extend */ 1042} /* ext4_group_extend */
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 8bfd56ef18c..9e32a2a8d28 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/super.c 2 * linux/fs/ext4/super.c
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -21,8 +21,8 @@
21#include <linux/fs.h> 21#include <linux/fs.h>
22#include <linux/time.h> 22#include <linux/time.h>
23#include <linux/jbd.h> 23#include <linux/jbd.h>
24#include <linux/ext3_fs.h> 24#include <linux/ext4_fs.h>
25#include <linux/ext3_jbd.h> 25#include <linux/ext4_jbd.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/blkdev.h> 28#include <linux/blkdev.h>
@@ -42,25 +42,25 @@
42#include "acl.h" 42#include "acl.h"
43#include "namei.h" 43#include "namei.h"
44 44
45static int ext3_load_journal(struct super_block *, struct ext3_super_block *, 45static int ext4_load_journal(struct super_block *, struct ext4_super_block *,
46 unsigned long journal_devnum); 46 unsigned long journal_devnum);
47static int ext3_create_journal(struct super_block *, struct ext3_super_block *, 47static int ext4_create_journal(struct super_block *, struct ext4_super_block *,
48 unsigned int); 48 unsigned int);
49static void ext3_commit_super (struct super_block * sb, 49static void ext4_commit_super (struct super_block * sb,
50 struct ext3_super_block * es, 50 struct ext4_super_block * es,
51 int sync); 51 int sync);
52static void ext3_mark_recovery_complete(struct super_block * sb, 52static void ext4_mark_recovery_complete(struct super_block * sb,
53 struct ext3_super_block * es); 53 struct ext4_super_block * es);
54static void ext3_clear_journal_err(struct super_block * sb, 54static void ext4_clear_journal_err(struct super_block * sb,
55 struct ext3_super_block * es); 55 struct ext4_super_block * es);
56static int ext3_sync_fs(struct super_block *sb, int wait); 56static int ext4_sync_fs(struct super_block *sb, int wait);
57static const char *ext3_decode_error(struct super_block * sb, int errno, 57static const char *ext4_decode_error(struct super_block * sb, int errno,
58 char nbuf[16]); 58 char nbuf[16]);
59static int ext3_remount (struct super_block * sb, int * flags, char * data); 59static int ext4_remount (struct super_block * sb, int * flags, char * data);
60static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf); 60static int ext4_statfs (struct dentry * dentry, struct kstatfs * buf);
61static void ext3_unlockfs(struct super_block *sb); 61static void ext4_unlockfs(struct super_block *sb);
62static void ext3_write_super (struct super_block * sb); 62static void ext4_write_super (struct super_block * sb);
63static void ext3_write_super_lockfs(struct super_block *sb); 63static void ext4_write_super_lockfs(struct super_block *sb);
64 64
65/* 65/*
66 * Wrappers for journal_start/end. 66 * Wrappers for journal_start/end.
@@ -70,7 +70,7 @@ static void ext3_write_super_lockfs(struct super_block *sb);
70 * that sync() will call the filesystem's write_super callback if 70 * that sync() will call the filesystem's write_super callback if
71 * appropriate. 71 * appropriate.
72 */ 72 */
73handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks) 73handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
74{ 74{
75 journal_t *journal; 75 journal_t *journal;
76 76
@@ -80,9 +80,9 @@ handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks)
80 /* Special case here: if the journal has aborted behind our 80 /* Special case here: if the journal has aborted behind our
81 * backs (eg. EIO in the commit thread), then we still need to 81 * backs (eg. EIO in the commit thread), then we still need to
82 * take the FS itself readonly cleanly. */ 82 * take the FS itself readonly cleanly. */
83 journal = EXT3_SB(sb)->s_journal; 83 journal = EXT4_SB(sb)->s_journal;
84 if (is_journal_aborted(journal)) { 84 if (is_journal_aborted(journal)) {
85 ext3_abort(sb, __FUNCTION__, 85 ext4_abort(sb, __FUNCTION__,
86 "Detected aborted journal"); 86 "Detected aborted journal");
87 return ERR_PTR(-EROFS); 87 return ERR_PTR(-EROFS);
88 } 88 }
@@ -96,7 +96,7 @@ handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks)
96 * that sync() will call the filesystem's write_super callback if 96 * that sync() will call the filesystem's write_super callback if
97 * appropriate. 97 * appropriate.
98 */ 98 */
99int __ext3_journal_stop(const char *where, handle_t *handle) 99int __ext4_journal_stop(const char *where, handle_t *handle)
100{ 100{
101 struct super_block *sb; 101 struct super_block *sb;
102 int err; 102 int err;
@@ -109,15 +109,15 @@ int __ext3_journal_stop(const char *where, handle_t *handle)
109 if (!err) 109 if (!err)
110 err = rc; 110 err = rc;
111 if (err) 111 if (err)
112 __ext3_std_error(sb, where, err); 112 __ext4_std_error(sb, where, err);
113 return err; 113 return err;
114} 114}
115 115
116void ext3_journal_abort_handle(const char *caller, const char *err_fn, 116void ext4_journal_abort_handle(const char *caller, const char *err_fn,
117 struct buffer_head *bh, handle_t *handle, int err) 117 struct buffer_head *bh, handle_t *handle, int err)
118{ 118{
119 char nbuf[16]; 119 char nbuf[16];
120 const char *errstr = ext3_decode_error(NULL, err, nbuf); 120 const char *errstr = ext4_decode_error(NULL, err, nbuf);
121 121
122 if (bh) 122 if (bh)
123 BUFFER_TRACE(bh, "abort"); 123 BUFFER_TRACE(bh, "abort");
@@ -138,7 +138,7 @@ void ext3_journal_abort_handle(const char *caller, const char *err_fn,
138 * inconsistencies detected or read IO failures. 138 * inconsistencies detected or read IO failures.
139 * 139 *
140 * On ext2, we can store the error state of the filesystem in the 140 * On ext2, we can store the error state of the filesystem in the
141 * superblock. That is not possible on ext3, because we may have other 141 * superblock. That is not possible on ext4, because we may have other
142 * write ordering constraints on the superblock which prevent us from 142 * write ordering constraints on the superblock which prevent us from
143 * writing it out straight away; and given that the journal is about to 143 * writing it out straight away; and given that the journal is about to
144 * be aborted, we can't rely on the current, or future, transactions to 144 * be aborted, we can't rely on the current, or future, transactions to
@@ -149,20 +149,20 @@ void ext3_journal_abort_handle(const char *caller, const char *err_fn,
149 * that error until we've noted it down and cleared it. 149 * that error until we've noted it down and cleared it.
150 */ 150 */
151 151
152static void ext3_handle_error(struct super_block *sb) 152static void ext4_handle_error(struct super_block *sb)
153{ 153{
154 struct ext3_super_block *es = EXT3_SB(sb)->s_es; 154 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
155 155
156 EXT3_SB(sb)->s_mount_state |= EXT3_ERROR_FS; 156 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
157 es->s_state |= cpu_to_le16(EXT3_ERROR_FS); 157 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
158 158
159 if (sb->s_flags & MS_RDONLY) 159 if (sb->s_flags & MS_RDONLY)
160 return; 160 return;
161 161
162 if (!test_opt (sb, ERRORS_CONT)) { 162 if (!test_opt (sb, ERRORS_CONT)) {
163 journal_t *journal = EXT3_SB(sb)->s_journal; 163 journal_t *journal = EXT4_SB(sb)->s_journal;
164 164
165 EXT3_SB(sb)->s_mount_opt |= EXT3_MOUNT_ABORT; 165 EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT;
166 if (journal) 166 if (journal)
167 journal_abort(journal, -EIO); 167 journal_abort(journal, -EIO);
168 } 168 }
@@ -170,27 +170,27 @@ static void ext3_handle_error(struct super_block *sb)
170 printk (KERN_CRIT "Remounting filesystem read-only\n"); 170 printk (KERN_CRIT "Remounting filesystem read-only\n");
171 sb->s_flags |= MS_RDONLY; 171 sb->s_flags |= MS_RDONLY;
172 } 172 }
173 ext3_commit_super(sb, es, 1); 173 ext4_commit_super(sb, es, 1);
174 if (test_opt(sb, ERRORS_PANIC)) 174 if (test_opt(sb, ERRORS_PANIC))
175 panic("EXT3-fs (device %s): panic forced after error\n", 175 panic("EXT4-fs (device %s): panic forced after error\n",
176 sb->s_id); 176 sb->s_id);
177} 177}
178 178
179void ext3_error (struct super_block * sb, const char * function, 179void ext4_error (struct super_block * sb, const char * function,
180 const char * fmt, ...) 180 const char * fmt, ...)
181{ 181{
182 va_list args; 182 va_list args;
183 183
184 va_start(args, fmt); 184 va_start(args, fmt);
185 printk(KERN_CRIT "EXT3-fs error (device %s): %s: ",sb->s_id, function); 185 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ",sb->s_id, function);
186 vprintk(fmt, args); 186 vprintk(fmt, args);
187 printk("\n"); 187 printk("\n");
188 va_end(args); 188 va_end(args);
189 189
190 ext3_handle_error(sb); 190 ext4_handle_error(sb);
191} 191}
192 192
193static const char *ext3_decode_error(struct super_block * sb, int errno, 193static const char *ext4_decode_error(struct super_block * sb, int errno,
194 char nbuf[16]) 194 char nbuf[16])
195{ 195{
196 char *errstr = NULL; 196 char *errstr = NULL;
@@ -203,7 +203,7 @@ static const char *ext3_decode_error(struct super_block * sb, int errno,
203 errstr = "Out of memory"; 203 errstr = "Out of memory";
204 break; 204 break;
205 case -EROFS: 205 case -EROFS:
206 if (!sb || EXT3_SB(sb)->s_journal->j_flags & JFS_ABORT) 206 if (!sb || EXT4_SB(sb)->s_journal->j_flags & JFS_ABORT)
207 errstr = "Journal has aborted"; 207 errstr = "Journal has aborted";
208 else 208 else
209 errstr = "Readonly filesystem"; 209 errstr = "Readonly filesystem";
@@ -223,10 +223,10 @@ static const char *ext3_decode_error(struct super_block * sb, int errno,
223 return errstr; 223 return errstr;
224} 224}
225 225
226/* __ext3_std_error decodes expected errors from journaling functions 226/* __ext4_std_error decodes expected errors from journaling functions
227 * automatically and invokes the appropriate error response. */ 227 * automatically and invokes the appropriate error response. */
228 228
229void __ext3_std_error (struct super_block * sb, const char * function, 229void __ext4_std_error (struct super_block * sb, const char * function,
230 int errno) 230 int errno)
231{ 231{
232 char nbuf[16]; 232 char nbuf[16];
@@ -239,15 +239,15 @@ void __ext3_std_error (struct super_block * sb, const char * function,
239 (sb->s_flags & MS_RDONLY)) 239 (sb->s_flags & MS_RDONLY))
240 return; 240 return;
241 241
242 errstr = ext3_decode_error(sb, errno, nbuf); 242 errstr = ext4_decode_error(sb, errno, nbuf);
243 printk (KERN_CRIT "EXT3-fs error (device %s) in %s: %s\n", 243 printk (KERN_CRIT "EXT4-fs error (device %s) in %s: %s\n",
244 sb->s_id, function, errstr); 244 sb->s_id, function, errstr);
245 245
246 ext3_handle_error(sb); 246 ext4_handle_error(sb);
247} 247}
248 248
249/* 249/*
250 * ext3_abort is a much stronger failure handler than ext3_error. The 250 * ext4_abort is a much stronger failure handler than ext4_error. The
251 * abort function may be used to deal with unrecoverable failures such 251 * abort function may be used to deal with unrecoverable failures such
252 * as journal IO errors or ENOMEM at a critical moment in log management. 252 * as journal IO errors or ENOMEM at a critical moment in log management.
253 * 253 *
@@ -256,60 +256,60 @@ void __ext3_std_error (struct super_block * sb, const char * function,
256 * case we take the easy way out and panic immediately. 256 * case we take the easy way out and panic immediately.
257 */ 257 */
258 258
259void ext3_abort (struct super_block * sb, const char * function, 259void ext4_abort (struct super_block * sb, const char * function,
260 const char * fmt, ...) 260 const char * fmt, ...)
261{ 261{
262 va_list args; 262 va_list args;
263 263
264 printk (KERN_CRIT "ext3_abort called.\n"); 264 printk (KERN_CRIT "ext4_abort called.\n");
265 265
266 va_start(args, fmt); 266 va_start(args, fmt);
267 printk(KERN_CRIT "EXT3-fs error (device %s): %s: ",sb->s_id, function); 267 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ",sb->s_id, function);
268 vprintk(fmt, args); 268 vprintk(fmt, args);
269 printk("\n"); 269 printk("\n");
270 va_end(args); 270 va_end(args);
271 271
272 if (test_opt(sb, ERRORS_PANIC)) 272 if (test_opt(sb, ERRORS_PANIC))
273 panic("EXT3-fs panic from previous error\n"); 273 panic("EXT4-fs panic from previous error\n");
274 274
275 if (sb->s_flags & MS_RDONLY) 275 if (sb->s_flags & MS_RDONLY)
276 return; 276 return;
277 277
278 printk(KERN_CRIT "Remounting filesystem read-only\n"); 278 printk(KERN_CRIT "Remounting filesystem read-only\n");
279 EXT3_SB(sb)->s_mount_state |= EXT3_ERROR_FS; 279 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
280 sb->s_flags |= MS_RDONLY; 280 sb->s_flags |= MS_RDONLY;
281 EXT3_SB(sb)->s_mount_opt |= EXT3_MOUNT_ABORT; 281 EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT;
282 journal_abort(EXT3_SB(sb)->s_journal, -EIO); 282 journal_abort(EXT4_SB(sb)->s_journal, -EIO);
283} 283}
284 284
285void ext3_warning (struct super_block * sb, const char * function, 285void ext4_warning (struct super_block * sb, const char * function,
286 const char * fmt, ...) 286 const char * fmt, ...)
287{ 287{
288 va_list args; 288 va_list args;
289 289
290 va_start(args, fmt); 290 va_start(args, fmt);
291 printk(KERN_WARNING "EXT3-fs warning (device %s): %s: ", 291 printk(KERN_WARNING "EXT4-fs warning (device %s): %s: ",
292 sb->s_id, function); 292 sb->s_id, function);
293 vprintk(fmt, args); 293 vprintk(fmt, args);
294 printk("\n"); 294 printk("\n");
295 va_end(args); 295 va_end(args);
296} 296}
297 297
298void ext3_update_dynamic_rev(struct super_block *sb) 298void ext4_update_dynamic_rev(struct super_block *sb)
299{ 299{
300 struct ext3_super_block *es = EXT3_SB(sb)->s_es; 300 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
301 301
302 if (le32_to_cpu(es->s_rev_level) > EXT3_GOOD_OLD_REV) 302 if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV)
303 return; 303 return;
304 304
305 ext3_warning(sb, __FUNCTION__, 305 ext4_warning(sb, __FUNCTION__,
306 "updating to rev %d because of new feature flag, " 306 "updating to rev %d because of new feature flag, "
307 "running e2fsck is recommended", 307 "running e2fsck is recommended",
308 EXT3_DYNAMIC_REV); 308 EXT4_DYNAMIC_REV);
309 309
310 es->s_first_ino = cpu_to_le32(EXT3_GOOD_OLD_FIRST_INO); 310 es->s_first_ino = cpu_to_le32(EXT4_GOOD_OLD_FIRST_INO);
311 es->s_inode_size = cpu_to_le16(EXT3_GOOD_OLD_INODE_SIZE); 311 es->s_inode_size = cpu_to_le16(EXT4_GOOD_OLD_INODE_SIZE);
312 es->s_rev_level = cpu_to_le32(EXT3_DYNAMIC_REV); 312 es->s_rev_level = cpu_to_le32(EXT4_DYNAMIC_REV);
313 /* leave es->s_feature_*compat flags alone */ 313 /* leave es->s_feature_*compat flags alone */
314 /* es->s_uuid will be set by e2fsck if empty */ 314 /* es->s_uuid will be set by e2fsck if empty */
315 315
@@ -323,7 +323,7 @@ void ext3_update_dynamic_rev(struct super_block *sb)
323/* 323/*
324 * Open the external journal device 324 * Open the external journal device
325 */ 325 */
326static struct block_device *ext3_blkdev_get(dev_t dev) 326static struct block_device *ext4_blkdev_get(dev_t dev)
327{ 327{
328 struct block_device *bdev; 328 struct block_device *bdev;
329 char b[BDEVNAME_SIZE]; 329 char b[BDEVNAME_SIZE];
@@ -334,7 +334,7 @@ static struct block_device *ext3_blkdev_get(dev_t dev)
334 return bdev; 334 return bdev;
335 335
336fail: 336fail:
337 printk(KERN_ERR "EXT3: failed to open journal device %s: %ld\n", 337 printk(KERN_ERR "EXT4: failed to open journal device %s: %ld\n",
338 __bdevname(dev, b), PTR_ERR(bdev)); 338 __bdevname(dev, b), PTR_ERR(bdev));
339 return NULL; 339 return NULL;
340} 340}
@@ -342,20 +342,20 @@ fail:
342/* 342/*
343 * Release the journal device 343 * Release the journal device
344 */ 344 */
345static int ext3_blkdev_put(struct block_device *bdev) 345static int ext4_blkdev_put(struct block_device *bdev)
346{ 346{
347 bd_release(bdev); 347 bd_release(bdev);
348 return blkdev_put(bdev); 348 return blkdev_put(bdev);
349} 349}
350 350
351static int ext3_blkdev_remove(struct ext3_sb_info *sbi) 351static int ext4_blkdev_remove(struct ext4_sb_info *sbi)
352{ 352{
353 struct block_device *bdev; 353 struct block_device *bdev;
354 int ret = -ENODEV; 354 int ret = -ENODEV;
355 355
356 bdev = sbi->journal_bdev; 356 bdev = sbi->journal_bdev;
357 if (bdev) { 357 if (bdev) {
358 ret = ext3_blkdev_put(bdev); 358 ret = ext4_blkdev_put(bdev);
359 sbi->journal_bdev = NULL; 359 sbi->journal_bdev = NULL;
360 } 360 }
361 return ret; 361 return ret;
@@ -363,10 +363,10 @@ static int ext3_blkdev_remove(struct ext3_sb_info *sbi)
363 363
364static inline struct inode *orphan_list_entry(struct list_head *l) 364static inline struct inode *orphan_list_entry(struct list_head *l)
365{ 365{
366 return &list_entry(l, struct ext3_inode_info, i_orphan)->vfs_inode; 366 return &list_entry(l, struct ext4_inode_info, i_orphan)->vfs_inode;
367} 367}
368 368
369static void dump_orphan_list(struct super_block *sb, struct ext3_sb_info *sbi) 369static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi)
370{ 370{
371 struct list_head *l; 371 struct list_head *l;
372 372
@@ -384,20 +384,20 @@ static void dump_orphan_list(struct super_block *sb, struct ext3_sb_info *sbi)
384 } 384 }
385} 385}
386 386
387static void ext3_put_super (struct super_block * sb) 387static void ext4_put_super (struct super_block * sb)
388{ 388{
389 struct ext3_sb_info *sbi = EXT3_SB(sb); 389 struct ext4_sb_info *sbi = EXT4_SB(sb);
390 struct ext3_super_block *es = sbi->s_es; 390 struct ext4_super_block *es = sbi->s_es;
391 int i; 391 int i;
392 392
393 ext3_xattr_put_super(sb); 393 ext4_xattr_put_super(sb);
394 journal_destroy(sbi->s_journal); 394 journal_destroy(sbi->s_journal);
395 if (!(sb->s_flags & MS_RDONLY)) { 395 if (!(sb->s_flags & MS_RDONLY)) {
396 EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); 396 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
397 es->s_state = cpu_to_le16(sbi->s_mount_state); 397 es->s_state = cpu_to_le16(sbi->s_mount_state);
398 BUFFER_TRACE(sbi->s_sbh, "marking dirty"); 398 BUFFER_TRACE(sbi->s_sbh, "marking dirty");
399 mark_buffer_dirty(sbi->s_sbh); 399 mark_buffer_dirty(sbi->s_sbh);
400 ext3_commit_super(sb, es, 1); 400 ext4_commit_super(sb, es, 1);
401 } 401 }
402 402
403 for (i = 0; i < sbi->s_gdb_count; i++) 403 for (i = 0; i < sbi->s_gdb_count; i++)
@@ -429,47 +429,47 @@ static void ext3_put_super (struct super_block * sb)
429 */ 429 */
430 sync_blockdev(sbi->journal_bdev); 430 sync_blockdev(sbi->journal_bdev);
431 invalidate_bdev(sbi->journal_bdev, 0); 431 invalidate_bdev(sbi->journal_bdev, 0);
432 ext3_blkdev_remove(sbi); 432 ext4_blkdev_remove(sbi);
433 } 433 }
434 sb->s_fs_info = NULL; 434 sb->s_fs_info = NULL;
435 kfree(sbi); 435 kfree(sbi);
436 return; 436 return;
437} 437}
438 438
439static kmem_cache_t *ext3_inode_cachep; 439static kmem_cache_t *ext4_inode_cachep;
440 440
441/* 441/*
442 * Called inside transaction, so use GFP_NOFS 442 * Called inside transaction, so use GFP_NOFS
443 */ 443 */
444static struct inode *ext3_alloc_inode(struct super_block *sb) 444static struct inode *ext4_alloc_inode(struct super_block *sb)
445{ 445{
446 struct ext3_inode_info *ei; 446 struct ext4_inode_info *ei;
447 447
448 ei = kmem_cache_alloc(ext3_inode_cachep, SLAB_NOFS); 448 ei = kmem_cache_alloc(ext4_inode_cachep, SLAB_NOFS);
449 if (!ei) 449 if (!ei)
450 return NULL; 450 return NULL;
451#ifdef CONFIG_EXT3_FS_POSIX_ACL 451#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
452 ei->i_acl = EXT3_ACL_NOT_CACHED; 452 ei->i_acl = EXT4_ACL_NOT_CACHED;
453 ei->i_default_acl = EXT3_ACL_NOT_CACHED; 453 ei->i_default_acl = EXT4_ACL_NOT_CACHED;
454#endif 454#endif
455 ei->i_block_alloc_info = NULL; 455 ei->i_block_alloc_info = NULL;
456 ei->vfs_inode.i_version = 1; 456 ei->vfs_inode.i_version = 1;
457 return &ei->vfs_inode; 457 return &ei->vfs_inode;
458} 458}
459 459
460static void ext3_destroy_inode(struct inode *inode) 460static void ext4_destroy_inode(struct inode *inode)
461{ 461{
462 kmem_cache_free(ext3_inode_cachep, EXT3_I(inode)); 462 kmem_cache_free(ext4_inode_cachep, EXT4_I(inode));
463} 463}
464 464
465static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags) 465static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
466{ 466{
467 struct ext3_inode_info *ei = (struct ext3_inode_info *) foo; 467 struct ext4_inode_info *ei = (struct ext4_inode_info *) foo;
468 468
469 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == 469 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
470 SLAB_CTOR_CONSTRUCTOR) { 470 SLAB_CTOR_CONSTRUCTOR) {
471 INIT_LIST_HEAD(&ei->i_orphan); 471 INIT_LIST_HEAD(&ei->i_orphan);
472#ifdef CONFIG_EXT3_FS_XATTR 472#ifdef CONFIG_EXT4DEV_FS_XATTR
473 init_rwsem(&ei->xattr_sem); 473 init_rwsem(&ei->xattr_sem);
474#endif 474#endif
475 mutex_init(&ei->truncate_mutex); 475 mutex_init(&ei->truncate_mutex);
@@ -479,46 +479,46 @@ static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
479 479
480static int init_inodecache(void) 480static int init_inodecache(void)
481{ 481{
482 ext3_inode_cachep = kmem_cache_create("ext3_inode_cache", 482 ext4_inode_cachep = kmem_cache_create("ext4_inode_cache",
483 sizeof(struct ext3_inode_info), 483 sizeof(struct ext4_inode_info),
484 0, (SLAB_RECLAIM_ACCOUNT| 484 0, (SLAB_RECLAIM_ACCOUNT|
485 SLAB_MEM_SPREAD), 485 SLAB_MEM_SPREAD),
486 init_once, NULL); 486 init_once, NULL);
487 if (ext3_inode_cachep == NULL) 487 if (ext4_inode_cachep == NULL)
488 return -ENOMEM; 488 return -ENOMEM;
489 return 0; 489 return 0;
490} 490}
491 491
492static void destroy_inodecache(void) 492static void destroy_inodecache(void)
493{ 493{
494 kmem_cache_destroy(ext3_inode_cachep); 494 kmem_cache_destroy(ext4_inode_cachep);
495} 495}
496 496
497static void ext3_clear_inode(struct inode *inode) 497static void ext4_clear_inode(struct inode *inode)
498{ 498{
499 struct ext3_block_alloc_info *rsv = EXT3_I(inode)->i_block_alloc_info; 499 struct ext4_block_alloc_info *rsv = EXT4_I(inode)->i_block_alloc_info;
500#ifdef CONFIG_EXT3_FS_POSIX_ACL 500#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
501 if (EXT3_I(inode)->i_acl && 501 if (EXT4_I(inode)->i_acl &&
502 EXT3_I(inode)->i_acl != EXT3_ACL_NOT_CACHED) { 502 EXT4_I(inode)->i_acl != EXT4_ACL_NOT_CACHED) {
503 posix_acl_release(EXT3_I(inode)->i_acl); 503 posix_acl_release(EXT4_I(inode)->i_acl);
504 EXT3_I(inode)->i_acl = EXT3_ACL_NOT_CACHED; 504 EXT4_I(inode)->i_acl = EXT4_ACL_NOT_CACHED;
505 } 505 }
506 if (EXT3_I(inode)->i_default_acl && 506 if (EXT4_I(inode)->i_default_acl &&
507 EXT3_I(inode)->i_default_acl != EXT3_ACL_NOT_CACHED) { 507 EXT4_I(inode)->i_default_acl != EXT4_ACL_NOT_CACHED) {
508 posix_acl_release(EXT3_I(inode)->i_default_acl); 508 posix_acl_release(EXT4_I(inode)->i_default_acl);
509 EXT3_I(inode)->i_default_acl = EXT3_ACL_NOT_CACHED; 509 EXT4_I(inode)->i_default_acl = EXT4_ACL_NOT_CACHED;
510 } 510 }
511#endif 511#endif
512 ext3_discard_reservation(inode); 512 ext4_discard_reservation(inode);
513 EXT3_I(inode)->i_block_alloc_info = NULL; 513 EXT4_I(inode)->i_block_alloc_info = NULL;
514 if (unlikely(rsv)) 514 if (unlikely(rsv))
515 kfree(rsv); 515 kfree(rsv);
516} 516}
517 517
518static inline void ext3_show_quota_options(struct seq_file *seq, struct super_block *sb) 518static inline void ext4_show_quota_options(struct seq_file *seq, struct super_block *sb)
519{ 519{
520#if defined(CONFIG_QUOTA) 520#if defined(CONFIG_QUOTA)
521 struct ext3_sb_info *sbi = EXT3_SB(sb); 521 struct ext4_sb_info *sbi = EXT4_SB(sb);
522 522
523 if (sbi->s_jquota_fmt) 523 if (sbi->s_jquota_fmt)
524 seq_printf(seq, ",jqfmt=%s", 524 seq_printf(seq, ",jqfmt=%s",
@@ -530,32 +530,32 @@ static inline void ext3_show_quota_options(struct seq_file *seq, struct super_bl
530 if (sbi->s_qf_names[GRPQUOTA]) 530 if (sbi->s_qf_names[GRPQUOTA])
531 seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]); 531 seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]);
532 532
533 if (sbi->s_mount_opt & EXT3_MOUNT_USRQUOTA) 533 if (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA)
534 seq_puts(seq, ",usrquota"); 534 seq_puts(seq, ",usrquota");
535 535
536 if (sbi->s_mount_opt & EXT3_MOUNT_GRPQUOTA) 536 if (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)
537 seq_puts(seq, ",grpquota"); 537 seq_puts(seq, ",grpquota");
538#endif 538#endif
539} 539}
540 540
541static int ext3_show_options(struct seq_file *seq, struct vfsmount *vfs) 541static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
542{ 542{
543 struct super_block *sb = vfs->mnt_sb; 543 struct super_block *sb = vfs->mnt_sb;
544 544
545 if (test_opt(sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA) 545 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
546 seq_puts(seq, ",data=journal"); 546 seq_puts(seq, ",data=journal");
547 else if (test_opt(sb, DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA) 547 else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
548 seq_puts(seq, ",data=ordered"); 548 seq_puts(seq, ",data=ordered");
549 else if (test_opt(sb, DATA_FLAGS) == EXT3_MOUNT_WRITEBACK_DATA) 549 else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
550 seq_puts(seq, ",data=writeback"); 550 seq_puts(seq, ",data=writeback");
551 551
552 ext3_show_quota_options(seq, sb); 552 ext4_show_quota_options(seq, sb);
553 553
554 return 0; 554 return 0;
555} 555}
556 556
557 557
558static struct dentry *ext3_get_dentry(struct super_block *sb, void *vobjp) 558static struct dentry *ext4_get_dentry(struct super_block *sb, void *vobjp)
559{ 559{
560 __u32 *objp = vobjp; 560 __u32 *objp = vobjp;
561 unsigned long ino = objp[0]; 561 unsigned long ino = objp[0];
@@ -563,14 +563,14 @@ static struct dentry *ext3_get_dentry(struct super_block *sb, void *vobjp)
563 struct inode *inode; 563 struct inode *inode;
564 struct dentry *result; 564 struct dentry *result;
565 565
566 if (ino < EXT3_FIRST_INO(sb) && ino != EXT3_ROOT_INO) 566 if (ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO)
567 return ERR_PTR(-ESTALE); 567 return ERR_PTR(-ESTALE);
568 if (ino > le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count)) 568 if (ino > le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count))
569 return ERR_PTR(-ESTALE); 569 return ERR_PTR(-ESTALE);
570 570
571 /* iget isn't really right if the inode is currently unallocated!! 571 /* iget isn't really right if the inode is currently unallocated!!
572 * 572 *
573 * ext3_read_inode will return a bad_inode if the inode had been 573 * ext4_read_inode will return a bad_inode if the inode had been
574 * deleted, so we should be safe. 574 * deleted, so we should be safe.
575 * 575 *
576 * Currently we don't know the generation for parent directory, so 576 * Currently we don't know the generation for parent directory, so
@@ -599,37 +599,37 @@ static struct dentry *ext3_get_dentry(struct super_block *sb, void *vobjp)
599#define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group") 599#define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
600#define QTYPE2MOPT(on, t) ((t)==USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA)) 600#define QTYPE2MOPT(on, t) ((t)==USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA))
601 601
602static int ext3_dquot_initialize(struct inode *inode, int type); 602static int ext4_dquot_initialize(struct inode *inode, int type);
603static int ext3_dquot_drop(struct inode *inode); 603static int ext4_dquot_drop(struct inode *inode);
604static int ext3_write_dquot(struct dquot *dquot); 604static int ext4_write_dquot(struct dquot *dquot);
605static int ext3_acquire_dquot(struct dquot *dquot); 605static int ext4_acquire_dquot(struct dquot *dquot);
606static int ext3_release_dquot(struct dquot *dquot); 606static int ext4_release_dquot(struct dquot *dquot);
607static int ext3_mark_dquot_dirty(struct dquot *dquot); 607static int ext4_mark_dquot_dirty(struct dquot *dquot);
608static int ext3_write_info(struct super_block *sb, int type); 608static int ext4_write_info(struct super_block *sb, int type);
609static int ext3_quota_on(struct super_block *sb, int type, int format_id, char *path); 609static int ext4_quota_on(struct super_block *sb, int type, int format_id, char *path);
610static int ext3_quota_on_mount(struct super_block *sb, int type); 610static int ext4_quota_on_mount(struct super_block *sb, int type);
611static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data, 611static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
612 size_t len, loff_t off); 612 size_t len, loff_t off);
613static ssize_t ext3_quota_write(struct super_block *sb, int type, 613static ssize_t ext4_quota_write(struct super_block *sb, int type,
614 const char *data, size_t len, loff_t off); 614 const char *data, size_t len, loff_t off);
615 615
616static struct dquot_operations ext3_quota_operations = { 616static struct dquot_operations ext4_quota_operations = {
617 .initialize = ext3_dquot_initialize, 617 .initialize = ext4_dquot_initialize,
618 .drop = ext3_dquot_drop, 618 .drop = ext4_dquot_drop,
619 .alloc_space = dquot_alloc_space, 619 .alloc_space = dquot_alloc_space,
620 .alloc_inode = dquot_alloc_inode, 620 .alloc_inode = dquot_alloc_inode,
621 .free_space = dquot_free_space, 621 .free_space = dquot_free_space,
622 .free_inode = dquot_free_inode, 622 .free_inode = dquot_free_inode,
623 .transfer = dquot_transfer, 623 .transfer = dquot_transfer,
624 .write_dquot = ext3_write_dquot, 624 .write_dquot = ext4_write_dquot,
625 .acquire_dquot = ext3_acquire_dquot, 625 .acquire_dquot = ext4_acquire_dquot,
626 .release_dquot = ext3_release_dquot, 626 .release_dquot = ext4_release_dquot,
627 .mark_dirty = ext3_mark_dquot_dirty, 627 .mark_dirty = ext4_mark_dquot_dirty,
628 .write_info = ext3_write_info 628 .write_info = ext4_write_info
629}; 629};
630 630
631static struct quotactl_ops ext3_qctl_operations = { 631static struct quotactl_ops ext4_qctl_operations = {
632 .quota_on = ext3_quota_on, 632 .quota_on = ext4_quota_on,
633 .quota_off = vfs_quota_off, 633 .quota_off = vfs_quota_off,
634 .quota_sync = vfs_quota_sync, 634 .quota_sync = vfs_quota_sync,
635 .get_info = vfs_get_dqinfo, 635 .get_info = vfs_get_dqinfo,
@@ -639,31 +639,31 @@ static struct quotactl_ops ext3_qctl_operations = {
639}; 639};
640#endif 640#endif
641 641
642static struct super_operations ext3_sops = { 642static struct super_operations ext4_sops = {
643 .alloc_inode = ext3_alloc_inode, 643 .alloc_inode = ext4_alloc_inode,
644 .destroy_inode = ext3_destroy_inode, 644 .destroy_inode = ext4_destroy_inode,
645 .read_inode = ext3_read_inode, 645 .read_inode = ext4_read_inode,
646 .write_inode = ext3_write_inode, 646 .write_inode = ext4_write_inode,
647 .dirty_inode = ext3_dirty_inode, 647 .dirty_inode = ext4_dirty_inode,
648 .delete_inode = ext3_delete_inode, 648 .delete_inode = ext4_delete_inode,
649 .put_super = ext3_put_super, 649 .put_super = ext4_put_super,
650 .write_super = ext3_write_super, 650 .write_super = ext4_write_super,
651 .sync_fs = ext3_sync_fs, 651 .sync_fs = ext4_sync_fs,
652 .write_super_lockfs = ext3_write_super_lockfs, 652 .write_super_lockfs = ext4_write_super_lockfs,
653 .unlockfs = ext3_unlockfs, 653 .unlockfs = ext4_unlockfs,
654 .statfs = ext3_statfs, 654 .statfs = ext4_statfs,
655 .remount_fs = ext3_remount, 655 .remount_fs = ext4_remount,
656 .clear_inode = ext3_clear_inode, 656 .clear_inode = ext4_clear_inode,
657 .show_options = ext3_show_options, 657 .show_options = ext4_show_options,
658#ifdef CONFIG_QUOTA 658#ifdef CONFIG_QUOTA
659 .quota_read = ext3_quota_read, 659 .quota_read = ext4_quota_read,
660 .quota_write = ext3_quota_write, 660 .quota_write = ext4_quota_write,
661#endif 661#endif
662}; 662};
663 663
664static struct export_operations ext3_export_ops = { 664static struct export_operations ext4_export_ops = {
665 .get_parent = ext3_get_parent, 665 .get_parent = ext4_get_parent,
666 .get_dentry = ext3_get_dentry, 666 .get_dentry = ext4_get_dentry,
667}; 667};
668 668
669enum { 669enum {
@@ -731,18 +731,18 @@ static match_table_t tokens = {
731 {Opt_resize, "resize"}, 731 {Opt_resize, "resize"},
732}; 732};
733 733
734static ext3_fsblk_t get_sb_block(void **data) 734static ext4_fsblk_t get_sb_block(void **data)
735{ 735{
736 ext3_fsblk_t sb_block; 736 ext4_fsblk_t sb_block;
737 char *options = (char *) *data; 737 char *options = (char *) *data;
738 738
739 if (!options || strncmp(options, "sb=", 3) != 0) 739 if (!options || strncmp(options, "sb=", 3) != 0)
740 return 1; /* Default location */ 740 return 1; /* Default location */
741 options += 3; 741 options += 3;
742 /*todo: use simple_strtoll with >32bit ext3 */ 742 /*todo: use simple_strtoll with >32bit ext4 */
743 sb_block = simple_strtoul(options, &options, 0); 743 sb_block = simple_strtoul(options, &options, 0);
744 if (*options && *options != ',') { 744 if (*options && *options != ',') {
745 printk("EXT3-fs: Invalid sb specification: %s\n", 745 printk("EXT4-fs: Invalid sb specification: %s\n",
746 (char *) *data); 746 (char *) *data);
747 return 1; 747 return 1;
748 } 748 }
@@ -754,9 +754,9 @@ static ext3_fsblk_t get_sb_block(void **data)
754 754
755static int parse_options (char *options, struct super_block *sb, 755static int parse_options (char *options, struct super_block *sb,
756 unsigned int *inum, unsigned long *journal_devnum, 756 unsigned int *inum, unsigned long *journal_devnum,
757 ext3_fsblk_t *n_blocks_count, int is_remount) 757 ext4_fsblk_t *n_blocks_count, int is_remount)
758{ 758{
759 struct ext3_sb_info *sbi = EXT3_SB(sb); 759 struct ext4_sb_info *sbi = EXT4_SB(sb);
760 char * p; 760 char * p;
761 substring_t args[MAX_OPT_ARGS]; 761 substring_t args[MAX_OPT_ARGS];
762 int data_opt = 0; 762 int data_opt = 0;
@@ -832,7 +832,7 @@ static int parse_options (char *options, struct super_block *sb,
832 case Opt_orlov: 832 case Opt_orlov:
833 clear_opt (sbi->s_mount_opt, OLDALLOC); 833 clear_opt (sbi->s_mount_opt, OLDALLOC);
834 break; 834 break;
835#ifdef CONFIG_EXT3_FS_XATTR 835#ifdef CONFIG_EXT4DEV_FS_XATTR
836 case Opt_user_xattr: 836 case Opt_user_xattr:
837 set_opt (sbi->s_mount_opt, XATTR_USER); 837 set_opt (sbi->s_mount_opt, XATTR_USER);
838 break; 838 break;
@@ -842,10 +842,10 @@ static int parse_options (char *options, struct super_block *sb,
842#else 842#else
843 case Opt_user_xattr: 843 case Opt_user_xattr:
844 case Opt_nouser_xattr: 844 case Opt_nouser_xattr:
845 printk("EXT3 (no)user_xattr options not supported\n"); 845 printk("EXT4 (no)user_xattr options not supported\n");
846 break; 846 break;
847#endif 847#endif
848#ifdef CONFIG_EXT3_FS_POSIX_ACL 848#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
849 case Opt_acl: 849 case Opt_acl:
850 set_opt(sbi->s_mount_opt, POSIX_ACL); 850 set_opt(sbi->s_mount_opt, POSIX_ACL);
851 break; 851 break;
@@ -855,7 +855,7 @@ static int parse_options (char *options, struct super_block *sb,
855#else 855#else
856 case Opt_acl: 856 case Opt_acl:
857 case Opt_noacl: 857 case Opt_noacl:
858 printk("EXT3 (no)acl options not supported\n"); 858 printk("EXT4 (no)acl options not supported\n");
859 break; 859 break;
860#endif 860#endif
861 case Opt_reservation: 861 case Opt_reservation:
@@ -871,7 +871,7 @@ static int parse_options (char *options, struct super_block *sb,
871 user to specify an existing inode to be the 871 user to specify an existing inode to be the
872 journal file. */ 872 journal file. */
873 if (is_remount) { 873 if (is_remount) {
874 printk(KERN_ERR "EXT3-fs: cannot specify " 874 printk(KERN_ERR "EXT4-fs: cannot specify "
875 "journal on remount\n"); 875 "journal on remount\n");
876 return 0; 876 return 0;
877 } 877 }
@@ -879,7 +879,7 @@ static int parse_options (char *options, struct super_block *sb,
879 break; 879 break;
880 case Opt_journal_inum: 880 case Opt_journal_inum:
881 if (is_remount) { 881 if (is_remount) {
882 printk(KERN_ERR "EXT3-fs: cannot specify " 882 printk(KERN_ERR "EXT4-fs: cannot specify "
883 "journal on remount\n"); 883 "journal on remount\n");
884 return 0; 884 return 0;
885 } 885 }
@@ -889,7 +889,7 @@ static int parse_options (char *options, struct super_block *sb,
889 break; 889 break;
890 case Opt_journal_dev: 890 case Opt_journal_dev:
891 if (is_remount) { 891 if (is_remount) {
892 printk(KERN_ERR "EXT3-fs: cannot specify " 892 printk(KERN_ERR "EXT4-fs: cannot specify "
893 "journal on remount\n"); 893 "journal on remount\n");
894 return 0; 894 return 0;
895 } 895 }
@@ -910,24 +910,24 @@ static int parse_options (char *options, struct super_block *sb,
910 sbi->s_commit_interval = HZ * option; 910 sbi->s_commit_interval = HZ * option;
911 break; 911 break;
912 case Opt_data_journal: 912 case Opt_data_journal:
913 data_opt = EXT3_MOUNT_JOURNAL_DATA; 913 data_opt = EXT4_MOUNT_JOURNAL_DATA;
914 goto datacheck; 914 goto datacheck;
915 case Opt_data_ordered: 915 case Opt_data_ordered:
916 data_opt = EXT3_MOUNT_ORDERED_DATA; 916 data_opt = EXT4_MOUNT_ORDERED_DATA;
917 goto datacheck; 917 goto datacheck;
918 case Opt_data_writeback: 918 case Opt_data_writeback:
919 data_opt = EXT3_MOUNT_WRITEBACK_DATA; 919 data_opt = EXT4_MOUNT_WRITEBACK_DATA;
920 datacheck: 920 datacheck:
921 if (is_remount) { 921 if (is_remount) {
922 if ((sbi->s_mount_opt & EXT3_MOUNT_DATA_FLAGS) 922 if ((sbi->s_mount_opt & EXT4_MOUNT_DATA_FLAGS)
923 != data_opt) { 923 != data_opt) {
924 printk(KERN_ERR 924 printk(KERN_ERR
925 "EXT3-fs: cannot change data " 925 "EXT4-fs: cannot change data "
926 "mode on remount\n"); 926 "mode on remount\n");
927 return 0; 927 return 0;
928 } 928 }
929 } else { 929 } else {
930 sbi->s_mount_opt &= ~EXT3_MOUNT_DATA_FLAGS; 930 sbi->s_mount_opt &= ~EXT4_MOUNT_DATA_FLAGS;
931 sbi->s_mount_opt |= data_opt; 931 sbi->s_mount_opt |= data_opt;
932 } 932 }
933 break; 933 break;
@@ -940,21 +940,21 @@ static int parse_options (char *options, struct super_block *sb,
940set_qf_name: 940set_qf_name:
941 if (sb_any_quota_enabled(sb)) { 941 if (sb_any_quota_enabled(sb)) {
942 printk(KERN_ERR 942 printk(KERN_ERR
943 "EXT3-fs: Cannot change journalled " 943 "EXT4-fs: Cannot change journalled "
944 "quota options when quota turned on.\n"); 944 "quota options when quota turned on.\n");
945 return 0; 945 return 0;
946 } 946 }
947 qname = match_strdup(&args[0]); 947 qname = match_strdup(&args[0]);
948 if (!qname) { 948 if (!qname) {
949 printk(KERN_ERR 949 printk(KERN_ERR
950 "EXT3-fs: not enough memory for " 950 "EXT4-fs: not enough memory for "
951 "storing quotafile name.\n"); 951 "storing quotafile name.\n");
952 return 0; 952 return 0;
953 } 953 }
954 if (sbi->s_qf_names[qtype] && 954 if (sbi->s_qf_names[qtype] &&
955 strcmp(sbi->s_qf_names[qtype], qname)) { 955 strcmp(sbi->s_qf_names[qtype], qname)) {
956 printk(KERN_ERR 956 printk(KERN_ERR
957 "EXT3-fs: %s quota file already " 957 "EXT4-fs: %s quota file already "
958 "specified.\n", QTYPE2NAME(qtype)); 958 "specified.\n", QTYPE2NAME(qtype));
959 kfree(qname); 959 kfree(qname);
960 return 0; 960 return 0;
@@ -962,7 +962,7 @@ set_qf_name:
962 sbi->s_qf_names[qtype] = qname; 962 sbi->s_qf_names[qtype] = qname;
963 if (strchr(sbi->s_qf_names[qtype], '/')) { 963 if (strchr(sbi->s_qf_names[qtype], '/')) {
964 printk(KERN_ERR 964 printk(KERN_ERR
965 "EXT3-fs: quotafile must be on " 965 "EXT4-fs: quotafile must be on "
966 "filesystem root.\n"); 966 "filesystem root.\n");
967 kfree(sbi->s_qf_names[qtype]); 967 kfree(sbi->s_qf_names[qtype]);
968 sbi->s_qf_names[qtype] = NULL; 968 sbi->s_qf_names[qtype] = NULL;
@@ -977,7 +977,7 @@ set_qf_name:
977 qtype = GRPQUOTA; 977 qtype = GRPQUOTA;
978clear_qf_name: 978clear_qf_name:
979 if (sb_any_quota_enabled(sb)) { 979 if (sb_any_quota_enabled(sb)) {
980 printk(KERN_ERR "EXT3-fs: Cannot change " 980 printk(KERN_ERR "EXT4-fs: Cannot change "
981 "journalled quota options when " 981 "journalled quota options when "
982 "quota turned on.\n"); 982 "quota turned on.\n");
983 return 0; 983 return 0;
@@ -1005,7 +1005,7 @@ clear_qf_name:
1005 break; 1005 break;
1006 case Opt_noquota: 1006 case Opt_noquota:
1007 if (sb_any_quota_enabled(sb)) { 1007 if (sb_any_quota_enabled(sb)) {
1008 printk(KERN_ERR "EXT3-fs: Cannot change quota " 1008 printk(KERN_ERR "EXT4-fs: Cannot change quota "
1009 "options when quota turned on.\n"); 1009 "options when quota turned on.\n");
1010 return 0; 1010 return 0;
1011 } 1011 }
@@ -1024,7 +1024,7 @@ clear_qf_name:
1024 case Opt_jqfmt_vfsold: 1024 case Opt_jqfmt_vfsold:
1025 case Opt_jqfmt_vfsv0: 1025 case Opt_jqfmt_vfsv0:
1026 printk(KERN_ERR 1026 printk(KERN_ERR
1027 "EXT3-fs: journalled quota options not " 1027 "EXT4-fs: journalled quota options not "
1028 "supported.\n"); 1028 "supported.\n");
1029 break; 1029 break;
1030 case Opt_noquota: 1030 case Opt_noquota:
@@ -1045,7 +1045,7 @@ clear_qf_name:
1045 break; 1045 break;
1046 case Opt_resize: 1046 case Opt_resize:
1047 if (!is_remount) { 1047 if (!is_remount) {
1048 printk("EXT3-fs: resize option only available " 1048 printk("EXT4-fs: resize option only available "
1049 "for remount\n"); 1049 "for remount\n");
1050 return 0; 1050 return 0;
1051 } 1051 }
@@ -1061,38 +1061,38 @@ clear_qf_name:
1061 break; 1061 break;
1062 default: 1062 default:
1063 printk (KERN_ERR 1063 printk (KERN_ERR
1064 "EXT3-fs: Unrecognized mount option \"%s\" " 1064 "EXT4-fs: Unrecognized mount option \"%s\" "
1065 "or missing value\n", p); 1065 "or missing value\n", p);
1066 return 0; 1066 return 0;
1067 } 1067 }
1068 } 1068 }
1069#ifdef CONFIG_QUOTA 1069#ifdef CONFIG_QUOTA
1070 if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) { 1070 if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) {
1071 if ((sbi->s_mount_opt & EXT3_MOUNT_USRQUOTA) && 1071 if ((sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA) &&
1072 sbi->s_qf_names[USRQUOTA]) 1072 sbi->s_qf_names[USRQUOTA])
1073 clear_opt(sbi->s_mount_opt, USRQUOTA); 1073 clear_opt(sbi->s_mount_opt, USRQUOTA);
1074 1074
1075 if ((sbi->s_mount_opt & EXT3_MOUNT_GRPQUOTA) && 1075 if ((sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA) &&
1076 sbi->s_qf_names[GRPQUOTA]) 1076 sbi->s_qf_names[GRPQUOTA])
1077 clear_opt(sbi->s_mount_opt, GRPQUOTA); 1077 clear_opt(sbi->s_mount_opt, GRPQUOTA);
1078 1078
1079 if ((sbi->s_qf_names[USRQUOTA] && 1079 if ((sbi->s_qf_names[USRQUOTA] &&
1080 (sbi->s_mount_opt & EXT3_MOUNT_GRPQUOTA)) || 1080 (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)) ||
1081 (sbi->s_qf_names[GRPQUOTA] && 1081 (sbi->s_qf_names[GRPQUOTA] &&
1082 (sbi->s_mount_opt & EXT3_MOUNT_USRQUOTA))) { 1082 (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA))) {
1083 printk(KERN_ERR "EXT3-fs: old and new quota " 1083 printk(KERN_ERR "EXT4-fs: old and new quota "
1084 "format mixing.\n"); 1084 "format mixing.\n");
1085 return 0; 1085 return 0;
1086 } 1086 }
1087 1087
1088 if (!sbi->s_jquota_fmt) { 1088 if (!sbi->s_jquota_fmt) {
1089 printk(KERN_ERR "EXT3-fs: journalled quota format " 1089 printk(KERN_ERR "EXT4-fs: journalled quota format "
1090 "not specified.\n"); 1090 "not specified.\n");
1091 return 0; 1091 return 0;
1092 } 1092 }
1093 } else { 1093 } else {
1094 if (sbi->s_jquota_fmt) { 1094 if (sbi->s_jquota_fmt) {
1095 printk(KERN_ERR "EXT3-fs: journalled quota format " 1095 printk(KERN_ERR "EXT4-fs: journalled quota format "
1096 "specified with no journalling " 1096 "specified with no journalling "
1097 "enabled.\n"); 1097 "enabled.\n");
1098 return 0; 1098 return 0;
@@ -1102,68 +1102,68 @@ clear_qf_name:
1102 return 1; 1102 return 1;
1103} 1103}
1104 1104
1105static int ext3_setup_super(struct super_block *sb, struct ext3_super_block *es, 1105static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
1106 int read_only) 1106 int read_only)
1107{ 1107{
1108 struct ext3_sb_info *sbi = EXT3_SB(sb); 1108 struct ext4_sb_info *sbi = EXT4_SB(sb);
1109 int res = 0; 1109 int res = 0;
1110 1110
1111 if (le32_to_cpu(es->s_rev_level) > EXT3_MAX_SUPP_REV) { 1111 if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) {
1112 printk (KERN_ERR "EXT3-fs warning: revision level too high, " 1112 printk (KERN_ERR "EXT4-fs warning: revision level too high, "
1113 "forcing read-only mode\n"); 1113 "forcing read-only mode\n");
1114 res = MS_RDONLY; 1114 res = MS_RDONLY;
1115 } 1115 }
1116 if (read_only) 1116 if (read_only)
1117 return res; 1117 return res;
1118 if (!(sbi->s_mount_state & EXT3_VALID_FS)) 1118 if (!(sbi->s_mount_state & EXT4_VALID_FS))
1119 printk (KERN_WARNING "EXT3-fs warning: mounting unchecked fs, " 1119 printk (KERN_WARNING "EXT4-fs warning: mounting unchecked fs, "
1120 "running e2fsck is recommended\n"); 1120 "running e2fsck is recommended\n");
1121 else if ((sbi->s_mount_state & EXT3_ERROR_FS)) 1121 else if ((sbi->s_mount_state & EXT4_ERROR_FS))
1122 printk (KERN_WARNING 1122 printk (KERN_WARNING
1123 "EXT3-fs warning: mounting fs with errors, " 1123 "EXT4-fs warning: mounting fs with errors, "
1124 "running e2fsck is recommended\n"); 1124 "running e2fsck is recommended\n");
1125 else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 && 1125 else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 &&
1126 le16_to_cpu(es->s_mnt_count) >= 1126 le16_to_cpu(es->s_mnt_count) >=
1127 (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count)) 1127 (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count))
1128 printk (KERN_WARNING 1128 printk (KERN_WARNING
1129 "EXT3-fs warning: maximal mount count reached, " 1129 "EXT4-fs warning: maximal mount count reached, "
1130 "running e2fsck is recommended\n"); 1130 "running e2fsck is recommended\n");
1131 else if (le32_to_cpu(es->s_checkinterval) && 1131 else if (le32_to_cpu(es->s_checkinterval) &&
1132 (le32_to_cpu(es->s_lastcheck) + 1132 (le32_to_cpu(es->s_lastcheck) +
1133 le32_to_cpu(es->s_checkinterval) <= get_seconds())) 1133 le32_to_cpu(es->s_checkinterval) <= get_seconds()))
1134 printk (KERN_WARNING 1134 printk (KERN_WARNING
1135 "EXT3-fs warning: checktime reached, " 1135 "EXT4-fs warning: checktime reached, "
1136 "running e2fsck is recommended\n"); 1136 "running e2fsck is recommended\n");
1137#if 0 1137#if 0
1138 /* @@@ We _will_ want to clear the valid bit if we find 1138 /* @@@ We _will_ want to clear the valid bit if we find
1139 inconsistencies, to force a fsck at reboot. But for 1139 inconsistencies, to force a fsck at reboot. But for
1140 a plain journaled filesystem we can keep it set as 1140 a plain journaled filesystem we can keep it set as
1141 valid forever! :) */ 1141 valid forever! :) */
1142 es->s_state = cpu_to_le16(le16_to_cpu(es->s_state) & ~EXT3_VALID_FS); 1142 es->s_state = cpu_to_le16(le16_to_cpu(es->s_state) & ~EXT4_VALID_FS);
1143#endif 1143#endif
1144 if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) 1144 if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
1145 es->s_max_mnt_count = cpu_to_le16(EXT3_DFL_MAX_MNT_COUNT); 1145 es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
1146 es->s_mnt_count=cpu_to_le16(le16_to_cpu(es->s_mnt_count) + 1); 1146 es->s_mnt_count=cpu_to_le16(le16_to_cpu(es->s_mnt_count) + 1);
1147 es->s_mtime = cpu_to_le32(get_seconds()); 1147 es->s_mtime = cpu_to_le32(get_seconds());
1148 ext3_update_dynamic_rev(sb); 1148 ext4_update_dynamic_rev(sb);
1149 EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); 1149 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
1150 1150
1151 ext3_commit_super(sb, es, 1); 1151 ext4_commit_super(sb, es, 1);
1152 if (test_opt(sb, DEBUG)) 1152 if (test_opt(sb, DEBUG))
1153 printk(KERN_INFO "[EXT3 FS bs=%lu, gc=%lu, " 1153 printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%lu, "
1154 "bpg=%lu, ipg=%lu, mo=%04lx]\n", 1154 "bpg=%lu, ipg=%lu, mo=%04lx]\n",
1155 sb->s_blocksize, 1155 sb->s_blocksize,
1156 sbi->s_groups_count, 1156 sbi->s_groups_count,
1157 EXT3_BLOCKS_PER_GROUP(sb), 1157 EXT4_BLOCKS_PER_GROUP(sb),
1158 EXT3_INODES_PER_GROUP(sb), 1158 EXT4_INODES_PER_GROUP(sb),
1159 sbi->s_mount_opt); 1159 sbi->s_mount_opt);
1160 1160
1161 printk(KERN_INFO "EXT3 FS on %s, ", sb->s_id); 1161 printk(KERN_INFO "EXT4 FS on %s, ", sb->s_id);
1162 if (EXT3_SB(sb)->s_journal->j_inode == NULL) { 1162 if (EXT4_SB(sb)->s_journal->j_inode == NULL) {
1163 char b[BDEVNAME_SIZE]; 1163 char b[BDEVNAME_SIZE];
1164 1164
1165 printk("external journal on %s\n", 1165 printk("external journal on %s\n",
1166 bdevname(EXT3_SB(sb)->s_journal->j_dev, b)); 1166 bdevname(EXT4_SB(sb)->s_journal->j_dev, b));
1167 } else { 1167 } else {
1168 printk("internal journal\n"); 1168 printk("internal journal\n");
1169 } 1169 }
@@ -1171,16 +1171,16 @@ static int ext3_setup_super(struct super_block *sb, struct ext3_super_block *es,
1171} 1171}
1172 1172
1173/* Called at mount-time, super-block is locked */ 1173/* Called at mount-time, super-block is locked */
1174static int ext3_check_descriptors (struct super_block * sb) 1174static int ext4_check_descriptors (struct super_block * sb)
1175{ 1175{
1176 struct ext3_sb_info *sbi = EXT3_SB(sb); 1176 struct ext4_sb_info *sbi = EXT4_SB(sb);
1177 ext3_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block); 1177 ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
1178 ext3_fsblk_t last_block; 1178 ext4_fsblk_t last_block;
1179 struct ext3_group_desc * gdp = NULL; 1179 struct ext4_group_desc * gdp = NULL;
1180 int desc_block = 0; 1180 int desc_block = 0;
1181 int i; 1181 int i;
1182 1182
1183 ext3_debug ("Checking group descriptors"); 1183 ext4_debug ("Checking group descriptors");
1184 1184
1185 for (i = 0; i < sbi->s_groups_count; i++) 1185 for (i = 0; i < sbi->s_groups_count; i++)
1186 { 1186 {
@@ -1188,15 +1188,15 @@ static int ext3_check_descriptors (struct super_block * sb)
1188 last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1; 1188 last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1;
1189 else 1189 else
1190 last_block = first_block + 1190 last_block = first_block +
1191 (EXT3_BLOCKS_PER_GROUP(sb) - 1); 1191 (EXT4_BLOCKS_PER_GROUP(sb) - 1);
1192 1192
1193 if ((i % EXT3_DESC_PER_BLOCK(sb)) == 0) 1193 if ((i % EXT4_DESC_PER_BLOCK(sb)) == 0)
1194 gdp = (struct ext3_group_desc *) 1194 gdp = (struct ext4_group_desc *)
1195 sbi->s_group_desc[desc_block++]->b_data; 1195 sbi->s_group_desc[desc_block++]->b_data;
1196 if (le32_to_cpu(gdp->bg_block_bitmap) < first_block || 1196 if (le32_to_cpu(gdp->bg_block_bitmap) < first_block ||
1197 le32_to_cpu(gdp->bg_block_bitmap) > last_block) 1197 le32_to_cpu(gdp->bg_block_bitmap) > last_block)
1198 { 1198 {
1199 ext3_error (sb, "ext3_check_descriptors", 1199 ext4_error (sb, "ext4_check_descriptors",
1200 "Block bitmap for group %d" 1200 "Block bitmap for group %d"
1201 " not in group (block %lu)!", 1201 " not in group (block %lu)!",
1202 i, (unsigned long) 1202 i, (unsigned long)
@@ -1206,7 +1206,7 @@ static int ext3_check_descriptors (struct super_block * sb)
1206 if (le32_to_cpu(gdp->bg_inode_bitmap) < first_block || 1206 if (le32_to_cpu(gdp->bg_inode_bitmap) < first_block ||
1207 le32_to_cpu(gdp->bg_inode_bitmap) > last_block) 1207 le32_to_cpu(gdp->bg_inode_bitmap) > last_block)
1208 { 1208 {
1209 ext3_error (sb, "ext3_check_descriptors", 1209 ext4_error (sb, "ext4_check_descriptors",
1210 "Inode bitmap for group %d" 1210 "Inode bitmap for group %d"
1211 " not in group (block %lu)!", 1211 " not in group (block %lu)!",
1212 i, (unsigned long) 1212 i, (unsigned long)
@@ -1217,24 +1217,24 @@ static int ext3_check_descriptors (struct super_block * sb)
1217 le32_to_cpu(gdp->bg_inode_table) + sbi->s_itb_per_group > 1217 le32_to_cpu(gdp->bg_inode_table) + sbi->s_itb_per_group >
1218 last_block) 1218 last_block)
1219 { 1219 {
1220 ext3_error (sb, "ext3_check_descriptors", 1220 ext4_error (sb, "ext4_check_descriptors",
1221 "Inode table for group %d" 1221 "Inode table for group %d"
1222 " not in group (block %lu)!", 1222 " not in group (block %lu)!",
1223 i, (unsigned long) 1223 i, (unsigned long)
1224 le32_to_cpu(gdp->bg_inode_table)); 1224 le32_to_cpu(gdp->bg_inode_table));
1225 return 0; 1225 return 0;
1226 } 1226 }
1227 first_block += EXT3_BLOCKS_PER_GROUP(sb); 1227 first_block += EXT4_BLOCKS_PER_GROUP(sb);
1228 gdp++; 1228 gdp++;
1229 } 1229 }
1230 1230
1231 sbi->s_es->s_free_blocks_count=cpu_to_le32(ext3_count_free_blocks(sb)); 1231 sbi->s_es->s_free_blocks_count=cpu_to_le32(ext4_count_free_blocks(sb));
1232 sbi->s_es->s_free_inodes_count=cpu_to_le32(ext3_count_free_inodes(sb)); 1232 sbi->s_es->s_free_inodes_count=cpu_to_le32(ext4_count_free_inodes(sb));
1233 return 1; 1233 return 1;
1234} 1234}
1235 1235
1236 1236
1237/* ext3_orphan_cleanup() walks a singly-linked list of inodes (starting at 1237/* ext4_orphan_cleanup() walks a singly-linked list of inodes (starting at
1238 * the superblock) which were deleted from all directories, but held open by 1238 * the superblock) which were deleted from all directories, but held open by
1239 * a process at the time of a crash. We walk the list and try to delete these 1239 * a process at the time of a crash. We walk the list and try to delete these
1240 * inodes at recovery time (only with a read-write filesystem). 1240 * inodes at recovery time (only with a read-write filesystem).
@@ -1247,12 +1247,12 @@ static int ext3_check_descriptors (struct super_block * sb)
1247 * We only do an iget() and an iput() on each inode, which is very safe if we 1247 * We only do an iget() and an iput() on each inode, which is very safe if we
1248 * accidentally point at an in-use or already deleted inode. The worst that 1248 * accidentally point at an in-use or already deleted inode. The worst that
1249 * can happen in this case is that we get a "bit already cleared" message from 1249 * can happen in this case is that we get a "bit already cleared" message from
1250 * ext3_free_inode(). The only reason we would point at a wrong inode is if 1250 * ext4_free_inode(). The only reason we would point at a wrong inode is if
1251 * e2fsck was run on this filesystem, and it must have already done the orphan 1251 * e2fsck was run on this filesystem, and it must have already done the orphan
1252 * inode cleanup for us, so we can safely abort without any further action. 1252 * inode cleanup for us, so we can safely abort without any further action.
1253 */ 1253 */
1254static void ext3_orphan_cleanup (struct super_block * sb, 1254static void ext4_orphan_cleanup (struct super_block * sb,
1255 struct ext3_super_block * es) 1255 struct ext4_super_block * es)
1256{ 1256{
1257 unsigned int s_flags = sb->s_flags; 1257 unsigned int s_flags = sb->s_flags;
1258 int nr_orphans = 0, nr_truncates = 0; 1258 int nr_orphans = 0, nr_truncates = 0;
@@ -1264,7 +1264,7 @@ static void ext3_orphan_cleanup (struct super_block * sb,
1264 return; 1264 return;
1265 } 1265 }
1266 1266
1267 if (EXT3_SB(sb)->s_mount_state & EXT3_ERROR_FS) { 1267 if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) {
1268 if (es->s_last_orphan) 1268 if (es->s_last_orphan)
1269 jbd_debug(1, "Errors on filesystem, " 1269 jbd_debug(1, "Errors on filesystem, "
1270 "clearing orphan list.\n"); 1270 "clearing orphan list.\n");
@@ -1274,7 +1274,7 @@ static void ext3_orphan_cleanup (struct super_block * sb,
1274 } 1274 }
1275 1275
1276 if (s_flags & MS_RDONLY) { 1276 if (s_flags & MS_RDONLY) {
1277 printk(KERN_INFO "EXT3-fs: %s: orphan cleanup on readonly fs\n", 1277 printk(KERN_INFO "EXT4-fs: %s: orphan cleanup on readonly fs\n",
1278 sb->s_id); 1278 sb->s_id);
1279 sb->s_flags &= ~MS_RDONLY; 1279 sb->s_flags &= ~MS_RDONLY;
1280 } 1280 }
@@ -1283,11 +1283,11 @@ static void ext3_orphan_cleanup (struct super_block * sb,
1283 sb->s_flags |= MS_ACTIVE; 1283 sb->s_flags |= MS_ACTIVE;
1284 /* Turn on quotas so that they are updated correctly */ 1284 /* Turn on quotas so that they are updated correctly */
1285 for (i = 0; i < MAXQUOTAS; i++) { 1285 for (i = 0; i < MAXQUOTAS; i++) {
1286 if (EXT3_SB(sb)->s_qf_names[i]) { 1286 if (EXT4_SB(sb)->s_qf_names[i]) {
1287 int ret = ext3_quota_on_mount(sb, i); 1287 int ret = ext4_quota_on_mount(sb, i);
1288 if (ret < 0) 1288 if (ret < 0)
1289 printk(KERN_ERR 1289 printk(KERN_ERR
1290 "EXT3-fs: Cannot turn on journalled " 1290 "EXT4-fs: Cannot turn on journalled "
1291 "quota: error %d\n", ret); 1291 "quota: error %d\n", ret);
1292 } 1292 }
1293 } 1293 }
@@ -1297,12 +1297,12 @@ static void ext3_orphan_cleanup (struct super_block * sb,
1297 struct inode *inode; 1297 struct inode *inode;
1298 1298
1299 if (!(inode = 1299 if (!(inode =
1300 ext3_orphan_get(sb, le32_to_cpu(es->s_last_orphan)))) { 1300 ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan)))) {
1301 es->s_last_orphan = 0; 1301 es->s_last_orphan = 0;
1302 break; 1302 break;
1303 } 1303 }
1304 1304
1305 list_add(&EXT3_I(inode)->i_orphan, &EXT3_SB(sb)->s_orphan); 1305 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
1306 DQUOT_INIT(inode); 1306 DQUOT_INIT(inode);
1307 if (inode->i_nlink) { 1307 if (inode->i_nlink) {
1308 printk(KERN_DEBUG 1308 printk(KERN_DEBUG
@@ -1310,7 +1310,7 @@ static void ext3_orphan_cleanup (struct super_block * sb,
1310 __FUNCTION__, inode->i_ino, inode->i_size); 1310 __FUNCTION__, inode->i_ino, inode->i_size);
1311 jbd_debug(2, "truncating inode %lu to %Ld bytes\n", 1311 jbd_debug(2, "truncating inode %lu to %Ld bytes\n",
1312 inode->i_ino, inode->i_size); 1312 inode->i_ino, inode->i_size);
1313 ext3_truncate(inode); 1313 ext4_truncate(inode);
1314 nr_truncates++; 1314 nr_truncates++;
1315 } else { 1315 } else {
1316 printk(KERN_DEBUG 1316 printk(KERN_DEBUG
@@ -1326,10 +1326,10 @@ static void ext3_orphan_cleanup (struct super_block * sb,
1326#define PLURAL(x) (x), ((x)==1) ? "" : "s" 1326#define PLURAL(x) (x), ((x)==1) ? "" : "s"
1327 1327
1328 if (nr_orphans) 1328 if (nr_orphans)
1329 printk(KERN_INFO "EXT3-fs: %s: %d orphan inode%s deleted\n", 1329 printk(KERN_INFO "EXT4-fs: %s: %d orphan inode%s deleted\n",
1330 sb->s_id, PLURAL(nr_orphans)); 1330 sb->s_id, PLURAL(nr_orphans));
1331 if (nr_truncates) 1331 if (nr_truncates)
1332 printk(KERN_INFO "EXT3-fs: %s: %d truncate%s cleaned up\n", 1332 printk(KERN_INFO "EXT4-fs: %s: %d truncate%s cleaned up\n",
1333 sb->s_id, PLURAL(nr_truncates)); 1333 sb->s_id, PLURAL(nr_truncates));
1334#ifdef CONFIG_QUOTA 1334#ifdef CONFIG_QUOTA
1335 /* Turn quotas off */ 1335 /* Turn quotas off */
@@ -1348,9 +1348,9 @@ static void ext3_orphan_cleanup (struct super_block * sb,
1348 * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks. 1348 * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks.
1349 * We need to be 1 filesystem block less than the 2^32 sector limit. 1349 * We need to be 1 filesystem block less than the 2^32 sector limit.
1350 */ 1350 */
1351static loff_t ext3_max_size(int bits) 1351static loff_t ext4_max_size(int bits)
1352{ 1352{
1353 loff_t res = EXT3_NDIR_BLOCKS; 1353 loff_t res = EXT4_NDIR_BLOCKS;
1354 /* This constant is calculated to be the largest file size for a 1354 /* This constant is calculated to be the largest file size for a
1355 * dense, 4k-blocksize file such that the total number of 1355 * dense, 4k-blocksize file such that the total number of
1356 * sectors in the file, including data and all indirect blocks, 1356 * sectors in the file, including data and all indirect blocks,
@@ -1366,34 +1366,34 @@ static loff_t ext3_max_size(int bits)
1366 return res; 1366 return res;
1367} 1367}
1368 1368
1369static ext3_fsblk_t descriptor_loc(struct super_block *sb, 1369static ext4_fsblk_t descriptor_loc(struct super_block *sb,
1370 ext3_fsblk_t logic_sb_block, 1370 ext4_fsblk_t logic_sb_block,
1371 int nr) 1371 int nr)
1372{ 1372{
1373 struct ext3_sb_info *sbi = EXT3_SB(sb); 1373 struct ext4_sb_info *sbi = EXT4_SB(sb);
1374 unsigned long bg, first_meta_bg; 1374 unsigned long bg, first_meta_bg;
1375 int has_super = 0; 1375 int has_super = 0;
1376 1376
1377 first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg); 1377 first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg);
1378 1378
1379 if (!EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_META_BG) || 1379 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_META_BG) ||
1380 nr < first_meta_bg) 1380 nr < first_meta_bg)
1381 return (logic_sb_block + nr + 1); 1381 return (logic_sb_block + nr + 1);
1382 bg = sbi->s_desc_per_block * nr; 1382 bg = sbi->s_desc_per_block * nr;
1383 if (ext3_bg_has_super(sb, bg)) 1383 if (ext4_bg_has_super(sb, bg))
1384 has_super = 1; 1384 has_super = 1;
1385 return (has_super + ext3_group_first_block_no(sb, bg)); 1385 return (has_super + ext4_group_first_block_no(sb, bg));
1386} 1386}
1387 1387
1388 1388
1389static int ext3_fill_super (struct super_block *sb, void *data, int silent) 1389static int ext4_fill_super (struct super_block *sb, void *data, int silent)
1390{ 1390{
1391 struct buffer_head * bh; 1391 struct buffer_head * bh;
1392 struct ext3_super_block *es = NULL; 1392 struct ext4_super_block *es = NULL;
1393 struct ext3_sb_info *sbi; 1393 struct ext4_sb_info *sbi;
1394 ext3_fsblk_t block; 1394 ext4_fsblk_t block;
1395 ext3_fsblk_t sb_block = get_sb_block(&data); 1395 ext4_fsblk_t sb_block = get_sb_block(&data);
1396 ext3_fsblk_t logic_sb_block; 1396 ext4_fsblk_t logic_sb_block;
1397 unsigned long offset = 0; 1397 unsigned long offset = 0;
1398 unsigned int journal_inum = 0; 1398 unsigned int journal_inum = 0;
1399 unsigned long journal_devnum = 0; 1399 unsigned long journal_devnum = 0;
@@ -1411,64 +1411,64 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1411 return -ENOMEM; 1411 return -ENOMEM;
1412 sb->s_fs_info = sbi; 1412 sb->s_fs_info = sbi;
1413 sbi->s_mount_opt = 0; 1413 sbi->s_mount_opt = 0;
1414 sbi->s_resuid = EXT3_DEF_RESUID; 1414 sbi->s_resuid = EXT4_DEF_RESUID;
1415 sbi->s_resgid = EXT3_DEF_RESGID; 1415 sbi->s_resgid = EXT4_DEF_RESGID;
1416 1416
1417 unlock_kernel(); 1417 unlock_kernel();
1418 1418
1419 blocksize = sb_min_blocksize(sb, EXT3_MIN_BLOCK_SIZE); 1419 blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);
1420 if (!blocksize) { 1420 if (!blocksize) {
1421 printk(KERN_ERR "EXT3-fs: unable to set blocksize\n"); 1421 printk(KERN_ERR "EXT4-fs: unable to set blocksize\n");
1422 goto out_fail; 1422 goto out_fail;
1423 } 1423 }
1424 1424
1425 /* 1425 /*
1426 * The ext3 superblock will not be buffer aligned for other than 1kB 1426 * The ext4 superblock will not be buffer aligned for other than 1kB
1427 * block sizes. We need to calculate the offset from buffer start. 1427 * block sizes. We need to calculate the offset from buffer start.
1428 */ 1428 */
1429 if (blocksize != EXT3_MIN_BLOCK_SIZE) { 1429 if (blocksize != EXT4_MIN_BLOCK_SIZE) {
1430 logic_sb_block = (sb_block * EXT3_MIN_BLOCK_SIZE) / blocksize; 1430 logic_sb_block = (sb_block * EXT4_MIN_BLOCK_SIZE) / blocksize;
1431 offset = (sb_block * EXT3_MIN_BLOCK_SIZE) % blocksize; 1431 offset = (sb_block * EXT4_MIN_BLOCK_SIZE) % blocksize;
1432 } else { 1432 } else {
1433 logic_sb_block = sb_block; 1433 logic_sb_block = sb_block;
1434 } 1434 }
1435 1435
1436 if (!(bh = sb_bread(sb, logic_sb_block))) { 1436 if (!(bh = sb_bread(sb, logic_sb_block))) {
1437 printk (KERN_ERR "EXT3-fs: unable to read superblock\n"); 1437 printk (KERN_ERR "EXT4-fs: unable to read superblock\n");
1438 goto out_fail; 1438 goto out_fail;
1439 } 1439 }
1440 /* 1440 /*
1441 * Note: s_es must be initialized as soon as possible because 1441 * Note: s_es must be initialized as soon as possible because
1442 * some ext3 macro-instructions depend on its value 1442 * some ext4 macro-instructions depend on its value
1443 */ 1443 */
1444 es = (struct ext3_super_block *) (((char *)bh->b_data) + offset); 1444 es = (struct ext4_super_block *) (((char *)bh->b_data) + offset);
1445 sbi->s_es = es; 1445 sbi->s_es = es;
1446 sb->s_magic = le16_to_cpu(es->s_magic); 1446 sb->s_magic = le16_to_cpu(es->s_magic);
1447 if (sb->s_magic != EXT3_SUPER_MAGIC) 1447 if (sb->s_magic != EXT4_SUPER_MAGIC)
1448 goto cantfind_ext3; 1448 goto cantfind_ext4;
1449 1449
1450 /* Set defaults before we parse the mount options */ 1450 /* Set defaults before we parse the mount options */
1451 def_mount_opts = le32_to_cpu(es->s_default_mount_opts); 1451 def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
1452 if (def_mount_opts & EXT3_DEFM_DEBUG) 1452 if (def_mount_opts & EXT4_DEFM_DEBUG)
1453 set_opt(sbi->s_mount_opt, DEBUG); 1453 set_opt(sbi->s_mount_opt, DEBUG);
1454 if (def_mount_opts & EXT3_DEFM_BSDGROUPS) 1454 if (def_mount_opts & EXT4_DEFM_BSDGROUPS)
1455 set_opt(sbi->s_mount_opt, GRPID); 1455 set_opt(sbi->s_mount_opt, GRPID);
1456 if (def_mount_opts & EXT3_DEFM_UID16) 1456 if (def_mount_opts & EXT4_DEFM_UID16)
1457 set_opt(sbi->s_mount_opt, NO_UID32); 1457 set_opt(sbi->s_mount_opt, NO_UID32);
1458 if (def_mount_opts & EXT3_DEFM_XATTR_USER) 1458 if (def_mount_opts & EXT4_DEFM_XATTR_USER)
1459 set_opt(sbi->s_mount_opt, XATTR_USER); 1459 set_opt(sbi->s_mount_opt, XATTR_USER);
1460 if (def_mount_opts & EXT3_DEFM_ACL) 1460 if (def_mount_opts & EXT4_DEFM_ACL)
1461 set_opt(sbi->s_mount_opt, POSIX_ACL); 1461 set_opt(sbi->s_mount_opt, POSIX_ACL);
1462 if ((def_mount_opts & EXT3_DEFM_JMODE) == EXT3_DEFM_JMODE_DATA) 1462 if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_DATA)
1463 sbi->s_mount_opt |= EXT3_MOUNT_JOURNAL_DATA; 1463 sbi->s_mount_opt |= EXT4_MOUNT_JOURNAL_DATA;
1464 else if ((def_mount_opts & EXT3_DEFM_JMODE) == EXT3_DEFM_JMODE_ORDERED) 1464 else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_ORDERED)
1465 sbi->s_mount_opt |= EXT3_MOUNT_ORDERED_DATA; 1465 sbi->s_mount_opt |= EXT4_MOUNT_ORDERED_DATA;
1466 else if ((def_mount_opts & EXT3_DEFM_JMODE) == EXT3_DEFM_JMODE_WBACK) 1466 else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_WBACK)
1467 sbi->s_mount_opt |= EXT3_MOUNT_WRITEBACK_DATA; 1467 sbi->s_mount_opt |= EXT4_MOUNT_WRITEBACK_DATA;
1468 1468
1469 if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_PANIC) 1469 if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC)
1470 set_opt(sbi->s_mount_opt, ERRORS_PANIC); 1470 set_opt(sbi->s_mount_opt, ERRORS_PANIC);
1471 else if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_RO) 1471 else if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_RO)
1472 set_opt(sbi->s_mount_opt, ERRORS_RO); 1472 set_opt(sbi->s_mount_opt, ERRORS_RO);
1473 1473
1474 sbi->s_resuid = le16_to_cpu(es->s_def_resuid); 1474 sbi->s_resuid = le16_to_cpu(es->s_def_resuid);
@@ -1481,40 +1481,40 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1481 goto failed_mount; 1481 goto failed_mount;
1482 1482
1483 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 1483 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
1484 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); 1484 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
1485 1485
1486 if (le32_to_cpu(es->s_rev_level) == EXT3_GOOD_OLD_REV && 1486 if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV &&
1487 (EXT3_HAS_COMPAT_FEATURE(sb, ~0U) || 1487 (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) ||
1488 EXT3_HAS_RO_COMPAT_FEATURE(sb, ~0U) || 1488 EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
1489 EXT3_HAS_INCOMPAT_FEATURE(sb, ~0U))) 1489 EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U)))
1490 printk(KERN_WARNING 1490 printk(KERN_WARNING
1491 "EXT3-fs warning: feature flags set on rev 0 fs, " 1491 "EXT4-fs warning: feature flags set on rev 0 fs, "
1492 "running e2fsck is recommended\n"); 1492 "running e2fsck is recommended\n");
1493 /* 1493 /*
1494 * Check feature flags regardless of the revision level, since we 1494 * Check feature flags regardless of the revision level, since we
1495 * previously didn't change the revision level when setting the flags, 1495 * previously didn't change the revision level when setting the flags,
1496 * so there is a chance incompat flags are set on a rev 0 filesystem. 1496 * so there is a chance incompat flags are set on a rev 0 filesystem.
1497 */ 1497 */
1498 features = EXT3_HAS_INCOMPAT_FEATURE(sb, ~EXT3_FEATURE_INCOMPAT_SUPP); 1498 features = EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP);
1499 if (features) { 1499 if (features) {
1500 printk(KERN_ERR "EXT3-fs: %s: couldn't mount because of " 1500 printk(KERN_ERR "EXT4-fs: %s: couldn't mount because of "
1501 "unsupported optional features (%x).\n", 1501 "unsupported optional features (%x).\n",
1502 sb->s_id, le32_to_cpu(features)); 1502 sb->s_id, le32_to_cpu(features));
1503 goto failed_mount; 1503 goto failed_mount;
1504 } 1504 }
1505 features = EXT3_HAS_RO_COMPAT_FEATURE(sb, ~EXT3_FEATURE_RO_COMPAT_SUPP); 1505 features = EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP);
1506 if (!(sb->s_flags & MS_RDONLY) && features) { 1506 if (!(sb->s_flags & MS_RDONLY) && features) {
1507 printk(KERN_ERR "EXT3-fs: %s: couldn't mount RDWR because of " 1507 printk(KERN_ERR "EXT4-fs: %s: couldn't mount RDWR because of "
1508 "unsupported optional features (%x).\n", 1508 "unsupported optional features (%x).\n",
1509 sb->s_id, le32_to_cpu(features)); 1509 sb->s_id, le32_to_cpu(features));
1510 goto failed_mount; 1510 goto failed_mount;
1511 } 1511 }
1512 blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size); 1512 blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size);
1513 1513
1514 if (blocksize < EXT3_MIN_BLOCK_SIZE || 1514 if (blocksize < EXT4_MIN_BLOCK_SIZE ||
1515 blocksize > EXT3_MAX_BLOCK_SIZE) { 1515 blocksize > EXT4_MAX_BLOCK_SIZE) {
1516 printk(KERN_ERR 1516 printk(KERN_ERR
1517 "EXT3-fs: Unsupported filesystem blocksize %d on %s.\n", 1517 "EXT4-fs: Unsupported filesystem blocksize %d on %s.\n",
1518 blocksize, sb->s_id); 1518 blocksize, sb->s_id);
1519 goto failed_mount; 1519 goto failed_mount;
1520 } 1520 }
@@ -1526,52 +1526,52 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1526 * than the hardware sectorsize for the machine. 1526 * than the hardware sectorsize for the machine.
1527 */ 1527 */
1528 if (blocksize < hblock) { 1528 if (blocksize < hblock) {
1529 printk(KERN_ERR "EXT3-fs: blocksize %d too small for " 1529 printk(KERN_ERR "EXT4-fs: blocksize %d too small for "
1530 "device blocksize %d.\n", blocksize, hblock); 1530 "device blocksize %d.\n", blocksize, hblock);
1531 goto failed_mount; 1531 goto failed_mount;
1532 } 1532 }
1533 1533
1534 brelse (bh); 1534 brelse (bh);
1535 sb_set_blocksize(sb, blocksize); 1535 sb_set_blocksize(sb, blocksize);
1536 logic_sb_block = (sb_block * EXT3_MIN_BLOCK_SIZE) / blocksize; 1536 logic_sb_block = (sb_block * EXT4_MIN_BLOCK_SIZE) / blocksize;
1537 offset = (sb_block * EXT3_MIN_BLOCK_SIZE) % blocksize; 1537 offset = (sb_block * EXT4_MIN_BLOCK_SIZE) % blocksize;
1538 bh = sb_bread(sb, logic_sb_block); 1538 bh = sb_bread(sb, logic_sb_block);
1539 if (!bh) { 1539 if (!bh) {
1540 printk(KERN_ERR 1540 printk(KERN_ERR
1541 "EXT3-fs: Can't read superblock on 2nd try.\n"); 1541 "EXT4-fs: Can't read superblock on 2nd try.\n");
1542 goto failed_mount; 1542 goto failed_mount;
1543 } 1543 }
1544 es = (struct ext3_super_block *)(((char *)bh->b_data) + offset); 1544 es = (struct ext4_super_block *)(((char *)bh->b_data) + offset);
1545 sbi->s_es = es; 1545 sbi->s_es = es;
1546 if (es->s_magic != cpu_to_le16(EXT3_SUPER_MAGIC)) { 1546 if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) {
1547 printk (KERN_ERR 1547 printk (KERN_ERR
1548 "EXT3-fs: Magic mismatch, very weird !\n"); 1548 "EXT4-fs: Magic mismatch, very weird !\n");
1549 goto failed_mount; 1549 goto failed_mount;
1550 } 1550 }
1551 } 1551 }
1552 1552
1553 sb->s_maxbytes = ext3_max_size(sb->s_blocksize_bits); 1553 sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits);
1554 1554
1555 if (le32_to_cpu(es->s_rev_level) == EXT3_GOOD_OLD_REV) { 1555 if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) {
1556 sbi->s_inode_size = EXT3_GOOD_OLD_INODE_SIZE; 1556 sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE;
1557 sbi->s_first_ino = EXT3_GOOD_OLD_FIRST_INO; 1557 sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO;
1558 } else { 1558 } else {
1559 sbi->s_inode_size = le16_to_cpu(es->s_inode_size); 1559 sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
1560 sbi->s_first_ino = le32_to_cpu(es->s_first_ino); 1560 sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
1561 if ((sbi->s_inode_size < EXT3_GOOD_OLD_INODE_SIZE) || 1561 if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) ||
1562 (sbi->s_inode_size & (sbi->s_inode_size - 1)) || 1562 (sbi->s_inode_size & (sbi->s_inode_size - 1)) ||
1563 (sbi->s_inode_size > blocksize)) { 1563 (sbi->s_inode_size > blocksize)) {
1564 printk (KERN_ERR 1564 printk (KERN_ERR
1565 "EXT3-fs: unsupported inode size: %d\n", 1565 "EXT4-fs: unsupported inode size: %d\n",
1566 sbi->s_inode_size); 1566 sbi->s_inode_size);
1567 goto failed_mount; 1567 goto failed_mount;
1568 } 1568 }
1569 } 1569 }
1570 sbi->s_frag_size = EXT3_MIN_FRAG_SIZE << 1570 sbi->s_frag_size = EXT4_MIN_FRAG_SIZE <<
1571 le32_to_cpu(es->s_log_frag_size); 1571 le32_to_cpu(es->s_log_frag_size);
1572 if (blocksize != sbi->s_frag_size) { 1572 if (blocksize != sbi->s_frag_size) {
1573 printk(KERN_ERR 1573 printk(KERN_ERR
1574 "EXT3-fs: fragsize %lu != blocksize %u (unsupported)\n", 1574 "EXT4-fs: fragsize %lu != blocksize %u (unsupported)\n",
1575 sbi->s_frag_size, blocksize); 1575 sbi->s_frag_size, blocksize);
1576 goto failed_mount; 1576 goto failed_mount;
1577 } 1577 }
@@ -1579,62 +1579,62 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1579 sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group); 1579 sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
1580 sbi->s_frags_per_group = le32_to_cpu(es->s_frags_per_group); 1580 sbi->s_frags_per_group = le32_to_cpu(es->s_frags_per_group);
1581 sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group); 1581 sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
1582 if (EXT3_INODE_SIZE(sb) == 0) 1582 if (EXT4_INODE_SIZE(sb) == 0)
1583 goto cantfind_ext3; 1583 goto cantfind_ext4;
1584 sbi->s_inodes_per_block = blocksize / EXT3_INODE_SIZE(sb); 1584 sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb);
1585 if (sbi->s_inodes_per_block == 0) 1585 if (sbi->s_inodes_per_block == 0)
1586 goto cantfind_ext3; 1586 goto cantfind_ext4;
1587 sbi->s_itb_per_group = sbi->s_inodes_per_group / 1587 sbi->s_itb_per_group = sbi->s_inodes_per_group /
1588 sbi->s_inodes_per_block; 1588 sbi->s_inodes_per_block;
1589 sbi->s_desc_per_block = blocksize / sizeof(struct ext3_group_desc); 1589 sbi->s_desc_per_block = blocksize / sizeof(struct ext4_group_desc);
1590 sbi->s_sbh = bh; 1590 sbi->s_sbh = bh;
1591 sbi->s_mount_state = le16_to_cpu(es->s_state); 1591 sbi->s_mount_state = le16_to_cpu(es->s_state);
1592 sbi->s_addr_per_block_bits = log2(EXT3_ADDR_PER_BLOCK(sb)); 1592 sbi->s_addr_per_block_bits = log2(EXT4_ADDR_PER_BLOCK(sb));
1593 sbi->s_desc_per_block_bits = log2(EXT3_DESC_PER_BLOCK(sb)); 1593 sbi->s_desc_per_block_bits = log2(EXT4_DESC_PER_BLOCK(sb));
1594 for (i=0; i < 4; i++) 1594 for (i=0; i < 4; i++)
1595 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); 1595 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
1596 sbi->s_def_hash_version = es->s_def_hash_version; 1596 sbi->s_def_hash_version = es->s_def_hash_version;
1597 1597
1598 if (sbi->s_blocks_per_group > blocksize * 8) { 1598 if (sbi->s_blocks_per_group > blocksize * 8) {
1599 printk (KERN_ERR 1599 printk (KERN_ERR
1600 "EXT3-fs: #blocks per group too big: %lu\n", 1600 "EXT4-fs: #blocks per group too big: %lu\n",
1601 sbi->s_blocks_per_group); 1601 sbi->s_blocks_per_group);
1602 goto failed_mount; 1602 goto failed_mount;
1603 } 1603 }
1604 if (sbi->s_frags_per_group > blocksize * 8) { 1604 if (sbi->s_frags_per_group > blocksize * 8) {
1605 printk (KERN_ERR 1605 printk (KERN_ERR
1606 "EXT3-fs: #fragments per group too big: %lu\n", 1606 "EXT4-fs: #fragments per group too big: %lu\n",
1607 sbi->s_frags_per_group); 1607 sbi->s_frags_per_group);
1608 goto failed_mount; 1608 goto failed_mount;
1609 } 1609 }
1610 if (sbi->s_inodes_per_group > blocksize * 8) { 1610 if (sbi->s_inodes_per_group > blocksize * 8) {
1611 printk (KERN_ERR 1611 printk (KERN_ERR
1612 "EXT3-fs: #inodes per group too big: %lu\n", 1612 "EXT4-fs: #inodes per group too big: %lu\n",
1613 sbi->s_inodes_per_group); 1613 sbi->s_inodes_per_group);
1614 goto failed_mount; 1614 goto failed_mount;
1615 } 1615 }
1616 1616
1617 if (le32_to_cpu(es->s_blocks_count) > 1617 if (le32_to_cpu(es->s_blocks_count) >
1618 (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) { 1618 (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
1619 printk(KERN_ERR "EXT3-fs: filesystem on %s:" 1619 printk(KERN_ERR "EXT4-fs: filesystem on %s:"
1620 " too large to mount safely\n", sb->s_id); 1620 " too large to mount safely\n", sb->s_id);
1621 if (sizeof(sector_t) < 8) 1621 if (sizeof(sector_t) < 8)
1622 printk(KERN_WARNING "EXT3-fs: CONFIG_LBD not " 1622 printk(KERN_WARNING "EXT4-fs: CONFIG_LBD not "
1623 "enabled\n"); 1623 "enabled\n");
1624 goto failed_mount; 1624 goto failed_mount;
1625 } 1625 }
1626 1626
1627 if (EXT3_BLOCKS_PER_GROUP(sb) == 0) 1627 if (EXT4_BLOCKS_PER_GROUP(sb) == 0)
1628 goto cantfind_ext3; 1628 goto cantfind_ext4;
1629 sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) - 1629 sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) -
1630 le32_to_cpu(es->s_first_data_block) - 1) 1630 le32_to_cpu(es->s_first_data_block) - 1)
1631 / EXT3_BLOCKS_PER_GROUP(sb)) + 1; 1631 / EXT4_BLOCKS_PER_GROUP(sb)) + 1;
1632 db_count = (sbi->s_groups_count + EXT3_DESC_PER_BLOCK(sb) - 1) / 1632 db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
1633 EXT3_DESC_PER_BLOCK(sb); 1633 EXT4_DESC_PER_BLOCK(sb);
1634 sbi->s_group_desc = kmalloc(db_count * sizeof (struct buffer_head *), 1634 sbi->s_group_desc = kmalloc(db_count * sizeof (struct buffer_head *),
1635 GFP_KERNEL); 1635 GFP_KERNEL);
1636 if (sbi->s_group_desc == NULL) { 1636 if (sbi->s_group_desc == NULL) {
1637 printk (KERN_ERR "EXT3-fs: not enough memory\n"); 1637 printk (KERN_ERR "EXT4-fs: not enough memory\n");
1638 goto failed_mount; 1638 goto failed_mount;
1639 } 1639 }
1640 1640
@@ -1644,14 +1644,14 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1644 block = descriptor_loc(sb, logic_sb_block, i); 1644 block = descriptor_loc(sb, logic_sb_block, i);
1645 sbi->s_group_desc[i] = sb_bread(sb, block); 1645 sbi->s_group_desc[i] = sb_bread(sb, block);
1646 if (!sbi->s_group_desc[i]) { 1646 if (!sbi->s_group_desc[i]) {
1647 printk (KERN_ERR "EXT3-fs: " 1647 printk (KERN_ERR "EXT4-fs: "
1648 "can't read group descriptor %d\n", i); 1648 "can't read group descriptor %d\n", i);
1649 db_count = i; 1649 db_count = i;
1650 goto failed_mount2; 1650 goto failed_mount2;
1651 } 1651 }
1652 } 1652 }
1653 if (!ext3_check_descriptors (sb)) { 1653 if (!ext4_check_descriptors (sb)) {
1654 printk(KERN_ERR "EXT3-fs: group descriptors corrupted!\n"); 1654 printk(KERN_ERR "EXT4-fs: group descriptors corrupted!\n");
1655 goto failed_mount2; 1655 goto failed_mount2;
1656 } 1656 }
1657 sbi->s_gdb_count = db_count; 1657 sbi->s_gdb_count = db_count;
@@ -1659,11 +1659,11 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1659 spin_lock_init(&sbi->s_next_gen_lock); 1659 spin_lock_init(&sbi->s_next_gen_lock);
1660 1660
1661 percpu_counter_init(&sbi->s_freeblocks_counter, 1661 percpu_counter_init(&sbi->s_freeblocks_counter,
1662 ext3_count_free_blocks(sb)); 1662 ext4_count_free_blocks(sb));
1663 percpu_counter_init(&sbi->s_freeinodes_counter, 1663 percpu_counter_init(&sbi->s_freeinodes_counter,
1664 ext3_count_free_inodes(sb)); 1664 ext4_count_free_inodes(sb));
1665 percpu_counter_init(&sbi->s_dirs_counter, 1665 percpu_counter_init(&sbi->s_dirs_counter,
1666 ext3_count_dirs(sb)); 1666 ext4_count_dirs(sb));
1667 1667
1668 /* per fileystem reservation list head & lock */ 1668 /* per fileystem reservation list head & lock */
1669 spin_lock_init(&sbi->s_rsv_window_lock); 1669 spin_lock_init(&sbi->s_rsv_window_lock);
@@ -1672,45 +1672,45 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1672 * reservation window list --- it gives us a placeholder for 1672 * reservation window list --- it gives us a placeholder for
1673 * append-at-start-of-list which makes the allocation logic 1673 * append-at-start-of-list which makes the allocation logic
1674 * _much_ simpler. */ 1674 * _much_ simpler. */
1675 sbi->s_rsv_window_head.rsv_start = EXT3_RESERVE_WINDOW_NOT_ALLOCATED; 1675 sbi->s_rsv_window_head.rsv_start = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
1676 sbi->s_rsv_window_head.rsv_end = EXT3_RESERVE_WINDOW_NOT_ALLOCATED; 1676 sbi->s_rsv_window_head.rsv_end = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
1677 sbi->s_rsv_window_head.rsv_alloc_hit = 0; 1677 sbi->s_rsv_window_head.rsv_alloc_hit = 0;
1678 sbi->s_rsv_window_head.rsv_goal_size = 0; 1678 sbi->s_rsv_window_head.rsv_goal_size = 0;
1679 ext3_rsv_window_add(sb, &sbi->s_rsv_window_head); 1679 ext4_rsv_window_add(sb, &sbi->s_rsv_window_head);
1680 1680
1681 /* 1681 /*
1682 * set up enough so that it can read an inode 1682 * set up enough so that it can read an inode
1683 */ 1683 */
1684 sb->s_op = &ext3_sops; 1684 sb->s_op = &ext4_sops;
1685 sb->s_export_op = &ext3_export_ops; 1685 sb->s_export_op = &ext4_export_ops;
1686 sb->s_xattr = ext3_xattr_handlers; 1686 sb->s_xattr = ext4_xattr_handlers;
1687#ifdef CONFIG_QUOTA 1687#ifdef CONFIG_QUOTA
1688 sb->s_qcop = &ext3_qctl_operations; 1688 sb->s_qcop = &ext4_qctl_operations;
1689 sb->dq_op = &ext3_quota_operations; 1689 sb->dq_op = &ext4_quota_operations;
1690#endif 1690#endif
1691 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */ 1691 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
1692 1692
1693 sb->s_root = NULL; 1693 sb->s_root = NULL;
1694 1694
1695 needs_recovery = (es->s_last_orphan != 0 || 1695 needs_recovery = (es->s_last_orphan != 0 ||
1696 EXT3_HAS_INCOMPAT_FEATURE(sb, 1696 EXT4_HAS_INCOMPAT_FEATURE(sb,
1697 EXT3_FEATURE_INCOMPAT_RECOVER)); 1697 EXT4_FEATURE_INCOMPAT_RECOVER));
1698 1698
1699 /* 1699 /*
1700 * The first inode we look at is the journal inode. Don't try 1700 * The first inode we look at is the journal inode. Don't try
1701 * root first: it may be modified in the journal! 1701 * root first: it may be modified in the journal!
1702 */ 1702 */
1703 if (!test_opt(sb, NOLOAD) && 1703 if (!test_opt(sb, NOLOAD) &&
1704 EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) { 1704 EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) {
1705 if (ext3_load_journal(sb, es, journal_devnum)) 1705 if (ext4_load_journal(sb, es, journal_devnum))
1706 goto failed_mount3; 1706 goto failed_mount3;
1707 } else if (journal_inum) { 1707 } else if (journal_inum) {
1708 if (ext3_create_journal(sb, es, journal_inum)) 1708 if (ext4_create_journal(sb, es, journal_inum))
1709 goto failed_mount3; 1709 goto failed_mount3;
1710 } else { 1710 } else {
1711 if (!silent) 1711 if (!silent)
1712 printk (KERN_ERR 1712 printk (KERN_ERR
1713 "ext3: No journal on filesystem on %s\n", 1713 "ext4: No journal on filesystem on %s\n",
1714 sb->s_id); 1714 sb->s_id);
1715 goto failed_mount3; 1715 goto failed_mount3;
1716 } 1716 }
@@ -1729,11 +1729,11 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1729 set_opt(sbi->s_mount_opt, JOURNAL_DATA); 1729 set_opt(sbi->s_mount_opt, JOURNAL_DATA);
1730 break; 1730 break;
1731 1731
1732 case EXT3_MOUNT_ORDERED_DATA: 1732 case EXT4_MOUNT_ORDERED_DATA:
1733 case EXT3_MOUNT_WRITEBACK_DATA: 1733 case EXT4_MOUNT_WRITEBACK_DATA:
1734 if (!journal_check_available_features 1734 if (!journal_check_available_features
1735 (sbi->s_journal, 0, 0, JFS_FEATURE_INCOMPAT_REVOKE)) { 1735 (sbi->s_journal, 0, 0, JFS_FEATURE_INCOMPAT_REVOKE)) {
1736 printk(KERN_ERR "EXT3-fs: Journal does not support " 1736 printk(KERN_ERR "EXT4-fs: Journal does not support "
1737 "requested data journaling mode\n"); 1737 "requested data journaling mode\n");
1738 goto failed_mount4; 1738 goto failed_mount4;
1739 } 1739 }
@@ -1742,8 +1742,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1742 } 1742 }
1743 1743
1744 if (test_opt(sb, NOBH)) { 1744 if (test_opt(sb, NOBH)) {
1745 if (!(test_opt(sb, DATA_FLAGS) == EXT3_MOUNT_WRITEBACK_DATA)) { 1745 if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) {
1746 printk(KERN_WARNING "EXT3-fs: Ignoring nobh option - " 1746 printk(KERN_WARNING "EXT4-fs: Ignoring nobh option - "
1747 "its supported only with writeback mode\n"); 1747 "its supported only with writeback mode\n");
1748 clear_opt(sbi->s_mount_opt, NOBH); 1748 clear_opt(sbi->s_mount_opt, NOBH);
1749 } 1749 }
@@ -1753,21 +1753,21 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1753 * so we can safely mount the rest of the filesystem now. 1753 * so we can safely mount the rest of the filesystem now.
1754 */ 1754 */
1755 1755
1756 root = iget(sb, EXT3_ROOT_INO); 1756 root = iget(sb, EXT4_ROOT_INO);
1757 sb->s_root = d_alloc_root(root); 1757 sb->s_root = d_alloc_root(root);
1758 if (!sb->s_root) { 1758 if (!sb->s_root) {
1759 printk(KERN_ERR "EXT3-fs: get root inode failed\n"); 1759 printk(KERN_ERR "EXT4-fs: get root inode failed\n");
1760 iput(root); 1760 iput(root);
1761 goto failed_mount4; 1761 goto failed_mount4;
1762 } 1762 }
1763 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { 1763 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
1764 dput(sb->s_root); 1764 dput(sb->s_root);
1765 sb->s_root = NULL; 1765 sb->s_root = NULL;
1766 printk(KERN_ERR "EXT3-fs: corrupt root inode, run e2fsck\n"); 1766 printk(KERN_ERR "EXT4-fs: corrupt root inode, run e2fsck\n");
1767 goto failed_mount4; 1767 goto failed_mount4;
1768 } 1768 }
1769 1769
1770 ext3_setup_super (sb, es, sb->s_flags & MS_RDONLY); 1770 ext4_setup_super (sb, es, sb->s_flags & MS_RDONLY);
1771 /* 1771 /*
1772 * akpm: core read_super() calls in here with the superblock locked. 1772 * akpm: core read_super() calls in here with the superblock locked.
1773 * That deadlocks, because orphan cleanup needs to lock the superblock 1773 * That deadlocks, because orphan cleanup needs to lock the superblock
@@ -1776,23 +1776,23 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1776 * and aviro says that's the only reason for hanging onto the 1776 * and aviro says that's the only reason for hanging onto the
1777 * superblock lock. 1777 * superblock lock.
1778 */ 1778 */
1779 EXT3_SB(sb)->s_mount_state |= EXT3_ORPHAN_FS; 1779 EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
1780 ext3_orphan_cleanup(sb, es); 1780 ext4_orphan_cleanup(sb, es);
1781 EXT3_SB(sb)->s_mount_state &= ~EXT3_ORPHAN_FS; 1781 EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
1782 if (needs_recovery) 1782 if (needs_recovery)
1783 printk (KERN_INFO "EXT3-fs: recovery complete.\n"); 1783 printk (KERN_INFO "EXT4-fs: recovery complete.\n");
1784 ext3_mark_recovery_complete(sb, es); 1784 ext4_mark_recovery_complete(sb, es);
1785 printk (KERN_INFO "EXT3-fs: mounted filesystem with %s data mode.\n", 1785 printk (KERN_INFO "EXT4-fs: mounted filesystem with %s data mode.\n",
1786 test_opt(sb,DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA ? "journal": 1786 test_opt(sb,DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA ? "journal":
1787 test_opt(sb,DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA ? "ordered": 1787 test_opt(sb,DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA ? "ordered":
1788 "writeback"); 1788 "writeback");
1789 1789
1790 lock_kernel(); 1790 lock_kernel();
1791 return 0; 1791 return 0;
1792 1792
1793cantfind_ext3: 1793cantfind_ext4:
1794 if (!silent) 1794 if (!silent)
1795 printk(KERN_ERR "VFS: Can't find ext3 filesystem on dev %s.\n", 1795 printk(KERN_ERR "VFS: Can't find ext4 filesystem on dev %s.\n",
1796 sb->s_id); 1796 sb->s_id);
1797 goto failed_mount; 1797 goto failed_mount;
1798 1798
@@ -1811,7 +1811,7 @@ failed_mount:
1811 for (i = 0; i < MAXQUOTAS; i++) 1811 for (i = 0; i < MAXQUOTAS; i++)
1812 kfree(sbi->s_qf_names[i]); 1812 kfree(sbi->s_qf_names[i]);
1813#endif 1813#endif
1814 ext3_blkdev_remove(sbi); 1814 ext4_blkdev_remove(sbi);
1815 brelse(bh); 1815 brelse(bh);
1816out_fail: 1816out_fail:
1817 sb->s_fs_info = NULL; 1817 sb->s_fs_info = NULL;
@@ -1825,13 +1825,13 @@ out_fail:
1825 * initial mount, once the journal has been initialised but before we've 1825 * initial mount, once the journal has been initialised but before we've
1826 * done any recovery; and again on any subsequent remount. 1826 * done any recovery; and again on any subsequent remount.
1827 */ 1827 */
1828static void ext3_init_journal_params(struct super_block *sb, journal_t *journal) 1828static void ext4_init_journal_params(struct super_block *sb, journal_t *journal)
1829{ 1829{
1830 struct ext3_sb_info *sbi = EXT3_SB(sb); 1830 struct ext4_sb_info *sbi = EXT4_SB(sb);
1831 1831
1832 if (sbi->s_commit_interval) 1832 if (sbi->s_commit_interval)
1833 journal->j_commit_interval = sbi->s_commit_interval; 1833 journal->j_commit_interval = sbi->s_commit_interval;
1834 /* We could also set up an ext3-specific default for the commit 1834 /* We could also set up an ext4-specific default for the commit
1835 * interval here, but for now we'll just fall back to the jbd 1835 * interval here, but for now we'll just fall back to the jbd
1836 * default. */ 1836 * default. */
1837 1837
@@ -1843,7 +1843,7 @@ static void ext3_init_journal_params(struct super_block *sb, journal_t *journal)
1843 spin_unlock(&journal->j_state_lock); 1843 spin_unlock(&journal->j_state_lock);
1844} 1844}
1845 1845
1846static journal_t *ext3_get_journal(struct super_block *sb, 1846static journal_t *ext4_get_journal(struct super_block *sb,
1847 unsigned int journal_inum) 1847 unsigned int journal_inum)
1848{ 1848{
1849 struct inode *journal_inode; 1849 struct inode *journal_inode;
@@ -1855,55 +1855,55 @@ static journal_t *ext3_get_journal(struct super_block *sb,
1855 1855
1856 journal_inode = iget(sb, journal_inum); 1856 journal_inode = iget(sb, journal_inum);
1857 if (!journal_inode) { 1857 if (!journal_inode) {
1858 printk(KERN_ERR "EXT3-fs: no journal found.\n"); 1858 printk(KERN_ERR "EXT4-fs: no journal found.\n");
1859 return NULL; 1859 return NULL;
1860 } 1860 }
1861 if (!journal_inode->i_nlink) { 1861 if (!journal_inode->i_nlink) {
1862 make_bad_inode(journal_inode); 1862 make_bad_inode(journal_inode);
1863 iput(journal_inode); 1863 iput(journal_inode);
1864 printk(KERN_ERR "EXT3-fs: journal inode is deleted.\n"); 1864 printk(KERN_ERR "EXT4-fs: journal inode is deleted.\n");
1865 return NULL; 1865 return NULL;
1866 } 1866 }
1867 1867
1868 jbd_debug(2, "Journal inode found at %p: %Ld bytes\n", 1868 jbd_debug(2, "Journal inode found at %p: %Ld bytes\n",
1869 journal_inode, journal_inode->i_size); 1869 journal_inode, journal_inode->i_size);
1870 if (is_bad_inode(journal_inode) || !S_ISREG(journal_inode->i_mode)) { 1870 if (is_bad_inode(journal_inode) || !S_ISREG(journal_inode->i_mode)) {
1871 printk(KERN_ERR "EXT3-fs: invalid journal inode.\n"); 1871 printk(KERN_ERR "EXT4-fs: invalid journal inode.\n");
1872 iput(journal_inode); 1872 iput(journal_inode);
1873 return NULL; 1873 return NULL;
1874 } 1874 }
1875 1875
1876 journal = journal_init_inode(journal_inode); 1876 journal = journal_init_inode(journal_inode);
1877 if (!journal) { 1877 if (!journal) {
1878 printk(KERN_ERR "EXT3-fs: Could not load journal inode\n"); 1878 printk(KERN_ERR "EXT4-fs: Could not load journal inode\n");
1879 iput(journal_inode); 1879 iput(journal_inode);
1880 return NULL; 1880 return NULL;
1881 } 1881 }
1882 journal->j_private = sb; 1882 journal->j_private = sb;
1883 ext3_init_journal_params(sb, journal); 1883 ext4_init_journal_params(sb, journal);
1884 return journal; 1884 return journal;
1885} 1885}
1886 1886
1887static journal_t *ext3_get_dev_journal(struct super_block *sb, 1887static journal_t *ext4_get_dev_journal(struct super_block *sb,
1888 dev_t j_dev) 1888 dev_t j_dev)
1889{ 1889{
1890 struct buffer_head * bh; 1890 struct buffer_head * bh;
1891 journal_t *journal; 1891 journal_t *journal;
1892 ext3_fsblk_t start; 1892 ext4_fsblk_t start;
1893 ext3_fsblk_t len; 1893 ext4_fsblk_t len;
1894 int hblock, blocksize; 1894 int hblock, blocksize;
1895 ext3_fsblk_t sb_block; 1895 ext4_fsblk_t sb_block;
1896 unsigned long offset; 1896 unsigned long offset;
1897 struct ext3_super_block * es; 1897 struct ext4_super_block * es;
1898 struct block_device *bdev; 1898 struct block_device *bdev;
1899 1899
1900 bdev = ext3_blkdev_get(j_dev); 1900 bdev = ext4_blkdev_get(j_dev);
1901 if (bdev == NULL) 1901 if (bdev == NULL)
1902 return NULL; 1902 return NULL;
1903 1903
1904 if (bd_claim(bdev, sb)) { 1904 if (bd_claim(bdev, sb)) {
1905 printk(KERN_ERR 1905 printk(KERN_ERR
1906 "EXT3: failed to claim external journal device.\n"); 1906 "EXT4: failed to claim external journal device.\n");
1907 blkdev_put(bdev); 1907 blkdev_put(bdev);
1908 return NULL; 1908 return NULL;
1909 } 1909 }
@@ -1912,31 +1912,31 @@ static journal_t *ext3_get_dev_journal(struct super_block *sb,
1912 hblock = bdev_hardsect_size(bdev); 1912 hblock = bdev_hardsect_size(bdev);
1913 if (blocksize < hblock) { 1913 if (blocksize < hblock) {
1914 printk(KERN_ERR 1914 printk(KERN_ERR
1915 "EXT3-fs: blocksize too small for journal device.\n"); 1915 "EXT4-fs: blocksize too small for journal device.\n");
1916 goto out_bdev; 1916 goto out_bdev;
1917 } 1917 }
1918 1918
1919 sb_block = EXT3_MIN_BLOCK_SIZE / blocksize; 1919 sb_block = EXT4_MIN_BLOCK_SIZE / blocksize;
1920 offset = EXT3_MIN_BLOCK_SIZE % blocksize; 1920 offset = EXT4_MIN_BLOCK_SIZE % blocksize;
1921 set_blocksize(bdev, blocksize); 1921 set_blocksize(bdev, blocksize);
1922 if (!(bh = __bread(bdev, sb_block, blocksize))) { 1922 if (!(bh = __bread(bdev, sb_block, blocksize))) {
1923 printk(KERN_ERR "EXT3-fs: couldn't read superblock of " 1923 printk(KERN_ERR "EXT4-fs: couldn't read superblock of "
1924 "external journal\n"); 1924 "external journal\n");
1925 goto out_bdev; 1925 goto out_bdev;
1926 } 1926 }
1927 1927
1928 es = (struct ext3_super_block *) (((char *)bh->b_data) + offset); 1928 es = (struct ext4_super_block *) (((char *)bh->b_data) + offset);
1929 if ((le16_to_cpu(es->s_magic) != EXT3_SUPER_MAGIC) || 1929 if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) ||
1930 !(le32_to_cpu(es->s_feature_incompat) & 1930 !(le32_to_cpu(es->s_feature_incompat) &
1931 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) { 1931 EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) {
1932 printk(KERN_ERR "EXT3-fs: external journal has " 1932 printk(KERN_ERR "EXT4-fs: external journal has "
1933 "bad superblock\n"); 1933 "bad superblock\n");
1934 brelse(bh); 1934 brelse(bh);
1935 goto out_bdev; 1935 goto out_bdev;
1936 } 1936 }
1937 1937
1938 if (memcmp(EXT3_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) { 1938 if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) {
1939 printk(KERN_ERR "EXT3-fs: journal UUID does not match\n"); 1939 printk(KERN_ERR "EXT4-fs: journal UUID does not match\n");
1940 brelse(bh); 1940 brelse(bh);
1941 goto out_bdev; 1941 goto out_bdev;
1942 } 1942 }
@@ -1948,34 +1948,34 @@ static journal_t *ext3_get_dev_journal(struct super_block *sb,
1948 journal = journal_init_dev(bdev, sb->s_bdev, 1948 journal = journal_init_dev(bdev, sb->s_bdev,
1949 start, len, blocksize); 1949 start, len, blocksize);
1950 if (!journal) { 1950 if (!journal) {
1951 printk(KERN_ERR "EXT3-fs: failed to create device journal\n"); 1951 printk(KERN_ERR "EXT4-fs: failed to create device journal\n");
1952 goto out_bdev; 1952 goto out_bdev;
1953 } 1953 }
1954 journal->j_private = sb; 1954 journal->j_private = sb;
1955 ll_rw_block(READ, 1, &journal->j_sb_buffer); 1955 ll_rw_block(READ, 1, &journal->j_sb_buffer);
1956 wait_on_buffer(journal->j_sb_buffer); 1956 wait_on_buffer(journal->j_sb_buffer);
1957 if (!buffer_uptodate(journal->j_sb_buffer)) { 1957 if (!buffer_uptodate(journal->j_sb_buffer)) {
1958 printk(KERN_ERR "EXT3-fs: I/O error on journal device\n"); 1958 printk(KERN_ERR "EXT4-fs: I/O error on journal device\n");
1959 goto out_journal; 1959 goto out_journal;
1960 } 1960 }
1961 if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) { 1961 if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) {
1962 printk(KERN_ERR "EXT3-fs: External journal has more than one " 1962 printk(KERN_ERR "EXT4-fs: External journal has more than one "
1963 "user (unsupported) - %d\n", 1963 "user (unsupported) - %d\n",
1964 be32_to_cpu(journal->j_superblock->s_nr_users)); 1964 be32_to_cpu(journal->j_superblock->s_nr_users));
1965 goto out_journal; 1965 goto out_journal;
1966 } 1966 }
1967 EXT3_SB(sb)->journal_bdev = bdev; 1967 EXT4_SB(sb)->journal_bdev = bdev;
1968 ext3_init_journal_params(sb, journal); 1968 ext4_init_journal_params(sb, journal);
1969 return journal; 1969 return journal;
1970out_journal: 1970out_journal:
1971 journal_destroy(journal); 1971 journal_destroy(journal);
1972out_bdev: 1972out_bdev:
1973 ext3_blkdev_put(bdev); 1973 ext4_blkdev_put(bdev);
1974 return NULL; 1974 return NULL;
1975} 1975}
1976 1976
1977static int ext3_load_journal(struct super_block *sb, 1977static int ext4_load_journal(struct super_block *sb,
1978 struct ext3_super_block *es, 1978 struct ext4_super_block *es,
1979 unsigned long journal_devnum) 1979 unsigned long journal_devnum)
1980{ 1980{
1981 journal_t *journal; 1981 journal_t *journal;
@@ -1986,7 +1986,7 @@ static int ext3_load_journal(struct super_block *sb,
1986 1986
1987 if (journal_devnum && 1987 if (journal_devnum &&
1988 journal_devnum != le32_to_cpu(es->s_journal_dev)) { 1988 journal_devnum != le32_to_cpu(es->s_journal_dev)) {
1989 printk(KERN_INFO "EXT3-fs: external journal device major/minor " 1989 printk(KERN_INFO "EXT4-fs: external journal device major/minor "
1990 "numbers have changed\n"); 1990 "numbers have changed\n");
1991 journal_dev = new_decode_dev(journal_devnum); 1991 journal_dev = new_decode_dev(journal_devnum);
1992 } else 1992 } else
@@ -2000,56 +2000,56 @@ static int ext3_load_journal(struct super_block *sb,
2000 * can get read-write access to the device. 2000 * can get read-write access to the device.
2001 */ 2001 */
2002 2002
2003 if (EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER)) { 2003 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
2004 if (sb->s_flags & MS_RDONLY) { 2004 if (sb->s_flags & MS_RDONLY) {
2005 printk(KERN_INFO "EXT3-fs: INFO: recovery " 2005 printk(KERN_INFO "EXT4-fs: INFO: recovery "
2006 "required on readonly filesystem.\n"); 2006 "required on readonly filesystem.\n");
2007 if (really_read_only) { 2007 if (really_read_only) {
2008 printk(KERN_ERR "EXT3-fs: write access " 2008 printk(KERN_ERR "EXT4-fs: write access "
2009 "unavailable, cannot proceed.\n"); 2009 "unavailable, cannot proceed.\n");
2010 return -EROFS; 2010 return -EROFS;
2011 } 2011 }
2012 printk (KERN_INFO "EXT3-fs: write access will " 2012 printk (KERN_INFO "EXT4-fs: write access will "
2013 "be enabled during recovery.\n"); 2013 "be enabled during recovery.\n");
2014 } 2014 }
2015 } 2015 }
2016 2016
2017 if (journal_inum && journal_dev) { 2017 if (journal_inum && journal_dev) {
2018 printk(KERN_ERR "EXT3-fs: filesystem has both journal " 2018 printk(KERN_ERR "EXT4-fs: filesystem has both journal "
2019 "and inode journals!\n"); 2019 "and inode journals!\n");
2020 return -EINVAL; 2020 return -EINVAL;
2021 } 2021 }
2022 2022
2023 if (journal_inum) { 2023 if (journal_inum) {
2024 if (!(journal = ext3_get_journal(sb, journal_inum))) 2024 if (!(journal = ext4_get_journal(sb, journal_inum)))
2025 return -EINVAL; 2025 return -EINVAL;
2026 } else { 2026 } else {
2027 if (!(journal = ext3_get_dev_journal(sb, journal_dev))) 2027 if (!(journal = ext4_get_dev_journal(sb, journal_dev)))
2028 return -EINVAL; 2028 return -EINVAL;
2029 } 2029 }
2030 2030
2031 if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) { 2031 if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) {
2032 err = journal_update_format(journal); 2032 err = journal_update_format(journal);
2033 if (err) { 2033 if (err) {
2034 printk(KERN_ERR "EXT3-fs: error updating journal.\n"); 2034 printk(KERN_ERR "EXT4-fs: error updating journal.\n");
2035 journal_destroy(journal); 2035 journal_destroy(journal);
2036 return err; 2036 return err;
2037 } 2037 }
2038 } 2038 }
2039 2039
2040 if (!EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER)) 2040 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER))
2041 err = journal_wipe(journal, !really_read_only); 2041 err = journal_wipe(journal, !really_read_only);
2042 if (!err) 2042 if (!err)
2043 err = journal_load(journal); 2043 err = journal_load(journal);
2044 2044
2045 if (err) { 2045 if (err) {
2046 printk(KERN_ERR "EXT3-fs: error loading journal.\n"); 2046 printk(KERN_ERR "EXT4-fs: error loading journal.\n");
2047 journal_destroy(journal); 2047 journal_destroy(journal);
2048 return err; 2048 return err;
2049 } 2049 }
2050 2050
2051 EXT3_SB(sb)->s_journal = journal; 2051 EXT4_SB(sb)->s_journal = journal;
2052 ext3_clear_journal_err(sb, es); 2052 ext4_clear_journal_err(sb, es);
2053 2053
2054 if (journal_devnum && 2054 if (journal_devnum &&
2055 journal_devnum != le32_to_cpu(es->s_journal_dev)) { 2055 journal_devnum != le32_to_cpu(es->s_journal_dev)) {
@@ -2057,62 +2057,62 @@ static int ext3_load_journal(struct super_block *sb,
2057 sb->s_dirt = 1; 2057 sb->s_dirt = 1;
2058 2058
2059 /* Make sure we flush the recovery flag to disk. */ 2059 /* Make sure we flush the recovery flag to disk. */
2060 ext3_commit_super(sb, es, 1); 2060 ext4_commit_super(sb, es, 1);
2061 } 2061 }
2062 2062
2063 return 0; 2063 return 0;
2064} 2064}
2065 2065
2066static int ext3_create_journal(struct super_block * sb, 2066static int ext4_create_journal(struct super_block * sb,
2067 struct ext3_super_block * es, 2067 struct ext4_super_block * es,
2068 unsigned int journal_inum) 2068 unsigned int journal_inum)
2069{ 2069{
2070 journal_t *journal; 2070 journal_t *journal;
2071 2071
2072 if (sb->s_flags & MS_RDONLY) { 2072 if (sb->s_flags & MS_RDONLY) {
2073 printk(KERN_ERR "EXT3-fs: readonly filesystem when trying to " 2073 printk(KERN_ERR "EXT4-fs: readonly filesystem when trying to "
2074 "create journal.\n"); 2074 "create journal.\n");
2075 return -EROFS; 2075 return -EROFS;
2076 } 2076 }
2077 2077
2078 if (!(journal = ext3_get_journal(sb, journal_inum))) 2078 if (!(journal = ext4_get_journal(sb, journal_inum)))
2079 return -EINVAL; 2079 return -EINVAL;
2080 2080
2081 printk(KERN_INFO "EXT3-fs: creating new journal on inode %u\n", 2081 printk(KERN_INFO "EXT4-fs: creating new journal on inode %u\n",
2082 journal_inum); 2082 journal_inum);
2083 2083
2084 if (journal_create(journal)) { 2084 if (journal_create(journal)) {
2085 printk(KERN_ERR "EXT3-fs: error creating journal.\n"); 2085 printk(KERN_ERR "EXT4-fs: error creating journal.\n");
2086 journal_destroy(journal); 2086 journal_destroy(journal);
2087 return -EIO; 2087 return -EIO;
2088 } 2088 }
2089 2089
2090 EXT3_SB(sb)->s_journal = journal; 2090 EXT4_SB(sb)->s_journal = journal;
2091 2091
2092 ext3_update_dynamic_rev(sb); 2092 ext4_update_dynamic_rev(sb);
2093 EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); 2093 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
2094 EXT3_SET_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL); 2094 EXT4_SET_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL);
2095 2095
2096 es->s_journal_inum = cpu_to_le32(journal_inum); 2096 es->s_journal_inum = cpu_to_le32(journal_inum);
2097 sb->s_dirt = 1; 2097 sb->s_dirt = 1;
2098 2098
2099 /* Make sure we flush the recovery flag to disk. */ 2099 /* Make sure we flush the recovery flag to disk. */
2100 ext3_commit_super(sb, es, 1); 2100 ext4_commit_super(sb, es, 1);
2101 2101
2102 return 0; 2102 return 0;
2103} 2103}
2104 2104
2105static void ext3_commit_super (struct super_block * sb, 2105static void ext4_commit_super (struct super_block * sb,
2106 struct ext3_super_block * es, 2106 struct ext4_super_block * es,
2107 int sync) 2107 int sync)
2108{ 2108{
2109 struct buffer_head *sbh = EXT3_SB(sb)->s_sbh; 2109 struct buffer_head *sbh = EXT4_SB(sb)->s_sbh;
2110 2110
2111 if (!sbh) 2111 if (!sbh)
2112 return; 2112 return;
2113 es->s_wtime = cpu_to_le32(get_seconds()); 2113 es->s_wtime = cpu_to_le32(get_seconds());
2114 es->s_free_blocks_count = cpu_to_le32(ext3_count_free_blocks(sb)); 2114 es->s_free_blocks_count = cpu_to_le32(ext4_count_free_blocks(sb));
2115 es->s_free_inodes_count = cpu_to_le32(ext3_count_free_inodes(sb)); 2115 es->s_free_inodes_count = cpu_to_le32(ext4_count_free_inodes(sb));
2116 BUFFER_TRACE(sbh, "marking dirty"); 2116 BUFFER_TRACE(sbh, "marking dirty");
2117 mark_buffer_dirty(sbh); 2117 mark_buffer_dirty(sbh);
2118 if (sync) 2118 if (sync)
@@ -2125,18 +2125,18 @@ static void ext3_commit_super (struct super_block * sb,
2125 * remounting) the filesystem readonly, then we will end up with a 2125 * remounting) the filesystem readonly, then we will end up with a
2126 * consistent fs on disk. Record that fact. 2126 * consistent fs on disk. Record that fact.
2127 */ 2127 */
2128static void ext3_mark_recovery_complete(struct super_block * sb, 2128static void ext4_mark_recovery_complete(struct super_block * sb,
2129 struct ext3_super_block * es) 2129 struct ext4_super_block * es)
2130{ 2130{
2131 journal_t *journal = EXT3_SB(sb)->s_journal; 2131 journal_t *journal = EXT4_SB(sb)->s_journal;
2132 2132
2133 journal_lock_updates(journal); 2133 journal_lock_updates(journal);
2134 journal_flush(journal); 2134 journal_flush(journal);
2135 if (EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER) && 2135 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) &&
2136 sb->s_flags & MS_RDONLY) { 2136 sb->s_flags & MS_RDONLY) {
2137 EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); 2137 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
2138 sb->s_dirt = 0; 2138 sb->s_dirt = 0;
2139 ext3_commit_super(sb, es, 1); 2139 ext4_commit_super(sb, es, 1);
2140 } 2140 }
2141 journal_unlock_updates(journal); 2141 journal_unlock_updates(journal);
2142} 2142}
@@ -2146,33 +2146,33 @@ static void ext3_mark_recovery_complete(struct super_block * sb,
2146 * has recorded an error from a previous lifetime, move that error to the 2146 * has recorded an error from a previous lifetime, move that error to the
2147 * main filesystem now. 2147 * main filesystem now.
2148 */ 2148 */
2149static void ext3_clear_journal_err(struct super_block * sb, 2149static void ext4_clear_journal_err(struct super_block * sb,
2150 struct ext3_super_block * es) 2150 struct ext4_super_block * es)
2151{ 2151{
2152 journal_t *journal; 2152 journal_t *journal;
2153 int j_errno; 2153 int j_errno;
2154 const char *errstr; 2154 const char *errstr;
2155 2155
2156 journal = EXT3_SB(sb)->s_journal; 2156 journal = EXT4_SB(sb)->s_journal;
2157 2157
2158 /* 2158 /*
2159 * Now check for any error status which may have been recorded in the 2159 * Now check for any error status which may have been recorded in the
2160 * journal by a prior ext3_error() or ext3_abort() 2160 * journal by a prior ext4_error() or ext4_abort()
2161 */ 2161 */
2162 2162
2163 j_errno = journal_errno(journal); 2163 j_errno = journal_errno(journal);
2164 if (j_errno) { 2164 if (j_errno) {
2165 char nbuf[16]; 2165 char nbuf[16];
2166 2166
2167 errstr = ext3_decode_error(sb, j_errno, nbuf); 2167 errstr = ext4_decode_error(sb, j_errno, nbuf);
2168 ext3_warning(sb, __FUNCTION__, "Filesystem error recorded " 2168 ext4_warning(sb, __FUNCTION__, "Filesystem error recorded "
2169 "from previous mount: %s", errstr); 2169 "from previous mount: %s", errstr);
2170 ext3_warning(sb, __FUNCTION__, "Marking fs in need of " 2170 ext4_warning(sb, __FUNCTION__, "Marking fs in need of "
2171 "filesystem check."); 2171 "filesystem check.");
2172 2172
2173 EXT3_SB(sb)->s_mount_state |= EXT3_ERROR_FS; 2173 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
2174 es->s_state |= cpu_to_le16(EXT3_ERROR_FS); 2174 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
2175 ext3_commit_super (sb, es, 1); 2175 ext4_commit_super (sb, es, 1);
2176 2176
2177 journal_clear_err(journal); 2177 journal_clear_err(journal);
2178 } 2178 }
@@ -2182,7 +2182,7 @@ static void ext3_clear_journal_err(struct super_block * sb,
2182 * Force the running and committing transactions to commit, 2182 * Force the running and committing transactions to commit,
2183 * and wait on the commit. 2183 * and wait on the commit.
2184 */ 2184 */
2185int ext3_force_commit(struct super_block *sb) 2185int ext4_force_commit(struct super_block *sb)
2186{ 2186{
2187 journal_t *journal; 2187 journal_t *journal;
2188 int ret; 2188 int ret;
@@ -2190,14 +2190,14 @@ int ext3_force_commit(struct super_block *sb)
2190 if (sb->s_flags & MS_RDONLY) 2190 if (sb->s_flags & MS_RDONLY)
2191 return 0; 2191 return 0;
2192 2192
2193 journal = EXT3_SB(sb)->s_journal; 2193 journal = EXT4_SB(sb)->s_journal;
2194 sb->s_dirt = 0; 2194 sb->s_dirt = 0;
2195 ret = ext3_journal_force_commit(journal); 2195 ret = ext4_journal_force_commit(journal);
2196 return ret; 2196 return ret;
2197} 2197}
2198 2198
2199/* 2199/*
2200 * Ext3 always journals updates to the superblock itself, so we don't 2200 * Ext4 always journals updates to the superblock itself, so we don't
2201 * have to propagate any other updates to the superblock on disk at this 2201 * have to propagate any other updates to the superblock on disk at this
2202 * point. Just start an async writeback to get the buffers on their way 2202 * point. Just start an async writeback to get the buffers on their way
2203 * to the disk. 2203 * to the disk.
@@ -2205,21 +2205,21 @@ int ext3_force_commit(struct super_block *sb)
2205 * This implicitly triggers the writebehind on sync(). 2205 * This implicitly triggers the writebehind on sync().
2206 */ 2206 */
2207 2207
2208static void ext3_write_super (struct super_block * sb) 2208static void ext4_write_super (struct super_block * sb)
2209{ 2209{
2210 if (mutex_trylock(&sb->s_lock) != 0) 2210 if (mutex_trylock(&sb->s_lock) != 0)
2211 BUG(); 2211 BUG();
2212 sb->s_dirt = 0; 2212 sb->s_dirt = 0;
2213} 2213}
2214 2214
2215static int ext3_sync_fs(struct super_block *sb, int wait) 2215static int ext4_sync_fs(struct super_block *sb, int wait)
2216{ 2216{
2217 tid_t target; 2217 tid_t target;
2218 2218
2219 sb->s_dirt = 0; 2219 sb->s_dirt = 0;
2220 if (journal_start_commit(EXT3_SB(sb)->s_journal, &target)) { 2220 if (journal_start_commit(EXT4_SB(sb)->s_journal, &target)) {
2221 if (wait) 2221 if (wait)
2222 log_wait_commit(EXT3_SB(sb)->s_journal, target); 2222 log_wait_commit(EXT4_SB(sb)->s_journal, target);
2223 } 2223 }
2224 return 0; 2224 return 0;
2225} 2225}
@@ -2228,20 +2228,20 @@ static int ext3_sync_fs(struct super_block *sb, int wait)
2228 * LVM calls this function before a (read-only) snapshot is created. This 2228 * LVM calls this function before a (read-only) snapshot is created. This
2229 * gives us a chance to flush the journal completely and mark the fs clean. 2229 * gives us a chance to flush the journal completely and mark the fs clean.
2230 */ 2230 */
2231static void ext3_write_super_lockfs(struct super_block *sb) 2231static void ext4_write_super_lockfs(struct super_block *sb)
2232{ 2232{
2233 sb->s_dirt = 0; 2233 sb->s_dirt = 0;
2234 2234
2235 if (!(sb->s_flags & MS_RDONLY)) { 2235 if (!(sb->s_flags & MS_RDONLY)) {
2236 journal_t *journal = EXT3_SB(sb)->s_journal; 2236 journal_t *journal = EXT4_SB(sb)->s_journal;
2237 2237
2238 /* Now we set up the journal barrier. */ 2238 /* Now we set up the journal barrier. */
2239 journal_lock_updates(journal); 2239 journal_lock_updates(journal);
2240 journal_flush(journal); 2240 journal_flush(journal);
2241 2241
2242 /* Journal blocked and flushed, clear needs_recovery flag. */ 2242 /* Journal blocked and flushed, clear needs_recovery flag. */
2243 EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); 2243 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
2244 ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1); 2244 ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1);
2245 } 2245 }
2246} 2246}
2247 2247
@@ -2249,25 +2249,25 @@ static void ext3_write_super_lockfs(struct super_block *sb)
2249 * Called by LVM after the snapshot is done. We need to reset the RECOVER 2249 * Called by LVM after the snapshot is done. We need to reset the RECOVER
2250 * flag here, even though the filesystem is not technically dirty yet. 2250 * flag here, even though the filesystem is not technically dirty yet.
2251 */ 2251 */
2252static void ext3_unlockfs(struct super_block *sb) 2252static void ext4_unlockfs(struct super_block *sb)
2253{ 2253{
2254 if (!(sb->s_flags & MS_RDONLY)) { 2254 if (!(sb->s_flags & MS_RDONLY)) {
2255 lock_super(sb); 2255 lock_super(sb);
2256 /* Reser the needs_recovery flag before the fs is unlocked. */ 2256 /* Reser the needs_recovery flag before the fs is unlocked. */
2257 EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); 2257 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
2258 ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1); 2258 ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1);
2259 unlock_super(sb); 2259 unlock_super(sb);
2260 journal_unlock_updates(EXT3_SB(sb)->s_journal); 2260 journal_unlock_updates(EXT4_SB(sb)->s_journal);
2261 } 2261 }
2262} 2262}
2263 2263
2264static int ext3_remount (struct super_block * sb, int * flags, char * data) 2264static int ext4_remount (struct super_block * sb, int * flags, char * data)
2265{ 2265{
2266 struct ext3_super_block * es; 2266 struct ext4_super_block * es;
2267 struct ext3_sb_info *sbi = EXT3_SB(sb); 2267 struct ext4_sb_info *sbi = EXT4_SB(sb);
2268 ext3_fsblk_t n_blocks_count = 0; 2268 ext4_fsblk_t n_blocks_count = 0;
2269 unsigned long old_sb_flags; 2269 unsigned long old_sb_flags;
2270 struct ext3_mount_options old_opts; 2270 struct ext4_mount_options old_opts;
2271 int err; 2271 int err;
2272#ifdef CONFIG_QUOTA 2272#ifdef CONFIG_QUOTA
2273 int i; 2273 int i;
@@ -2293,19 +2293,19 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
2293 goto restore_opts; 2293 goto restore_opts;
2294 } 2294 }
2295 2295
2296 if (sbi->s_mount_opt & EXT3_MOUNT_ABORT) 2296 if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
2297 ext3_abort(sb, __FUNCTION__, "Abort forced by user"); 2297 ext4_abort(sb, __FUNCTION__, "Abort forced by user");
2298 2298
2299 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 2299 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2300 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); 2300 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2301 2301
2302 es = sbi->s_es; 2302 es = sbi->s_es;
2303 2303
2304 ext3_init_journal_params(sb, sbi->s_journal); 2304 ext4_init_journal_params(sb, sbi->s_journal);
2305 2305
2306 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) || 2306 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) ||
2307 n_blocks_count > le32_to_cpu(es->s_blocks_count)) { 2307 n_blocks_count > le32_to_cpu(es->s_blocks_count)) {
2308 if (sbi->s_mount_opt & EXT3_MOUNT_ABORT) { 2308 if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) {
2309 err = -EROFS; 2309 err = -EROFS;
2310 goto restore_opts; 2310 goto restore_opts;
2311 } 2311 }
@@ -2322,16 +2322,16 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
2322 * readonly, and if so set the rdonly flag and then 2322 * readonly, and if so set the rdonly flag and then
2323 * mark the partition as valid again. 2323 * mark the partition as valid again.
2324 */ 2324 */
2325 if (!(es->s_state & cpu_to_le16(EXT3_VALID_FS)) && 2325 if (!(es->s_state & cpu_to_le16(EXT4_VALID_FS)) &&
2326 (sbi->s_mount_state & EXT3_VALID_FS)) 2326 (sbi->s_mount_state & EXT4_VALID_FS))
2327 es->s_state = cpu_to_le16(sbi->s_mount_state); 2327 es->s_state = cpu_to_le16(sbi->s_mount_state);
2328 2328
2329 ext3_mark_recovery_complete(sb, es); 2329 ext4_mark_recovery_complete(sb, es);
2330 } else { 2330 } else {
2331 __le32 ret; 2331 __le32 ret;
2332 if ((ret = EXT3_HAS_RO_COMPAT_FEATURE(sb, 2332 if ((ret = EXT4_HAS_RO_COMPAT_FEATURE(sb,
2333 ~EXT3_FEATURE_RO_COMPAT_SUPP))) { 2333 ~EXT4_FEATURE_RO_COMPAT_SUPP))) {
2334 printk(KERN_WARNING "EXT3-fs: %s: couldn't " 2334 printk(KERN_WARNING "EXT4-fs: %s: couldn't "
2335 "remount RDWR because of unsupported " 2335 "remount RDWR because of unsupported "
2336 "optional features (%x).\n", 2336 "optional features (%x).\n",
2337 sb->s_id, le32_to_cpu(ret)); 2337 sb->s_id, le32_to_cpu(ret));
@@ -2344,11 +2344,11 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
2344 * been changed by e2fsck since we originally mounted 2344 * been changed by e2fsck since we originally mounted
2345 * the partition.) 2345 * the partition.)
2346 */ 2346 */
2347 ext3_clear_journal_err(sb, es); 2347 ext4_clear_journal_err(sb, es);
2348 sbi->s_mount_state = le16_to_cpu(es->s_state); 2348 sbi->s_mount_state = le16_to_cpu(es->s_state);
2349 if ((err = ext3_group_extend(sb, es, n_blocks_count))) 2349 if ((err = ext4_group_extend(sb, es, n_blocks_count)))
2350 goto restore_opts; 2350 goto restore_opts;
2351 if (!ext3_setup_super (sb, es, 0)) 2351 if (!ext4_setup_super (sb, es, 0))
2352 sb->s_flags &= ~MS_RDONLY; 2352 sb->s_flags &= ~MS_RDONLY;
2353 } 2353 }
2354 } 2354 }
@@ -2378,19 +2378,19 @@ restore_opts:
2378 return err; 2378 return err;
2379} 2379}
2380 2380
2381static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf) 2381static int ext4_statfs (struct dentry * dentry, struct kstatfs * buf)
2382{ 2382{
2383 struct super_block *sb = dentry->d_sb; 2383 struct super_block *sb = dentry->d_sb;
2384 struct ext3_sb_info *sbi = EXT3_SB(sb); 2384 struct ext4_sb_info *sbi = EXT4_SB(sb);
2385 struct ext3_super_block *es = sbi->s_es; 2385 struct ext4_super_block *es = sbi->s_es;
2386 ext3_fsblk_t overhead; 2386 ext4_fsblk_t overhead;
2387 int i; 2387 int i;
2388 2388
2389 if (test_opt (sb, MINIX_DF)) 2389 if (test_opt (sb, MINIX_DF))
2390 overhead = 0; 2390 overhead = 0;
2391 else { 2391 else {
2392 unsigned long ngroups; 2392 unsigned long ngroups;
2393 ngroups = EXT3_SB(sb)->s_groups_count; 2393 ngroups = EXT4_SB(sb)->s_groups_count;
2394 smp_rmb(); 2394 smp_rmb();
2395 2395
2396 /* 2396 /*
@@ -2409,8 +2409,8 @@ static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf)
2409 * feature is turned on, then not all groups have this. 2409 * feature is turned on, then not all groups have this.
2410 */ 2410 */
2411 for (i = 0; i < ngroups; i++) { 2411 for (i = 0; i < ngroups; i++) {
2412 overhead += ext3_bg_has_super(sb, i) + 2412 overhead += ext4_bg_has_super(sb, i) +
2413 ext3_bg_num_gdb(sb, i); 2413 ext4_bg_num_gdb(sb, i);
2414 cond_resched(); 2414 cond_resched();
2415 } 2415 }
2416 2416
@@ -2418,10 +2418,10 @@ static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf)
2418 * Every block group has an inode bitmap, a block 2418 * Every block group has an inode bitmap, a block
2419 * bitmap, and an inode table. 2419 * bitmap, and an inode table.
2420 */ 2420 */
2421 overhead += (ngroups * (2 + EXT3_SB(sb)->s_itb_per_group)); 2421 overhead += (ngroups * (2 + EXT4_SB(sb)->s_itb_per_group));
2422 } 2422 }
2423 2423
2424 buf->f_type = EXT3_SUPER_MAGIC; 2424 buf->f_type = EXT4_SUPER_MAGIC;
2425 buf->f_bsize = sb->s_blocksize; 2425 buf->f_bsize = sb->s_blocksize;
2426 buf->f_blocks = le32_to_cpu(es->s_blocks_count) - overhead; 2426 buf->f_blocks = le32_to_cpu(es->s_blocks_count) - overhead;
2427 buf->f_bfree = percpu_counter_sum(&sbi->s_freeblocks_counter); 2427 buf->f_bfree = percpu_counter_sum(&sbi->s_freeblocks_counter);
@@ -2430,14 +2430,14 @@ static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf)
2430 buf->f_bavail = 0; 2430 buf->f_bavail = 0;
2431 buf->f_files = le32_to_cpu(es->s_inodes_count); 2431 buf->f_files = le32_to_cpu(es->s_inodes_count);
2432 buf->f_ffree = percpu_counter_sum(&sbi->s_freeinodes_counter); 2432 buf->f_ffree = percpu_counter_sum(&sbi->s_freeinodes_counter);
2433 buf->f_namelen = EXT3_NAME_LEN; 2433 buf->f_namelen = EXT4_NAME_LEN;
2434 return 0; 2434 return 0;
2435} 2435}
2436 2436
2437/* Helper function for writing quotas on sync - we need to start transaction before quota file 2437/* Helper function for writing quotas on sync - we need to start transaction before quota file
2438 * is locked for write. Otherwise the are possible deadlocks: 2438 * is locked for write. Otherwise the are possible deadlocks:
2439 * Process 1 Process 2 2439 * Process 1 Process 2
2440 * ext3_create() quota_sync() 2440 * ext4_create() quota_sync()
2441 * journal_start() write_dquot() 2441 * journal_start() write_dquot()
2442 * DQUOT_INIT() down(dqio_mutex) 2442 * DQUOT_INIT() down(dqio_mutex)
2443 * down(dqio_mutex) journal_start() 2443 * down(dqio_mutex) journal_start()
@@ -2451,111 +2451,111 @@ static inline struct inode *dquot_to_inode(struct dquot *dquot)
2451 return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type]; 2451 return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
2452} 2452}
2453 2453
2454static int ext3_dquot_initialize(struct inode *inode, int type) 2454static int ext4_dquot_initialize(struct inode *inode, int type)
2455{ 2455{
2456 handle_t *handle; 2456 handle_t *handle;
2457 int ret, err; 2457 int ret, err;
2458 2458
2459 /* We may create quota structure so we need to reserve enough blocks */ 2459 /* We may create quota structure so we need to reserve enough blocks */
2460 handle = ext3_journal_start(inode, 2*EXT3_QUOTA_INIT_BLOCKS(inode->i_sb)); 2460 handle = ext4_journal_start(inode, 2*EXT4_QUOTA_INIT_BLOCKS(inode->i_sb));
2461 if (IS_ERR(handle)) 2461 if (IS_ERR(handle))
2462 return PTR_ERR(handle); 2462 return PTR_ERR(handle);
2463 ret = dquot_initialize(inode, type); 2463 ret = dquot_initialize(inode, type);
2464 err = ext3_journal_stop(handle); 2464 err = ext4_journal_stop(handle);
2465 if (!ret) 2465 if (!ret)
2466 ret = err; 2466 ret = err;
2467 return ret; 2467 return ret;
2468} 2468}
2469 2469
2470static int ext3_dquot_drop(struct inode *inode) 2470static int ext4_dquot_drop(struct inode *inode)
2471{ 2471{
2472 handle_t *handle; 2472 handle_t *handle;
2473 int ret, err; 2473 int ret, err;
2474 2474
2475 /* We may delete quota structure so we need to reserve enough blocks */ 2475 /* We may delete quota structure so we need to reserve enough blocks */
2476 handle = ext3_journal_start(inode, 2*EXT3_QUOTA_DEL_BLOCKS(inode->i_sb)); 2476 handle = ext4_journal_start(inode, 2*EXT4_QUOTA_DEL_BLOCKS(inode->i_sb));
2477 if (IS_ERR(handle)) 2477 if (IS_ERR(handle))
2478 return PTR_ERR(handle); 2478 return PTR_ERR(handle);
2479 ret = dquot_drop(inode); 2479 ret = dquot_drop(inode);
2480 err = ext3_journal_stop(handle); 2480 err = ext4_journal_stop(handle);
2481 if (!ret) 2481 if (!ret)
2482 ret = err; 2482 ret = err;
2483 return ret; 2483 return ret;
2484} 2484}
2485 2485
2486static int ext3_write_dquot(struct dquot *dquot) 2486static int ext4_write_dquot(struct dquot *dquot)
2487{ 2487{
2488 int ret, err; 2488 int ret, err;
2489 handle_t *handle; 2489 handle_t *handle;
2490 struct inode *inode; 2490 struct inode *inode;
2491 2491
2492 inode = dquot_to_inode(dquot); 2492 inode = dquot_to_inode(dquot);
2493 handle = ext3_journal_start(inode, 2493 handle = ext4_journal_start(inode,
2494 EXT3_QUOTA_TRANS_BLOCKS(dquot->dq_sb)); 2494 EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
2495 if (IS_ERR(handle)) 2495 if (IS_ERR(handle))
2496 return PTR_ERR(handle); 2496 return PTR_ERR(handle);
2497 ret = dquot_commit(dquot); 2497 ret = dquot_commit(dquot);
2498 err = ext3_journal_stop(handle); 2498 err = ext4_journal_stop(handle);
2499 if (!ret) 2499 if (!ret)
2500 ret = err; 2500 ret = err;
2501 return ret; 2501 return ret;
2502} 2502}
2503 2503
2504static int ext3_acquire_dquot(struct dquot *dquot) 2504static int ext4_acquire_dquot(struct dquot *dquot)
2505{ 2505{
2506 int ret, err; 2506 int ret, err;
2507 handle_t *handle; 2507 handle_t *handle;
2508 2508
2509 handle = ext3_journal_start(dquot_to_inode(dquot), 2509 handle = ext4_journal_start(dquot_to_inode(dquot),
2510 EXT3_QUOTA_INIT_BLOCKS(dquot->dq_sb)); 2510 EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb));
2511 if (IS_ERR(handle)) 2511 if (IS_ERR(handle))
2512 return PTR_ERR(handle); 2512 return PTR_ERR(handle);
2513 ret = dquot_acquire(dquot); 2513 ret = dquot_acquire(dquot);
2514 err = ext3_journal_stop(handle); 2514 err = ext4_journal_stop(handle);
2515 if (!ret) 2515 if (!ret)
2516 ret = err; 2516 ret = err;
2517 return ret; 2517 return ret;
2518} 2518}
2519 2519
2520static int ext3_release_dquot(struct dquot *dquot) 2520static int ext4_release_dquot(struct dquot *dquot)
2521{ 2521{
2522 int ret, err; 2522 int ret, err;
2523 handle_t *handle; 2523 handle_t *handle;
2524 2524
2525 handle = ext3_journal_start(dquot_to_inode(dquot), 2525 handle = ext4_journal_start(dquot_to_inode(dquot),
2526 EXT3_QUOTA_DEL_BLOCKS(dquot->dq_sb)); 2526 EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb));
2527 if (IS_ERR(handle)) 2527 if (IS_ERR(handle))
2528 return PTR_ERR(handle); 2528 return PTR_ERR(handle);
2529 ret = dquot_release(dquot); 2529 ret = dquot_release(dquot);
2530 err = ext3_journal_stop(handle); 2530 err = ext4_journal_stop(handle);
2531 if (!ret) 2531 if (!ret)
2532 ret = err; 2532 ret = err;
2533 return ret; 2533 return ret;
2534} 2534}
2535 2535
2536static int ext3_mark_dquot_dirty(struct dquot *dquot) 2536static int ext4_mark_dquot_dirty(struct dquot *dquot)
2537{ 2537{
2538 /* Are we journalling quotas? */ 2538 /* Are we journalling quotas? */
2539 if (EXT3_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] || 2539 if (EXT4_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] ||
2540 EXT3_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) { 2540 EXT4_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) {
2541 dquot_mark_dquot_dirty(dquot); 2541 dquot_mark_dquot_dirty(dquot);
2542 return ext3_write_dquot(dquot); 2542 return ext4_write_dquot(dquot);
2543 } else { 2543 } else {
2544 return dquot_mark_dquot_dirty(dquot); 2544 return dquot_mark_dquot_dirty(dquot);
2545 } 2545 }
2546} 2546}
2547 2547
2548static int ext3_write_info(struct super_block *sb, int type) 2548static int ext4_write_info(struct super_block *sb, int type)
2549{ 2549{
2550 int ret, err; 2550 int ret, err;
2551 handle_t *handle; 2551 handle_t *handle;
2552 2552
2553 /* Data block + inode block */ 2553 /* Data block + inode block */
2554 handle = ext3_journal_start(sb->s_root->d_inode, 2); 2554 handle = ext4_journal_start(sb->s_root->d_inode, 2);
2555 if (IS_ERR(handle)) 2555 if (IS_ERR(handle))
2556 return PTR_ERR(handle); 2556 return PTR_ERR(handle);
2557 ret = dquot_commit_info(sb, type); 2557 ret = dquot_commit_info(sb, type);
2558 err = ext3_journal_stop(handle); 2558 err = ext4_journal_stop(handle);
2559 if (!ret) 2559 if (!ret)
2560 ret = err; 2560 ret = err;
2561 return ret; 2561 return ret;
@@ -2565,16 +2565,16 @@ static int ext3_write_info(struct super_block *sb, int type)
2565 * Turn on quotas during mount time - we need to find 2565 * Turn on quotas during mount time - we need to find
2566 * the quota file and such... 2566 * the quota file and such...
2567 */ 2567 */
2568static int ext3_quota_on_mount(struct super_block *sb, int type) 2568static int ext4_quota_on_mount(struct super_block *sb, int type)
2569{ 2569{
2570 return vfs_quota_on_mount(sb, EXT3_SB(sb)->s_qf_names[type], 2570 return vfs_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type],
2571 EXT3_SB(sb)->s_jquota_fmt, type); 2571 EXT4_SB(sb)->s_jquota_fmt, type);
2572} 2572}
2573 2573
2574/* 2574/*
2575 * Standard function to be called on quota_on 2575 * Standard function to be called on quota_on
2576 */ 2576 */
2577static int ext3_quota_on(struct super_block *sb, int type, int format_id, 2577static int ext4_quota_on(struct super_block *sb, int type, int format_id,
2578 char *path) 2578 char *path)
2579{ 2579{
2580 int err; 2580 int err;
@@ -2583,8 +2583,8 @@ static int ext3_quota_on(struct super_block *sb, int type, int format_id,
2583 if (!test_opt(sb, QUOTA)) 2583 if (!test_opt(sb, QUOTA))
2584 return -EINVAL; 2584 return -EINVAL;
2585 /* Not journalling quota? */ 2585 /* Not journalling quota? */
2586 if (!EXT3_SB(sb)->s_qf_names[USRQUOTA] && 2586 if (!EXT4_SB(sb)->s_qf_names[USRQUOTA] &&
2587 !EXT3_SB(sb)->s_qf_names[GRPQUOTA]) 2587 !EXT4_SB(sb)->s_qf_names[GRPQUOTA])
2588 return vfs_quota_on(sb, type, format_id, path); 2588 return vfs_quota_on(sb, type, format_id, path);
2589 err = path_lookup(path, LOOKUP_FOLLOW, &nd); 2589 err = path_lookup(path, LOOKUP_FOLLOW, &nd);
2590 if (err) 2590 if (err)
@@ -2597,7 +2597,7 @@ static int ext3_quota_on(struct super_block *sb, int type, int format_id,
2597 /* Quotafile not of fs root? */ 2597 /* Quotafile not of fs root? */
2598 if (nd.dentry->d_parent->d_inode != sb->s_root->d_inode) 2598 if (nd.dentry->d_parent->d_inode != sb->s_root->d_inode)
2599 printk(KERN_WARNING 2599 printk(KERN_WARNING
2600 "EXT3-fs: Quota file not on filesystem root. " 2600 "EXT4-fs: Quota file not on filesystem root. "
2601 "Journalled quota will not work.\n"); 2601 "Journalled quota will not work.\n");
2602 path_release(&nd); 2602 path_release(&nd);
2603 return vfs_quota_on(sb, type, format_id, path); 2603 return vfs_quota_on(sb, type, format_id, path);
@@ -2607,11 +2607,11 @@ static int ext3_quota_on(struct super_block *sb, int type, int format_id,
2607 * acquiring the locks... As quota files are never truncated and quota code 2607 * acquiring the locks... As quota files are never truncated and quota code
2608 * itself serializes the operations (and noone else should touch the files) 2608 * itself serializes the operations (and noone else should touch the files)
2609 * we don't have to be afraid of races */ 2609 * we don't have to be afraid of races */
2610static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data, 2610static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
2611 size_t len, loff_t off) 2611 size_t len, loff_t off)
2612{ 2612{
2613 struct inode *inode = sb_dqopt(sb)->files[type]; 2613 struct inode *inode = sb_dqopt(sb)->files[type];
2614 sector_t blk = off >> EXT3_BLOCK_SIZE_BITS(sb); 2614 sector_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
2615 int err = 0; 2615 int err = 0;
2616 int offset = off & (sb->s_blocksize - 1); 2616 int offset = off & (sb->s_blocksize - 1);
2617 int tocopy; 2617 int tocopy;
@@ -2627,7 +2627,7 @@ static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data,
2627 while (toread > 0) { 2627 while (toread > 0) {
2628 tocopy = sb->s_blocksize - offset < toread ? 2628 tocopy = sb->s_blocksize - offset < toread ?
2629 sb->s_blocksize - offset : toread; 2629 sb->s_blocksize - offset : toread;
2630 bh = ext3_bread(NULL, inode, blk, 0, &err); 2630 bh = ext4_bread(NULL, inode, blk, 0, &err);
2631 if (err) 2631 if (err)
2632 return err; 2632 return err;
2633 if (!bh) /* A hole? */ 2633 if (!bh) /* A hole? */
@@ -2645,15 +2645,15 @@ static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data,
2645 2645
2646/* Write to quotafile (we know the transaction is already started and has 2646/* Write to quotafile (we know the transaction is already started and has
2647 * enough credits) */ 2647 * enough credits) */
2648static ssize_t ext3_quota_write(struct super_block *sb, int type, 2648static ssize_t ext4_quota_write(struct super_block *sb, int type,
2649 const char *data, size_t len, loff_t off) 2649 const char *data, size_t len, loff_t off)
2650{ 2650{
2651 struct inode *inode = sb_dqopt(sb)->files[type]; 2651 struct inode *inode = sb_dqopt(sb)->files[type];
2652 sector_t blk = off >> EXT3_BLOCK_SIZE_BITS(sb); 2652 sector_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
2653 int err = 0; 2653 int err = 0;
2654 int offset = off & (sb->s_blocksize - 1); 2654 int offset = off & (sb->s_blocksize - 1);
2655 int tocopy; 2655 int tocopy;
2656 int journal_quota = EXT3_SB(sb)->s_qf_names[type] != NULL; 2656 int journal_quota = EXT4_SB(sb)->s_qf_names[type] != NULL;
2657 size_t towrite = len; 2657 size_t towrite = len;
2658 struct buffer_head *bh; 2658 struct buffer_head *bh;
2659 handle_t *handle = journal_current_handle(); 2659 handle_t *handle = journal_current_handle();
@@ -2662,11 +2662,11 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type,
2662 while (towrite > 0) { 2662 while (towrite > 0) {
2663 tocopy = sb->s_blocksize - offset < towrite ? 2663 tocopy = sb->s_blocksize - offset < towrite ?
2664 sb->s_blocksize - offset : towrite; 2664 sb->s_blocksize - offset : towrite;
2665 bh = ext3_bread(handle, inode, blk, 1, &err); 2665 bh = ext4_bread(handle, inode, blk, 1, &err);
2666 if (!bh) 2666 if (!bh)
2667 goto out; 2667 goto out;
2668 if (journal_quota) { 2668 if (journal_quota) {
2669 err = ext3_journal_get_write_access(handle, bh); 2669 err = ext4_journal_get_write_access(handle, bh);
2670 if (err) { 2670 if (err) {
2671 brelse(bh); 2671 brelse(bh);
2672 goto out; 2672 goto out;
@@ -2677,10 +2677,10 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type,
2677 flush_dcache_page(bh->b_page); 2677 flush_dcache_page(bh->b_page);
2678 unlock_buffer(bh); 2678 unlock_buffer(bh);
2679 if (journal_quota) 2679 if (journal_quota)
2680 err = ext3_journal_dirty_metadata(handle, bh); 2680 err = ext4_journal_dirty_metadata(handle, bh);
2681 else { 2681 else {
2682 /* Always do at least ordered writes for quotas */ 2682 /* Always do at least ordered writes for quotas */
2683 err = ext3_journal_dirty_data(handle, bh); 2683 err = ext4_journal_dirty_data(handle, bh);
2684 mark_buffer_dirty(bh); 2684 mark_buffer_dirty(bh);
2685 } 2685 }
2686 brelse(bh); 2686 brelse(bh);
@@ -2696,59 +2696,59 @@ out:
2696 return err; 2696 return err;
2697 if (inode->i_size < off+len-towrite) { 2697 if (inode->i_size < off+len-towrite) {
2698 i_size_write(inode, off+len-towrite); 2698 i_size_write(inode, off+len-towrite);
2699 EXT3_I(inode)->i_disksize = inode->i_size; 2699 EXT4_I(inode)->i_disksize = inode->i_size;
2700 } 2700 }
2701 inode->i_version++; 2701 inode->i_version++;
2702 inode->i_mtime = inode->i_ctime = CURRENT_TIME; 2702 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
2703 ext3_mark_inode_dirty(handle, inode); 2703 ext4_mark_inode_dirty(handle, inode);
2704 mutex_unlock(&inode->i_mutex); 2704 mutex_unlock(&inode->i_mutex);
2705 return len - towrite; 2705 return len - towrite;
2706} 2706}
2707 2707
2708#endif 2708#endif
2709 2709
2710static int ext3_get_sb(struct file_system_type *fs_type, 2710static int ext4_get_sb(struct file_system_type *fs_type,
2711 int flags, const char *dev_name, void *data, struct vfsmount *mnt) 2711 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
2712{ 2712{
2713 return get_sb_bdev(fs_type, flags, dev_name, data, ext3_fill_super, mnt); 2713 return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt);
2714} 2714}
2715 2715
2716static struct file_system_type ext3_fs_type = { 2716static struct file_system_type ext4dev_fs_type = {
2717 .owner = THIS_MODULE, 2717 .owner = THIS_MODULE,
2718 .name = "ext3", 2718 .name = "ext4dev",
2719 .get_sb = ext3_get_sb, 2719 .get_sb = ext4_get_sb,
2720 .kill_sb = kill_block_super, 2720 .kill_sb = kill_block_super,
2721 .fs_flags = FS_REQUIRES_DEV, 2721 .fs_flags = FS_REQUIRES_DEV,
2722}; 2722};
2723 2723
2724static int __init init_ext3_fs(void) 2724static int __init init_ext4_fs(void)
2725{ 2725{
2726 int err = init_ext3_xattr(); 2726 int err = init_ext4_xattr();
2727 if (err) 2727 if (err)
2728 return err; 2728 return err;
2729 err = init_inodecache(); 2729 err = init_inodecache();
2730 if (err) 2730 if (err)
2731 goto out1; 2731 goto out1;
2732 err = register_filesystem(&ext3_fs_type); 2732 err = register_filesystem(&ext4dev_fs_type);
2733 if (err) 2733 if (err)
2734 goto out; 2734 goto out;
2735 return 0; 2735 return 0;
2736out: 2736out:
2737 destroy_inodecache(); 2737 destroy_inodecache();
2738out1: 2738out1:
2739 exit_ext3_xattr(); 2739 exit_ext4_xattr();
2740 return err; 2740 return err;
2741} 2741}
2742 2742
2743static void __exit exit_ext3_fs(void) 2743static void __exit exit_ext4_fs(void)
2744{ 2744{
2745 unregister_filesystem(&ext3_fs_type); 2745 unregister_filesystem(&ext4dev_fs_type);
2746 destroy_inodecache(); 2746 destroy_inodecache();
2747 exit_ext3_xattr(); 2747 exit_ext4_xattr();
2748} 2748}
2749 2749
2750MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); 2750MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
2751MODULE_DESCRIPTION("Second Extended Filesystem with journaling extensions"); 2751MODULE_DESCRIPTION("Fourth Extended Filesystem with extents");
2752MODULE_LICENSE("GPL"); 2752MODULE_LICENSE("GPL");
2753module_init(init_ext3_fs) 2753module_init(init_ext4_fs)
2754module_exit(exit_ext3_fs) 2754module_exit(exit_ext4_fs)
diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c
index 4f79122cde6..9e4c75f912f 100644
--- a/fs/ext4/symlink.c
+++ b/fs/ext4/symlink.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/symlink.c 2 * linux/fs/ext4/symlink.c
3 * 3 *
4 * Only fast symlinks left here - the rest is done by generic code. AV, 1999 4 * Only fast symlinks left here - the rest is done by generic code. AV, 1999
5 * 5 *
@@ -14,41 +14,41 @@
14 * 14 *
15 * Copyright (C) 1991, 1992 Linus Torvalds 15 * Copyright (C) 1991, 1992 Linus Torvalds
16 * 16 *
17 * ext3 symlink handling code 17 * ext4 symlink handling code
18 */ 18 */
19 19
20#include <linux/fs.h> 20#include <linux/fs.h>
21#include <linux/jbd.h> 21#include <linux/jbd.h>
22#include <linux/ext3_fs.h> 22#include <linux/ext4_fs.h>
23#include <linux/namei.h> 23#include <linux/namei.h>
24#include "xattr.h" 24#include "xattr.h"
25 25
26static void * ext3_follow_link(struct dentry *dentry, struct nameidata *nd) 26static void * ext4_follow_link(struct dentry *dentry, struct nameidata *nd)
27{ 27{
28 struct ext3_inode_info *ei = EXT3_I(dentry->d_inode); 28 struct ext4_inode_info *ei = EXT4_I(dentry->d_inode);
29 nd_set_link(nd, (char*)ei->i_data); 29 nd_set_link(nd, (char*)ei->i_data);
30 return NULL; 30 return NULL;
31} 31}
32 32
33struct inode_operations ext3_symlink_inode_operations = { 33struct inode_operations ext4_symlink_inode_operations = {
34 .readlink = generic_readlink, 34 .readlink = generic_readlink,
35 .follow_link = page_follow_link_light, 35 .follow_link = page_follow_link_light,
36 .put_link = page_put_link, 36 .put_link = page_put_link,
37#ifdef CONFIG_EXT3_FS_XATTR 37#ifdef CONFIG_EXT4DEV_FS_XATTR
38 .setxattr = generic_setxattr, 38 .setxattr = generic_setxattr,
39 .getxattr = generic_getxattr, 39 .getxattr = generic_getxattr,
40 .listxattr = ext3_listxattr, 40 .listxattr = ext4_listxattr,
41 .removexattr = generic_removexattr, 41 .removexattr = generic_removexattr,
42#endif 42#endif
43}; 43};
44 44
45struct inode_operations ext3_fast_symlink_inode_operations = { 45struct inode_operations ext4_fast_symlink_inode_operations = {
46 .readlink = generic_readlink, 46 .readlink = generic_readlink,
47 .follow_link = ext3_follow_link, 47 .follow_link = ext4_follow_link,
48#ifdef CONFIG_EXT3_FS_XATTR 48#ifdef CONFIG_EXT4DEV_FS_XATTR
49 .setxattr = generic_setxattr, 49 .setxattr = generic_setxattr,
50 .getxattr = generic_getxattr, 50 .getxattr = generic_getxattr,
51 .listxattr = ext3_listxattr, 51 .listxattr = ext4_listxattr,
52 .removexattr = generic_removexattr, 52 .removexattr = generic_removexattr,
53#endif 53#endif
54}; 54};
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index f86f2482f01..d3a40815410 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * linux/fs/ext3/xattr.c 2 * linux/fs/ext4/xattr.c
3 * 3 *
4 * Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de> 4 * Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de>
5 * 5 *
6 * Fix by Harrison Xing <harrison@mountainviewdata.com>. 6 * Fix by Harrison Xing <harrison@mountainviewdata.com>.
7 * Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>. 7 * Ext4 code with a lot of help from Eric Jarman <ejarman@acm.org>.
8 * Extended attributes for symlinks and special files added per 8 * Extended attributes for symlinks and special files added per
9 * suggestion of Luka Renko <luka.renko@hermes.si>. 9 * suggestion of Luka Renko <luka.renko@hermes.si>.
10 * xattr consolidation Copyright (c) 2004 James Morris <jmorris@redhat.com>, 10 * xattr consolidation Copyright (c) 2004 James Morris <jmorris@redhat.com>,
@@ -43,7 +43,7 @@
43 * 43 *
44 * Locking strategy 44 * Locking strategy
45 * ---------------- 45 * ----------------
46 * EXT3_I(inode)->i_file_acl is protected by EXT3_I(inode)->xattr_sem. 46 * EXT4_I(inode)->i_file_acl is protected by EXT4_I(inode)->xattr_sem.
47 * EA blocks are only changed if they are exclusive to an inode, so 47 * EA blocks are only changed if they are exclusive to an inode, so
48 * holding xattr_sem also means that nothing but the EA block's reference 48 * holding xattr_sem also means that nothing but the EA block's reference
49 * count can change. Multiple writers to the same block are synchronized 49 * count can change. Multiple writers to the same block are synchronized
@@ -53,27 +53,27 @@
53#include <linux/init.h> 53#include <linux/init.h>
54#include <linux/fs.h> 54#include <linux/fs.h>
55#include <linux/slab.h> 55#include <linux/slab.h>
56#include <linux/ext3_jbd.h> 56#include <linux/ext4_jbd.h>
57#include <linux/ext3_fs.h> 57#include <linux/ext4_fs.h>
58#include <linux/mbcache.h> 58#include <linux/mbcache.h>
59#include <linux/quotaops.h> 59#include <linux/quotaops.h>
60#include <linux/rwsem.h> 60#include <linux/rwsem.h>
61#include "xattr.h" 61#include "xattr.h"
62#include "acl.h" 62#include "acl.h"
63 63
64#define BHDR(bh) ((struct ext3_xattr_header *)((bh)->b_data)) 64#define BHDR(bh) ((struct ext4_xattr_header *)((bh)->b_data))
65#define ENTRY(ptr) ((struct ext3_xattr_entry *)(ptr)) 65#define ENTRY(ptr) ((struct ext4_xattr_entry *)(ptr))
66#define BFIRST(bh) ENTRY(BHDR(bh)+1) 66#define BFIRST(bh) ENTRY(BHDR(bh)+1)
67#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0) 67#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
68 68
69#define IHDR(inode, raw_inode) \ 69#define IHDR(inode, raw_inode) \
70 ((struct ext3_xattr_ibody_header *) \ 70 ((struct ext4_xattr_ibody_header *) \
71 ((void *)raw_inode + \ 71 ((void *)raw_inode + \
72 EXT3_GOOD_OLD_INODE_SIZE + \ 72 EXT4_GOOD_OLD_INODE_SIZE + \
73 EXT3_I(inode)->i_extra_isize)) 73 EXT4_I(inode)->i_extra_isize))
74#define IFIRST(hdr) ((struct ext3_xattr_entry *)((hdr)+1)) 74#define IFIRST(hdr) ((struct ext4_xattr_entry *)((hdr)+1))
75 75
76#ifdef EXT3_XATTR_DEBUG 76#ifdef EXT4_XATTR_DEBUG
77# define ea_idebug(inode, f...) do { \ 77# define ea_idebug(inode, f...) do { \
78 printk(KERN_DEBUG "inode %s:%lu: ", \ 78 printk(KERN_DEBUG "inode %s:%lu: ", \
79 inode->i_sb->s_id, inode->i_ino); \ 79 inode->i_sb->s_id, inode->i_ino); \
@@ -93,47 +93,47 @@
93# define ea_bdebug(f...) 93# define ea_bdebug(f...)
94#endif 94#endif
95 95
96static void ext3_xattr_cache_insert(struct buffer_head *); 96static void ext4_xattr_cache_insert(struct buffer_head *);
97static struct buffer_head *ext3_xattr_cache_find(struct inode *, 97static struct buffer_head *ext4_xattr_cache_find(struct inode *,
98 struct ext3_xattr_header *, 98 struct ext4_xattr_header *,
99 struct mb_cache_entry **); 99 struct mb_cache_entry **);
100static void ext3_xattr_rehash(struct ext3_xattr_header *, 100static void ext4_xattr_rehash(struct ext4_xattr_header *,
101 struct ext3_xattr_entry *); 101 struct ext4_xattr_entry *);
102 102
103static struct mb_cache *ext3_xattr_cache; 103static struct mb_cache *ext4_xattr_cache;
104 104
105static struct xattr_handler *ext3_xattr_handler_map[] = { 105static struct xattr_handler *ext4_xattr_handler_map[] = {
106 [EXT3_XATTR_INDEX_USER] = &ext3_xattr_user_handler, 106 [EXT4_XATTR_INDEX_USER] = &ext4_xattr_user_handler,
107#ifdef CONFIG_EXT3_FS_POSIX_ACL 107#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
108 [EXT3_XATTR_INDEX_POSIX_ACL_ACCESS] = &ext3_xattr_acl_access_handler, 108 [EXT4_XATTR_INDEX_POSIX_ACL_ACCESS] = &ext4_xattr_acl_access_handler,
109 [EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT] = &ext3_xattr_acl_default_handler, 109 [EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT] = &ext4_xattr_acl_default_handler,
110#endif 110#endif
111 [EXT3_XATTR_INDEX_TRUSTED] = &ext3_xattr_trusted_handler, 111 [EXT4_XATTR_INDEX_TRUSTED] = &ext4_xattr_trusted_handler,
112#ifdef CONFIG_EXT3_FS_SECURITY 112#ifdef CONFIG_EXT4DEV_FS_SECURITY
113 [EXT3_XATTR_INDEX_SECURITY] = &ext3_xattr_security_handler, 113 [EXT4_XATTR_INDEX_SECURITY] = &ext4_xattr_security_handler,
114#endif 114#endif
115}; 115};
116 116
117struct xattr_handler *ext3_xattr_handlers[] = { 117struct xattr_handler *ext4_xattr_handlers[] = {
118 &ext3_xattr_user_handler, 118 &ext4_xattr_user_handler,
119 &ext3_xattr_trusted_handler, 119 &ext4_xattr_trusted_handler,
120#ifdef CONFIG_EXT3_FS_POSIX_ACL 120#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
121 &ext3_xattr_acl_access_handler, 121 &ext4_xattr_acl_access_handler,
122 &ext3_xattr_acl_default_handler, 122 &ext4_xattr_acl_default_handler,
123#endif 123#endif
124#ifdef CONFIG_EXT3_FS_SECURITY 124#ifdef CONFIG_EXT4DEV_FS_SECURITY
125 &ext3_xattr_security_handler, 125 &ext4_xattr_security_handler,
126#endif 126#endif
127 NULL 127 NULL
128}; 128};
129 129
130static inline struct xattr_handler * 130static inline struct xattr_handler *
131ext3_xattr_handler(int name_index) 131ext4_xattr_handler(int name_index)
132{ 132{
133 struct xattr_handler *handler = NULL; 133 struct xattr_handler *handler = NULL;
134 134
135 if (name_index > 0 && name_index < ARRAY_SIZE(ext3_xattr_handler_map)) 135 if (name_index > 0 && name_index < ARRAY_SIZE(ext4_xattr_handler_map))
136 handler = ext3_xattr_handler_map[name_index]; 136 handler = ext4_xattr_handler_map[name_index];
137 return handler; 137 return handler;
138} 138}
139 139
@@ -143,16 +143,16 @@ ext3_xattr_handler(int name_index)
143 * dentry->d_inode->i_mutex: don't care 143 * dentry->d_inode->i_mutex: don't care
144 */ 144 */
145ssize_t 145ssize_t
146ext3_listxattr(struct dentry *dentry, char *buffer, size_t size) 146ext4_listxattr(struct dentry *dentry, char *buffer, size_t size)
147{ 147{
148 return ext3_xattr_list(dentry->d_inode, buffer, size); 148 return ext4_xattr_list(dentry->d_inode, buffer, size);
149} 149}
150 150
151static int 151static int
152ext3_xattr_check_names(struct ext3_xattr_entry *entry, void *end) 152ext4_xattr_check_names(struct ext4_xattr_entry *entry, void *end)
153{ 153{
154 while (!IS_LAST_ENTRY(entry)) { 154 while (!IS_LAST_ENTRY(entry)) {
155 struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(entry); 155 struct ext4_xattr_entry *next = EXT4_XATTR_NEXT(entry);
156 if ((void *)next >= end) 156 if ((void *)next >= end)
157 return -EIO; 157 return -EIO;
158 entry = next; 158 entry = next;
@@ -161,19 +161,19 @@ ext3_xattr_check_names(struct ext3_xattr_entry *entry, void *end)
161} 161}
162 162
163static inline int 163static inline int
164ext3_xattr_check_block(struct buffer_head *bh) 164ext4_xattr_check_block(struct buffer_head *bh)
165{ 165{
166 int error; 166 int error;
167 167
168 if (BHDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) || 168 if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
169 BHDR(bh)->h_blocks != cpu_to_le32(1)) 169 BHDR(bh)->h_blocks != cpu_to_le32(1))
170 return -EIO; 170 return -EIO;
171 error = ext3_xattr_check_names(BFIRST(bh), bh->b_data + bh->b_size); 171 error = ext4_xattr_check_names(BFIRST(bh), bh->b_data + bh->b_size);
172 return error; 172 return error;
173} 173}
174 174
175static inline int 175static inline int
176ext3_xattr_check_entry(struct ext3_xattr_entry *entry, size_t size) 176ext4_xattr_check_entry(struct ext4_xattr_entry *entry, size_t size)
177{ 177{
178 size_t value_size = le32_to_cpu(entry->e_value_size); 178 size_t value_size = le32_to_cpu(entry->e_value_size);
179 179
@@ -184,10 +184,10 @@ ext3_xattr_check_entry(struct ext3_xattr_entry *entry, size_t size)
184} 184}
185 185
186static int 186static int
187ext3_xattr_find_entry(struct ext3_xattr_entry **pentry, int name_index, 187ext4_xattr_find_entry(struct ext4_xattr_entry **pentry, int name_index,
188 const char *name, size_t size, int sorted) 188 const char *name, size_t size, int sorted)
189{ 189{
190 struct ext3_xattr_entry *entry; 190 struct ext4_xattr_entry *entry;
191 size_t name_len; 191 size_t name_len;
192 int cmp = 1; 192 int cmp = 1;
193 193
@@ -195,7 +195,7 @@ ext3_xattr_find_entry(struct ext3_xattr_entry **pentry, int name_index,
195 return -EINVAL; 195 return -EINVAL;
196 name_len = strlen(name); 196 name_len = strlen(name);
197 entry = *pentry; 197 entry = *pentry;
198 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) { 198 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
199 cmp = name_index - entry->e_name_index; 199 cmp = name_index - entry->e_name_index;
200 if (!cmp) 200 if (!cmp)
201 cmp = name_len - entry->e_name_len; 201 cmp = name_len - entry->e_name_len;
@@ -205,17 +205,17 @@ ext3_xattr_find_entry(struct ext3_xattr_entry **pentry, int name_index,
205 break; 205 break;
206 } 206 }
207 *pentry = entry; 207 *pentry = entry;
208 if (!cmp && ext3_xattr_check_entry(entry, size)) 208 if (!cmp && ext4_xattr_check_entry(entry, size))
209 return -EIO; 209 return -EIO;
210 return cmp ? -ENODATA : 0; 210 return cmp ? -ENODATA : 0;
211} 211}
212 212
213static int 213static int
214ext3_xattr_block_get(struct inode *inode, int name_index, const char *name, 214ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
215 void *buffer, size_t buffer_size) 215 void *buffer, size_t buffer_size)
216{ 216{
217 struct buffer_head *bh = NULL; 217 struct buffer_head *bh = NULL;
218 struct ext3_xattr_entry *entry; 218 struct ext4_xattr_entry *entry;
219 size_t size; 219 size_t size;
220 int error; 220 int error;
221 221
@@ -223,24 +223,24 @@ ext3_xattr_block_get(struct inode *inode, int name_index, const char *name,
223 name_index, name, buffer, (long)buffer_size); 223 name_index, name, buffer, (long)buffer_size);
224 224
225 error = -ENODATA; 225 error = -ENODATA;
226 if (!EXT3_I(inode)->i_file_acl) 226 if (!EXT4_I(inode)->i_file_acl)
227 goto cleanup; 227 goto cleanup;
228 ea_idebug(inode, "reading block %u", EXT3_I(inode)->i_file_acl); 228 ea_idebug(inode, "reading block %u", EXT4_I(inode)->i_file_acl);
229 bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl); 229 bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
230 if (!bh) 230 if (!bh)
231 goto cleanup; 231 goto cleanup;
232 ea_bdebug(bh, "b_count=%d, refcount=%d", 232 ea_bdebug(bh, "b_count=%d, refcount=%d",
233 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); 233 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
234 if (ext3_xattr_check_block(bh)) { 234 if (ext4_xattr_check_block(bh)) {
235bad_block: ext3_error(inode->i_sb, __FUNCTION__, 235bad_block: ext4_error(inode->i_sb, __FUNCTION__,
236 "inode %lu: bad block "E3FSBLK, inode->i_ino, 236 "inode %lu: bad block "E3FSBLK, inode->i_ino,
237 EXT3_I(inode)->i_file_acl); 237 EXT4_I(inode)->i_file_acl);
238 error = -EIO; 238 error = -EIO;
239 goto cleanup; 239 goto cleanup;
240 } 240 }
241 ext3_xattr_cache_insert(bh); 241 ext4_xattr_cache_insert(bh);
242 entry = BFIRST(bh); 242 entry = BFIRST(bh);
243 error = ext3_xattr_find_entry(&entry, name_index, name, bh->b_size, 1); 243 error = ext4_xattr_find_entry(&entry, name_index, name, bh->b_size, 1);
244 if (error == -EIO) 244 if (error == -EIO)
245 goto bad_block; 245 goto bad_block;
246 if (error) 246 if (error)
@@ -261,30 +261,30 @@ cleanup:
261} 261}
262 262
263static int 263static int
264ext3_xattr_ibody_get(struct inode *inode, int name_index, const char *name, 264ext4_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
265 void *buffer, size_t buffer_size) 265 void *buffer, size_t buffer_size)
266{ 266{
267 struct ext3_xattr_ibody_header *header; 267 struct ext4_xattr_ibody_header *header;
268 struct ext3_xattr_entry *entry; 268 struct ext4_xattr_entry *entry;
269 struct ext3_inode *raw_inode; 269 struct ext4_inode *raw_inode;
270 struct ext3_iloc iloc; 270 struct ext4_iloc iloc;
271 size_t size; 271 size_t size;
272 void *end; 272 void *end;
273 int error; 273 int error;
274 274
275 if (!(EXT3_I(inode)->i_state & EXT3_STATE_XATTR)) 275 if (!(EXT4_I(inode)->i_state & EXT4_STATE_XATTR))
276 return -ENODATA; 276 return -ENODATA;
277 error = ext3_get_inode_loc(inode, &iloc); 277 error = ext4_get_inode_loc(inode, &iloc);
278 if (error) 278 if (error)
279 return error; 279 return error;
280 raw_inode = ext3_raw_inode(&iloc); 280 raw_inode = ext4_raw_inode(&iloc);
281 header = IHDR(inode, raw_inode); 281 header = IHDR(inode, raw_inode);
282 entry = IFIRST(header); 282 entry = IFIRST(header);
283 end = (void *)raw_inode + EXT3_SB(inode->i_sb)->s_inode_size; 283 end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size;
284 error = ext3_xattr_check_names(entry, end); 284 error = ext4_xattr_check_names(entry, end);
285 if (error) 285 if (error)
286 goto cleanup; 286 goto cleanup;
287 error = ext3_xattr_find_entry(&entry, name_index, name, 287 error = ext4_xattr_find_entry(&entry, name_index, name,
288 end - (void *)entry, 0); 288 end - (void *)entry, 0);
289 if (error) 289 if (error)
290 goto cleanup; 290 goto cleanup;
@@ -304,7 +304,7 @@ cleanup:
304} 304}
305 305
306/* 306/*
307 * ext3_xattr_get() 307 * ext4_xattr_get()
308 * 308 *
309 * Copy an extended attribute into the buffer 309 * Copy an extended attribute into the buffer
310 * provided, or compute the buffer size required. 310 * provided, or compute the buffer size required.
@@ -314,30 +314,30 @@ cleanup:
314 * used / required on success. 314 * used / required on success.
315 */ 315 */
316int 316int
317ext3_xattr_get(struct inode *inode, int name_index, const char *name, 317ext4_xattr_get(struct inode *inode, int name_index, const char *name,
318 void *buffer, size_t buffer_size) 318 void *buffer, size_t buffer_size)
319{ 319{
320 int error; 320 int error;
321 321
322 down_read(&EXT3_I(inode)->xattr_sem); 322 down_read(&EXT4_I(inode)->xattr_sem);
323 error = ext3_xattr_ibody_get(inode, name_index, name, buffer, 323 error = ext4_xattr_ibody_get(inode, name_index, name, buffer,
324 buffer_size); 324 buffer_size);
325 if (error == -ENODATA) 325 if (error == -ENODATA)
326 error = ext3_xattr_block_get(inode, name_index, name, buffer, 326 error = ext4_xattr_block_get(inode, name_index, name, buffer,
327 buffer_size); 327 buffer_size);
328 up_read(&EXT3_I(inode)->xattr_sem); 328 up_read(&EXT4_I(inode)->xattr_sem);
329 return error; 329 return error;
330} 330}
331 331
332static int 332static int
333ext3_xattr_list_entries(struct inode *inode, struct ext3_xattr_entry *entry, 333ext4_xattr_list_entries(struct inode *inode, struct ext4_xattr_entry *entry,
334 char *buffer, size_t buffer_size) 334 char *buffer, size_t buffer_size)
335{ 335{
336 size_t rest = buffer_size; 336 size_t rest = buffer_size;
337 337
338 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) { 338 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
339 struct xattr_handler *handler = 339 struct xattr_handler *handler =
340 ext3_xattr_handler(entry->e_name_index); 340 ext4_xattr_handler(entry->e_name_index);
341 341
342 if (handler) { 342 if (handler) {
343 size_t size = handler->list(inode, buffer, rest, 343 size_t size = handler->list(inode, buffer, rest,
@@ -355,7 +355,7 @@ ext3_xattr_list_entries(struct inode *inode, struct ext3_xattr_entry *entry,
355} 355}
356 356
357static int 357static int
358ext3_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size) 358ext4_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size)
359{ 359{
360 struct buffer_head *bh = NULL; 360 struct buffer_head *bh = NULL;
361 int error; 361 int error;
@@ -364,24 +364,24 @@ ext3_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size)
364 buffer, (long)buffer_size); 364 buffer, (long)buffer_size);
365 365
366 error = 0; 366 error = 0;
367 if (!EXT3_I(inode)->i_file_acl) 367 if (!EXT4_I(inode)->i_file_acl)
368 goto cleanup; 368 goto cleanup;
369 ea_idebug(inode, "reading block %u", EXT3_I(inode)->i_file_acl); 369 ea_idebug(inode, "reading block %u", EXT4_I(inode)->i_file_acl);
370 bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl); 370 bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
371 error = -EIO; 371 error = -EIO;
372 if (!bh) 372 if (!bh)
373 goto cleanup; 373 goto cleanup;
374 ea_bdebug(bh, "b_count=%d, refcount=%d", 374 ea_bdebug(bh, "b_count=%d, refcount=%d",
375 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); 375 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
376 if (ext3_xattr_check_block(bh)) { 376 if (ext4_xattr_check_block(bh)) {
377 ext3_error(inode->i_sb, __FUNCTION__, 377 ext4_error(inode->i_sb, __FUNCTION__,
378 "inode %lu: bad block "E3FSBLK, inode->i_ino, 378 "inode %lu: bad block "E3FSBLK, inode->i_ino,
379 EXT3_I(inode)->i_file_acl); 379 EXT4_I(inode)->i_file_acl);
380 error = -EIO; 380 error = -EIO;
381 goto cleanup; 381 goto cleanup;
382 } 382 }
383 ext3_xattr_cache_insert(bh); 383 ext4_xattr_cache_insert(bh);
384 error = ext3_xattr_list_entries(inode, BFIRST(bh), buffer, buffer_size); 384 error = ext4_xattr_list_entries(inode, BFIRST(bh), buffer, buffer_size);
385 385
386cleanup: 386cleanup:
387 brelse(bh); 387 brelse(bh);
@@ -390,26 +390,26 @@ cleanup:
390} 390}
391 391
392static int 392static int
393ext3_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size) 393ext4_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size)
394{ 394{
395 struct ext3_xattr_ibody_header *header; 395 struct ext4_xattr_ibody_header *header;
396 struct ext3_inode *raw_inode; 396 struct ext4_inode *raw_inode;
397 struct ext3_iloc iloc; 397 struct ext4_iloc iloc;
398 void *end; 398 void *end;
399 int error; 399 int error;
400 400
401 if (!(EXT3_I(inode)->i_state & EXT3_STATE_XATTR)) 401 if (!(EXT4_I(inode)->i_state & EXT4_STATE_XATTR))
402 return 0; 402 return 0;
403 error = ext3_get_inode_loc(inode, &iloc); 403 error = ext4_get_inode_loc(inode, &iloc);
404 if (error) 404 if (error)
405 return error; 405 return error;
406 raw_inode = ext3_raw_inode(&iloc); 406 raw_inode = ext4_raw_inode(&iloc);
407 header = IHDR(inode, raw_inode); 407 header = IHDR(inode, raw_inode);
408 end = (void *)raw_inode + EXT3_SB(inode->i_sb)->s_inode_size; 408 end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size;
409 error = ext3_xattr_check_names(IFIRST(header), end); 409 error = ext4_xattr_check_names(IFIRST(header), end);
410 if (error) 410 if (error)
411 goto cleanup; 411 goto cleanup;
412 error = ext3_xattr_list_entries(inode, IFIRST(header), 412 error = ext4_xattr_list_entries(inode, IFIRST(header),
413 buffer, buffer_size); 413 buffer, buffer_size);
414 414
415cleanup: 415cleanup:
@@ -418,7 +418,7 @@ cleanup:
418} 418}
419 419
420/* 420/*
421 * ext3_xattr_list() 421 * ext4_xattr_list()
422 * 422 *
423 * Copy a list of attribute names into the buffer 423 * Copy a list of attribute names into the buffer
424 * provided, or compute the buffer size required. 424 * provided, or compute the buffer size required.
@@ -428,12 +428,12 @@ cleanup:
428 * used / required on success. 428 * used / required on success.
429 */ 429 */
430int 430int
431ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size) 431ext4_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
432{ 432{
433 int i_error, b_error; 433 int i_error, b_error;
434 434
435 down_read(&EXT3_I(inode)->xattr_sem); 435 down_read(&EXT4_I(inode)->xattr_sem);
436 i_error = ext3_xattr_ibody_list(inode, buffer, buffer_size); 436 i_error = ext4_xattr_ibody_list(inode, buffer, buffer_size);
437 if (i_error < 0) { 437 if (i_error < 0) {
438 b_error = 0; 438 b_error = 0;
439 } else { 439 } else {
@@ -441,30 +441,30 @@ ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
441 buffer += i_error; 441 buffer += i_error;
442 buffer_size -= i_error; 442 buffer_size -= i_error;
443 } 443 }
444 b_error = ext3_xattr_block_list(inode, buffer, buffer_size); 444 b_error = ext4_xattr_block_list(inode, buffer, buffer_size);
445 if (b_error < 0) 445 if (b_error < 0)
446 i_error = 0; 446 i_error = 0;
447 } 447 }
448 up_read(&EXT3_I(inode)->xattr_sem); 448 up_read(&EXT4_I(inode)->xattr_sem);
449 return i_error + b_error; 449 return i_error + b_error;
450} 450}
451 451
452/* 452/*
453 * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is 453 * If the EXT4_FEATURE_COMPAT_EXT_ATTR feature of this file system is
454 * not set, set it. 454 * not set, set it.
455 */ 455 */
456static void ext3_xattr_update_super_block(handle_t *handle, 456static void ext4_xattr_update_super_block(handle_t *handle,
457 struct super_block *sb) 457 struct super_block *sb)
458{ 458{
459 if (EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_EXT_ATTR)) 459 if (EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_EXT_ATTR))
460 return; 460 return;
461 461
462 lock_super(sb); 462 lock_super(sb);
463 if (ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh) == 0) { 463 if (ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh) == 0) {
464 EXT3_SB(sb)->s_es->s_feature_compat |= 464 EXT4_SB(sb)->s_es->s_feature_compat |=
465 cpu_to_le32(EXT3_FEATURE_COMPAT_EXT_ATTR); 465 cpu_to_le32(EXT4_FEATURE_COMPAT_EXT_ATTR);
466 sb->s_dirt = 1; 466 sb->s_dirt = 1;
467 ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); 467 ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh);
468 } 468 }
469 unlock_super(sb); 469 unlock_super(sb);
470} 470}
@@ -474,25 +474,25 @@ static void ext3_xattr_update_super_block(handle_t *handle,
474 * it; otherwise free the block. 474 * it; otherwise free the block.
475 */ 475 */
476static void 476static void
477ext3_xattr_release_block(handle_t *handle, struct inode *inode, 477ext4_xattr_release_block(handle_t *handle, struct inode *inode,
478 struct buffer_head *bh) 478 struct buffer_head *bh)
479{ 479{
480 struct mb_cache_entry *ce = NULL; 480 struct mb_cache_entry *ce = NULL;
481 481
482 ce = mb_cache_entry_get(ext3_xattr_cache, bh->b_bdev, bh->b_blocknr); 482 ce = mb_cache_entry_get(ext4_xattr_cache, bh->b_bdev, bh->b_blocknr);
483 if (BHDR(bh)->h_refcount == cpu_to_le32(1)) { 483 if (BHDR(bh)->h_refcount == cpu_to_le32(1)) {
484 ea_bdebug(bh, "refcount now=0; freeing"); 484 ea_bdebug(bh, "refcount now=0; freeing");
485 if (ce) 485 if (ce)
486 mb_cache_entry_free(ce); 486 mb_cache_entry_free(ce);
487 ext3_free_blocks(handle, inode, bh->b_blocknr, 1); 487 ext4_free_blocks(handle, inode, bh->b_blocknr, 1);
488 get_bh(bh); 488 get_bh(bh);
489 ext3_forget(handle, 1, inode, bh, bh->b_blocknr); 489 ext4_forget(handle, 1, inode, bh, bh->b_blocknr);
490 } else { 490 } else {
491 if (ext3_journal_get_write_access(handle, bh) == 0) { 491 if (ext4_journal_get_write_access(handle, bh) == 0) {
492 lock_buffer(bh); 492 lock_buffer(bh);
493 BHDR(bh)->h_refcount = cpu_to_le32( 493 BHDR(bh)->h_refcount = cpu_to_le32(
494 le32_to_cpu(BHDR(bh)->h_refcount) - 1); 494 le32_to_cpu(BHDR(bh)->h_refcount) - 1);
495 ext3_journal_dirty_metadata(handle, bh); 495 ext4_journal_dirty_metadata(handle, bh);
496 if (IS_SYNC(inode)) 496 if (IS_SYNC(inode))
497 handle->h_sync = 1; 497 handle->h_sync = 1;
498 DQUOT_FREE_BLOCK(inode, 1); 498 DQUOT_FREE_BLOCK(inode, 1);
@@ -505,30 +505,30 @@ ext3_xattr_release_block(handle_t *handle, struct inode *inode,
505 } 505 }
506} 506}
507 507
508struct ext3_xattr_info { 508struct ext4_xattr_info {
509 int name_index; 509 int name_index;
510 const char *name; 510 const char *name;
511 const void *value; 511 const void *value;
512 size_t value_len; 512 size_t value_len;
513}; 513};
514 514
515struct ext3_xattr_search { 515struct ext4_xattr_search {
516 struct ext3_xattr_entry *first; 516 struct ext4_xattr_entry *first;
517 void *base; 517 void *base;
518 void *end; 518 void *end;
519 struct ext3_xattr_entry *here; 519 struct ext4_xattr_entry *here;
520 int not_found; 520 int not_found;
521}; 521};
522 522
523static int 523static int
524ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s) 524ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s)
525{ 525{
526 struct ext3_xattr_entry *last; 526 struct ext4_xattr_entry *last;
527 size_t free, min_offs = s->end - s->base, name_len = strlen(i->name); 527 size_t free, min_offs = s->end - s->base, name_len = strlen(i->name);
528 528
529 /* Compute min_offs and last. */ 529 /* Compute min_offs and last. */
530 last = s->first; 530 last = s->first;
531 for (; !IS_LAST_ENTRY(last); last = EXT3_XATTR_NEXT(last)) { 531 for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
532 if (!last->e_value_block && last->e_value_size) { 532 if (!last->e_value_block && last->e_value_size) {
533 size_t offs = le16_to_cpu(last->e_value_offs); 533 size_t offs = le16_to_cpu(last->e_value_offs);
534 if (offs < min_offs) 534 if (offs < min_offs)
@@ -539,20 +539,20 @@ ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s)
539 if (!s->not_found) { 539 if (!s->not_found) {
540 if (!s->here->e_value_block && s->here->e_value_size) { 540 if (!s->here->e_value_block && s->here->e_value_size) {
541 size_t size = le32_to_cpu(s->here->e_value_size); 541 size_t size = le32_to_cpu(s->here->e_value_size);
542 free += EXT3_XATTR_SIZE(size); 542 free += EXT4_XATTR_SIZE(size);
543 } 543 }
544 free += EXT3_XATTR_LEN(name_len); 544 free += EXT4_XATTR_LEN(name_len);
545 } 545 }
546 if (i->value) { 546 if (i->value) {
547 if (free < EXT3_XATTR_SIZE(i->value_len) || 547 if (free < EXT4_XATTR_SIZE(i->value_len) ||
548 free < EXT3_XATTR_LEN(name_len) + 548 free < EXT4_XATTR_LEN(name_len) +
549 EXT3_XATTR_SIZE(i->value_len)) 549 EXT4_XATTR_SIZE(i->value_len))
550 return -ENOSPC; 550 return -ENOSPC;
551 } 551 }
552 552
553 if (i->value && s->not_found) { 553 if (i->value && s->not_found) {
554 /* Insert the new name. */ 554 /* Insert the new name. */
555 size_t size = EXT3_XATTR_LEN(name_len); 555 size_t size = EXT4_XATTR_LEN(name_len);
556 size_t rest = (void *)last - (void *)s->here + sizeof(__u32); 556 size_t rest = (void *)last - (void *)s->here + sizeof(__u32);
557 memmove((void *)s->here + size, s->here, rest); 557 memmove((void *)s->here + size, s->here, rest);
558 memset(s->here, 0, size); 558 memset(s->here, 0, size);
@@ -564,16 +564,16 @@ ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s)
564 void *first_val = s->base + min_offs; 564 void *first_val = s->base + min_offs;
565 size_t offs = le16_to_cpu(s->here->e_value_offs); 565 size_t offs = le16_to_cpu(s->here->e_value_offs);
566 void *val = s->base + offs; 566 void *val = s->base + offs;
567 size_t size = EXT3_XATTR_SIZE( 567 size_t size = EXT4_XATTR_SIZE(
568 le32_to_cpu(s->here->e_value_size)); 568 le32_to_cpu(s->here->e_value_size));
569 569
570 if (i->value && size == EXT3_XATTR_SIZE(i->value_len)) { 570 if (i->value && size == EXT4_XATTR_SIZE(i->value_len)) {
571 /* The old and the new value have the same 571 /* The old and the new value have the same
572 size. Just replace. */ 572 size. Just replace. */
573 s->here->e_value_size = 573 s->here->e_value_size =
574 cpu_to_le32(i->value_len); 574 cpu_to_le32(i->value_len);
575 memset(val + size - EXT3_XATTR_PAD, 0, 575 memset(val + size - EXT4_XATTR_PAD, 0,
576 EXT3_XATTR_PAD); /* Clear pad bytes. */ 576 EXT4_XATTR_PAD); /* Clear pad bytes. */
577 memcpy(val, i->value, i->value_len); 577 memcpy(val, i->value, i->value_len);
578 return 0; 578 return 0;
579 } 579 }
@@ -593,12 +593,12 @@ ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s)
593 last->e_value_size && o < offs) 593 last->e_value_size && o < offs)
594 last->e_value_offs = 594 last->e_value_offs =
595 cpu_to_le16(o + size); 595 cpu_to_le16(o + size);
596 last = EXT3_XATTR_NEXT(last); 596 last = EXT4_XATTR_NEXT(last);
597 } 597 }
598 } 598 }
599 if (!i->value) { 599 if (!i->value) {
600 /* Remove the old name. */ 600 /* Remove the old name. */
601 size_t size = EXT3_XATTR_LEN(name_len); 601 size_t size = EXT4_XATTR_LEN(name_len);
602 last = ENTRY((void *)last - size); 602 last = ENTRY((void *)last - size);
603 memmove(s->here, (void *)s->here + size, 603 memmove(s->here, (void *)s->here + size,
604 (void *)last - (void *)s->here + sizeof(__u32)); 604 (void *)last - (void *)s->here + sizeof(__u32));
@@ -610,25 +610,25 @@ ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s)
610 /* Insert the new value. */ 610 /* Insert the new value. */
611 s->here->e_value_size = cpu_to_le32(i->value_len); 611 s->here->e_value_size = cpu_to_le32(i->value_len);
612 if (i->value_len) { 612 if (i->value_len) {
613 size_t size = EXT3_XATTR_SIZE(i->value_len); 613 size_t size = EXT4_XATTR_SIZE(i->value_len);
614 void *val = s->base + min_offs - size; 614 void *val = s->base + min_offs - size;
615 s->here->e_value_offs = cpu_to_le16(min_offs - size); 615 s->here->e_value_offs = cpu_to_le16(min_offs - size);
616 memset(val + size - EXT3_XATTR_PAD, 0, 616 memset(val + size - EXT4_XATTR_PAD, 0,
617 EXT3_XATTR_PAD); /* Clear the pad bytes. */ 617 EXT4_XATTR_PAD); /* Clear the pad bytes. */
618 memcpy(val, i->value, i->value_len); 618 memcpy(val, i->value, i->value_len);
619 } 619 }
620 } 620 }
621 return 0; 621 return 0;
622} 622}
623 623
624struct ext3_xattr_block_find { 624struct ext4_xattr_block_find {
625 struct ext3_xattr_search s; 625 struct ext4_xattr_search s;
626 struct buffer_head *bh; 626 struct buffer_head *bh;
627}; 627};
628 628
629static int 629static int
630ext3_xattr_block_find(struct inode *inode, struct ext3_xattr_info *i, 630ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i,
631 struct ext3_xattr_block_find *bs) 631 struct ext4_xattr_block_find *bs)
632{ 632{
633 struct super_block *sb = inode->i_sb; 633 struct super_block *sb = inode->i_sb;
634 int error; 634 int error;
@@ -636,19 +636,19 @@ ext3_xattr_block_find(struct inode *inode, struct ext3_xattr_info *i,
636 ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld", 636 ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
637 i->name_index, i->name, i->value, (long)i->value_len); 637 i->name_index, i->name, i->value, (long)i->value_len);
638 638
639 if (EXT3_I(inode)->i_file_acl) { 639 if (EXT4_I(inode)->i_file_acl) {
640 /* The inode already has an extended attribute block. */ 640 /* The inode already has an extended attribute block. */
641 bs->bh = sb_bread(sb, EXT3_I(inode)->i_file_acl); 641 bs->bh = sb_bread(sb, EXT4_I(inode)->i_file_acl);
642 error = -EIO; 642 error = -EIO;
643 if (!bs->bh) 643 if (!bs->bh)
644 goto cleanup; 644 goto cleanup;
645 ea_bdebug(bs->bh, "b_count=%d, refcount=%d", 645 ea_bdebug(bs->bh, "b_count=%d, refcount=%d",
646 atomic_read(&(bs->bh->b_count)), 646 atomic_read(&(bs->bh->b_count)),
647 le32_to_cpu(BHDR(bs->bh)->h_refcount)); 647 le32_to_cpu(BHDR(bs->bh)->h_refcount));
648 if (ext3_xattr_check_block(bs->bh)) { 648 if (ext4_xattr_check_block(bs->bh)) {
649 ext3_error(sb, __FUNCTION__, 649 ext4_error(sb, __FUNCTION__,
650 "inode %lu: bad block "E3FSBLK, inode->i_ino, 650 "inode %lu: bad block "E3FSBLK, inode->i_ino,
651 EXT3_I(inode)->i_file_acl); 651 EXT4_I(inode)->i_file_acl);
652 error = -EIO; 652 error = -EIO;
653 goto cleanup; 653 goto cleanup;
654 } 654 }
@@ -657,7 +657,7 @@ ext3_xattr_block_find(struct inode *inode, struct ext3_xattr_info *i,
657 bs->s.first = BFIRST(bs->bh); 657 bs->s.first = BFIRST(bs->bh);
658 bs->s.end = bs->bh->b_data + bs->bh->b_size; 658 bs->s.end = bs->bh->b_data + bs->bh->b_size;
659 bs->s.here = bs->s.first; 659 bs->s.here = bs->s.first;
660 error = ext3_xattr_find_entry(&bs->s.here, i->name_index, 660 error = ext4_xattr_find_entry(&bs->s.here, i->name_index,
661 i->name, bs->bh->b_size, 1); 661 i->name, bs->bh->b_size, 1);
662 if (error && error != -ENODATA) 662 if (error && error != -ENODATA)
663 goto cleanup; 663 goto cleanup;
@@ -670,22 +670,22 @@ cleanup:
670} 670}
671 671
672static int 672static int
673ext3_xattr_block_set(handle_t *handle, struct inode *inode, 673ext4_xattr_block_set(handle_t *handle, struct inode *inode,
674 struct ext3_xattr_info *i, 674 struct ext4_xattr_info *i,
675 struct ext3_xattr_block_find *bs) 675 struct ext4_xattr_block_find *bs)
676{ 676{
677 struct super_block *sb = inode->i_sb; 677 struct super_block *sb = inode->i_sb;
678 struct buffer_head *new_bh = NULL; 678 struct buffer_head *new_bh = NULL;
679 struct ext3_xattr_search *s = &bs->s; 679 struct ext4_xattr_search *s = &bs->s;
680 struct mb_cache_entry *ce = NULL; 680 struct mb_cache_entry *ce = NULL;
681 int error; 681 int error;
682 682
683#define header(x) ((struct ext3_xattr_header *)(x)) 683#define header(x) ((struct ext4_xattr_header *)(x))
684 684
685 if (i->value && i->value_len > sb->s_blocksize) 685 if (i->value && i->value_len > sb->s_blocksize)
686 return -ENOSPC; 686 return -ENOSPC;
687 if (s->base) { 687 if (s->base) {
688 ce = mb_cache_entry_get(ext3_xattr_cache, bs->bh->b_bdev, 688 ce = mb_cache_entry_get(ext4_xattr_cache, bs->bh->b_bdev,
689 bs->bh->b_blocknr); 689 bs->bh->b_blocknr);
690 if (header(s->base)->h_refcount == cpu_to_le32(1)) { 690 if (header(s->base)->h_refcount == cpu_to_le32(1)) {
691 if (ce) { 691 if (ce) {
@@ -693,22 +693,22 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
693 ce = NULL; 693 ce = NULL;
694 } 694 }
695 ea_bdebug(bs->bh, "modifying in-place"); 695 ea_bdebug(bs->bh, "modifying in-place");
696 error = ext3_journal_get_write_access(handle, bs->bh); 696 error = ext4_journal_get_write_access(handle, bs->bh);
697 if (error) 697 if (error)
698 goto cleanup; 698 goto cleanup;
699 lock_buffer(bs->bh); 699 lock_buffer(bs->bh);
700 error = ext3_xattr_set_entry(i, s); 700 error = ext4_xattr_set_entry(i, s);
701 if (!error) { 701 if (!error) {
702 if (!IS_LAST_ENTRY(s->first)) 702 if (!IS_LAST_ENTRY(s->first))
703 ext3_xattr_rehash(header(s->base), 703 ext4_xattr_rehash(header(s->base),
704 s->here); 704 s->here);
705 ext3_xattr_cache_insert(bs->bh); 705 ext4_xattr_cache_insert(bs->bh);
706 } 706 }
707 unlock_buffer(bs->bh); 707 unlock_buffer(bs->bh);
708 if (error == -EIO) 708 if (error == -EIO)
709 goto bad_block; 709 goto bad_block;
710 if (!error) 710 if (!error)
711 error = ext3_journal_dirty_metadata(handle, 711 error = ext4_journal_dirty_metadata(handle,
712 bs->bh); 712 bs->bh);
713 if (error) 713 if (error)
714 goto cleanup; 714 goto cleanup;
@@ -739,7 +739,7 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
739 if (s->base == NULL) 739 if (s->base == NULL)
740 goto cleanup; 740 goto cleanup;
741 memset(s->base, 0, sb->s_blocksize); 741 memset(s->base, 0, sb->s_blocksize);
742 header(s->base)->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC); 742 header(s->base)->h_magic = cpu_to_le32(EXT4_XATTR_MAGIC);
743 header(s->base)->h_blocks = cpu_to_le32(1); 743 header(s->base)->h_blocks = cpu_to_le32(1);
744 header(s->base)->h_refcount = cpu_to_le32(1); 744 header(s->base)->h_refcount = cpu_to_le32(1);
745 s->first = ENTRY(header(s->base)+1); 745 s->first = ENTRY(header(s->base)+1);
@@ -747,17 +747,17 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
747 s->end = s->base + sb->s_blocksize; 747 s->end = s->base + sb->s_blocksize;
748 } 748 }
749 749
750 error = ext3_xattr_set_entry(i, s); 750 error = ext4_xattr_set_entry(i, s);
751 if (error == -EIO) 751 if (error == -EIO)
752 goto bad_block; 752 goto bad_block;
753 if (error) 753 if (error)
754 goto cleanup; 754 goto cleanup;
755 if (!IS_LAST_ENTRY(s->first)) 755 if (!IS_LAST_ENTRY(s->first))
756 ext3_xattr_rehash(header(s->base), s->here); 756 ext4_xattr_rehash(header(s->base), s->here);
757 757
758inserted: 758inserted:
759 if (!IS_LAST_ENTRY(s->first)) { 759 if (!IS_LAST_ENTRY(s->first)) {
760 new_bh = ext3_xattr_cache_find(inode, header(s->base), &ce); 760 new_bh = ext4_xattr_cache_find(inode, header(s->base), &ce);
761 if (new_bh) { 761 if (new_bh) {
762 /* We found an identical block in the cache. */ 762 /* We found an identical block in the cache. */
763 if (new_bh == bs->bh) 763 if (new_bh == bs->bh)
@@ -768,7 +768,7 @@ inserted:
768 error = -EDQUOT; 768 error = -EDQUOT;
769 if (DQUOT_ALLOC_BLOCK(inode, 1)) 769 if (DQUOT_ALLOC_BLOCK(inode, 1))
770 goto cleanup; 770 goto cleanup;
771 error = ext3_journal_get_write_access(handle, 771 error = ext4_journal_get_write_access(handle,
772 new_bh); 772 new_bh);
773 if (error) 773 if (error)
774 goto cleanup_dquot; 774 goto cleanup_dquot;
@@ -778,7 +778,7 @@ inserted:
778 ea_bdebug(new_bh, "reusing; refcount now=%d", 778 ea_bdebug(new_bh, "reusing; refcount now=%d",
779 le32_to_cpu(BHDR(new_bh)->h_refcount)); 779 le32_to_cpu(BHDR(new_bh)->h_refcount));
780 unlock_buffer(new_bh); 780 unlock_buffer(new_bh);
781 error = ext3_journal_dirty_metadata(handle, 781 error = ext4_journal_dirty_metadata(handle,
782 new_bh); 782 new_bh);
783 if (error) 783 if (error)
784 goto cleanup_dquot; 784 goto cleanup_dquot;
@@ -792,11 +792,11 @@ inserted:
792 get_bh(new_bh); 792 get_bh(new_bh);
793 } else { 793 } else {
794 /* We need to allocate a new block */ 794 /* We need to allocate a new block */
795 ext3_fsblk_t goal = le32_to_cpu( 795 ext4_fsblk_t goal = le32_to_cpu(
796 EXT3_SB(sb)->s_es->s_first_data_block) + 796 EXT4_SB(sb)->s_es->s_first_data_block) +
797 (ext3_fsblk_t)EXT3_I(inode)->i_block_group * 797 (ext4_fsblk_t)EXT4_I(inode)->i_block_group *
798 EXT3_BLOCKS_PER_GROUP(sb); 798 EXT4_BLOCKS_PER_GROUP(sb);
799 ext3_fsblk_t block = ext3_new_block(handle, inode, 799 ext4_fsblk_t block = ext4_new_block(handle, inode,
800 goal, &error); 800 goal, &error);
801 if (error) 801 if (error)
802 goto cleanup; 802 goto cleanup;
@@ -805,12 +805,12 @@ inserted:
805 new_bh = sb_getblk(sb, block); 805 new_bh = sb_getblk(sb, block);
806 if (!new_bh) { 806 if (!new_bh) {
807getblk_failed: 807getblk_failed:
808 ext3_free_blocks(handle, inode, block, 1); 808 ext4_free_blocks(handle, inode, block, 1);
809 error = -EIO; 809 error = -EIO;
810 goto cleanup; 810 goto cleanup;
811 } 811 }
812 lock_buffer(new_bh); 812 lock_buffer(new_bh);
813 error = ext3_journal_get_create_access(handle, new_bh); 813 error = ext4_journal_get_create_access(handle, new_bh);
814 if (error) { 814 if (error) {
815 unlock_buffer(new_bh); 815 unlock_buffer(new_bh);
816 goto getblk_failed; 816 goto getblk_failed;
@@ -818,19 +818,19 @@ getblk_failed:
818 memcpy(new_bh->b_data, s->base, new_bh->b_size); 818 memcpy(new_bh->b_data, s->base, new_bh->b_size);
819 set_buffer_uptodate(new_bh); 819 set_buffer_uptodate(new_bh);
820 unlock_buffer(new_bh); 820 unlock_buffer(new_bh);
821 ext3_xattr_cache_insert(new_bh); 821 ext4_xattr_cache_insert(new_bh);
822 error = ext3_journal_dirty_metadata(handle, new_bh); 822 error = ext4_journal_dirty_metadata(handle, new_bh);
823 if (error) 823 if (error)
824 goto cleanup; 824 goto cleanup;
825 } 825 }
826 } 826 }
827 827
828 /* Update the inode. */ 828 /* Update the inode. */
829 EXT3_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0; 829 EXT4_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
830 830
831 /* Drop the previous xattr block. */ 831 /* Drop the previous xattr block. */
832 if (bs->bh && bs->bh != new_bh) 832 if (bs->bh && bs->bh != new_bh)
833 ext3_xattr_release_block(handle, inode, bs->bh); 833 ext4_xattr_release_block(handle, inode, bs->bh);
834 error = 0; 834 error = 0;
835 835
836cleanup: 836cleanup:
@@ -847,40 +847,40 @@ cleanup_dquot:
847 goto cleanup; 847 goto cleanup;
848 848
849bad_block: 849bad_block:
850 ext3_error(inode->i_sb, __FUNCTION__, 850 ext4_error(inode->i_sb, __FUNCTION__,
851 "inode %lu: bad block "E3FSBLK, inode->i_ino, 851 "inode %lu: bad block "E3FSBLK, inode->i_ino,
852 EXT3_I(inode)->i_file_acl); 852 EXT4_I(inode)->i_file_acl);
853 goto cleanup; 853 goto cleanup;
854 854
855#undef header 855#undef header
856} 856}
857 857
858struct ext3_xattr_ibody_find { 858struct ext4_xattr_ibody_find {
859 struct ext3_xattr_search s; 859 struct ext4_xattr_search s;
860 struct ext3_iloc iloc; 860 struct ext4_iloc iloc;
861}; 861};
862 862
863static int 863static int
864ext3_xattr_ibody_find(struct inode *inode, struct ext3_xattr_info *i, 864ext4_xattr_ibody_find(struct inode *inode, struct ext4_xattr_info *i,
865 struct ext3_xattr_ibody_find *is) 865 struct ext4_xattr_ibody_find *is)
866{ 866{
867 struct ext3_xattr_ibody_header *header; 867 struct ext4_xattr_ibody_header *header;
868 struct ext3_inode *raw_inode; 868 struct ext4_inode *raw_inode;
869 int error; 869 int error;
870 870
871 if (EXT3_I(inode)->i_extra_isize == 0) 871 if (EXT4_I(inode)->i_extra_isize == 0)
872 return 0; 872 return 0;
873 raw_inode = ext3_raw_inode(&is->iloc); 873 raw_inode = ext4_raw_inode(&is->iloc);
874 header = IHDR(inode, raw_inode); 874 header = IHDR(inode, raw_inode);
875 is->s.base = is->s.first = IFIRST(header); 875 is->s.base = is->s.first = IFIRST(header);
876 is->s.here = is->s.first; 876 is->s.here = is->s.first;
877 is->s.end = (void *)raw_inode + EXT3_SB(inode->i_sb)->s_inode_size; 877 is->s.end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size;
878 if (EXT3_I(inode)->i_state & EXT3_STATE_XATTR) { 878 if (EXT4_I(inode)->i_state & EXT4_STATE_XATTR) {
879 error = ext3_xattr_check_names(IFIRST(header), is->s.end); 879 error = ext4_xattr_check_names(IFIRST(header), is->s.end);
880 if (error) 880 if (error)
881 return error; 881 return error;
882 /* Find the named attribute. */ 882 /* Find the named attribute. */
883 error = ext3_xattr_find_entry(&is->s.here, i->name_index, 883 error = ext4_xattr_find_entry(&is->s.here, i->name_index,
884 i->name, is->s.end - 884 i->name, is->s.end -
885 (void *)is->s.base, 0); 885 (void *)is->s.base, 0);
886 if (error && error != -ENODATA) 886 if (error && error != -ENODATA)
@@ -891,32 +891,32 @@ ext3_xattr_ibody_find(struct inode *inode, struct ext3_xattr_info *i,
891} 891}
892 892
893static int 893static int
894ext3_xattr_ibody_set(handle_t *handle, struct inode *inode, 894ext4_xattr_ibody_set(handle_t *handle, struct inode *inode,
895 struct ext3_xattr_info *i, 895 struct ext4_xattr_info *i,
896 struct ext3_xattr_ibody_find *is) 896 struct ext4_xattr_ibody_find *is)
897{ 897{
898 struct ext3_xattr_ibody_header *header; 898 struct ext4_xattr_ibody_header *header;
899 struct ext3_xattr_search *s = &is->s; 899 struct ext4_xattr_search *s = &is->s;
900 int error; 900 int error;
901 901
902 if (EXT3_I(inode)->i_extra_isize == 0) 902 if (EXT4_I(inode)->i_extra_isize == 0)
903 return -ENOSPC; 903 return -ENOSPC;
904 error = ext3_xattr_set_entry(i, s); 904 error = ext4_xattr_set_entry(i, s);
905 if (error) 905 if (error)
906 return error; 906 return error;
907 header = IHDR(inode, ext3_raw_inode(&is->iloc)); 907 header = IHDR(inode, ext4_raw_inode(&is->iloc));
908 if (!IS_LAST_ENTRY(s->first)) { 908 if (!IS_LAST_ENTRY(s->first)) {
909 header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC); 909 header->h_magic = cpu_to_le32(EXT4_XATTR_MAGIC);
910 EXT3_I(inode)->i_state |= EXT3_STATE_XATTR; 910 EXT4_I(inode)->i_state |= EXT4_STATE_XATTR;
911 } else { 911 } else {
912 header->h_magic = cpu_to_le32(0); 912 header->h_magic = cpu_to_le32(0);
913 EXT3_I(inode)->i_state &= ~EXT3_STATE_XATTR; 913 EXT4_I(inode)->i_state &= ~EXT4_STATE_XATTR;
914 } 914 }
915 return 0; 915 return 0;
916} 916}
917 917
918/* 918/*
919 * ext3_xattr_set_handle() 919 * ext4_xattr_set_handle()
920 * 920 *
921 * Create, replace or remove an extended attribute for this inode. Buffer 921 * Create, replace or remove an extended attribute for this inode. Buffer
922 * is NULL to remove an existing extended attribute, and non-NULL to 922 * is NULL to remove an existing extended attribute, and non-NULL to
@@ -928,21 +928,21 @@ ext3_xattr_ibody_set(handle_t *handle, struct inode *inode,
928 * Returns 0, or a negative error number on failure. 928 * Returns 0, or a negative error number on failure.
929 */ 929 */
930int 930int
931ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index, 931ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
932 const char *name, const void *value, size_t value_len, 932 const char *name, const void *value, size_t value_len,
933 int flags) 933 int flags)
934{ 934{
935 struct ext3_xattr_info i = { 935 struct ext4_xattr_info i = {
936 .name_index = name_index, 936 .name_index = name_index,
937 .name = name, 937 .name = name,
938 .value = value, 938 .value = value,
939 .value_len = value_len, 939 .value_len = value_len,
940 940
941 }; 941 };
942 struct ext3_xattr_ibody_find is = { 942 struct ext4_xattr_ibody_find is = {
943 .s = { .not_found = -ENODATA, }, 943 .s = { .not_found = -ENODATA, },
944 }; 944 };
945 struct ext3_xattr_block_find bs = { 945 struct ext4_xattr_block_find bs = {
946 .s = { .not_found = -ENODATA, }, 946 .s = { .not_found = -ENODATA, },
947 }; 947 };
948 int error; 948 int error;
@@ -951,22 +951,22 @@ ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
951 return -EINVAL; 951 return -EINVAL;
952 if (strlen(name) > 255) 952 if (strlen(name) > 255)
953 return -ERANGE; 953 return -ERANGE;
954 down_write(&EXT3_I(inode)->xattr_sem); 954 down_write(&EXT4_I(inode)->xattr_sem);
955 error = ext3_get_inode_loc(inode, &is.iloc); 955 error = ext4_get_inode_loc(inode, &is.iloc);
956 if (error) 956 if (error)
957 goto cleanup; 957 goto cleanup;
958 958
959 if (EXT3_I(inode)->i_state & EXT3_STATE_NEW) { 959 if (EXT4_I(inode)->i_state & EXT4_STATE_NEW) {
960 struct ext3_inode *raw_inode = ext3_raw_inode(&is.iloc); 960 struct ext4_inode *raw_inode = ext4_raw_inode(&is.iloc);
961 memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size); 961 memset(raw_inode, 0, EXT4_SB(inode->i_sb)->s_inode_size);
962 EXT3_I(inode)->i_state &= ~EXT3_STATE_NEW; 962 EXT4_I(inode)->i_state &= ~EXT4_STATE_NEW;
963 } 963 }
964 964
965 error = ext3_xattr_ibody_find(inode, &i, &is); 965 error = ext4_xattr_ibody_find(inode, &i, &is);
966 if (error) 966 if (error)
967 goto cleanup; 967 goto cleanup;
968 if (is.s.not_found) 968 if (is.s.not_found)
969 error = ext3_xattr_block_find(inode, &i, &bs); 969 error = ext4_xattr_block_find(inode, &i, &bs);
970 if (error) 970 if (error)
971 goto cleanup; 971 goto cleanup;
972 if (is.s.not_found && bs.s.not_found) { 972 if (is.s.not_found && bs.s.not_found) {
@@ -981,36 +981,36 @@ ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
981 if (flags & XATTR_CREATE) 981 if (flags & XATTR_CREATE)
982 goto cleanup; 982 goto cleanup;
983 } 983 }
984 error = ext3_journal_get_write_access(handle, is.iloc.bh); 984 error = ext4_journal_get_write_access(handle, is.iloc.bh);
985 if (error) 985 if (error)
986 goto cleanup; 986 goto cleanup;
987 if (!value) { 987 if (!value) {
988 if (!is.s.not_found) 988 if (!is.s.not_found)
989 error = ext3_xattr_ibody_set(handle, inode, &i, &is); 989 error = ext4_xattr_ibody_set(handle, inode, &i, &is);
990 else if (!bs.s.not_found) 990 else if (!bs.s.not_found)
991 error = ext3_xattr_block_set(handle, inode, &i, &bs); 991 error = ext4_xattr_block_set(handle, inode, &i, &bs);
992 } else { 992 } else {
993 error = ext3_xattr_ibody_set(handle, inode, &i, &is); 993 error = ext4_xattr_ibody_set(handle, inode, &i, &is);
994 if (!error && !bs.s.not_found) { 994 if (!error && !bs.s.not_found) {
995 i.value = NULL; 995 i.value = NULL;
996 error = ext3_xattr_block_set(handle, inode, &i, &bs); 996 error = ext4_xattr_block_set(handle, inode, &i, &bs);
997 } else if (error == -ENOSPC) { 997 } else if (error == -ENOSPC) {
998 error = ext3_xattr_block_set(handle, inode, &i, &bs); 998 error = ext4_xattr_block_set(handle, inode, &i, &bs);
999 if (error) 999 if (error)
1000 goto cleanup; 1000 goto cleanup;
1001 if (!is.s.not_found) { 1001 if (!is.s.not_found) {
1002 i.value = NULL; 1002 i.value = NULL;
1003 error = ext3_xattr_ibody_set(handle, inode, &i, 1003 error = ext4_xattr_ibody_set(handle, inode, &i,
1004 &is); 1004 &is);
1005 } 1005 }
1006 } 1006 }
1007 } 1007 }
1008 if (!error) { 1008 if (!error) {
1009 ext3_xattr_update_super_block(handle, inode->i_sb); 1009 ext4_xattr_update_super_block(handle, inode->i_sb);
1010 inode->i_ctime = CURRENT_TIME_SEC; 1010 inode->i_ctime = CURRENT_TIME_SEC;
1011 error = ext3_mark_iloc_dirty(handle, inode, &is.iloc); 1011 error = ext4_mark_iloc_dirty(handle, inode, &is.iloc);
1012 /* 1012 /*
1013 * The bh is consumed by ext3_mark_iloc_dirty, even with 1013 * The bh is consumed by ext4_mark_iloc_dirty, even with
1014 * error != 0. 1014 * error != 0.
1015 */ 1015 */
1016 is.iloc.bh = NULL; 1016 is.iloc.bh = NULL;
@@ -1021,37 +1021,37 @@ ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
1021cleanup: 1021cleanup:
1022 brelse(is.iloc.bh); 1022 brelse(is.iloc.bh);
1023 brelse(bs.bh); 1023 brelse(bs.bh);
1024 up_write(&EXT3_I(inode)->xattr_sem); 1024 up_write(&EXT4_I(inode)->xattr_sem);
1025 return error; 1025 return error;
1026} 1026}
1027 1027
1028/* 1028/*
1029 * ext3_xattr_set() 1029 * ext4_xattr_set()
1030 * 1030 *
1031 * Like ext3_xattr_set_handle, but start from an inode. This extended 1031 * Like ext4_xattr_set_handle, but start from an inode. This extended
1032 * attribute modification is a filesystem transaction by itself. 1032 * attribute modification is a filesystem transaction by itself.
1033 * 1033 *
1034 * Returns 0, or a negative error number on failure. 1034 * Returns 0, or a negative error number on failure.
1035 */ 1035 */
1036int 1036int
1037ext3_xattr_set(struct inode *inode, int name_index, const char *name, 1037ext4_xattr_set(struct inode *inode, int name_index, const char *name,
1038 const void *value, size_t value_len, int flags) 1038 const void *value, size_t value_len, int flags)
1039{ 1039{
1040 handle_t *handle; 1040 handle_t *handle;
1041 int error, retries = 0; 1041 int error, retries = 0;
1042 1042
1043retry: 1043retry:
1044 handle = ext3_journal_start(inode, EXT3_DATA_TRANS_BLOCKS(inode->i_sb)); 1044 handle = ext4_journal_start(inode, EXT4_DATA_TRANS_BLOCKS(inode->i_sb));
1045 if (IS_ERR(handle)) { 1045 if (IS_ERR(handle)) {
1046 error = PTR_ERR(handle); 1046 error = PTR_ERR(handle);
1047 } else { 1047 } else {
1048 int error2; 1048 int error2;
1049 1049
1050 error = ext3_xattr_set_handle(handle, inode, name_index, name, 1050 error = ext4_xattr_set_handle(handle, inode, name_index, name,
1051 value, value_len, flags); 1051 value, value_len, flags);
1052 error2 = ext3_journal_stop(handle); 1052 error2 = ext4_journal_stop(handle);
1053 if (error == -ENOSPC && 1053 if (error == -ENOSPC &&
1054 ext3_should_retry_alloc(inode->i_sb, &retries)) 1054 ext4_should_retry_alloc(inode->i_sb, &retries))
1055 goto retry; 1055 goto retry;
1056 if (error == 0) 1056 if (error == 0)
1057 error = error2; 1057 error = error2;
@@ -1061,53 +1061,53 @@ retry:
1061} 1061}
1062 1062
1063/* 1063/*
1064 * ext3_xattr_delete_inode() 1064 * ext4_xattr_delete_inode()
1065 * 1065 *
1066 * Free extended attribute resources associated with this inode. This 1066 * Free extended attribute resources associated with this inode. This
1067 * is called immediately before an inode is freed. We have exclusive 1067 * is called immediately before an inode is freed. We have exclusive
1068 * access to the inode. 1068 * access to the inode.
1069 */ 1069 */
1070void 1070void
1071ext3_xattr_delete_inode(handle_t *handle, struct inode *inode) 1071ext4_xattr_delete_inode(handle_t *handle, struct inode *inode)
1072{ 1072{
1073 struct buffer_head *bh = NULL; 1073 struct buffer_head *bh = NULL;
1074 1074
1075 if (!EXT3_I(inode)->i_file_acl) 1075 if (!EXT4_I(inode)->i_file_acl)
1076 goto cleanup; 1076 goto cleanup;
1077 bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl); 1077 bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
1078 if (!bh) { 1078 if (!bh) {
1079 ext3_error(inode->i_sb, __FUNCTION__, 1079 ext4_error(inode->i_sb, __FUNCTION__,
1080 "inode %lu: block "E3FSBLK" read error", inode->i_ino, 1080 "inode %lu: block "E3FSBLK" read error", inode->i_ino,
1081 EXT3_I(inode)->i_file_acl); 1081 EXT4_I(inode)->i_file_acl);
1082 goto cleanup; 1082 goto cleanup;
1083 } 1083 }
1084 if (BHDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) || 1084 if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
1085 BHDR(bh)->h_blocks != cpu_to_le32(1)) { 1085 BHDR(bh)->h_blocks != cpu_to_le32(1)) {
1086 ext3_error(inode->i_sb, __FUNCTION__, 1086 ext4_error(inode->i_sb, __FUNCTION__,
1087 "inode %lu: bad block "E3FSBLK, inode->i_ino, 1087 "inode %lu: bad block "E3FSBLK, inode->i_ino,
1088 EXT3_I(inode)->i_file_acl); 1088 EXT4_I(inode)->i_file_acl);
1089 goto cleanup; 1089 goto cleanup;
1090 } 1090 }
1091 ext3_xattr_release_block(handle, inode, bh); 1091 ext4_xattr_release_block(handle, inode, bh);
1092 EXT3_I(inode)->i_file_acl = 0; 1092 EXT4_I(inode)->i_file_acl = 0;
1093 1093
1094cleanup: 1094cleanup:
1095 brelse(bh); 1095 brelse(bh);
1096} 1096}
1097 1097
1098/* 1098/*
1099 * ext3_xattr_put_super() 1099 * ext4_xattr_put_super()
1100 * 1100 *
1101 * This is called when a file system is unmounted. 1101 * This is called when a file system is unmounted.
1102 */ 1102 */
1103void 1103void
1104ext3_xattr_put_super(struct super_block *sb) 1104ext4_xattr_put_super(struct super_block *sb)
1105{ 1105{
1106 mb_cache_shrink(sb->s_bdev); 1106 mb_cache_shrink(sb->s_bdev);
1107} 1107}
1108 1108
1109/* 1109/*
1110 * ext3_xattr_cache_insert() 1110 * ext4_xattr_cache_insert()
1111 * 1111 *
1112 * Create a new entry in the extended attribute cache, and insert 1112 * Create a new entry in the extended attribute cache, and insert
1113 * it unless such an entry is already in the cache. 1113 * it unless such an entry is already in the cache.
@@ -1115,13 +1115,13 @@ ext3_xattr_put_super(struct super_block *sb)
1115 * Returns 0, or a negative error number on failure. 1115 * Returns 0, or a negative error number on failure.
1116 */ 1116 */
1117static void 1117static void
1118ext3_xattr_cache_insert(struct buffer_head *bh) 1118ext4_xattr_cache_insert(struct buffer_head *bh)
1119{ 1119{
1120 __u32 hash = le32_to_cpu(BHDR(bh)->h_hash); 1120 __u32 hash = le32_to_cpu(BHDR(bh)->h_hash);
1121 struct mb_cache_entry *ce; 1121 struct mb_cache_entry *ce;
1122 int error; 1122 int error;
1123 1123
1124 ce = mb_cache_entry_alloc(ext3_xattr_cache); 1124 ce = mb_cache_entry_alloc(ext4_xattr_cache);
1125 if (!ce) { 1125 if (!ce) {
1126 ea_bdebug(bh, "out of memory"); 1126 ea_bdebug(bh, "out of memory");
1127 return; 1127 return;
@@ -1140,7 +1140,7 @@ ext3_xattr_cache_insert(struct buffer_head *bh)
1140} 1140}
1141 1141
1142/* 1142/*
1143 * ext3_xattr_cmp() 1143 * ext4_xattr_cmp()
1144 * 1144 *
1145 * Compare two extended attribute blocks for equality. 1145 * Compare two extended attribute blocks for equality.
1146 * 1146 *
@@ -1148,10 +1148,10 @@ ext3_xattr_cache_insert(struct buffer_head *bh)
1148 * a negative error number on errors. 1148 * a negative error number on errors.
1149 */ 1149 */
1150static int 1150static int
1151ext3_xattr_cmp(struct ext3_xattr_header *header1, 1151ext4_xattr_cmp(struct ext4_xattr_header *header1,
1152 struct ext3_xattr_header *header2) 1152 struct ext4_xattr_header *header2)
1153{ 1153{
1154 struct ext3_xattr_entry *entry1, *entry2; 1154 struct ext4_xattr_entry *entry1, *entry2;
1155 1155
1156 entry1 = ENTRY(header1+1); 1156 entry1 = ENTRY(header1+1);
1157 entry2 = ENTRY(header2+1); 1157 entry2 = ENTRY(header2+1);
@@ -1171,8 +1171,8 @@ ext3_xattr_cmp(struct ext3_xattr_header *header1,
1171 le32_to_cpu(entry1->e_value_size))) 1171 le32_to_cpu(entry1->e_value_size)))
1172 return 1; 1172 return 1;
1173 1173
1174 entry1 = EXT3_XATTR_NEXT(entry1); 1174 entry1 = EXT4_XATTR_NEXT(entry1);
1175 entry2 = EXT3_XATTR_NEXT(entry2); 1175 entry2 = EXT4_XATTR_NEXT(entry2);
1176 } 1176 }
1177 if (!IS_LAST_ENTRY(entry2)) 1177 if (!IS_LAST_ENTRY(entry2))
1178 return 1; 1178 return 1;
@@ -1180,7 +1180,7 @@ ext3_xattr_cmp(struct ext3_xattr_header *header1,
1180} 1180}
1181 1181
1182/* 1182/*
1183 * ext3_xattr_cache_find() 1183 * ext4_xattr_cache_find()
1184 * 1184 *
1185 * Find an identical extended attribute block. 1185 * Find an identical extended attribute block.
1186 * 1186 *
@@ -1188,7 +1188,7 @@ ext3_xattr_cmp(struct ext3_xattr_header *header1,
1188 * not found or an error occurred. 1188 * not found or an error occurred.
1189 */ 1189 */
1190static struct buffer_head * 1190static struct buffer_head *
1191ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header, 1191ext4_xattr_cache_find(struct inode *inode, struct ext4_xattr_header *header,
1192 struct mb_cache_entry **pce) 1192 struct mb_cache_entry **pce)
1193{ 1193{
1194 __u32 hash = le32_to_cpu(header->h_hash); 1194 __u32 hash = le32_to_cpu(header->h_hash);
@@ -1198,7 +1198,7 @@ ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header,
1198 return NULL; /* never share */ 1198 return NULL; /* never share */
1199 ea_idebug(inode, "looking for cached blocks [%x]", (int)hash); 1199 ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
1200again: 1200again:
1201 ce = mb_cache_entry_find_first(ext3_xattr_cache, 0, 1201 ce = mb_cache_entry_find_first(ext4_xattr_cache, 0,
1202 inode->i_sb->s_bdev, hash); 1202 inode->i_sb->s_bdev, hash);
1203 while (ce) { 1203 while (ce) {
1204 struct buffer_head *bh; 1204 struct buffer_head *bh;
@@ -1210,16 +1210,16 @@ again:
1210 } 1210 }
1211 bh = sb_bread(inode->i_sb, ce->e_block); 1211 bh = sb_bread(inode->i_sb, ce->e_block);
1212 if (!bh) { 1212 if (!bh) {
1213 ext3_error(inode->i_sb, __FUNCTION__, 1213 ext4_error(inode->i_sb, __FUNCTION__,
1214 "inode %lu: block %lu read error", 1214 "inode %lu: block %lu read error",
1215 inode->i_ino, (unsigned long) ce->e_block); 1215 inode->i_ino, (unsigned long) ce->e_block);
1216 } else if (le32_to_cpu(BHDR(bh)->h_refcount) >= 1216 } else if (le32_to_cpu(BHDR(bh)->h_refcount) >=
1217 EXT3_XATTR_REFCOUNT_MAX) { 1217 EXT4_XATTR_REFCOUNT_MAX) {
1218 ea_idebug(inode, "block %lu refcount %d>=%d", 1218 ea_idebug(inode, "block %lu refcount %d>=%d",
1219 (unsigned long) ce->e_block, 1219 (unsigned long) ce->e_block,
1220 le32_to_cpu(BHDR(bh)->h_refcount), 1220 le32_to_cpu(BHDR(bh)->h_refcount),
1221 EXT3_XATTR_REFCOUNT_MAX); 1221 EXT4_XATTR_REFCOUNT_MAX);
1222 } else if (ext3_xattr_cmp(header, BHDR(bh)) == 0) { 1222 } else if (ext4_xattr_cmp(header, BHDR(bh)) == 0) {
1223 *pce = ce; 1223 *pce = ce;
1224 return bh; 1224 return bh;
1225 } 1225 }
@@ -1233,12 +1233,12 @@ again:
1233#define VALUE_HASH_SHIFT 16 1233#define VALUE_HASH_SHIFT 16
1234 1234
1235/* 1235/*
1236 * ext3_xattr_hash_entry() 1236 * ext4_xattr_hash_entry()
1237 * 1237 *
1238 * Compute the hash of an extended attribute. 1238 * Compute the hash of an extended attribute.
1239 */ 1239 */
1240static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header, 1240static inline void ext4_xattr_hash_entry(struct ext4_xattr_header *header,
1241 struct ext3_xattr_entry *entry) 1241 struct ext4_xattr_entry *entry)
1242{ 1242{
1243 __u32 hash = 0; 1243 __u32 hash = 0;
1244 char *name = entry->e_name; 1244 char *name = entry->e_name;
@@ -1254,7 +1254,7 @@ static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
1254 __le32 *value = (__le32 *)((char *)header + 1254 __le32 *value = (__le32 *)((char *)header +
1255 le16_to_cpu(entry->e_value_offs)); 1255 le16_to_cpu(entry->e_value_offs));
1256 for (n = (le32_to_cpu(entry->e_value_size) + 1256 for (n = (le32_to_cpu(entry->e_value_size) +
1257 EXT3_XATTR_ROUND) >> EXT3_XATTR_PAD_BITS; n; n--) { 1257 EXT4_XATTR_ROUND) >> EXT4_XATTR_PAD_BITS; n; n--) {
1258 hash = (hash << VALUE_HASH_SHIFT) ^ 1258 hash = (hash << VALUE_HASH_SHIFT) ^
1259 (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^ 1259 (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
1260 le32_to_cpu(*value++); 1260 le32_to_cpu(*value++);
@@ -1269,17 +1269,17 @@ static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
1269#define BLOCK_HASH_SHIFT 16 1269#define BLOCK_HASH_SHIFT 16
1270 1270
1271/* 1271/*
1272 * ext3_xattr_rehash() 1272 * ext4_xattr_rehash()
1273 * 1273 *
1274 * Re-compute the extended attribute hash value after an entry has changed. 1274 * Re-compute the extended attribute hash value after an entry has changed.
1275 */ 1275 */
1276static void ext3_xattr_rehash(struct ext3_xattr_header *header, 1276static void ext4_xattr_rehash(struct ext4_xattr_header *header,
1277 struct ext3_xattr_entry *entry) 1277 struct ext4_xattr_entry *entry)
1278{ 1278{
1279 struct ext3_xattr_entry *here; 1279 struct ext4_xattr_entry *here;
1280 __u32 hash = 0; 1280 __u32 hash = 0;
1281 1281
1282 ext3_xattr_hash_entry(header, entry); 1282 ext4_xattr_hash_entry(header, entry);
1283 here = ENTRY(header+1); 1283 here = ENTRY(header+1);
1284 while (!IS_LAST_ENTRY(here)) { 1284 while (!IS_LAST_ENTRY(here)) {
1285 if (!here->e_hash) { 1285 if (!here->e_hash) {
@@ -1290,7 +1290,7 @@ static void ext3_xattr_rehash(struct ext3_xattr_header *header,
1290 hash = (hash << BLOCK_HASH_SHIFT) ^ 1290 hash = (hash << BLOCK_HASH_SHIFT) ^
1291 (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^ 1291 (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
1292 le32_to_cpu(here->e_hash); 1292 le32_to_cpu(here->e_hash);
1293 here = EXT3_XATTR_NEXT(here); 1293 here = EXT4_XATTR_NEXT(here);
1294 } 1294 }
1295 header->h_hash = cpu_to_le32(hash); 1295 header->h_hash = cpu_to_le32(hash);
1296} 1296}
@@ -1298,20 +1298,20 @@ static void ext3_xattr_rehash(struct ext3_xattr_header *header,
1298#undef BLOCK_HASH_SHIFT 1298#undef BLOCK_HASH_SHIFT
1299 1299
1300int __init 1300int __init
1301init_ext3_xattr(void) 1301init_ext4_xattr(void)
1302{ 1302{
1303 ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL, 1303 ext4_xattr_cache = mb_cache_create("ext4_xattr", NULL,
1304 sizeof(struct mb_cache_entry) + 1304 sizeof(struct mb_cache_entry) +
1305 sizeof(((struct mb_cache_entry *) 0)->e_indexes[0]), 1, 6); 1305 sizeof(((struct mb_cache_entry *) 0)->e_indexes[0]), 1, 6);
1306 if (!ext3_xattr_cache) 1306 if (!ext4_xattr_cache)
1307 return -ENOMEM; 1307 return -ENOMEM;
1308 return 0; 1308 return 0;
1309} 1309}
1310 1310
1311void 1311void
1312exit_ext3_xattr(void) 1312exit_ext4_xattr(void)
1313{ 1313{
1314 if (ext3_xattr_cache) 1314 if (ext4_xattr_cache)
1315 mb_cache_destroy(ext3_xattr_cache); 1315 mb_cache_destroy(ext4_xattr_cache);
1316 ext3_xattr_cache = NULL; 1316 ext4_xattr_cache = NULL;
1317} 1317}
diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h
index 6b1ae1c6182..79432b35398 100644
--- a/fs/ext4/xattr.h
+++ b/fs/ext4/xattr.h
@@ -1,7 +1,7 @@
1/* 1/*
2 File: fs/ext3/xattr.h 2 File: fs/ext4/xattr.h
3 3
4 On-disk format of extended attributes for the ext3 filesystem. 4 On-disk format of extended attributes for the ext4 filesystem.
5 5
6 (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org> 6 (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
7*/ 7*/
@@ -9,20 +9,20 @@
9#include <linux/xattr.h> 9#include <linux/xattr.h>
10 10
11/* Magic value in attribute blocks */ 11/* Magic value in attribute blocks */
12#define EXT3_XATTR_MAGIC 0xEA020000 12#define EXT4_XATTR_MAGIC 0xEA020000
13 13
14/* Maximum number of references to one attribute block */ 14/* Maximum number of references to one attribute block */
15#define EXT3_XATTR_REFCOUNT_MAX 1024 15#define EXT4_XATTR_REFCOUNT_MAX 1024
16 16
17/* Name indexes */ 17/* Name indexes */
18#define EXT3_XATTR_INDEX_USER 1 18#define EXT4_XATTR_INDEX_USER 1
19#define EXT3_XATTR_INDEX_POSIX_ACL_ACCESS 2 19#define EXT4_XATTR_INDEX_POSIX_ACL_ACCESS 2
20#define EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT 3 20#define EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT 3
21#define EXT3_XATTR_INDEX_TRUSTED 4 21#define EXT4_XATTR_INDEX_TRUSTED 4
22#define EXT3_XATTR_INDEX_LUSTRE 5 22#define EXT4_XATTR_INDEX_LUSTRE 5
23#define EXT3_XATTR_INDEX_SECURITY 6 23#define EXT4_XATTR_INDEX_SECURITY 6
24 24
25struct ext3_xattr_header { 25struct ext4_xattr_header {
26 __le32 h_magic; /* magic number for identification */ 26 __le32 h_magic; /* magic number for identification */
27 __le32 h_refcount; /* reference count */ 27 __le32 h_refcount; /* reference count */
28 __le32 h_blocks; /* number of disk blocks used */ 28 __le32 h_blocks; /* number of disk blocks used */
@@ -30,11 +30,11 @@ struct ext3_xattr_header {
30 __u32 h_reserved[4]; /* zero right now */ 30 __u32 h_reserved[4]; /* zero right now */
31}; 31};
32 32
33struct ext3_xattr_ibody_header { 33struct ext4_xattr_ibody_header {
34 __le32 h_magic; /* magic number for identification */ 34 __le32 h_magic; /* magic number for identification */
35}; 35};
36 36
37struct ext3_xattr_entry { 37struct ext4_xattr_entry {
38 __u8 e_name_len; /* length of name */ 38 __u8 e_name_len; /* length of name */
39 __u8 e_name_index; /* attribute name index */ 39 __u8 e_name_index; /* attribute name index */
40 __le16 e_value_offs; /* offset in disk block of value */ 40 __le16 e_value_offs; /* offset in disk block of value */
@@ -44,100 +44,100 @@ struct ext3_xattr_entry {
44 char e_name[0]; /* attribute name */ 44 char e_name[0]; /* attribute name */
45}; 45};
46 46
47#define EXT3_XATTR_PAD_BITS 2 47#define EXT4_XATTR_PAD_BITS 2
48#define EXT3_XATTR_PAD (1<<EXT3_XATTR_PAD_BITS) 48#define EXT4_XATTR_PAD (1<<EXT4_XATTR_PAD_BITS)
49#define EXT3_XATTR_ROUND (EXT3_XATTR_PAD-1) 49#define EXT4_XATTR_ROUND (EXT4_XATTR_PAD-1)
50#define EXT3_XATTR_LEN(name_len) \ 50#define EXT4_XATTR_LEN(name_len) \
51 (((name_len) + EXT3_XATTR_ROUND + \ 51 (((name_len) + EXT4_XATTR_ROUND + \
52 sizeof(struct ext3_xattr_entry)) & ~EXT3_XATTR_ROUND) 52 sizeof(struct ext4_xattr_entry)) & ~EXT4_XATTR_ROUND)
53#define EXT3_XATTR_NEXT(entry) \ 53#define EXT4_XATTR_NEXT(entry) \
54 ( (struct ext3_xattr_entry *)( \ 54 ( (struct ext4_xattr_entry *)( \
55 (char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) ) 55 (char *)(entry) + EXT4_XATTR_LEN((entry)->e_name_len)) )
56#define EXT3_XATTR_SIZE(size) \ 56#define EXT4_XATTR_SIZE(size) \
57 (((size) + EXT3_XATTR_ROUND) & ~EXT3_XATTR_ROUND) 57 (((size) + EXT4_XATTR_ROUND) & ~EXT4_XATTR_ROUND)
58 58
59# ifdef CONFIG_EXT3_FS_XATTR 59# ifdef CONFIG_EXT4DEV_FS_XATTR
60 60
61extern struct xattr_handler ext3_xattr_user_handler; 61extern struct xattr_handler ext4_xattr_user_handler;
62extern struct xattr_handler ext3_xattr_trusted_handler; 62extern struct xattr_handler ext4_xattr_trusted_handler;
63extern struct xattr_handler ext3_xattr_acl_access_handler; 63extern struct xattr_handler ext4_xattr_acl_access_handler;
64extern struct xattr_handler ext3_xattr_acl_default_handler; 64extern struct xattr_handler ext4_xattr_acl_default_handler;
65extern struct xattr_handler ext3_xattr_security_handler; 65extern struct xattr_handler ext4_xattr_security_handler;
66 66
67extern ssize_t ext3_listxattr(struct dentry *, char *, size_t); 67extern ssize_t ext4_listxattr(struct dentry *, char *, size_t);
68 68
69extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t); 69extern int ext4_xattr_get(struct inode *, int, const char *, void *, size_t);
70extern int ext3_xattr_list(struct inode *, char *, size_t); 70extern int ext4_xattr_list(struct inode *, char *, size_t);
71extern int ext3_xattr_set(struct inode *, int, const char *, const void *, size_t, int); 71extern int ext4_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
72extern int ext3_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int); 72extern int ext4_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int);
73 73
74extern void ext3_xattr_delete_inode(handle_t *, struct inode *); 74extern void ext4_xattr_delete_inode(handle_t *, struct inode *);
75extern void ext3_xattr_put_super(struct super_block *); 75extern void ext4_xattr_put_super(struct super_block *);
76 76
77extern int init_ext3_xattr(void); 77extern int init_ext4_xattr(void);
78extern void exit_ext3_xattr(void); 78extern void exit_ext4_xattr(void);
79 79
80extern struct xattr_handler *ext3_xattr_handlers[]; 80extern struct xattr_handler *ext4_xattr_handlers[];
81 81
82# else /* CONFIG_EXT3_FS_XATTR */ 82# else /* CONFIG_EXT4DEV_FS_XATTR */
83 83
84static inline int 84static inline int
85ext3_xattr_get(struct inode *inode, int name_index, const char *name, 85ext4_xattr_get(struct inode *inode, int name_index, const char *name,
86 void *buffer, size_t size, int flags) 86 void *buffer, size_t size, int flags)
87{ 87{
88 return -EOPNOTSUPP; 88 return -EOPNOTSUPP;
89} 89}
90 90
91static inline int 91static inline int
92ext3_xattr_list(struct inode *inode, void *buffer, size_t size) 92ext4_xattr_list(struct inode *inode, void *buffer, size_t size)
93{ 93{
94 return -EOPNOTSUPP; 94 return -EOPNOTSUPP;
95} 95}
96 96
97static inline int 97static inline int
98ext3_xattr_set(struct inode *inode, int name_index, const char *name, 98ext4_xattr_set(struct inode *inode, int name_index, const char *name,
99 const void *value, size_t size, int flags) 99 const void *value, size_t size, int flags)
100{ 100{
101 return -EOPNOTSUPP; 101 return -EOPNOTSUPP;
102} 102}
103 103
104static inline int 104static inline int
105ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index, 105ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
106 const char *name, const void *value, size_t size, int flags) 106 const char *name, const void *value, size_t size, int flags)
107{ 107{
108 return -EOPNOTSUPP; 108 return -EOPNOTSUPP;
109} 109}
110 110
111static inline void 111static inline void
112ext3_xattr_delete_inode(handle_t *handle, struct inode *inode) 112ext4_xattr_delete_inode(handle_t *handle, struct inode *inode)
113{ 113{
114} 114}
115 115
116static inline void 116static inline void
117ext3_xattr_put_super(struct super_block *sb) 117ext4_xattr_put_super(struct super_block *sb)
118{ 118{
119} 119}
120 120
121static inline int 121static inline int
122init_ext3_xattr(void) 122init_ext4_xattr(void)
123{ 123{
124 return 0; 124 return 0;
125} 125}
126 126
127static inline void 127static inline void
128exit_ext3_xattr(void) 128exit_ext4_xattr(void)
129{ 129{
130} 130}
131 131
132#define ext3_xattr_handlers NULL 132#define ext4_xattr_handlers NULL
133 133
134# endif /* CONFIG_EXT3_FS_XATTR */ 134# endif /* CONFIG_EXT4DEV_FS_XATTR */
135 135
136#ifdef CONFIG_EXT3_FS_SECURITY 136#ifdef CONFIG_EXT4DEV_FS_SECURITY
137extern int ext3_init_security(handle_t *handle, struct inode *inode, 137extern int ext4_init_security(handle_t *handle, struct inode *inode,
138 struct inode *dir); 138 struct inode *dir);
139#else 139#else
140static inline int ext3_init_security(handle_t *handle, struct inode *inode, 140static inline int ext4_init_security(handle_t *handle, struct inode *inode,
141 struct inode *dir) 141 struct inode *dir)
142{ 142{
143 return 0; 143 return 0;
diff --git a/fs/ext4/xattr_security.c b/fs/ext4/xattr_security.c
index b9c40c15647..d84b1dabeb1 100644
--- a/fs/ext4/xattr_security.c
+++ b/fs/ext4/xattr_security.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/xattr_security.c 2 * linux/fs/ext4/xattr_security.c
3 * Handler for storing security labels as extended attributes. 3 * Handler for storing security labels as extended attributes.
4 */ 4 */
5 5
@@ -7,13 +7,13 @@
7#include <linux/string.h> 7#include <linux/string.h>
8#include <linux/fs.h> 8#include <linux/fs.h>
9#include <linux/smp_lock.h> 9#include <linux/smp_lock.h>
10#include <linux/ext3_jbd.h> 10#include <linux/ext4_jbd.h>
11#include <linux/ext3_fs.h> 11#include <linux/ext4_fs.h>
12#include <linux/security.h> 12#include <linux/security.h>
13#include "xattr.h" 13#include "xattr.h"
14 14
15static size_t 15static size_t
16ext3_xattr_security_list(struct inode *inode, char *list, size_t list_size, 16ext4_xattr_security_list(struct inode *inode, char *list, size_t list_size,
17 const char *name, size_t name_len) 17 const char *name, size_t name_len)
18{ 18{
19 const size_t prefix_len = sizeof(XATTR_SECURITY_PREFIX)-1; 19 const size_t prefix_len = sizeof(XATTR_SECURITY_PREFIX)-1;
@@ -29,27 +29,27 @@ ext3_xattr_security_list(struct inode *inode, char *list, size_t list_size,
29} 29}
30 30
31static int 31static int
32ext3_xattr_security_get(struct inode *inode, const char *name, 32ext4_xattr_security_get(struct inode *inode, const char *name,
33 void *buffer, size_t size) 33 void *buffer, size_t size)
34{ 34{
35 if (strcmp(name, "") == 0) 35 if (strcmp(name, "") == 0)
36 return -EINVAL; 36 return -EINVAL;
37 return ext3_xattr_get(inode, EXT3_XATTR_INDEX_SECURITY, name, 37 return ext4_xattr_get(inode, EXT4_XATTR_INDEX_SECURITY, name,
38 buffer, size); 38 buffer, size);
39} 39}
40 40
41static int 41static int
42ext3_xattr_security_set(struct inode *inode, const char *name, 42ext4_xattr_security_set(struct inode *inode, const char *name,
43 const void *value, size_t size, int flags) 43 const void *value, size_t size, int flags)
44{ 44{
45 if (strcmp(name, "") == 0) 45 if (strcmp(name, "") == 0)
46 return -EINVAL; 46 return -EINVAL;
47 return ext3_xattr_set(inode, EXT3_XATTR_INDEX_SECURITY, name, 47 return ext4_xattr_set(inode, EXT4_XATTR_INDEX_SECURITY, name,
48 value, size, flags); 48 value, size, flags);
49} 49}
50 50
51int 51int
52ext3_init_security(handle_t *handle, struct inode *inode, struct inode *dir) 52ext4_init_security(handle_t *handle, struct inode *inode, struct inode *dir)
53{ 53{
54 int err; 54 int err;
55 size_t len; 55 size_t len;
@@ -62,16 +62,16 @@ ext3_init_security(handle_t *handle, struct inode *inode, struct inode *dir)
62 return 0; 62 return 0;
63 return err; 63 return err;
64 } 64 }
65 err = ext3_xattr_set_handle(handle, inode, EXT3_XATTR_INDEX_SECURITY, 65 err = ext4_xattr_set_handle(handle, inode, EXT4_XATTR_INDEX_SECURITY,
66 name, value, len, 0); 66 name, value, len, 0);
67 kfree(name); 67 kfree(name);
68 kfree(value); 68 kfree(value);
69 return err; 69 return err;
70} 70}
71 71
72struct xattr_handler ext3_xattr_security_handler = { 72struct xattr_handler ext4_xattr_security_handler = {
73 .prefix = XATTR_SECURITY_PREFIX, 73 .prefix = XATTR_SECURITY_PREFIX,
74 .list = ext3_xattr_security_list, 74 .list = ext4_xattr_security_list,
75 .get = ext3_xattr_security_get, 75 .get = ext4_xattr_security_get,
76 .set = ext3_xattr_security_set, 76 .set = ext4_xattr_security_set,
77}; 77};
diff --git a/fs/ext4/xattr_trusted.c b/fs/ext4/xattr_trusted.c
index 86d91f1186d..11bd58c95a6 100644
--- a/fs/ext4/xattr_trusted.c
+++ b/fs/ext4/xattr_trusted.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/xattr_trusted.c 2 * linux/fs/ext4/xattr_trusted.c
3 * Handler for trusted extended attributes. 3 * Handler for trusted extended attributes.
4 * 4 *
5 * Copyright (C) 2003 by Andreas Gruenbacher, <a.gruenbacher@computer.org> 5 * Copyright (C) 2003 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
@@ -10,14 +10,14 @@
10#include <linux/capability.h> 10#include <linux/capability.h>
11#include <linux/fs.h> 11#include <linux/fs.h>
12#include <linux/smp_lock.h> 12#include <linux/smp_lock.h>
13#include <linux/ext3_jbd.h> 13#include <linux/ext4_jbd.h>
14#include <linux/ext3_fs.h> 14#include <linux/ext4_fs.h>
15#include "xattr.h" 15#include "xattr.h"
16 16
17#define XATTR_TRUSTED_PREFIX "trusted." 17#define XATTR_TRUSTED_PREFIX "trusted."
18 18
19static size_t 19static size_t
20ext3_xattr_trusted_list(struct inode *inode, char *list, size_t list_size, 20ext4_xattr_trusted_list(struct inode *inode, char *list, size_t list_size,
21 const char *name, size_t name_len) 21 const char *name, size_t name_len)
22{ 22{
23 const size_t prefix_len = sizeof(XATTR_TRUSTED_PREFIX)-1; 23 const size_t prefix_len = sizeof(XATTR_TRUSTED_PREFIX)-1;
@@ -35,28 +35,28 @@ ext3_xattr_trusted_list(struct inode *inode, char *list, size_t list_size,
35} 35}
36 36
37static int 37static int
38ext3_xattr_trusted_get(struct inode *inode, const char *name, 38ext4_xattr_trusted_get(struct inode *inode, const char *name,
39 void *buffer, size_t size) 39 void *buffer, size_t size)
40{ 40{
41 if (strcmp(name, "") == 0) 41 if (strcmp(name, "") == 0)
42 return -EINVAL; 42 return -EINVAL;
43 return ext3_xattr_get(inode, EXT3_XATTR_INDEX_TRUSTED, name, 43 return ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED, name,
44 buffer, size); 44 buffer, size);
45} 45}
46 46
47static int 47static int
48ext3_xattr_trusted_set(struct inode *inode, const char *name, 48ext4_xattr_trusted_set(struct inode *inode, const char *name,
49 const void *value, size_t size, int flags) 49 const void *value, size_t size, int flags)
50{ 50{
51 if (strcmp(name, "") == 0) 51 if (strcmp(name, "") == 0)
52 return -EINVAL; 52 return -EINVAL;
53 return ext3_xattr_set(inode, EXT3_XATTR_INDEX_TRUSTED, name, 53 return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED, name,
54 value, size, flags); 54 value, size, flags);
55} 55}
56 56
57struct xattr_handler ext3_xattr_trusted_handler = { 57struct xattr_handler ext4_xattr_trusted_handler = {
58 .prefix = XATTR_TRUSTED_PREFIX, 58 .prefix = XATTR_TRUSTED_PREFIX,
59 .list = ext3_xattr_trusted_list, 59 .list = ext4_xattr_trusted_list,
60 .get = ext3_xattr_trusted_get, 60 .get = ext4_xattr_trusted_get,
61 .set = ext3_xattr_trusted_set, 61 .set = ext4_xattr_trusted_set,
62}; 62};
diff --git a/fs/ext4/xattr_user.c b/fs/ext4/xattr_user.c
index a85a0a17c4f..9c5a665e083 100644
--- a/fs/ext4/xattr_user.c
+++ b/fs/ext4/xattr_user.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/fs/ext3/xattr_user.c 2 * linux/fs/ext4/xattr_user.c
3 * Handler for extended user attributes. 3 * Handler for extended user attributes.
4 * 4 *
5 * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org> 5 * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
@@ -9,14 +9,14 @@
9#include <linux/string.h> 9#include <linux/string.h>
10#include <linux/fs.h> 10#include <linux/fs.h>
11#include <linux/smp_lock.h> 11#include <linux/smp_lock.h>
12#include <linux/ext3_jbd.h> 12#include <linux/ext4_jbd.h>
13#include <linux/ext3_fs.h> 13#include <linux/ext4_fs.h>
14#include "xattr.h" 14#include "xattr.h"
15 15
16#define XATTR_USER_PREFIX "user." 16#define XATTR_USER_PREFIX "user."
17 17
18static size_t 18static size_t
19ext3_xattr_user_list(struct inode *inode, char *list, size_t list_size, 19ext4_xattr_user_list(struct inode *inode, char *list, size_t list_size,
20 const char *name, size_t name_len) 20 const char *name, size_t name_len)
21{ 21{
22 const size_t prefix_len = sizeof(XATTR_USER_PREFIX)-1; 22 const size_t prefix_len = sizeof(XATTR_USER_PREFIX)-1;
@@ -34,31 +34,31 @@ ext3_xattr_user_list(struct inode *inode, char *list, size_t list_size,
34} 34}
35 35
36static int 36static int
37ext3_xattr_user_get(struct inode *inode, const char *name, 37ext4_xattr_user_get(struct inode *inode, const char *name,
38 void *buffer, size_t size) 38 void *buffer, size_t size)
39{ 39{
40 if (strcmp(name, "") == 0) 40 if (strcmp(name, "") == 0)
41 return -EINVAL; 41 return -EINVAL;
42 if (!test_opt(inode->i_sb, XATTR_USER)) 42 if (!test_opt(inode->i_sb, XATTR_USER))
43 return -EOPNOTSUPP; 43 return -EOPNOTSUPP;
44 return ext3_xattr_get(inode, EXT3_XATTR_INDEX_USER, name, buffer, size); 44 return ext4_xattr_get(inode, EXT4_XATTR_INDEX_USER, name, buffer, size);
45} 45}
46 46
47static int 47static int
48ext3_xattr_user_set(struct inode *inode, const char *name, 48ext4_xattr_user_set(struct inode *inode, const char *name,
49 const void *value, size_t size, int flags) 49 const void *value, size_t size, int flags)
50{ 50{
51 if (strcmp(name, "") == 0) 51 if (strcmp(name, "") == 0)
52 return -EINVAL; 52 return -EINVAL;
53 if (!test_opt(inode->i_sb, XATTR_USER)) 53 if (!test_opt(inode->i_sb, XATTR_USER))
54 return -EOPNOTSUPP; 54 return -EOPNOTSUPP;
55 return ext3_xattr_set(inode, EXT3_XATTR_INDEX_USER, name, 55 return ext4_xattr_set(inode, EXT4_XATTR_INDEX_USER, name,
56 value, size, flags); 56 value, size, flags);
57} 57}
58 58
59struct xattr_handler ext3_xattr_user_handler = { 59struct xattr_handler ext4_xattr_user_handler = {
60 .prefix = XATTR_USER_PREFIX, 60 .prefix = XATTR_USER_PREFIX,
61 .list = ext3_xattr_user_list, 61 .list = ext4_xattr_user_list,
62 .get = ext3_xattr_user_get, 62 .get = ext4_xattr_user_get,
63 .set = ext3_xattr_user_set, 63 .set = ext4_xattr_user_set,
64}; 64};
diff --git a/include/linux/ext4_fs.h b/include/linux/ext4_fs.h
index 11cca1bdc0c..f582cd762ca 100644
--- a/include/linux/ext4_fs.h
+++ b/include/linux/ext4_fs.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/include/linux/ext3_fs.h 2 * linux/include/linux/ext4_fs.h
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -13,8 +13,8 @@
13 * Copyright (C) 1991, 1992 Linus Torvalds 13 * Copyright (C) 1991, 1992 Linus Torvalds
14 */ 14 */
15 15
16#ifndef _LINUX_EXT3_FS_H 16#ifndef _LINUX_EXT4_FS_H
17#define _LINUX_EXT3_FS_H 17#define _LINUX_EXT4_FS_H
18 18
19#include <linux/types.h> 19#include <linux/types.h>
20#include <linux/magic.h> 20#include <linux/magic.h>
@@ -24,102 +24,102 @@
24 */ 24 */
25 25
26/* 26/*
27 * Define EXT3FS_DEBUG to produce debug messages 27 * Define EXT4FS_DEBUG to produce debug messages
28 */ 28 */
29#undef EXT3FS_DEBUG 29#undef EXT4FS_DEBUG
30 30
31/* 31/*
32 * Define EXT3_RESERVATION to reserve data blocks for expanding files 32 * Define EXT4_RESERVATION to reserve data blocks for expanding files
33 */ 33 */
34#define EXT3_DEFAULT_RESERVE_BLOCKS 8 34#define EXT4_DEFAULT_RESERVE_BLOCKS 8
35/*max window size: 1024(direct blocks) + 3([t,d]indirect blocks) */ 35/*max window size: 1024(direct blocks) + 3([t,d]indirect blocks) */
36#define EXT3_MAX_RESERVE_BLOCKS 1027 36#define EXT4_MAX_RESERVE_BLOCKS 1027
37#define EXT3_RESERVE_WINDOW_NOT_ALLOCATED 0 37#define EXT4_RESERVE_WINDOW_NOT_ALLOCATED 0
38/* 38/*
39 * Always enable hashed directories 39 * Always enable hashed directories
40 */ 40 */
41#define CONFIG_EXT3_INDEX 41#define CONFIG_EXT4_INDEX
42 42
43/* 43/*
44 * Debug code 44 * Debug code
45 */ 45 */
46#ifdef EXT3FS_DEBUG 46#ifdef EXT4FS_DEBUG
47#define ext3_debug(f, a...) \ 47#define ext4_debug(f, a...) \
48 do { \ 48 do { \
49 printk (KERN_DEBUG "EXT3-fs DEBUG (%s, %d): %s:", \ 49 printk (KERN_DEBUG "EXT4-fs DEBUG (%s, %d): %s:", \
50 __FILE__, __LINE__, __FUNCTION__); \ 50 __FILE__, __LINE__, __FUNCTION__); \
51 printk (KERN_DEBUG f, ## a); \ 51 printk (KERN_DEBUG f, ## a); \
52 } while (0) 52 } while (0)
53#else 53#else
54#define ext3_debug(f, a...) do {} while (0) 54#define ext4_debug(f, a...) do {} while (0)
55#endif 55#endif
56 56
57/* 57/*
58 * Special inodes numbers 58 * Special inodes numbers
59 */ 59 */
60#define EXT3_BAD_INO 1 /* Bad blocks inode */ 60#define EXT4_BAD_INO 1 /* Bad blocks inode */
61#define EXT3_ROOT_INO 2 /* Root inode */ 61#define EXT4_ROOT_INO 2 /* Root inode */
62#define EXT3_BOOT_LOADER_INO 5 /* Boot loader inode */ 62#define EXT4_BOOT_LOADER_INO 5 /* Boot loader inode */
63#define EXT3_UNDEL_DIR_INO 6 /* Undelete directory inode */ 63#define EXT4_UNDEL_DIR_INO 6 /* Undelete directory inode */
64#define EXT3_RESIZE_INO 7 /* Reserved group descriptors inode */ 64#define EXT4_RESIZE_INO 7 /* Reserved group descriptors inode */
65#define EXT3_JOURNAL_INO 8 /* Journal inode */ 65#define EXT4_JOURNAL_INO 8 /* Journal inode */
66 66
67/* First non-reserved inode for old ext3 filesystems */ 67/* First non-reserved inode for old ext4 filesystems */
68#define EXT3_GOOD_OLD_FIRST_INO 11 68#define EXT4_GOOD_OLD_FIRST_INO 11
69 69
70/* 70/*
71 * Maximal count of links to a file 71 * Maximal count of links to a file
72 */ 72 */
73#define EXT3_LINK_MAX 32000 73#define EXT4_LINK_MAX 32000
74 74
75/* 75/*
76 * Macro-instructions used to manage several block sizes 76 * Macro-instructions used to manage several block sizes
77 */ 77 */
78#define EXT3_MIN_BLOCK_SIZE 1024 78#define EXT4_MIN_BLOCK_SIZE 1024
79#define EXT3_MAX_BLOCK_SIZE 4096 79#define EXT4_MAX_BLOCK_SIZE 4096
80#define EXT3_MIN_BLOCK_LOG_SIZE 10 80#define EXT4_MIN_BLOCK_LOG_SIZE 10
81#ifdef __KERNEL__ 81#ifdef __KERNEL__
82# define EXT3_BLOCK_SIZE(s) ((s)->s_blocksize) 82# define EXT4_BLOCK_SIZE(s) ((s)->s_blocksize)
83#else 83#else
84# define EXT3_BLOCK_SIZE(s) (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size) 84# define EXT4_BLOCK_SIZE(s) (EXT4_MIN_BLOCK_SIZE << (s)->s_log_block_size)
85#endif 85#endif
86#define EXT3_ADDR_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (__u32)) 86#define EXT4_ADDR_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / sizeof (__u32))
87#ifdef __KERNEL__ 87#ifdef __KERNEL__
88# define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits) 88# define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
89#else 89#else
90# define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10) 90# define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
91#endif 91#endif
92#ifdef __KERNEL__ 92#ifdef __KERNEL__
93#define EXT3_ADDR_PER_BLOCK_BITS(s) (EXT3_SB(s)->s_addr_per_block_bits) 93#define EXT4_ADDR_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_addr_per_block_bits)
94#define EXT3_INODE_SIZE(s) (EXT3_SB(s)->s_inode_size) 94#define EXT4_INODE_SIZE(s) (EXT4_SB(s)->s_inode_size)
95#define EXT3_FIRST_INO(s) (EXT3_SB(s)->s_first_ino) 95#define EXT4_FIRST_INO(s) (EXT4_SB(s)->s_first_ino)
96#else 96#else
97#define EXT3_INODE_SIZE(s) (((s)->s_rev_level == EXT3_GOOD_OLD_REV) ? \ 97#define EXT4_INODE_SIZE(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \
98 EXT3_GOOD_OLD_INODE_SIZE : \ 98 EXT4_GOOD_OLD_INODE_SIZE : \
99 (s)->s_inode_size) 99 (s)->s_inode_size)
100#define EXT3_FIRST_INO(s) (((s)->s_rev_level == EXT3_GOOD_OLD_REV) ? \ 100#define EXT4_FIRST_INO(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \
101 EXT3_GOOD_OLD_FIRST_INO : \ 101 EXT4_GOOD_OLD_FIRST_INO : \
102 (s)->s_first_ino) 102 (s)->s_first_ino)
103#endif 103#endif
104 104
105/* 105/*
106 * Macro-instructions used to manage fragments 106 * Macro-instructions used to manage fragments
107 */ 107 */
108#define EXT3_MIN_FRAG_SIZE 1024 108#define EXT4_MIN_FRAG_SIZE 1024
109#define EXT3_MAX_FRAG_SIZE 4096 109#define EXT4_MAX_FRAG_SIZE 4096
110#define EXT3_MIN_FRAG_LOG_SIZE 10 110#define EXT4_MIN_FRAG_LOG_SIZE 10
111#ifdef __KERNEL__ 111#ifdef __KERNEL__
112# define EXT3_FRAG_SIZE(s) (EXT3_SB(s)->s_frag_size) 112# define EXT4_FRAG_SIZE(s) (EXT4_SB(s)->s_frag_size)
113# define EXT3_FRAGS_PER_BLOCK(s) (EXT3_SB(s)->s_frags_per_block) 113# define EXT4_FRAGS_PER_BLOCK(s) (EXT4_SB(s)->s_frags_per_block)
114#else 114#else
115# define EXT3_FRAG_SIZE(s) (EXT3_MIN_FRAG_SIZE << (s)->s_log_frag_size) 115# define EXT4_FRAG_SIZE(s) (EXT4_MIN_FRAG_SIZE << (s)->s_log_frag_size)
116# define EXT3_FRAGS_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / EXT3_FRAG_SIZE(s)) 116# define EXT4_FRAGS_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / EXT4_FRAG_SIZE(s))
117#endif 117#endif
118 118
119/* 119/*
120 * Structure of a blocks group descriptor 120 * Structure of a blocks group descriptor
121 */ 121 */
122struct ext3_group_desc 122struct ext4_group_desc
123{ 123{
124 __le32 bg_block_bitmap; /* Blocks bitmap block */ 124 __le32 bg_block_bitmap; /* Blocks bitmap block */
125 __le32 bg_inode_bitmap; /* Inodes bitmap block */ 125 __le32 bg_inode_bitmap; /* Inodes bitmap block */
@@ -135,62 +135,62 @@ struct ext3_group_desc
135 * Macro-instructions used to manage group descriptors 135 * Macro-instructions used to manage group descriptors
136 */ 136 */
137#ifdef __KERNEL__ 137#ifdef __KERNEL__
138# define EXT3_BLOCKS_PER_GROUP(s) (EXT3_SB(s)->s_blocks_per_group) 138# define EXT4_BLOCKS_PER_GROUP(s) (EXT4_SB(s)->s_blocks_per_group)
139# define EXT3_DESC_PER_BLOCK(s) (EXT3_SB(s)->s_desc_per_block) 139# define EXT4_DESC_PER_BLOCK(s) (EXT4_SB(s)->s_desc_per_block)
140# define EXT3_INODES_PER_GROUP(s) (EXT3_SB(s)->s_inodes_per_group) 140# define EXT4_INODES_PER_GROUP(s) (EXT4_SB(s)->s_inodes_per_group)
141# define EXT3_DESC_PER_BLOCK_BITS(s) (EXT3_SB(s)->s_desc_per_block_bits) 141# define EXT4_DESC_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_desc_per_block_bits)
142#else 142#else
143# define EXT3_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group) 143# define EXT4_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)
144# define EXT3_DESC_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_group_desc)) 144# define EXT4_DESC_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / sizeof (struct ext4_group_desc))
145# define EXT3_INODES_PER_GROUP(s) ((s)->s_inodes_per_group) 145# define EXT4_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)
146#endif 146#endif
147 147
148/* 148/*
149 * Constants relative to the data blocks 149 * Constants relative to the data blocks
150 */ 150 */
151#define EXT3_NDIR_BLOCKS 12 151#define EXT4_NDIR_BLOCKS 12
152#define EXT3_IND_BLOCK EXT3_NDIR_BLOCKS 152#define EXT4_IND_BLOCK EXT4_NDIR_BLOCKS
153#define EXT3_DIND_BLOCK (EXT3_IND_BLOCK + 1) 153#define EXT4_DIND_BLOCK (EXT4_IND_BLOCK + 1)
154#define EXT3_TIND_BLOCK (EXT3_DIND_BLOCK + 1) 154#define EXT4_TIND_BLOCK (EXT4_DIND_BLOCK + 1)
155#define EXT3_N_BLOCKS (EXT3_TIND_BLOCK + 1) 155#define EXT4_N_BLOCKS (EXT4_TIND_BLOCK + 1)
156 156
157/* 157/*
158 * Inode flags 158 * Inode flags
159 */ 159 */
160#define EXT3_SECRM_FL 0x00000001 /* Secure deletion */ 160#define EXT4_SECRM_FL 0x00000001 /* Secure deletion */
161#define EXT3_UNRM_FL 0x00000002 /* Undelete */ 161#define EXT4_UNRM_FL 0x00000002 /* Undelete */
162#define EXT3_COMPR_FL 0x00000004 /* Compress file */ 162#define EXT4_COMPR_FL 0x00000004 /* Compress file */
163#define EXT3_SYNC_FL 0x00000008 /* Synchronous updates */ 163#define EXT4_SYNC_FL 0x00000008 /* Synchronous updates */
164#define EXT3_IMMUTABLE_FL 0x00000010 /* Immutable file */ 164#define EXT4_IMMUTABLE_FL 0x00000010 /* Immutable file */
165#define EXT3_APPEND_FL 0x00000020 /* writes to file may only append */ 165#define EXT4_APPEND_FL 0x00000020 /* writes to file may only append */
166#define EXT3_NODUMP_FL 0x00000040 /* do not dump file */ 166#define EXT4_NODUMP_FL 0x00000040 /* do not dump file */
167#define EXT3_NOATIME_FL 0x00000080 /* do not update atime */ 167#define EXT4_NOATIME_FL 0x00000080 /* do not update atime */
168/* Reserved for compression usage... */ 168/* Reserved for compression usage... */
169#define EXT3_DIRTY_FL 0x00000100 169#define EXT4_DIRTY_FL 0x00000100
170#define EXT3_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ 170#define EXT4_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
171#define EXT3_NOCOMPR_FL 0x00000400 /* Don't compress */ 171#define EXT4_NOCOMPR_FL 0x00000400 /* Don't compress */
172#define EXT3_ECOMPR_FL 0x00000800 /* Compression error */ 172#define EXT4_ECOMPR_FL 0x00000800 /* Compression error */
173/* End compression flags --- maybe not all used */ 173/* End compression flags --- maybe not all used */
174#define EXT3_INDEX_FL 0x00001000 /* hash-indexed directory */ 174#define EXT4_INDEX_FL 0x00001000 /* hash-indexed directory */
175#define EXT3_IMAGIC_FL 0x00002000 /* AFS directory */ 175#define EXT4_IMAGIC_FL 0x00002000 /* AFS directory */
176#define EXT3_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */ 176#define EXT4_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */
177#define EXT3_NOTAIL_FL 0x00008000 /* file tail should not be merged */ 177#define EXT4_NOTAIL_FL 0x00008000 /* file tail should not be merged */
178#define EXT3_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ 178#define EXT4_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
179#define EXT3_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ 179#define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
180#define EXT3_RESERVED_FL 0x80000000 /* reserved for ext3 lib */ 180#define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
181 181
182#define EXT3_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ 182#define EXT4_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
183#define EXT3_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */ 183#define EXT4_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
184 184
185/* 185/*
186 * Inode dynamic state flags 186 * Inode dynamic state flags
187 */ 187 */
188#define EXT3_STATE_JDATA 0x00000001 /* journaled data exists */ 188#define EXT4_STATE_JDATA 0x00000001 /* journaled data exists */
189#define EXT3_STATE_NEW 0x00000002 /* inode is newly created */ 189#define EXT4_STATE_NEW 0x00000002 /* inode is newly created */
190#define EXT3_STATE_XATTR 0x00000004 /* has in-inode xattrs */ 190#define EXT4_STATE_XATTR 0x00000004 /* has in-inode xattrs */
191 191
192/* Used to pass group descriptor data when online resize is done */ 192/* Used to pass group descriptor data when online resize is done */
193struct ext3_new_group_input { 193struct ext4_new_group_input {
194 __u32 group; /* Group number for this data */ 194 __u32 group; /* Group number for this data */
195 __u32 block_bitmap; /* Absolute block number of block bitmap */ 195 __u32 block_bitmap; /* Absolute block number of block bitmap */
196 __u32 inode_bitmap; /* Absolute block number of inode bitmap */ 196 __u32 inode_bitmap; /* Absolute block number of inode bitmap */
@@ -200,8 +200,8 @@ struct ext3_new_group_input {
200 __u16 unused; 200 __u16 unused;
201}; 201};
202 202
203/* The struct ext3_new_group_input in kernel space, with free_blocks_count */ 203/* The struct ext4_new_group_input in kernel space, with free_blocks_count */
204struct ext3_new_group_data { 204struct ext4_new_group_data {
205 __u32 group; 205 __u32 group;
206 __u32 block_bitmap; 206 __u32 block_bitmap;
207 __u32 inode_bitmap; 207 __u32 inode_bitmap;
@@ -216,41 +216,41 @@ struct ext3_new_group_data {
216/* 216/*
217 * ioctl commands 217 * ioctl commands
218 */ 218 */
219#define EXT3_IOC_GETFLAGS FS_IOC_GETFLAGS 219#define EXT4_IOC_GETFLAGS FS_IOC_GETFLAGS
220#define EXT3_IOC_SETFLAGS FS_IOC_SETFLAGS 220#define EXT4_IOC_SETFLAGS FS_IOC_SETFLAGS
221#define EXT3_IOC_GETVERSION _IOR('f', 3, long) 221#define EXT4_IOC_GETVERSION _IOR('f', 3, long)
222#define EXT3_IOC_SETVERSION _IOW('f', 4, long) 222#define EXT4_IOC_SETVERSION _IOW('f', 4, long)
223#define EXT3_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long) 223#define EXT4_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long)
224#define EXT3_IOC_GROUP_ADD _IOW('f', 8,struct ext3_new_group_input) 224#define EXT4_IOC_GROUP_ADD _IOW('f', 8,struct ext4_new_group_input)
225#define EXT3_IOC_GETVERSION_OLD FS_IOC_GETVERSION 225#define EXT4_IOC_GETVERSION_OLD FS_IOC_GETVERSION
226#define EXT3_IOC_SETVERSION_OLD FS_IOC_SETVERSION 226#define EXT4_IOC_SETVERSION_OLD FS_IOC_SETVERSION
227#ifdef CONFIG_JBD_DEBUG 227#ifdef CONFIG_JBD_DEBUG
228#define EXT3_IOC_WAIT_FOR_READONLY _IOR('f', 99, long) 228#define EXT4_IOC_WAIT_FOR_READONLY _IOR('f', 99, long)
229#endif 229#endif
230#define EXT3_IOC_GETRSVSZ _IOR('f', 5, long) 230#define EXT4_IOC_GETRSVSZ _IOR('f', 5, long)
231#define EXT3_IOC_SETRSVSZ _IOW('f', 6, long) 231#define EXT4_IOC_SETRSVSZ _IOW('f', 6, long)
232 232
233/* 233/*
234 * ioctl commands in 32 bit emulation 234 * ioctl commands in 32 bit emulation
235 */ 235 */
236#define EXT3_IOC32_GETFLAGS FS_IOC32_GETFLAGS 236#define EXT4_IOC32_GETFLAGS FS_IOC32_GETFLAGS
237#define EXT3_IOC32_SETFLAGS FS_IOC32_SETFLAGS 237#define EXT4_IOC32_SETFLAGS FS_IOC32_SETFLAGS
238#define EXT3_IOC32_GETVERSION _IOR('f', 3, int) 238#define EXT4_IOC32_GETVERSION _IOR('f', 3, int)
239#define EXT3_IOC32_SETVERSION _IOW('f', 4, int) 239#define EXT4_IOC32_SETVERSION _IOW('f', 4, int)
240#define EXT3_IOC32_GETRSVSZ _IOR('f', 5, int) 240#define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int)
241#define EXT3_IOC32_SETRSVSZ _IOW('f', 6, int) 241#define EXT4_IOC32_SETRSVSZ _IOW('f', 6, int)
242#define EXT3_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int) 242#define EXT4_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int)
243#ifdef CONFIG_JBD_DEBUG 243#ifdef CONFIG_JBD_DEBUG
244#define EXT3_IOC32_WAIT_FOR_READONLY _IOR('f', 99, int) 244#define EXT4_IOC32_WAIT_FOR_READONLY _IOR('f', 99, int)
245#endif 245#endif
246#define EXT3_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION 246#define EXT4_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION
247#define EXT3_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION 247#define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION
248 248
249 249
250/* 250/*
251 * Mount options 251 * Mount options
252 */ 252 */
253struct ext3_mount_options { 253struct ext4_mount_options {
254 unsigned long s_mount_opt; 254 unsigned long s_mount_opt;
255 uid_t s_resuid; 255 uid_t s_resuid;
256 gid_t s_resgid; 256 gid_t s_resgid;
@@ -264,7 +264,7 @@ struct ext3_mount_options {
264/* 264/*
265 * Structure of an inode on the disk 265 * Structure of an inode on the disk
266 */ 266 */
267struct ext3_inode { 267struct ext4_inode {
268 __le16 i_mode; /* File mode */ 268 __le16 i_mode; /* File mode */
269 __le16 i_uid; /* Low 16 bits of Owner Uid */ 269 __le16 i_uid; /* Low 16 bits of Owner Uid */
270 __le32 i_size; /* Size in bytes */ 270 __le32 i_size; /* Size in bytes */
@@ -287,7 +287,7 @@ struct ext3_inode {
287 __u32 m_i_reserved1; 287 __u32 m_i_reserved1;
288 } masix1; 288 } masix1;
289 } osd1; /* OS dependent 1 */ 289 } osd1; /* OS dependent 1 */
290 __le32 i_block[EXT3_N_BLOCKS];/* Pointers to blocks */ 290 __le32 i_block[EXT4_N_BLOCKS];/* Pointers to blocks */
291 __le32 i_generation; /* File version (for NFS) */ 291 __le32 i_generation; /* File version (for NFS) */
292 __le32 i_file_acl; /* File ACL */ 292 __le32 i_file_acl; /* File ACL */
293 __le32 i_dir_acl; /* Directory ACL */ 293 __le32 i_dir_acl; /* Directory ACL */
@@ -353,76 +353,76 @@ struct ext3_inode {
353/* 353/*
354 * File system states 354 * File system states
355 */ 355 */
356#define EXT3_VALID_FS 0x0001 /* Unmounted cleanly */ 356#define EXT4_VALID_FS 0x0001 /* Unmounted cleanly */
357#define EXT3_ERROR_FS 0x0002 /* Errors detected */ 357#define EXT4_ERROR_FS 0x0002 /* Errors detected */
358#define EXT3_ORPHAN_FS 0x0004 /* Orphans being recovered */ 358#define EXT4_ORPHAN_FS 0x0004 /* Orphans being recovered */
359 359
360/* 360/*
361 * Mount flags 361 * Mount flags
362 */ 362 */
363#define EXT3_MOUNT_CHECK 0x00001 /* Do mount-time checks */ 363#define EXT4_MOUNT_CHECK 0x00001 /* Do mount-time checks */
364#define EXT3_MOUNT_OLDALLOC 0x00002 /* Don't use the new Orlov allocator */ 364#define EXT4_MOUNT_OLDALLOC 0x00002 /* Don't use the new Orlov allocator */
365#define EXT3_MOUNT_GRPID 0x00004 /* Create files with directory's group */ 365#define EXT4_MOUNT_GRPID 0x00004 /* Create files with directory's group */
366#define EXT3_MOUNT_DEBUG 0x00008 /* Some debugging messages */ 366#define EXT4_MOUNT_DEBUG 0x00008 /* Some debugging messages */
367#define EXT3_MOUNT_ERRORS_CONT 0x00010 /* Continue on errors */ 367#define EXT4_MOUNT_ERRORS_CONT 0x00010 /* Continue on errors */
368#define EXT3_MOUNT_ERRORS_RO 0x00020 /* Remount fs ro on errors */ 368#define EXT4_MOUNT_ERRORS_RO 0x00020 /* Remount fs ro on errors */
369#define EXT3_MOUNT_ERRORS_PANIC 0x00040 /* Panic on errors */ 369#define EXT4_MOUNT_ERRORS_PANIC 0x00040 /* Panic on errors */
370#define EXT3_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */ 370#define EXT4_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */
371#define EXT3_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/ 371#define EXT4_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/
372#define EXT3_MOUNT_ABORT 0x00200 /* Fatal error detected */ 372#define EXT4_MOUNT_ABORT 0x00200 /* Fatal error detected */
373#define EXT3_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */ 373#define EXT4_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */
374#define EXT3_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */ 374#define EXT4_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */
375#define EXT3_MOUNT_ORDERED_DATA 0x00800 /* Flush data before commit */ 375#define EXT4_MOUNT_ORDERED_DATA 0x00800 /* Flush data before commit */
376#define EXT3_MOUNT_WRITEBACK_DATA 0x00C00 /* No data ordering */ 376#define EXT4_MOUNT_WRITEBACK_DATA 0x00C00 /* No data ordering */
377#define EXT3_MOUNT_UPDATE_JOURNAL 0x01000 /* Update the journal format */ 377#define EXT4_MOUNT_UPDATE_JOURNAL 0x01000 /* Update the journal format */
378#define EXT3_MOUNT_NO_UID32 0x02000 /* Disable 32-bit UIDs */ 378#define EXT4_MOUNT_NO_UID32 0x02000 /* Disable 32-bit UIDs */
379#define EXT3_MOUNT_XATTR_USER 0x04000 /* Extended user attributes */ 379#define EXT4_MOUNT_XATTR_USER 0x04000 /* Extended user attributes */
380#define EXT3_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */ 380#define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
381#define EXT3_MOUNT_RESERVATION 0x10000 /* Preallocation */ 381#define EXT4_MOUNT_RESERVATION 0x10000 /* Preallocation */
382#define EXT3_MOUNT_BARRIER 0x20000 /* Use block barriers */ 382#define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */
383#define EXT3_MOUNT_NOBH 0x40000 /* No bufferheads */ 383#define EXT4_MOUNT_NOBH 0x40000 /* No bufferheads */
384#define EXT3_MOUNT_QUOTA 0x80000 /* Some quota option set */ 384#define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */
385#define EXT3_MOUNT_USRQUOTA 0x100000 /* "old" user quota */ 385#define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
386#define EXT3_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */ 386#define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
387 387
388/* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */ 388/* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
389#ifndef _LINUX_EXT2_FS_H 389#ifndef _LINUX_EXT2_FS_H
390#define clear_opt(o, opt) o &= ~EXT3_MOUNT_##opt 390#define clear_opt(o, opt) o &= ~EXT4_MOUNT_##opt
391#define set_opt(o, opt) o |= EXT3_MOUNT_##opt 391#define set_opt(o, opt) o |= EXT4_MOUNT_##opt
392#define test_opt(sb, opt) (EXT3_SB(sb)->s_mount_opt & \ 392#define test_opt(sb, opt) (EXT4_SB(sb)->s_mount_opt & \
393 EXT3_MOUNT_##opt) 393 EXT4_MOUNT_##opt)
394#else 394#else
395#define EXT2_MOUNT_NOLOAD EXT3_MOUNT_NOLOAD 395#define EXT2_MOUNT_NOLOAD EXT4_MOUNT_NOLOAD
396#define EXT2_MOUNT_ABORT EXT3_MOUNT_ABORT 396#define EXT2_MOUNT_ABORT EXT4_MOUNT_ABORT
397#define EXT2_MOUNT_DATA_FLAGS EXT3_MOUNT_DATA_FLAGS 397#define EXT2_MOUNT_DATA_FLAGS EXT4_MOUNT_DATA_FLAGS
398#endif 398#endif
399 399
400#define ext3_set_bit ext2_set_bit 400#define ext4_set_bit ext2_set_bit
401#define ext3_set_bit_atomic ext2_set_bit_atomic 401#define ext4_set_bit_atomic ext2_set_bit_atomic
402#define ext3_clear_bit ext2_clear_bit 402#define ext4_clear_bit ext2_clear_bit
403#define ext3_clear_bit_atomic ext2_clear_bit_atomic 403#define ext4_clear_bit_atomic ext2_clear_bit_atomic
404#define ext3_test_bit ext2_test_bit 404#define ext4_test_bit ext2_test_bit
405#define ext3_find_first_zero_bit ext2_find_first_zero_bit 405#define ext4_find_first_zero_bit ext2_find_first_zero_bit
406#define ext3_find_next_zero_bit ext2_find_next_zero_bit 406#define ext4_find_next_zero_bit ext2_find_next_zero_bit
407 407
408/* 408/*
409 * Maximal mount counts between two filesystem checks 409 * Maximal mount counts between two filesystem checks
410 */ 410 */
411#define EXT3_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */ 411#define EXT4_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
412#define EXT3_DFL_CHECKINTERVAL 0 /* Don't use interval check */ 412#define EXT4_DFL_CHECKINTERVAL 0 /* Don't use interval check */
413 413
414/* 414/*
415 * Behaviour when detecting errors 415 * Behaviour when detecting errors
416 */ 416 */
417#define EXT3_ERRORS_CONTINUE 1 /* Continue execution */ 417#define EXT4_ERRORS_CONTINUE 1 /* Continue execution */
418#define EXT3_ERRORS_RO 2 /* Remount fs read-only */ 418#define EXT4_ERRORS_RO 2 /* Remount fs read-only */
419#define EXT3_ERRORS_PANIC 3 /* Panic */ 419#define EXT4_ERRORS_PANIC 3 /* Panic */
420#define EXT3_ERRORS_DEFAULT EXT3_ERRORS_CONTINUE 420#define EXT4_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE
421 421
422/* 422/*
423 * Structure of the super block 423 * Structure of the super block
424 */ 424 */
425struct ext3_super_block { 425struct ext4_super_block {
426/*00*/ __le32 s_inodes_count; /* Inodes count */ 426/*00*/ __le32 s_inodes_count; /* Inodes count */
427 __le32 s_blocks_count; /* Blocks count */ 427 __le32 s_blocks_count; /* Blocks count */
428 __le32 s_r_blocks_count; /* Reserved blocks count */ 428 __le32 s_r_blocks_count; /* Reserved blocks count */
@@ -449,7 +449,7 @@ struct ext3_super_block {
449/*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */ 449/*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */
450 __le16 s_def_resgid; /* Default gid for reserved blocks */ 450 __le16 s_def_resgid; /* Default gid for reserved blocks */
451 /* 451 /*
452 * These fields are for EXT3_DYNAMIC_REV superblocks only. 452 * These fields are for EXT4_DYNAMIC_REV superblocks only.
453 * 453 *
454 * Note: the difference between the compatible feature set and 454 * Note: the difference between the compatible feature set and
455 * the incompatible feature set is that if there is a bit set 455 * the incompatible feature set is that if there is a bit set
@@ -473,13 +473,13 @@ struct ext3_super_block {
473/*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */ 473/*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */
474 /* 474 /*
475 * Performance hints. Directory preallocation should only 475 * Performance hints. Directory preallocation should only
476 * happen if the EXT3_FEATURE_COMPAT_DIR_PREALLOC flag is on. 476 * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on.
477 */ 477 */
478 __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ 478 __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
479 __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ 479 __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
480 __le16 s_reserved_gdt_blocks; /* Per group desc for online growth */ 480 __le16 s_reserved_gdt_blocks; /* Per group desc for online growth */
481 /* 481 /*
482 * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set. 482 * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set.
483 */ 483 */
484/*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */ 484/*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */
485/*E0*/ __le32 s_journal_inum; /* inode number of journal file */ 485/*E0*/ __le32 s_journal_inum; /* inode number of journal file */
@@ -495,186 +495,186 @@ struct ext3_super_block {
495}; 495};
496 496
497#ifdef __KERNEL__ 497#ifdef __KERNEL__
498#include <linux/ext3_fs_i.h> 498#include <linux/ext4_fs_i.h>
499#include <linux/ext3_fs_sb.h> 499#include <linux/ext4_fs_sb.h>
500static inline struct ext3_sb_info * EXT3_SB(struct super_block *sb) 500static inline struct ext4_sb_info * EXT4_SB(struct super_block *sb)
501{ 501{
502 return sb->s_fs_info; 502 return sb->s_fs_info;
503} 503}
504static inline struct ext3_inode_info *EXT3_I(struct inode *inode) 504static inline struct ext4_inode_info *EXT4_I(struct inode *inode)
505{ 505{
506 return container_of(inode, struct ext3_inode_info, vfs_inode); 506 return container_of(inode, struct ext4_inode_info, vfs_inode);
507} 507}
508 508
509static inline int ext3_valid_inum(struct super_block *sb, unsigned long ino) 509static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
510{ 510{
511 return ino == EXT3_ROOT_INO || 511 return ino == EXT4_ROOT_INO ||
512 ino == EXT3_JOURNAL_INO || 512 ino == EXT4_JOURNAL_INO ||
513 ino == EXT3_RESIZE_INO || 513 ino == EXT4_RESIZE_INO ||
514 (ino >= EXT3_FIRST_INO(sb) && 514 (ino >= EXT4_FIRST_INO(sb) &&
515 ino <= le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count)); 515 ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count));
516} 516}
517#else 517#else
518/* Assume that user mode programs are passing in an ext3fs superblock, not 518/* Assume that user mode programs are passing in an ext4fs superblock, not
519 * a kernel struct super_block. This will allow us to call the feature-test 519 * a kernel struct super_block. This will allow us to call the feature-test
520 * macros from user land. */ 520 * macros from user land. */
521#define EXT3_SB(sb) (sb) 521#define EXT4_SB(sb) (sb)
522#endif 522#endif
523 523
524#define NEXT_ORPHAN(inode) EXT3_I(inode)->i_dtime 524#define NEXT_ORPHAN(inode) EXT4_I(inode)->i_dtime
525 525
526/* 526/*
527 * Codes for operating systems 527 * Codes for operating systems
528 */ 528 */
529#define EXT3_OS_LINUX 0 529#define EXT4_OS_LINUX 0
530#define EXT3_OS_HURD 1 530#define EXT4_OS_HURD 1
531#define EXT3_OS_MASIX 2 531#define EXT4_OS_MASIX 2
532#define EXT3_OS_FREEBSD 3 532#define EXT4_OS_FREEBSD 3
533#define EXT3_OS_LITES 4 533#define EXT4_OS_LITES 4
534 534
535/* 535/*
536 * Revision levels 536 * Revision levels
537 */ 537 */
538#define EXT3_GOOD_OLD_REV 0 /* The good old (original) format */ 538#define EXT4_GOOD_OLD_REV 0 /* The good old (original) format */
539#define EXT3_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */ 539#define EXT4_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
540 540
541#define EXT3_CURRENT_REV EXT3_GOOD_OLD_REV 541#define EXT4_CURRENT_REV EXT4_GOOD_OLD_REV
542#define EXT3_MAX_SUPP_REV EXT3_DYNAMIC_REV 542#define EXT4_MAX_SUPP_REV EXT4_DYNAMIC_REV
543 543
544#define EXT3_GOOD_OLD_INODE_SIZE 128 544#define EXT4_GOOD_OLD_INODE_SIZE 128
545 545
546/* 546/*
547 * Feature set definitions 547 * Feature set definitions
548 */ 548 */
549 549
550#define EXT3_HAS_COMPAT_FEATURE(sb,mask) \ 550#define EXT4_HAS_COMPAT_FEATURE(sb,mask) \
551 ( EXT3_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) ) 551 ( EXT4_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
552#define EXT3_HAS_RO_COMPAT_FEATURE(sb,mask) \ 552#define EXT4_HAS_RO_COMPAT_FEATURE(sb,mask) \
553 ( EXT3_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) ) 553 ( EXT4_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
554#define EXT3_HAS_INCOMPAT_FEATURE(sb,mask) \ 554#define EXT4_HAS_INCOMPAT_FEATURE(sb,mask) \
555 ( EXT3_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) ) 555 ( EXT4_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
556#define EXT3_SET_COMPAT_FEATURE(sb,mask) \ 556#define EXT4_SET_COMPAT_FEATURE(sb,mask) \
557 EXT3_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask) 557 EXT4_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
558#define EXT3_SET_RO_COMPAT_FEATURE(sb,mask) \ 558#define EXT4_SET_RO_COMPAT_FEATURE(sb,mask) \
559 EXT3_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask) 559 EXT4_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
560#define EXT3_SET_INCOMPAT_FEATURE(sb,mask) \ 560#define EXT4_SET_INCOMPAT_FEATURE(sb,mask) \
561 EXT3_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask) 561 EXT4_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
562#define EXT3_CLEAR_COMPAT_FEATURE(sb,mask) \ 562#define EXT4_CLEAR_COMPAT_FEATURE(sb,mask) \
563 EXT3_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask) 563 EXT4_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
564#define EXT3_CLEAR_RO_COMPAT_FEATURE(sb,mask) \ 564#define EXT4_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
565 EXT3_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask) 565 EXT4_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
566#define EXT3_CLEAR_INCOMPAT_FEATURE(sb,mask) \ 566#define EXT4_CLEAR_INCOMPAT_FEATURE(sb,mask) \
567 EXT3_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask) 567 EXT4_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
568 568
569#define EXT3_FEATURE_COMPAT_DIR_PREALLOC 0x0001 569#define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001
570#define EXT3_FEATURE_COMPAT_IMAGIC_INODES 0x0002 570#define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002
571#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 571#define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004
572#define EXT3_FEATURE_COMPAT_EXT_ATTR 0x0008 572#define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008
573#define EXT3_FEATURE_COMPAT_RESIZE_INODE 0x0010 573#define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010
574#define EXT3_FEATURE_COMPAT_DIR_INDEX 0x0020 574#define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020
575 575
576#define EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 576#define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
577#define EXT3_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 577#define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
578#define EXT3_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 578#define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
579 579
580#define EXT3_FEATURE_INCOMPAT_COMPRESSION 0x0001 580#define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001
581#define EXT3_FEATURE_INCOMPAT_FILETYPE 0x0002 581#define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002
582#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */ 582#define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
583#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */ 583#define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
584#define EXT3_FEATURE_INCOMPAT_META_BG 0x0010 584#define EXT4_FEATURE_INCOMPAT_META_BG 0x0010
585 585
586#define EXT3_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR 586#define EXT4_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
587#define EXT3_FEATURE_INCOMPAT_SUPP (EXT3_FEATURE_INCOMPAT_FILETYPE| \ 587#define EXT4_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \
588 EXT3_FEATURE_INCOMPAT_RECOVER| \ 588 EXT4_FEATURE_INCOMPAT_RECOVER| \
589 EXT3_FEATURE_INCOMPAT_META_BG) 589 EXT4_FEATURE_INCOMPAT_META_BG)
590#define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \ 590#define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \
591 EXT3_FEATURE_RO_COMPAT_LARGE_FILE| \ 591 EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \
592 EXT3_FEATURE_RO_COMPAT_BTREE_DIR) 592 EXT4_FEATURE_RO_COMPAT_BTREE_DIR)
593 593
594/* 594/*
595 * Default values for user and/or group using reserved blocks 595 * Default values for user and/or group using reserved blocks
596 */ 596 */
597#define EXT3_DEF_RESUID 0 597#define EXT4_DEF_RESUID 0
598#define EXT3_DEF_RESGID 0 598#define EXT4_DEF_RESGID 0
599 599
600/* 600/*
601 * Default mount options 601 * Default mount options
602 */ 602 */
603#define EXT3_DEFM_DEBUG 0x0001 603#define EXT4_DEFM_DEBUG 0x0001
604#define EXT3_DEFM_BSDGROUPS 0x0002 604#define EXT4_DEFM_BSDGROUPS 0x0002
605#define EXT3_DEFM_XATTR_USER 0x0004 605#define EXT4_DEFM_XATTR_USER 0x0004
606#define EXT3_DEFM_ACL 0x0008 606#define EXT4_DEFM_ACL 0x0008
607#define EXT3_DEFM_UID16 0x0010 607#define EXT4_DEFM_UID16 0x0010
608#define EXT3_DEFM_JMODE 0x0060 608#define EXT4_DEFM_JMODE 0x0060
609#define EXT3_DEFM_JMODE_DATA 0x0020 609#define EXT4_DEFM_JMODE_DATA 0x0020
610#define EXT3_DEFM_JMODE_ORDERED 0x0040 610#define EXT4_DEFM_JMODE_ORDERED 0x0040
611#define EXT3_DEFM_JMODE_WBACK 0x0060 611#define EXT4_DEFM_JMODE_WBACK 0x0060
612 612
613/* 613/*
614 * Structure of a directory entry 614 * Structure of a directory entry
615 */ 615 */
616#define EXT3_NAME_LEN 255 616#define EXT4_NAME_LEN 255
617 617
618struct ext3_dir_entry { 618struct ext4_dir_entry {
619 __le32 inode; /* Inode number */ 619 __le32 inode; /* Inode number */
620 __le16 rec_len; /* Directory entry length */ 620 __le16 rec_len; /* Directory entry length */
621 __le16 name_len; /* Name length */ 621 __le16 name_len; /* Name length */
622 char name[EXT3_NAME_LEN]; /* File name */ 622 char name[EXT4_NAME_LEN]; /* File name */
623}; 623};
624 624
625/* 625/*
626 * The new version of the directory entry. Since EXT3 structures are 626 * The new version of the directory entry. Since EXT4 structures are
627 * stored in intel byte order, and the name_len field could never be 627 * stored in intel byte order, and the name_len field could never be
628 * bigger than 255 chars, it's safe to reclaim the extra byte for the 628 * bigger than 255 chars, it's safe to reclaim the extra byte for the
629 * file_type field. 629 * file_type field.
630 */ 630 */
631struct ext3_dir_entry_2 { 631struct ext4_dir_entry_2 {
632 __le32 inode; /* Inode number */ 632 __le32 inode; /* Inode number */
633 __le16 rec_len; /* Directory entry length */ 633 __le16 rec_len; /* Directory entry length */
634 __u8 name_len; /* Name length */ 634 __u8 name_len; /* Name length */
635 __u8 file_type; 635 __u8 file_type;
636 char name[EXT3_NAME_LEN]; /* File name */ 636 char name[EXT4_NAME_LEN]; /* File name */
637}; 637};
638 638
639/* 639/*
640 * Ext3 directory file types. Only the low 3 bits are used. The 640 * Ext4 directory file types. Only the low 3 bits are used. The
641 * other bits are reserved for now. 641 * other bits are reserved for now.
642 */ 642 */
643#define EXT3_FT_UNKNOWN 0 643#define EXT4_FT_UNKNOWN 0
644#define EXT3_FT_REG_FILE 1 644#define EXT4_FT_REG_FILE 1
645#define EXT3_FT_DIR 2 645#define EXT4_FT_DIR 2
646#define EXT3_FT_CHRDEV 3 646#define EXT4_FT_CHRDEV 3
647#define EXT3_FT_BLKDEV 4 647#define EXT4_FT_BLKDEV 4
648#define EXT3_FT_FIFO 5 648#define EXT4_FT_FIFO 5
649#define EXT3_FT_SOCK 6 649#define EXT4_FT_SOCK 6
650#define EXT3_FT_SYMLINK 7 650#define EXT4_FT_SYMLINK 7
651 651
652#define EXT3_FT_MAX 8 652#define EXT4_FT_MAX 8
653 653
654/* 654/*
655 * EXT3_DIR_PAD defines the directory entries boundaries 655 * EXT4_DIR_PAD defines the directory entries boundaries
656 * 656 *
657 * NOTE: It must be a multiple of 4 657 * NOTE: It must be a multiple of 4
658 */ 658 */
659#define EXT3_DIR_PAD 4 659#define EXT4_DIR_PAD 4
660#define EXT3_DIR_ROUND (EXT3_DIR_PAD - 1) 660#define EXT4_DIR_ROUND (EXT4_DIR_PAD - 1)
661#define EXT3_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT3_DIR_ROUND) & \ 661#define EXT4_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT4_DIR_ROUND) & \
662 ~EXT3_DIR_ROUND) 662 ~EXT4_DIR_ROUND)
663/* 663/*
664 * Hash Tree Directory indexing 664 * Hash Tree Directory indexing
665 * (c) Daniel Phillips, 2001 665 * (c) Daniel Phillips, 2001
666 */ 666 */
667 667
668#ifdef CONFIG_EXT3_INDEX 668#ifdef CONFIG_EXT4_INDEX
669 #define is_dx(dir) (EXT3_HAS_COMPAT_FEATURE(dir->i_sb, \ 669 #define is_dx(dir) (EXT4_HAS_COMPAT_FEATURE(dir->i_sb, \
670 EXT3_FEATURE_COMPAT_DIR_INDEX) && \ 670 EXT4_FEATURE_COMPAT_DIR_INDEX) && \
671 (EXT3_I(dir)->i_flags & EXT3_INDEX_FL)) 671 (EXT4_I(dir)->i_flags & EXT4_INDEX_FL))
672#define EXT3_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT3_LINK_MAX) 672#define EXT4_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT4_LINK_MAX)
673#define EXT3_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1) 673#define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1)
674#else 674#else
675 #define is_dx(dir) 0 675 #define is_dx(dir) 0
676#define EXT3_DIR_LINK_MAX(dir) ((dir)->i_nlink >= EXT3_LINK_MAX) 676#define EXT4_DIR_LINK_MAX(dir) ((dir)->i_nlink >= EXT4_LINK_MAX)
677#define EXT3_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2) 677#define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2)
678#endif 678#endif
679 679
680/* Legal values for the dx_root hash_version field: */ 680/* Legal values for the dx_root hash_version field: */
@@ -694,10 +694,10 @@ struct dx_hash_info
694 u32 *seed; 694 u32 *seed;
695}; 695};
696 696
697#define EXT3_HTREE_EOF 0x7fffffff 697#define EXT4_HTREE_EOF 0x7fffffff
698 698
699/* 699/*
700 * Control parameters used by ext3_htree_next_block 700 * Control parameters used by ext4_htree_next_block
701 */ 701 */
702#define HASH_NB_ALWAYS 1 702#define HASH_NB_ALWAYS 1
703 703
@@ -705,16 +705,16 @@ struct dx_hash_info
705/* 705/*
706 * Describe an inode's exact location on disk and in memory 706 * Describe an inode's exact location on disk and in memory
707 */ 707 */
708struct ext3_iloc 708struct ext4_iloc
709{ 709{
710 struct buffer_head *bh; 710 struct buffer_head *bh;
711 unsigned long offset; 711 unsigned long offset;
712 unsigned long block_group; 712 unsigned long block_group;
713}; 713};
714 714
715static inline struct ext3_inode *ext3_raw_inode(struct ext3_iloc *iloc) 715static inline struct ext4_inode *ext4_raw_inode(struct ext4_iloc *iloc)
716{ 716{
717 return (struct ext3_inode *) (iloc->bh->b_data + iloc->offset); 717 return (struct ext4_inode *) (iloc->bh->b_data + iloc->offset);
718} 718}
719 719
720/* 720/*
@@ -733,11 +733,11 @@ struct dir_private_info {
733}; 733};
734 734
735/* calculate the first block number of the group */ 735/* calculate the first block number of the group */
736static inline ext3_fsblk_t 736static inline ext4_fsblk_t
737ext3_group_first_block_no(struct super_block *sb, unsigned long group_no) 737ext4_group_first_block_no(struct super_block *sb, unsigned long group_no)
738{ 738{
739 return group_no * (ext3_fsblk_t)EXT3_BLOCKS_PER_GROUP(sb) + 739 return group_no * (ext4_fsblk_t)EXT4_BLOCKS_PER_GROUP(sb) +
740 le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block); 740 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
741} 741}
742 742
743/* 743/*
@@ -751,113 +751,113 @@ ext3_group_first_block_no(struct super_block *sb, unsigned long group_no)
751 751
752/* 752/*
753 * Ok, these declarations are also in <linux/kernel.h> but none of the 753 * Ok, these declarations are also in <linux/kernel.h> but none of the
754 * ext3 source programs needs to include it so they are duplicated here. 754 * ext4 source programs needs to include it so they are duplicated here.
755 */ 755 */
756# define NORET_TYPE /**/ 756# define NORET_TYPE /**/
757# define ATTRIB_NORET __attribute__((noreturn)) 757# define ATTRIB_NORET __attribute__((noreturn))
758# define NORET_AND noreturn, 758# define NORET_AND noreturn,
759 759
760/* balloc.c */ 760/* balloc.c */
761extern int ext3_bg_has_super(struct super_block *sb, int group); 761extern int ext4_bg_has_super(struct super_block *sb, int group);
762extern unsigned long ext3_bg_num_gdb(struct super_block *sb, int group); 762extern unsigned long ext4_bg_num_gdb(struct super_block *sb, int group);
763extern ext3_fsblk_t ext3_new_block (handle_t *handle, struct inode *inode, 763extern ext4_fsblk_t ext4_new_block (handle_t *handle, struct inode *inode,
764 ext3_fsblk_t goal, int *errp); 764 ext4_fsblk_t goal, int *errp);
765extern ext3_fsblk_t ext3_new_blocks (handle_t *handle, struct inode *inode, 765extern ext4_fsblk_t ext4_new_blocks (handle_t *handle, struct inode *inode,
766 ext3_fsblk_t goal, unsigned long *count, int *errp); 766 ext4_fsblk_t goal, unsigned long *count, int *errp);
767extern void ext3_free_blocks (handle_t *handle, struct inode *inode, 767extern void ext4_free_blocks (handle_t *handle, struct inode *inode,
768 ext3_fsblk_t block, unsigned long count); 768 ext4_fsblk_t block, unsigned long count);
769extern void ext3_free_blocks_sb (handle_t *handle, struct super_block *sb, 769extern void ext4_free_blocks_sb (handle_t *handle, struct super_block *sb,
770 ext3_fsblk_t block, unsigned long count, 770 ext4_fsblk_t block, unsigned long count,
771 unsigned long *pdquot_freed_blocks); 771 unsigned long *pdquot_freed_blocks);
772extern ext3_fsblk_t ext3_count_free_blocks (struct super_block *); 772extern ext4_fsblk_t ext4_count_free_blocks (struct super_block *);
773extern void ext3_check_blocks_bitmap (struct super_block *); 773extern void ext4_check_blocks_bitmap (struct super_block *);
774extern struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb, 774extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
775 unsigned int block_group, 775 unsigned int block_group,
776 struct buffer_head ** bh); 776 struct buffer_head ** bh);
777extern int ext3_should_retry_alloc(struct super_block *sb, int *retries); 777extern int ext4_should_retry_alloc(struct super_block *sb, int *retries);
778extern void ext3_init_block_alloc_info(struct inode *); 778extern void ext4_init_block_alloc_info(struct inode *);
779extern void ext3_rsv_window_add(struct super_block *sb, struct ext3_reserve_window_node *rsv); 779extern void ext4_rsv_window_add(struct super_block *sb, struct ext4_reserve_window_node *rsv);
780 780
781/* dir.c */ 781/* dir.c */
782extern int ext3_check_dir_entry(const char *, struct inode *, 782extern int ext4_check_dir_entry(const char *, struct inode *,
783 struct ext3_dir_entry_2 *, 783 struct ext4_dir_entry_2 *,
784 struct buffer_head *, unsigned long); 784 struct buffer_head *, unsigned long);
785extern int ext3_htree_store_dirent(struct file *dir_file, __u32 hash, 785extern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
786 __u32 minor_hash, 786 __u32 minor_hash,
787 struct ext3_dir_entry_2 *dirent); 787 struct ext4_dir_entry_2 *dirent);
788extern void ext3_htree_free_dir_info(struct dir_private_info *p); 788extern void ext4_htree_free_dir_info(struct dir_private_info *p);
789 789
790/* fsync.c */ 790/* fsync.c */
791extern int ext3_sync_file (struct file *, struct dentry *, int); 791extern int ext4_sync_file (struct file *, struct dentry *, int);
792 792
793/* hash.c */ 793/* hash.c */
794extern int ext3fs_dirhash(const char *name, int len, struct 794extern int ext4fs_dirhash(const char *name, int len, struct
795 dx_hash_info *hinfo); 795 dx_hash_info *hinfo);
796 796
797/* ialloc.c */ 797/* ialloc.c */
798extern struct inode * ext3_new_inode (handle_t *, struct inode *, int); 798extern struct inode * ext4_new_inode (handle_t *, struct inode *, int);
799extern void ext3_free_inode (handle_t *, struct inode *); 799extern void ext4_free_inode (handle_t *, struct inode *);
800extern struct inode * ext3_orphan_get (struct super_block *, unsigned long); 800extern struct inode * ext4_orphan_get (struct super_block *, unsigned long);
801extern unsigned long ext3_count_free_inodes (struct super_block *); 801extern unsigned long ext4_count_free_inodes (struct super_block *);
802extern unsigned long ext3_count_dirs (struct super_block *); 802extern unsigned long ext4_count_dirs (struct super_block *);
803extern void ext3_check_inodes_bitmap (struct super_block *); 803extern void ext4_check_inodes_bitmap (struct super_block *);
804extern unsigned long ext3_count_free (struct buffer_head *, unsigned); 804extern unsigned long ext4_count_free (struct buffer_head *, unsigned);
805 805
806 806
807/* inode.c */ 807/* inode.c */
808int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode, 808int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode,
809 struct buffer_head *bh, ext3_fsblk_t blocknr); 809 struct buffer_head *bh, ext4_fsblk_t blocknr);
810struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *); 810struct buffer_head * ext4_getblk (handle_t *, struct inode *, long, int, int *);
811struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *); 811struct buffer_head * ext4_bread (handle_t *, struct inode *, int, int, int *);
812int ext3_get_blocks_handle(handle_t *handle, struct inode *inode, 812int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
813 sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result, 813 sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
814 int create, int extend_disksize); 814 int create, int extend_disksize);
815 815
816extern void ext3_read_inode (struct inode *); 816extern void ext4_read_inode (struct inode *);
817extern int ext3_write_inode (struct inode *, int); 817extern int ext4_write_inode (struct inode *, int);
818extern int ext3_setattr (struct dentry *, struct iattr *); 818extern int ext4_setattr (struct dentry *, struct iattr *);
819extern void ext3_delete_inode (struct inode *); 819extern void ext4_delete_inode (struct inode *);
820extern int ext3_sync_inode (handle_t *, struct inode *); 820extern int ext4_sync_inode (handle_t *, struct inode *);
821extern void ext3_discard_reservation (struct inode *); 821extern void ext4_discard_reservation (struct inode *);
822extern void ext3_dirty_inode(struct inode *); 822extern void ext4_dirty_inode(struct inode *);
823extern int ext3_change_inode_journal_flag(struct inode *, int); 823extern int ext4_change_inode_journal_flag(struct inode *, int);
824extern int ext3_get_inode_loc(struct inode *, struct ext3_iloc *); 824extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *);
825extern void ext3_truncate (struct inode *); 825extern void ext4_truncate (struct inode *);
826extern void ext3_set_inode_flags(struct inode *); 826extern void ext4_set_inode_flags(struct inode *);
827extern void ext3_set_aops(struct inode *inode); 827extern void ext4_set_aops(struct inode *inode);
828 828
829/* ioctl.c */ 829/* ioctl.c */
830extern int ext3_ioctl (struct inode *, struct file *, unsigned int, 830extern int ext4_ioctl (struct inode *, struct file *, unsigned int,
831 unsigned long); 831 unsigned long);
832extern long ext3_compat_ioctl (struct file *, unsigned int, unsigned long); 832extern long ext4_compat_ioctl (struct file *, unsigned int, unsigned long);
833 833
834/* namei.c */ 834/* namei.c */
835extern int ext3_orphan_add(handle_t *, struct inode *); 835extern int ext4_orphan_add(handle_t *, struct inode *);
836extern int ext3_orphan_del(handle_t *, struct inode *); 836extern int ext4_orphan_del(handle_t *, struct inode *);
837extern int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash, 837extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
838 __u32 start_minor_hash, __u32 *next_hash); 838 __u32 start_minor_hash, __u32 *next_hash);
839 839
840/* resize.c */ 840/* resize.c */
841extern int ext3_group_add(struct super_block *sb, 841extern int ext4_group_add(struct super_block *sb,
842 struct ext3_new_group_data *input); 842 struct ext4_new_group_data *input);
843extern int ext3_group_extend(struct super_block *sb, 843extern int ext4_group_extend(struct super_block *sb,
844 struct ext3_super_block *es, 844 struct ext4_super_block *es,
845 ext3_fsblk_t n_blocks_count); 845 ext4_fsblk_t n_blocks_count);
846 846
847/* super.c */ 847/* super.c */
848extern void ext3_error (struct super_block *, const char *, const char *, ...) 848extern void ext4_error (struct super_block *, const char *, const char *, ...)
849 __attribute__ ((format (printf, 3, 4))); 849 __attribute__ ((format (printf, 3, 4)));
850extern void __ext3_std_error (struct super_block *, const char *, int); 850extern void __ext4_std_error (struct super_block *, const char *, int);
851extern void ext3_abort (struct super_block *, const char *, const char *, ...) 851extern void ext4_abort (struct super_block *, const char *, const char *, ...)
852 __attribute__ ((format (printf, 3, 4))); 852 __attribute__ ((format (printf, 3, 4)));
853extern void ext3_warning (struct super_block *, const char *, const char *, ...) 853extern void ext4_warning (struct super_block *, const char *, const char *, ...)
854 __attribute__ ((format (printf, 3, 4))); 854 __attribute__ ((format (printf, 3, 4)));
855extern void ext3_update_dynamic_rev (struct super_block *sb); 855extern void ext4_update_dynamic_rev (struct super_block *sb);
856 856
857#define ext3_std_error(sb, errno) \ 857#define ext4_std_error(sb, errno) \
858do { \ 858do { \
859 if ((errno)) \ 859 if ((errno)) \
860 __ext3_std_error((sb), __FUNCTION__, (errno)); \ 860 __ext4_std_error((sb), __FUNCTION__, (errno)); \
861} while (0) 861} while (0)
862 862
863/* 863/*
@@ -865,21 +865,21 @@ do { \
865 */ 865 */
866 866
867/* dir.c */ 867/* dir.c */
868extern const struct file_operations ext3_dir_operations; 868extern const struct file_operations ext4_dir_operations;
869 869
870/* file.c */ 870/* file.c */
871extern struct inode_operations ext3_file_inode_operations; 871extern struct inode_operations ext4_file_inode_operations;
872extern const struct file_operations ext3_file_operations; 872extern const struct file_operations ext4_file_operations;
873 873
874/* namei.c */ 874/* namei.c */
875extern struct inode_operations ext3_dir_inode_operations; 875extern struct inode_operations ext4_dir_inode_operations;
876extern struct inode_operations ext3_special_inode_operations; 876extern struct inode_operations ext4_special_inode_operations;
877 877
878/* symlink.c */ 878/* symlink.c */
879extern struct inode_operations ext3_symlink_inode_operations; 879extern struct inode_operations ext4_symlink_inode_operations;
880extern struct inode_operations ext3_fast_symlink_inode_operations; 880extern struct inode_operations ext4_fast_symlink_inode_operations;
881 881
882 882
883#endif /* __KERNEL__ */ 883#endif /* __KERNEL__ */
884 884
885#endif /* _LINUX_EXT3_FS_H */ 885#endif /* _LINUX_EXT4_FS_H */
diff --git a/include/linux/ext4_fs_i.h b/include/linux/ext4_fs_i.h
index 4395e520674..18a6ce98537 100644
--- a/include/linux/ext4_fs_i.h
+++ b/include/linux/ext4_fs_i.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/include/linux/ext3_fs_i.h 2 * linux/include/linux/ext4_fs_i.h
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -13,8 +13,8 @@
13 * Copyright (C) 1991, 1992 Linus Torvalds 13 * Copyright (C) 1991, 1992 Linus Torvalds
14 */ 14 */
15 15
16#ifndef _LINUX_EXT3_FS_I 16#ifndef _LINUX_EXT4_FS_I
17#define _LINUX_EXT3_FS_I 17#define _LINUX_EXT4_FS_I
18 18
19#include <linux/rwsem.h> 19#include <linux/rwsem.h>
20#include <linux/rbtree.h> 20#include <linux/rbtree.h>
@@ -22,43 +22,43 @@
22#include <linux/mutex.h> 22#include <linux/mutex.h>
23 23
24/* data type for block offset of block group */ 24/* data type for block offset of block group */
25typedef int ext3_grpblk_t; 25typedef int ext4_grpblk_t;
26 26
27/* data type for filesystem-wide blocks number */ 27/* data type for filesystem-wide blocks number */
28typedef unsigned long ext3_fsblk_t; 28typedef unsigned long ext4_fsblk_t;
29 29
30#define E3FSBLK "%lu" 30#define E3FSBLK "%lu"
31 31
32struct ext3_reserve_window { 32struct ext4_reserve_window {
33 ext3_fsblk_t _rsv_start; /* First byte reserved */ 33 ext4_fsblk_t _rsv_start; /* First byte reserved */
34 ext3_fsblk_t _rsv_end; /* Last byte reserved or 0 */ 34 ext4_fsblk_t _rsv_end; /* Last byte reserved or 0 */
35}; 35};
36 36
37struct ext3_reserve_window_node { 37struct ext4_reserve_window_node {
38 struct rb_node rsv_node; 38 struct rb_node rsv_node;
39 __u32 rsv_goal_size; 39 __u32 rsv_goal_size;
40 __u32 rsv_alloc_hit; 40 __u32 rsv_alloc_hit;
41 struct ext3_reserve_window rsv_window; 41 struct ext4_reserve_window rsv_window;
42}; 42};
43 43
44struct ext3_block_alloc_info { 44struct ext4_block_alloc_info {
45 /* information about reservation window */ 45 /* information about reservation window */
46 struct ext3_reserve_window_node rsv_window_node; 46 struct ext4_reserve_window_node rsv_window_node;
47 /* 47 /*
48 * was i_next_alloc_block in ext3_inode_info 48 * was i_next_alloc_block in ext4_inode_info
49 * is the logical (file-relative) number of the 49 * is the logical (file-relative) number of the
50 * most-recently-allocated block in this file. 50 * most-recently-allocated block in this file.
51 * We use this for detecting linearly ascending allocation requests. 51 * We use this for detecting linearly ascending allocation requests.
52 */ 52 */
53 __u32 last_alloc_logical_block; 53 __u32 last_alloc_logical_block;
54 /* 54 /*
55 * Was i_next_alloc_goal in ext3_inode_info 55 * Was i_next_alloc_goal in ext4_inode_info
56 * is the *physical* companion to i_next_alloc_block. 56 * is the *physical* companion to i_next_alloc_block.
57 * it the the physical block number of the block which was most-recentl 57 * it the the physical block number of the block which was most-recentl
58 * allocated to this file. This give us the goal (target) for the next 58 * allocated to this file. This give us the goal (target) for the next
59 * allocation when we detect linearly ascending requests. 59 * allocation when we detect linearly ascending requests.
60 */ 60 */
61 ext3_fsblk_t last_alloc_physical_block; 61 ext4_fsblk_t last_alloc_physical_block;
62}; 62};
63 63
64#define rsv_start rsv_window._rsv_start 64#define rsv_start rsv_window._rsv_start
@@ -67,15 +67,15 @@ struct ext3_block_alloc_info {
67/* 67/*
68 * third extended file system inode data in memory 68 * third extended file system inode data in memory
69 */ 69 */
70struct ext3_inode_info { 70struct ext4_inode_info {
71 __le32 i_data[15]; /* unconverted */ 71 __le32 i_data[15]; /* unconverted */
72 __u32 i_flags; 72 __u32 i_flags;
73#ifdef EXT3_FRAGMENTS 73#ifdef EXT4_FRAGMENTS
74 __u32 i_faddr; 74 __u32 i_faddr;
75 __u8 i_frag_no; 75 __u8 i_frag_no;
76 __u8 i_frag_size; 76 __u8 i_frag_size;
77#endif 77#endif
78 ext3_fsblk_t i_file_acl; 78 ext4_fsblk_t i_file_acl;
79 __u32 i_dir_acl; 79 __u32 i_dir_acl;
80 __u32 i_dtime; 80 __u32 i_dtime;
81 81
@@ -87,13 +87,13 @@ struct ext3_inode_info {
87 * near to their parent directory's inode. 87 * near to their parent directory's inode.
88 */ 88 */
89 __u32 i_block_group; 89 __u32 i_block_group;
90 __u32 i_state; /* Dynamic state flags for ext3 */ 90 __u32 i_state; /* Dynamic state flags for ext4 */
91 91
92 /* block reservation info */ 92 /* block reservation info */
93 struct ext3_block_alloc_info *i_block_alloc_info; 93 struct ext4_block_alloc_info *i_block_alloc_info;
94 94
95 __u32 i_dir_start_lookup; 95 __u32 i_dir_start_lookup;
96#ifdef CONFIG_EXT3_FS_XATTR 96#ifdef CONFIG_EXT4DEV_FS_XATTR
97 /* 97 /*
98 * Extended attributes can be read independently of the main file 98 * Extended attributes can be read independently of the main file
99 * data. Taking i_mutex even when reading would cause contention 99 * data. Taking i_mutex even when reading would cause contention
@@ -103,7 +103,7 @@ struct ext3_inode_info {
103 */ 103 */
104 struct rw_semaphore xattr_sem; 104 struct rw_semaphore xattr_sem;
105#endif 105#endif
106#ifdef CONFIG_EXT3_FS_POSIX_ACL 106#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
107 struct posix_acl *i_acl; 107 struct posix_acl *i_acl;
108 struct posix_acl *i_default_acl; 108 struct posix_acl *i_default_acl;
109#endif 109#endif
@@ -113,7 +113,7 @@ struct ext3_inode_info {
113 /* 113 /*
114 * i_disksize keeps track of what the inode size is ON DISK, not 114 * i_disksize keeps track of what the inode size is ON DISK, not
115 * in memory. During truncate, i_size is set to the new size by 115 * in memory. During truncate, i_size is set to the new size by
116 * the VFS prior to calling ext3_truncate(), but the filesystem won't 116 * the VFS prior to calling ext4_truncate(), but the filesystem won't
117 * set i_disksize to 0 until the truncate is actually under way. 117 * set i_disksize to 0 until the truncate is actually under way.
118 * 118 *
119 * The intent is that i_disksize always represents the blocks which 119 * The intent is that i_disksize always represents the blocks which
@@ -123,7 +123,7 @@ struct ext3_inode_info {
123 * 123 *
124 * The only time when i_disksize and i_size may be different is when 124 * The only time when i_disksize and i_size may be different is when
125 * a truncate is in progress. The only things which change i_disksize 125 * a truncate is in progress. The only things which change i_disksize
126 * are ext3_get_block (growth) and ext3_truncate (shrinkth). 126 * are ext4_get_block (growth) and ext4_truncate (shrinkth).
127 */ 127 */
128 loff_t i_disksize; 128 loff_t i_disksize;
129 129
@@ -131,10 +131,10 @@ struct ext3_inode_info {
131 __u16 i_extra_isize; 131 __u16 i_extra_isize;
132 132
133 /* 133 /*
134 * truncate_mutex is for serialising ext3_truncate() against 134 * truncate_mutex is for serialising ext4_truncate() against
135 * ext3_getblock(). In the 2.4 ext2 design, great chunks of inode's 135 * ext4_getblock(). In the 2.4 ext2 design, great chunks of inode's
136 * data tree are chopped off during truncate. We can't do that in 136 * data tree are chopped off during truncate. We can't do that in
137 * ext3 because whenever we perform intermediate commits during 137 * ext4 because whenever we perform intermediate commits during
138 * truncate, the inode and all the metadata blocks *must* be in a 138 * truncate, the inode and all the metadata blocks *must* be in a
139 * consistent state which allows truncation of the orphans to restart 139 * consistent state which allows truncation of the orphans to restart
140 * during recovery. Hence we must fix the get_block-vs-truncate race 140 * during recovery. Hence we must fix the get_block-vs-truncate race
@@ -144,4 +144,4 @@ struct ext3_inode_info {
144 struct inode vfs_inode; 144 struct inode vfs_inode;
145}; 145};
146 146
147#endif /* _LINUX_EXT3_FS_I */ 147#endif /* _LINUX_EXT4_FS_I */
diff --git a/include/linux/ext4_fs_sb.h b/include/linux/ext4_fs_sb.h
index f61309c81cc..ce4856d7010 100644
--- a/include/linux/ext4_fs_sb.h
+++ b/include/linux/ext4_fs_sb.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/include/linux/ext3_fs_sb.h 2 * linux/include/linux/ext4_fs_sb.h
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -13,8 +13,8 @@
13 * Copyright (C) 1991, 1992 Linus Torvalds 13 * Copyright (C) 1991, 1992 Linus Torvalds
14 */ 14 */
15 15
16#ifndef _LINUX_EXT3_FS_SB 16#ifndef _LINUX_EXT4_FS_SB
17#define _LINUX_EXT3_FS_SB 17#define _LINUX_EXT4_FS_SB
18 18
19#ifdef __KERNEL__ 19#ifdef __KERNEL__
20#include <linux/timer.h> 20#include <linux/timer.h>
@@ -27,7 +27,7 @@
27/* 27/*
28 * third extended-fs super-block data in memory 28 * third extended-fs super-block data in memory
29 */ 29 */
30struct ext3_sb_info { 30struct ext4_sb_info {
31 unsigned long s_frag_size; /* Size of a fragment in bytes */ 31 unsigned long s_frag_size; /* Size of a fragment in bytes */
32 unsigned long s_frags_per_block;/* Number of fragments per block */ 32 unsigned long s_frags_per_block;/* Number of fragments per block */
33 unsigned long s_inodes_per_block;/* Number of inodes per block */ 33 unsigned long s_inodes_per_block;/* Number of inodes per block */
@@ -39,7 +39,7 @@ struct ext3_sb_info {
39 unsigned long s_desc_per_block; /* Number of group descriptors per block */ 39 unsigned long s_desc_per_block; /* Number of group descriptors per block */
40 unsigned long s_groups_count; /* Number of groups in the fs */ 40 unsigned long s_groups_count; /* Number of groups in the fs */
41 struct buffer_head * s_sbh; /* Buffer containing the super block */ 41 struct buffer_head * s_sbh; /* Buffer containing the super block */
42 struct ext3_super_block * s_es; /* Pointer to the super block in the buffer */ 42 struct ext4_super_block * s_es; /* Pointer to the super block in the buffer */
43 struct buffer_head ** s_group_desc; 43 struct buffer_head ** s_group_desc;
44 unsigned long s_mount_opt; 44 unsigned long s_mount_opt;
45 uid_t s_resuid; 45 uid_t s_resuid;
@@ -62,7 +62,7 @@ struct ext3_sb_info {
62 /* root of the per fs reservation window tree */ 62 /* root of the per fs reservation window tree */
63 spinlock_t s_rsv_window_lock; 63 spinlock_t s_rsv_window_lock;
64 struct rb_root s_rsv_window_root; 64 struct rb_root s_rsv_window_root;
65 struct ext3_reserve_window_node s_rsv_window_head; 65 struct ext4_reserve_window_node s_rsv_window_head;
66 66
67 /* Journaling */ 67 /* Journaling */
68 struct inode * s_journal_inode; 68 struct inode * s_journal_inode;
@@ -80,4 +80,4 @@ struct ext3_sb_info {
80#endif 80#endif
81}; 81};
82 82
83#endif /* _LINUX_EXT3_FS_SB */ 83#endif /* _LINUX_EXT4_FS_SB */
diff --git a/include/linux/ext4_jbd.h b/include/linux/ext4_jbd.h
index ce0e6109aff..3dbf6c77903 100644
--- a/include/linux/ext4_jbd.h
+++ b/include/linux/ext4_jbd.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/include/linux/ext3_jbd.h 2 * linux/include/linux/ext4_jbd.h
3 * 3 *
4 * Written by Stephen C. Tweedie <sct@redhat.com>, 1999 4 * Written by Stephen C. Tweedie <sct@redhat.com>, 1999
5 * 5 *
@@ -9,17 +9,17 @@
9 * the terms of the GNU General Public License, version 2, or at your 9 * the terms of the GNU General Public License, version 2, or at your
10 * option, any later version, incorporated herein by reference. 10 * option, any later version, incorporated herein by reference.
11 * 11 *
12 * Ext3-specific journaling extensions. 12 * Ext4-specific journaling extensions.
13 */ 13 */
14 14
15#ifndef _LINUX_EXT3_JBD_H 15#ifndef _LINUX_EXT4_JBD_H
16#define _LINUX_EXT3_JBD_H 16#define _LINUX_EXT4_JBD_H
17 17
18#include <linux/fs.h> 18#include <linux/fs.h>
19#include <linux/jbd.h> 19#include <linux/jbd.h>
20#include <linux/ext3_fs.h> 20#include <linux/ext4_fs.h>
21 21
22#define EXT3_JOURNAL(inode) (EXT3_SB((inode)->i_sb)->s_journal) 22#define EXT4_JOURNAL(inode) (EXT4_SB((inode)->i_sb)->s_journal)
23 23
24/* Define the number of blocks we need to account to a transaction to 24/* Define the number of blocks we need to account to a transaction to
25 * modify one block of data. 25 * modify one block of data.
@@ -28,13 +28,13 @@
28 * indirection blocks, the group and superblock summaries, and the data 28 * indirection blocks, the group and superblock summaries, and the data
29 * block to complete the transaction. */ 29 * block to complete the transaction. */
30 30
31#define EXT3_SINGLEDATA_TRANS_BLOCKS 8U 31#define EXT4_SINGLEDATA_TRANS_BLOCKS 8U
32 32
33/* Extended attribute operations touch at most two data buffers, 33/* Extended attribute operations touch at most two data buffers,
34 * two bitmap buffers, and two group summaries, in addition to the inode 34 * two bitmap buffers, and two group summaries, in addition to the inode
35 * and the superblock, which are already accounted for. */ 35 * and the superblock, which are already accounted for. */
36 36
37#define EXT3_XATTR_TRANS_BLOCKS 6U 37#define EXT4_XATTR_TRANS_BLOCKS 6U
38 38
39/* Define the minimum size for a transaction which modifies data. This 39/* Define the minimum size for a transaction which modifies data. This
40 * needs to take into account the fact that we may end up modifying two 40 * needs to take into account the fact that we may end up modifying two
@@ -42,15 +42,15 @@
42 * superblock only gets updated once, of course, so don't bother 42 * superblock only gets updated once, of course, so don't bother
43 * counting that again for the quota updates. */ 43 * counting that again for the quota updates. */
44 44
45#define EXT3_DATA_TRANS_BLOCKS(sb) (EXT3_SINGLEDATA_TRANS_BLOCKS + \ 45#define EXT4_DATA_TRANS_BLOCKS(sb) (EXT4_SINGLEDATA_TRANS_BLOCKS + \
46 EXT3_XATTR_TRANS_BLOCKS - 2 + \ 46 EXT4_XATTR_TRANS_BLOCKS - 2 + \
47 2*EXT3_QUOTA_TRANS_BLOCKS(sb)) 47 2*EXT4_QUOTA_TRANS_BLOCKS(sb))
48 48
49/* Delete operations potentially hit one directory's namespace plus an 49/* Delete operations potentially hit one directory's namespace plus an
50 * entire inode, plus arbitrary amounts of bitmap/indirection data. Be 50 * entire inode, plus arbitrary amounts of bitmap/indirection data. Be
51 * generous. We can grow the delete transaction later if necessary. */ 51 * generous. We can grow the delete transaction later if necessary. */
52 52
53#define EXT3_DELETE_TRANS_BLOCKS(sb) (2 * EXT3_DATA_TRANS_BLOCKS(sb) + 64) 53#define EXT4_DELETE_TRANS_BLOCKS(sb) (2 * EXT4_DATA_TRANS_BLOCKS(sb) + 64)
54 54
55/* Define an arbitrary limit for the amount of data we will anticipate 55/* Define an arbitrary limit for the amount of data we will anticipate
56 * writing to any given transaction. For unbounded transactions such as 56 * writing to any given transaction. For unbounded transactions such as
@@ -58,7 +58,7 @@
58 * start off at the maximum transaction size and grow the transaction 58 * start off at the maximum transaction size and grow the transaction
59 * optimistically as we go. */ 59 * optimistically as we go. */
60 60
61#define EXT3_MAX_TRANS_DATA 64U 61#define EXT4_MAX_TRANS_DATA 64U
62 62
63/* We break up a large truncate or write transaction once the handle's 63/* We break up a large truncate or write transaction once the handle's
64 * buffer credits gets this low, we need either to extend the 64 * buffer credits gets this low, we need either to extend the
@@ -67,202 +67,202 @@
67 * one block, plus two quota updates. Quota allocations are not 67 * one block, plus two quota updates. Quota allocations are not
68 * needed. */ 68 * needed. */
69 69
70#define EXT3_RESERVE_TRANS_BLOCKS 12U 70#define EXT4_RESERVE_TRANS_BLOCKS 12U
71 71
72#define EXT3_INDEX_EXTRA_TRANS_BLOCKS 8 72#define EXT4_INDEX_EXTRA_TRANS_BLOCKS 8
73 73
74#ifdef CONFIG_QUOTA 74#ifdef CONFIG_QUOTA
75/* Amount of blocks needed for quota update - we know that the structure was 75/* Amount of blocks needed for quota update - we know that the structure was
76 * allocated so we need to update only inode+data */ 76 * allocated so we need to update only inode+data */
77#define EXT3_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 2 : 0) 77#define EXT4_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 2 : 0)
78/* Amount of blocks needed for quota insert/delete - we do some block writes 78/* Amount of blocks needed for quota insert/delete - we do some block writes
79 * but inode, sb and group updates are done only once */ 79 * but inode, sb and group updates are done only once */
80#define EXT3_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\ 80#define EXT4_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\
81 (EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_INIT_REWRITE) : 0) 81 (EXT4_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_INIT_REWRITE) : 0)
82#define EXT3_QUOTA_DEL_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_DEL_ALLOC*\ 82#define EXT4_QUOTA_DEL_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_DEL_ALLOC*\
83 (EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_DEL_REWRITE) : 0) 83 (EXT4_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_DEL_REWRITE) : 0)
84#else 84#else
85#define EXT3_QUOTA_TRANS_BLOCKS(sb) 0 85#define EXT4_QUOTA_TRANS_BLOCKS(sb) 0
86#define EXT3_QUOTA_INIT_BLOCKS(sb) 0 86#define EXT4_QUOTA_INIT_BLOCKS(sb) 0
87#define EXT3_QUOTA_DEL_BLOCKS(sb) 0 87#define EXT4_QUOTA_DEL_BLOCKS(sb) 0
88#endif 88#endif
89 89
90int 90int
91ext3_mark_iloc_dirty(handle_t *handle, 91ext4_mark_iloc_dirty(handle_t *handle,
92 struct inode *inode, 92 struct inode *inode,
93 struct ext3_iloc *iloc); 93 struct ext4_iloc *iloc);
94 94
95/* 95/*
96 * On success, We end up with an outstanding reference count against 96 * On success, We end up with an outstanding reference count against
97 * iloc->bh. This _must_ be cleaned up later. 97 * iloc->bh. This _must_ be cleaned up later.
98 */ 98 */
99 99
100int ext3_reserve_inode_write(handle_t *handle, struct inode *inode, 100int ext4_reserve_inode_write(handle_t *handle, struct inode *inode,
101 struct ext3_iloc *iloc); 101 struct ext4_iloc *iloc);
102 102
103int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode); 103int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode);
104 104
105/* 105/*
106 * Wrapper functions with which ext3 calls into JBD. The intent here is 106 * Wrapper functions with which ext4 calls into JBD. The intent here is
107 * to allow these to be turned into appropriate stubs so ext3 can control 107 * to allow these to be turned into appropriate stubs so ext4 can control
108 * ext2 filesystems, so ext2+ext3 systems only nee one fs. This work hasn't 108 * ext2 filesystems, so ext2+ext4 systems only nee one fs. This work hasn't
109 * been done yet. 109 * been done yet.
110 */ 110 */
111 111
112void ext3_journal_abort_handle(const char *caller, const char *err_fn, 112void ext4_journal_abort_handle(const char *caller, const char *err_fn,
113 struct buffer_head *bh, handle_t *handle, int err); 113 struct buffer_head *bh, handle_t *handle, int err);
114 114
115static inline int 115static inline int
116__ext3_journal_get_undo_access(const char *where, handle_t *handle, 116__ext4_journal_get_undo_access(const char *where, handle_t *handle,
117 struct buffer_head *bh) 117 struct buffer_head *bh)
118{ 118{
119 int err = journal_get_undo_access(handle, bh); 119 int err = journal_get_undo_access(handle, bh);
120 if (err) 120 if (err)
121 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err); 121 ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
122 return err; 122 return err;
123} 123}
124 124
125static inline int 125static inline int
126__ext3_journal_get_write_access(const char *where, handle_t *handle, 126__ext4_journal_get_write_access(const char *where, handle_t *handle,
127 struct buffer_head *bh) 127 struct buffer_head *bh)
128{ 128{
129 int err = journal_get_write_access(handle, bh); 129 int err = journal_get_write_access(handle, bh);
130 if (err) 130 if (err)
131 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err); 131 ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
132 return err; 132 return err;
133} 133}
134 134
135static inline void 135static inline void
136ext3_journal_release_buffer(handle_t *handle, struct buffer_head *bh) 136ext4_journal_release_buffer(handle_t *handle, struct buffer_head *bh)
137{ 137{
138 journal_release_buffer(handle, bh); 138 journal_release_buffer(handle, bh);
139} 139}
140 140
141static inline int 141static inline int
142__ext3_journal_forget(const char *where, handle_t *handle, struct buffer_head *bh) 142__ext4_journal_forget(const char *where, handle_t *handle, struct buffer_head *bh)
143{ 143{
144 int err = journal_forget(handle, bh); 144 int err = journal_forget(handle, bh);
145 if (err) 145 if (err)
146 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err); 146 ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
147 return err; 147 return err;
148} 148}
149 149
150static inline int 150static inline int
151__ext3_journal_revoke(const char *where, handle_t *handle, 151__ext4_journal_revoke(const char *where, handle_t *handle,
152 unsigned long blocknr, struct buffer_head *bh) 152 unsigned long blocknr, struct buffer_head *bh)
153{ 153{
154 int err = journal_revoke(handle, blocknr, bh); 154 int err = journal_revoke(handle, blocknr, bh);
155 if (err) 155 if (err)
156 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err); 156 ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
157 return err; 157 return err;
158} 158}
159 159
160static inline int 160static inline int
161__ext3_journal_get_create_access(const char *where, 161__ext4_journal_get_create_access(const char *where,
162 handle_t *handle, struct buffer_head *bh) 162 handle_t *handle, struct buffer_head *bh)
163{ 163{
164 int err = journal_get_create_access(handle, bh); 164 int err = journal_get_create_access(handle, bh);
165 if (err) 165 if (err)
166 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err); 166 ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
167 return err; 167 return err;
168} 168}
169 169
170static inline int 170static inline int
171__ext3_journal_dirty_metadata(const char *where, 171__ext4_journal_dirty_metadata(const char *where,
172 handle_t *handle, struct buffer_head *bh) 172 handle_t *handle, struct buffer_head *bh)
173{ 173{
174 int err = journal_dirty_metadata(handle, bh); 174 int err = journal_dirty_metadata(handle, bh);
175 if (err) 175 if (err)
176 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err); 176 ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
177 return err; 177 return err;
178} 178}
179 179
180 180
181#define ext3_journal_get_undo_access(handle, bh) \ 181#define ext4_journal_get_undo_access(handle, bh) \
182 __ext3_journal_get_undo_access(__FUNCTION__, (handle), (bh)) 182 __ext4_journal_get_undo_access(__FUNCTION__, (handle), (bh))
183#define ext3_journal_get_write_access(handle, bh) \ 183#define ext4_journal_get_write_access(handle, bh) \
184 __ext3_journal_get_write_access(__FUNCTION__, (handle), (bh)) 184 __ext4_journal_get_write_access(__FUNCTION__, (handle), (bh))
185#define ext3_journal_revoke(handle, blocknr, bh) \ 185#define ext4_journal_revoke(handle, blocknr, bh) \
186 __ext3_journal_revoke(__FUNCTION__, (handle), (blocknr), (bh)) 186 __ext4_journal_revoke(__FUNCTION__, (handle), (blocknr), (bh))
187#define ext3_journal_get_create_access(handle, bh) \ 187#define ext4_journal_get_create_access(handle, bh) \
188 __ext3_journal_get_create_access(__FUNCTION__, (handle), (bh)) 188 __ext4_journal_get_create_access(__FUNCTION__, (handle), (bh))
189#define ext3_journal_dirty_metadata(handle, bh) \ 189#define ext4_journal_dirty_metadata(handle, bh) \
190 __ext3_journal_dirty_metadata(__FUNCTION__, (handle), (bh)) 190 __ext4_journal_dirty_metadata(__FUNCTION__, (handle), (bh))
191#define ext3_journal_forget(handle, bh) \ 191#define ext4_journal_forget(handle, bh) \
192 __ext3_journal_forget(__FUNCTION__, (handle), (bh)) 192 __ext4_journal_forget(__FUNCTION__, (handle), (bh))
193 193
194int ext3_journal_dirty_data(handle_t *handle, struct buffer_head *bh); 194int ext4_journal_dirty_data(handle_t *handle, struct buffer_head *bh);
195 195
196handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks); 196handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks);
197int __ext3_journal_stop(const char *where, handle_t *handle); 197int __ext4_journal_stop(const char *where, handle_t *handle);
198 198
199static inline handle_t *ext3_journal_start(struct inode *inode, int nblocks) 199static inline handle_t *ext4_journal_start(struct inode *inode, int nblocks)
200{ 200{
201 return ext3_journal_start_sb(inode->i_sb, nblocks); 201 return ext4_journal_start_sb(inode->i_sb, nblocks);
202} 202}
203 203
204#define ext3_journal_stop(handle) \ 204#define ext4_journal_stop(handle) \
205 __ext3_journal_stop(__FUNCTION__, (handle)) 205 __ext4_journal_stop(__FUNCTION__, (handle))
206 206
207static inline handle_t *ext3_journal_current_handle(void) 207static inline handle_t *ext4_journal_current_handle(void)
208{ 208{
209 return journal_current_handle(); 209 return journal_current_handle();
210} 210}
211 211
212static inline int ext3_journal_extend(handle_t *handle, int nblocks) 212static inline int ext4_journal_extend(handle_t *handle, int nblocks)
213{ 213{
214 return journal_extend(handle, nblocks); 214 return journal_extend(handle, nblocks);
215} 215}
216 216
217static inline int ext3_journal_restart(handle_t *handle, int nblocks) 217static inline int ext4_journal_restart(handle_t *handle, int nblocks)
218{ 218{
219 return journal_restart(handle, nblocks); 219 return journal_restart(handle, nblocks);
220} 220}
221 221
222static inline int ext3_journal_blocks_per_page(struct inode *inode) 222static inline int ext4_journal_blocks_per_page(struct inode *inode)
223{ 223{
224 return journal_blocks_per_page(inode); 224 return journal_blocks_per_page(inode);
225} 225}
226 226
227static inline int ext3_journal_force_commit(journal_t *journal) 227static inline int ext4_journal_force_commit(journal_t *journal)
228{ 228{
229 return journal_force_commit(journal); 229 return journal_force_commit(journal);
230} 230}
231 231
232/* super.c */ 232/* super.c */
233int ext3_force_commit(struct super_block *sb); 233int ext4_force_commit(struct super_block *sb);
234 234
235static inline int ext3_should_journal_data(struct inode *inode) 235static inline int ext4_should_journal_data(struct inode *inode)
236{ 236{
237 if (!S_ISREG(inode->i_mode)) 237 if (!S_ISREG(inode->i_mode))
238 return 1; 238 return 1;
239 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA) 239 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
240 return 1; 240 return 1;
241 if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL) 241 if (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL)
242 return 1; 242 return 1;
243 return 0; 243 return 0;
244} 244}
245 245
246static inline int ext3_should_order_data(struct inode *inode) 246static inline int ext4_should_order_data(struct inode *inode)
247{ 247{
248 if (!S_ISREG(inode->i_mode)) 248 if (!S_ISREG(inode->i_mode))
249 return 0; 249 return 0;
250 if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL) 250 if (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL)
251 return 0; 251 return 0;
252 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA) 252 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
253 return 1; 253 return 1;
254 return 0; 254 return 0;
255} 255}
256 256
257static inline int ext3_should_writeback_data(struct inode *inode) 257static inline int ext4_should_writeback_data(struct inode *inode)
258{ 258{
259 if (!S_ISREG(inode->i_mode)) 259 if (!S_ISREG(inode->i_mode))
260 return 0; 260 return 0;
261 if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL) 261 if (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL)
262 return 0; 262 return 0;
263 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_WRITEBACK_DATA) 263 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
264 return 1; 264 return 1;
265 return 0; 265 return 0;
266} 266}
267 267
268#endif /* _LINUX_EXT3_JBD_H */ 268#endif /* _LINUX_EXT4_JBD_H */