提交 617ba13b 编写于 作者: M Mingming Cao 提交者: Linus Torvalds

[PATCH] ext4: rename ext4 symbols to avoid duplication of ext3 symbols

Mingming Cao originally did this work, and Shaggy reproduced it using some
scripts from her.
Signed-off-by: NMingming Cao <cmm@us.ibm.com>
Signed-off-by: NDave Kleikamp <shaggy@austin.ibm.com>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 ac27a0ec
# #
# Makefile for the linux ext3-filesystem routines. # Makefile for the linux ext4-filesystem routines.
# #
obj-$(CONFIG_EXT3_FS) += ext3.o obj-$(CONFIG_EXT4DEV_FS) += ext4dev.o
ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \ ext4dev-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
ioctl.o namei.o super.o symlink.o hash.o resize.o ioctl.o namei.o super.o symlink.o hash.o resize.o
ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o ext4dev-$(CONFIG_EXT4DEV_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o ext4dev-$(CONFIG_EXT4DEV_FS_POSIX_ACL) += acl.o
ext3-$(CONFIG_EXT3_FS_SECURITY) += xattr_security.o ext4dev-$(CONFIG_EXT4DEV_FS_SECURITY) += xattr_security.o
/* /*
* linux/fs/ext3/acl.c * linux/fs/ext4/acl.c
* *
* Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de> * Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de>
*/ */
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/ext3_jbd.h> #include <linux/ext4_jbd.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#include "xattr.h" #include "xattr.h"
#include "acl.h" #include "acl.h"
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* Convert from filesystem to in-memory representation. * Convert from filesystem to in-memory representation.
*/ */
static struct posix_acl * static struct posix_acl *
ext3_acl_from_disk(const void *value, size_t size) ext4_acl_from_disk(const void *value, size_t size)
{ {
const char *end = (char *)value + size; const char *end = (char *)value + size;
int n, count; int n, count;
...@@ -26,13 +26,13 @@ ext3_acl_from_disk(const void *value, size_t size) ...@@ -26,13 +26,13 @@ ext3_acl_from_disk(const void *value, size_t size)
if (!value) if (!value)
return NULL; return NULL;
if (size < sizeof(ext3_acl_header)) if (size < sizeof(ext4_acl_header))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
if (((ext3_acl_header *)value)->a_version != if (((ext4_acl_header *)value)->a_version !=
cpu_to_le32(EXT3_ACL_VERSION)) cpu_to_le32(EXT4_ACL_VERSION))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
value = (char *)value + sizeof(ext3_acl_header); value = (char *)value + sizeof(ext4_acl_header);
count = ext3_acl_count(size); count = ext4_acl_count(size);
if (count < 0) if (count < 0)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
if (count == 0) if (count == 0)
...@@ -41,9 +41,9 @@ ext3_acl_from_disk(const void *value, size_t size) ...@@ -41,9 +41,9 @@ ext3_acl_from_disk(const void *value, size_t size)
if (!acl) if (!acl)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
for (n=0; n < count; n++) { for (n=0; n < count; n++) {
ext3_acl_entry *entry = ext4_acl_entry *entry =
(ext3_acl_entry *)value; (ext4_acl_entry *)value;
if ((char *)value + sizeof(ext3_acl_entry_short) > end) if ((char *)value + sizeof(ext4_acl_entry_short) > end)
goto fail; goto fail;
acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag); acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag);
acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm); 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,13 +53,13 @@ ext3_acl_from_disk(const void *value, size_t size)
case ACL_MASK: case ACL_MASK:
case ACL_OTHER: case ACL_OTHER:
value = (char *)value + value = (char *)value +
sizeof(ext3_acl_entry_short); sizeof(ext4_acl_entry_short);
acl->a_entries[n].e_id = ACL_UNDEFINED_ID; acl->a_entries[n].e_id = ACL_UNDEFINED_ID;
break; break;
case ACL_USER: case ACL_USER:
case ACL_GROUP: case ACL_GROUP:
value = (char *)value + sizeof(ext3_acl_entry); value = (char *)value + sizeof(ext4_acl_entry);
if ((char *)value > end) if ((char *)value > end)
goto fail; goto fail;
acl->a_entries[n].e_id = acl->a_entries[n].e_id =
...@@ -83,21 +83,21 @@ ext3_acl_from_disk(const void *value, size_t size) ...@@ -83,21 +83,21 @@ ext3_acl_from_disk(const void *value, size_t size)
* Convert from in-memory to filesystem representation. * Convert from in-memory to filesystem representation.
*/ */
static void * static void *
ext3_acl_to_disk(const struct posix_acl *acl, size_t *size) ext4_acl_to_disk(const struct posix_acl *acl, size_t *size)
{ {
ext3_acl_header *ext_acl; ext4_acl_header *ext_acl;
char *e; char *e;
size_t n; size_t n;
*size = ext3_acl_size(acl->a_count); *size = ext4_acl_size(acl->a_count);
ext_acl = kmalloc(sizeof(ext3_acl_header) + acl->a_count * ext_acl = kmalloc(sizeof(ext4_acl_header) + acl->a_count *
sizeof(ext3_acl_entry), GFP_KERNEL); sizeof(ext4_acl_entry), GFP_KERNEL);
if (!ext_acl) if (!ext_acl)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
ext_acl->a_version = cpu_to_le32(EXT3_ACL_VERSION); ext_acl->a_version = cpu_to_le32(EXT4_ACL_VERSION);
e = (char *)ext_acl + sizeof(ext3_acl_header); e = (char *)ext_acl + sizeof(ext4_acl_header);
for (n=0; n < acl->a_count; n++) { for (n=0; n < acl->a_count; n++) {
ext3_acl_entry *entry = (ext3_acl_entry *)e; ext4_acl_entry *entry = (ext4_acl_entry *)e;
entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag); entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag);
entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm); entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm);
switch(acl->a_entries[n].e_tag) { switch(acl->a_entries[n].e_tag) {
...@@ -105,14 +105,14 @@ ext3_acl_to_disk(const struct posix_acl *acl, size_t *size) ...@@ -105,14 +105,14 @@ ext3_acl_to_disk(const struct posix_acl *acl, size_t *size)
case ACL_GROUP: case ACL_GROUP:
entry->e_id = entry->e_id =
cpu_to_le32(acl->a_entries[n].e_id); cpu_to_le32(acl->a_entries[n].e_id);
e += sizeof(ext3_acl_entry); e += sizeof(ext4_acl_entry);
break; break;
case ACL_USER_OBJ: case ACL_USER_OBJ:
case ACL_GROUP_OBJ: case ACL_GROUP_OBJ:
case ACL_MASK: case ACL_MASK:
case ACL_OTHER: case ACL_OTHER:
e += sizeof(ext3_acl_entry_short); e += sizeof(ext4_acl_entry_short);
break; break;
default: default:
...@@ -127,12 +127,12 @@ ext3_acl_to_disk(const struct posix_acl *acl, size_t *size) ...@@ -127,12 +127,12 @@ ext3_acl_to_disk(const struct posix_acl *acl, size_t *size)
} }
static inline struct posix_acl * static inline struct posix_acl *
ext3_iget_acl(struct inode *inode, struct posix_acl **i_acl) ext4_iget_acl(struct inode *inode, struct posix_acl **i_acl)
{ {
struct posix_acl *acl = EXT3_ACL_NOT_CACHED; struct posix_acl *acl = EXT4_ACL_NOT_CACHED;
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
if (*i_acl != EXT3_ACL_NOT_CACHED) if (*i_acl != EXT4_ACL_NOT_CACHED)
acl = posix_acl_dup(*i_acl); acl = posix_acl_dup(*i_acl);
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
...@@ -140,11 +140,11 @@ ext3_iget_acl(struct inode *inode, struct posix_acl **i_acl) ...@@ -140,11 +140,11 @@ ext3_iget_acl(struct inode *inode, struct posix_acl **i_acl)
} }
static inline void static inline void
ext3_iset_acl(struct inode *inode, struct posix_acl **i_acl, ext4_iset_acl(struct inode *inode, struct posix_acl **i_acl,
struct posix_acl *acl) struct posix_acl *acl)
{ {
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
if (*i_acl != EXT3_ACL_NOT_CACHED) if (*i_acl != EXT4_ACL_NOT_CACHED)
posix_acl_release(*i_acl); posix_acl_release(*i_acl);
*i_acl = posix_acl_dup(acl); *i_acl = posix_acl_dup(acl);
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
...@@ -156,9 +156,9 @@ ext3_iset_acl(struct inode *inode, struct posix_acl **i_acl, ...@@ -156,9 +156,9 @@ ext3_iset_acl(struct inode *inode, struct posix_acl **i_acl,
* inode->i_mutex: don't care * inode->i_mutex: don't care
*/ */
static struct posix_acl * static struct posix_acl *
ext3_get_acl(struct inode *inode, int type) ext4_get_acl(struct inode *inode, int type)
{ {
struct ext3_inode_info *ei = EXT3_I(inode); struct ext4_inode_info *ei = EXT4_I(inode);
int name_index; int name_index;
char *value = NULL; char *value = NULL;
struct posix_acl *acl; struct posix_acl *acl;
...@@ -169,31 +169,31 @@ ext3_get_acl(struct inode *inode, int type) ...@@ -169,31 +169,31 @@ ext3_get_acl(struct inode *inode, int type)
switch(type) { switch(type) {
case ACL_TYPE_ACCESS: case ACL_TYPE_ACCESS:
acl = ext3_iget_acl(inode, &ei->i_acl); acl = ext4_iget_acl(inode, &ei->i_acl);
if (acl != EXT3_ACL_NOT_CACHED) if (acl != EXT4_ACL_NOT_CACHED)
return acl; return acl;
name_index = EXT3_XATTR_INDEX_POSIX_ACL_ACCESS; name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS;
break; break;
case ACL_TYPE_DEFAULT: case ACL_TYPE_DEFAULT:
acl = ext3_iget_acl(inode, &ei->i_default_acl); acl = ext4_iget_acl(inode, &ei->i_default_acl);
if (acl != EXT3_ACL_NOT_CACHED) if (acl != EXT4_ACL_NOT_CACHED)
return acl; return acl;
name_index = EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT; name_index = EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT;
break; break;
default: default:
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
retval = ext3_xattr_get(inode, name_index, "", NULL, 0); retval = ext4_xattr_get(inode, name_index, "", NULL, 0);
if (retval > 0) { if (retval > 0) {
value = kmalloc(retval, GFP_KERNEL); value = kmalloc(retval, GFP_KERNEL);
if (!value) if (!value)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
retval = ext3_xattr_get(inode, name_index, "", value, retval); retval = ext4_xattr_get(inode, name_index, "", value, retval);
} }
if (retval > 0) if (retval > 0)
acl = ext3_acl_from_disk(value, retval); acl = ext4_acl_from_disk(value, retval);
else if (retval == -ENODATA || retval == -ENOSYS) else if (retval == -ENODATA || retval == -ENOSYS)
acl = NULL; acl = NULL;
else else
...@@ -203,11 +203,11 @@ ext3_get_acl(struct inode *inode, int type) ...@@ -203,11 +203,11 @@ ext3_get_acl(struct inode *inode, int type)
if (!IS_ERR(acl)) { if (!IS_ERR(acl)) {
switch(type) { switch(type) {
case ACL_TYPE_ACCESS: case ACL_TYPE_ACCESS:
ext3_iset_acl(inode, &ei->i_acl, acl); ext4_iset_acl(inode, &ei->i_acl, acl);
break; break;
case ACL_TYPE_DEFAULT: case ACL_TYPE_DEFAULT:
ext3_iset_acl(inode, &ei->i_default_acl, acl); ext4_iset_acl(inode, &ei->i_default_acl, acl);
break; break;
} }
} }
...@@ -217,13 +217,13 @@ ext3_get_acl(struct inode *inode, int type) ...@@ -217,13 +217,13 @@ ext3_get_acl(struct inode *inode, int type)
/* /*
* Set the access or default ACL of an inode. * Set the access or default ACL of an inode.
* *
* inode->i_mutex: down unless called from ext3_new_inode * inode->i_mutex: down unless called from ext4_new_inode
*/ */
static int static int
ext3_set_acl(handle_t *handle, struct inode *inode, int type, ext4_set_acl(handle_t *handle, struct inode *inode, int type,
struct posix_acl *acl) struct posix_acl *acl)
{ {
struct ext3_inode_info *ei = EXT3_I(inode); struct ext4_inode_info *ei = EXT4_I(inode);
int name_index; int name_index;
void *value = NULL; void *value = NULL;
size_t size = 0; size_t size = 0;
...@@ -234,7 +234,7 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type, ...@@ -234,7 +234,7 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
switch(type) { switch(type) {
case ACL_TYPE_ACCESS: case ACL_TYPE_ACCESS:
name_index = EXT3_XATTR_INDEX_POSIX_ACL_ACCESS; name_index = EXT4_XATTR_INDEX_POSIX_ACL_ACCESS;
if (acl) { if (acl) {
mode_t mode = inode->i_mode; mode_t mode = inode->i_mode;
error = posix_acl_equiv_mode(acl, &mode); error = posix_acl_equiv_mode(acl, &mode);
...@@ -242,7 +242,7 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type, ...@@ -242,7 +242,7 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
return error; return error;
else { else {
inode->i_mode = mode; inode->i_mode = mode;
ext3_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
if (error == 0) if (error == 0)
acl = NULL; acl = NULL;
} }
...@@ -250,7 +250,7 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type, ...@@ -250,7 +250,7 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
break; break;
case ACL_TYPE_DEFAULT: case ACL_TYPE_DEFAULT:
name_index = EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT; name_index = EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT;
if (!S_ISDIR(inode->i_mode)) if (!S_ISDIR(inode->i_mode))
return acl ? -EACCES : 0; return acl ? -EACCES : 0;
break; break;
...@@ -259,23 +259,23 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type, ...@@ -259,23 +259,23 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
return -EINVAL; return -EINVAL;
} }
if (acl) { if (acl) {
value = ext3_acl_to_disk(acl, &size); value = ext4_acl_to_disk(acl, &size);
if (IS_ERR(value)) if (IS_ERR(value))
return (int)PTR_ERR(value); return (int)PTR_ERR(value);
} }
error = ext3_xattr_set_handle(handle, inode, name_index, "", error = ext4_xattr_set_handle(handle, inode, name_index, "",
value, size, 0); value, size, 0);
kfree(value); kfree(value);
if (!error) { if (!error) {
switch(type) { switch(type) {
case ACL_TYPE_ACCESS: case ACL_TYPE_ACCESS:
ext3_iset_acl(inode, &ei->i_acl, acl); ext4_iset_acl(inode, &ei->i_acl, acl);
break; break;
case ACL_TYPE_DEFAULT: case ACL_TYPE_DEFAULT:
ext3_iset_acl(inode, &ei->i_default_acl, acl); ext4_iset_acl(inode, &ei->i_default_acl, acl);
break; break;
} }
} }
...@@ -283,9 +283,9 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type, ...@@ -283,9 +283,9 @@ ext3_set_acl(handle_t *handle, struct inode *inode, int type,
} }
static int static int
ext3_check_acl(struct inode *inode, int mask) ext4_check_acl(struct inode *inode, int mask)
{ {
struct posix_acl *acl = ext3_get_acl(inode, ACL_TYPE_ACCESS); struct posix_acl *acl = ext4_get_acl(inode, ACL_TYPE_ACCESS);
if (IS_ERR(acl)) if (IS_ERR(acl))
return PTR_ERR(acl); return PTR_ERR(acl);
...@@ -299,26 +299,26 @@ ext3_check_acl(struct inode *inode, int mask) ...@@ -299,26 +299,26 @@ ext3_check_acl(struct inode *inode, int mask)
} }
int int
ext3_permission(struct inode *inode, int mask, struct nameidata *nd) ext4_permission(struct inode *inode, int mask, struct nameidata *nd)
{ {
return generic_permission(inode, mask, ext3_check_acl); return generic_permission(inode, mask, ext4_check_acl);
} }
/* /*
* Initialize the ACLs of a new inode. Called from ext3_new_inode. * Initialize the ACLs of a new inode. Called from ext4_new_inode.
* *
* dir->i_mutex: down * dir->i_mutex: down
* inode->i_mutex: up (access to inode is still exclusive) * inode->i_mutex: up (access to inode is still exclusive)
*/ */
int int
ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir) ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
{ {
struct posix_acl *acl = NULL; struct posix_acl *acl = NULL;
int error = 0; int error = 0;
if (!S_ISLNK(inode->i_mode)) { if (!S_ISLNK(inode->i_mode)) {
if (test_opt(dir->i_sb, POSIX_ACL)) { if (test_opt(dir->i_sb, POSIX_ACL)) {
acl = ext3_get_acl(dir, ACL_TYPE_DEFAULT); acl = ext4_get_acl(dir, ACL_TYPE_DEFAULT);
if (IS_ERR(acl)) if (IS_ERR(acl))
return PTR_ERR(acl); return PTR_ERR(acl);
} }
...@@ -330,7 +330,7 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir) ...@@ -330,7 +330,7 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
mode_t mode; mode_t mode;
if (S_ISDIR(inode->i_mode)) { if (S_ISDIR(inode->i_mode)) {
error = ext3_set_acl(handle, inode, error = ext4_set_acl(handle, inode,
ACL_TYPE_DEFAULT, acl); ACL_TYPE_DEFAULT, acl);
if (error) if (error)
goto cleanup; goto cleanup;
...@@ -346,7 +346,7 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir) ...@@ -346,7 +346,7 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
inode->i_mode = mode; inode->i_mode = mode;
if (error > 0) { if (error > 0) {
/* This is an extended ACL */ /* This is an extended ACL */
error = ext3_set_acl(handle, inode, error = ext4_set_acl(handle, inode,
ACL_TYPE_ACCESS, clone); ACL_TYPE_ACCESS, clone);
} }
} }
...@@ -372,7 +372,7 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir) ...@@ -372,7 +372,7 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
* inode->i_mutex: down * inode->i_mutex: down
*/ */
int int
ext3_acl_chmod(struct inode *inode) ext4_acl_chmod(struct inode *inode)
{ {
struct posix_acl *acl, *clone; struct posix_acl *acl, *clone;
int error; int error;
...@@ -381,7 +381,7 @@ ext3_acl_chmod(struct inode *inode) ...@@ -381,7 +381,7 @@ ext3_acl_chmod(struct inode *inode)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (!test_opt(inode->i_sb, POSIX_ACL)) if (!test_opt(inode->i_sb, POSIX_ACL))
return 0; return 0;
acl = ext3_get_acl(inode, ACL_TYPE_ACCESS); acl = ext4_get_acl(inode, ACL_TYPE_ACCESS);
if (IS_ERR(acl) || !acl) if (IS_ERR(acl) || !acl)
return PTR_ERR(acl); return PTR_ERR(acl);
clone = posix_acl_clone(acl, GFP_KERNEL); clone = posix_acl_clone(acl, GFP_KERNEL);
...@@ -394,17 +394,17 @@ ext3_acl_chmod(struct inode *inode) ...@@ -394,17 +394,17 @@ ext3_acl_chmod(struct inode *inode)
int retries = 0; int retries = 0;
retry: retry:
handle = ext3_journal_start(inode, handle = ext4_journal_start(inode,
EXT3_DATA_TRANS_BLOCKS(inode->i_sb)); EXT4_DATA_TRANS_BLOCKS(inode->i_sb));
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
error = PTR_ERR(handle); error = PTR_ERR(handle);
ext3_std_error(inode->i_sb, error); ext4_std_error(inode->i_sb, error);
goto out; goto out;
} }
error = ext3_set_acl(handle, inode, ACL_TYPE_ACCESS, clone); error = ext4_set_acl(handle, inode, ACL_TYPE_ACCESS, clone);
ext3_journal_stop(handle); ext4_journal_stop(handle);
if (error == -ENOSPC && if (error == -ENOSPC &&
ext3_should_retry_alloc(inode->i_sb, &retries)) ext4_should_retry_alloc(inode->i_sb, &retries))
goto retry; goto retry;
} }
out: out:
...@@ -416,7 +416,7 @@ ext3_acl_chmod(struct inode *inode) ...@@ -416,7 +416,7 @@ ext3_acl_chmod(struct inode *inode)
* Extended attribute handlers * Extended attribute handlers
*/ */
static size_t static size_t
ext3_xattr_list_acl_access(struct inode *inode, char *list, size_t list_len, ext4_xattr_list_acl_access(struct inode *inode, char *list, size_t list_len,
const char *name, size_t name_len) const char *name, size_t name_len)
{ {
const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS); 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,7 +429,7 @@ ext3_xattr_list_acl_access(struct inode *inode, char *list, size_t list_len,
} }
static size_t static size_t
ext3_xattr_list_acl_default(struct inode *inode, char *list, size_t list_len, ext4_xattr_list_acl_default(struct inode *inode, char *list, size_t list_len,
const char *name, size_t name_len) const char *name, size_t name_len)
{ {
const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT); 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,7 +442,7 @@ ext3_xattr_list_acl_default(struct inode *inode, char *list, size_t list_len,
} }
static int static int
ext3_xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size) ext4_xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size)
{ {
struct posix_acl *acl; struct posix_acl *acl;
int error; int error;
...@@ -450,7 +450,7 @@ ext3_xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size) ...@@ -450,7 +450,7 @@ ext3_xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size)
if (!test_opt(inode->i_sb, POSIX_ACL)) if (!test_opt(inode->i_sb, POSIX_ACL))
return -EOPNOTSUPP; return -EOPNOTSUPP;
acl = ext3_get_acl(inode, type); acl = ext4_get_acl(inode, type);
if (IS_ERR(acl)) if (IS_ERR(acl))
return PTR_ERR(acl); return PTR_ERR(acl);
if (acl == NULL) if (acl == NULL)
...@@ -462,25 +462,25 @@ ext3_xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size) ...@@ -462,25 +462,25 @@ ext3_xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size)
} }
static int static int
ext3_xattr_get_acl_access(struct inode *inode, const char *name, ext4_xattr_get_acl_access(struct inode *inode, const char *name,
void *buffer, size_t size) void *buffer, size_t size)
{ {
if (strcmp(name, "") != 0) if (strcmp(name, "") != 0)
return -EINVAL; return -EINVAL;
return ext3_xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size); return ext4_xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size);
} }
static int static int
ext3_xattr_get_acl_default(struct inode *inode, const char *name, ext4_xattr_get_acl_default(struct inode *inode, const char *name,
void *buffer, size_t size) void *buffer, size_t size)
{ {
if (strcmp(name, "") != 0) if (strcmp(name, "") != 0)
return -EINVAL; return -EINVAL;
return ext3_xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size); return ext4_xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size);
} }
static int static int
ext3_xattr_set_acl(struct inode *inode, int type, const void *value, ext4_xattr_set_acl(struct inode *inode, int type, const void *value,
size_t size) size_t size)
{ {
handle_t *handle; handle_t *handle;
...@@ -505,12 +505,12 @@ ext3_xattr_set_acl(struct inode *inode, int type, const void *value, ...@@ -505,12 +505,12 @@ ext3_xattr_set_acl(struct inode *inode, int type, const void *value,
acl = NULL; acl = NULL;
retry: retry:
handle = ext3_journal_start(inode, EXT3_DATA_TRANS_BLOCKS(inode->i_sb)); handle = ext4_journal_start(inode, EXT4_DATA_TRANS_BLOCKS(inode->i_sb));
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
error = ext3_set_acl(handle, inode, type, acl); error = ext4_set_acl(handle, inode, type, acl);
ext3_journal_stop(handle); ext4_journal_stop(handle);
if (error == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries)) if (error == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
goto retry; goto retry;
release_and_out: release_and_out:
...@@ -519,33 +519,33 @@ ext3_xattr_set_acl(struct inode *inode, int type, const void *value, ...@@ -519,33 +519,33 @@ ext3_xattr_set_acl(struct inode *inode, int type, const void *value,
} }
static int static int
ext3_xattr_set_acl_access(struct inode *inode, const char *name, ext4_xattr_set_acl_access(struct inode *inode, const char *name,
const void *value, size_t size, int flags) const void *value, size_t size, int flags)
{ {
if (strcmp(name, "") != 0) if (strcmp(name, "") != 0)
return -EINVAL; return -EINVAL;
return ext3_xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size); return ext4_xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size);
} }
static int static int
ext3_xattr_set_acl_default(struct inode *inode, const char *name, ext4_xattr_set_acl_default(struct inode *inode, const char *name,
const void *value, size_t size, int flags) const void *value, size_t size, int flags)
{ {
if (strcmp(name, "") != 0) if (strcmp(name, "") != 0)
return -EINVAL; return -EINVAL;
return ext3_xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size); return ext4_xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size);
} }
struct xattr_handler ext3_xattr_acl_access_handler = { struct xattr_handler ext4_xattr_acl_access_handler = {
.prefix = POSIX_ACL_XATTR_ACCESS, .prefix = POSIX_ACL_XATTR_ACCESS,
.list = ext3_xattr_list_acl_access, .list = ext4_xattr_list_acl_access,
.get = ext3_xattr_get_acl_access, .get = ext4_xattr_get_acl_access,
.set = ext3_xattr_set_acl_access, .set = ext4_xattr_set_acl_access,
}; };
struct xattr_handler ext3_xattr_acl_default_handler = { struct xattr_handler ext4_xattr_acl_default_handler = {
.prefix = POSIX_ACL_XATTR_DEFAULT, .prefix = POSIX_ACL_XATTR_DEFAULT,
.list = ext3_xattr_list_acl_default, .list = ext4_xattr_list_acl_default,
.get = ext3_xattr_get_acl_default, .get = ext4_xattr_get_acl_default,
.set = ext3_xattr_set_acl_default, .set = ext4_xattr_set_acl_default,
}; };
/* /*
File: fs/ext3/acl.h File: fs/ext4/acl.h
(C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org> (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
*/ */
#include <linux/posix_acl_xattr.h> #include <linux/posix_acl_xattr.h>
#define EXT3_ACL_VERSION 0x0001 #define EXT4_ACL_VERSION 0x0001
typedef struct { typedef struct {
__le16 e_tag; __le16 e_tag;
__le16 e_perm; __le16 e_perm;
__le32 e_id; __le32 e_id;
} ext3_acl_entry; } ext4_acl_entry;
typedef struct { typedef struct {
__le16 e_tag; __le16 e_tag;
__le16 e_perm; __le16 e_perm;
} ext3_acl_entry_short; } ext4_acl_entry_short;
typedef struct { typedef struct {
__le32 a_version; __le32 a_version;
} ext3_acl_header; } ext4_acl_header;
static inline size_t ext3_acl_size(int count) static inline size_t ext4_acl_size(int count)
{ {
if (count <= 4) { if (count <= 4) {
return sizeof(ext3_acl_header) + return sizeof(ext4_acl_header) +
count * sizeof(ext3_acl_entry_short); count * sizeof(ext4_acl_entry_short);
} else { } else {
return sizeof(ext3_acl_header) + return sizeof(ext4_acl_header) +
4 * sizeof(ext3_acl_entry_short) + 4 * sizeof(ext4_acl_entry_short) +
(count - 4) * sizeof(ext3_acl_entry); (count - 4) * sizeof(ext4_acl_entry);
} }
} }
static inline int ext3_acl_count(size_t size) static inline int ext4_acl_count(size_t size)
{ {
ssize_t s; ssize_t s;
size -= sizeof(ext3_acl_header); size -= sizeof(ext4_acl_header);
s = size - 4 * sizeof(ext3_acl_entry_short); s = size - 4 * sizeof(ext4_acl_entry_short);
if (s < 0) { if (s < 0) {
if (size % sizeof(ext3_acl_entry_short)) if (size % sizeof(ext4_acl_entry_short))
return -1; return -1;
return size / sizeof(ext3_acl_entry_short); return size / sizeof(ext4_acl_entry_short);
} else { } else {
if (s % sizeof(ext3_acl_entry)) if (s % sizeof(ext4_acl_entry))
return -1; return -1;
return s / sizeof(ext3_acl_entry) + 4; return s / sizeof(ext4_acl_entry) + 4;
} }
} }
#ifdef CONFIG_EXT3_FS_POSIX_ACL #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
/* Value for inode->u.ext3_i.i_acl and inode->u.ext3_i.i_default_acl /* Value for inode->u.ext4_i.i_acl and inode->u.ext4_i.i_default_acl
if the ACL has not been cached */ if the ACL has not been cached */
#define EXT3_ACL_NOT_CACHED ((void *)-1) #define EXT4_ACL_NOT_CACHED ((void *)-1)
/* acl.c */ /* acl.c */
extern int ext3_permission (struct inode *, int, struct nameidata *); extern int ext4_permission (struct inode *, int, struct nameidata *);
extern int ext3_acl_chmod (struct inode *); extern int ext4_acl_chmod (struct inode *);
extern int ext3_init_acl (handle_t *, struct inode *, struct inode *); extern int ext4_init_acl (handle_t *, struct inode *, struct inode *);
#else /* CONFIG_EXT3_FS_POSIX_ACL */ #else /* CONFIG_EXT4DEV_FS_POSIX_ACL */
#include <linux/sched.h> #include <linux/sched.h>
#define ext3_permission NULL #define ext4_permission NULL
static inline int static inline int
ext3_acl_chmod(struct inode *inode) ext4_acl_chmod(struct inode *inode)
{ {
return 0; return 0;
} }
static inline int static inline int
ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir) ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
{ {
return 0; return 0;
} }
#endif /* CONFIG_EXT3_FS_POSIX_ACL */ #endif /* CONFIG_EXT4DEV_FS_POSIX_ACL */
/* /*
* linux/fs/ext3/balloc.c * linux/fs/ext4/balloc.c
* *
* Copyright (C) 1992, 1993, 1994, 1995 * Copyright (C) 1992, 1993, 1994, 1995
* Remy Card (card@masi.ibp.fr) * Remy Card (card@masi.ibp.fr)
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/jbd.h> #include <linux/jbd.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#include <linux/ext3_jbd.h> #include <linux/ext4_jbd.h>
#include <linux/quotaops.h> #include <linux/quotaops.h>
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
...@@ -32,30 +32,30 @@ ...@@ -32,30 +32,30 @@
* The file system contains group descriptors which are located after the * The file system contains group descriptors which are located after the
* super block. Each descriptor contains the number of the bitmap block and * super block. Each descriptor contains the number of the bitmap block and
* the free blocks count in the block. The descriptors are loaded in memory * the free blocks count in the block. The descriptors are loaded in memory
* when a file system is mounted (see ext3_read_super). * when a file system is mounted (see ext4_read_super).
*/ */
#define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1) #define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1)
/** /**
* ext3_get_group_desc() -- load group descriptor from disk * ext4_get_group_desc() -- load group descriptor from disk
* @sb: super block * @sb: super block
* @block_group: given block group * @block_group: given block group
* @bh: pointer to the buffer head to store the block * @bh: pointer to the buffer head to store the block
* group descriptor * group descriptor
*/ */
struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb, struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
unsigned int block_group, unsigned int block_group,
struct buffer_head ** bh) struct buffer_head ** bh)
{ {
unsigned long group_desc; unsigned long group_desc;
unsigned long offset; unsigned long offset;
struct ext3_group_desc * desc; struct ext4_group_desc * desc;
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
if (block_group >= sbi->s_groups_count) { if (block_group >= sbi->s_groups_count) {
ext3_error (sb, "ext3_get_group_desc", ext4_error (sb, "ext4_get_group_desc",
"block_group >= groups_count - " "block_group >= groups_count - "
"block_group = %d, groups_count = %lu", "block_group = %d, groups_count = %lu",
block_group, sbi->s_groups_count); block_group, sbi->s_groups_count);
...@@ -64,17 +64,17 @@ struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb, ...@@ -64,17 +64,17 @@ struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb,
} }
smp_rmb(); smp_rmb();
group_desc = block_group >> EXT3_DESC_PER_BLOCK_BITS(sb); group_desc = block_group >> EXT4_DESC_PER_BLOCK_BITS(sb);
offset = block_group & (EXT3_DESC_PER_BLOCK(sb) - 1); offset = block_group & (EXT4_DESC_PER_BLOCK(sb) - 1);
if (!sbi->s_group_desc[group_desc]) { if (!sbi->s_group_desc[group_desc]) {
ext3_error (sb, "ext3_get_group_desc", ext4_error (sb, "ext4_get_group_desc",
"Group descriptor not loaded - " "Group descriptor not loaded - "
"block_group = %d, group_desc = %lu, desc = %lu", "block_group = %d, group_desc = %lu, desc = %lu",
block_group, group_desc, offset); block_group, group_desc, offset);
return NULL; return NULL;
} }
desc = (struct ext3_group_desc *) sbi->s_group_desc[group_desc]->b_data; desc = (struct ext4_group_desc *) sbi->s_group_desc[group_desc]->b_data;
if (bh) if (bh)
*bh = sbi->s_group_desc[group_desc]; *bh = sbi->s_group_desc[group_desc];
return desc + offset; return desc + offset;
...@@ -93,15 +93,15 @@ struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb, ...@@ -93,15 +93,15 @@ struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb,
static struct buffer_head * static struct buffer_head *
read_block_bitmap(struct super_block *sb, unsigned int block_group) read_block_bitmap(struct super_block *sb, unsigned int block_group)
{ {
struct ext3_group_desc * desc; struct ext4_group_desc * desc;
struct buffer_head * bh = NULL; struct buffer_head * bh = NULL;
desc = ext3_get_group_desc (sb, block_group, NULL); desc = ext4_get_group_desc (sb, block_group, NULL);
if (!desc) if (!desc)
goto error_out; goto error_out;
bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap)); bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap));
if (!bh) if (!bh)
ext3_error (sb, "read_block_bitmap", ext4_error (sb, "read_block_bitmap",
"Cannot read block bitmap - " "Cannot read block bitmap - "
"block_group = %d, block_bitmap = %u", "block_group = %d, block_bitmap = %u",
block_group, le32_to_cpu(desc->bg_block_bitmap)); 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,7 +134,7 @@ static void __rsv_window_dump(struct rb_root *root, int verbose,
const char *fn) const char *fn)
{ {
struct rb_node *n; struct rb_node *n;
struct ext3_reserve_window_node *rsv, *prev; struct ext4_reserve_window_node *rsv, *prev;
int bad; int bad;
restart: restart:
...@@ -144,7 +144,7 @@ static void __rsv_window_dump(struct rb_root *root, int verbose, ...@@ -144,7 +144,7 @@ static void __rsv_window_dump(struct rb_root *root, int verbose,
printk("Block Allocation Reservation Windows Map (%s):\n", fn); printk("Block Allocation Reservation Windows Map (%s):\n", fn);
while (n) { while (n) {
rsv = list_entry(n, struct ext3_reserve_window_node, rsv_node); rsv = list_entry(n, struct ext4_reserve_window_node, rsv_node);
if (verbose) if (verbose)
printk("reservation window 0x%p " printk("reservation window 0x%p "
"start: %lu, end: %lu\n", "start: %lu, end: %lu\n",
...@@ -196,13 +196,13 @@ static void __rsv_window_dump(struct rb_root *root, int verbose, ...@@ -196,13 +196,13 @@ static void __rsv_window_dump(struct rb_root *root, int verbose,
* otherwise, return 0; * otherwise, return 0;
*/ */
static int static int
goal_in_my_reservation(struct ext3_reserve_window *rsv, ext3_grpblk_t grp_goal, goal_in_my_reservation(struct ext4_reserve_window *rsv, ext4_grpblk_t grp_goal,
unsigned int group, struct super_block * sb) unsigned int group, struct super_block * sb)
{ {
ext3_fsblk_t group_first_block, group_last_block; ext4_fsblk_t group_first_block, group_last_block;
group_first_block = ext3_group_first_block_no(sb, group); group_first_block = ext4_group_first_block_no(sb, group);
group_last_block = group_first_block + (EXT3_BLOCKS_PER_GROUP(sb) - 1); group_last_block = group_first_block + (EXT4_BLOCKS_PER_GROUP(sb) - 1);
if ((rsv->_rsv_start > group_last_block) || if ((rsv->_rsv_start > group_last_block) ||
(rsv->_rsv_end < group_first_block)) (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,17 +222,17 @@ goal_in_my_reservation(struct ext3_reserve_window *rsv, ext3_grpblk_t grp_goal,
* if the goal is not in any window. * if the goal is not in any window.
* Returns NULL if there are no windows or if all windows start after the goal. * Returns NULL if there are no windows or if all windows start after the goal.
*/ */
static struct ext3_reserve_window_node * static struct ext4_reserve_window_node *
search_reserve_window(struct rb_root *root, ext3_fsblk_t goal) search_reserve_window(struct rb_root *root, ext4_fsblk_t goal)
{ {
struct rb_node *n = root->rb_node; struct rb_node *n = root->rb_node;
struct ext3_reserve_window_node *rsv; struct ext4_reserve_window_node *rsv;
if (!n) if (!n)
return NULL; return NULL;
do { do {
rsv = rb_entry(n, struct ext3_reserve_window_node, rsv_node); rsv = rb_entry(n, struct ext4_reserve_window_node, rsv_node);
if (goal < rsv->rsv_start) if (goal < rsv->rsv_start)
n = n->rb_left; n = n->rb_left;
...@@ -249,33 +249,33 @@ search_reserve_window(struct rb_root *root, ext3_fsblk_t goal) ...@@ -249,33 +249,33 @@ search_reserve_window(struct rb_root *root, ext3_fsblk_t goal)
*/ */
if (rsv->rsv_start > goal) { if (rsv->rsv_start > goal) {
n = rb_prev(&rsv->rsv_node); n = rb_prev(&rsv->rsv_node);
rsv = rb_entry(n, struct ext3_reserve_window_node, rsv_node); rsv = rb_entry(n, struct ext4_reserve_window_node, rsv_node);
} }
return rsv; return rsv;
} }
/** /**
* ext3_rsv_window_add() -- Insert a window to the block reservation rb tree. * ext4_rsv_window_add() -- Insert a window to the block reservation rb tree.
* @sb: super block * @sb: super block
* @rsv: reservation window to add * @rsv: reservation window to add
* *
* Must be called with rsv_lock hold. * Must be called with rsv_lock hold.
*/ */
void ext3_rsv_window_add(struct super_block *sb, void ext4_rsv_window_add(struct super_block *sb,
struct ext3_reserve_window_node *rsv) struct ext4_reserve_window_node *rsv)
{ {
struct rb_root *root = &EXT3_SB(sb)->s_rsv_window_root; struct rb_root *root = &EXT4_SB(sb)->s_rsv_window_root;
struct rb_node *node = &rsv->rsv_node; struct rb_node *node = &rsv->rsv_node;
ext3_fsblk_t start = rsv->rsv_start; ext4_fsblk_t start = rsv->rsv_start;
struct rb_node ** p = &root->rb_node; struct rb_node ** p = &root->rb_node;
struct rb_node * parent = NULL; struct rb_node * parent = NULL;
struct ext3_reserve_window_node *this; struct ext4_reserve_window_node *this;
while (*p) while (*p)
{ {
parent = *p; parent = *p;
this = rb_entry(parent, struct ext3_reserve_window_node, rsv_node); this = rb_entry(parent, struct ext4_reserve_window_node, rsv_node);
if (start < this->rsv_start) if (start < this->rsv_start)
p = &(*p)->rb_left; p = &(*p)->rb_left;
...@@ -292,7 +292,7 @@ void ext3_rsv_window_add(struct super_block *sb, ...@@ -292,7 +292,7 @@ void ext3_rsv_window_add(struct super_block *sb,
} }
/** /**
* ext3_rsv_window_remove() -- unlink a window from the reservation rb tree * ext4_rsv_window_remove() -- unlink a window from the reservation rb tree
* @sb: super block * @sb: super block
* @rsv: reservation window to remove * @rsv: reservation window to remove
* *
...@@ -301,59 +301,59 @@ void ext3_rsv_window_add(struct super_block *sb, ...@@ -301,59 +301,59 @@ void ext3_rsv_window_add(struct super_block *sb,
* rsv_lock hold. * rsv_lock hold.
*/ */
static void rsv_window_remove(struct super_block *sb, static void rsv_window_remove(struct super_block *sb,
struct ext3_reserve_window_node *rsv) struct ext4_reserve_window_node *rsv)
{ {
rsv->rsv_start = EXT3_RESERVE_WINDOW_NOT_ALLOCATED; rsv->rsv_start = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
rsv->rsv_end = EXT3_RESERVE_WINDOW_NOT_ALLOCATED; rsv->rsv_end = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
rsv->rsv_alloc_hit = 0; rsv->rsv_alloc_hit = 0;
rb_erase(&rsv->rsv_node, &EXT3_SB(sb)->s_rsv_window_root); rb_erase(&rsv->rsv_node, &EXT4_SB(sb)->s_rsv_window_root);
} }
/* /*
* rsv_is_empty() -- Check if the reservation window is allocated. * rsv_is_empty() -- Check if the reservation window is allocated.
* @rsv: given reservation window to check * @rsv: given reservation window to check
* *
* returns 1 if the end block is EXT3_RESERVE_WINDOW_NOT_ALLOCATED. * returns 1 if the end block is EXT4_RESERVE_WINDOW_NOT_ALLOCATED.
*/ */
static inline int rsv_is_empty(struct ext3_reserve_window *rsv) static inline int rsv_is_empty(struct ext4_reserve_window *rsv)
{ {
/* a valid reservation end block could not be 0 */ /* a valid reservation end block could not be 0 */
return rsv->_rsv_end == EXT3_RESERVE_WINDOW_NOT_ALLOCATED; return rsv->_rsv_end == EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
} }
/** /**
* ext3_init_block_alloc_info() * ext4_init_block_alloc_info()
* @inode: file inode structure * @inode: file inode structure
* *
* Allocate and initialize the reservation window structure, and * Allocate and initialize the reservation window structure, and
* link the window to the ext3 inode structure at last * link the window to the ext4 inode structure at last
* *
* The reservation window structure is only dynamically allocated * The reservation window structure is only dynamically allocated
* and linked to ext3 inode the first time the open file * and linked to ext4 inode the first time the open file
* needs a new block. So, before every ext3_new_block(s) call, for * needs a new block. So, before every ext4_new_block(s) call, for
* regular files, we should check whether the reservation window * regular files, we should check whether the reservation window
* structure exists or not. In the latter case, this function is called. * structure exists or not. In the latter case, this function is called.
* Fail to do so will result in block reservation being turned off for that * Fail to do so will result in block reservation being turned off for that
* open file. * open file.
* *
* This function is called from ext3_get_blocks_handle(), also called * This function is called from ext4_get_blocks_handle(), also called
* when setting the reservation window size through ioctl before the file * when setting the reservation window size through ioctl before the file
* is open for write (needs block allocation). * is open for write (needs block allocation).
* *
* Needs truncate_mutex protection prior to call this function. * Needs truncate_mutex protection prior to call this function.
*/ */
void ext3_init_block_alloc_info(struct inode *inode) void ext4_init_block_alloc_info(struct inode *inode)
{ {
struct ext3_inode_info *ei = EXT3_I(inode); struct ext4_inode_info *ei = EXT4_I(inode);
struct ext3_block_alloc_info *block_i = ei->i_block_alloc_info; struct ext4_block_alloc_info *block_i = ei->i_block_alloc_info;
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
block_i = kmalloc(sizeof(*block_i), GFP_NOFS); block_i = kmalloc(sizeof(*block_i), GFP_NOFS);
if (block_i) { if (block_i) {
struct ext3_reserve_window_node *rsv = &block_i->rsv_window_node; struct ext4_reserve_window_node *rsv = &block_i->rsv_window_node;
rsv->rsv_start = EXT3_RESERVE_WINDOW_NOT_ALLOCATED; rsv->rsv_start = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
rsv->rsv_end = EXT3_RESERVE_WINDOW_NOT_ALLOCATED; rsv->rsv_end = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
/* /*
* if filesystem is mounted with NORESERVATION, the goal * if filesystem is mounted with NORESERVATION, the goal
...@@ -363,7 +363,7 @@ void ext3_init_block_alloc_info(struct inode *inode) ...@@ -363,7 +363,7 @@ void ext3_init_block_alloc_info(struct inode *inode)
if (!test_opt(sb, RESERVATION)) if (!test_opt(sb, RESERVATION))
rsv->rsv_goal_size = 0; rsv->rsv_goal_size = 0;
else else
rsv->rsv_goal_size = EXT3_DEFAULT_RESERVE_BLOCKS; rsv->rsv_goal_size = EXT4_DEFAULT_RESERVE_BLOCKS;
rsv->rsv_alloc_hit = 0; rsv->rsv_alloc_hit = 0;
block_i->last_alloc_logical_block = 0; block_i->last_alloc_logical_block = 0;
block_i->last_alloc_physical_block = 0; block_i->last_alloc_physical_block = 0;
...@@ -372,24 +372,24 @@ void ext3_init_block_alloc_info(struct inode *inode) ...@@ -372,24 +372,24 @@ void ext3_init_block_alloc_info(struct inode *inode)
} }
/** /**
* ext3_discard_reservation() * ext4_discard_reservation()
* @inode: inode * @inode: inode
* *
* Discard(free) block reservation window on last file close, or truncate * Discard(free) block reservation window on last file close, or truncate
* or at last iput(). * or at last iput().
* *
* It is being called in three cases: * It is being called in three cases:
* ext3_release_file(): last writer close the file * ext4_release_file(): last writer close the file
* ext3_clear_inode(): last iput(), when nobody link to this file. * ext4_clear_inode(): last iput(), when nobody link to this file.
* ext3_truncate(): when the block indirect map is about to change. * ext4_truncate(): when the block indirect map is about to change.
* *
*/ */
void ext3_discard_reservation(struct inode *inode) void ext4_discard_reservation(struct inode *inode)
{ {
struct ext3_inode_info *ei = EXT3_I(inode); struct ext4_inode_info *ei = EXT4_I(inode);
struct ext3_block_alloc_info *block_i = ei->i_block_alloc_info; struct ext4_block_alloc_info *block_i = ei->i_block_alloc_info;
struct ext3_reserve_window_node *rsv; struct ext4_reserve_window_node *rsv;
spinlock_t *rsv_lock = &EXT3_SB(inode->i_sb)->s_rsv_window_lock; spinlock_t *rsv_lock = &EXT4_SB(inode->i_sb)->s_rsv_window_lock;
if (!block_i) if (!block_i)
return; return;
...@@ -404,62 +404,62 @@ void ext3_discard_reservation(struct inode *inode) ...@@ -404,62 +404,62 @@ void ext3_discard_reservation(struct inode *inode)
} }
/** /**
* ext3_free_blocks_sb() -- Free given blocks and update quota * ext4_free_blocks_sb() -- Free given blocks and update quota
* @handle: handle to this transaction * @handle: handle to this transaction
* @sb: super block * @sb: super block
* @block: start physcial block to free * @block: start physcial block to free
* @count: number of blocks to free * @count: number of blocks to free
* @pdquot_freed_blocks: pointer to quota * @pdquot_freed_blocks: pointer to quota
*/ */
void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb, void ext4_free_blocks_sb(handle_t *handle, struct super_block *sb,
ext3_fsblk_t block, unsigned long count, ext4_fsblk_t block, unsigned long count,
unsigned long *pdquot_freed_blocks) unsigned long *pdquot_freed_blocks)
{ {
struct buffer_head *bitmap_bh = NULL; struct buffer_head *bitmap_bh = NULL;
struct buffer_head *gd_bh; struct buffer_head *gd_bh;
unsigned long block_group; unsigned long block_group;
ext3_grpblk_t bit; ext4_grpblk_t bit;
unsigned long i; unsigned long i;
unsigned long overflow; unsigned long overflow;
struct ext3_group_desc * desc; struct ext4_group_desc * desc;
struct ext3_super_block * es; struct ext4_super_block * es;
struct ext3_sb_info *sbi; struct ext4_sb_info *sbi;
int err = 0, ret; int err = 0, ret;
ext3_grpblk_t group_freed; ext4_grpblk_t group_freed;
*pdquot_freed_blocks = 0; *pdquot_freed_blocks = 0;
sbi = EXT3_SB(sb); sbi = EXT4_SB(sb);
es = sbi->s_es; es = sbi->s_es;
if (block < le32_to_cpu(es->s_first_data_block) || if (block < le32_to_cpu(es->s_first_data_block) ||
block + count < block || block + count < block ||
block + count > le32_to_cpu(es->s_blocks_count)) { block + count > le32_to_cpu(es->s_blocks_count)) {
ext3_error (sb, "ext3_free_blocks", ext4_error (sb, "ext4_free_blocks",
"Freeing blocks not in datazone - " "Freeing blocks not in datazone - "
"block = "E3FSBLK", count = %lu", block, count); "block = "E3FSBLK", count = %lu", block, count);
goto error_return; goto error_return;
} }
ext3_debug ("freeing block(s) %lu-%lu\n", block, block + count - 1); ext4_debug ("freeing block(s) %lu-%lu\n", block, block + count - 1);
do_more: do_more:
overflow = 0; overflow = 0;
block_group = (block - le32_to_cpu(es->s_first_data_block)) / block_group = (block - le32_to_cpu(es->s_first_data_block)) /
EXT3_BLOCKS_PER_GROUP(sb); EXT4_BLOCKS_PER_GROUP(sb);
bit = (block - le32_to_cpu(es->s_first_data_block)) % bit = (block - le32_to_cpu(es->s_first_data_block)) %
EXT3_BLOCKS_PER_GROUP(sb); EXT4_BLOCKS_PER_GROUP(sb);
/* /*
* Check to see if we are freeing blocks across a group * Check to see if we are freeing blocks across a group
* boundary. * boundary.
*/ */
if (bit + count > EXT3_BLOCKS_PER_GROUP(sb)) { if (bit + count > EXT4_BLOCKS_PER_GROUP(sb)) {
overflow = bit + count - EXT3_BLOCKS_PER_GROUP(sb); overflow = bit + count - EXT4_BLOCKS_PER_GROUP(sb);
count -= overflow; count -= overflow;
} }
brelse(bitmap_bh); brelse(bitmap_bh);
bitmap_bh = read_block_bitmap(sb, block_group); bitmap_bh = read_block_bitmap(sb, block_group);
if (!bitmap_bh) if (!bitmap_bh)
goto error_return; goto error_return;
desc = ext3_get_group_desc (sb, block_group, &gd_bh); desc = ext4_get_group_desc (sb, block_group, &gd_bh);
if (!desc) if (!desc)
goto error_return; goto error_return;
...@@ -469,7 +469,7 @@ void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb, ...@@ -469,7 +469,7 @@ void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb,
sbi->s_itb_per_group) || sbi->s_itb_per_group) ||
in_range (block + count - 1, le32_to_cpu(desc->bg_inode_table), in_range (block + count - 1, le32_to_cpu(desc->bg_inode_table),
sbi->s_itb_per_group)) sbi->s_itb_per_group))
ext3_error (sb, "ext3_free_blocks", ext4_error (sb, "ext4_free_blocks",
"Freeing blocks in system zones - " "Freeing blocks in system zones - "
"Block = "E3FSBLK", count = %lu", "Block = "E3FSBLK", count = %lu",
block, count); block, count);
...@@ -480,7 +480,7 @@ void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb, ...@@ -480,7 +480,7 @@ void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb,
*/ */
/* @@@ check errors */ /* @@@ check errors */
BUFFER_TRACE(bitmap_bh, "getting undo access"); BUFFER_TRACE(bitmap_bh, "getting undo access");
err = ext3_journal_get_undo_access(handle, bitmap_bh); err = ext4_journal_get_undo_access(handle, bitmap_bh);
if (err) if (err)
goto error_return; goto error_return;
...@@ -490,7 +490,7 @@ void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb, ...@@ -490,7 +490,7 @@ void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb,
* using it * using it
*/ */
BUFFER_TRACE(gd_bh, "get_write_access"); BUFFER_TRACE(gd_bh, "get_write_access");
err = ext3_journal_get_write_access(handle, gd_bh); err = ext4_journal_get_write_access(handle, gd_bh);
if (err) if (err)
goto error_return; goto error_return;
...@@ -542,7 +542,7 @@ void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb, ...@@ -542,7 +542,7 @@ void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb,
BUFFER_TRACE(bitmap_bh, "set in b_committed_data"); BUFFER_TRACE(bitmap_bh, "set in b_committed_data");
J_ASSERT_BH(bitmap_bh, J_ASSERT_BH(bitmap_bh,
bh2jh(bitmap_bh)->b_committed_data != NULL); bh2jh(bitmap_bh)->b_committed_data != NULL);
ext3_set_bit_atomic(sb_bgl_lock(sbi, block_group), bit + i, ext4_set_bit_atomic(sb_bgl_lock(sbi, block_group), bit + i,
bh2jh(bitmap_bh)->b_committed_data); bh2jh(bitmap_bh)->b_committed_data);
/* /*
...@@ -551,10 +551,10 @@ void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb, ...@@ -551,10 +551,10 @@ void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb,
* the allocator uses. * the allocator uses.
*/ */
BUFFER_TRACE(bitmap_bh, "clear bit"); BUFFER_TRACE(bitmap_bh, "clear bit");
if (!ext3_clear_bit_atomic(sb_bgl_lock(sbi, block_group), if (!ext4_clear_bit_atomic(sb_bgl_lock(sbi, block_group),
bit + i, bitmap_bh->b_data)) { bit + i, bitmap_bh->b_data)) {
jbd_unlock_bh_state(bitmap_bh); jbd_unlock_bh_state(bitmap_bh);
ext3_error(sb, __FUNCTION__, ext4_error(sb, __FUNCTION__,
"bit already cleared for block "E3FSBLK, "bit already cleared for block "E3FSBLK,
block + i); block + i);
jbd_lock_bh_state(bitmap_bh); jbd_lock_bh_state(bitmap_bh);
...@@ -574,11 +574,11 @@ void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb, ...@@ -574,11 +574,11 @@ void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb,
/* We dirtied the bitmap block */ /* We dirtied the bitmap block */
BUFFER_TRACE(bitmap_bh, "dirtied bitmap block"); BUFFER_TRACE(bitmap_bh, "dirtied bitmap block");
err = ext3_journal_dirty_metadata(handle, bitmap_bh); err = ext4_journal_dirty_metadata(handle, bitmap_bh);
/* And the group descriptor block */ /* And the group descriptor block */
BUFFER_TRACE(gd_bh, "dirtied group descriptor block"); BUFFER_TRACE(gd_bh, "dirtied group descriptor block");
ret = ext3_journal_dirty_metadata(handle, gd_bh); ret = ext4_journal_dirty_metadata(handle, gd_bh);
if (!err) err = ret; if (!err) err = ret;
*pdquot_freed_blocks += group_freed; *pdquot_freed_blocks += group_freed;
...@@ -590,40 +590,40 @@ void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb, ...@@ -590,40 +590,40 @@ void ext3_free_blocks_sb(handle_t *handle, struct super_block *sb,
sb->s_dirt = 1; sb->s_dirt = 1;
error_return: error_return:
brelse(bitmap_bh); brelse(bitmap_bh);
ext3_std_error(sb, err); ext4_std_error(sb, err);
return; return;
} }
/** /**
* ext3_free_blocks() -- Free given blocks and update quota * ext4_free_blocks() -- Free given blocks and update quota
* @handle: handle for this transaction * @handle: handle for this transaction
* @inode: inode * @inode: inode
* @block: start physical block to free * @block: start physical block to free
* @count: number of blocks to count * @count: number of blocks to count
*/ */
void ext3_free_blocks(handle_t *handle, struct inode *inode, void ext4_free_blocks(handle_t *handle, struct inode *inode,
ext3_fsblk_t block, unsigned long count) ext4_fsblk_t block, unsigned long count)
{ {
struct super_block * sb; struct super_block * sb;
unsigned long dquot_freed_blocks; unsigned long dquot_freed_blocks;
sb = inode->i_sb; sb = inode->i_sb;
if (!sb) { if (!sb) {
printk ("ext3_free_blocks: nonexistent device"); printk ("ext4_free_blocks: nonexistent device");
return; return;
} }
ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks); ext4_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
if (dquot_freed_blocks) if (dquot_freed_blocks)
DQUOT_FREE_BLOCK(inode, dquot_freed_blocks); DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
return; return;
} }
/** /**
* ext3_test_allocatable() * ext4_test_allocatable()
* @nr: given allocation block group * @nr: given allocation block group
* @bh: bufferhead contains the bitmap of the given block group * @bh: bufferhead contains the bitmap of the given block group
* *
* For ext3 allocations, we must not reuse any blocks which are * For ext4 allocations, we must not reuse any blocks which are
* allocated in the bitmap buffer's "last committed data" copy. This * allocated in the bitmap buffer's "last committed data" copy. This
* prevents deletes from freeing up the page for reuse until we have * prevents deletes from freeing up the page for reuse until we have
* committed the delete transaction. * committed the delete transaction.
...@@ -638,19 +638,19 @@ void ext3_free_blocks(handle_t *handle, struct inode *inode, ...@@ -638,19 +638,19 @@ void ext3_free_blocks(handle_t *handle, struct inode *inode,
* data-writes at some point, and disable it for metadata allocations or * data-writes at some point, and disable it for metadata allocations or
* sync-data inodes. * sync-data inodes.
*/ */
static int ext3_test_allocatable(ext3_grpblk_t nr, struct buffer_head *bh) static int ext4_test_allocatable(ext4_grpblk_t nr, struct buffer_head *bh)
{ {
int ret; int ret;
struct journal_head *jh = bh2jh(bh); struct journal_head *jh = bh2jh(bh);
if (ext3_test_bit(nr, bh->b_data)) if (ext4_test_bit(nr, bh->b_data))
return 0; return 0;
jbd_lock_bh_state(bh); jbd_lock_bh_state(bh);
if (!jh->b_committed_data) if (!jh->b_committed_data)
ret = 1; ret = 1;
else else
ret = !ext3_test_bit(nr, jh->b_committed_data); ret = !ext4_test_bit(nr, jh->b_committed_data);
jbd_unlock_bh_state(bh); jbd_unlock_bh_state(bh);
return ret; return ret;
} }
...@@ -665,22 +665,22 @@ static int ext3_test_allocatable(ext3_grpblk_t nr, struct buffer_head *bh) ...@@ -665,22 +665,22 @@ static int ext3_test_allocatable(ext3_grpblk_t nr, struct buffer_head *bh)
* bitmap on disk and the last-committed copy in journal, until we find a * bitmap on disk and the last-committed copy in journal, until we find a
* bit free in both bitmaps. * bit free in both bitmaps.
*/ */
static ext3_grpblk_t static ext4_grpblk_t
bitmap_search_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh, bitmap_search_next_usable_block(ext4_grpblk_t start, struct buffer_head *bh,
ext3_grpblk_t maxblocks) ext4_grpblk_t maxblocks)
{ {
ext3_grpblk_t next; ext4_grpblk_t next;
struct journal_head *jh = bh2jh(bh); struct journal_head *jh = bh2jh(bh);
while (start < maxblocks) { while (start < maxblocks) {
next = ext3_find_next_zero_bit(bh->b_data, maxblocks, start); next = ext4_find_next_zero_bit(bh->b_data, maxblocks, start);
if (next >= maxblocks) if (next >= maxblocks)
return -1; return -1;
if (ext3_test_allocatable(next, bh)) if (ext4_test_allocatable(next, bh))
return next; return next;
jbd_lock_bh_state(bh); jbd_lock_bh_state(bh);
if (jh->b_committed_data) if (jh->b_committed_data)
start = ext3_find_next_zero_bit(jh->b_committed_data, start = ext4_find_next_zero_bit(jh->b_committed_data,
maxblocks, next); maxblocks, next);
jbd_unlock_bh_state(bh); jbd_unlock_bh_state(bh);
} }
...@@ -700,11 +700,11 @@ bitmap_search_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh, ...@@ -700,11 +700,11 @@ bitmap_search_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh,
* the initial goal; then for a free byte somewhere in the bitmap; then * the initial goal; then for a free byte somewhere in the bitmap; then
* for any free bit in the bitmap. * for any free bit in the bitmap.
*/ */
static ext3_grpblk_t static ext4_grpblk_t
find_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh, find_next_usable_block(ext4_grpblk_t start, struct buffer_head *bh,
ext3_grpblk_t maxblocks) ext4_grpblk_t maxblocks)
{ {
ext3_grpblk_t here, next; ext4_grpblk_t here, next;
char *p, *r; char *p, *r;
if (start > 0) { if (start > 0) {
...@@ -713,16 +713,16 @@ find_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh, ...@@ -713,16 +713,16 @@ find_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh,
* block within the next XX blocks. * block within the next XX blocks.
* *
* end_goal is more or less random, but it has to be * end_goal is more or less random, but it has to be
* less than EXT3_BLOCKS_PER_GROUP. Aligning up to the * less than EXT4_BLOCKS_PER_GROUP. Aligning up to the
* next 64-bit boundary is simple.. * next 64-bit boundary is simple..
*/ */
ext3_grpblk_t end_goal = (start + 63) & ~63; ext4_grpblk_t end_goal = (start + 63) & ~63;
if (end_goal > maxblocks) if (end_goal > maxblocks)
end_goal = maxblocks; end_goal = maxblocks;
here = ext3_find_next_zero_bit(bh->b_data, end_goal, start); here = ext4_find_next_zero_bit(bh->b_data, end_goal, start);
if (here < end_goal && ext3_test_allocatable(here, bh)) if (here < end_goal && ext4_test_allocatable(here, bh))
return here; return here;
ext3_debug("Bit not found near goal\n"); ext4_debug("Bit not found near goal\n");
} }
here = start; here = start;
...@@ -733,7 +733,7 @@ find_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh, ...@@ -733,7 +733,7 @@ find_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh,
r = memscan(p, 0, (maxblocks - here + 7) >> 3); r = memscan(p, 0, (maxblocks - here + 7) >> 3);
next = (r - ((char *)bh->b_data)) << 3; next = (r - ((char *)bh->b_data)) << 3;
if (next < maxblocks && next >= start && ext3_test_allocatable(next, bh)) if (next < maxblocks && next >= start && ext4_test_allocatable(next, bh))
return next; return next;
/* /*
...@@ -757,16 +757,16 @@ find_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh, ...@@ -757,16 +757,16 @@ find_next_usable_block(ext3_grpblk_t start, struct buffer_head *bh,
* zero (failure). * zero (failure).
*/ */
static inline int static inline int
claim_block(spinlock_t *lock, ext3_grpblk_t block, struct buffer_head *bh) claim_block(spinlock_t *lock, ext4_grpblk_t block, struct buffer_head *bh)
{ {
struct journal_head *jh = bh2jh(bh); struct journal_head *jh = bh2jh(bh);
int ret; int ret;
if (ext3_set_bit_atomic(lock, block, bh->b_data)) if (ext4_set_bit_atomic(lock, block, bh->b_data))
return 0; return 0;
jbd_lock_bh_state(bh); jbd_lock_bh_state(bh);
if (jh->b_committed_data && ext3_test_bit(block,jh->b_committed_data)) { if (jh->b_committed_data && ext4_test_bit(block,jh->b_committed_data)) {
ext3_clear_bit_atomic(lock, block, bh->b_data); ext4_clear_bit_atomic(lock, block, bh->b_data);
ret = 0; ret = 0;
} else { } else {
ret = 1; ret = 1;
...@@ -776,7 +776,7 @@ claim_block(spinlock_t *lock, ext3_grpblk_t block, struct buffer_head *bh) ...@@ -776,7 +776,7 @@ claim_block(spinlock_t *lock, ext3_grpblk_t block, struct buffer_head *bh)
} }
/** /**
* ext3_try_to_allocate() * ext4_try_to_allocate()
* @sb: superblock * @sb: superblock
* @handle: handle to this transaction * @handle: handle to this transaction
* @group: given allocation block group * @group: given allocation block group
...@@ -797,29 +797,29 @@ claim_block(spinlock_t *lock, ext3_grpblk_t block, struct buffer_head *bh) ...@@ -797,29 +797,29 @@ claim_block(spinlock_t *lock, ext3_grpblk_t block, struct buffer_head *bh)
* *
* If we failed to allocate the desired block then we may end up crossing to a * If we failed to allocate the desired block then we may end up crossing to a
* new bitmap. In that case we must release write access to the old one via * new bitmap. In that case we must release write access to the old one via
* ext3_journal_release_buffer(), else we'll run out of credits. * ext4_journal_release_buffer(), else we'll run out of credits.
*/ */
static ext3_grpblk_t static ext4_grpblk_t
ext3_try_to_allocate(struct super_block *sb, handle_t *handle, int group, ext4_try_to_allocate(struct super_block *sb, handle_t *handle, int group,
struct buffer_head *bitmap_bh, ext3_grpblk_t grp_goal, struct buffer_head *bitmap_bh, ext4_grpblk_t grp_goal,
unsigned long *count, struct ext3_reserve_window *my_rsv) unsigned long *count, struct ext4_reserve_window *my_rsv)
{ {
ext3_fsblk_t group_first_block; ext4_fsblk_t group_first_block;
ext3_grpblk_t start, end; ext4_grpblk_t start, end;
unsigned long num = 0; unsigned long num = 0;
/* we do allocation within the reservation window if we have a window */ /* we do allocation within the reservation window if we have a window */
if (my_rsv) { if (my_rsv) {
group_first_block = ext3_group_first_block_no(sb, group); group_first_block = ext4_group_first_block_no(sb, group);
if (my_rsv->_rsv_start >= group_first_block) if (my_rsv->_rsv_start >= group_first_block)
start = my_rsv->_rsv_start - group_first_block; start = my_rsv->_rsv_start - group_first_block;
else else
/* reservation window cross group boundary */ /* reservation window cross group boundary */
start = 0; start = 0;
end = my_rsv->_rsv_end - group_first_block + 1; end = my_rsv->_rsv_end - group_first_block + 1;
if (end > EXT3_BLOCKS_PER_GROUP(sb)) if (end > EXT4_BLOCKS_PER_GROUP(sb))
/* reservation window crosses group boundary */ /* reservation window crosses group boundary */
end = EXT3_BLOCKS_PER_GROUP(sb); end = EXT4_BLOCKS_PER_GROUP(sb);
if ((start <= grp_goal) && (grp_goal < end)) if ((start <= grp_goal) && (grp_goal < end))
start = grp_goal; start = grp_goal;
else else
...@@ -829,13 +829,13 @@ ext3_try_to_allocate(struct super_block *sb, handle_t *handle, int group, ...@@ -829,13 +829,13 @@ ext3_try_to_allocate(struct super_block *sb, handle_t *handle, int group,
start = grp_goal; start = grp_goal;
else else
start = 0; start = 0;
end = EXT3_BLOCKS_PER_GROUP(sb); end = EXT4_BLOCKS_PER_GROUP(sb);
} }
BUG_ON(start > EXT3_BLOCKS_PER_GROUP(sb)); BUG_ON(start > EXT4_BLOCKS_PER_GROUP(sb));
repeat: repeat:
if (grp_goal < 0 || !ext3_test_allocatable(grp_goal, bitmap_bh)) { if (grp_goal < 0 || !ext4_test_allocatable(grp_goal, bitmap_bh)) {
grp_goal = find_next_usable_block(start, bitmap_bh, end); grp_goal = find_next_usable_block(start, bitmap_bh, end);
if (grp_goal < 0) if (grp_goal < 0)
goto fail_access; goto fail_access;
...@@ -843,7 +843,7 @@ ext3_try_to_allocate(struct super_block *sb, handle_t *handle, int group, ...@@ -843,7 +843,7 @@ ext3_try_to_allocate(struct super_block *sb, handle_t *handle, int group,
int i; int i;
for (i = 0; i < 7 && grp_goal > start && for (i = 0; i < 7 && grp_goal > start &&
ext3_test_allocatable(grp_goal - 1, ext4_test_allocatable(grp_goal - 1,
bitmap_bh); bitmap_bh);
i++, grp_goal--) i++, grp_goal--)
; ;
...@@ -851,7 +851,7 @@ ext3_try_to_allocate(struct super_block *sb, handle_t *handle, int group, ...@@ -851,7 +851,7 @@ ext3_try_to_allocate(struct super_block *sb, handle_t *handle, int group,
} }
start = grp_goal; start = grp_goal;
if (!claim_block(sb_bgl_lock(EXT3_SB(sb), group), if (!claim_block(sb_bgl_lock(EXT4_SB(sb), group),
grp_goal, bitmap_bh)) { grp_goal, bitmap_bh)) {
/* /*
* The block was allocated by another thread, or it was * The block was allocated by another thread, or it was
...@@ -866,8 +866,8 @@ ext3_try_to_allocate(struct super_block *sb, handle_t *handle, int group, ...@@ -866,8 +866,8 @@ ext3_try_to_allocate(struct super_block *sb, handle_t *handle, int group,
num++; num++;
grp_goal++; grp_goal++;
while (num < *count && grp_goal < end while (num < *count && grp_goal < end
&& ext3_test_allocatable(grp_goal, bitmap_bh) && ext4_test_allocatable(grp_goal, bitmap_bh)
&& claim_block(sb_bgl_lock(EXT3_SB(sb), group), && claim_block(sb_bgl_lock(EXT4_SB(sb), group),
grp_goal, bitmap_bh)) { grp_goal, bitmap_bh)) {
num++; num++;
grp_goal++; grp_goal++;
...@@ -913,15 +913,15 @@ ext3_try_to_allocate(struct super_block *sb, handle_t *handle, int group, ...@@ -913,15 +913,15 @@ ext3_try_to_allocate(struct super_block *sb, handle_t *handle, int group,
* *
*/ */
static int find_next_reservable_window( static int find_next_reservable_window(
struct ext3_reserve_window_node *search_head, struct ext4_reserve_window_node *search_head,
struct ext3_reserve_window_node *my_rsv, struct ext4_reserve_window_node *my_rsv,
struct super_block * sb, struct super_block * sb,
ext3_fsblk_t start_block, ext4_fsblk_t start_block,
ext3_fsblk_t last_block) ext4_fsblk_t last_block)
{ {
struct rb_node *next; struct rb_node *next;
struct ext3_reserve_window_node *rsv, *prev; struct ext4_reserve_window_node *rsv, *prev;
ext3_fsblk_t cur; ext4_fsblk_t cur;
int size = my_rsv->rsv_goal_size; int size = my_rsv->rsv_goal_size;
/* TODO: make the start of the reservation window byte-aligned */ /* TODO: make the start of the reservation window byte-aligned */
...@@ -949,7 +949,7 @@ static int find_next_reservable_window( ...@@ -949,7 +949,7 @@ static int find_next_reservable_window(
prev = rsv; prev = rsv;
next = rb_next(&rsv->rsv_node); next = rb_next(&rsv->rsv_node);
rsv = list_entry(next,struct ext3_reserve_window_node,rsv_node); rsv = list_entry(next,struct ext4_reserve_window_node,rsv_node);
/* /*
* Reached the last reservation, we can just append to the * Reached the last reservation, we can just append to the
...@@ -992,7 +992,7 @@ static int find_next_reservable_window( ...@@ -992,7 +992,7 @@ static int find_next_reservable_window(
my_rsv->rsv_alloc_hit = 0; my_rsv->rsv_alloc_hit = 0;
if (prev != my_rsv) if (prev != my_rsv)
ext3_rsv_window_add(sb, my_rsv); ext4_rsv_window_add(sb, my_rsv);
return 0; return 0;
} }
...@@ -1034,20 +1034,20 @@ static int find_next_reservable_window( ...@@ -1034,20 +1034,20 @@ static int find_next_reservable_window(
* @bitmap_bh: the block group block bitmap * @bitmap_bh: the block group block bitmap
* *
*/ */
static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv, static int alloc_new_reservation(struct ext4_reserve_window_node *my_rsv,
ext3_grpblk_t grp_goal, struct super_block *sb, ext4_grpblk_t grp_goal, struct super_block *sb,
unsigned int group, struct buffer_head *bitmap_bh) unsigned int group, struct buffer_head *bitmap_bh)
{ {
struct ext3_reserve_window_node *search_head; struct ext4_reserve_window_node *search_head;
ext3_fsblk_t group_first_block, group_end_block, start_block; ext4_fsblk_t group_first_block, group_end_block, start_block;
ext3_grpblk_t first_free_block; ext4_grpblk_t first_free_block;
struct rb_root *fs_rsv_root = &EXT3_SB(sb)->s_rsv_window_root; struct rb_root *fs_rsv_root = &EXT4_SB(sb)->s_rsv_window_root;
unsigned long size; unsigned long size;
int ret; int ret;
spinlock_t *rsv_lock = &EXT3_SB(sb)->s_rsv_window_lock; spinlock_t *rsv_lock = &EXT4_SB(sb)->s_rsv_window_lock;
group_first_block = ext3_group_first_block_no(sb, group); group_first_block = ext4_group_first_block_no(sb, group);
group_end_block = group_first_block + (EXT3_BLOCKS_PER_GROUP(sb) - 1); group_end_block = group_first_block + (EXT4_BLOCKS_PER_GROUP(sb) - 1);
if (grp_goal < 0) if (grp_goal < 0)
start_block = group_first_block; start_block = group_first_block;
...@@ -1085,8 +1085,8 @@ static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv, ...@@ -1085,8 +1085,8 @@ static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv,
* otherwise we keep the same size window * otherwise we keep the same size window
*/ */
size = size * 2; size = size * 2;
if (size > EXT3_MAX_RESERVE_BLOCKS) if (size > EXT4_MAX_RESERVE_BLOCKS)
size = EXT3_MAX_RESERVE_BLOCKS; size = EXT4_MAX_RESERVE_BLOCKS;
my_rsv->rsv_goal_size= size; my_rsv->rsv_goal_size= size;
} }
} }
...@@ -1170,20 +1170,20 @@ static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv, ...@@ -1170,20 +1170,20 @@ static int alloc_new_reservation(struct ext3_reserve_window_node *my_rsv,
* Attempt to expand the reservation window large enough to have * Attempt to expand the reservation window large enough to have
* required number of free blocks * required number of free blocks
* *
* Since ext3_try_to_allocate() will always allocate blocks within * Since ext4_try_to_allocate() will always allocate blocks within
* the reservation window range, if the window size is too small, * the reservation window range, if the window size is too small,
* multiple blocks allocation has to stop at the end of the reservation * multiple blocks allocation has to stop at the end of the reservation
* window. To make this more efficient, given the total number of * window. To make this more efficient, given the total number of
* blocks needed and the current size of the window, we try to * blocks needed and the current size of the window, we try to
* expand the reservation window size if necessary on a best-effort * expand the reservation window size if necessary on a best-effort
* basis before ext3_new_blocks() tries to allocate blocks, * basis before ext4_new_blocks() tries to allocate blocks,
*/ */
static void try_to_extend_reservation(struct ext3_reserve_window_node *my_rsv, static void try_to_extend_reservation(struct ext4_reserve_window_node *my_rsv,
struct super_block *sb, int size) struct super_block *sb, int size)
{ {
struct ext3_reserve_window_node *next_rsv; struct ext4_reserve_window_node *next_rsv;
struct rb_node *next; struct rb_node *next;
spinlock_t *rsv_lock = &EXT3_SB(sb)->s_rsv_window_lock; spinlock_t *rsv_lock = &EXT4_SB(sb)->s_rsv_window_lock;
if (!spin_trylock(rsv_lock)) if (!spin_trylock(rsv_lock))
return; return;
...@@ -1193,7 +1193,7 @@ static void try_to_extend_reservation(struct ext3_reserve_window_node *my_rsv, ...@@ -1193,7 +1193,7 @@ static void try_to_extend_reservation(struct ext3_reserve_window_node *my_rsv,
if (!next) if (!next)
my_rsv->rsv_end += size; my_rsv->rsv_end += size;
else { else {
next_rsv = list_entry(next, struct ext3_reserve_window_node, rsv_node); next_rsv = list_entry(next, struct ext4_reserve_window_node, rsv_node);
if ((next_rsv->rsv_start - my_rsv->rsv_end - 1) >= size) if ((next_rsv->rsv_start - my_rsv->rsv_end - 1) >= size)
my_rsv->rsv_end += size; my_rsv->rsv_end += size;
...@@ -1204,7 +1204,7 @@ static void try_to_extend_reservation(struct ext3_reserve_window_node *my_rsv, ...@@ -1204,7 +1204,7 @@ static void try_to_extend_reservation(struct ext3_reserve_window_node *my_rsv,
} }
/** /**
* ext3_try_to_allocate_with_rsv() * ext4_try_to_allocate_with_rsv()
* @sb: superblock * @sb: superblock
* @handle: handle to this transaction * @handle: handle to this transaction
* @group: given allocation block group * @group: given allocation block group
...@@ -1232,15 +1232,15 @@ static void try_to_extend_reservation(struct ext3_reserve_window_node *my_rsv, ...@@ -1232,15 +1232,15 @@ static void try_to_extend_reservation(struct ext3_reserve_window_node *my_rsv,
* We use a red-black tree for the per-filesystem reservation list. * We use a red-black tree for the per-filesystem reservation list.
* *
*/ */
static ext3_grpblk_t static ext4_grpblk_t
ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle, ext4_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
unsigned int group, struct buffer_head *bitmap_bh, unsigned int group, struct buffer_head *bitmap_bh,
ext3_grpblk_t grp_goal, ext4_grpblk_t grp_goal,
struct ext3_reserve_window_node * my_rsv, struct ext4_reserve_window_node * my_rsv,
unsigned long *count, int *errp) unsigned long *count, int *errp)
{ {
ext3_fsblk_t group_first_block, group_last_block; ext4_fsblk_t group_first_block, group_last_block;
ext3_grpblk_t ret = 0; ext4_grpblk_t ret = 0;
int fatal; int fatal;
unsigned long num = *count; unsigned long num = *count;
...@@ -1252,7 +1252,7 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle, ...@@ -1252,7 +1252,7 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
* if the buffer is in BJ_Forget state in the committing transaction. * if the buffer is in BJ_Forget state in the committing transaction.
*/ */
BUFFER_TRACE(bitmap_bh, "get undo access for new block"); BUFFER_TRACE(bitmap_bh, "get undo access for new block");
fatal = ext3_journal_get_undo_access(handle, bitmap_bh); fatal = ext4_journal_get_undo_access(handle, bitmap_bh);
if (fatal) { if (fatal) {
*errp = fatal; *errp = fatal;
return -1; return -1;
...@@ -1265,18 +1265,18 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle, ...@@ -1265,18 +1265,18 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
* or last attempt to allocate a block with reservation turned on failed * or last attempt to allocate a block with reservation turned on failed
*/ */
if (my_rsv == NULL ) { if (my_rsv == NULL ) {
ret = ext3_try_to_allocate(sb, handle, group, bitmap_bh, ret = ext4_try_to_allocate(sb, handle, group, bitmap_bh,
grp_goal, count, NULL); grp_goal, count, NULL);
goto out; goto out;
} }
/* /*
* grp_goal is a group relative block number (if there is a goal) * grp_goal is a group relative block number (if there is a goal)
* 0 < grp_goal < EXT3_BLOCKS_PER_GROUP(sb) * 0 < grp_goal < EXT4_BLOCKS_PER_GROUP(sb)
* first block is a filesystem wide block number * first block is a filesystem wide block number
* first block is the block number of the first block in this group * first block is the block number of the first block in this group
*/ */
group_first_block = ext3_group_first_block_no(sb, group); group_first_block = ext4_group_first_block_no(sb, group);
group_last_block = group_first_block + (EXT3_BLOCKS_PER_GROUP(sb) - 1); group_last_block = group_first_block + (EXT4_BLOCKS_PER_GROUP(sb) - 1);
/* /*
* Basically we will allocate a new block from inode's reservation * 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,10 +1314,10 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
if ((my_rsv->rsv_start > group_last_block) || if ((my_rsv->rsv_start > group_last_block) ||
(my_rsv->rsv_end < group_first_block)) { (my_rsv->rsv_end < group_first_block)) {
rsv_window_dump(&EXT3_SB(sb)->s_rsv_window_root, 1); rsv_window_dump(&EXT4_SB(sb)->s_rsv_window_root, 1);
BUG(); BUG();
} }
ret = ext3_try_to_allocate(sb, handle, group, bitmap_bh, ret = ext4_try_to_allocate(sb, handle, group, bitmap_bh,
grp_goal, &num, &my_rsv->rsv_window); grp_goal, &num, &my_rsv->rsv_window);
if (ret >= 0) { if (ret >= 0) {
my_rsv->rsv_alloc_hit += num; my_rsv->rsv_alloc_hit += num;
...@@ -1330,7 +1330,7 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle, ...@@ -1330,7 +1330,7 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
if (ret >= 0) { if (ret >= 0) {
BUFFER_TRACE(bitmap_bh, "journal_dirty_metadata for " BUFFER_TRACE(bitmap_bh, "journal_dirty_metadata for "
"bitmap block"); "bitmap block");
fatal = ext3_journal_dirty_metadata(handle, bitmap_bh); fatal = ext4_journal_dirty_metadata(handle, bitmap_bh);
if (fatal) { if (fatal) {
*errp = fatal; *errp = fatal;
return -1; return -1;
...@@ -1339,19 +1339,19 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle, ...@@ -1339,19 +1339,19 @@ ext3_try_to_allocate_with_rsv(struct super_block *sb, handle_t *handle,
} }
BUFFER_TRACE(bitmap_bh, "journal_release_buffer"); BUFFER_TRACE(bitmap_bh, "journal_release_buffer");
ext3_journal_release_buffer(handle, bitmap_bh); ext4_journal_release_buffer(handle, bitmap_bh);
return ret; return ret;
} }
/** /**
* ext3_has_free_blocks() * ext4_has_free_blocks()
* @sbi: in-core super block structure. * @sbi: in-core super block structure.
* *
* Check if filesystem has at least 1 free block available for allocation. * Check if filesystem has at least 1 free block available for allocation.
*/ */
static int ext3_has_free_blocks(struct ext3_sb_info *sbi) static int ext4_has_free_blocks(struct ext4_sb_info *sbi)
{ {
ext3_fsblk_t free_blocks, root_blocks; ext4_fsblk_t free_blocks, root_blocks;
free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter); free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count); 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,63 +1364,63 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
} }
/** /**
* ext3_should_retry_alloc() * ext4_should_retry_alloc()
* @sb: super block * @sb: super block
* @retries number of attemps has been made * @retries number of attemps has been made
* *
* ext3_should_retry_alloc() is called when ENOSPC is returned, and if * ext4_should_retry_alloc() is called when ENOSPC is returned, and if
* it is profitable to retry the operation, this function will wait * it is profitable to retry the operation, this function will wait
* for the current or commiting transaction to complete, and then * for the current or commiting transaction to complete, and then
* return TRUE. * return TRUE.
* *
* if the total number of retries exceed three times, return FALSE. * if the total number of retries exceed three times, return FALSE.
*/ */
int ext3_should_retry_alloc(struct super_block *sb, int *retries) int ext4_should_retry_alloc(struct super_block *sb, int *retries)
{ {
if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3) if (!ext4_has_free_blocks(EXT4_SB(sb)) || (*retries)++ > 3)
return 0; return 0;
jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id); jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
return journal_force_commit_nested(EXT3_SB(sb)->s_journal); return journal_force_commit_nested(EXT4_SB(sb)->s_journal);
} }
/** /**
* ext3_new_blocks() -- core block(s) allocation function * ext4_new_blocks() -- core block(s) allocation function
* @handle: handle to this transaction * @handle: handle to this transaction
* @inode: file inode * @inode: file inode
* @goal: given target block(filesystem wide) * @goal: given target block(filesystem wide)
* @count: target number of blocks to allocate * @count: target number of blocks to allocate
* @errp: error code * @errp: error code
* *
* ext3_new_blocks uses a goal block to assist allocation. It tries to * ext4_new_blocks uses a goal block to assist allocation. It tries to
* allocate block(s) from the block group contains the goal block first. If that * allocate block(s) from the block group contains the goal block first. If that
* fails, it will try to allocate block(s) from other block groups without * fails, it will try to allocate block(s) from other block groups without
* any specific goal block. * any specific goal block.
* *
*/ */
ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode, ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
ext3_fsblk_t goal, unsigned long *count, int *errp) ext4_fsblk_t goal, unsigned long *count, int *errp)
{ {
struct buffer_head *bitmap_bh = NULL; struct buffer_head *bitmap_bh = NULL;
struct buffer_head *gdp_bh; struct buffer_head *gdp_bh;
int group_no; int group_no;
int goal_group; int goal_group;
ext3_grpblk_t grp_target_blk; /* blockgroup relative goal block */ ext4_grpblk_t grp_target_blk; /* blockgroup relative goal block */
ext3_grpblk_t grp_alloc_blk; /* blockgroup-relative allocated block*/ ext4_grpblk_t grp_alloc_blk; /* blockgroup-relative allocated block*/
ext3_fsblk_t ret_block; /* filesyetem-wide allocated block */ ext4_fsblk_t ret_block; /* filesyetem-wide allocated block */
int bgi; /* blockgroup iteration index */ int bgi; /* blockgroup iteration index */
int fatal = 0, err; int fatal = 0, err;
int performed_allocation = 0; int performed_allocation = 0;
ext3_grpblk_t free_blocks; /* number of free blocks in a group */ ext4_grpblk_t free_blocks; /* number of free blocks in a group */
struct super_block *sb; struct super_block *sb;
struct ext3_group_desc *gdp; struct ext4_group_desc *gdp;
struct ext3_super_block *es; struct ext4_super_block *es;
struct ext3_sb_info *sbi; struct ext4_sb_info *sbi;
struct ext3_reserve_window_node *my_rsv = NULL; struct ext4_reserve_window_node *my_rsv = NULL;
struct ext3_block_alloc_info *block_i; struct ext4_block_alloc_info *block_i;
unsigned short windowsz = 0; unsigned short windowsz = 0;
#ifdef EXT3FS_DEBUG #ifdef EXT4FS_DEBUG
static int goal_hits, goal_attempts; static int goal_hits, goal_attempts;
#endif #endif
unsigned long ngroups; unsigned long ngroups;
...@@ -1429,7 +1429,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode, ...@@ -1429,7 +1429,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
*errp = -ENOSPC; *errp = -ENOSPC;
sb = inode->i_sb; sb = inode->i_sb;
if (!sb) { if (!sb) {
printk("ext3_new_block: nonexistent device"); printk("ext4_new_block: nonexistent device");
return 0; return 0;
} }
...@@ -1441,22 +1441,22 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode, ...@@ -1441,22 +1441,22 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
return 0; return 0;
} }
sbi = EXT3_SB(sb); sbi = EXT4_SB(sb);
es = EXT3_SB(sb)->s_es; es = EXT4_SB(sb)->s_es;
ext3_debug("goal=%lu.\n", goal); ext4_debug("goal=%lu.\n", goal);
/* /*
* Allocate a block from reservation only when * Allocate a block from reservation only when
* filesystem is mounted with reservation(default,-o reservation), and * filesystem is mounted with reservation(default,-o reservation), and
* it's a regular file, and * it's a regular file, and
* the desired window size is greater than 0 (One could use ioctl * the desired window size is greater than 0 (One could use ioctl
* command EXT3_IOC_SETRSVSZ to set the window size to 0 to turn off * command EXT4_IOC_SETRSVSZ to set the window size to 0 to turn off
* reservation on that particular file) * reservation on that particular file)
*/ */
block_i = EXT3_I(inode)->i_block_alloc_info; block_i = EXT4_I(inode)->i_block_alloc_info;
if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0)) if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
my_rsv = &block_i->rsv_window_node; my_rsv = &block_i->rsv_window_node;
if (!ext3_has_free_blocks(sbi)) { if (!ext4_has_free_blocks(sbi)) {
*errp = -ENOSPC; *errp = -ENOSPC;
goto out; goto out;
} }
...@@ -1468,10 +1468,10 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode, ...@@ -1468,10 +1468,10 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
goal >= le32_to_cpu(es->s_blocks_count)) goal >= le32_to_cpu(es->s_blocks_count))
goal = le32_to_cpu(es->s_first_data_block); goal = le32_to_cpu(es->s_first_data_block);
group_no = (goal - le32_to_cpu(es->s_first_data_block)) / group_no = (goal - le32_to_cpu(es->s_first_data_block)) /
EXT3_BLOCKS_PER_GROUP(sb); EXT4_BLOCKS_PER_GROUP(sb);
goal_group = group_no; goal_group = group_no;
retry_alloc: retry_alloc:
gdp = ext3_get_group_desc(sb, group_no, &gdp_bh); gdp = ext4_get_group_desc(sb, group_no, &gdp_bh);
if (!gdp) if (!gdp)
goto io_error; goto io_error;
...@@ -1486,11 +1486,11 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode, ...@@ -1486,11 +1486,11 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
if (free_blocks > 0) { if (free_blocks > 0) {
grp_target_blk = ((goal - le32_to_cpu(es->s_first_data_block)) % grp_target_blk = ((goal - le32_to_cpu(es->s_first_data_block)) %
EXT3_BLOCKS_PER_GROUP(sb)); EXT4_BLOCKS_PER_GROUP(sb));
bitmap_bh = read_block_bitmap(sb, group_no); bitmap_bh = read_block_bitmap(sb, group_no);
if (!bitmap_bh) if (!bitmap_bh)
goto io_error; goto io_error;
grp_alloc_blk = ext3_try_to_allocate_with_rsv(sb, handle, grp_alloc_blk = ext4_try_to_allocate_with_rsv(sb, handle,
group_no, bitmap_bh, grp_target_blk, group_no, bitmap_bh, grp_target_blk,
my_rsv, &num, &fatal); my_rsv, &num, &fatal);
if (fatal) if (fatal)
...@@ -1499,7 +1499,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode, ...@@ -1499,7 +1499,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
goto allocated; goto allocated;
} }
ngroups = EXT3_SB(sb)->s_groups_count; ngroups = EXT4_SB(sb)->s_groups_count;
smp_rmb(); smp_rmb();
/* /*
...@@ -1510,7 +1510,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode, ...@@ -1510,7 +1510,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
group_no++; group_no++;
if (group_no >= ngroups) if (group_no >= ngroups)
group_no = 0; group_no = 0;
gdp = ext3_get_group_desc(sb, group_no, &gdp_bh); gdp = ext4_get_group_desc(sb, group_no, &gdp_bh);
if (!gdp) { if (!gdp) {
*errp = -EIO; *errp = -EIO;
goto out; goto out;
...@@ -1531,7 +1531,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode, ...@@ -1531,7 +1531,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
/* /*
* try to allocate block(s) from this group, without a goal(-1). * try to allocate block(s) from this group, without a goal(-1).
*/ */
grp_alloc_blk = ext3_try_to_allocate_with_rsv(sb, handle, grp_alloc_blk = ext4_try_to_allocate_with_rsv(sb, handle,
group_no, bitmap_bh, -1, my_rsv, group_no, bitmap_bh, -1, my_rsv,
&num, &fatal); &num, &fatal);
if (fatal) if (fatal)
...@@ -1557,23 +1557,23 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode, ...@@ -1557,23 +1557,23 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
allocated: allocated:
ext3_debug("using block group %d(%d)\n", ext4_debug("using block group %d(%d)\n",
group_no, gdp->bg_free_blocks_count); group_no, gdp->bg_free_blocks_count);
BUFFER_TRACE(gdp_bh, "get_write_access"); BUFFER_TRACE(gdp_bh, "get_write_access");
fatal = ext3_journal_get_write_access(handle, gdp_bh); fatal = ext4_journal_get_write_access(handle, gdp_bh);
if (fatal) if (fatal)
goto out; goto out;
ret_block = grp_alloc_blk + ext3_group_first_block_no(sb, group_no); ret_block = grp_alloc_blk + ext4_group_first_block_no(sb, group_no);
if (in_range(le32_to_cpu(gdp->bg_block_bitmap), ret_block, num) || if (in_range(le32_to_cpu(gdp->bg_block_bitmap), ret_block, num) ||
in_range(le32_to_cpu(gdp->bg_inode_bitmap), ret_block, num) || in_range(le32_to_cpu(gdp->bg_inode_bitmap), ret_block, num) ||
in_range(ret_block, le32_to_cpu(gdp->bg_inode_table), in_range(ret_block, le32_to_cpu(gdp->bg_inode_table),
EXT3_SB(sb)->s_itb_per_group) || EXT4_SB(sb)->s_itb_per_group) ||
in_range(ret_block + num - 1, le32_to_cpu(gdp->bg_inode_table), in_range(ret_block + num - 1, le32_to_cpu(gdp->bg_inode_table),
EXT3_SB(sb)->s_itb_per_group)) EXT4_SB(sb)->s_itb_per_group))
ext3_error(sb, "ext3_new_block", ext4_error(sb, "ext4_new_block",
"Allocating block in system zone - " "Allocating block in system zone - "
"blocks from "E3FSBLK", length %lu", "blocks from "E3FSBLK", length %lu",
ret_block, num); ret_block, num);
...@@ -1598,20 +1598,20 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode, ...@@ -1598,20 +1598,20 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
int i; int i;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
if (ext3_test_bit(grp_alloc_blk+i, if (ext4_test_bit(grp_alloc_blk+i,
bh2jh(bitmap_bh)->b_committed_data)) { bh2jh(bitmap_bh)->b_committed_data)) {
printk("%s: block was unexpectedly set in " printk("%s: block was unexpectedly set in "
"b_committed_data\n", __FUNCTION__); "b_committed_data\n", __FUNCTION__);
} }
} }
} }
ext3_debug("found bit %d\n", grp_alloc_blk); ext4_debug("found bit %d\n", grp_alloc_blk);
spin_unlock(sb_bgl_lock(sbi, group_no)); spin_unlock(sb_bgl_lock(sbi, group_no));
jbd_unlock_bh_state(bitmap_bh); jbd_unlock_bh_state(bitmap_bh);
#endif #endif
if (ret_block + num - 1 >= le32_to_cpu(es->s_blocks_count)) { if (ret_block + num - 1 >= le32_to_cpu(es->s_blocks_count)) {
ext3_error(sb, "ext3_new_block", ext4_error(sb, "ext4_new_block",
"block("E3FSBLK") >= blocks count(%d) - " "block("E3FSBLK") >= blocks count(%d) - "
"block_group = %d, es == %p ", ret_block, "block_group = %d, es == %p ", ret_block,
le32_to_cpu(es->s_blocks_count), group_no, es); le32_to_cpu(es->s_blocks_count), group_no, es);
...@@ -1623,7 +1623,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode, ...@@ -1623,7 +1623,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
* list of some description. We don't know in advance whether * list of some description. We don't know in advance whether
* the caller wants to use it as metadata or data. * the caller wants to use it as metadata or data.
*/ */
ext3_debug("allocating block %lu. Goal hits %d of %d.\n", ext4_debug("allocating block %lu. Goal hits %d of %d.\n",
ret_block, goal_hits, goal_attempts); ret_block, goal_hits, goal_attempts);
spin_lock(sb_bgl_lock(sbi, group_no)); spin_lock(sb_bgl_lock(sbi, group_no));
...@@ -1633,7 +1633,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode, ...@@ -1633,7 +1633,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
percpu_counter_mod(&sbi->s_freeblocks_counter, -num); percpu_counter_mod(&sbi->s_freeblocks_counter, -num);
BUFFER_TRACE(gdp_bh, "journal_dirty_metadata for group descriptor"); BUFFER_TRACE(gdp_bh, "journal_dirty_metadata for group descriptor");
err = ext3_journal_dirty_metadata(handle, gdp_bh); err = ext4_journal_dirty_metadata(handle, gdp_bh);
if (!fatal) if (!fatal)
fatal = err; fatal = err;
...@@ -1652,7 +1652,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode, ...@@ -1652,7 +1652,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
out: out:
if (fatal) { if (fatal) {
*errp = fatal; *errp = fatal;
ext3_std_error(sb, fatal); ext4_std_error(sb, fatal);
} }
/* /*
* Undo the block allocation * Undo the block allocation
...@@ -1663,40 +1663,40 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode, ...@@ -1663,40 +1663,40 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
return 0; return 0;
} }
ext3_fsblk_t ext3_new_block(handle_t *handle, struct inode *inode, ext4_fsblk_t ext4_new_block(handle_t *handle, struct inode *inode,
ext3_fsblk_t goal, int *errp) ext4_fsblk_t goal, int *errp)
{ {
unsigned long count = 1; unsigned long count = 1;
return ext3_new_blocks(handle, inode, goal, &count, errp); return ext4_new_blocks(handle, inode, goal, &count, errp);
} }
/** /**
* ext3_count_free_blocks() -- count filesystem free blocks * ext4_count_free_blocks() -- count filesystem free blocks
* @sb: superblock * @sb: superblock
* *
* Adds up the number of free blocks from each block group. * Adds up the number of free blocks from each block group.
*/ */
ext3_fsblk_t ext3_count_free_blocks(struct super_block *sb) ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)
{ {
ext3_fsblk_t desc_count; ext4_fsblk_t desc_count;
struct ext3_group_desc *gdp; struct ext4_group_desc *gdp;
int i; int i;
unsigned long ngroups = EXT3_SB(sb)->s_groups_count; unsigned long ngroups = EXT4_SB(sb)->s_groups_count;
#ifdef EXT3FS_DEBUG #ifdef EXT4FS_DEBUG
struct ext3_super_block *es; struct ext4_super_block *es;
ext3_fsblk_t bitmap_count; ext4_fsblk_t bitmap_count;
unsigned long x; unsigned long x;
struct buffer_head *bitmap_bh = NULL; struct buffer_head *bitmap_bh = NULL;
es = EXT3_SB(sb)->s_es; es = EXT4_SB(sb)->s_es;
desc_count = 0; desc_count = 0;
bitmap_count = 0; bitmap_count = 0;
gdp = NULL; gdp = NULL;
smp_rmb(); smp_rmb();
for (i = 0; i < ngroups; i++) { for (i = 0; i < ngroups; i++) {
gdp = ext3_get_group_desc(sb, i, NULL); gdp = ext4_get_group_desc(sb, i, NULL);
if (!gdp) if (!gdp)
continue; continue;
desc_count += le16_to_cpu(gdp->bg_free_blocks_count); 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,13 +1705,13 @@ ext3_fsblk_t ext3_count_free_blocks(struct super_block *sb)
if (bitmap_bh == NULL) if (bitmap_bh == NULL)
continue; continue;
x = ext3_count_free(bitmap_bh, sb->s_blocksize); x = ext4_count_free(bitmap_bh, sb->s_blocksize);
printk("group %d: stored = %d, counted = %lu\n", printk("group %d: stored = %d, counted = %lu\n",
i, le16_to_cpu(gdp->bg_free_blocks_count), x); i, le16_to_cpu(gdp->bg_free_blocks_count), x);
bitmap_count += x; bitmap_count += x;
} }
brelse(bitmap_bh); brelse(bitmap_bh);
printk("ext3_count_free_blocks: stored = "E3FSBLK printk("ext4_count_free_blocks: stored = "E3FSBLK
", computed = "E3FSBLK", "E3FSBLK"\n", ", computed = "E3FSBLK", "E3FSBLK"\n",
le32_to_cpu(es->s_free_blocks_count), le32_to_cpu(es->s_free_blocks_count),
desc_count, bitmap_count); desc_count, bitmap_count);
...@@ -1720,7 +1720,7 @@ ext3_fsblk_t ext3_count_free_blocks(struct super_block *sb) ...@@ -1720,7 +1720,7 @@ ext3_fsblk_t ext3_count_free_blocks(struct super_block *sb)
desc_count = 0; desc_count = 0;
smp_rmb(); smp_rmb();
for (i = 0; i < ngroups; i++) { for (i = 0; i < ngroups; i++) {
gdp = ext3_get_group_desc(sb, i, NULL); gdp = ext4_get_group_desc(sb, i, NULL);
if (!gdp) if (!gdp)
continue; continue;
desc_count += le16_to_cpu(gdp->bg_free_blocks_count); 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,11 +1731,11 @@ ext3_fsblk_t ext3_count_free_blocks(struct super_block *sb)
} }
static inline int static inline int
block_in_use(ext3_fsblk_t block, struct super_block *sb, unsigned char *map) block_in_use(ext4_fsblk_t block, struct super_block *sb, unsigned char *map)
{ {
return ext3_test_bit ((block - return ext4_test_bit ((block -
le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block)) % le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) %
EXT3_BLOCKS_PER_GROUP(sb), map); EXT4_BLOCKS_PER_GROUP(sb), map);
} }
static inline int test_root(int a, int b) static inline int test_root(int a, int b)
...@@ -1747,7 +1747,7 @@ static inline int test_root(int a, int b) ...@@ -1747,7 +1747,7 @@ static inline int test_root(int a, int b)
return num == a; return num == a;
} }
static int ext3_group_sparse(int group) static int ext4_group_sparse(int group)
{ {
if (group <= 1) if (group <= 1)
return 1; return 1;
...@@ -1758,44 +1758,44 @@ static int ext3_group_sparse(int group) ...@@ -1758,44 +1758,44 @@ static int ext3_group_sparse(int group)
} }
/** /**
* ext3_bg_has_super - number of blocks used by the superblock in group * ext4_bg_has_super - number of blocks used by the superblock in group
* @sb: superblock for filesystem * @sb: superblock for filesystem
* @group: group number to check * @group: group number to check
* *
* Return the number of blocks used by the superblock (primary or backup) * Return the number of blocks used by the superblock (primary or backup)
* in this group. Currently this will be only 0 or 1. * in this group. Currently this will be only 0 or 1.
*/ */
int ext3_bg_has_super(struct super_block *sb, int group) int ext4_bg_has_super(struct super_block *sb, int group)
{ {
if (EXT3_HAS_RO_COMPAT_FEATURE(sb, if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER) && EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
!ext3_group_sparse(group)) !ext4_group_sparse(group))
return 0; return 0;
return 1; return 1;
} }
static unsigned long ext3_bg_num_gdb_meta(struct super_block *sb, int group) static unsigned long ext4_bg_num_gdb_meta(struct super_block *sb, int group)
{ {
unsigned long metagroup = group / EXT3_DESC_PER_BLOCK(sb); unsigned long metagroup = group / EXT4_DESC_PER_BLOCK(sb);
unsigned long first = metagroup * EXT3_DESC_PER_BLOCK(sb); unsigned long first = metagroup * EXT4_DESC_PER_BLOCK(sb);
unsigned long last = first + EXT3_DESC_PER_BLOCK(sb) - 1; unsigned long last = first + EXT4_DESC_PER_BLOCK(sb) - 1;
if (group == first || group == first + 1 || group == last) if (group == first || group == first + 1 || group == last)
return 1; return 1;
return 0; return 0;
} }
static unsigned long ext3_bg_num_gdb_nometa(struct super_block *sb, int group) static unsigned long ext4_bg_num_gdb_nometa(struct super_block *sb, int group)
{ {
if (EXT3_HAS_RO_COMPAT_FEATURE(sb, if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER) && EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
!ext3_group_sparse(group)) !ext4_group_sparse(group))
return 0; return 0;
return EXT3_SB(sb)->s_gdb_count; return EXT4_SB(sb)->s_gdb_count;
} }
/** /**
* ext3_bg_num_gdb - number of blocks used by the group table in group * ext4_bg_num_gdb - number of blocks used by the group table in group
* @sb: superblock for filesystem * @sb: superblock for filesystem
* @group: group number to check * @group: group number to check
* *
...@@ -1803,16 +1803,16 @@ static unsigned long ext3_bg_num_gdb_nometa(struct super_block *sb, int group) ...@@ -1803,16 +1803,16 @@ static unsigned long ext3_bg_num_gdb_nometa(struct super_block *sb, int group)
* (primary or backup) in this group. In the future there may be a * (primary or backup) in this group. In the future there may be a
* different number of descriptor blocks in each group. * different number of descriptor blocks in each group.
*/ */
unsigned long ext3_bg_num_gdb(struct super_block *sb, int group) unsigned long ext4_bg_num_gdb(struct super_block *sb, int group)
{ {
unsigned long first_meta_bg = unsigned long first_meta_bg =
le32_to_cpu(EXT3_SB(sb)->s_es->s_first_meta_bg); le32_to_cpu(EXT4_SB(sb)->s_es->s_first_meta_bg);
unsigned long metagroup = group / EXT3_DESC_PER_BLOCK(sb); unsigned long metagroup = group / EXT4_DESC_PER_BLOCK(sb);
if (!EXT3_HAS_INCOMPAT_FEATURE(sb,EXT3_FEATURE_INCOMPAT_META_BG) || if (!EXT4_HAS_INCOMPAT_FEATURE(sb,EXT4_FEATURE_INCOMPAT_META_BG) ||
metagroup < first_meta_bg) metagroup < first_meta_bg)
return ext3_bg_num_gdb_nometa(sb,group); return ext4_bg_num_gdb_nometa(sb,group);
return ext3_bg_num_gdb_meta(sb,group); return ext4_bg_num_gdb_meta(sb,group);
} }
/* /*
* linux/fs/ext3/bitmap.c * linux/fs/ext4/bitmap.c
* *
* Copyright (C) 1992, 1993, 1994, 1995 * Copyright (C) 1992, 1993, 1994, 1995
* Remy Card (card@masi.ibp.fr) * Remy Card (card@masi.ibp.fr)
...@@ -9,13 +9,13 @@ ...@@ -9,13 +9,13 @@
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#include <linux/jbd.h> #include <linux/jbd.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#ifdef EXT3FS_DEBUG #ifdef EXT4FS_DEBUG
static int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0}; static int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
unsigned long ext3_count_free (struct buffer_head * map, unsigned int numchars) unsigned long ext4_count_free (struct buffer_head * map, unsigned int numchars)
{ {
unsigned int i; unsigned int i;
unsigned long sum = 0; unsigned long sum = 0;
...@@ -28,5 +28,5 @@ unsigned long ext3_count_free (struct buffer_head * map, unsigned int numchars) ...@@ -28,5 +28,5 @@ unsigned long ext3_count_free (struct buffer_head * map, unsigned int numchars)
return (sum); return (sum);
} }
#endif /* EXT3FS_DEBUG */ #endif /* EXT4FS_DEBUG */
/* /*
* linux/fs/ext3/dir.c * linux/fs/ext4/dir.c
* *
* Copyright (C) 1992, 1993, 1994, 1995 * Copyright (C) 1992, 1993, 1994, 1995
* Remy Card (card@masi.ibp.fr) * Remy Card (card@masi.ibp.fr)
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* Copyright (C) 1991, 1992 Linus Torvalds * Copyright (C) 1991, 1992 Linus Torvalds
* *
* ext3 directory handling functions * ext4 directory handling functions
* *
* Big-endian to little-endian byte-swapping/bitmaps by * Big-endian to little-endian byte-swapping/bitmaps by
* David S. Miller (davem@caip.rutgers.edu), 1995 * David S. Miller (davem@caip.rutgers.edu), 1995
...@@ -23,69 +23,69 @@ ...@@ -23,69 +23,69 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/jbd.h> #include <linux/jbd.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/rbtree.h> #include <linux/rbtree.h>
static unsigned char ext3_filetype_table[] = { static unsigned char ext4_filetype_table[] = {
DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
}; };
static int ext3_readdir(struct file *, void *, filldir_t); static int ext4_readdir(struct file *, void *, filldir_t);
static int ext3_dx_readdir(struct file * filp, static int ext4_dx_readdir(struct file * filp,
void * dirent, filldir_t filldir); void * dirent, filldir_t filldir);
static int ext3_release_dir (struct inode * inode, static int ext4_release_dir (struct inode * inode,
struct file * filp); struct file * filp);
const struct file_operations ext3_dir_operations = { const struct file_operations ext4_dir_operations = {
.llseek = generic_file_llseek, .llseek = generic_file_llseek,
.read = generic_read_dir, .read = generic_read_dir,
.readdir = ext3_readdir, /* we take BKL. needed?*/ .readdir = ext4_readdir, /* we take BKL. needed?*/
.ioctl = ext3_ioctl, /* BKL held */ .ioctl = ext4_ioctl, /* BKL held */
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
.compat_ioctl = ext3_compat_ioctl, .compat_ioctl = ext4_compat_ioctl,
#endif #endif
.fsync = ext3_sync_file, /* BKL held */ .fsync = ext4_sync_file, /* BKL held */
#ifdef CONFIG_EXT3_INDEX #ifdef CONFIG_EXT4_INDEX
.release = ext3_release_dir, .release = ext4_release_dir,
#endif #endif
}; };
static unsigned char get_dtype(struct super_block *sb, int filetype) static unsigned char get_dtype(struct super_block *sb, int filetype)
{ {
if (!EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_FILETYPE) || if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FILETYPE) ||
(filetype >= EXT3_FT_MAX)) (filetype >= EXT4_FT_MAX))
return DT_UNKNOWN; return DT_UNKNOWN;
return (ext3_filetype_table[filetype]); return (ext4_filetype_table[filetype]);
} }
int ext3_check_dir_entry (const char * function, struct inode * dir, int ext4_check_dir_entry (const char * function, struct inode * dir,
struct ext3_dir_entry_2 * de, struct ext4_dir_entry_2 * de,
struct buffer_head * bh, struct buffer_head * bh,
unsigned long offset) unsigned long offset)
{ {
const char * error_msg = NULL; const char * error_msg = NULL;
const int rlen = le16_to_cpu(de->rec_len); const int rlen = le16_to_cpu(de->rec_len);
if (rlen < EXT3_DIR_REC_LEN(1)) if (rlen < EXT4_DIR_REC_LEN(1))
error_msg = "rec_len is smaller than minimal"; error_msg = "rec_len is smaller than minimal";
else if (rlen % 4 != 0) else if (rlen % 4 != 0)
error_msg = "rec_len % 4 != 0"; error_msg = "rec_len % 4 != 0";
else if (rlen < EXT3_DIR_REC_LEN(de->name_len)) else if (rlen < EXT4_DIR_REC_LEN(de->name_len))
error_msg = "rec_len is too small for name_len"; error_msg = "rec_len is too small for name_len";
else if (((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize) else if (((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize)
error_msg = "directory entry across blocks"; error_msg = "directory entry across blocks";
else if (le32_to_cpu(de->inode) > else if (le32_to_cpu(de->inode) >
le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count)) le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count))
error_msg = "inode out of bounds"; error_msg = "inode out of bounds";
if (error_msg != NULL) if (error_msg != NULL)
ext3_error (dir->i_sb, function, ext4_error (dir->i_sb, function,
"bad entry in directory #%lu: %s - " "bad entry in directory #%lu: %s - "
"offset=%lu, inode=%lu, rec_len=%d, name_len=%d", "offset=%lu, inode=%lu, rec_len=%d, name_len=%d",
dir->i_ino, error_msg, offset, dir->i_ino, error_msg, offset,
...@@ -94,13 +94,13 @@ int ext3_check_dir_entry (const char * function, struct inode * dir, ...@@ -94,13 +94,13 @@ int ext3_check_dir_entry (const char * function, struct inode * dir,
return error_msg == NULL ? 1 : 0; return error_msg == NULL ? 1 : 0;
} }
static int ext3_readdir(struct file * filp, static int ext4_readdir(struct file * filp,
void * dirent, filldir_t filldir) void * dirent, filldir_t filldir)
{ {
int error = 0; int error = 0;
unsigned long offset; unsigned long offset;
int i, stored; int i, stored;
struct ext3_dir_entry_2 *de; struct ext4_dir_entry_2 *de;
struct super_block *sb; struct super_block *sb;
int err; int err;
struct inode *inode = filp->f_dentry->d_inode; struct inode *inode = filp->f_dentry->d_inode;
...@@ -108,12 +108,12 @@ static int ext3_readdir(struct file * filp, ...@@ -108,12 +108,12 @@ static int ext3_readdir(struct file * filp,
sb = inode->i_sb; sb = inode->i_sb;
#ifdef CONFIG_EXT3_INDEX #ifdef CONFIG_EXT4_INDEX
if (EXT3_HAS_COMPAT_FEATURE(inode->i_sb, if (EXT4_HAS_COMPAT_FEATURE(inode->i_sb,
EXT3_FEATURE_COMPAT_DIR_INDEX) && EXT4_FEATURE_COMPAT_DIR_INDEX) &&
((EXT3_I(inode)->i_flags & EXT3_INDEX_FL) || ((EXT4_I(inode)->i_flags & EXT4_INDEX_FL) ||
((inode->i_size >> sb->s_blocksize_bits) == 1))) { ((inode->i_size >> sb->s_blocksize_bits) == 1))) {
err = ext3_dx_readdir(filp, dirent, filldir); err = ext4_dx_readdir(filp, dirent, filldir);
if (err != ERR_BAD_DX_DIR) { if (err != ERR_BAD_DX_DIR) {
ret = err; ret = err;
goto out; goto out;
...@@ -122,19 +122,19 @@ static int ext3_readdir(struct file * filp, ...@@ -122,19 +122,19 @@ static int ext3_readdir(struct file * filp,
* We don't set the inode dirty flag since it's not * We don't set the inode dirty flag since it's not
* critical that it get flushed back to the disk. * critical that it get flushed back to the disk.
*/ */
EXT3_I(filp->f_dentry->d_inode)->i_flags &= ~EXT3_INDEX_FL; EXT4_I(filp->f_dentry->d_inode)->i_flags &= ~EXT4_INDEX_FL;
} }
#endif #endif
stored = 0; stored = 0;
offset = filp->f_pos & (sb->s_blocksize - 1); offset = filp->f_pos & (sb->s_blocksize - 1);
while (!error && !stored && filp->f_pos < inode->i_size) { while (!error && !stored && filp->f_pos < inode->i_size) {
unsigned long blk = filp->f_pos >> EXT3_BLOCK_SIZE_BITS(sb); unsigned long blk = filp->f_pos >> EXT4_BLOCK_SIZE_BITS(sb);
struct buffer_head map_bh; struct buffer_head map_bh;
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
map_bh.b_state = 0; map_bh.b_state = 0;
err = ext3_get_blocks_handle(NULL, inode, blk, 1, err = ext4_get_blocks_handle(NULL, inode, blk, 1,
&map_bh, 0, 0); &map_bh, 0, 0);
if (err > 0) { if (err > 0) {
page_cache_readahead(sb->s_bdev->bd_inode->i_mapping, page_cache_readahead(sb->s_bdev->bd_inode->i_mapping,
...@@ -143,7 +143,7 @@ static int ext3_readdir(struct file * filp, ...@@ -143,7 +143,7 @@ static int ext3_readdir(struct file * filp,
map_bh.b_blocknr >> map_bh.b_blocknr >>
(PAGE_CACHE_SHIFT - inode->i_blkbits), (PAGE_CACHE_SHIFT - inode->i_blkbits),
1); 1);
bh = ext3_bread(NULL, inode, blk, 0, &err); bh = ext4_bread(NULL, inode, blk, 0, &err);
} }
/* /*
...@@ -151,7 +151,7 @@ static int ext3_readdir(struct file * filp, ...@@ -151,7 +151,7 @@ static int ext3_readdir(struct file * filp,
* of recovering data when there's a bad sector * of recovering data when there's a bad sector
*/ */
if (!bh) { if (!bh) {
ext3_error (sb, "ext3_readdir", ext4_error (sb, "ext4_readdir",
"directory #%lu contains a hole at offset %lu", "directory #%lu contains a hole at offset %lu",
inode->i_ino, (unsigned long)filp->f_pos); inode->i_ino, (unsigned long)filp->f_pos);
filp->f_pos += sb->s_blocksize - offset; filp->f_pos += sb->s_blocksize - offset;
...@@ -165,7 +165,7 @@ static int ext3_readdir(struct file * filp, ...@@ -165,7 +165,7 @@ static int ext3_readdir(struct file * filp,
* to make sure. */ * to make sure. */
if (filp->f_version != inode->i_version) { if (filp->f_version != inode->i_version) {
for (i = 0; i < sb->s_blocksize && i < offset; ) { for (i = 0; i < sb->s_blocksize && i < offset; ) {
de = (struct ext3_dir_entry_2 *) de = (struct ext4_dir_entry_2 *)
(bh->b_data + i); (bh->b_data + i);
/* It's too expensive to do a full /* It's too expensive to do a full
* dirent test each time round this * dirent test each time round this
...@@ -174,7 +174,7 @@ static int ext3_readdir(struct file * filp, ...@@ -174,7 +174,7 @@ static int ext3_readdir(struct file * filp,
* failure will be detected in the * failure will be detected in the
* dirent test below. */ * dirent test below. */
if (le16_to_cpu(de->rec_len) < if (le16_to_cpu(de->rec_len) <
EXT3_DIR_REC_LEN(1)) EXT4_DIR_REC_LEN(1))
break; break;
i += le16_to_cpu(de->rec_len); i += le16_to_cpu(de->rec_len);
} }
...@@ -186,8 +186,8 @@ static int ext3_readdir(struct file * filp, ...@@ -186,8 +186,8 @@ static int ext3_readdir(struct file * filp,
while (!error && filp->f_pos < inode->i_size while (!error && filp->f_pos < inode->i_size
&& offset < sb->s_blocksize) { && offset < sb->s_blocksize) {
de = (struct ext3_dir_entry_2 *) (bh->b_data + offset); de = (struct ext4_dir_entry_2 *) (bh->b_data + offset);
if (!ext3_check_dir_entry ("ext3_readdir", inode, de, if (!ext4_check_dir_entry ("ext4_readdir", inode, de,
bh, offset)) { bh, offset)) {
/* On error, skip the f_pos to the /* On error, skip the f_pos to the
next block. */ next block. */
...@@ -228,7 +228,7 @@ static int ext3_readdir(struct file * filp, ...@@ -228,7 +228,7 @@ static int ext3_readdir(struct file * filp,
return ret; return ret;
} }
#ifdef CONFIG_EXT3_INDEX #ifdef CONFIG_EXT4_INDEX
/* /*
* These functions convert from the major/minor hash to an f_pos * These functions convert from the major/minor hash to an f_pos
* value. * value.
...@@ -323,7 +323,7 @@ static struct dir_private_info *create_dir_info(loff_t pos) ...@@ -323,7 +323,7 @@ static struct dir_private_info *create_dir_info(loff_t pos)
return p; return p;
} }
void ext3_htree_free_dir_info(struct dir_private_info *p) void ext4_htree_free_dir_info(struct dir_private_info *p)
{ {
free_rb_tree_fname(&p->root); free_rb_tree_fname(&p->root);
kfree(p); kfree(p);
...@@ -332,9 +332,9 @@ void ext3_htree_free_dir_info(struct dir_private_info *p) ...@@ -332,9 +332,9 @@ void ext3_htree_free_dir_info(struct dir_private_info *p)
/* /*
* Given a directory entry, enter it into the fname rb tree. * Given a directory entry, enter it into the fname rb tree.
*/ */
int ext3_htree_store_dirent(struct file *dir_file, __u32 hash, int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
__u32 minor_hash, __u32 minor_hash,
struct ext3_dir_entry_2 *dirent) struct ext4_dir_entry_2 *dirent)
{ {
struct rb_node **p, *parent = NULL; struct rb_node **p, *parent = NULL;
struct fname * fname, *new_fn; struct fname * fname, *new_fn;
...@@ -390,7 +390,7 @@ int ext3_htree_store_dirent(struct file *dir_file, __u32 hash, ...@@ -390,7 +390,7 @@ int ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
/* /*
* This is a helper function for ext3_dx_readdir. It calls filldir * This is a helper function for ext4_dx_readdir. It calls filldir
* for all entres on the fname linked list. (Normally there is only * for all entres on the fname linked list. (Normally there is only
* one entry on the linked list, unless there are 62 bit hash collisions.) * one entry on the linked list, unless there are 62 bit hash collisions.)
*/ */
...@@ -425,7 +425,7 @@ static int call_filldir(struct file * filp, void * dirent, ...@@ -425,7 +425,7 @@ static int call_filldir(struct file * filp, void * dirent,
return 0; return 0;
} }
static int ext3_dx_readdir(struct file * filp, static int ext4_dx_readdir(struct file * filp,
void * dirent, filldir_t filldir) void * dirent, filldir_t filldir)
{ {
struct dir_private_info *info = filp->private_data; struct dir_private_info *info = filp->private_data;
...@@ -440,7 +440,7 @@ static int ext3_dx_readdir(struct file * filp, ...@@ -440,7 +440,7 @@ static int ext3_dx_readdir(struct file * filp,
filp->private_data = info; filp->private_data = info;
} }
if (filp->f_pos == EXT3_HTREE_EOF) if (filp->f_pos == EXT4_HTREE_EOF)
return 0; /* EOF */ return 0; /* EOF */
/* Some one has messed with f_pos; reset the world */ /* Some one has messed with f_pos; reset the world */
...@@ -474,13 +474,13 @@ static int ext3_dx_readdir(struct file * filp, ...@@ -474,13 +474,13 @@ static int ext3_dx_readdir(struct file * filp,
info->curr_node = NULL; info->curr_node = NULL;
free_rb_tree_fname(&info->root); free_rb_tree_fname(&info->root);
filp->f_version = inode->i_version; filp->f_version = inode->i_version;
ret = ext3_htree_fill_tree(filp, info->curr_hash, ret = ext4_htree_fill_tree(filp, info->curr_hash,
info->curr_minor_hash, info->curr_minor_hash,
&info->next_hash); &info->next_hash);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret == 0) { if (ret == 0) {
filp->f_pos = EXT3_HTREE_EOF; filp->f_pos = EXT4_HTREE_EOF;
break; break;
} }
info->curr_node = rb_first(&info->root); info->curr_node = rb_first(&info->root);
...@@ -495,7 +495,7 @@ static int ext3_dx_readdir(struct file * filp, ...@@ -495,7 +495,7 @@ static int ext3_dx_readdir(struct file * filp,
info->curr_node = rb_next(info->curr_node); info->curr_node = rb_next(info->curr_node);
if (!info->curr_node) { if (!info->curr_node) {
if (info->next_hash == ~0) { if (info->next_hash == ~0) {
filp->f_pos = EXT3_HTREE_EOF; filp->f_pos = EXT4_HTREE_EOF;
break; break;
} }
info->curr_hash = info->next_hash; info->curr_hash = info->next_hash;
...@@ -507,10 +507,10 @@ static int ext3_dx_readdir(struct file * filp, ...@@ -507,10 +507,10 @@ static int ext3_dx_readdir(struct file * filp,
return 0; return 0;
} }
static int ext3_release_dir (struct inode * inode, struct file * filp) static int ext4_release_dir (struct inode * inode, struct file * filp)
{ {
if (filp->private_data) if (filp->private_data)
ext3_htree_free_dir_info(filp->private_data); ext4_htree_free_dir_info(filp->private_data);
return 0; return 0;
} }
......
/* /*
* linux/fs/ext3/file.c * linux/fs/ext4/file.c
* *
* Copyright (C) 1992, 1993, 1994, 1995 * Copyright (C) 1992, 1993, 1994, 1995
* Remy Card (card@masi.ibp.fr) * Remy Card (card@masi.ibp.fr)
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* Copyright (C) 1991, 1992 Linus Torvalds * Copyright (C) 1991, 1992 Linus Torvalds
* *
* ext3 fs regular file handling primitives * ext4 fs regular file handling primitives
* *
* 64-bit file support on 64-bit platforms by Jakub Jelinek * 64-bit file support on 64-bit platforms by Jakub Jelinek
* (jj@sunsite.ms.mff.cuni.cz) * (jj@sunsite.ms.mff.cuni.cz)
...@@ -21,34 +21,34 @@ ...@@ -21,34 +21,34 @@
#include <linux/time.h> #include <linux/time.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/jbd.h> #include <linux/jbd.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#include <linux/ext3_jbd.h> #include <linux/ext4_jbd.h>
#include "xattr.h" #include "xattr.h"
#include "acl.h" #include "acl.h"
/* /*
* Called when an inode is released. Note that this is different * Called when an inode is released. Note that this is different
* from ext3_file_open: open gets called at every open, but release * from ext4_file_open: open gets called at every open, but release
* gets called only when /all/ the files are closed. * gets called only when /all/ the files are closed.
*/ */
static int ext3_release_file (struct inode * inode, struct file * filp) static int ext4_release_file (struct inode * inode, struct file * filp)
{ {
/* if we are the last writer on the inode, drop the block reservation */ /* if we are the last writer on the inode, drop the block reservation */
if ((filp->f_mode & FMODE_WRITE) && if ((filp->f_mode & FMODE_WRITE) &&
(atomic_read(&inode->i_writecount) == 1)) (atomic_read(&inode->i_writecount) == 1))
{ {
mutex_lock(&EXT3_I(inode)->truncate_mutex); mutex_lock(&EXT4_I(inode)->truncate_mutex);
ext3_discard_reservation(inode); ext4_discard_reservation(inode);
mutex_unlock(&EXT3_I(inode)->truncate_mutex); mutex_unlock(&EXT4_I(inode)->truncate_mutex);
} }
if (is_dx(inode) && filp->private_data) if (is_dx(inode) && filp->private_data)
ext3_htree_free_dir_info(filp->private_data); ext4_htree_free_dir_info(filp->private_data);
return 0; return 0;
} }
static ssize_t static ssize_t
ext3_file_write(struct kiocb *iocb, const struct iovec *iov, ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
unsigned long nr_segs, loff_t pos) unsigned long nr_segs, loff_t pos)
{ {
struct file *file = iocb->ki_filp; struct file *file = iocb->ki_filp;
...@@ -79,7 +79,7 @@ ext3_file_write(struct kiocb *iocb, const struct iovec *iov, ...@@ -79,7 +79,7 @@ ext3_file_write(struct kiocb *iocb, const struct iovec *iov,
* Open question --- do we care about flushing timestamps too * Open question --- do we care about flushing timestamps too
* if the inode is IS_SYNC? * if the inode is IS_SYNC?
*/ */
if (!ext3_should_journal_data(inode)) if (!ext4_should_journal_data(inode))
return ret; return ret;
goto force_commit; goto force_commit;
...@@ -100,40 +100,40 @@ ext3_file_write(struct kiocb *iocb, const struct iovec *iov, ...@@ -100,40 +100,40 @@ ext3_file_write(struct kiocb *iocb, const struct iovec *iov,
*/ */
force_commit: force_commit:
err = ext3_force_commit(inode->i_sb); err = ext4_force_commit(inode->i_sb);
if (err) if (err)
return err; return err;
return ret; return ret;
} }
const struct file_operations ext3_file_operations = { const struct file_operations ext4_file_operations = {
.llseek = generic_file_llseek, .llseek = generic_file_llseek,
.read = do_sync_read, .read = do_sync_read,
.write = do_sync_write, .write = do_sync_write,
.aio_read = generic_file_aio_read, .aio_read = generic_file_aio_read,
.aio_write = ext3_file_write, .aio_write = ext4_file_write,
.ioctl = ext3_ioctl, .ioctl = ext4_ioctl,
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
.compat_ioctl = ext3_compat_ioctl, .compat_ioctl = ext4_compat_ioctl,
#endif #endif
.mmap = generic_file_mmap, .mmap = generic_file_mmap,
.open = generic_file_open, .open = generic_file_open,
.release = ext3_release_file, .release = ext4_release_file,
.fsync = ext3_sync_file, .fsync = ext4_sync_file,
.sendfile = generic_file_sendfile, .sendfile = generic_file_sendfile,
.splice_read = generic_file_splice_read, .splice_read = generic_file_splice_read,
.splice_write = generic_file_splice_write, .splice_write = generic_file_splice_write,
}; };
struct inode_operations ext3_file_inode_operations = { struct inode_operations ext4_file_inode_operations = {
.truncate = ext3_truncate, .truncate = ext4_truncate,
.setattr = ext3_setattr, .setattr = ext4_setattr,
#ifdef CONFIG_EXT3_FS_XATTR #ifdef CONFIG_EXT4DEV_FS_XATTR
.setxattr = generic_setxattr, .setxattr = generic_setxattr,
.getxattr = generic_getxattr, .getxattr = generic_getxattr,
.listxattr = ext3_listxattr, .listxattr = ext4_listxattr,
.removexattr = generic_removexattr, .removexattr = generic_removexattr,
#endif #endif
.permission = ext3_permission, .permission = ext4_permission,
}; };
/* /*
* linux/fs/ext3/fsync.c * linux/fs/ext4/fsync.c
* *
* Copyright (C) 1993 Stephen Tweedie (sct@redhat.com) * Copyright (C) 1993 Stephen Tweedie (sct@redhat.com)
* from * from
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* from * from
* linux/fs/minix/truncate.c Copyright (C) 1991, 1992 Linus Torvalds * linux/fs/minix/truncate.c Copyright (C) 1991, 1992 Linus Torvalds
* *
* ext3fs fsync primitive * ext4fs fsync primitive
* *
* Big-endian to little-endian byte-swapping/bitmaps by * Big-endian to little-endian byte-swapping/bitmaps by
* David S. Miller (davem@caip.rutgers.edu), 1995 * David S. Miller (davem@caip.rutgers.edu), 1995
...@@ -27,11 +27,11 @@ ...@@ -27,11 +27,11 @@
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/writeback.h> #include <linux/writeback.h>
#include <linux/jbd.h> #include <linux/jbd.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#include <linux/ext3_jbd.h> #include <linux/ext4_jbd.h>
/* /*
* akpm: A new design for ext3_sync_file(). * akpm: A new design for ext4_sync_file().
* *
* This is only called from sys_fsync(), sys_fdatasync() and sys_msync(). * This is only called from sys_fsync(), sys_fdatasync() and sys_msync().
* There cannot be a transaction open by this task. * There cannot be a transaction open by this task.
...@@ -42,12 +42,12 @@ ...@@ -42,12 +42,12 @@
* inode to disk. * inode to disk.
*/ */
int ext3_sync_file(struct file * file, struct dentry *dentry, int datasync) int ext4_sync_file(struct file * file, struct dentry *dentry, int datasync)
{ {
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
int ret = 0; int ret = 0;
J_ASSERT(ext3_journal_current_handle() == 0); J_ASSERT(ext4_journal_current_handle() == 0);
/* /*
* data=writeback: * data=writeback:
...@@ -61,14 +61,14 @@ int ext3_sync_file(struct file * file, struct dentry *dentry, int datasync) ...@@ -61,14 +61,14 @@ int ext3_sync_file(struct file * file, struct dentry *dentry, int datasync)
* *
* data=journal: * data=journal:
* filemap_fdatawrite won't do anything (the buffers are clean). * filemap_fdatawrite won't do anything (the buffers are clean).
* ext3_force_commit will write the file data into the journal and * ext4_force_commit will write the file data into the journal and
* will wait on that. * will wait on that.
* filemap_fdatawait() will encounter a ton of newly-dirtied pages * filemap_fdatawait() will encounter a ton of newly-dirtied pages
* (they were dirtied by commit). But that's OK - the blocks are * (they were dirtied by commit). But that's OK - the blocks are
* safe in-journal, which is all fsync() needs to ensure. * safe in-journal, which is all fsync() needs to ensure.
*/ */
if (ext3_should_journal_data(inode)) { if (ext4_should_journal_data(inode)) {
ret = ext3_force_commit(inode->i_sb); ret = ext4_force_commit(inode->i_sb);
goto out; goto out;
} }
......
/* /*
* linux/fs/ext3/hash.c * linux/fs/ext4/hash.c
* *
* Copyright (C) 2002 by Theodore Ts'o * Copyright (C) 2002 by Theodore Ts'o
* *
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/jbd.h> #include <linux/jbd.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#include <linux/cryptohash.h> #include <linux/cryptohash.h>
#define DELTA 0x9E3779B9 #define DELTA 0x9E3779B9
...@@ -89,7 +89,7 @@ static void str2hashbuf(const char *msg, int len, __u32 *buf, int num) ...@@ -89,7 +89,7 @@ static void str2hashbuf(const char *msg, int len, __u32 *buf, int num)
* represented, and whether or not the returned hash is 32 bits or 64 * represented, and whether or not the returned hash is 32 bits or 64
* bits. 32 bit hashes will return 0 for the minor hash. * bits. 32 bit hashes will return 0 for the minor hash.
*/ */
int ext3fs_dirhash(const char *name, int len, struct dx_hash_info *hinfo) int ext4fs_dirhash(const char *name, int len, struct dx_hash_info *hinfo)
{ {
__u32 hash; __u32 hash;
__u32 minor_hash = 0; __u32 minor_hash = 0;
...@@ -144,8 +144,8 @@ int ext3fs_dirhash(const char *name, int len, struct dx_hash_info *hinfo) ...@@ -144,8 +144,8 @@ int ext3fs_dirhash(const char *name, int len, struct dx_hash_info *hinfo)
return -1; return -1;
} }
hash = hash & ~1; hash = hash & ~1;
if (hash == (EXT3_HTREE_EOF << 1)) if (hash == (EXT4_HTREE_EOF << 1))
hash = (EXT3_HTREE_EOF-1) << 1; hash = (EXT4_HTREE_EOF-1) << 1;
hinfo->hash = hash; hinfo->hash = hash;
hinfo->minor_hash = minor_hash; hinfo->minor_hash = minor_hash;
return 0; return 0;
......
/* /*
* linux/fs/ext3/ialloc.c * linux/fs/ext4/ialloc.c
* *
* Copyright (C) 1992, 1993, 1994, 1995 * Copyright (C) 1992, 1993, 1994, 1995
* Remy Card (card@masi.ibp.fr) * Remy Card (card@masi.ibp.fr)
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#include <linux/time.h> #include <linux/time.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/jbd.h> #include <linux/jbd.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#include <linux/ext3_jbd.h> #include <linux/ext4_jbd.h>
#include <linux/stat.h> #include <linux/stat.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/quotaops.h> #include <linux/quotaops.h>
...@@ -53,16 +53,16 @@ ...@@ -53,16 +53,16 @@
static struct buffer_head * static struct buffer_head *
read_inode_bitmap(struct super_block * sb, unsigned long block_group) read_inode_bitmap(struct super_block * sb, unsigned long block_group)
{ {
struct ext3_group_desc *desc; struct ext4_group_desc *desc;
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
desc = ext3_get_group_desc(sb, block_group, NULL); desc = ext4_get_group_desc(sb, block_group, NULL);
if (!desc) if (!desc)
goto error_out; goto error_out;
bh = sb_bread(sb, le32_to_cpu(desc->bg_inode_bitmap)); bh = sb_bread(sb, le32_to_cpu(desc->bg_inode_bitmap));
if (!bh) if (!bh)
ext3_error(sb, "read_inode_bitmap", ext4_error(sb, "read_inode_bitmap",
"Cannot read inode bitmap - " "Cannot read inode bitmap - "
"block_group = %lu, inode_bitmap = %u", "block_group = %lu, inode_bitmap = %u",
block_group, le32_to_cpu(desc->bg_inode_bitmap)); block_group, le32_to_cpu(desc->bg_inode_bitmap));
...@@ -86,7 +86,7 @@ read_inode_bitmap(struct super_block * sb, unsigned long block_group) ...@@ -86,7 +86,7 @@ read_inode_bitmap(struct super_block * sb, unsigned long block_group)
* though), and then we'd have two inodes sharing the * though), and then we'd have two inodes sharing the
* same inode number and space on the harddisk. * same inode number and space on the harddisk.
*/ */
void ext3_free_inode (handle_t *handle, struct inode * inode) void ext4_free_inode (handle_t *handle, struct inode * inode)
{ {
struct super_block * sb = inode->i_sb; struct super_block * sb = inode->i_sb;
int is_directory; int is_directory;
...@@ -95,36 +95,36 @@ void ext3_free_inode (handle_t *handle, struct inode * inode) ...@@ -95,36 +95,36 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
struct buffer_head *bh2; struct buffer_head *bh2;
unsigned long block_group; unsigned long block_group;
unsigned long bit; unsigned long bit;
struct ext3_group_desc * gdp; struct ext4_group_desc * gdp;
struct ext3_super_block * es; struct ext4_super_block * es;
struct ext3_sb_info *sbi; struct ext4_sb_info *sbi;
int fatal = 0, err; int fatal = 0, err;
if (atomic_read(&inode->i_count) > 1) { if (atomic_read(&inode->i_count) > 1) {
printk ("ext3_free_inode: inode has count=%d\n", printk ("ext4_free_inode: inode has count=%d\n",
atomic_read(&inode->i_count)); atomic_read(&inode->i_count));
return; return;
} }
if (inode->i_nlink) { if (inode->i_nlink) {
printk ("ext3_free_inode: inode has nlink=%d\n", printk ("ext4_free_inode: inode has nlink=%d\n",
inode->i_nlink); inode->i_nlink);
return; return;
} }
if (!sb) { if (!sb) {
printk("ext3_free_inode: inode on nonexistent device\n"); printk("ext4_free_inode: inode on nonexistent device\n");
return; return;
} }
sbi = EXT3_SB(sb); sbi = EXT4_SB(sb);
ino = inode->i_ino; ino = inode->i_ino;
ext3_debug ("freeing inode %lu\n", ino); ext4_debug ("freeing inode %lu\n", ino);
/* /*
* Note: we must free any quota before locking the superblock, * Note: we must free any quota before locking the superblock,
* as writing the quota to disk may need the lock as well. * as writing the quota to disk may need the lock as well.
*/ */
DQUOT_INIT(inode); DQUOT_INIT(inode);
ext3_xattr_delete_inode(handle, inode); ext4_xattr_delete_inode(handle, inode);
DQUOT_FREE_INODE(inode); DQUOT_FREE_INODE(inode);
DQUOT_DROP(inode); DQUOT_DROP(inode);
...@@ -133,33 +133,33 @@ void ext3_free_inode (handle_t *handle, struct inode * inode) ...@@ -133,33 +133,33 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
/* Do this BEFORE marking the inode not in use or returning an error */ /* Do this BEFORE marking the inode not in use or returning an error */
clear_inode (inode); clear_inode (inode);
es = EXT3_SB(sb)->s_es; es = EXT4_SB(sb)->s_es;
if (ino < EXT3_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) { if (ino < EXT4_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) {
ext3_error (sb, "ext3_free_inode", ext4_error (sb, "ext4_free_inode",
"reserved or nonexistent inode %lu", ino); "reserved or nonexistent inode %lu", ino);
goto error_return; goto error_return;
} }
block_group = (ino - 1) / EXT3_INODES_PER_GROUP(sb); block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
bit = (ino - 1) % EXT3_INODES_PER_GROUP(sb); bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
bitmap_bh = read_inode_bitmap(sb, block_group); bitmap_bh = read_inode_bitmap(sb, block_group);
if (!bitmap_bh) if (!bitmap_bh)
goto error_return; goto error_return;
BUFFER_TRACE(bitmap_bh, "get_write_access"); BUFFER_TRACE(bitmap_bh, "get_write_access");
fatal = ext3_journal_get_write_access(handle, bitmap_bh); fatal = ext4_journal_get_write_access(handle, bitmap_bh);
if (fatal) if (fatal)
goto error_return; goto error_return;
/* Ok, now we can actually update the inode bitmaps.. */ /* Ok, now we can actually update the inode bitmaps.. */
if (!ext3_clear_bit_atomic(sb_bgl_lock(sbi, block_group), if (!ext4_clear_bit_atomic(sb_bgl_lock(sbi, block_group),
bit, bitmap_bh->b_data)) bit, bitmap_bh->b_data))
ext3_error (sb, "ext3_free_inode", ext4_error (sb, "ext4_free_inode",
"bit already cleared for inode %lu", ino); "bit already cleared for inode %lu", ino);
else { else {
gdp = ext3_get_group_desc (sb, block_group, &bh2); gdp = ext4_get_group_desc (sb, block_group, &bh2);
BUFFER_TRACE(bh2, "get_write_access"); BUFFER_TRACE(bh2, "get_write_access");
fatal = ext3_journal_get_write_access(handle, bh2); fatal = ext4_journal_get_write_access(handle, bh2);
if (fatal) goto error_return; if (fatal) goto error_return;
if (gdp) { if (gdp) {
...@@ -175,18 +175,18 @@ void ext3_free_inode (handle_t *handle, struct inode * inode) ...@@ -175,18 +175,18 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
percpu_counter_dec(&sbi->s_dirs_counter); percpu_counter_dec(&sbi->s_dirs_counter);
} }
BUFFER_TRACE(bh2, "call ext3_journal_dirty_metadata"); BUFFER_TRACE(bh2, "call ext4_journal_dirty_metadata");
err = ext3_journal_dirty_metadata(handle, bh2); err = ext4_journal_dirty_metadata(handle, bh2);
if (!fatal) fatal = err; if (!fatal) fatal = err;
} }
BUFFER_TRACE(bitmap_bh, "call ext3_journal_dirty_metadata"); BUFFER_TRACE(bitmap_bh, "call ext4_journal_dirty_metadata");
err = ext3_journal_dirty_metadata(handle, bitmap_bh); err = ext4_journal_dirty_metadata(handle, bitmap_bh);
if (!fatal) if (!fatal)
fatal = err; fatal = err;
sb->s_dirt = 1; sb->s_dirt = 1;
error_return: error_return:
brelse(bitmap_bh); brelse(bitmap_bh);
ext3_std_error(sb, fatal); ext4_std_error(sb, fatal);
} }
/* /*
...@@ -201,17 +201,17 @@ void ext3_free_inode (handle_t *handle, struct inode * inode) ...@@ -201,17 +201,17 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
*/ */
static int find_group_dir(struct super_block *sb, struct inode *parent) static int find_group_dir(struct super_block *sb, struct inode *parent)
{ {
int ngroups = EXT3_SB(sb)->s_groups_count; int ngroups = EXT4_SB(sb)->s_groups_count;
unsigned int freei, avefreei; unsigned int freei, avefreei;
struct ext3_group_desc *desc, *best_desc = NULL; struct ext4_group_desc *desc, *best_desc = NULL;
struct buffer_head *bh; struct buffer_head *bh;
int group, best_group = -1; int group, best_group = -1;
freei = percpu_counter_read_positive(&EXT3_SB(sb)->s_freeinodes_counter); freei = percpu_counter_read_positive(&EXT4_SB(sb)->s_freeinodes_counter);
avefreei = freei / ngroups; avefreei = freei / ngroups;
for (group = 0; group < ngroups; group++) { for (group = 0; group < ngroups; group++) {
desc = ext3_get_group_desc (sb, group, &bh); desc = ext4_get_group_desc (sb, group, &bh);
if (!desc || !desc->bg_free_inodes_count) if (!desc || !desc->bg_free_inodes_count)
continue; continue;
if (le16_to_cpu(desc->bg_free_inodes_count) < avefreei) 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,19 +256,19 @@ static int find_group_dir(struct super_block *sb, struct inode *parent)
static int find_group_orlov(struct super_block *sb, struct inode *parent) static int find_group_orlov(struct super_block *sb, struct inode *parent)
{ {
int parent_group = EXT3_I(parent)->i_block_group; int parent_group = EXT4_I(parent)->i_block_group;
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
struct ext3_super_block *es = sbi->s_es; struct ext4_super_block *es = sbi->s_es;
int ngroups = sbi->s_groups_count; int ngroups = sbi->s_groups_count;
int inodes_per_group = EXT3_INODES_PER_GROUP(sb); int inodes_per_group = EXT4_INODES_PER_GROUP(sb);
unsigned int freei, avefreei; unsigned int freei, avefreei;
ext3_fsblk_t freeb, avefreeb; ext4_fsblk_t freeb, avefreeb;
ext3_fsblk_t blocks_per_dir; ext4_fsblk_t blocks_per_dir;
unsigned int ndirs; unsigned int ndirs;
int max_debt, max_dirs, min_inodes; int max_debt, max_dirs, min_inodes;
ext3_grpblk_t min_blocks; ext4_grpblk_t min_blocks;
int group = -1, i; int group = -1, i;
struct ext3_group_desc *desc; struct ext4_group_desc *desc;
struct buffer_head *bh; struct buffer_head *bh;
freei = percpu_counter_read_positive(&sbi->s_freeinodes_counter); 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,7 +278,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
ndirs = percpu_counter_read_positive(&sbi->s_dirs_counter); ndirs = percpu_counter_read_positive(&sbi->s_dirs_counter);
if ((parent == sb->s_root->d_inode) || if ((parent == sb->s_root->d_inode) ||
(EXT3_I(parent)->i_flags & EXT3_TOPDIR_FL)) { (EXT4_I(parent)->i_flags & EXT4_TOPDIR_FL)) {
int best_ndir = inodes_per_group; int best_ndir = inodes_per_group;
int best_group = -1; int best_group = -1;
...@@ -286,7 +286,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent) ...@@ -286,7 +286,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
parent_group = (unsigned)group % ngroups; parent_group = (unsigned)group % ngroups;
for (i = 0; i < ngroups; i++) { for (i = 0; i < ngroups; i++) {
group = (parent_group + i) % ngroups; group = (parent_group + i) % ngroups;
desc = ext3_get_group_desc (sb, group, &bh); desc = ext4_get_group_desc (sb, group, &bh);
if (!desc || !desc->bg_free_inodes_count) if (!desc || !desc->bg_free_inodes_count)
continue; continue;
if (le16_to_cpu(desc->bg_used_dirs_count) >= best_ndir) 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,9 +307,9 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
max_dirs = ndirs / ngroups + inodes_per_group / 16; max_dirs = ndirs / ngroups + inodes_per_group / 16;
min_inodes = avefreei - inodes_per_group / 4; min_inodes = avefreei - inodes_per_group / 4;
min_blocks = avefreeb - EXT3_BLOCKS_PER_GROUP(sb) / 4; min_blocks = avefreeb - EXT4_BLOCKS_PER_GROUP(sb) / 4;
max_debt = EXT3_BLOCKS_PER_GROUP(sb) / max(blocks_per_dir, (ext3_fsblk_t)BLOCK_COST); max_debt = EXT4_BLOCKS_PER_GROUP(sb) / max(blocks_per_dir, (ext4_fsblk_t)BLOCK_COST);
if (max_debt * INODE_COST > inodes_per_group) if (max_debt * INODE_COST > inodes_per_group)
max_debt = inodes_per_group / INODE_COST; max_debt = inodes_per_group / INODE_COST;
if (max_debt > 255) if (max_debt > 255)
...@@ -319,7 +319,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent) ...@@ -319,7 +319,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
for (i = 0; i < ngroups; i++) { for (i = 0; i < ngroups; i++) {
group = (parent_group + i) % ngroups; group = (parent_group + i) % ngroups;
desc = ext3_get_group_desc (sb, group, &bh); desc = ext4_get_group_desc (sb, group, &bh);
if (!desc || !desc->bg_free_inodes_count) if (!desc || !desc->bg_free_inodes_count)
continue; continue;
if (le16_to_cpu(desc->bg_used_dirs_count) >= max_dirs) 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) ...@@ -334,7 +334,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
fallback: fallback:
for (i = 0; i < ngroups; i++) { for (i = 0; i < ngroups; i++) {
group = (parent_group + i) % ngroups; group = (parent_group + i) % ngroups;
desc = ext3_get_group_desc (sb, group, &bh); desc = ext4_get_group_desc (sb, group, &bh);
if (!desc || !desc->bg_free_inodes_count) if (!desc || !desc->bg_free_inodes_count)
continue; continue;
if (le16_to_cpu(desc->bg_free_inodes_count) >= avefreei) if (le16_to_cpu(desc->bg_free_inodes_count) >= avefreei)
...@@ -355,9 +355,9 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent) ...@@ -355,9 +355,9 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
static int find_group_other(struct super_block *sb, struct inode *parent) static int find_group_other(struct super_block *sb, struct inode *parent)
{ {
int parent_group = EXT3_I(parent)->i_block_group; int parent_group = EXT4_I(parent)->i_block_group;
int ngroups = EXT3_SB(sb)->s_groups_count; int ngroups = EXT4_SB(sb)->s_groups_count;
struct ext3_group_desc *desc; struct ext4_group_desc *desc;
struct buffer_head *bh; struct buffer_head *bh;
int group, i; int group, i;
...@@ -365,7 +365,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent) ...@@ -365,7 +365,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
* Try to place the inode in its parent directory * Try to place the inode in its parent directory
*/ */
group = parent_group; group = parent_group;
desc = ext3_get_group_desc (sb, group, &bh); desc = ext4_get_group_desc (sb, group, &bh);
if (desc && le16_to_cpu(desc->bg_free_inodes_count) && if (desc && le16_to_cpu(desc->bg_free_inodes_count) &&
le16_to_cpu(desc->bg_free_blocks_count)) le16_to_cpu(desc->bg_free_blocks_count))
return group; return group;
...@@ -389,7 +389,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent) ...@@ -389,7 +389,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
group += i; group += i;
if (group >= ngroups) if (group >= ngroups)
group -= ngroups; group -= ngroups;
desc = ext3_get_group_desc (sb, group, &bh); desc = ext4_get_group_desc (sb, group, &bh);
if (desc && le16_to_cpu(desc->bg_free_inodes_count) && if (desc && le16_to_cpu(desc->bg_free_inodes_count) &&
le16_to_cpu(desc->bg_free_blocks_count)) le16_to_cpu(desc->bg_free_blocks_count))
return group; return group;
...@@ -403,7 +403,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent) ...@@ -403,7 +403,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
for (i = 0; i < ngroups; i++) { for (i = 0; i < ngroups; i++) {
if (++group >= ngroups) if (++group >= ngroups)
group = 0; group = 0;
desc = ext3_get_group_desc (sb, group, &bh); desc = ext4_get_group_desc (sb, group, &bh);
if (desc && le16_to_cpu(desc->bg_free_inodes_count)) if (desc && le16_to_cpu(desc->bg_free_inodes_count))
return group; return group;
} }
...@@ -421,7 +421,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent) ...@@ -421,7 +421,7 @@ static int find_group_other(struct super_block *sb, struct inode *parent)
* For other inodes, search forward from the parent directory's block * For other inodes, search forward from the parent directory's block
* group to find a free inode. * group to find a free inode.
*/ */
struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) struct inode *ext4_new_inode(handle_t *handle, struct inode * dir, int mode)
{ {
struct super_block *sb; struct super_block *sb;
struct buffer_head *bitmap_bh = NULL; struct buffer_head *bitmap_bh = NULL;
...@@ -429,10 +429,10 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) ...@@ -429,10 +429,10 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
int group; int group;
unsigned long ino = 0; unsigned long ino = 0;
struct inode * inode; struct inode * inode;
struct ext3_group_desc * gdp = NULL; struct ext4_group_desc * gdp = NULL;
struct ext3_super_block * es; struct ext4_super_block * es;
struct ext3_inode_info *ei; struct ext4_inode_info *ei;
struct ext3_sb_info *sbi; struct ext4_sb_info *sbi;
int err = 0; int err = 0;
struct inode *ret; struct inode *ret;
int i; int i;
...@@ -445,9 +445,9 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) ...@@ -445,9 +445,9 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
inode = new_inode(sb); inode = new_inode(sb);
if (!inode) if (!inode)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
ei = EXT3_I(inode); ei = EXT4_I(inode);
sbi = EXT3_SB(sb); sbi = EXT4_SB(sb);
es = sbi->s_es; es = sbi->s_es;
if (S_ISDIR(mode)) { if (S_ISDIR(mode)) {
if (test_opt (sb, OLDALLOC)) if (test_opt (sb, OLDALLOC))
...@@ -464,7 +464,7 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) ...@@ -464,7 +464,7 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
for (i = 0; i < sbi->s_groups_count; i++) { for (i = 0; i < sbi->s_groups_count; i++) {
err = -EIO; err = -EIO;
gdp = ext3_get_group_desc(sb, group, &bh2); gdp = ext4_get_group_desc(sb, group, &bh2);
if (!gdp) if (!gdp)
goto fail; goto fail;
...@@ -476,21 +476,21 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) ...@@ -476,21 +476,21 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
ino = 0; ino = 0;
repeat_in_this_group: repeat_in_this_group:
ino = ext3_find_next_zero_bit((unsigned long *) ino = ext4_find_next_zero_bit((unsigned long *)
bitmap_bh->b_data, EXT3_INODES_PER_GROUP(sb), ino); bitmap_bh->b_data, EXT4_INODES_PER_GROUP(sb), ino);
if (ino < EXT3_INODES_PER_GROUP(sb)) { if (ino < EXT4_INODES_PER_GROUP(sb)) {
BUFFER_TRACE(bitmap_bh, "get_write_access"); BUFFER_TRACE(bitmap_bh, "get_write_access");
err = ext3_journal_get_write_access(handle, bitmap_bh); err = ext4_journal_get_write_access(handle, bitmap_bh);
if (err) if (err)
goto fail; goto fail;
if (!ext3_set_bit_atomic(sb_bgl_lock(sbi, group), if (!ext4_set_bit_atomic(sb_bgl_lock(sbi, group),
ino, bitmap_bh->b_data)) { ino, bitmap_bh->b_data)) {
/* we won it */ /* we won it */
BUFFER_TRACE(bitmap_bh, BUFFER_TRACE(bitmap_bh,
"call ext3_journal_dirty_metadata"); "call ext4_journal_dirty_metadata");
err = ext3_journal_dirty_metadata(handle, err = ext4_journal_dirty_metadata(handle,
bitmap_bh); bitmap_bh);
if (err) if (err)
goto fail; goto fail;
...@@ -499,7 +499,7 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) ...@@ -499,7 +499,7 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
/* we lost it */ /* we lost it */
journal_release_buffer(handle, bitmap_bh); journal_release_buffer(handle, bitmap_bh);
if (++ino < EXT3_INODES_PER_GROUP(sb)) if (++ino < EXT4_INODES_PER_GROUP(sb))
goto repeat_in_this_group; goto repeat_in_this_group;
} }
...@@ -517,9 +517,9 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) ...@@ -517,9 +517,9 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
goto out; goto out;
got: got:
ino += group * EXT3_INODES_PER_GROUP(sb) + 1; ino += group * EXT4_INODES_PER_GROUP(sb) + 1;
if (ino < EXT3_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) { if (ino < EXT4_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) {
ext3_error (sb, "ext3_new_inode", ext4_error (sb, "ext4_new_inode",
"reserved inode or inode > inodes count - " "reserved inode or inode > inodes count - "
"block_group = %d, inode=%lu", group, ino); "block_group = %d, inode=%lu", group, ino);
err = -EIO; err = -EIO;
...@@ -527,7 +527,7 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) ...@@ -527,7 +527,7 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
} }
BUFFER_TRACE(bh2, "get_write_access"); BUFFER_TRACE(bh2, "get_write_access");
err = ext3_journal_get_write_access(handle, bh2); err = ext4_journal_get_write_access(handle, bh2);
if (err) goto fail; if (err) goto fail;
spin_lock(sb_bgl_lock(sbi, group)); spin_lock(sb_bgl_lock(sbi, group));
gdp->bg_free_inodes_count = gdp->bg_free_inodes_count =
...@@ -537,8 +537,8 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) ...@@ -537,8 +537,8 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
cpu_to_le16(le16_to_cpu(gdp->bg_used_dirs_count) + 1); cpu_to_le16(le16_to_cpu(gdp->bg_used_dirs_count) + 1);
} }
spin_unlock(sb_bgl_lock(sbi, group)); spin_unlock(sb_bgl_lock(sbi, group));
BUFFER_TRACE(bh2, "call ext3_journal_dirty_metadata"); BUFFER_TRACE(bh2, "call ext4_journal_dirty_metadata");
err = ext3_journal_dirty_metadata(handle, bh2); err = ext4_journal_dirty_metadata(handle, bh2);
if (err) goto fail; if (err) goto fail;
percpu_counter_dec(&sbi->s_freeinodes_counter); percpu_counter_dec(&sbi->s_freeinodes_counter);
...@@ -566,13 +566,13 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) ...@@ -566,13 +566,13 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
ei->i_dir_start_lookup = 0; ei->i_dir_start_lookup = 0;
ei->i_disksize = 0; ei->i_disksize = 0;
ei->i_flags = EXT3_I(dir)->i_flags & ~EXT3_INDEX_FL; ei->i_flags = EXT4_I(dir)->i_flags & ~EXT4_INDEX_FL;
if (S_ISLNK(mode)) if (S_ISLNK(mode))
ei->i_flags &= ~(EXT3_IMMUTABLE_FL|EXT3_APPEND_FL); ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
/* dirsync only applies to directories */ /* dirsync only applies to directories */
if (!S_ISDIR(mode)) if (!S_ISDIR(mode))
ei->i_flags &= ~EXT3_DIRSYNC_FL; ei->i_flags &= ~EXT4_DIRSYNC_FL;
#ifdef EXT3_FRAGMENTS #ifdef EXT4_FRAGMENTS
ei->i_faddr = 0; ei->i_faddr = 0;
ei->i_frag_no = 0; ei->i_frag_no = 0;
ei->i_frag_size = 0; ei->i_frag_size = 0;
...@@ -583,7 +583,7 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) ...@@ -583,7 +583,7 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
ei->i_block_alloc_info = NULL; ei->i_block_alloc_info = NULL;
ei->i_block_group = group; ei->i_block_group = group;
ext3_set_inode_flags(inode); ext4_set_inode_flags(inode);
if (IS_DIRSYNC(inode)) if (IS_DIRSYNC(inode))
handle->h_sync = 1; handle->h_sync = 1;
insert_inode_hash(inode); insert_inode_hash(inode);
...@@ -591,10 +591,10 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) ...@@ -591,10 +591,10 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
inode->i_generation = sbi->s_next_generation++; inode->i_generation = sbi->s_next_generation++;
spin_unlock(&sbi->s_next_gen_lock); spin_unlock(&sbi->s_next_gen_lock);
ei->i_state = EXT3_STATE_NEW; ei->i_state = EXT4_STATE_NEW;
ei->i_extra_isize = ei->i_extra_isize =
(EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE) ? (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) ?
sizeof(struct ext3_inode) - EXT3_GOOD_OLD_INODE_SIZE : 0; sizeof(struct ext4_inode) - EXT4_GOOD_OLD_INODE_SIZE : 0;
ret = inode; ret = inode;
if(DQUOT_ALLOC_INODE(inode)) { if(DQUOT_ALLOC_INODE(inode)) {
...@@ -602,24 +602,24 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) ...@@ -602,24 +602,24 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
goto fail_drop; goto fail_drop;
} }
err = ext3_init_acl(handle, inode, dir); err = ext4_init_acl(handle, inode, dir);
if (err) if (err)
goto fail_free_drop; goto fail_free_drop;
err = ext3_init_security(handle,inode, dir); err = ext4_init_security(handle,inode, dir);
if (err) if (err)
goto fail_free_drop; goto fail_free_drop;
err = ext3_mark_inode_dirty(handle, inode); err = ext4_mark_inode_dirty(handle, inode);
if (err) { if (err) {
ext3_std_error(sb, err); ext4_std_error(sb, err);
goto fail_free_drop; goto fail_free_drop;
} }
ext3_debug("allocating inode %lu\n", inode->i_ino); ext4_debug("allocating inode %lu\n", inode->i_ino);
goto really_out; goto really_out;
fail: fail:
ext3_std_error(sb, err); ext4_std_error(sb, err);
out: out:
iput(inode); iput(inode);
ret = ERR_PTR(err); ret = ERR_PTR(err);
...@@ -640,9 +640,9 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode) ...@@ -640,9 +640,9 @@ struct inode *ext3_new_inode(handle_t *handle, struct inode * dir, int mode)
} }
/* Verify that we are loading a valid orphan from disk */ /* Verify that we are loading a valid orphan from disk */
struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino) struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
{ {
unsigned long max_ino = le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count); unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count);
unsigned long block_group; unsigned long block_group;
int bit; int bit;
struct buffer_head *bitmap_bh = NULL; struct buffer_head *bitmap_bh = NULL;
...@@ -650,16 +650,16 @@ struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino) ...@@ -650,16 +650,16 @@ struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino)
/* Error cases - e2fsck has already cleaned up for us */ /* Error cases - e2fsck has already cleaned up for us */
if (ino > max_ino) { if (ino > max_ino) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"bad orphan ino %lu! e2fsck was run?", ino); "bad orphan ino %lu! e2fsck was run?", ino);
goto out; goto out;
} }
block_group = (ino - 1) / EXT3_INODES_PER_GROUP(sb); block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
bit = (ino - 1) % EXT3_INODES_PER_GROUP(sb); bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
bitmap_bh = read_inode_bitmap(sb, block_group); bitmap_bh = read_inode_bitmap(sb, block_group);
if (!bitmap_bh) { if (!bitmap_bh) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"inode bitmap error for orphan %lu", ino); "inode bitmap error for orphan %lu", ino);
goto out; goto out;
} }
...@@ -668,14 +668,14 @@ struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino) ...@@ -668,14 +668,14 @@ struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino)
* is a valid orphan (no e2fsck run on fs). Orphans also include * is a valid orphan (no e2fsck run on fs). Orphans also include
* inodes that were being truncated, so we can't check i_nlink==0. * inodes that were being truncated, so we can't check i_nlink==0.
*/ */
if (!ext3_test_bit(bit, bitmap_bh->b_data) || if (!ext4_test_bit(bit, bitmap_bh->b_data) ||
!(inode = iget(sb, ino)) || is_bad_inode(inode) || !(inode = iget(sb, ino)) || is_bad_inode(inode) ||
NEXT_ORPHAN(inode) > max_ino) { NEXT_ORPHAN(inode) > max_ino) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"bad orphan inode %lu! e2fsck was run?", ino); "bad orphan inode %lu! e2fsck was run?", ino);
printk(KERN_NOTICE "ext3_test_bit(bit=%d, block=%llu) = %d\n", printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n",
bit, (unsigned long long)bitmap_bh->b_blocknr, bit, (unsigned long long)bitmap_bh->b_blocknr,
ext3_test_bit(bit, bitmap_bh->b_data)); ext4_test_bit(bit, bitmap_bh->b_data));
printk(KERN_NOTICE "inode=%p\n", inode); printk(KERN_NOTICE "inode=%p\n", inode);
if (inode) { if (inode) {
printk(KERN_NOTICE "is_bad_inode(inode)=%d\n", printk(KERN_NOTICE "is_bad_inode(inode)=%d\n",
...@@ -695,22 +695,22 @@ struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino) ...@@ -695,22 +695,22 @@ struct inode *ext3_orphan_get(struct super_block *sb, unsigned long ino)
return inode; return inode;
} }
unsigned long ext3_count_free_inodes (struct super_block * sb) unsigned long ext4_count_free_inodes (struct super_block * sb)
{ {
unsigned long desc_count; unsigned long desc_count;
struct ext3_group_desc *gdp; struct ext4_group_desc *gdp;
int i; int i;
#ifdef EXT3FS_DEBUG #ifdef EXT4FS_DEBUG
struct ext3_super_block *es; struct ext4_super_block *es;
unsigned long bitmap_count, x; unsigned long bitmap_count, x;
struct buffer_head *bitmap_bh = NULL; struct buffer_head *bitmap_bh = NULL;
es = EXT3_SB(sb)->s_es; es = EXT4_SB(sb)->s_es;
desc_count = 0; desc_count = 0;
bitmap_count = 0; bitmap_count = 0;
gdp = NULL; gdp = NULL;
for (i = 0; i < EXT3_SB(sb)->s_groups_count; i++) { for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) {
gdp = ext3_get_group_desc (sb, i, NULL); gdp = ext4_get_group_desc (sb, i, NULL);
if (!gdp) if (!gdp)
continue; continue;
desc_count += le16_to_cpu(gdp->bg_free_inodes_count); 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,19 +719,19 @@ unsigned long ext3_count_free_inodes (struct super_block * sb)
if (!bitmap_bh) if (!bitmap_bh)
continue; continue;
x = ext3_count_free(bitmap_bh, EXT3_INODES_PER_GROUP(sb) / 8); x = ext4_count_free(bitmap_bh, EXT4_INODES_PER_GROUP(sb) / 8);
printk("group %d: stored = %d, counted = %lu\n", printk("group %d: stored = %d, counted = %lu\n",
i, le16_to_cpu(gdp->bg_free_inodes_count), x); i, le16_to_cpu(gdp->bg_free_inodes_count), x);
bitmap_count += x; bitmap_count += x;
} }
brelse(bitmap_bh); brelse(bitmap_bh);
printk("ext3_count_free_inodes: stored = %u, computed = %lu, %lu\n", printk("ext4_count_free_inodes: stored = %u, computed = %lu, %lu\n",
le32_to_cpu(es->s_free_inodes_count), desc_count, bitmap_count); le32_to_cpu(es->s_free_inodes_count), desc_count, bitmap_count);
return desc_count; return desc_count;
#else #else
desc_count = 0; desc_count = 0;
for (i = 0; i < EXT3_SB(sb)->s_groups_count; i++) { for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) {
gdp = ext3_get_group_desc (sb, i, NULL); gdp = ext4_get_group_desc (sb, i, NULL);
if (!gdp) if (!gdp)
continue; continue;
desc_count += le16_to_cpu(gdp->bg_free_inodes_count); 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,13 +742,13 @@ unsigned long ext3_count_free_inodes (struct super_block * sb)
} }
/* Called at mount-time, super-block is locked */ /* Called at mount-time, super-block is locked */
unsigned long ext3_count_dirs (struct super_block * sb) unsigned long ext4_count_dirs (struct super_block * sb)
{ {
unsigned long count = 0; unsigned long count = 0;
int i; int i;
for (i = 0; i < EXT3_SB(sb)->s_groups_count; i++) { for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) {
struct ext3_group_desc *gdp = ext3_get_group_desc (sb, i, NULL); struct ext4_group_desc *gdp = ext4_get_group_desc (sb, i, NULL);
if (!gdp) if (!gdp)
continue; continue;
count += le16_to_cpu(gdp->bg_used_dirs_count); count += le16_to_cpu(gdp->bg_used_dirs_count);
......
/* /*
* linux/fs/ext3/inode.c * linux/fs/ext4/inode.c
* *
* Copyright (C) 1992, 1993, 1994, 1995 * Copyright (C) 1992, 1993, 1994, 1995
* Remy Card (card@masi.ibp.fr) * Remy Card (card@masi.ibp.fr)
...@@ -19,13 +19,13 @@ ...@@ -19,13 +19,13 @@
* 64-bit file support on 64-bit platforms by Jakub Jelinek * 64-bit file support on 64-bit platforms by Jakub Jelinek
* (jj@sunsite.ms.mff.cuni.cz) * (jj@sunsite.ms.mff.cuni.cz)
* *
* Assorted race fixes, rewrite of ext3_get_block() by Al Viro, 2000 * Assorted race fixes, rewrite of ext4_get_block() by Al Viro, 2000
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/time.h> #include <linux/time.h>
#include <linux/ext3_jbd.h> #include <linux/ext4_jbd.h>
#include <linux/jbd.h> #include <linux/jbd.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/highuid.h> #include <linux/highuid.h>
...@@ -40,21 +40,21 @@ ...@@ -40,21 +40,21 @@
#include "xattr.h" #include "xattr.h"
#include "acl.h" #include "acl.h"
static int ext3_writepage_trans_blocks(struct inode *inode); static int ext4_writepage_trans_blocks(struct inode *inode);
/* /*
* Test whether an inode is a fast symlink. * Test whether an inode is a fast symlink.
*/ */
static int ext3_inode_is_fast_symlink(struct inode *inode) static int ext4_inode_is_fast_symlink(struct inode *inode)
{ {
int ea_blocks = EXT3_I(inode)->i_file_acl ? int ea_blocks = EXT4_I(inode)->i_file_acl ?
(inode->i_sb->s_blocksize >> 9) : 0; (inode->i_sb->s_blocksize >> 9) : 0;
return (S_ISLNK(inode->i_mode) && inode->i_blocks - ea_blocks == 0); return (S_ISLNK(inode->i_mode) && inode->i_blocks - ea_blocks == 0);
} }
/* /*
* The ext3 forget function must perform a revoke if we are freeing data * The ext4 forget function must perform a revoke if we are freeing data
* which has been journaled. Metadata (eg. indirect blocks) must be * which has been journaled. Metadata (eg. indirect blocks) must be
* revoked in all cases. * revoked in all cases.
* *
...@@ -62,8 +62,8 @@ static int ext3_inode_is_fast_symlink(struct inode *inode) ...@@ -62,8 +62,8 @@ static int ext3_inode_is_fast_symlink(struct inode *inode)
* but there may still be a record of it in the journal, and that record * but there may still be a record of it in the journal, and that record
* still needs to be revoked. * still needs to be revoked.
*/ */
int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode, int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode,
struct buffer_head *bh, ext3_fsblk_t blocknr) struct buffer_head *bh, ext4_fsblk_t blocknr)
{ {
int err; int err;
...@@ -81,11 +81,11 @@ int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode, ...@@ -81,11 +81,11 @@ int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode,
* support it. Otherwise, only skip the revoke on un-journaled * support it. Otherwise, only skip the revoke on un-journaled
* data blocks. */ * data blocks. */
if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA || if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA ||
(!is_metadata && !ext3_should_journal_data(inode))) { (!is_metadata && !ext4_should_journal_data(inode))) {
if (bh) { if (bh) {
BUFFER_TRACE(bh, "call journal_forget"); BUFFER_TRACE(bh, "call journal_forget");
return ext3_journal_forget(handle, bh); return ext4_journal_forget(handle, bh);
} }
return 0; return 0;
} }
...@@ -93,10 +93,10 @@ int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode, ...@@ -93,10 +93,10 @@ int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode,
/* /*
* data!=journal && (is_metadata || should_journal_data(inode)) * data!=journal && (is_metadata || should_journal_data(inode))
*/ */
BUFFER_TRACE(bh, "call ext3_journal_revoke"); BUFFER_TRACE(bh, "call ext4_journal_revoke");
err = ext3_journal_revoke(handle, blocknr, bh); err = ext4_journal_revoke(handle, blocknr, bh);
if (err) if (err)
ext3_abort(inode->i_sb, __FUNCTION__, ext4_abort(inode->i_sb, __FUNCTION__,
"error %d when attempting revoke", err); "error %d when attempting revoke", err);
BUFFER_TRACE(bh, "exit"); BUFFER_TRACE(bh, "exit");
return err; return err;
...@@ -115,7 +115,7 @@ static unsigned long blocks_for_truncate(struct inode *inode) ...@@ -115,7 +115,7 @@ static unsigned long blocks_for_truncate(struct inode *inode)
/* Give ourselves just enough room to cope with inodes in which /* Give ourselves just enough room to cope with inodes in which
* i_blocks is corrupt: we've seen disk corruptions in the past * i_blocks is corrupt: we've seen disk corruptions in the past
* which resulted in random data in an inode which looked enough * which resulted in random data in an inode which looked enough
* like a regular file for ext3 to try to delete it. Things * like a regular file for ext4 to try to delete it. Things
* will go a bit crazy if that happens, but at least we should * will go a bit crazy if that happens, but at least we should
* try not to panic the whole kernel. */ * try not to panic the whole kernel. */
if (needed < 2) if (needed < 2)
...@@ -123,10 +123,10 @@ static unsigned long blocks_for_truncate(struct inode *inode) ...@@ -123,10 +123,10 @@ static unsigned long blocks_for_truncate(struct inode *inode)
/* But we need to bound the transaction so we don't overflow the /* But we need to bound the transaction so we don't overflow the
* journal. */ * journal. */
if (needed > EXT3_MAX_TRANS_DATA) if (needed > EXT4_MAX_TRANS_DATA)
needed = EXT3_MAX_TRANS_DATA; needed = EXT4_MAX_TRANS_DATA;
return EXT3_DATA_TRANS_BLOCKS(inode->i_sb) + needed; return EXT4_DATA_TRANS_BLOCKS(inode->i_sb) + needed;
} }
/* /*
...@@ -143,11 +143,11 @@ static handle_t *start_transaction(struct inode *inode) ...@@ -143,11 +143,11 @@ static handle_t *start_transaction(struct inode *inode)
{ {
handle_t *result; handle_t *result;
result = ext3_journal_start(inode, blocks_for_truncate(inode)); result = ext4_journal_start(inode, blocks_for_truncate(inode));
if (!IS_ERR(result)) if (!IS_ERR(result))
return result; return result;
ext3_std_error(inode->i_sb, PTR_ERR(result)); ext4_std_error(inode->i_sb, PTR_ERR(result));
return result; return result;
} }
...@@ -159,9 +159,9 @@ static handle_t *start_transaction(struct inode *inode) ...@@ -159,9 +159,9 @@ static handle_t *start_transaction(struct inode *inode)
*/ */
static int try_to_extend_transaction(handle_t *handle, struct inode *inode) static int try_to_extend_transaction(handle_t *handle, struct inode *inode)
{ {
if (handle->h_buffer_credits > EXT3_RESERVE_TRANS_BLOCKS) if (handle->h_buffer_credits > EXT4_RESERVE_TRANS_BLOCKS)
return 0; return 0;
if (!ext3_journal_extend(handle, blocks_for_truncate(inode))) if (!ext4_journal_extend(handle, blocks_for_truncate(inode)))
return 0; return 0;
return 1; return 1;
} }
...@@ -171,16 +171,16 @@ static int try_to_extend_transaction(handle_t *handle, struct inode *inode) ...@@ -171,16 +171,16 @@ static int try_to_extend_transaction(handle_t *handle, struct inode *inode)
* so before we call here everything must be consistently dirtied against * so before we call here everything must be consistently dirtied against
* this transaction. * this transaction.
*/ */
static int ext3_journal_test_restart(handle_t *handle, struct inode *inode) static int ext4_journal_test_restart(handle_t *handle, struct inode *inode)
{ {
jbd_debug(2, "restarting handle %p\n", handle); jbd_debug(2, "restarting handle %p\n", handle);
return ext3_journal_restart(handle, blocks_for_truncate(inode)); return ext4_journal_restart(handle, blocks_for_truncate(inode));
} }
/* /*
* Called at the last iput() if i_nlink is zero. * Called at the last iput() if i_nlink is zero.
*/ */
void ext3_delete_inode (struct inode * inode) void ext4_delete_inode (struct inode * inode)
{ {
handle_t *handle; handle_t *handle;
...@@ -196,7 +196,7 @@ void ext3_delete_inode (struct inode * inode) ...@@ -196,7 +196,7 @@ void ext3_delete_inode (struct inode * inode)
* make sure that the in-core orphan linked list is properly * make sure that the in-core orphan linked list is properly
* cleaned up. * cleaned up.
*/ */
ext3_orphan_del(NULL, inode); ext4_orphan_del(NULL, inode);
goto no_delete; goto no_delete;
} }
...@@ -204,17 +204,17 @@ void ext3_delete_inode (struct inode * inode) ...@@ -204,17 +204,17 @@ void ext3_delete_inode (struct inode * inode)
handle->h_sync = 1; handle->h_sync = 1;
inode->i_size = 0; inode->i_size = 0;
if (inode->i_blocks) if (inode->i_blocks)
ext3_truncate(inode); ext4_truncate(inode);
/* /*
* Kill off the orphan record which ext3_truncate created. * Kill off the orphan record which ext4_truncate created.
* AKPM: I think this can be inside the above `if'. * AKPM: I think this can be inside the above `if'.
* Note that ext3_orphan_del() has to be able to cope with the * Note that ext4_orphan_del() has to be able to cope with the
* deletion of a non-existent orphan - this is because we don't * deletion of a non-existent orphan - this is because we don't
* know if ext3_truncate() actually created an orphan record. * know if ext4_truncate() actually created an orphan record.
* (Well, we could do this if we need to, but heck - it works) * (Well, we could do this if we need to, but heck - it works)
*/ */
ext3_orphan_del(handle, inode); ext4_orphan_del(handle, inode);
EXT3_I(inode)->i_dtime = get_seconds(); EXT4_I(inode)->i_dtime = get_seconds();
/* /*
* One subtle ordering requirement: if anything has gone wrong * One subtle ordering requirement: if anything has gone wrong
...@@ -223,12 +223,12 @@ void ext3_delete_inode (struct inode * inode) ...@@ -223,12 +223,12 @@ void ext3_delete_inode (struct inode * inode)
* having errors), but we can't free the inode if the mark_dirty * having errors), but we can't free the inode if the mark_dirty
* fails. * fails.
*/ */
if (ext3_mark_inode_dirty(handle, inode)) if (ext4_mark_inode_dirty(handle, inode))
/* If that failed, just do the required in-core inode clear. */ /* If that failed, just do the required in-core inode clear. */
clear_inode(inode); clear_inode(inode);
else else
ext3_free_inode(handle, inode); ext4_free_inode(handle, inode);
ext3_journal_stop(handle); ext4_journal_stop(handle);
return; return;
no_delete: no_delete:
clear_inode(inode); /* We must guarantee clearing of inode... */ clear_inode(inode); /* We must guarantee clearing of inode... */
...@@ -254,14 +254,14 @@ static int verify_chain(Indirect *from, Indirect *to) ...@@ -254,14 +254,14 @@ static int verify_chain(Indirect *from, Indirect *to)
} }
/** /**
* ext3_block_to_path - parse the block number into array of offsets * ext4_block_to_path - parse the block number into array of offsets
* @inode: inode in question (we are only interested in its superblock) * @inode: inode in question (we are only interested in its superblock)
* @i_block: block number to be parsed * @i_block: block number to be parsed
* @offsets: array to store the offsets in * @offsets: array to store the offsets in
* @boundary: set this non-zero if the referred-to block is likely to be * @boundary: set this non-zero if the referred-to block is likely to be
* followed (on disk) by an indirect block. * followed (on disk) by an indirect block.
* *
* To store the locations of file's data ext3 uses a data structure common * To store the locations of file's data ext4 uses a data structure common
* for UNIX filesystems - tree of pointers anchored in the inode, with * for UNIX filesystems - tree of pointers anchored in the inode, with
* data blocks at leaves and indirect blocks in intermediate nodes. * data blocks at leaves and indirect blocks in intermediate nodes.
* This function translates the block number into path in that tree - * This function translates the block number into path in that tree -
...@@ -284,39 +284,39 @@ static int verify_chain(Indirect *from, Indirect *to) ...@@ -284,39 +284,39 @@ static int verify_chain(Indirect *from, Indirect *to)
* get there at all. * get there at all.
*/ */
static int ext3_block_to_path(struct inode *inode, static int ext4_block_to_path(struct inode *inode,
long i_block, int offsets[4], int *boundary) long i_block, int offsets[4], int *boundary)
{ {
int ptrs = EXT3_ADDR_PER_BLOCK(inode->i_sb); int ptrs = EXT4_ADDR_PER_BLOCK(inode->i_sb);
int ptrs_bits = EXT3_ADDR_PER_BLOCK_BITS(inode->i_sb); int ptrs_bits = EXT4_ADDR_PER_BLOCK_BITS(inode->i_sb);
const long direct_blocks = EXT3_NDIR_BLOCKS, const long direct_blocks = EXT4_NDIR_BLOCKS,
indirect_blocks = ptrs, indirect_blocks = ptrs,
double_blocks = (1 << (ptrs_bits * 2)); double_blocks = (1 << (ptrs_bits * 2));
int n = 0; int n = 0;
int final = 0; int final = 0;
if (i_block < 0) { if (i_block < 0) {
ext3_warning (inode->i_sb, "ext3_block_to_path", "block < 0"); ext4_warning (inode->i_sb, "ext4_block_to_path", "block < 0");
} else if (i_block < direct_blocks) { } else if (i_block < direct_blocks) {
offsets[n++] = i_block; offsets[n++] = i_block;
final = direct_blocks; final = direct_blocks;
} else if ( (i_block -= direct_blocks) < indirect_blocks) { } else if ( (i_block -= direct_blocks) < indirect_blocks) {
offsets[n++] = EXT3_IND_BLOCK; offsets[n++] = EXT4_IND_BLOCK;
offsets[n++] = i_block; offsets[n++] = i_block;
final = ptrs; final = ptrs;
} else if ((i_block -= indirect_blocks) < double_blocks) { } else if ((i_block -= indirect_blocks) < double_blocks) {
offsets[n++] = EXT3_DIND_BLOCK; offsets[n++] = EXT4_DIND_BLOCK;
offsets[n++] = i_block >> ptrs_bits; offsets[n++] = i_block >> ptrs_bits;
offsets[n++] = i_block & (ptrs - 1); offsets[n++] = i_block & (ptrs - 1);
final = ptrs; final = ptrs;
} else if (((i_block -= double_blocks) >> (ptrs_bits * 2)) < ptrs) { } else if (((i_block -= double_blocks) >> (ptrs_bits * 2)) < ptrs) {
offsets[n++] = EXT3_TIND_BLOCK; offsets[n++] = EXT4_TIND_BLOCK;
offsets[n++] = i_block >> (ptrs_bits * 2); offsets[n++] = i_block >> (ptrs_bits * 2);
offsets[n++] = (i_block >> ptrs_bits) & (ptrs - 1); offsets[n++] = (i_block >> ptrs_bits) & (ptrs - 1);
offsets[n++] = i_block & (ptrs - 1); offsets[n++] = i_block & (ptrs - 1);
final = ptrs; final = ptrs;
} else { } else {
ext3_warning(inode->i_sb, "ext3_block_to_path", "block > big"); ext4_warning(inode->i_sb, "ext4_block_to_path", "block > big");
} }
if (boundary) if (boundary)
*boundary = final - 1 - (i_block & (ptrs - 1)); *boundary = final - 1 - (i_block & (ptrs - 1));
...@@ -324,7 +324,7 @@ static int ext3_block_to_path(struct inode *inode, ...@@ -324,7 +324,7 @@ static int ext3_block_to_path(struct inode *inode,
} }
/** /**
* ext3_get_branch - read the chain of indirect blocks leading to data * ext4_get_branch - read the chain of indirect blocks leading to data
* @inode: inode in question * @inode: inode in question
* @depth: depth of the chain (1 - direct pointer, etc.) * @depth: depth of the chain (1 - direct pointer, etc.)
* @offsets: offsets of pointers in inode/indirect blocks * @offsets: offsets of pointers in inode/indirect blocks
...@@ -352,7 +352,7 @@ static int ext3_block_to_path(struct inode *inode, ...@@ -352,7 +352,7 @@ static int ext3_block_to_path(struct inode *inode,
* or when it reads all @depth-1 indirect blocks successfully and finds * or when it reads all @depth-1 indirect blocks successfully and finds
* the whole chain, all way to the data (returns %NULL, *err == 0). * the whole chain, all way to the data (returns %NULL, *err == 0).
*/ */
static Indirect *ext3_get_branch(struct inode *inode, int depth, int *offsets, static Indirect *ext4_get_branch(struct inode *inode, int depth, int *offsets,
Indirect chain[4], int *err) Indirect chain[4], int *err)
{ {
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
...@@ -361,7 +361,7 @@ static Indirect *ext3_get_branch(struct inode *inode, int depth, int *offsets, ...@@ -361,7 +361,7 @@ static Indirect *ext3_get_branch(struct inode *inode, int depth, int *offsets,
*err = 0; *err = 0;
/* i_data is not going away, no lock needed */ /* i_data is not going away, no lock needed */
add_chain (chain, NULL, EXT3_I(inode)->i_data + *offsets); add_chain (chain, NULL, EXT4_I(inode)->i_data + *offsets);
if (!p->key) if (!p->key)
goto no_block; goto no_block;
while (--depth) { while (--depth) {
...@@ -389,7 +389,7 @@ static Indirect *ext3_get_branch(struct inode *inode, int depth, int *offsets, ...@@ -389,7 +389,7 @@ static Indirect *ext3_get_branch(struct inode *inode, int depth, int *offsets,
} }
/** /**
* ext3_find_near - find a place for allocation with sufficient locality * ext4_find_near - find a place for allocation with sufficient locality
* @inode: owner * @inode: owner
* @ind: descriptor of indirect block. * @ind: descriptor of indirect block.
* *
...@@ -408,13 +408,13 @@ static Indirect *ext3_get_branch(struct inode *inode, int depth, int *offsets, ...@@ -408,13 +408,13 @@ static Indirect *ext3_get_branch(struct inode *inode, int depth, int *offsets,
* *
* Caller must make sure that @ind is valid and will stay that way. * Caller must make sure that @ind is valid and will stay that way.
*/ */
static ext3_fsblk_t ext3_find_near(struct inode *inode, Indirect *ind) static ext4_fsblk_t ext4_find_near(struct inode *inode, Indirect *ind)
{ {
struct ext3_inode_info *ei = EXT3_I(inode); struct ext4_inode_info *ei = EXT4_I(inode);
__le32 *start = ind->bh ? (__le32*) ind->bh->b_data : ei->i_data; __le32 *start = ind->bh ? (__le32*) ind->bh->b_data : ei->i_data;
__le32 *p; __le32 *p;
ext3_fsblk_t bg_start; ext4_fsblk_t bg_start;
ext3_grpblk_t colour; ext4_grpblk_t colour;
/* Try to find previous block */ /* Try to find previous block */
for (p = ind->p - 1; p >= start; p--) { 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,14 +430,14 @@ static ext3_fsblk_t ext3_find_near(struct inode *inode, Indirect *ind)
* It is going to be referred to from the inode itself? OK, just put it * It is going to be referred to from the inode itself? OK, just put it
* into the same cylinder group then. * into the same cylinder group then.
*/ */
bg_start = ext3_group_first_block_no(inode->i_sb, ei->i_block_group); bg_start = ext4_group_first_block_no(inode->i_sb, ei->i_block_group);
colour = (current->pid % 16) * colour = (current->pid % 16) *
(EXT3_BLOCKS_PER_GROUP(inode->i_sb) / 16); (EXT4_BLOCKS_PER_GROUP(inode->i_sb) / 16);
return bg_start + colour; return bg_start + colour;
} }
/** /**
* ext3_find_goal - find a prefered place for allocation. * ext4_find_goal - find a prefered place for allocation.
* @inode: owner * @inode: owner
* @block: block we want * @block: block we want
* @chain: chain of indirect blocks * @chain: chain of indirect blocks
...@@ -448,12 +448,12 @@ static ext3_fsblk_t ext3_find_near(struct inode *inode, Indirect *ind) ...@@ -448,12 +448,12 @@ static ext3_fsblk_t ext3_find_near(struct inode *inode, Indirect *ind)
* stores it in *@goal and returns zero. * stores it in *@goal and returns zero.
*/ */
static ext3_fsblk_t ext3_find_goal(struct inode *inode, long block, static ext4_fsblk_t ext4_find_goal(struct inode *inode, long block,
Indirect chain[4], Indirect *partial) Indirect chain[4], Indirect *partial)
{ {
struct ext3_block_alloc_info *block_i; struct ext4_block_alloc_info *block_i;
block_i = EXT3_I(inode)->i_block_alloc_info; block_i = EXT4_I(inode)->i_block_alloc_info;
/* /*
* try the heuristic for sequential allocation, * try the heuristic for sequential allocation,
...@@ -464,11 +464,11 @@ static ext3_fsblk_t ext3_find_goal(struct inode *inode, long block, ...@@ -464,11 +464,11 @@ static ext3_fsblk_t ext3_find_goal(struct inode *inode, long block,
return block_i->last_alloc_physical_block + 1; return block_i->last_alloc_physical_block + 1;
} }
return ext3_find_near(inode, partial); return ext4_find_near(inode, partial);
} }
/** /**
* ext3_blks_to_allocate: Look up the block map and count the number * ext4_blks_to_allocate: Look up the block map and count the number
* of direct blocks need to be allocated for the given branch. * of direct blocks need to be allocated for the given branch.
* *
* @branch: chain of indirect blocks * @branch: chain of indirect blocks
...@@ -479,7 +479,7 @@ static ext3_fsblk_t ext3_find_goal(struct inode *inode, long block, ...@@ -479,7 +479,7 @@ static ext3_fsblk_t ext3_find_goal(struct inode *inode, long block,
* return the total number of blocks to be allocate, including the * return the total number of blocks to be allocate, including the
* direct and indirect blocks. * direct and indirect blocks.
*/ */
static int ext3_blks_to_allocate(Indirect *branch, int k, unsigned long blks, static int ext4_blks_to_allocate(Indirect *branch, int k, unsigned long blks,
int blocks_to_boundary) int blocks_to_boundary)
{ {
unsigned long count = 0; unsigned long count = 0;
...@@ -506,7 +506,7 @@ static int ext3_blks_to_allocate(Indirect *branch, int k, unsigned long blks, ...@@ -506,7 +506,7 @@ static int ext3_blks_to_allocate(Indirect *branch, int k, unsigned long blks,
} }
/** /**
* ext3_alloc_blocks: multiple allocate blocks needed for a branch * ext4_alloc_blocks: multiple allocate blocks needed for a branch
* @indirect_blks: the number of blocks need to allocate for indirect * @indirect_blks: the number of blocks need to allocate for indirect
* blocks * blocks
* *
...@@ -515,14 +515,14 @@ static int ext3_blks_to_allocate(Indirect *branch, int k, unsigned long blks, ...@@ -515,14 +515,14 @@ static int ext3_blks_to_allocate(Indirect *branch, int k, unsigned long blks,
* @blks: on return it will store the total number of allocated * @blks: on return it will store the total number of allocated
* direct blocks * direct blocks
*/ */
static int ext3_alloc_blocks(handle_t *handle, struct inode *inode, static int ext4_alloc_blocks(handle_t *handle, struct inode *inode,
ext3_fsblk_t goal, int indirect_blks, int blks, ext4_fsblk_t goal, int indirect_blks, int blks,
ext3_fsblk_t new_blocks[4], int *err) ext4_fsblk_t new_blocks[4], int *err)
{ {
int target, i; int target, i;
unsigned long count = 0; unsigned long count = 0;
int index = 0; int index = 0;
ext3_fsblk_t current_block = 0; ext4_fsblk_t current_block = 0;
int ret = 0; int ret = 0;
/* /*
...@@ -538,7 +538,7 @@ static int ext3_alloc_blocks(handle_t *handle, struct inode *inode, ...@@ -538,7 +538,7 @@ static int ext3_alloc_blocks(handle_t *handle, struct inode *inode,
while (1) { while (1) {
count = target; count = target;
/* allocating blocks for indirect blocks and direct blocks */ /* allocating blocks for indirect blocks and direct blocks */
current_block = ext3_new_blocks(handle,inode,goal,&count,err); current_block = ext4_new_blocks(handle,inode,goal,&count,err);
if (*err) if (*err)
goto failed_out; goto failed_out;
...@@ -562,12 +562,12 @@ static int ext3_alloc_blocks(handle_t *handle, struct inode *inode, ...@@ -562,12 +562,12 @@ static int ext3_alloc_blocks(handle_t *handle, struct inode *inode,
return ret; return ret;
failed_out: failed_out:
for (i = 0; i <index; i++) for (i = 0; i <index; i++)
ext3_free_blocks(handle, inode, new_blocks[i], 1); ext4_free_blocks(handle, inode, new_blocks[i], 1);
return ret; return ret;
} }
/** /**
* ext3_alloc_branch - allocate and set up a chain of blocks. * ext4_alloc_branch - allocate and set up a chain of blocks.
* @inode: owner * @inode: owner
* @indirect_blks: number of allocated indirect blocks * @indirect_blks: number of allocated indirect blocks
* @blks: number of allocated direct blocks * @blks: number of allocated direct blocks
...@@ -578,21 +578,21 @@ static int ext3_alloc_blocks(handle_t *handle, struct inode *inode, ...@@ -578,21 +578,21 @@ static int ext3_alloc_blocks(handle_t *handle, struct inode *inode,
* links them into chain and (if we are synchronous) writes them to disk. * links them into chain and (if we are synchronous) writes them to disk.
* In other words, it prepares a branch that can be spliced onto the * In other words, it prepares a branch that can be spliced onto the
* inode. It stores the information about that chain in the branch[], in * inode. It stores the information about that chain in the branch[], in
* the same format as ext3_get_branch() would do. We are calling it after * the same format as ext4_get_branch() would do. We are calling it after
* we had read the existing part of chain and partial points to the last * we had read the existing part of chain and partial points to the last
* triple of that (one with zero ->key). Upon the exit we have the same * triple of that (one with zero ->key). Upon the exit we have the same
* picture as after the successful ext3_get_block(), except that in one * picture as after the successful ext4_get_block(), except that in one
* place chain is disconnected - *branch->p is still zero (we did not * place chain is disconnected - *branch->p is still zero (we did not
* set the last link), but branch->key contains the number that should * set the last link), but branch->key contains the number that should
* be placed into *branch->p to fill that gap. * be placed into *branch->p to fill that gap.
* *
* If allocation fails we free all blocks we've allocated (and forget * If allocation fails we free all blocks we've allocated (and forget
* their buffer_heads) and return the error value the from failed * their buffer_heads) and return the error value the from failed
* ext3_alloc_block() (normally -ENOSPC). Otherwise we set the chain * ext4_alloc_block() (normally -ENOSPC). Otherwise we set the chain
* as described above and return 0. * as described above and return 0.
*/ */
static int ext3_alloc_branch(handle_t *handle, struct inode *inode, static int ext4_alloc_branch(handle_t *handle, struct inode *inode,
int indirect_blks, int *blks, ext3_fsblk_t goal, int indirect_blks, int *blks, ext4_fsblk_t goal,
int *offsets, Indirect *branch) int *offsets, Indirect *branch)
{ {
int blocksize = inode->i_sb->s_blocksize; int blocksize = inode->i_sb->s_blocksize;
...@@ -600,10 +600,10 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode, ...@@ -600,10 +600,10 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode,
int err = 0; int err = 0;
struct buffer_head *bh; struct buffer_head *bh;
int num; int num;
ext3_fsblk_t new_blocks[4]; ext4_fsblk_t new_blocks[4];
ext3_fsblk_t current_block; ext4_fsblk_t current_block;
num = ext3_alloc_blocks(handle, inode, goal, indirect_blks, num = ext4_alloc_blocks(handle, inode, goal, indirect_blks,
*blks, new_blocks, &err); *blks, new_blocks, &err);
if (err) if (err)
return err; return err;
...@@ -622,7 +622,7 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode, ...@@ -622,7 +622,7 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode,
branch[n].bh = bh; branch[n].bh = bh;
lock_buffer(bh); lock_buffer(bh);
BUFFER_TRACE(bh, "call get_create_access"); BUFFER_TRACE(bh, "call get_create_access");
err = ext3_journal_get_create_access(handle, bh); err = ext4_journal_get_create_access(handle, bh);
if (err) { if (err) {
unlock_buffer(bh); unlock_buffer(bh);
brelse(bh); brelse(bh);
...@@ -647,8 +647,8 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode, ...@@ -647,8 +647,8 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode,
set_buffer_uptodate(bh); set_buffer_uptodate(bh);
unlock_buffer(bh); unlock_buffer(bh);
BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata"); BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
err = ext3_journal_dirty_metadata(handle, bh); err = ext4_journal_dirty_metadata(handle, bh);
if (err) if (err)
goto failed; goto failed;
} }
...@@ -658,22 +658,22 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode, ...@@ -658,22 +658,22 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode,
/* Allocation failed, free what we already allocated */ /* Allocation failed, free what we already allocated */
for (i = 1; i <= n ; i++) { for (i = 1; i <= n ; i++) {
BUFFER_TRACE(branch[i].bh, "call journal_forget"); BUFFER_TRACE(branch[i].bh, "call journal_forget");
ext3_journal_forget(handle, branch[i].bh); ext4_journal_forget(handle, branch[i].bh);
} }
for (i = 0; i <indirect_blks; i++) for (i = 0; i <indirect_blks; i++)
ext3_free_blocks(handle, inode, new_blocks[i], 1); ext4_free_blocks(handle, inode, new_blocks[i], 1);
ext3_free_blocks(handle, inode, new_blocks[i], num); ext4_free_blocks(handle, inode, new_blocks[i], num);
return err; return err;
} }
/** /**
* ext3_splice_branch - splice the allocated branch onto inode. * ext4_splice_branch - splice the allocated branch onto inode.
* @inode: owner * @inode: owner
* @block: (logical) number of block we are adding * @block: (logical) number of block we are adding
* @chain: chain of indirect blocks (with a missing link - see * @chain: chain of indirect blocks (with a missing link - see
* ext3_alloc_branch) * ext4_alloc_branch)
* @where: location of missing link * @where: location of missing link
* @num: number of indirect blocks we are adding * @num: number of indirect blocks we are adding
* @blks: number of direct blocks we are adding * @blks: number of direct blocks we are adding
...@@ -682,15 +682,15 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode, ...@@ -682,15 +682,15 @@ static int ext3_alloc_branch(handle_t *handle, struct inode *inode,
* inode (->i_blocks, etc.). In case of success we end up with the full * inode (->i_blocks, etc.). In case of success we end up with the full
* chain to new block and return 0. * chain to new block and return 0.
*/ */
static int ext3_splice_branch(handle_t *handle, struct inode *inode, static int ext4_splice_branch(handle_t *handle, struct inode *inode,
long block, Indirect *where, int num, int blks) long block, Indirect *where, int num, int blks)
{ {
int i; int i;
int err = 0; int err = 0;
struct ext3_block_alloc_info *block_i; struct ext4_block_alloc_info *block_i;
ext3_fsblk_t current_block; ext4_fsblk_t current_block;
block_i = EXT3_I(inode)->i_block_alloc_info; block_i = EXT4_I(inode)->i_block_alloc_info;
/* /*
* If we're splicing into a [td]indirect block (as opposed to the * If we're splicing into a [td]indirect block (as opposed to the
* inode) then we need to get write access to the [td]indirect block * 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,7 +698,7 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode,
*/ */
if (where->bh) { if (where->bh) {
BUFFER_TRACE(where->bh, "get_write_access"); BUFFER_TRACE(where->bh, "get_write_access");
err = ext3_journal_get_write_access(handle, where->bh); err = ext4_journal_get_write_access(handle, where->bh);
if (err) if (err)
goto err_out; goto err_out;
} }
...@@ -730,7 +730,7 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode, ...@@ -730,7 +730,7 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode,
/* We are done with atomic stuff, now do the rest of housekeeping */ /* We are done with atomic stuff, now do the rest of housekeeping */
inode->i_ctime = CURRENT_TIME_SEC; inode->i_ctime = CURRENT_TIME_SEC;
ext3_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
/* had we spliced it onto indirect block? */ /* had we spliced it onto indirect block? */
if (where->bh) { if (where->bh) {
...@@ -740,11 +740,11 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode, ...@@ -740,11 +740,11 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode,
* onto an indirect block at the very end of the file (the * onto an indirect block at the very end of the file (the
* file is growing) then we *will* alter the inode to reflect * file is growing) then we *will* alter the inode to reflect
* the new i_size. But that is not done here - it is done in * the new i_size. But that is not done here - it is done in
* generic_commit_write->__mark_inode_dirty->ext3_dirty_inode. * generic_commit_write->__mark_inode_dirty->ext4_dirty_inode.
*/ */
jbd_debug(5, "splicing indirect only\n"); jbd_debug(5, "splicing indirect only\n");
BUFFER_TRACE(where->bh, "call ext3_journal_dirty_metadata"); BUFFER_TRACE(where->bh, "call ext4_journal_dirty_metadata");
err = ext3_journal_dirty_metadata(handle, where->bh); err = ext4_journal_dirty_metadata(handle, where->bh);
if (err) if (err)
goto err_out; goto err_out;
} else { } else {
...@@ -759,10 +759,10 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode, ...@@ -759,10 +759,10 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode,
err_out: err_out:
for (i = 1; i <= num; i++) { for (i = 1; i <= num; i++) {
BUFFER_TRACE(where[i].bh, "call journal_forget"); BUFFER_TRACE(where[i].bh, "call journal_forget");
ext3_journal_forget(handle, where[i].bh); ext4_journal_forget(handle, where[i].bh);
ext3_free_blocks(handle,inode,le32_to_cpu(where[i-1].key),1); ext4_free_blocks(handle,inode,le32_to_cpu(where[i-1].key),1);
} }
ext3_free_blocks(handle, inode, le32_to_cpu(where[num].key), blks); ext4_free_blocks(handle, inode, le32_to_cpu(where[num].key), blks);
return err; return err;
} }
...@@ -786,7 +786,7 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode, ...@@ -786,7 +786,7 @@ static int ext3_splice_branch(handle_t *handle, struct inode *inode,
* return = 0, if plain lookup failed. * return = 0, if plain lookup failed.
* return < 0, error case. * return < 0, error case.
*/ */
int ext3_get_blocks_handle(handle_t *handle, struct inode *inode, int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
sector_t iblock, unsigned long maxblocks, sector_t iblock, unsigned long maxblocks,
struct buffer_head *bh_result, struct buffer_head *bh_result,
int create, int extend_disksize) int create, int extend_disksize)
...@@ -795,22 +795,22 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode, ...@@ -795,22 +795,22 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
int offsets[4]; int offsets[4];
Indirect chain[4]; Indirect chain[4];
Indirect *partial; Indirect *partial;
ext3_fsblk_t goal; ext4_fsblk_t goal;
int indirect_blks; int indirect_blks;
int blocks_to_boundary = 0; int blocks_to_boundary = 0;
int depth; int depth;
struct ext3_inode_info *ei = EXT3_I(inode); struct ext4_inode_info *ei = EXT4_I(inode);
int count = 0; int count = 0;
ext3_fsblk_t first_block = 0; ext4_fsblk_t first_block = 0;
J_ASSERT(handle != NULL || create == 0); J_ASSERT(handle != NULL || create == 0);
depth = ext3_block_to_path(inode,iblock,offsets,&blocks_to_boundary); depth = ext4_block_to_path(inode,iblock,offsets,&blocks_to_boundary);
if (depth == 0) if (depth == 0)
goto out; goto out;
partial = ext3_get_branch(inode, depth, offsets, chain, &err); partial = ext4_get_branch(inode, depth, offsets, chain, &err);
/* Simplest case - block found, no allocation needed */ /* Simplest case - block found, no allocation needed */
if (!partial) { if (!partial) {
...@@ -819,7 +819,7 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode, ...@@ -819,7 +819,7 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
count++; count++;
/*map more blocks*/ /*map more blocks*/
while (count < maxblocks && count <= blocks_to_boundary) { while (count < maxblocks && count <= blocks_to_boundary) {
ext3_fsblk_t blk; ext4_fsblk_t blk;
if (!verify_chain(chain, partial)) { if (!verify_chain(chain, partial)) {
/* /*
...@@ -852,7 +852,7 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode, ...@@ -852,7 +852,7 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
/* /*
* If the indirect block is missing while we are reading * If the indirect block is missing while we are reading
* the chain(ext3_get_branch() returns -EAGAIN err), or * the chain(ext4_get_branch() returns -EAGAIN err), or
* if the chain has been changed after we grab the semaphore, * if the chain has been changed after we grab the semaphore,
* (either because another process truncated this branch, or * (either because another process truncated this branch, or
* another get_block allocated this branch) re-grab the chain to see if * 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,7 +867,7 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
brelse(partial->bh); brelse(partial->bh);
partial--; partial--;
} }
partial = ext3_get_branch(inode, depth, offsets, chain, &err); partial = ext4_get_branch(inode, depth, offsets, chain, &err);
if (!partial) { if (!partial) {
count++; count++;
mutex_unlock(&ei->truncate_mutex); mutex_unlock(&ei->truncate_mutex);
...@@ -883,9 +883,9 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode, ...@@ -883,9 +883,9 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
* allocation info here if necessary * allocation info here if necessary
*/ */
if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info)) if (S_ISREG(inode->i_mode) && (!ei->i_block_alloc_info))
ext3_init_block_alloc_info(inode); ext4_init_block_alloc_info(inode);
goal = ext3_find_goal(inode, iblock, chain, partial); goal = ext4_find_goal(inode, iblock, chain, partial);
/* the number of blocks need to allocate for [d,t]indirect blocks */ /* the number of blocks need to allocate for [d,t]indirect blocks */
indirect_blks = (chain + depth) - partial - 1; indirect_blks = (chain + depth) - partial - 1;
...@@ -894,28 +894,28 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode, ...@@ -894,28 +894,28 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
* Next look up the indirect map to count the totoal number of * Next look up the indirect map to count the totoal number of
* direct blocks to allocate for this branch. * direct blocks to allocate for this branch.
*/ */
count = ext3_blks_to_allocate(partial, indirect_blks, count = ext4_blks_to_allocate(partial, indirect_blks,
maxblocks, blocks_to_boundary); maxblocks, blocks_to_boundary);
/* /*
* Block out ext3_truncate while we alter the tree * Block out ext4_truncate while we alter the tree
*/ */
err = ext3_alloc_branch(handle, inode, indirect_blks, &count, goal, err = ext4_alloc_branch(handle, inode, indirect_blks, &count, goal,
offsets + (partial - chain), partial); offsets + (partial - chain), partial);
/* /*
* The ext3_splice_branch call will free and forget any buffers * The ext4_splice_branch call will free and forget any buffers
* on the new chain if there is a failure, but that risks using * on the new chain if there is a failure, but that risks using
* up transaction credits, especially for bitmaps where the * up transaction credits, especially for bitmaps where the
* credits cannot be returned. Can we handle this somehow? We * credits cannot be returned. Can we handle this somehow? We
* may need to return -EAGAIN upwards in the worst case. --sct * may need to return -EAGAIN upwards in the worst case. --sct
*/ */
if (!err) if (!err)
err = ext3_splice_branch(handle, inode, iblock, err = ext4_splice_branch(handle, inode, iblock,
partial, indirect_blks, count); partial, indirect_blks, count);
/* /*
* i_disksize growing is protected by truncate_mutex. Don't forget to * i_disksize growing is protected by truncate_mutex. Don't forget to
* protect it if you're about to implement concurrent * protect it if you're about to implement concurrent
* ext3_get_block() -bzzz * ext4_get_block() -bzzz
*/ */
if (!err && extend_disksize && inode->i_size > ei->i_disksize) if (!err && extend_disksize && inode->i_size > ei->i_disksize)
ei->i_disksize = inode->i_size; ei->i_disksize = inode->i_size;
...@@ -942,9 +942,9 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode, ...@@ -942,9 +942,9 @@ int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
return err; return err;
} }
#define DIO_CREDITS (EXT3_RESERVE_TRANS_BLOCKS + 32) #define DIO_CREDITS (EXT4_RESERVE_TRANS_BLOCKS + 32)
static int ext3_get_block(struct inode *inode, sector_t iblock, static int ext4_get_block(struct inode *inode, sector_t iblock,
struct buffer_head *bh_result, int create) struct buffer_head *bh_result, int create)
{ {
handle_t *handle = journal_current_handle(); handle_t *handle = journal_current_handle();
...@@ -962,29 +962,29 @@ static int ext3_get_block(struct inode *inode, sector_t iblock, ...@@ -962,29 +962,29 @@ static int ext3_get_block(struct inode *inode, sector_t iblock,
* Huge direct-io writes can hold off commits for long * Huge direct-io writes can hold off commits for long
* periods of time. Let this commit run. * periods of time. Let this commit run.
*/ */
ext3_journal_stop(handle); ext4_journal_stop(handle);
handle = ext3_journal_start(inode, DIO_CREDITS); handle = ext4_journal_start(inode, DIO_CREDITS);
if (IS_ERR(handle)) if (IS_ERR(handle))
ret = PTR_ERR(handle); ret = PTR_ERR(handle);
goto get_block; goto get_block;
} }
if (handle->h_buffer_credits <= EXT3_RESERVE_TRANS_BLOCKS) { if (handle->h_buffer_credits <= EXT4_RESERVE_TRANS_BLOCKS) {
/* /*
* Getting low on buffer credits... * Getting low on buffer credits...
*/ */
ret = ext3_journal_extend(handle, DIO_CREDITS); ret = ext4_journal_extend(handle, DIO_CREDITS);
if (ret > 0) { if (ret > 0) {
/* /*
* Couldn't extend the transaction. Start a new one. * Couldn't extend the transaction. Start a new one.
*/ */
ret = ext3_journal_restart(handle, DIO_CREDITS); ret = ext4_journal_restart(handle, DIO_CREDITS);
} }
} }
get_block: get_block:
if (ret == 0) { if (ret == 0) {
ret = ext3_get_blocks_handle(handle, inode, iblock, ret = ext4_get_blocks_handle(handle, inode, iblock,
max_blocks, bh_result, create, 0); max_blocks, bh_result, create, 0);
if (ret > 0) { if (ret > 0) {
bh_result->b_size = (ret << inode->i_blkbits); bh_result->b_size = (ret << inode->i_blkbits);
...@@ -997,7 +997,7 @@ static int ext3_get_block(struct inode *inode, sector_t iblock, ...@@ -997,7 +997,7 @@ static int ext3_get_block(struct inode *inode, sector_t iblock,
/* /*
* `handle' can be NULL if create is zero * `handle' can be NULL if create is zero
*/ */
struct buffer_head *ext3_getblk(handle_t *handle, struct inode *inode, struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
long block, int create, int *errp) long block, int create, int *errp)
{ {
struct buffer_head dummy; struct buffer_head dummy;
...@@ -1008,10 +1008,10 @@ struct buffer_head *ext3_getblk(handle_t *handle, struct inode *inode, ...@@ -1008,10 +1008,10 @@ struct buffer_head *ext3_getblk(handle_t *handle, struct inode *inode,
dummy.b_state = 0; dummy.b_state = 0;
dummy.b_blocknr = -1000; dummy.b_blocknr = -1000;
buffer_trace_init(&dummy.b_history); buffer_trace_init(&dummy.b_history);
err = ext3_get_blocks_handle(handle, inode, block, 1, err = ext4_get_blocks_handle(handle, inode, block, 1,
&dummy, create, 1); &dummy, create, 1);
/* /*
* ext3_get_blocks_handle() returns number of blocks * ext4_get_blocks_handle() returns number of blocks
* mapped. 0 in case of a HOLE. * mapped. 0 in case of a HOLE.
*/ */
if (err > 0) { if (err > 0) {
...@@ -1035,19 +1035,19 @@ struct buffer_head *ext3_getblk(handle_t *handle, struct inode *inode, ...@@ -1035,19 +1035,19 @@ struct buffer_head *ext3_getblk(handle_t *handle, struct inode *inode,
* Now that we do not always journal data, we should * Now that we do not always journal data, we should
* keep in mind whether this should always journal the * keep in mind whether this should always journal the
* new buffer as metadata. For now, regular file * new buffer as metadata. For now, regular file
* writes use ext3_get_block instead, so it's not a * writes use ext4_get_block instead, so it's not a
* problem. * problem.
*/ */
lock_buffer(bh); lock_buffer(bh);
BUFFER_TRACE(bh, "call get_create_access"); BUFFER_TRACE(bh, "call get_create_access");
fatal = ext3_journal_get_create_access(handle, bh); fatal = ext4_journal_get_create_access(handle, bh);
if (!fatal && !buffer_uptodate(bh)) { if (!fatal && !buffer_uptodate(bh)) {
memset(bh->b_data,0,inode->i_sb->s_blocksize); memset(bh->b_data,0,inode->i_sb->s_blocksize);
set_buffer_uptodate(bh); set_buffer_uptodate(bh);
} }
unlock_buffer(bh); unlock_buffer(bh);
BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata"); BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
err = ext3_journal_dirty_metadata(handle, bh); err = ext4_journal_dirty_metadata(handle, bh);
if (!fatal) if (!fatal)
fatal = err; fatal = err;
} else { } else {
...@@ -1064,12 +1064,12 @@ struct buffer_head *ext3_getblk(handle_t *handle, struct inode *inode, ...@@ -1064,12 +1064,12 @@ struct buffer_head *ext3_getblk(handle_t *handle, struct inode *inode,
return NULL; return NULL;
} }
struct buffer_head *ext3_bread(handle_t *handle, struct inode *inode, struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode,
int block, int create, int *err) int block, int create, int *err)
{ {
struct buffer_head * bh; struct buffer_head * bh;
bh = ext3_getblk(handle, inode, block, create, err); bh = ext4_getblk(handle, inode, block, create, err);
if (!bh) if (!bh)
return bh; return bh;
if (buffer_uptodate(bh)) if (buffer_uptodate(bh))
...@@ -1118,17 +1118,17 @@ static int walk_page_buffers( handle_t *handle, ...@@ -1118,17 +1118,17 @@ static int walk_page_buffers( handle_t *handle,
/* /*
* To preserve ordering, it is essential that the hole instantiation and * To preserve ordering, it is essential that the hole instantiation and
* the data write be encapsulated in a single transaction. We cannot * the data write be encapsulated in a single transaction. We cannot
* close off a transaction and start a new one between the ext3_get_block() * close off a transaction and start a new one between the ext4_get_block()
* and the commit_write(). So doing the journal_start at the start of * and the commit_write(). So doing the journal_start at the start of
* prepare_write() is the right place. * prepare_write() is the right place.
* *
* Also, this function can nest inside ext3_writepage() -> * Also, this function can nest inside ext4_writepage() ->
* block_write_full_page(). In that case, we *know* that ext3_writepage() * block_write_full_page(). In that case, we *know* that ext4_writepage()
* has generated enough buffer credits to do the whole page. So we won't * has generated enough buffer credits to do the whole page. So we won't
* block on the journal in that case, which is good, because the caller may * block on the journal in that case, which is good, because the caller may
* be PF_MEMALLOC. * be PF_MEMALLOC.
* *
* By accident, ext3 can be reentered when a transaction is open via * By accident, ext4 can be reentered when a transaction is open via
* quota file writes. If we were to commit the transaction while thus * quota file writes. If we were to commit the transaction while thus
* reentered, there can be a deadlock - we would be holding a quota * reentered, there can be a deadlock - we would be holding a quota
* lock, and the commit would never complete if another thread had a * 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,48 +1145,48 @@ static int do_journal_get_write_access(handle_t *handle,
{ {
if (!buffer_mapped(bh) || buffer_freed(bh)) if (!buffer_mapped(bh) || buffer_freed(bh))
return 0; return 0;
return ext3_journal_get_write_access(handle, bh); return ext4_journal_get_write_access(handle, bh);
} }
static int ext3_prepare_write(struct file *file, struct page *page, static int ext4_prepare_write(struct file *file, struct page *page,
unsigned from, unsigned to) unsigned from, unsigned to)
{ {
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
int ret, needed_blocks = ext3_writepage_trans_blocks(inode); int ret, needed_blocks = ext4_writepage_trans_blocks(inode);
handle_t *handle; handle_t *handle;
int retries = 0; int retries = 0;
retry: retry:
handle = ext3_journal_start(inode, needed_blocks); handle = ext4_journal_start(inode, needed_blocks);
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
ret = PTR_ERR(handle); ret = PTR_ERR(handle);
goto out; goto out;
} }
if (test_opt(inode->i_sb, NOBH) && ext3_should_writeback_data(inode)) if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode))
ret = nobh_prepare_write(page, from, to, ext3_get_block); ret = nobh_prepare_write(page, from, to, ext4_get_block);
else else
ret = block_prepare_write(page, from, to, ext3_get_block); ret = block_prepare_write(page, from, to, ext4_get_block);
if (ret) if (ret)
goto prepare_write_failed; goto prepare_write_failed;
if (ext3_should_journal_data(inode)) { if (ext4_should_journal_data(inode)) {
ret = walk_page_buffers(handle, page_buffers(page), ret = walk_page_buffers(handle, page_buffers(page),
from, to, NULL, do_journal_get_write_access); from, to, NULL, do_journal_get_write_access);
} }
prepare_write_failed: prepare_write_failed:
if (ret) if (ret)
ext3_journal_stop(handle); ext4_journal_stop(handle);
if (ret == -ENOSPC && ext3_should_retry_alloc(inode->i_sb, &retries)) if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
goto retry; goto retry;
out: out:
return ret; return ret;
} }
int ext3_journal_dirty_data(handle_t *handle, struct buffer_head *bh) int ext4_journal_dirty_data(handle_t *handle, struct buffer_head *bh)
{ {
int err = journal_dirty_data(handle, bh); int err = journal_dirty_data(handle, bh);
if (err) if (err)
ext3_journal_abort_handle(__FUNCTION__, __FUNCTION__, ext4_journal_abort_handle(__FUNCTION__, __FUNCTION__,
bh, handle,err); bh, handle,err);
return err; return err;
} }
...@@ -1197,25 +1197,25 @@ static int commit_write_fn(handle_t *handle, struct buffer_head *bh) ...@@ -1197,25 +1197,25 @@ static int commit_write_fn(handle_t *handle, struct buffer_head *bh)
if (!buffer_mapped(bh) || buffer_freed(bh)) if (!buffer_mapped(bh) || buffer_freed(bh))
return 0; return 0;
set_buffer_uptodate(bh); set_buffer_uptodate(bh);
return ext3_journal_dirty_metadata(handle, bh); return ext4_journal_dirty_metadata(handle, bh);
} }
/* /*
* We need to pick up the new inode size which generic_commit_write gave us * We need to pick up the new inode size which generic_commit_write gave us
* `file' can be NULL - eg, when called from page_symlink(). * `file' can be NULL - eg, when called from page_symlink().
* *
* ext3 never places buffers on inode->i_mapping->private_list. metadata * ext4 never places buffers on inode->i_mapping->private_list. metadata
* buffers are managed internally. * buffers are managed internally.
*/ */
static int ext3_ordered_commit_write(struct file *file, struct page *page, static int ext4_ordered_commit_write(struct file *file, struct page *page,
unsigned from, unsigned to) unsigned from, unsigned to)
{ {
handle_t *handle = ext3_journal_current_handle(); handle_t *handle = ext4_journal_current_handle();
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
int ret = 0, ret2; int ret = 0, ret2;
ret = walk_page_buffers(handle, page_buffers(page), ret = walk_page_buffers(handle, page_buffers(page),
from, to, NULL, ext3_journal_dirty_data); from, to, NULL, ext4_journal_dirty_data);
if (ret == 0) { if (ret == 0) {
/* /*
...@@ -1226,43 +1226,43 @@ static int ext3_ordered_commit_write(struct file *file, struct page *page, ...@@ -1226,43 +1226,43 @@ static int ext3_ordered_commit_write(struct file *file, struct page *page,
loff_t new_i_size; loff_t new_i_size;
new_i_size = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to; new_i_size = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
if (new_i_size > EXT3_I(inode)->i_disksize) if (new_i_size > EXT4_I(inode)->i_disksize)
EXT3_I(inode)->i_disksize = new_i_size; EXT4_I(inode)->i_disksize = new_i_size;
ret = generic_commit_write(file, page, from, to); ret = generic_commit_write(file, page, from, to);
} }
ret2 = ext3_journal_stop(handle); ret2 = ext4_journal_stop(handle);
if (!ret) if (!ret)
ret = ret2; ret = ret2;
return ret; return ret;
} }
static int ext3_writeback_commit_write(struct file *file, struct page *page, static int ext4_writeback_commit_write(struct file *file, struct page *page,
unsigned from, unsigned to) unsigned from, unsigned to)
{ {
handle_t *handle = ext3_journal_current_handle(); handle_t *handle = ext4_journal_current_handle();
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
int ret = 0, ret2; int ret = 0, ret2;
loff_t new_i_size; loff_t new_i_size;
new_i_size = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to; new_i_size = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
if (new_i_size > EXT3_I(inode)->i_disksize) if (new_i_size > EXT4_I(inode)->i_disksize)
EXT3_I(inode)->i_disksize = new_i_size; EXT4_I(inode)->i_disksize = new_i_size;
if (test_opt(inode->i_sb, NOBH) && ext3_should_writeback_data(inode)) if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode))
ret = nobh_commit_write(file, page, from, to); ret = nobh_commit_write(file, page, from, to);
else else
ret = generic_commit_write(file, page, from, to); ret = generic_commit_write(file, page, from, to);
ret2 = ext3_journal_stop(handle); ret2 = ext4_journal_stop(handle);
if (!ret) if (!ret)
ret = ret2; ret = ret2;
return ret; return ret;
} }
static int ext3_journalled_commit_write(struct file *file, static int ext4_journalled_commit_write(struct file *file,
struct page *page, unsigned from, unsigned to) struct page *page, unsigned from, unsigned to)
{ {
handle_t *handle = ext3_journal_current_handle(); handle_t *handle = ext4_journal_current_handle();
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
int ret = 0, ret2; int ret = 0, ret2;
int partial = 0; int partial = 0;
...@@ -1279,14 +1279,14 @@ static int ext3_journalled_commit_write(struct file *file, ...@@ -1279,14 +1279,14 @@ static int ext3_journalled_commit_write(struct file *file,
SetPageUptodate(page); SetPageUptodate(page);
if (pos > inode->i_size) if (pos > inode->i_size)
i_size_write(inode, pos); i_size_write(inode, pos);
EXT3_I(inode)->i_state |= EXT3_STATE_JDATA; EXT4_I(inode)->i_state |= EXT4_STATE_JDATA;
if (inode->i_size > EXT3_I(inode)->i_disksize) { if (inode->i_size > EXT4_I(inode)->i_disksize) {
EXT3_I(inode)->i_disksize = inode->i_size; EXT4_I(inode)->i_disksize = inode->i_size;
ret2 = ext3_mark_inode_dirty(handle, inode); ret2 = ext4_mark_inode_dirty(handle, inode);
if (!ret) if (!ret)
ret = ret2; ret = ret2;
} }
ret2 = ext3_journal_stop(handle); ret2 = ext4_journal_stop(handle);
if (!ret) if (!ret)
ret = ret2; ret = ret2;
return ret; return ret;
...@@ -1297,7 +1297,7 @@ static int ext3_journalled_commit_write(struct file *file, ...@@ -1297,7 +1297,7 @@ static int ext3_journalled_commit_write(struct file *file,
* the swapper to find the on-disk block of a specific piece of data. * the swapper to find the on-disk block of a specific piece of data.
* *
* Naturally, this is dangerous if the block concerned is still in the * Naturally, this is dangerous if the block concerned is still in the
* journal. If somebody makes a swapfile on an ext3 data-journaling * journal. If somebody makes a swapfile on an ext4 data-journaling
* filesystem and enables swap, then they may get a nasty shock when the * filesystem and enables swap, then they may get a nasty shock when the
* data getting swapped to that swapfile suddenly gets overwritten by * data getting swapped to that swapfile suddenly gets overwritten by
* the original zero's written out previously to the journal and * 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,13 +1306,13 @@ static int ext3_journalled_commit_write(struct file *file,
* So, if we see any bmap calls here on a modified, data-journaled file, * So, if we see any bmap calls here on a modified, data-journaled file,
* take extra steps to flush any blocks which might be in the cache. * take extra steps to flush any blocks which might be in the cache.
*/ */
static sector_t ext3_bmap(struct address_space *mapping, sector_t block) static sector_t ext4_bmap(struct address_space *mapping, sector_t block)
{ {
struct inode *inode = mapping->host; struct inode *inode = mapping->host;
journal_t *journal; journal_t *journal;
int err; int err;
if (EXT3_I(inode)->i_state & EXT3_STATE_JDATA) { if (EXT4_I(inode)->i_state & EXT4_STATE_JDATA) {
/* /*
* This is a REALLY heavyweight approach, but the use of * This is a REALLY heavyweight approach, but the use of
* bmap on dirty files is expected to be extremely rare: * 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,15 +1324,15 @@ static sector_t ext3_bmap(struct address_space *mapping, sector_t block)
* in trouble if mortal users could trigger this path at * in trouble if mortal users could trigger this path at
* will.) * will.)
* *
* NB. EXT3_STATE_JDATA is not set on files other than * NB. EXT4_STATE_JDATA is not set on files other than
* regular files. If somebody wants to bmap a directory * regular files. If somebody wants to bmap a directory
* or symlink and gets confused because the buffer * or symlink and gets confused because the buffer
* hasn't yet been flushed to disk, they deserve * hasn't yet been flushed to disk, they deserve
* everything they get. * everything they get.
*/ */
EXT3_I(inode)->i_state &= ~EXT3_STATE_JDATA; EXT4_I(inode)->i_state &= ~EXT4_STATE_JDATA;
journal = EXT3_JOURNAL(inode); journal = EXT4_JOURNAL(inode);
journal_lock_updates(journal); journal_lock_updates(journal);
err = journal_flush(journal); err = journal_flush(journal);
journal_unlock_updates(journal); journal_unlock_updates(journal);
...@@ -1341,7 +1341,7 @@ static sector_t ext3_bmap(struct address_space *mapping, sector_t block) ...@@ -1341,7 +1341,7 @@ static sector_t ext3_bmap(struct address_space *mapping, sector_t block)
return 0; return 0;
} }
return generic_block_bmap(mapping,block,ext3_get_block); return generic_block_bmap(mapping,block,ext4_get_block);
} }
static int bget_one(handle_t *handle, struct buffer_head *bh) static 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) ...@@ -1359,14 +1359,14 @@ static int bput_one(handle_t *handle, struct buffer_head *bh)
static int journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh) static int journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)
{ {
if (buffer_mapped(bh)) if (buffer_mapped(bh))
return ext3_journal_dirty_data(handle, bh); return ext4_journal_dirty_data(handle, bh);
return 0; return 0;
} }
/* /*
* Note that we always start a transaction even if we're not journalling * Note that we always start a transaction even if we're not journalling
* data. This is to preserve ordering: any hole instantiation within * data. This is to preserve ordering: any hole instantiation within
* __block_write_full_page -> ext3_get_block() should be journalled * __block_write_full_page -> ext4_get_block() should be journalled
* along with the data so we don't crash and then get metadata which * along with the data so we don't crash and then get metadata which
* refers to old data. * refers to old data.
* *
...@@ -1374,14 +1374,14 @@ static int journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh) ...@@ -1374,14 +1374,14 @@ static int journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)
* *
* Problem: * Problem:
* *
* ext3_writepage() -> kmalloc() -> __alloc_pages() -> page_launder() -> * ext4_writepage() -> kmalloc() -> __alloc_pages() -> page_launder() ->
* ext3_writepage() * ext4_writepage()
* *
* Similar for: * Similar for:
* *
* ext3_file_write() -> generic_file_write() -> __alloc_pages() -> ... * ext4_file_write() -> generic_file_write() -> __alloc_pages() -> ...
* *
* Same applies to ext3_get_block(). We will deadlock on various things like * Same applies to ext4_get_block(). We will deadlock on various things like
* lock_journal and i_truncate_mutex. * lock_journal and i_truncate_mutex.
* *
* Setting PF_MEMALLOC here doesn't work - too many internal memory * 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,7 +1415,7 @@ static int journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)
* AKPM2: if all the page's buffers are mapped to disk and !data=journal, * AKPM2: if all the page's buffers are mapped to disk and !data=journal,
* we don't need to open a transaction here. * we don't need to open a transaction here.
*/ */
static int ext3_ordered_writepage(struct page *page, static int ext4_ordered_writepage(struct page *page,
struct writeback_control *wbc) struct writeback_control *wbc)
{ {
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
...@@ -1430,10 +1430,10 @@ static int ext3_ordered_writepage(struct page *page, ...@@ -1430,10 +1430,10 @@ static int ext3_ordered_writepage(struct page *page,
* We give up here if we're reentered, because it might be for a * We give up here if we're reentered, because it might be for a
* different filesystem. * different filesystem.
*/ */
if (ext3_journal_current_handle()) if (ext4_journal_current_handle())
goto out_fail; goto out_fail;
handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode)); handle = ext4_journal_start(inode, ext4_writepage_trans_blocks(inode));
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
ret = PTR_ERR(handle); ret = PTR_ERR(handle);
...@@ -1448,7 +1448,7 @@ static int ext3_ordered_writepage(struct page *page, ...@@ -1448,7 +1448,7 @@ static int ext3_ordered_writepage(struct page *page,
walk_page_buffers(handle, page_bufs, 0, walk_page_buffers(handle, page_bufs, 0,
PAGE_CACHE_SIZE, NULL, bget_one); PAGE_CACHE_SIZE, NULL, bget_one);
ret = block_write_full_page(page, ext3_get_block, wbc); ret = block_write_full_page(page, ext4_get_block, wbc);
/* /*
* The page can become unlocked at any point now, and * The page can become unlocked at any point now, and
...@@ -1470,7 +1470,7 @@ static int ext3_ordered_writepage(struct page *page, ...@@ -1470,7 +1470,7 @@ static int ext3_ordered_writepage(struct page *page,
} }
walk_page_buffers(handle, page_bufs, 0, walk_page_buffers(handle, page_bufs, 0,
PAGE_CACHE_SIZE, NULL, bput_one); PAGE_CACHE_SIZE, NULL, bput_one);
err = ext3_journal_stop(handle); err = ext4_journal_stop(handle);
if (!ret) if (!ret)
ret = err; ret = err;
return ret; return ret;
...@@ -1481,7 +1481,7 @@ static int ext3_ordered_writepage(struct page *page, ...@@ -1481,7 +1481,7 @@ static int ext3_ordered_writepage(struct page *page,
return ret; return ret;
} }
static int ext3_writeback_writepage(struct page *page, static int ext4_writeback_writepage(struct page *page,
struct writeback_control *wbc) struct writeback_control *wbc)
{ {
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
...@@ -1489,21 +1489,21 @@ static int ext3_writeback_writepage(struct page *page, ...@@ -1489,21 +1489,21 @@ static int ext3_writeback_writepage(struct page *page,
int ret = 0; int ret = 0;
int err; int err;
if (ext3_journal_current_handle()) if (ext4_journal_current_handle())
goto out_fail; goto out_fail;
handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode)); handle = ext4_journal_start(inode, ext4_writepage_trans_blocks(inode));
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
ret = PTR_ERR(handle); ret = PTR_ERR(handle);
goto out_fail; goto out_fail;
} }
if (test_opt(inode->i_sb, NOBH) && ext3_should_writeback_data(inode)) if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode))
ret = nobh_writepage(page, ext3_get_block, wbc); ret = nobh_writepage(page, ext4_get_block, wbc);
else else
ret = block_write_full_page(page, ext3_get_block, wbc); ret = block_write_full_page(page, ext4_get_block, wbc);
err = ext3_journal_stop(handle); err = ext4_journal_stop(handle);
if (!ret) if (!ret)
ret = err; ret = err;
return ret; return ret;
...@@ -1514,7 +1514,7 @@ static int ext3_writeback_writepage(struct page *page, ...@@ -1514,7 +1514,7 @@ static int ext3_writeback_writepage(struct page *page,
return ret; return ret;
} }
static int ext3_journalled_writepage(struct page *page, static int ext4_journalled_writepage(struct page *page,
struct writeback_control *wbc) struct writeback_control *wbc)
{ {
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
...@@ -1522,10 +1522,10 @@ static int ext3_journalled_writepage(struct page *page, ...@@ -1522,10 +1522,10 @@ static int ext3_journalled_writepage(struct page *page,
int ret = 0; int ret = 0;
int err; int err;
if (ext3_journal_current_handle()) if (ext4_journal_current_handle())
goto no_write; goto no_write;
handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode)); handle = ext4_journal_start(inode, ext4_writepage_trans_blocks(inode));
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
ret = PTR_ERR(handle); ret = PTR_ERR(handle);
goto no_write; goto no_write;
...@@ -1538,9 +1538,9 @@ static int ext3_journalled_writepage(struct page *page, ...@@ -1538,9 +1538,9 @@ static int ext3_journalled_writepage(struct page *page,
*/ */
ClearPageChecked(page); ClearPageChecked(page);
ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE, ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE,
ext3_get_block); ext4_get_block);
if (ret != 0) { if (ret != 0) {
ext3_journal_stop(handle); ext4_journal_stop(handle);
goto out_unlock; goto out_unlock;
} }
ret = walk_page_buffers(handle, page_buffers(page), 0, ret = walk_page_buffers(handle, page_buffers(page), 0,
...@@ -1550,7 +1550,7 @@ static int ext3_journalled_writepage(struct page *page, ...@@ -1550,7 +1550,7 @@ static int ext3_journalled_writepage(struct page *page,
PAGE_CACHE_SIZE, NULL, commit_write_fn); PAGE_CACHE_SIZE, NULL, commit_write_fn);
if (ret == 0) if (ret == 0)
ret = err; ret = err;
EXT3_I(inode)->i_state |= EXT3_STATE_JDATA; EXT4_I(inode)->i_state |= EXT4_STATE_JDATA;
unlock_page(page); unlock_page(page);
} else { } else {
/* /*
...@@ -1558,9 +1558,9 @@ static int ext3_journalled_writepage(struct page *page, ...@@ -1558,9 +1558,9 @@ static int ext3_journalled_writepage(struct page *page,
* really know unless we go poke around in the buffer_heads. * really know unless we go poke around in the buffer_heads.
* But block_write_full_page will do the right thing. * But block_write_full_page will do the right thing.
*/ */
ret = block_write_full_page(page, ext3_get_block, wbc); ret = block_write_full_page(page, ext4_get_block, wbc);
} }
err = ext3_journal_stop(handle); err = ext4_journal_stop(handle);
if (!ret) if (!ret)
ret = err; ret = err;
out: out:
...@@ -1573,21 +1573,21 @@ static int ext3_journalled_writepage(struct page *page, ...@@ -1573,21 +1573,21 @@ static int ext3_journalled_writepage(struct page *page,
goto out; goto out;
} }
static int ext3_readpage(struct file *file, struct page *page) static int ext4_readpage(struct file *file, struct page *page)
{ {
return mpage_readpage(page, ext3_get_block); return mpage_readpage(page, ext4_get_block);
} }
static int static int
ext3_readpages(struct file *file, struct address_space *mapping, ext4_readpages(struct file *file, struct address_space *mapping,
struct list_head *pages, unsigned nr_pages) struct list_head *pages, unsigned nr_pages)
{ {
return mpage_readpages(mapping, pages, nr_pages, ext3_get_block); return mpage_readpages(mapping, pages, nr_pages, ext4_get_block);
} }
static void ext3_invalidatepage(struct page *page, unsigned long offset) static void ext4_invalidatepage(struct page *page, unsigned long offset)
{ {
journal_t *journal = EXT3_JOURNAL(page->mapping->host); journal_t *journal = EXT4_JOURNAL(page->mapping->host);
/* /*
* If it's a full truncate we just forget about the pending dirtying * 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,9 +1598,9 @@ static void ext3_invalidatepage(struct page *page, unsigned long offset)
journal_invalidatepage(journal, page, offset); journal_invalidatepage(journal, page, offset);
} }
static int ext3_releasepage(struct page *page, gfp_t wait) static int ext4_releasepage(struct page *page, gfp_t wait)
{ {
journal_t *journal = EXT3_JOURNAL(page->mapping->host); journal_t *journal = EXT4_JOURNAL(page->mapping->host);
WARN_ON(PageChecked(page)); WARN_ON(PageChecked(page));
if (!page_has_buffers(page)) if (!page_has_buffers(page))
...@@ -1616,13 +1616,13 @@ static int ext3_releasepage(struct page *page, gfp_t wait) ...@@ -1616,13 +1616,13 @@ static int ext3_releasepage(struct page *page, gfp_t wait)
* If the O_DIRECT write is intantiating holes inside i_size and the machine * If the O_DIRECT write is intantiating holes inside i_size and the machine
* crashes then stale disk data _may_ be exposed inside the file. * crashes then stale disk data _may_ be exposed inside the file.
*/ */
static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb,
const struct iovec *iov, loff_t offset, const struct iovec *iov, loff_t offset,
unsigned long nr_segs) unsigned long nr_segs)
{ {
struct file *file = iocb->ki_filp; struct file *file = iocb->ki_filp;
struct inode *inode = file->f_mapping->host; struct inode *inode = file->f_mapping->host;
struct ext3_inode_info *ei = EXT3_I(inode); struct ext4_inode_info *ei = EXT4_I(inode);
handle_t *handle = NULL; handle_t *handle = NULL;
ssize_t ret; ssize_t ret;
int orphan = 0; int orphan = 0;
...@@ -1631,13 +1631,13 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, ...@@ -1631,13 +1631,13 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
if (rw == WRITE) { if (rw == WRITE) {
loff_t final_size = offset + count; loff_t final_size = offset + count;
handle = ext3_journal_start(inode, DIO_CREDITS); handle = ext4_journal_start(inode, DIO_CREDITS);
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
ret = PTR_ERR(handle); ret = PTR_ERR(handle);
goto out; goto out;
} }
if (final_size > inode->i_size) { if (final_size > inode->i_size) {
ret = ext3_orphan_add(handle, inode); ret = ext4_orphan_add(handle, inode);
if (ret) if (ret)
goto out_stop; goto out_stop;
orphan = 1; orphan = 1;
...@@ -1647,10 +1647,10 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, ...@@ -1647,10 +1647,10 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
ret = blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, ret = blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov,
offset, nr_segs, offset, nr_segs,
ext3_get_block, NULL); ext4_get_block, NULL);
/* /*
* Reacquire the handle: ext3_get_block() can restart the transaction * Reacquire the handle: ext4_get_block() can restart the transaction
*/ */
handle = journal_current_handle(); handle = journal_current_handle();
...@@ -1659,7 +1659,7 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, ...@@ -1659,7 +1659,7 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
int err; int err;
if (orphan && inode->i_nlink) if (orphan && inode->i_nlink)
ext3_orphan_del(handle, inode); ext4_orphan_del(handle, inode);
if (orphan && ret > 0) { if (orphan && ret > 0) {
loff_t end = offset + ret; loff_t end = offset + ret;
if (end > inode->i_size) { if (end > inode->i_size) {
...@@ -1669,13 +1669,13 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, ...@@ -1669,13 +1669,13 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
* We're going to return a positive `ret' * We're going to return a positive `ret'
* here due to non-zero-length I/O, so there's * here due to non-zero-length I/O, so there's
* no way of reporting error returns from * no way of reporting error returns from
* ext3_mark_inode_dirty() to userspace. So * ext4_mark_inode_dirty() to userspace. So
* ignore it. * ignore it.
*/ */
ext3_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
} }
} }
err = ext3_journal_stop(handle); err = ext4_journal_stop(handle);
if (ret == 0) if (ret == 0)
ret = err; ret = err;
} }
...@@ -1684,7 +1684,7 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, ...@@ -1684,7 +1684,7 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
} }
/* /*
* Pages can be marked dirty completely asynchronously from ext3's journalling * Pages can be marked dirty completely asynchronously from ext4's journalling
* activity. By filemap_sync_pte(), try_to_unmap_one(), etc. We cannot do * activity. By filemap_sync_pte(), try_to_unmap_one(), etc. We cannot do
* much here because ->set_page_dirty is called under VFS locks. The page is * much here because ->set_page_dirty is called under VFS locks. The page is
* not necessarily locked. * not necessarily locked.
...@@ -1696,73 +1696,73 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb, ...@@ -1696,73 +1696,73 @@ static ssize_t ext3_direct_IO(int rw, struct kiocb *iocb,
* So what we do is to mark the page "pending dirty" and next time writepage * So what we do is to mark the page "pending dirty" and next time writepage
* is called, propagate that into the buffers appropriately. * is called, propagate that into the buffers appropriately.
*/ */
static int ext3_journalled_set_page_dirty(struct page *page) static int ext4_journalled_set_page_dirty(struct page *page)
{ {
SetPageChecked(page); SetPageChecked(page);
return __set_page_dirty_nobuffers(page); return __set_page_dirty_nobuffers(page);
} }
static const struct address_space_operations ext3_ordered_aops = { static const struct address_space_operations ext4_ordered_aops = {
.readpage = ext3_readpage, .readpage = ext4_readpage,
.readpages = ext3_readpages, .readpages = ext4_readpages,
.writepage = ext3_ordered_writepage, .writepage = ext4_ordered_writepage,
.sync_page = block_sync_page, .sync_page = block_sync_page,
.prepare_write = ext3_prepare_write, .prepare_write = ext4_prepare_write,
.commit_write = ext3_ordered_commit_write, .commit_write = ext4_ordered_commit_write,
.bmap = ext3_bmap, .bmap = ext4_bmap,
.invalidatepage = ext3_invalidatepage, .invalidatepage = ext4_invalidatepage,
.releasepage = ext3_releasepage, .releasepage = ext4_releasepage,
.direct_IO = ext3_direct_IO, .direct_IO = ext4_direct_IO,
.migratepage = buffer_migrate_page, .migratepage = buffer_migrate_page,
}; };
static const struct address_space_operations ext3_writeback_aops = { static const struct address_space_operations ext4_writeback_aops = {
.readpage = ext3_readpage, .readpage = ext4_readpage,
.readpages = ext3_readpages, .readpages = ext4_readpages,
.writepage = ext3_writeback_writepage, .writepage = ext4_writeback_writepage,
.sync_page = block_sync_page, .sync_page = block_sync_page,
.prepare_write = ext3_prepare_write, .prepare_write = ext4_prepare_write,
.commit_write = ext3_writeback_commit_write, .commit_write = ext4_writeback_commit_write,
.bmap = ext3_bmap, .bmap = ext4_bmap,
.invalidatepage = ext3_invalidatepage, .invalidatepage = ext4_invalidatepage,
.releasepage = ext3_releasepage, .releasepage = ext4_releasepage,
.direct_IO = ext3_direct_IO, .direct_IO = ext4_direct_IO,
.migratepage = buffer_migrate_page, .migratepage = buffer_migrate_page,
}; };
static const struct address_space_operations ext3_journalled_aops = { static const struct address_space_operations ext4_journalled_aops = {
.readpage = ext3_readpage, .readpage = ext4_readpage,
.readpages = ext3_readpages, .readpages = ext4_readpages,
.writepage = ext3_journalled_writepage, .writepage = ext4_journalled_writepage,
.sync_page = block_sync_page, .sync_page = block_sync_page,
.prepare_write = ext3_prepare_write, .prepare_write = ext4_prepare_write,
.commit_write = ext3_journalled_commit_write, .commit_write = ext4_journalled_commit_write,
.set_page_dirty = ext3_journalled_set_page_dirty, .set_page_dirty = ext4_journalled_set_page_dirty,
.bmap = ext3_bmap, .bmap = ext4_bmap,
.invalidatepage = ext3_invalidatepage, .invalidatepage = ext4_invalidatepage,
.releasepage = ext3_releasepage, .releasepage = ext4_releasepage,
}; };
void ext3_set_aops(struct inode *inode) void ext4_set_aops(struct inode *inode)
{ {
if (ext3_should_order_data(inode)) if (ext4_should_order_data(inode))
inode->i_mapping->a_ops = &ext3_ordered_aops; inode->i_mapping->a_ops = &ext4_ordered_aops;
else if (ext3_should_writeback_data(inode)) else if (ext4_should_writeback_data(inode))
inode->i_mapping->a_ops = &ext3_writeback_aops; inode->i_mapping->a_ops = &ext4_writeback_aops;
else else
inode->i_mapping->a_ops = &ext3_journalled_aops; inode->i_mapping->a_ops = &ext4_journalled_aops;
} }
/* /*
* ext3_block_truncate_page() zeroes out a mapping from file offset `from' * ext4_block_truncate_page() zeroes out a mapping from file offset `from'
* up to the end of the block which corresponds to `from'. * up to the end of the block which corresponds to `from'.
* This required during truncate. We need to physically zero the tail end * This required during truncate. We need to physically zero the tail end
* of that block so it doesn't yield old data if the file is later grown. * of that block so it doesn't yield old data if the file is later grown.
*/ */
static int ext3_block_truncate_page(handle_t *handle, struct page *page, static int ext4_block_truncate_page(handle_t *handle, struct page *page,
struct address_space *mapping, loff_t from) struct address_space *mapping, loff_t from)
{ {
ext3_fsblk_t index = from >> PAGE_CACHE_SHIFT; ext4_fsblk_t index = from >> PAGE_CACHE_SHIFT;
unsigned offset = from & (PAGE_CACHE_SIZE-1); unsigned offset = from & (PAGE_CACHE_SIZE-1);
unsigned blocksize, iblock, length, pos; unsigned blocksize, iblock, length, pos;
struct inode *inode = mapping->host; struct inode *inode = mapping->host;
...@@ -1779,7 +1779,7 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page, ...@@ -1779,7 +1779,7 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page,
* read-in the page - otherwise we create buffers to do the IO. * read-in the page - otherwise we create buffers to do the IO.
*/ */
if (!page_has_buffers(page) && test_opt(inode->i_sb, NOBH) && if (!page_has_buffers(page) && test_opt(inode->i_sb, NOBH) &&
ext3_should_writeback_data(inode) && PageUptodate(page)) { ext4_should_writeback_data(inode) && PageUptodate(page)) {
kaddr = kmap_atomic(page, KM_USER0); kaddr = kmap_atomic(page, KM_USER0);
memset(kaddr + offset, 0, length); memset(kaddr + offset, 0, length);
flush_dcache_page(page); flush_dcache_page(page);
...@@ -1808,7 +1808,7 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page, ...@@ -1808,7 +1808,7 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page,
if (!buffer_mapped(bh)) { if (!buffer_mapped(bh)) {
BUFFER_TRACE(bh, "unmapped"); BUFFER_TRACE(bh, "unmapped");
ext3_get_block(inode, iblock, bh, 0); ext4_get_block(inode, iblock, bh, 0);
/* unmapped? It's a hole - nothing to do */ /* unmapped? It's a hole - nothing to do */
if (!buffer_mapped(bh)) { if (!buffer_mapped(bh)) {
BUFFER_TRACE(bh, "still unmapped"); BUFFER_TRACE(bh, "still unmapped");
...@@ -1829,9 +1829,9 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page, ...@@ -1829,9 +1829,9 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page,
goto unlock; goto unlock;
} }
if (ext3_should_journal_data(inode)) { if (ext4_should_journal_data(inode)) {
BUFFER_TRACE(bh, "get write access"); BUFFER_TRACE(bh, "get write access");
err = ext3_journal_get_write_access(handle, bh); err = ext4_journal_get_write_access(handle, bh);
if (err) if (err)
goto unlock; goto unlock;
} }
...@@ -1844,11 +1844,11 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page, ...@@ -1844,11 +1844,11 @@ static int ext3_block_truncate_page(handle_t *handle, struct page *page,
BUFFER_TRACE(bh, "zeroed end of block"); BUFFER_TRACE(bh, "zeroed end of block");
err = 0; err = 0;
if (ext3_should_journal_data(inode)) { if (ext4_should_journal_data(inode)) {
err = ext3_journal_dirty_metadata(handle, bh); err = ext4_journal_dirty_metadata(handle, bh);
} else { } else {
if (ext3_should_order_data(inode)) if (ext4_should_order_data(inode))
err = ext3_journal_dirty_data(handle, bh); err = ext4_journal_dirty_data(handle, bh);
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
} }
...@@ -1872,14 +1872,14 @@ static inline int all_zeroes(__le32 *p, __le32 *q) ...@@ -1872,14 +1872,14 @@ static inline int all_zeroes(__le32 *p, __le32 *q)
} }
/** /**
* ext3_find_shared - find the indirect blocks for partial truncation. * ext4_find_shared - find the indirect blocks for partial truncation.
* @inode: inode in question * @inode: inode in question
* @depth: depth of the affected branch * @depth: depth of the affected branch
* @offsets: offsets of pointers in that branch (see ext3_block_to_path) * @offsets: offsets of pointers in that branch (see ext4_block_to_path)
* @chain: place to store the pointers to partial indirect blocks * @chain: place to store the pointers to partial indirect blocks
* @top: place to the (detached) top of branch * @top: place to the (detached) top of branch
* *
* This is a helper function used by ext3_truncate(). * This is a helper function used by ext4_truncate().
* *
* When we do truncate() we may have to clean the ends of several * When we do truncate() we may have to clean the ends of several
* indirect blocks but leave the blocks themselves alive. Block is * indirect blocks but leave the blocks themselves alive. Block is
...@@ -1887,7 +1887,7 @@ static inline int all_zeroes(__le32 *p, __le32 *q) ...@@ -1887,7 +1887,7 @@ static inline int all_zeroes(__le32 *p, __le32 *q)
* from it (and it is on the path to the first completely truncated * from it (and it is on the path to the first completely truncated
* data block, indeed). We have to free the top of that path along * data block, indeed). We have to free the top of that path along
* with everything to the right of the path. Since no allocation * with everything to the right of the path. Since no allocation
* past the truncation point is possible until ext3_truncate() * past the truncation point is possible until ext4_truncate()
* finishes, we may safely do the latter, but top of branch may * finishes, we may safely do the latter, but top of branch may
* require special attention - pageout below the truncation point * require special attention - pageout below the truncation point
* might try to populate it. * might try to populate it.
...@@ -1906,7 +1906,7 @@ static inline int all_zeroes(__le32 *p, __le32 *q) ...@@ -1906,7 +1906,7 @@ static inline int all_zeroes(__le32 *p, __le32 *q)
* c) free the subtrees growing from the inode past the @chain[0]. * c) free the subtrees growing from the inode past the @chain[0].
* (no partially truncated stuff there). */ * (no partially truncated stuff there). */
static Indirect *ext3_find_shared(struct inode *inode, int depth, static Indirect *ext4_find_shared(struct inode *inode, int depth,
int offsets[4], Indirect chain[4], __le32 *top) int offsets[4], Indirect chain[4], __le32 *top)
{ {
Indirect *partial, *p; Indirect *partial, *p;
...@@ -1916,7 +1916,7 @@ static Indirect *ext3_find_shared(struct inode *inode, int depth, ...@@ -1916,7 +1916,7 @@ static Indirect *ext3_find_shared(struct inode *inode, int depth,
/* Make k index the deepest non-null offest + 1 */ /* Make k index the deepest non-null offest + 1 */
for (k = depth; k > 1 && !offsets[k-1]; k--) for (k = depth; k > 1 && !offsets[k-1]; k--)
; ;
partial = ext3_get_branch(inode, k, offsets, chain, &err); partial = ext4_get_branch(inode, k, offsets, chain, &err);
/* Writer: pointers */ /* Writer: pointers */
if (!partial) if (!partial)
partial = chain + k-1; partial = chain + k-1;
...@@ -1939,7 +1939,7 @@ static Indirect *ext3_find_shared(struct inode *inode, int depth, ...@@ -1939,7 +1939,7 @@ static Indirect *ext3_find_shared(struct inode *inode, int depth,
p->p--; p->p--;
} else { } else {
*top = *p->p; *top = *p->p;
/* Nope, don't do this in ext3. Must leave the tree intact */ /* Nope, don't do this in ext4. Must leave the tree intact */
#if 0 #if 0
*p->p = 0; *p->p = 0;
#endif #endif
...@@ -1962,21 +1962,21 @@ static Indirect *ext3_find_shared(struct inode *inode, int depth, ...@@ -1962,21 +1962,21 @@ static Indirect *ext3_find_shared(struct inode *inode, int depth,
* We release `count' blocks on disk, but (last - first) may be greater * We release `count' blocks on disk, but (last - first) may be greater
* than `count' because there can be holes in there. * than `count' because there can be holes in there.
*/ */
static void ext3_clear_blocks(handle_t *handle, struct inode *inode, static void ext4_clear_blocks(handle_t *handle, struct inode *inode,
struct buffer_head *bh, ext3_fsblk_t block_to_free, struct buffer_head *bh, ext4_fsblk_t block_to_free,
unsigned long count, __le32 *first, __le32 *last) unsigned long count, __le32 *first, __le32 *last)
{ {
__le32 *p; __le32 *p;
if (try_to_extend_transaction(handle, inode)) { if (try_to_extend_transaction(handle, inode)) {
if (bh) { if (bh) {
BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata"); BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
ext3_journal_dirty_metadata(handle, bh); ext4_journal_dirty_metadata(handle, bh);
} }
ext3_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
ext3_journal_test_restart(handle, inode); ext4_journal_test_restart(handle, inode);
if (bh) { if (bh) {
BUFFER_TRACE(bh, "retaking write access"); BUFFER_TRACE(bh, "retaking write access");
ext3_journal_get_write_access(handle, bh); ext4_journal_get_write_access(handle, bh);
} }
} }
...@@ -1995,15 +1995,15 @@ static void ext3_clear_blocks(handle_t *handle, struct inode *inode, ...@@ -1995,15 +1995,15 @@ static void ext3_clear_blocks(handle_t *handle, struct inode *inode,
*p = 0; *p = 0;
bh = sb_find_get_block(inode->i_sb, nr); bh = sb_find_get_block(inode->i_sb, nr);
ext3_forget(handle, 0, inode, bh, nr); ext4_forget(handle, 0, inode, bh, nr);
} }
} }
ext3_free_blocks(handle, inode, block_to_free, count); ext4_free_blocks(handle, inode, block_to_free, count);
} }
/** /**
* ext3_free_data - free a list of data blocks * ext4_free_data - free a list of data blocks
* @handle: handle for this transaction * @handle: handle for this transaction
* @inode: inode we are dealing with * @inode: inode we are dealing with
* @this_bh: indirect buffer_head which contains *@first and *@last * @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,23 +2021,23 @@ static void ext3_clear_blocks(handle_t *handle, struct inode *inode,
* @this_bh will be %NULL if @first and @last point into the inode's direct * @this_bh will be %NULL if @first and @last point into the inode's direct
* block pointers. * block pointers.
*/ */
static void ext3_free_data(handle_t *handle, struct inode *inode, static void ext4_free_data(handle_t *handle, struct inode *inode,
struct buffer_head *this_bh, struct buffer_head *this_bh,
__le32 *first, __le32 *last) __le32 *first, __le32 *last)
{ {
ext3_fsblk_t block_to_free = 0; /* Starting block # of a run */ ext4_fsblk_t block_to_free = 0; /* Starting block # of a run */
unsigned long count = 0; /* Number of blocks in the run */ unsigned long count = 0; /* Number of blocks in the run */
__le32 *block_to_free_p = NULL; /* Pointer into inode/ind __le32 *block_to_free_p = NULL; /* Pointer into inode/ind
corresponding to corresponding to
block_to_free */ block_to_free */
ext3_fsblk_t nr; /* Current block # */ ext4_fsblk_t nr; /* Current block # */
__le32 *p; /* Pointer into inode/ind __le32 *p; /* Pointer into inode/ind
for current block */ for current block */
int err; int err;
if (this_bh) { /* For indirect block */ if (this_bh) { /* For indirect block */
BUFFER_TRACE(this_bh, "get_write_access"); BUFFER_TRACE(this_bh, "get_write_access");
err = ext3_journal_get_write_access(handle, this_bh); err = ext4_journal_get_write_access(handle, this_bh);
/* Important: if we can't update the indirect pointers /* Important: if we can't update the indirect pointers
* to the blocks, we can't free them. */ * to the blocks, we can't free them. */
if (err) if (err)
...@@ -2055,7 +2055,7 @@ static void ext3_free_data(handle_t *handle, struct inode *inode, ...@@ -2055,7 +2055,7 @@ static void ext3_free_data(handle_t *handle, struct inode *inode,
} else if (nr == block_to_free + count) { } else if (nr == block_to_free + count) {
count++; count++;
} else { } else {
ext3_clear_blocks(handle, inode, this_bh, ext4_clear_blocks(handle, inode, this_bh,
block_to_free, block_to_free,
count, block_to_free_p, p); count, block_to_free_p, p);
block_to_free = nr; block_to_free = nr;
...@@ -2066,17 +2066,17 @@ static void ext3_free_data(handle_t *handle, struct inode *inode, ...@@ -2066,17 +2066,17 @@ static void ext3_free_data(handle_t *handle, struct inode *inode,
} }
if (count > 0) if (count > 0)
ext3_clear_blocks(handle, inode, this_bh, block_to_free, ext4_clear_blocks(handle, inode, this_bh, block_to_free,
count, block_to_free_p, p); count, block_to_free_p, p);
if (this_bh) { if (this_bh) {
BUFFER_TRACE(this_bh, "call ext3_journal_dirty_metadata"); BUFFER_TRACE(this_bh, "call ext4_journal_dirty_metadata");
ext3_journal_dirty_metadata(handle, this_bh); ext4_journal_dirty_metadata(handle, this_bh);
} }
} }
/** /**
* ext3_free_branches - free an array of branches * ext4_free_branches - free an array of branches
* @handle: JBD handle for this transaction * @handle: JBD handle for this transaction
* @inode: inode we are dealing with * @inode: inode we are dealing with
* @parent_bh: the buffer_head which contains *@first and *@last * @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,11 +2088,11 @@ static void ext3_free_data(handle_t *handle, struct inode *inode,
* stored as little-endian 32-bit) and updating @inode->i_blocks * stored as little-endian 32-bit) and updating @inode->i_blocks
* appropriately. * appropriately.
*/ */
static void ext3_free_branches(handle_t *handle, struct inode *inode, static void ext4_free_branches(handle_t *handle, struct inode *inode,
struct buffer_head *parent_bh, struct buffer_head *parent_bh,
__le32 *first, __le32 *last, int depth) __le32 *first, __le32 *last, int depth)
{ {
ext3_fsblk_t nr; ext4_fsblk_t nr;
__le32 *p; __le32 *p;
if (is_handle_aborted(handle)) if (is_handle_aborted(handle))
...@@ -2100,7 +2100,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode, ...@@ -2100,7 +2100,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
if (depth--) { if (depth--) {
struct buffer_head *bh; struct buffer_head *bh;
int addr_per_block = EXT3_ADDR_PER_BLOCK(inode->i_sb); int addr_per_block = EXT4_ADDR_PER_BLOCK(inode->i_sb);
p = last; p = last;
while (--p >= first) { while (--p >= first) {
nr = le32_to_cpu(*p); nr = le32_to_cpu(*p);
...@@ -2115,7 +2115,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode, ...@@ -2115,7 +2115,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
* (should be rare). * (should be rare).
*/ */
if (!bh) { if (!bh) {
ext3_error(inode->i_sb, "ext3_free_branches", ext4_error(inode->i_sb, "ext4_free_branches",
"Read failure, inode=%lu, block="E3FSBLK, "Read failure, inode=%lu, block="E3FSBLK,
inode->i_ino, nr); inode->i_ino, nr);
continue; continue;
...@@ -2123,7 +2123,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode, ...@@ -2123,7 +2123,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
/* This zaps the entire block. Bottom up. */ /* This zaps the entire block. Bottom up. */
BUFFER_TRACE(bh, "free child branches"); BUFFER_TRACE(bh, "free child branches");
ext3_free_branches(handle, inode, bh, ext4_free_branches(handle, inode, bh,
(__le32*)bh->b_data, (__le32*)bh->b_data,
(__le32*)bh->b_data + addr_per_block, (__le32*)bh->b_data + addr_per_block,
depth); depth);
...@@ -2138,7 +2138,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode, ...@@ -2138,7 +2138,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
* transaction. But if it's part of the committing * transaction. But if it's part of the committing
* transaction then journal_forget() will simply * transaction then journal_forget() will simply
* brelse() it. That means that if the underlying * brelse() it. That means that if the underlying
* block is reallocated in ext3_get_block(), * block is reallocated in ext4_get_block(),
* unmap_underlying_metadata() will find this block * unmap_underlying_metadata() will find this block
* and will try to get rid of it. damn, damn. * and will try to get rid of it. damn, damn.
* *
...@@ -2147,7 +2147,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode, ...@@ -2147,7 +2147,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
* revoke records must be emitted *before* clearing * revoke records must be emitted *before* clearing
* this block's bit in the bitmaps. * this block's bit in the bitmaps.
*/ */
ext3_forget(handle, 1, inode, bh, bh->b_blocknr); ext4_forget(handle, 1, inode, bh, bh->b_blocknr);
/* /*
* Everything below this this pointer has been * Everything below this this pointer has been
...@@ -2168,11 +2168,11 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode, ...@@ -2168,11 +2168,11 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
if (is_handle_aborted(handle)) if (is_handle_aborted(handle))
return; return;
if (try_to_extend_transaction(handle, inode)) { if (try_to_extend_transaction(handle, inode)) {
ext3_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
ext3_journal_test_restart(handle, inode); ext4_journal_test_restart(handle, inode);
} }
ext3_free_blocks(handle, inode, nr, 1); ext4_free_blocks(handle, inode, nr, 1);
if (parent_bh) { if (parent_bh) {
/* /*
...@@ -2180,12 +2180,12 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode, ...@@ -2180,12 +2180,12 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
* pointed to by an indirect block: journal it * pointed to by an indirect block: journal it
*/ */
BUFFER_TRACE(parent_bh, "get_write_access"); BUFFER_TRACE(parent_bh, "get_write_access");
if (!ext3_journal_get_write_access(handle, if (!ext4_journal_get_write_access(handle,
parent_bh)){ parent_bh)){
*p = 0; *p = 0;
BUFFER_TRACE(parent_bh, BUFFER_TRACE(parent_bh,
"call ext3_journal_dirty_metadata"); "call ext4_journal_dirty_metadata");
ext3_journal_dirty_metadata(handle, ext4_journal_dirty_metadata(handle,
parent_bh); parent_bh);
} }
} }
...@@ -2193,15 +2193,15 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode, ...@@ -2193,15 +2193,15 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
} else { } else {
/* We have reached the bottom of the tree. */ /* We have reached the bottom of the tree. */
BUFFER_TRACE(parent_bh, "free data blocks"); BUFFER_TRACE(parent_bh, "free data blocks");
ext3_free_data(handle, inode, parent_bh, first, last); ext4_free_data(handle, inode, parent_bh, first, last);
} }
} }
/* /*
* ext3_truncate() * ext4_truncate()
* *
* We block out ext3_get_block() block instantiations across the entire * We block out ext4_get_block() block instantiations across the entire
* transaction, and VFS/VM ensures that ext3_truncate() cannot run * transaction, and VFS/VM ensures that ext4_truncate() cannot run
* simultaneously on behalf of the same inode. * simultaneously on behalf of the same inode.
* *
* As we work through the truncate and commmit bits of it to the journal there * 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,19 +2218,19 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
* truncate against the orphan inode list. * truncate against the orphan inode list.
* *
* The committed inode has the new, desired i_size (which is the same as * The committed inode has the new, desired i_size (which is the same as
* i_disksize in this case). After a crash, ext3_orphan_cleanup() will see * i_disksize in this case). After a crash, ext4_orphan_cleanup() will see
* that this inode's truncate did not complete and it will again call * that this inode's truncate did not complete and it will again call
* ext3_truncate() to have another go. So there will be instantiated blocks * ext4_truncate() to have another go. So there will be instantiated blocks
* to the right of the truncation point in a crashed ext3 filesystem. But * to the right of the truncation point in a crashed ext4 filesystem. But
* that's fine - as long as they are linked from the inode, the post-crash * that's fine - as long as they are linked from the inode, the post-crash
* ext3_truncate() run will find them and release them. * ext4_truncate() run will find them and release them.
*/ */
void ext3_truncate(struct inode *inode) void ext4_truncate(struct inode *inode)
{ {
handle_t *handle; handle_t *handle;
struct ext3_inode_info *ei = EXT3_I(inode); struct ext4_inode_info *ei = EXT4_I(inode);
__le32 *i_data = ei->i_data; __le32 *i_data = ei->i_data;
int addr_per_block = EXT3_ADDR_PER_BLOCK(inode->i_sb); int addr_per_block = EXT4_ADDR_PER_BLOCK(inode->i_sb);
struct address_space *mapping = inode->i_mapping; struct address_space *mapping = inode->i_mapping;
int offsets[4]; int offsets[4];
Indirect chain[4]; Indirect chain[4];
...@@ -2244,7 +2244,7 @@ void ext3_truncate(struct inode *inode) ...@@ -2244,7 +2244,7 @@ void ext3_truncate(struct inode *inode)
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
S_ISLNK(inode->i_mode))) S_ISLNK(inode->i_mode)))
return; return;
if (ext3_inode_is_fast_symlink(inode)) if (ext4_inode_is_fast_symlink(inode))
return; return;
if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
return; return;
...@@ -2275,12 +2275,12 @@ void ext3_truncate(struct inode *inode) ...@@ -2275,12 +2275,12 @@ void ext3_truncate(struct inode *inode)
} }
last_block = (inode->i_size + blocksize-1) last_block = (inode->i_size + blocksize-1)
>> EXT3_BLOCK_SIZE_BITS(inode->i_sb); >> EXT4_BLOCK_SIZE_BITS(inode->i_sb);
if (page) if (page)
ext3_block_truncate_page(handle, page, mapping, inode->i_size); ext4_block_truncate_page(handle, page, mapping, inode->i_size);
n = ext3_block_to_path(inode, last_block, offsets, NULL); n = ext4_block_to_path(inode, last_block, offsets, NULL);
if (n == 0) if (n == 0)
goto out_stop; /* error */ goto out_stop; /* error */
...@@ -2293,7 +2293,7 @@ void ext3_truncate(struct inode *inode) ...@@ -2293,7 +2293,7 @@ void ext3_truncate(struct inode *inode)
* Implication: the file must always be in a sane, consistent * Implication: the file must always be in a sane, consistent
* truncatable state while each transaction commits. * truncatable state while each transaction commits.
*/ */
if (ext3_orphan_add(handle, inode)) if (ext4_orphan_add(handle, inode))
goto out_stop; goto out_stop;
/* /*
...@@ -2301,28 +2301,28 @@ void ext3_truncate(struct inode *inode) ...@@ -2301,28 +2301,28 @@ void ext3_truncate(struct inode *inode)
* occurs before the truncate completes, so it is now safe to propagate * occurs before the truncate completes, so it is now safe to propagate
* the new, shorter inode size (held for now in i_size) into the * the new, shorter inode size (held for now in i_size) into the
* on-disk inode. We do this via i_disksize, which is the value which * on-disk inode. We do this via i_disksize, which is the value which
* ext3 *really* writes onto the disk inode. * ext4 *really* writes onto the disk inode.
*/ */
ei->i_disksize = inode->i_size; ei->i_disksize = inode->i_size;
/* /*
* From here we block out all ext3_get_block() callers who want to * From here we block out all ext4_get_block() callers who want to
* modify the block allocation tree. * modify the block allocation tree.
*/ */
mutex_lock(&ei->truncate_mutex); mutex_lock(&ei->truncate_mutex);
if (n == 1) { /* direct blocks */ if (n == 1) { /* direct blocks */
ext3_free_data(handle, inode, NULL, i_data+offsets[0], ext4_free_data(handle, inode, NULL, i_data+offsets[0],
i_data + EXT3_NDIR_BLOCKS); i_data + EXT4_NDIR_BLOCKS);
goto do_indirects; goto do_indirects;
} }
partial = ext3_find_shared(inode, n, offsets, chain, &nr); partial = ext4_find_shared(inode, n, offsets, chain, &nr);
/* Kill the top of shared branch (not detached) */ /* Kill the top of shared branch (not detached) */
if (nr) { if (nr) {
if (partial == chain) { if (partial == chain) {
/* Shared branch grows from the inode */ /* Shared branch grows from the inode */
ext3_free_branches(handle, inode, NULL, ext4_free_branches(handle, inode, NULL,
&nr, &nr+1, (chain+n-1) - partial); &nr, &nr+1, (chain+n-1) - partial);
*partial->p = 0; *partial->p = 0;
/* /*
...@@ -2332,14 +2332,14 @@ void ext3_truncate(struct inode *inode) ...@@ -2332,14 +2332,14 @@ void ext3_truncate(struct inode *inode)
} else { } else {
/* Shared branch grows from an indirect block */ /* Shared branch grows from an indirect block */
BUFFER_TRACE(partial->bh, "get_write_access"); BUFFER_TRACE(partial->bh, "get_write_access");
ext3_free_branches(handle, inode, partial->bh, ext4_free_branches(handle, inode, partial->bh,
partial->p, partial->p,
partial->p+1, (chain+n-1) - partial); partial->p+1, (chain+n-1) - partial);
} }
} }
/* Clear the ends of indirect blocks on the shared branch */ /* Clear the ends of indirect blocks on the shared branch */
while (partial > chain) { while (partial > chain) {
ext3_free_branches(handle, inode, partial->bh, partial->p + 1, ext4_free_branches(handle, inode, partial->bh, partial->p + 1,
(__le32*)partial->bh->b_data+addr_per_block, (__le32*)partial->bh->b_data+addr_per_block,
(chain+n-1) - partial); (chain+n-1) - partial);
BUFFER_TRACE(partial->bh, "call brelse"); BUFFER_TRACE(partial->bh, "call brelse");
...@@ -2350,32 +2350,32 @@ void ext3_truncate(struct inode *inode) ...@@ -2350,32 +2350,32 @@ void ext3_truncate(struct inode *inode)
/* Kill the remaining (whole) subtrees */ /* Kill the remaining (whole) subtrees */
switch (offsets[0]) { switch (offsets[0]) {
default: default:
nr = i_data[EXT3_IND_BLOCK]; nr = i_data[EXT4_IND_BLOCK];
if (nr) { if (nr) {
ext3_free_branches(handle, inode, NULL, &nr, &nr+1, 1); ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 1);
i_data[EXT3_IND_BLOCK] = 0; i_data[EXT4_IND_BLOCK] = 0;
} }
case EXT3_IND_BLOCK: case EXT4_IND_BLOCK:
nr = i_data[EXT3_DIND_BLOCK]; nr = i_data[EXT4_DIND_BLOCK];
if (nr) { if (nr) {
ext3_free_branches(handle, inode, NULL, &nr, &nr+1, 2); ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 2);
i_data[EXT3_DIND_BLOCK] = 0; i_data[EXT4_DIND_BLOCK] = 0;
} }
case EXT3_DIND_BLOCK: case EXT4_DIND_BLOCK:
nr = i_data[EXT3_TIND_BLOCK]; nr = i_data[EXT4_TIND_BLOCK];
if (nr) { if (nr) {
ext3_free_branches(handle, inode, NULL, &nr, &nr+1, 3); ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 3);
i_data[EXT3_TIND_BLOCK] = 0; i_data[EXT4_TIND_BLOCK] = 0;
} }
case EXT3_TIND_BLOCK: case EXT4_TIND_BLOCK:
; ;
} }
ext3_discard_reservation(inode); ext4_discard_reservation(inode);
mutex_unlock(&ei->truncate_mutex); mutex_unlock(&ei->truncate_mutex);
inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC; inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
ext3_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
/* /*
* In a multi-transaction truncate, we only make the final transaction * In a multi-transaction truncate, we only make the final transaction
...@@ -2388,25 +2388,25 @@ void ext3_truncate(struct inode *inode) ...@@ -2388,25 +2388,25 @@ void ext3_truncate(struct inode *inode)
* If this was a simple ftruncate(), and the file will remain alive * If this was a simple ftruncate(), and the file will remain alive
* then we need to clear up the orphan record which we created above. * then we need to clear up the orphan record which we created above.
* However, if this was a real unlink then we were called by * However, if this was a real unlink then we were called by
* ext3_delete_inode(), and we allow that function to clean up the * ext4_delete_inode(), and we allow that function to clean up the
* orphan info for us. * orphan info for us.
*/ */
if (inode->i_nlink) if (inode->i_nlink)
ext3_orphan_del(handle, inode); ext4_orphan_del(handle, inode);
ext3_journal_stop(handle); ext4_journal_stop(handle);
} }
static ext3_fsblk_t ext3_get_inode_block(struct super_block *sb, static ext4_fsblk_t ext4_get_inode_block(struct super_block *sb,
unsigned long ino, struct ext3_iloc *iloc) unsigned long ino, struct ext4_iloc *iloc)
{ {
unsigned long desc, group_desc, block_group; unsigned long desc, group_desc, block_group;
unsigned long offset; unsigned long offset;
ext3_fsblk_t block; ext4_fsblk_t block;
struct buffer_head *bh; struct buffer_head *bh;
struct ext3_group_desc * gdp; struct ext4_group_desc * gdp;
if (!ext3_valid_inum(sb, ino)) { if (!ext4_valid_inum(sb, ino)) {
/* /*
* This error is already checked for in namei.c unless we are * This error is already checked for in namei.c unless we are
* looking at an NFS filehandle, in which case no error * 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,54 +2415,54 @@ static ext3_fsblk_t ext3_get_inode_block(struct super_block *sb,
return 0; return 0;
} }
block_group = (ino - 1) / EXT3_INODES_PER_GROUP(sb); block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
if (block_group >= EXT3_SB(sb)->s_groups_count) { if (block_group >= EXT4_SB(sb)->s_groups_count) {
ext3_error(sb,"ext3_get_inode_block","group >= groups count"); ext4_error(sb,"ext4_get_inode_block","group >= groups count");
return 0; return 0;
} }
smp_rmb(); smp_rmb();
group_desc = block_group >> EXT3_DESC_PER_BLOCK_BITS(sb); group_desc = block_group >> EXT4_DESC_PER_BLOCK_BITS(sb);
desc = block_group & (EXT3_DESC_PER_BLOCK(sb) - 1); desc = block_group & (EXT4_DESC_PER_BLOCK(sb) - 1);
bh = EXT3_SB(sb)->s_group_desc[group_desc]; bh = EXT4_SB(sb)->s_group_desc[group_desc];
if (!bh) { if (!bh) {
ext3_error (sb, "ext3_get_inode_block", ext4_error (sb, "ext4_get_inode_block",
"Descriptor not loaded"); "Descriptor not loaded");
return 0; return 0;
} }
gdp = (struct ext3_group_desc *)bh->b_data; gdp = (struct ext4_group_desc *)bh->b_data;
/* /*
* Figure out the offset within the block group inode table * Figure out the offset within the block group inode table
*/ */
offset = ((ino - 1) % EXT3_INODES_PER_GROUP(sb)) * offset = ((ino - 1) % EXT4_INODES_PER_GROUP(sb)) *
EXT3_INODE_SIZE(sb); EXT4_INODE_SIZE(sb);
block = le32_to_cpu(gdp[desc].bg_inode_table) + block = le32_to_cpu(gdp[desc].bg_inode_table) +
(offset >> EXT3_BLOCK_SIZE_BITS(sb)); (offset >> EXT4_BLOCK_SIZE_BITS(sb));
iloc->block_group = block_group; iloc->block_group = block_group;
iloc->offset = offset & (EXT3_BLOCK_SIZE(sb) - 1); iloc->offset = offset & (EXT4_BLOCK_SIZE(sb) - 1);
return block; return block;
} }
/* /*
* ext3_get_inode_loc returns with an extra refcount against the inode's * ext4_get_inode_loc returns with an extra refcount against the inode's
* underlying buffer_head on success. If 'in_mem' is true, we have all * underlying buffer_head on success. If 'in_mem' is true, we have all
* data in memory that is needed to recreate the on-disk version of this * data in memory that is needed to recreate the on-disk version of this
* inode. * inode.
*/ */
static int __ext3_get_inode_loc(struct inode *inode, static int __ext4_get_inode_loc(struct inode *inode,
struct ext3_iloc *iloc, int in_mem) struct ext4_iloc *iloc, int in_mem)
{ {
ext3_fsblk_t block; ext4_fsblk_t block;
struct buffer_head *bh; struct buffer_head *bh;
block = ext3_get_inode_block(inode->i_sb, inode->i_ino, iloc); block = ext4_get_inode_block(inode->i_sb, inode->i_ino, iloc);
if (!block) if (!block)
return -EIO; return -EIO;
bh = sb_getblk(inode->i_sb, block); bh = sb_getblk(inode->i_sb, block);
if (!bh) { if (!bh) {
ext3_error (inode->i_sb, "ext3_get_inode_loc", ext4_error (inode->i_sb, "ext4_get_inode_loc",
"unable to read inode block - " "unable to read inode block - "
"inode=%lu, block="E3FSBLK, "inode=%lu, block="E3FSBLK,
inode->i_ino, block); inode->i_ino, block);
...@@ -2483,22 +2483,22 @@ static int __ext3_get_inode_loc(struct inode *inode, ...@@ -2483,22 +2483,22 @@ static int __ext3_get_inode_loc(struct inode *inode,
*/ */
if (in_mem) { if (in_mem) {
struct buffer_head *bitmap_bh; struct buffer_head *bitmap_bh;
struct ext3_group_desc *desc; struct ext4_group_desc *desc;
int inodes_per_buffer; int inodes_per_buffer;
int inode_offset, i; int inode_offset, i;
int block_group; int block_group;
int start; int start;
block_group = (inode->i_ino - 1) / block_group = (inode->i_ino - 1) /
EXT3_INODES_PER_GROUP(inode->i_sb); EXT4_INODES_PER_GROUP(inode->i_sb);
inodes_per_buffer = bh->b_size / inodes_per_buffer = bh->b_size /
EXT3_INODE_SIZE(inode->i_sb); EXT4_INODE_SIZE(inode->i_sb);
inode_offset = ((inode->i_ino - 1) % inode_offset = ((inode->i_ino - 1) %
EXT3_INODES_PER_GROUP(inode->i_sb)); EXT4_INODES_PER_GROUP(inode->i_sb));
start = inode_offset & ~(inodes_per_buffer - 1); start = inode_offset & ~(inodes_per_buffer - 1);
/* Is the inode bitmap in cache? */ /* Is the inode bitmap in cache? */
desc = ext3_get_group_desc(inode->i_sb, desc = ext4_get_group_desc(inode->i_sb,
block_group, NULL); block_group, NULL);
if (!desc) if (!desc)
goto make_io; goto make_io;
...@@ -2520,7 +2520,7 @@ static int __ext3_get_inode_loc(struct inode *inode, ...@@ -2520,7 +2520,7 @@ static int __ext3_get_inode_loc(struct inode *inode,
for (i = start; i < start + inodes_per_buffer; i++) { for (i = start; i < start + inodes_per_buffer; i++) {
if (i == inode_offset) if (i == inode_offset)
continue; continue;
if (ext3_test_bit(i, bitmap_bh->b_data)) if (ext4_test_bit(i, bitmap_bh->b_data))
break; break;
} }
brelse(bitmap_bh); brelse(bitmap_bh);
...@@ -2544,7 +2544,7 @@ static int __ext3_get_inode_loc(struct inode *inode, ...@@ -2544,7 +2544,7 @@ static int __ext3_get_inode_loc(struct inode *inode,
submit_bh(READ_META, bh); submit_bh(READ_META, bh);
wait_on_buffer(bh); wait_on_buffer(bh);
if (!buffer_uptodate(bh)) { if (!buffer_uptodate(bh)) {
ext3_error(inode->i_sb, "ext3_get_inode_loc", ext4_error(inode->i_sb, "ext4_get_inode_loc",
"unable to read inode block - " "unable to read inode block - "
"inode=%lu, block="E3FSBLK, "inode=%lu, block="E3FSBLK,
inode->i_ino, block); inode->i_ino, block);
...@@ -2557,48 +2557,48 @@ static int __ext3_get_inode_loc(struct inode *inode, ...@@ -2557,48 +2557,48 @@ static int __ext3_get_inode_loc(struct inode *inode,
return 0; return 0;
} }
int ext3_get_inode_loc(struct inode *inode, struct ext3_iloc *iloc) int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc)
{ {
/* We have all inode data except xattrs in memory here. */ /* We have all inode data except xattrs in memory here. */
return __ext3_get_inode_loc(inode, iloc, return __ext4_get_inode_loc(inode, iloc,
!(EXT3_I(inode)->i_state & EXT3_STATE_XATTR)); !(EXT4_I(inode)->i_state & EXT4_STATE_XATTR));
} }
void ext3_set_inode_flags(struct inode *inode) void ext4_set_inode_flags(struct inode *inode)
{ {
unsigned int flags = EXT3_I(inode)->i_flags; unsigned int flags = EXT4_I(inode)->i_flags;
inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC); inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
if (flags & EXT3_SYNC_FL) if (flags & EXT4_SYNC_FL)
inode->i_flags |= S_SYNC; inode->i_flags |= S_SYNC;
if (flags & EXT3_APPEND_FL) if (flags & EXT4_APPEND_FL)
inode->i_flags |= S_APPEND; inode->i_flags |= S_APPEND;
if (flags & EXT3_IMMUTABLE_FL) if (flags & EXT4_IMMUTABLE_FL)
inode->i_flags |= S_IMMUTABLE; inode->i_flags |= S_IMMUTABLE;
if (flags & EXT3_NOATIME_FL) if (flags & EXT4_NOATIME_FL)
inode->i_flags |= S_NOATIME; inode->i_flags |= S_NOATIME;
if (flags & EXT3_DIRSYNC_FL) if (flags & EXT4_DIRSYNC_FL)
inode->i_flags |= S_DIRSYNC; inode->i_flags |= S_DIRSYNC;
} }
void ext3_read_inode(struct inode * inode) void ext4_read_inode(struct inode * inode)
{ {
struct ext3_iloc iloc; struct ext4_iloc iloc;
struct ext3_inode *raw_inode; struct ext4_inode *raw_inode;
struct ext3_inode_info *ei = EXT3_I(inode); struct ext4_inode_info *ei = EXT4_I(inode);
struct buffer_head *bh; struct buffer_head *bh;
int block; int block;
#ifdef CONFIG_EXT3_FS_POSIX_ACL #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
ei->i_acl = EXT3_ACL_NOT_CACHED; ei->i_acl = EXT4_ACL_NOT_CACHED;
ei->i_default_acl = EXT3_ACL_NOT_CACHED; ei->i_default_acl = EXT4_ACL_NOT_CACHED;
#endif #endif
ei->i_block_alloc_info = NULL; ei->i_block_alloc_info = NULL;
if (__ext3_get_inode_loc(inode, &iloc, 0)) if (__ext4_get_inode_loc(inode, &iloc, 0))
goto bad_inode; goto bad_inode;
bh = iloc.bh; bh = iloc.bh;
raw_inode = ext3_raw_inode(&iloc); raw_inode = ext4_raw_inode(&iloc);
inode->i_mode = le16_to_cpu(raw_inode->i_mode); inode->i_mode = le16_to_cpu(raw_inode->i_mode);
inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low); inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low); 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,7 +2623,7 @@ void ext3_read_inode(struct inode * inode)
*/ */
if (inode->i_nlink == 0) { if (inode->i_nlink == 0) {
if (inode->i_mode == 0 || if (inode->i_mode == 0 ||
!(EXT3_SB(inode->i_sb)->s_mount_state & EXT3_ORPHAN_FS)) { !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS)) {
/* this inode is deleted */ /* this inode is deleted */
brelse (bh); brelse (bh);
goto bad_inode; goto bad_inode;
...@@ -2635,7 +2635,7 @@ void ext3_read_inode(struct inode * inode) ...@@ -2635,7 +2635,7 @@ void ext3_read_inode(struct inode * inode)
} }
inode->i_blocks = le32_to_cpu(raw_inode->i_blocks); inode->i_blocks = le32_to_cpu(raw_inode->i_blocks);
ei->i_flags = le32_to_cpu(raw_inode->i_flags); ei->i_flags = le32_to_cpu(raw_inode->i_flags);
#ifdef EXT3_FRAGMENTS #ifdef EXT4_FRAGMENTS
ei->i_faddr = le32_to_cpu(raw_inode->i_faddr); ei->i_faddr = le32_to_cpu(raw_inode->i_faddr);
ei->i_frag_no = raw_inode->i_frag; ei->i_frag_no = raw_inode->i_frag;
ei->i_frag_size = raw_inode->i_fsize; ei->i_frag_size = raw_inode->i_fsize;
...@@ -2654,51 +2654,51 @@ void ext3_read_inode(struct inode * inode) ...@@ -2654,51 +2654,51 @@ void ext3_read_inode(struct inode * inode)
* NOTE! The in-memory inode i_data array is in little-endian order * NOTE! The in-memory inode i_data array is in little-endian order
* even on big-endian machines: we do NOT byteswap the block numbers! * even on big-endian machines: we do NOT byteswap the block numbers!
*/ */
for (block = 0; block < EXT3_N_BLOCKS; block++) for (block = 0; block < EXT4_N_BLOCKS; block++)
ei->i_data[block] = raw_inode->i_block[block]; ei->i_data[block] = raw_inode->i_block[block];
INIT_LIST_HEAD(&ei->i_orphan); INIT_LIST_HEAD(&ei->i_orphan);
if (inode->i_ino >= EXT3_FIRST_INO(inode->i_sb) + 1 && if (inode->i_ino >= EXT4_FIRST_INO(inode->i_sb) + 1 &&
EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE) { EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) {
/* /*
* When mke2fs creates big inodes it does not zero out * When mke2fs creates big inodes it does not zero out
* the unused bytes above EXT3_GOOD_OLD_INODE_SIZE, * the unused bytes above EXT4_GOOD_OLD_INODE_SIZE,
* so ignore those first few inodes. * so ignore those first few inodes.
*/ */
ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize); ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize);
if (EXT3_GOOD_OLD_INODE_SIZE + ei->i_extra_isize > if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize >
EXT3_INODE_SIZE(inode->i_sb)) EXT4_INODE_SIZE(inode->i_sb))
goto bad_inode; goto bad_inode;
if (ei->i_extra_isize == 0) { if (ei->i_extra_isize == 0) {
/* The extra space is currently unused. Use it. */ /* The extra space is currently unused. Use it. */
ei->i_extra_isize = sizeof(struct ext3_inode) - ei->i_extra_isize = sizeof(struct ext4_inode) -
EXT3_GOOD_OLD_INODE_SIZE; EXT4_GOOD_OLD_INODE_SIZE;
} else { } else {
__le32 *magic = (void *)raw_inode + __le32 *magic = (void *)raw_inode +
EXT3_GOOD_OLD_INODE_SIZE + EXT4_GOOD_OLD_INODE_SIZE +
ei->i_extra_isize; ei->i_extra_isize;
if (*magic == cpu_to_le32(EXT3_XATTR_MAGIC)) if (*magic == cpu_to_le32(EXT4_XATTR_MAGIC))
ei->i_state |= EXT3_STATE_XATTR; ei->i_state |= EXT4_STATE_XATTR;
} }
} else } else
ei->i_extra_isize = 0; ei->i_extra_isize = 0;
if (S_ISREG(inode->i_mode)) { if (S_ISREG(inode->i_mode)) {
inode->i_op = &ext3_file_inode_operations; inode->i_op = &ext4_file_inode_operations;
inode->i_fop = &ext3_file_operations; inode->i_fop = &ext4_file_operations;
ext3_set_aops(inode); ext4_set_aops(inode);
} else if (S_ISDIR(inode->i_mode)) { } else if (S_ISDIR(inode->i_mode)) {
inode->i_op = &ext3_dir_inode_operations; inode->i_op = &ext4_dir_inode_operations;
inode->i_fop = &ext3_dir_operations; inode->i_fop = &ext4_dir_operations;
} else if (S_ISLNK(inode->i_mode)) { } else if (S_ISLNK(inode->i_mode)) {
if (ext3_inode_is_fast_symlink(inode)) if (ext4_inode_is_fast_symlink(inode))
inode->i_op = &ext3_fast_symlink_inode_operations; inode->i_op = &ext4_fast_symlink_inode_operations;
else { else {
inode->i_op = &ext3_symlink_inode_operations; inode->i_op = &ext4_symlink_inode_operations;
ext3_set_aops(inode); ext4_set_aops(inode);
} }
} else { } else {
inode->i_op = &ext3_special_inode_operations; inode->i_op = &ext4_special_inode_operations;
if (raw_inode->i_block[0]) if (raw_inode->i_block[0])
init_special_inode(inode, inode->i_mode, init_special_inode(inode, inode->i_mode,
old_decode_dev(le32_to_cpu(raw_inode->i_block[0]))); old_decode_dev(le32_to_cpu(raw_inode->i_block[0])));
...@@ -2707,7 +2707,7 @@ void ext3_read_inode(struct inode * inode) ...@@ -2707,7 +2707,7 @@ void ext3_read_inode(struct inode * inode)
new_decode_dev(le32_to_cpu(raw_inode->i_block[1]))); new_decode_dev(le32_to_cpu(raw_inode->i_block[1])));
} }
brelse (iloc.bh); brelse (iloc.bh);
ext3_set_inode_flags(inode); ext4_set_inode_flags(inode);
return; return;
bad_inode: bad_inode:
...@@ -2722,19 +2722,19 @@ void ext3_read_inode(struct inode * inode) ...@@ -2722,19 +2722,19 @@ void ext3_read_inode(struct inode * inode)
* *
* The caller must have write access to iloc->bh. * The caller must have write access to iloc->bh.
*/ */
static int ext3_do_update_inode(handle_t *handle, static int ext4_do_update_inode(handle_t *handle,
struct inode *inode, struct inode *inode,
struct ext3_iloc *iloc) struct ext4_iloc *iloc)
{ {
struct ext3_inode *raw_inode = ext3_raw_inode(iloc); struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
struct ext3_inode_info *ei = EXT3_I(inode); struct ext4_inode_info *ei = EXT4_I(inode);
struct buffer_head *bh = iloc->bh; struct buffer_head *bh = iloc->bh;
int err = 0, rc, block; int err = 0, rc, block;
/* For fields not not tracking in the in-memory inode, /* For fields not not tracking in the in-memory inode,
* initialise them to zero for new inodes. */ * initialise them to zero for new inodes. */
if (ei->i_state & EXT3_STATE_NEW) if (ei->i_state & EXT4_STATE_NEW)
memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size); memset(raw_inode, 0, EXT4_SB(inode->i_sb)->s_inode_size);
raw_inode->i_mode = cpu_to_le16(inode->i_mode); raw_inode->i_mode = cpu_to_le16(inode->i_mode);
if(!(test_opt(inode->i_sb, NO_UID32))) { if(!(test_opt(inode->i_sb, NO_UID32))) {
...@@ -2769,7 +2769,7 @@ static int ext3_do_update_inode(handle_t *handle, ...@@ -2769,7 +2769,7 @@ static int ext3_do_update_inode(handle_t *handle,
raw_inode->i_blocks = cpu_to_le32(inode->i_blocks); raw_inode->i_blocks = cpu_to_le32(inode->i_blocks);
raw_inode->i_dtime = cpu_to_le32(ei->i_dtime); raw_inode->i_dtime = cpu_to_le32(ei->i_dtime);
raw_inode->i_flags = cpu_to_le32(ei->i_flags); raw_inode->i_flags = cpu_to_le32(ei->i_flags);
#ifdef EXT3_FRAGMENTS #ifdef EXT4_FRAGMENTS
raw_inode->i_faddr = cpu_to_le32(ei->i_faddr); raw_inode->i_faddr = cpu_to_le32(ei->i_faddr);
raw_inode->i_frag = ei->i_frag_no; raw_inode->i_frag = ei->i_frag_no;
raw_inode->i_fsize = ei->i_frag_size; raw_inode->i_fsize = ei->i_frag_size;
...@@ -2782,24 +2782,24 @@ static int ext3_do_update_inode(handle_t *handle, ...@@ -2782,24 +2782,24 @@ static int ext3_do_update_inode(handle_t *handle,
cpu_to_le32(ei->i_disksize >> 32); cpu_to_le32(ei->i_disksize >> 32);
if (ei->i_disksize > 0x7fffffffULL) { if (ei->i_disksize > 0x7fffffffULL) {
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
if (!EXT3_HAS_RO_COMPAT_FEATURE(sb, if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
EXT3_FEATURE_RO_COMPAT_LARGE_FILE) || EXT4_FEATURE_RO_COMPAT_LARGE_FILE) ||
EXT3_SB(sb)->s_es->s_rev_level == EXT4_SB(sb)->s_es->s_rev_level ==
cpu_to_le32(EXT3_GOOD_OLD_REV)) { cpu_to_le32(EXT4_GOOD_OLD_REV)) {
/* If this is the first large file /* If this is the first large file
* created, add a flag to the superblock. * created, add a flag to the superblock.
*/ */
err = ext3_journal_get_write_access(handle, err = ext4_journal_get_write_access(handle,
EXT3_SB(sb)->s_sbh); EXT4_SB(sb)->s_sbh);
if (err) if (err)
goto out_brelse; goto out_brelse;
ext3_update_dynamic_rev(sb); ext4_update_dynamic_rev(sb);
EXT3_SET_RO_COMPAT_FEATURE(sb, EXT4_SET_RO_COMPAT_FEATURE(sb,
EXT3_FEATURE_RO_COMPAT_LARGE_FILE); EXT4_FEATURE_RO_COMPAT_LARGE_FILE);
sb->s_dirt = 1; sb->s_dirt = 1;
handle->h_sync = 1; handle->h_sync = 1;
err = ext3_journal_dirty_metadata(handle, err = ext4_journal_dirty_metadata(handle,
EXT3_SB(sb)->s_sbh); EXT4_SB(sb)->s_sbh);
} }
} }
} }
...@@ -2815,26 +2815,26 @@ static int ext3_do_update_inode(handle_t *handle, ...@@ -2815,26 +2815,26 @@ static int ext3_do_update_inode(handle_t *handle,
cpu_to_le32(new_encode_dev(inode->i_rdev)); cpu_to_le32(new_encode_dev(inode->i_rdev));
raw_inode->i_block[2] = 0; raw_inode->i_block[2] = 0;
} }
} else for (block = 0; block < EXT3_N_BLOCKS; block++) } else for (block = 0; block < EXT4_N_BLOCKS; block++)
raw_inode->i_block[block] = ei->i_data[block]; raw_inode->i_block[block] = ei->i_data[block];
if (ei->i_extra_isize) if (ei->i_extra_isize)
raw_inode->i_extra_isize = cpu_to_le16(ei->i_extra_isize); raw_inode->i_extra_isize = cpu_to_le16(ei->i_extra_isize);
BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata"); BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
rc = ext3_journal_dirty_metadata(handle, bh); rc = ext4_journal_dirty_metadata(handle, bh);
if (!err) if (!err)
err = rc; err = rc;
ei->i_state &= ~EXT3_STATE_NEW; ei->i_state &= ~EXT4_STATE_NEW;
out_brelse: out_brelse:
brelse (bh); brelse (bh);
ext3_std_error(inode->i_sb, err); ext4_std_error(inode->i_sb, err);
return err; return err;
} }
/* /*
* ext3_write_inode() * ext4_write_inode()
* *
* We are called from a few places: * We are called from a few places:
* *
...@@ -2851,7 +2851,7 @@ static int ext3_do_update_inode(handle_t *handle, ...@@ -2851,7 +2851,7 @@ static int ext3_do_update_inode(handle_t *handle,
* *
* In all cases it is actually safe for us to return without doing anything, * In all cases it is actually safe for us to return without doing anything,
* because the inode has been copied into a raw inode buffer in * because the inode has been copied into a raw inode buffer in
* ext3_mark_inode_dirty(). This is a correctness thing for O_SYNC and for * ext4_mark_inode_dirty(). This is a correctness thing for O_SYNC and for
* knfsd. * knfsd.
* *
* Note that we are absolutely dependent upon all inode dirtiers doing the * Note that we are absolutely dependent upon all inode dirtiers doing the
...@@ -2868,12 +2868,12 @@ static int ext3_do_update_inode(handle_t *handle, ...@@ -2868,12 +2868,12 @@ static int ext3_do_update_inode(handle_t *handle,
* `stuff()' is running, and the new i_size will be lost. Plus the inode * `stuff()' is running, and the new i_size will be lost. Plus the inode
* will no longer be on the superblock's dirty inode list. * will no longer be on the superblock's dirty inode list.
*/ */
int ext3_write_inode(struct inode *inode, int wait) int ext4_write_inode(struct inode *inode, int wait)
{ {
if (current->flags & PF_MEMALLOC) if (current->flags & PF_MEMALLOC)
return 0; return 0;
if (ext3_journal_current_handle()) { if (ext4_journal_current_handle()) {
jbd_debug(0, "called recursively, non-PF_MEMALLOC!\n"); jbd_debug(0, "called recursively, non-PF_MEMALLOC!\n");
dump_stack(); dump_stack();
return -EIO; return -EIO;
...@@ -2882,11 +2882,11 @@ int ext3_write_inode(struct inode *inode, int wait) ...@@ -2882,11 +2882,11 @@ int ext3_write_inode(struct inode *inode, int wait)
if (!wait) if (!wait)
return 0; return 0;
return ext3_force_commit(inode->i_sb); return ext4_force_commit(inode->i_sb);
} }
/* /*
* ext3_setattr() * ext4_setattr()
* *
* Called from notify_change. * Called from notify_change.
* *
...@@ -2902,7 +2902,7 @@ int ext3_write_inode(struct inode *inode, int wait) ...@@ -2902,7 +2902,7 @@ int ext3_write_inode(struct inode *inode, int wait)
* *
* Called with inode->sem down. * Called with inode->sem down.
*/ */
int ext3_setattr(struct dentry *dentry, struct iattr *attr) int ext4_setattr(struct dentry *dentry, struct iattr *attr)
{ {
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
int error, rc = 0; int error, rc = 0;
...@@ -2918,15 +2918,15 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -2918,15 +2918,15 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
/* (user+group)*(old+new) structure, inode write (sb, /* (user+group)*(old+new) structure, inode write (sb,
* inode block, ? - but truncate inode update has it) */ * inode block, ? - but truncate inode update has it) */
handle = ext3_journal_start(inode, 2*(EXT3_QUOTA_INIT_BLOCKS(inode->i_sb)+ handle = ext4_journal_start(inode, 2*(EXT4_QUOTA_INIT_BLOCKS(inode->i_sb)+
EXT3_QUOTA_DEL_BLOCKS(inode->i_sb))+3); EXT4_QUOTA_DEL_BLOCKS(inode->i_sb))+3);
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
error = PTR_ERR(handle); error = PTR_ERR(handle);
goto err_out; goto err_out;
} }
error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0; error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
if (error) { if (error) {
ext3_journal_stop(handle); ext4_journal_stop(handle);
return error; return error;
} }
/* Update corresponding info in inode so that everything is in /* Update corresponding info in inode so that everything is in
...@@ -2935,41 +2935,41 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -2935,41 +2935,41 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
inode->i_uid = attr->ia_uid; inode->i_uid = attr->ia_uid;
if (attr->ia_valid & ATTR_GID) if (attr->ia_valid & ATTR_GID)
inode->i_gid = attr->ia_gid; inode->i_gid = attr->ia_gid;
error = ext3_mark_inode_dirty(handle, inode); error = ext4_mark_inode_dirty(handle, inode);
ext3_journal_stop(handle); ext4_journal_stop(handle);
} }
if (S_ISREG(inode->i_mode) && if (S_ISREG(inode->i_mode) &&
attr->ia_valid & ATTR_SIZE && attr->ia_size < inode->i_size) { attr->ia_valid & ATTR_SIZE && attr->ia_size < inode->i_size) {
handle_t *handle; handle_t *handle;
handle = ext3_journal_start(inode, 3); handle = ext4_journal_start(inode, 3);
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
error = PTR_ERR(handle); error = PTR_ERR(handle);
goto err_out; goto err_out;
} }
error = ext3_orphan_add(handle, inode); error = ext4_orphan_add(handle, inode);
EXT3_I(inode)->i_disksize = attr->ia_size; EXT4_I(inode)->i_disksize = attr->ia_size;
rc = ext3_mark_inode_dirty(handle, inode); rc = ext4_mark_inode_dirty(handle, inode);
if (!error) if (!error)
error = rc; error = rc;
ext3_journal_stop(handle); ext4_journal_stop(handle);
} }
rc = inode_setattr(inode, attr); rc = inode_setattr(inode, attr);
/* If inode_setattr's call to ext3_truncate failed to get a /* If inode_setattr's call to ext4_truncate failed to get a
* transaction handle at all, we need to clean up the in-core * transaction handle at all, we need to clean up the in-core
* orphan list manually. */ * orphan list manually. */
if (inode->i_nlink) if (inode->i_nlink)
ext3_orphan_del(NULL, inode); ext4_orphan_del(NULL, inode);
if (!rc && (ia_valid & ATTR_MODE)) if (!rc && (ia_valid & ATTR_MODE))
rc = ext3_acl_chmod(inode); rc = ext4_acl_chmod(inode);
err_out: err_out:
ext3_std_error(inode->i_sb, error); ext4_std_error(inode->i_sb, error);
if (!error) if (!error)
error = rc; error = rc;
return error; return error;
...@@ -2988,9 +2988,9 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -2988,9 +2988,9 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
* N+5 group descriptor summary blocks * N+5 group descriptor summary blocks
* 1 inode block * 1 inode block
* 1 superblock. * 1 superblock.
* 2 * EXT3_SINGLEDATA_TRANS_BLOCKS for the quote files * 2 * EXT4_SINGLEDATA_TRANS_BLOCKS for the quote files
* *
* 3 * (N + 5) + 2 + 2 * EXT3_SINGLEDATA_TRANS_BLOCKS * 3 * (N + 5) + 2 + 2 * EXT4_SINGLEDATA_TRANS_BLOCKS
* *
* With ordered or writeback data it's the same, less the N data blocks. * With ordered or writeback data it's the same, less the N data blocks.
* *
...@@ -3003,13 +3003,13 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -3003,13 +3003,13 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
* block and work out the exact number of indirects which are touched. Pah. * block and work out the exact number of indirects which are touched. Pah.
*/ */
static int ext3_writepage_trans_blocks(struct inode *inode) static int ext4_writepage_trans_blocks(struct inode *inode)
{ {
int bpp = ext3_journal_blocks_per_page(inode); int bpp = ext4_journal_blocks_per_page(inode);
int indirects = (EXT3_NDIR_BLOCKS % bpp) ? 5 : 3; int indirects = (EXT4_NDIR_BLOCKS % bpp) ? 5 : 3;
int ret; int ret;
if (ext3_should_journal_data(inode)) if (ext4_should_journal_data(inode))
ret = 3 * (bpp + indirects) + 2; ret = 3 * (bpp + indirects) + 2;
else else
ret = 2 * (bpp + indirects) + 2; ret = 2 * (bpp + indirects) + 2;
...@@ -3017,26 +3017,26 @@ static int ext3_writepage_trans_blocks(struct inode *inode) ...@@ -3017,26 +3017,26 @@ static int ext3_writepage_trans_blocks(struct inode *inode)
#ifdef CONFIG_QUOTA #ifdef CONFIG_QUOTA
/* We know that structure was already allocated during DQUOT_INIT so /* We know that structure was already allocated during DQUOT_INIT so
* we will be updating only the data blocks + inodes */ * we will be updating only the data blocks + inodes */
ret += 2*EXT3_QUOTA_TRANS_BLOCKS(inode->i_sb); ret += 2*EXT4_QUOTA_TRANS_BLOCKS(inode->i_sb);
#endif #endif
return ret; return ret;
} }
/* /*
* The caller must have previously called ext3_reserve_inode_write(). * The caller must have previously called ext4_reserve_inode_write().
* Give this, we know that the caller already has write access to iloc->bh. * Give this, we know that the caller already has write access to iloc->bh.
*/ */
int ext3_mark_iloc_dirty(handle_t *handle, int ext4_mark_iloc_dirty(handle_t *handle,
struct inode *inode, struct ext3_iloc *iloc) struct inode *inode, struct ext4_iloc *iloc)
{ {
int err = 0; int err = 0;
/* the do_update_inode consumes one bh->b_count */ /* the do_update_inode consumes one bh->b_count */
get_bh(iloc->bh); get_bh(iloc->bh);
/* ext3_do_update_inode() does journal_dirty_metadata */ /* ext4_do_update_inode() does journal_dirty_metadata */
err = ext3_do_update_inode(handle, inode, iloc); err = ext4_do_update_inode(handle, inode, iloc);
put_bh(iloc->bh); put_bh(iloc->bh);
return err; return err;
} }
...@@ -3047,22 +3047,22 @@ int ext3_mark_iloc_dirty(handle_t *handle, ...@@ -3047,22 +3047,22 @@ int ext3_mark_iloc_dirty(handle_t *handle,
*/ */
int int
ext3_reserve_inode_write(handle_t *handle, struct inode *inode, ext4_reserve_inode_write(handle_t *handle, struct inode *inode,
struct ext3_iloc *iloc) struct ext4_iloc *iloc)
{ {
int err = 0; int err = 0;
if (handle) { if (handle) {
err = ext3_get_inode_loc(inode, iloc); err = ext4_get_inode_loc(inode, iloc);
if (!err) { if (!err) {
BUFFER_TRACE(iloc->bh, "get_write_access"); BUFFER_TRACE(iloc->bh, "get_write_access");
err = ext3_journal_get_write_access(handle, iloc->bh); err = ext4_journal_get_write_access(handle, iloc->bh);
if (err) { if (err) {
brelse(iloc->bh); brelse(iloc->bh);
iloc->bh = NULL; iloc->bh = NULL;
} }
} }
} }
ext3_std_error(inode->i_sb, err); ext4_std_error(inode->i_sb, err);
return err; return err;
} }
...@@ -3087,20 +3087,20 @@ ext3_reserve_inode_write(handle_t *handle, struct inode *inode, ...@@ -3087,20 +3087,20 @@ ext3_reserve_inode_write(handle_t *handle, struct inode *inode,
* to do a write_super() to free up some memory. It has the desired * to do a write_super() to free up some memory. It has the desired
* effect. * effect.
*/ */
int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode) int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode)
{ {
struct ext3_iloc iloc; struct ext4_iloc iloc;
int err; int err;
might_sleep(); might_sleep();
err = ext3_reserve_inode_write(handle, inode, &iloc); err = ext4_reserve_inode_write(handle, inode, &iloc);
if (!err) if (!err)
err = ext3_mark_iloc_dirty(handle, inode, &iloc); err = ext4_mark_iloc_dirty(handle, inode, &iloc);
return err; return err;
} }
/* /*
* ext3_dirty_inode() is called from __mark_inode_dirty() * ext4_dirty_inode() is called from __mark_inode_dirty()
* *
* We're really interested in the case where a file is being extended. * We're really interested in the case where a file is being extended.
* i_size has been changed by generic_commit_write() and we thus need * 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,12 +3113,12 @@ int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode)
* so would cause a commit on atime updates, which we don't bother doing. * so would cause a commit on atime updates, which we don't bother doing.
* We handle synchronous inodes at the highest possible level. * We handle synchronous inodes at the highest possible level.
*/ */
void ext3_dirty_inode(struct inode *inode) void ext4_dirty_inode(struct inode *inode)
{ {
handle_t *current_handle = ext3_journal_current_handle(); handle_t *current_handle = ext4_journal_current_handle();
handle_t *handle; handle_t *handle;
handle = ext3_journal_start(inode, 2); handle = ext4_journal_start(inode, 2);
if (IS_ERR(handle)) if (IS_ERR(handle))
goto out; goto out;
if (current_handle && if (current_handle &&
...@@ -3129,9 +3129,9 @@ void ext3_dirty_inode(struct inode *inode) ...@@ -3129,9 +3129,9 @@ void ext3_dirty_inode(struct inode *inode)
} else { } else {
jbd_debug(5, "marking dirty. outer handle=%p\n", jbd_debug(5, "marking dirty. outer handle=%p\n",
current_handle); current_handle);
ext3_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
} }
ext3_journal_stop(handle); ext4_journal_stop(handle);
out: out:
return; return;
} }
...@@ -3140,32 +3140,32 @@ void ext3_dirty_inode(struct inode *inode) ...@@ -3140,32 +3140,32 @@ void ext3_dirty_inode(struct inode *inode)
/* /*
* Bind an inode's backing buffer_head into this transaction, to prevent * Bind an inode's backing buffer_head into this transaction, to prevent
* it from being flushed to disk early. Unlike * it from being flushed to disk early. Unlike
* ext3_reserve_inode_write, this leaves behind no bh reference and * ext4_reserve_inode_write, this leaves behind no bh reference and
* returns no iloc structure, so the caller needs to repeat the iloc * returns no iloc structure, so the caller needs to repeat the iloc
* lookup to mark the inode dirty later. * lookup to mark the inode dirty later.
*/ */
static int ext3_pin_inode(handle_t *handle, struct inode *inode) static int ext4_pin_inode(handle_t *handle, struct inode *inode)
{ {
struct ext3_iloc iloc; struct ext4_iloc iloc;
int err = 0; int err = 0;
if (handle) { if (handle) {
err = ext3_get_inode_loc(inode, &iloc); err = ext4_get_inode_loc(inode, &iloc);
if (!err) { if (!err) {
BUFFER_TRACE(iloc.bh, "get_write_access"); BUFFER_TRACE(iloc.bh, "get_write_access");
err = journal_get_write_access(handle, iloc.bh); err = journal_get_write_access(handle, iloc.bh);
if (!err) if (!err)
err = ext3_journal_dirty_metadata(handle, err = ext4_journal_dirty_metadata(handle,
iloc.bh); iloc.bh);
brelse(iloc.bh); brelse(iloc.bh);
} }
} }
ext3_std_error(inode->i_sb, err); ext4_std_error(inode->i_sb, err);
return err; return err;
} }
#endif #endif
int ext3_change_inode_journal_flag(struct inode *inode, int val) int ext4_change_inode_journal_flag(struct inode *inode, int val)
{ {
journal_t *journal; journal_t *journal;
handle_t *handle; handle_t *handle;
...@@ -3181,7 +3181,7 @@ int ext3_change_inode_journal_flag(struct inode *inode, int val) ...@@ -3181,7 +3181,7 @@ int ext3_change_inode_journal_flag(struct inode *inode, int val)
* nobody is changing anything. * nobody is changing anything.
*/ */
journal = EXT3_JOURNAL(inode); journal = EXT4_JOURNAL(inode);
if (is_journal_aborted(journal) || IS_RDONLY(inode)) if (is_journal_aborted(journal) || IS_RDONLY(inode))
return -EROFS; return -EROFS;
...@@ -3197,23 +3197,23 @@ int ext3_change_inode_journal_flag(struct inode *inode, int val) ...@@ -3197,23 +3197,23 @@ int ext3_change_inode_journal_flag(struct inode *inode, int val)
*/ */
if (val) if (val)
EXT3_I(inode)->i_flags |= EXT3_JOURNAL_DATA_FL; EXT4_I(inode)->i_flags |= EXT4_JOURNAL_DATA_FL;
else else
EXT3_I(inode)->i_flags &= ~EXT3_JOURNAL_DATA_FL; EXT4_I(inode)->i_flags &= ~EXT4_JOURNAL_DATA_FL;
ext3_set_aops(inode); ext4_set_aops(inode);
journal_unlock_updates(journal); journal_unlock_updates(journal);
/* Finally we can mark the inode as dirty. */ /* Finally we can mark the inode as dirty. */
handle = ext3_journal_start(inode, 1); handle = ext4_journal_start(inode, 1);
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
err = ext3_mark_inode_dirty(handle, inode); err = ext4_mark_inode_dirty(handle, inode);
handle->h_sync = 1; handle->h_sync = 1;
ext3_journal_stop(handle); ext4_journal_stop(handle);
ext3_std_error(inode->i_sb, err); ext4_std_error(inode->i_sb, err);
return err; return err;
} }
/* /*
* linux/fs/ext3/ioctl.c * linux/fs/ext4/ioctl.c
* *
* Copyright (C) 1993, 1994, 1995 * Copyright (C) 1993, 1994, 1995
* Remy Card (card@masi.ibp.fr) * Remy Card (card@masi.ibp.fr)
...@@ -10,30 +10,30 @@ ...@@ -10,30 +10,30 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/jbd.h> #include <linux/jbd.h>
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#include <linux/ext3_jbd.h> #include <linux/ext4_jbd.h>
#include <linux/time.h> #include <linux/time.h>
#include <linux/compat.h> #include <linux/compat.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, int ext4_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
unsigned long arg) unsigned long arg)
{ {
struct ext3_inode_info *ei = EXT3_I(inode); struct ext4_inode_info *ei = EXT4_I(inode);
unsigned int flags; unsigned int flags;
unsigned short rsv_window_size; unsigned short rsv_window_size;
ext3_debug ("cmd = %u, arg = %lu\n", cmd, arg); ext4_debug ("cmd = %u, arg = %lu\n", cmd, arg);
switch (cmd) { switch (cmd) {
case EXT3_IOC_GETFLAGS: case EXT4_IOC_GETFLAGS:
flags = ei->i_flags & EXT3_FL_USER_VISIBLE; flags = ei->i_flags & EXT4_FL_USER_VISIBLE;
return put_user(flags, (int __user *) arg); return put_user(flags, (int __user *) arg);
case EXT3_IOC_SETFLAGS: { case EXT4_IOC_SETFLAGS: {
handle_t *handle = NULL; handle_t *handle = NULL;
int err; int err;
struct ext3_iloc iloc; struct ext4_iloc iloc;
unsigned int oldflags; unsigned int oldflags;
unsigned int jflag; unsigned int jflag;
...@@ -47,13 +47,13 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, ...@@ -47,13 +47,13 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
return -EFAULT; return -EFAULT;
if (!S_ISDIR(inode->i_mode)) if (!S_ISDIR(inode->i_mode))
flags &= ~EXT3_DIRSYNC_FL; flags &= ~EXT4_DIRSYNC_FL;
mutex_lock(&inode->i_mutex); mutex_lock(&inode->i_mutex);
oldflags = ei->i_flags; oldflags = ei->i_flags;
/* The JOURNAL_DATA flag is modifiable only by root */ /* The JOURNAL_DATA flag is modifiable only by root */
jflag = flags & EXT3_JOURNAL_DATA_FL; jflag = flags & EXT4_JOURNAL_DATA_FL;
/* /*
* The IMMUTABLE and APPEND_ONLY flags can only be changed by * 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,7 +61,7 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
* *
* This test looks nicer. Thanks to Pauline Middelink * This test looks nicer. Thanks to Pauline Middelink
*/ */
if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) { if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
if (!capable(CAP_LINUX_IMMUTABLE)) { if (!capable(CAP_LINUX_IMMUTABLE)) {
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
return -EPERM; return -EPERM;
...@@ -72,7 +72,7 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, ...@@ -72,7 +72,7 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
* The JOURNAL_DATA flag can only be changed by * The JOURNAL_DATA flag can only be changed by
* the relevant capability. * the relevant capability.
*/ */
if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL)) { if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) {
if (!capable(CAP_SYS_RESOURCE)) { if (!capable(CAP_SYS_RESOURCE)) {
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
return -EPERM; return -EPERM;
...@@ -80,44 +80,44 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, ...@@ -80,44 +80,44 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
} }
handle = ext3_journal_start(inode, 1); handle = ext4_journal_start(inode, 1);
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
return PTR_ERR(handle); return PTR_ERR(handle);
} }
if (IS_SYNC(inode)) if (IS_SYNC(inode))
handle->h_sync = 1; handle->h_sync = 1;
err = ext3_reserve_inode_write(handle, inode, &iloc); err = ext4_reserve_inode_write(handle, inode, &iloc);
if (err) if (err)
goto flags_err; goto flags_err;
flags = flags & EXT3_FL_USER_MODIFIABLE; flags = flags & EXT4_FL_USER_MODIFIABLE;
flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE; flags |= oldflags & ~EXT4_FL_USER_MODIFIABLE;
ei->i_flags = flags; ei->i_flags = flags;
ext3_set_inode_flags(inode); ext4_set_inode_flags(inode);
inode->i_ctime = CURRENT_TIME_SEC; inode->i_ctime = CURRENT_TIME_SEC;
err = ext3_mark_iloc_dirty(handle, inode, &iloc); err = ext4_mark_iloc_dirty(handle, inode, &iloc);
flags_err: flags_err:
ext3_journal_stop(handle); ext4_journal_stop(handle);
if (err) { if (err) {
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
return err; return err;
} }
if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL)) if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL))
err = ext3_change_inode_journal_flag(inode, jflag); err = ext4_change_inode_journal_flag(inode, jflag);
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
return err; return err;
} }
case EXT3_IOC_GETVERSION: case EXT4_IOC_GETVERSION:
case EXT3_IOC_GETVERSION_OLD: case EXT4_IOC_GETVERSION_OLD:
return put_user(inode->i_generation, (int __user *) arg); return put_user(inode->i_generation, (int __user *) arg);
case EXT3_IOC_SETVERSION: case EXT4_IOC_SETVERSION:
case EXT3_IOC_SETVERSION_OLD: { case EXT4_IOC_SETVERSION_OLD: {
handle_t *handle; handle_t *handle;
struct ext3_iloc iloc; struct ext4_iloc iloc;
__u32 generation; __u32 generation;
int err; int err;
...@@ -128,20 +128,20 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, ...@@ -128,20 +128,20 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
if (get_user(generation, (int __user *) arg)) if (get_user(generation, (int __user *) arg))
return -EFAULT; return -EFAULT;
handle = ext3_journal_start(inode, 1); handle = ext4_journal_start(inode, 1);
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
err = ext3_reserve_inode_write(handle, inode, &iloc); err = ext4_reserve_inode_write(handle, inode, &iloc);
if (err == 0) { if (err == 0) {
inode->i_ctime = CURRENT_TIME_SEC; inode->i_ctime = CURRENT_TIME_SEC;
inode->i_generation = generation; inode->i_generation = generation;
err = ext3_mark_iloc_dirty(handle, inode, &iloc); err = ext4_mark_iloc_dirty(handle, inode, &iloc);
} }
ext3_journal_stop(handle); ext4_journal_stop(handle);
return err; return err;
} }
#ifdef CONFIG_JBD_DEBUG #ifdef CONFIG_JBD_DEBUG
case EXT3_IOC_WAIT_FOR_READONLY: case EXT4_IOC_WAIT_FOR_READONLY:
/* /*
* This is racy - by the time we're woken up and running, * This is racy - by the time we're woken up and running,
* the superblock could be released. And the module could * the superblock could be released. And the module could
...@@ -155,16 +155,16 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, ...@@ -155,16 +155,16 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
int ret = 0; int ret = 0;
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait); add_wait_queue(&EXT4_SB(sb)->ro_wait_queue, &wait);
if (timer_pending(&EXT3_SB(sb)->turn_ro_timer)) { if (timer_pending(&EXT4_SB(sb)->turn_ro_timer)) {
schedule(); schedule();
ret = 1; ret = 1;
} }
remove_wait_queue(&EXT3_SB(sb)->ro_wait_queue, &wait); remove_wait_queue(&EXT4_SB(sb)->ro_wait_queue, &wait);
return ret; return ret;
} }
#endif #endif
case EXT3_IOC_GETRSVSZ: case EXT4_IOC_GETRSVSZ:
if (test_opt(inode->i_sb, RESERVATION) if (test_opt(inode->i_sb, RESERVATION)
&& S_ISREG(inode->i_mode) && S_ISREG(inode->i_mode)
&& ei->i_block_alloc_info) { && ei->i_block_alloc_info) {
...@@ -172,7 +172,7 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, ...@@ -172,7 +172,7 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
return put_user(rsv_window_size, (int __user *)arg); return put_user(rsv_window_size, (int __user *)arg);
} }
return -ENOTTY; return -ENOTTY;
case EXT3_IOC_SETRSVSZ: { case EXT4_IOC_SETRSVSZ: {
if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode)) if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
return -ENOTTY; return -ENOTTY;
...@@ -186,8 +186,8 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, ...@@ -186,8 +186,8 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
if (get_user(rsv_window_size, (int __user *)arg)) if (get_user(rsv_window_size, (int __user *)arg))
return -EFAULT; return -EFAULT;
if (rsv_window_size > EXT3_MAX_RESERVE_BLOCKS) if (rsv_window_size > EXT4_MAX_RESERVE_BLOCKS)
rsv_window_size = EXT3_MAX_RESERVE_BLOCKS; rsv_window_size = EXT4_MAX_RESERVE_BLOCKS;
/* /*
* need to allocate reservation structure for this inode * need to allocate reservation structure for this inode
...@@ -195,17 +195,17 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, ...@@ -195,17 +195,17 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
*/ */
mutex_lock(&ei->truncate_mutex); mutex_lock(&ei->truncate_mutex);
if (!ei->i_block_alloc_info) if (!ei->i_block_alloc_info)
ext3_init_block_alloc_info(inode); ext4_init_block_alloc_info(inode);
if (ei->i_block_alloc_info){ if (ei->i_block_alloc_info){
struct ext3_reserve_window_node *rsv = &ei->i_block_alloc_info->rsv_window_node; struct ext4_reserve_window_node *rsv = &ei->i_block_alloc_info->rsv_window_node;
rsv->rsv_goal_size = rsv_window_size; rsv->rsv_goal_size = rsv_window_size;
} }
mutex_unlock(&ei->truncate_mutex); mutex_unlock(&ei->truncate_mutex);
return 0; return 0;
} }
case EXT3_IOC_GROUP_EXTEND: { case EXT4_IOC_GROUP_EXTEND: {
ext3_fsblk_t n_blocks_count; ext4_fsblk_t n_blocks_count;
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
int err; int err;
...@@ -218,15 +218,15 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, ...@@ -218,15 +218,15 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
if (get_user(n_blocks_count, (__u32 __user *)arg)) if (get_user(n_blocks_count, (__u32 __user *)arg))
return -EFAULT; return -EFAULT;
err = ext3_group_extend(sb, EXT3_SB(sb)->s_es, n_blocks_count); err = ext4_group_extend(sb, EXT4_SB(sb)->s_es, n_blocks_count);
journal_lock_updates(EXT3_SB(sb)->s_journal); journal_lock_updates(EXT4_SB(sb)->s_journal);
journal_flush(EXT3_SB(sb)->s_journal); journal_flush(EXT4_SB(sb)->s_journal);
journal_unlock_updates(EXT3_SB(sb)->s_journal); journal_unlock_updates(EXT4_SB(sb)->s_journal);
return err; return err;
} }
case EXT3_IOC_GROUP_ADD: { case EXT4_IOC_GROUP_ADD: {
struct ext3_new_group_data input; struct ext4_new_group_data input;
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
int err; int err;
...@@ -236,14 +236,14 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, ...@@ -236,14 +236,14 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
if (IS_RDONLY(inode)) if (IS_RDONLY(inode))
return -EROFS; return -EROFS;
if (copy_from_user(&input, (struct ext3_new_group_input __user *)arg, if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
sizeof(input))) sizeof(input)))
return -EFAULT; return -EFAULT;
err = ext3_group_add(sb, &input); err = ext4_group_add(sb, &input);
journal_lock_updates(EXT3_SB(sb)->s_journal); journal_lock_updates(EXT4_SB(sb)->s_journal);
journal_flush(EXT3_SB(sb)->s_journal); journal_flush(EXT4_SB(sb)->s_journal);
journal_unlock_updates(EXT3_SB(sb)->s_journal); journal_unlock_updates(EXT4_SB(sb)->s_journal);
return err; return err;
} }
...@@ -255,52 +255,52 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, ...@@ -255,52 +255,52 @@ int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
} }
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
long ext3_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{ {
struct inode *inode = file->f_dentry->d_inode; struct inode *inode = file->f_dentry->d_inode;
int ret; int ret;
/* These are just misnamed, they actually get/put from/to user an int */ /* These are just misnamed, they actually get/put from/to user an int */
switch (cmd) { switch (cmd) {
case EXT3_IOC32_GETFLAGS: case EXT4_IOC32_GETFLAGS:
cmd = EXT3_IOC_GETFLAGS; cmd = EXT4_IOC_GETFLAGS;
break; break;
case EXT3_IOC32_SETFLAGS: case EXT4_IOC32_SETFLAGS:
cmd = EXT3_IOC_SETFLAGS; cmd = EXT4_IOC_SETFLAGS;
break; break;
case EXT3_IOC32_GETVERSION: case EXT4_IOC32_GETVERSION:
cmd = EXT3_IOC_GETVERSION; cmd = EXT4_IOC_GETVERSION;
break; break;
case EXT3_IOC32_SETVERSION: case EXT4_IOC32_SETVERSION:
cmd = EXT3_IOC_SETVERSION; cmd = EXT4_IOC_SETVERSION;
break; break;
case EXT3_IOC32_GROUP_EXTEND: case EXT4_IOC32_GROUP_EXTEND:
cmd = EXT3_IOC_GROUP_EXTEND; cmd = EXT4_IOC_GROUP_EXTEND;
break; break;
case EXT3_IOC32_GETVERSION_OLD: case EXT4_IOC32_GETVERSION_OLD:
cmd = EXT3_IOC_GETVERSION_OLD; cmd = EXT4_IOC_GETVERSION_OLD;
break; break;
case EXT3_IOC32_SETVERSION_OLD: case EXT4_IOC32_SETVERSION_OLD:
cmd = EXT3_IOC_SETVERSION_OLD; cmd = EXT4_IOC_SETVERSION_OLD;
break; break;
#ifdef CONFIG_JBD_DEBUG #ifdef CONFIG_JBD_DEBUG
case EXT3_IOC32_WAIT_FOR_READONLY: case EXT4_IOC32_WAIT_FOR_READONLY:
cmd = EXT3_IOC_WAIT_FOR_READONLY; cmd = EXT4_IOC_WAIT_FOR_READONLY;
break; break;
#endif #endif
case EXT3_IOC32_GETRSVSZ: case EXT4_IOC32_GETRSVSZ:
cmd = EXT3_IOC_GETRSVSZ; cmd = EXT4_IOC_GETRSVSZ;
break; break;
case EXT3_IOC32_SETRSVSZ: case EXT4_IOC32_SETRSVSZ:
cmd = EXT3_IOC_SETRSVSZ; cmd = EXT4_IOC_SETRSVSZ;
break; break;
case EXT3_IOC_GROUP_ADD: case EXT4_IOC_GROUP_ADD:
break; break;
default: default:
return -ENOIOCTLCMD; return -ENOIOCTLCMD;
} }
lock_kernel(); lock_kernel();
ret = ext3_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg)); ret = ext4_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));
unlock_kernel(); unlock_kernel();
return ret; return ret;
} }
......
/* /*
* linux/fs/ext3/namei.c * linux/fs/ext4/namei.c
* *
* Copyright (C) 1992, 1993, 1994, 1995 * Copyright (C) 1992, 1993, 1994, 1995
* Remy Card (card@masi.ibp.fr) * Remy Card (card@masi.ibp.fr)
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <linux/jbd.h> #include <linux/jbd.h>
#include <linux/time.h> #include <linux/time.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#include <linux/ext3_jbd.h> #include <linux/ext4_jbd.h>
#include <linux/fcntl.h> #include <linux/fcntl.h>
#include <linux/stat.h> #include <linux/stat.h>
#include <linux/string.h> #include <linux/string.h>
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
#define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS) #define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS)
#define NAMEI_RA_INDEX(c,b) (((c) * NAMEI_RA_BLOCKS) + (b)) #define NAMEI_RA_INDEX(c,b) (((c) * NAMEI_RA_BLOCKS) + (b))
static struct buffer_head *ext3_append(handle_t *handle, static struct buffer_head *ext4_append(handle_t *handle,
struct inode *inode, struct inode *inode,
u32 *block, int *err) u32 *block, int *err)
{ {
...@@ -58,10 +58,10 @@ static struct buffer_head *ext3_append(handle_t *handle, ...@@ -58,10 +58,10 @@ static struct buffer_head *ext3_append(handle_t *handle,
*block = inode->i_size >> inode->i_sb->s_blocksize_bits; *block = inode->i_size >> inode->i_sb->s_blocksize_bits;
if ((bh = ext3_bread(handle, inode, *block, 1, err))) { if ((bh = ext4_bread(handle, inode, *block, 1, err))) {
inode->i_size += inode->i_sb->s_blocksize; inode->i_size += inode->i_sb->s_blocksize;
EXT3_I(inode)->i_disksize = inode->i_size; EXT4_I(inode)->i_disksize = inode->i_size;
ext3_journal_get_write_access(handle,bh); ext4_journal_get_write_access(handle,bh);
} }
return bh; return bh;
} }
...@@ -144,7 +144,7 @@ struct dx_map_entry ...@@ -144,7 +144,7 @@ struct dx_map_entry
u32 offs; u32 offs;
}; };
#ifdef CONFIG_EXT3_INDEX #ifdef CONFIG_EXT4_INDEX
static inline unsigned dx_get_block (struct dx_entry *entry); static inline unsigned dx_get_block (struct dx_entry *entry);
static void dx_set_block (struct dx_entry *entry, unsigned value); static void dx_set_block (struct dx_entry *entry, unsigned value);
static inline unsigned dx_get_hash (struct dx_entry *entry); static inline unsigned dx_get_hash (struct dx_entry *entry);
...@@ -161,20 +161,20 @@ static struct dx_frame *dx_probe(struct dentry *dentry, ...@@ -161,20 +161,20 @@ static struct dx_frame *dx_probe(struct dentry *dentry,
struct dx_frame *frame, struct dx_frame *frame,
int *err); int *err);
static void dx_release (struct dx_frame *frames); static void dx_release (struct dx_frame *frames);
static int dx_make_map (struct ext3_dir_entry_2 *de, int size, static int dx_make_map (struct ext4_dir_entry_2 *de, int size,
struct dx_hash_info *hinfo, struct dx_map_entry map[]); struct dx_hash_info *hinfo, struct dx_map_entry map[]);
static void dx_sort_map(struct dx_map_entry *map, unsigned count); static void dx_sort_map(struct dx_map_entry *map, unsigned count);
static struct ext3_dir_entry_2 *dx_move_dirents (char *from, char *to, static struct ext4_dir_entry_2 *dx_move_dirents (char *from, char *to,
struct dx_map_entry *offsets, int count); struct dx_map_entry *offsets, int count);
static struct ext3_dir_entry_2* dx_pack_dirents (char *base, int size); static struct ext4_dir_entry_2* dx_pack_dirents (char *base, int size);
static void dx_insert_block (struct dx_frame *frame, u32 hash, u32 block); static void dx_insert_block (struct dx_frame *frame, u32 hash, u32 block);
static int ext3_htree_next_block(struct inode *dir, __u32 hash, static int ext4_htree_next_block(struct inode *dir, __u32 hash,
struct dx_frame *frame, struct dx_frame *frame,
struct dx_frame *frames, struct dx_frame *frames,
__u32 *start_hash); __u32 *start_hash);
static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry, static struct buffer_head * ext4_dx_find_entry(struct dentry *dentry,
struct ext3_dir_entry_2 **res_dir, int *err); struct ext4_dir_entry_2 **res_dir, int *err);
static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
struct inode *inode); struct inode *inode);
/* /*
...@@ -224,14 +224,14 @@ static inline void dx_set_limit (struct dx_entry *entries, unsigned value) ...@@ -224,14 +224,14 @@ static inline void dx_set_limit (struct dx_entry *entries, unsigned value)
static inline unsigned dx_root_limit (struct inode *dir, unsigned infosize) static inline unsigned dx_root_limit (struct inode *dir, unsigned infosize)
{ {
unsigned entry_space = dir->i_sb->s_blocksize - EXT3_DIR_REC_LEN(1) - unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(1) -
EXT3_DIR_REC_LEN(2) - infosize; EXT4_DIR_REC_LEN(2) - infosize;
return 0? 20: entry_space / sizeof(struct dx_entry); return 0? 20: entry_space / sizeof(struct dx_entry);
} }
static inline unsigned dx_node_limit (struct inode *dir) static inline unsigned dx_node_limit (struct inode *dir)
{ {
unsigned entry_space = dir->i_sb->s_blocksize - EXT3_DIR_REC_LEN(0); unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(0);
return 0? 22: entry_space / sizeof(struct dx_entry); return 0? 22: entry_space / sizeof(struct dx_entry);
} }
...@@ -257,7 +257,7 @@ struct stats ...@@ -257,7 +257,7 @@ struct stats
unsigned bcount; unsigned bcount;
}; };
static struct stats dx_show_leaf(struct dx_hash_info *hinfo, struct ext3_dir_entry_2 *de, static struct stats dx_show_leaf(struct dx_hash_info *hinfo, struct ext4_dir_entry_2 *de,
int size, int show_names) int size, int show_names)
{ {
unsigned names = 0, space = 0; 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,14 +274,14 @@ static struct stats dx_show_leaf(struct dx_hash_info *hinfo, struct ext3_dir_ent
int len = de->name_len; int len = de->name_len;
char *name = de->name; char *name = de->name;
while (len--) printk("%c", *name++); while (len--) printk("%c", *name++);
ext3fs_dirhash(de->name, de->name_len, &h); ext4fs_dirhash(de->name, de->name_len, &h);
printk(":%x.%u ", h.hash, printk(":%x.%u ", h.hash,
((char *) de - base)); ((char *) de - base));
} }
space += EXT3_DIR_REC_LEN(de->name_len); space += EXT4_DIR_REC_LEN(de->name_len);
names++; names++;
} }
de = (struct ext3_dir_entry_2 *) ((char *) de + le16_to_cpu(de->rec_len)); de = (struct ext4_dir_entry_2 *) ((char *) de + le16_to_cpu(de->rec_len));
} }
printk("(%i)\n", names); printk("(%i)\n", names);
return (struct stats) { names, space, 1 }; return (struct stats) { names, space, 1 };
...@@ -302,10 +302,10 @@ struct stats dx_show_entries(struct dx_hash_info *hinfo, struct inode *dir, ...@@ -302,10 +302,10 @@ struct stats dx_show_entries(struct dx_hash_info *hinfo, struct inode *dir,
u32 range = i < count - 1? (dx_get_hash(entries + 1) - hash): ~hash; u32 range = i < count - 1? (dx_get_hash(entries + 1) - hash): ~hash;
struct stats stats; struct stats stats;
printk("%s%3u:%03u hash %8x/%8x ",levels?"":" ", i, block, hash, range); printk("%s%3u:%03u hash %8x/%8x ",levels?"":" ", i, block, hash, range);
if (!(bh = ext3_bread (NULL,dir, block, 0,&err))) continue; if (!(bh = ext4_bread (NULL,dir, block, 0,&err))) continue;
stats = levels? stats = levels?
dx_show_entries(hinfo, dir, ((struct dx_node *) bh->b_data)->entries, levels - 1): dx_show_entries(hinfo, dir, ((struct dx_node *) bh->b_data)->entries, levels - 1):
dx_show_leaf(hinfo, (struct ext3_dir_entry_2 *) bh->b_data, blocksize, 0); dx_show_leaf(hinfo, (struct ext4_dir_entry_2 *) bh->b_data, blocksize, 0);
names += stats.names; names += stats.names;
space += stats.space; space += stats.space;
bcount += stats.bcount; bcount += stats.bcount;
...@@ -341,13 +341,13 @@ dx_probe(struct dentry *dentry, struct inode *dir, ...@@ -341,13 +341,13 @@ dx_probe(struct dentry *dentry, struct inode *dir,
frame->bh = NULL; frame->bh = NULL;
if (dentry) if (dentry)
dir = dentry->d_parent->d_inode; dir = dentry->d_parent->d_inode;
if (!(bh = ext3_bread (NULL,dir, 0, 0, err))) if (!(bh = ext4_bread (NULL,dir, 0, 0, err)))
goto fail; goto fail;
root = (struct dx_root *) bh->b_data; root = (struct dx_root *) bh->b_data;
if (root->info.hash_version != DX_HASH_TEA && if (root->info.hash_version != DX_HASH_TEA &&
root->info.hash_version != DX_HASH_HALF_MD4 && root->info.hash_version != DX_HASH_HALF_MD4 &&
root->info.hash_version != DX_HASH_LEGACY) { root->info.hash_version != DX_HASH_LEGACY) {
ext3_warning(dir->i_sb, __FUNCTION__, ext4_warning(dir->i_sb, __FUNCTION__,
"Unrecognised inode hash code %d", "Unrecognised inode hash code %d",
root->info.hash_version); root->info.hash_version);
brelse(bh); brelse(bh);
...@@ -355,13 +355,13 @@ dx_probe(struct dentry *dentry, struct inode *dir, ...@@ -355,13 +355,13 @@ dx_probe(struct dentry *dentry, struct inode *dir,
goto fail; goto fail;
} }
hinfo->hash_version = root->info.hash_version; hinfo->hash_version = root->info.hash_version;
hinfo->seed = EXT3_SB(dir->i_sb)->s_hash_seed; hinfo->seed = EXT4_SB(dir->i_sb)->s_hash_seed;
if (dentry) if (dentry)
ext3fs_dirhash(dentry->d_name.name, dentry->d_name.len, hinfo); ext4fs_dirhash(dentry->d_name.name, dentry->d_name.len, hinfo);
hash = hinfo->hash; hash = hinfo->hash;
if (root->info.unused_flags & 1) { if (root->info.unused_flags & 1) {
ext3_warning(dir->i_sb, __FUNCTION__, ext4_warning(dir->i_sb, __FUNCTION__,
"Unimplemented inode hash flags: %#06x", "Unimplemented inode hash flags: %#06x",
root->info.unused_flags); root->info.unused_flags);
brelse(bh); brelse(bh);
...@@ -370,7 +370,7 @@ dx_probe(struct dentry *dentry, struct inode *dir, ...@@ -370,7 +370,7 @@ dx_probe(struct dentry *dentry, struct inode *dir,
} }
if ((indirect = root->info.indirect_levels) > 1) { if ((indirect = root->info.indirect_levels) > 1) {
ext3_warning(dir->i_sb, __FUNCTION__, ext4_warning(dir->i_sb, __FUNCTION__,
"Unimplemented inode hash depth: %#06x", "Unimplemented inode hash depth: %#06x",
root->info.indirect_levels); root->info.indirect_levels);
brelse(bh); brelse(bh);
...@@ -421,7 +421,7 @@ dx_probe(struct dentry *dentry, struct inode *dir, ...@@ -421,7 +421,7 @@ dx_probe(struct dentry *dentry, struct inode *dir,
frame->entries = entries; frame->entries = entries;
frame->at = at; frame->at = at;
if (!indirect--) return frame; if (!indirect--) return frame;
if (!(bh = ext3_bread (NULL,dir, dx_get_block(at), 0, err))) if (!(bh = ext4_bread (NULL,dir, dx_get_block(at), 0, err)))
goto fail2; goto fail2;
at = entries = ((struct dx_node *) bh->b_data)->entries; at = entries = ((struct dx_node *) bh->b_data)->entries;
assert (dx_get_limit(entries) == dx_node_limit (dir)); assert (dx_get_limit(entries) == dx_node_limit (dir));
...@@ -463,7 +463,7 @@ static void dx_release (struct dx_frame *frames) ...@@ -463,7 +463,7 @@ static void dx_release (struct dx_frame *frames)
* If start_hash is non-null, it will be filled in with the starting * If start_hash is non-null, it will be filled in with the starting
* hash of the next page. * hash of the next page.
*/ */
static int ext3_htree_next_block(struct inode *dir, __u32 hash, static int ext4_htree_next_block(struct inode *dir, __u32 hash,
struct dx_frame *frame, struct dx_frame *frame,
struct dx_frame *frames, struct dx_frame *frames,
__u32 *start_hash) __u32 *start_hash)
...@@ -509,7 +509,7 @@ static int ext3_htree_next_block(struct inode *dir, __u32 hash, ...@@ -509,7 +509,7 @@ static int ext3_htree_next_block(struct inode *dir, __u32 hash,
* block so no check is necessary * block so no check is necessary
*/ */
while (num_frames--) { while (num_frames--) {
if (!(bh = ext3_bread(NULL, dir, dx_get_block(p->at), if (!(bh = ext4_bread(NULL, dir, dx_get_block(p->at),
0, &err))) 0, &err)))
return err; /* Failure */ return err; /* Failure */
p++; p++;
...@@ -524,9 +524,9 @@ static int ext3_htree_next_block(struct inode *dir, __u32 hash, ...@@ -524,9 +524,9 @@ static int ext3_htree_next_block(struct inode *dir, __u32 hash,
/* /*
* p is at least 6 bytes before the end of page * p is at least 6 bytes before the end of page
*/ */
static inline struct ext3_dir_entry_2 *ext3_next_entry(struct ext3_dir_entry_2 *p) static inline struct ext4_dir_entry_2 *ext4_next_entry(struct ext4_dir_entry_2 *p)
{ {
return (struct ext3_dir_entry_2 *)((char*)p + le16_to_cpu(p->rec_len)); return (struct ext4_dir_entry_2 *)((char*)p + le16_to_cpu(p->rec_len));
} }
/* /*
...@@ -540,26 +540,26 @@ static int htree_dirblock_to_tree(struct file *dir_file, ...@@ -540,26 +540,26 @@ static int htree_dirblock_to_tree(struct file *dir_file,
__u32 start_hash, __u32 start_minor_hash) __u32 start_hash, __u32 start_minor_hash)
{ {
struct buffer_head *bh; struct buffer_head *bh;
struct ext3_dir_entry_2 *de, *top; struct ext4_dir_entry_2 *de, *top;
int err, count = 0; int err, count = 0;
dxtrace(printk("In htree dirblock_to_tree: block %d\n", block)); dxtrace(printk("In htree dirblock_to_tree: block %d\n", block));
if (!(bh = ext3_bread (NULL, dir, block, 0, &err))) if (!(bh = ext4_bread (NULL, dir, block, 0, &err)))
return err; return err;
de = (struct ext3_dir_entry_2 *) bh->b_data; de = (struct ext4_dir_entry_2 *) bh->b_data;
top = (struct ext3_dir_entry_2 *) ((char *) de + top = (struct ext4_dir_entry_2 *) ((char *) de +
dir->i_sb->s_blocksize - dir->i_sb->s_blocksize -
EXT3_DIR_REC_LEN(0)); EXT4_DIR_REC_LEN(0));
for (; de < top; de = ext3_next_entry(de)) { for (; de < top; de = ext4_next_entry(de)) {
ext3fs_dirhash(de->name, de->name_len, hinfo); ext4fs_dirhash(de->name, de->name_len, hinfo);
if ((hinfo->hash < start_hash) || if ((hinfo->hash < start_hash) ||
((hinfo->hash == start_hash) && ((hinfo->hash == start_hash) &&
(hinfo->minor_hash < start_minor_hash))) (hinfo->minor_hash < start_minor_hash)))
continue; continue;
if (de->inode == 0) if (de->inode == 0)
continue; continue;
if ((err = ext3_htree_store_dirent(dir_file, if ((err = ext4_htree_store_dirent(dir_file,
hinfo->hash, hinfo->minor_hash, de)) != 0) { hinfo->hash, hinfo->minor_hash, de)) != 0) {
brelse(bh); brelse(bh);
return err; return err;
...@@ -579,11 +579,11 @@ static int htree_dirblock_to_tree(struct file *dir_file, ...@@ -579,11 +579,11 @@ static int htree_dirblock_to_tree(struct file *dir_file,
* This function returns the number of entries inserted into the tree, * This function returns the number of entries inserted into the tree,
* or a negative error code. * or a negative error code.
*/ */
int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash, int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
__u32 start_minor_hash, __u32 *next_hash) __u32 start_minor_hash, __u32 *next_hash)
{ {
struct dx_hash_info hinfo; struct dx_hash_info hinfo;
struct ext3_dir_entry_2 *de; struct ext4_dir_entry_2 *de;
struct dx_frame frames[2], *frame; struct dx_frame frames[2], *frame;
struct inode *dir; struct inode *dir;
int block, err; int block, err;
...@@ -594,9 +594,9 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash, ...@@ -594,9 +594,9 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
dxtrace(printk("In htree_fill_tree, start hash: %x:%x\n", start_hash, dxtrace(printk("In htree_fill_tree, start hash: %x:%x\n", start_hash,
start_minor_hash)); start_minor_hash));
dir = dir_file->f_dentry->d_inode; dir = dir_file->f_dentry->d_inode;
if (!(EXT3_I(dir)->i_flags & EXT3_INDEX_FL)) { if (!(EXT4_I(dir)->i_flags & EXT4_INDEX_FL)) {
hinfo.hash_version = EXT3_SB(dir->i_sb)->s_def_hash_version; hinfo.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
hinfo.seed = EXT3_SB(dir->i_sb)->s_hash_seed; hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
count = htree_dirblock_to_tree(dir_file, dir, 0, &hinfo, count = htree_dirblock_to_tree(dir_file, dir, 0, &hinfo,
start_hash, start_minor_hash); start_hash, start_minor_hash);
*next_hash = ~0; *next_hash = ~0;
...@@ -610,15 +610,15 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash, ...@@ -610,15 +610,15 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
/* Add '.' and '..' from the htree header */ /* Add '.' and '..' from the htree header */
if (!start_hash && !start_minor_hash) { if (!start_hash && !start_minor_hash) {
de = (struct ext3_dir_entry_2 *) frames[0].bh->b_data; de = (struct ext4_dir_entry_2 *) frames[0].bh->b_data;
if ((err = ext3_htree_store_dirent(dir_file, 0, 0, de)) != 0) if ((err = ext4_htree_store_dirent(dir_file, 0, 0, de)) != 0)
goto errout; goto errout;
count++; count++;
} }
if (start_hash < 2 || (start_hash ==2 && start_minor_hash==0)) { if (start_hash < 2 || (start_hash ==2 && start_minor_hash==0)) {
de = (struct ext3_dir_entry_2 *) frames[0].bh->b_data; de = (struct ext4_dir_entry_2 *) frames[0].bh->b_data;
de = ext3_next_entry(de); de = ext4_next_entry(de);
if ((err = ext3_htree_store_dirent(dir_file, 2, 0, de)) != 0) if ((err = ext4_htree_store_dirent(dir_file, 2, 0, de)) != 0)
goto errout; goto errout;
count++; count++;
} }
...@@ -633,7 +633,7 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash, ...@@ -633,7 +633,7 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
} }
count += ret; count += ret;
hashval = ~0; hashval = ~0;
ret = ext3_htree_next_block(dir, HASH_NB_ALWAYS, ret = ext4_htree_next_block(dir, HASH_NB_ALWAYS,
frame, frames, &hashval); frame, frames, &hashval);
*next_hash = hashval; *next_hash = hashval;
if (ret < 0) { if (ret < 0) {
...@@ -663,7 +663,7 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash, ...@@ -663,7 +663,7 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
* Directory block splitting, compacting * Directory block splitting, compacting
*/ */
static int dx_make_map (struct ext3_dir_entry_2 *de, int size, static int dx_make_map (struct ext4_dir_entry_2 *de, int size,
struct dx_hash_info *hinfo, struct dx_map_entry *map_tail) struct dx_hash_info *hinfo, struct dx_map_entry *map_tail)
{ {
int count = 0; int count = 0;
...@@ -673,7 +673,7 @@ static int dx_make_map (struct ext3_dir_entry_2 *de, int size, ...@@ -673,7 +673,7 @@ static int dx_make_map (struct ext3_dir_entry_2 *de, int size,
while ((char *) de < base + size) while ((char *) de < base + size)
{ {
if (de->name_len && de->inode) { if (de->name_len && de->inode) {
ext3fs_dirhash(de->name, de->name_len, &h); ext4fs_dirhash(de->name, de->name_len, &h);
map_tail--; map_tail--;
map_tail->hash = h.hash; map_tail->hash = h.hash;
map_tail->offs = (u32) ((char *) de - base); 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,7 +681,7 @@ static int dx_make_map (struct ext3_dir_entry_2 *de, int size,
cond_resched(); cond_resched();
} }
/* XXX: do we need to check rec_len == 0 case? -Chris */ /* XXX: do we need to check rec_len == 0 case? -Chris */
de = (struct ext3_dir_entry_2 *) ((char *) de + le16_to_cpu(de->rec_len)); de = (struct ext4_dir_entry_2 *) ((char *) de + le16_to_cpu(de->rec_len));
} }
return count; return count;
} }
...@@ -730,21 +730,21 @@ static void dx_insert_block(struct dx_frame *frame, u32 hash, u32 block) ...@@ -730,21 +730,21 @@ static void dx_insert_block(struct dx_frame *frame, u32 hash, u32 block)
#endif #endif
static void ext3_update_dx_flag(struct inode *inode) static void ext4_update_dx_flag(struct inode *inode)
{ {
if (!EXT3_HAS_COMPAT_FEATURE(inode->i_sb, if (!EXT4_HAS_COMPAT_FEATURE(inode->i_sb,
EXT3_FEATURE_COMPAT_DIR_INDEX)) EXT4_FEATURE_COMPAT_DIR_INDEX))
EXT3_I(inode)->i_flags &= ~EXT3_INDEX_FL; EXT4_I(inode)->i_flags &= ~EXT4_INDEX_FL;
} }
/* /*
* NOTE! unlike strncmp, ext3_match returns 1 for success, 0 for failure. * NOTE! unlike strncmp, ext4_match returns 1 for success, 0 for failure.
* *
* `len <= EXT3_NAME_LEN' is guaranteed by caller. * `len <= EXT4_NAME_LEN' is guaranteed by caller.
* `de != NULL' is guaranteed by caller. * `de != NULL' is guaranteed by caller.
*/ */
static inline int ext3_match (int len, const char * const name, static inline int ext4_match (int len, const char * const name,
struct ext3_dir_entry_2 * de) struct ext4_dir_entry_2 * de)
{ {
if (len != de->name_len) if (len != de->name_len)
return 0; return 0;
...@@ -760,24 +760,24 @@ static inline int search_dirblock(struct buffer_head * bh, ...@@ -760,24 +760,24 @@ static inline int search_dirblock(struct buffer_head * bh,
struct inode *dir, struct inode *dir,
struct dentry *dentry, struct dentry *dentry,
unsigned long offset, unsigned long offset,
struct ext3_dir_entry_2 ** res_dir) struct ext4_dir_entry_2 ** res_dir)
{ {
struct ext3_dir_entry_2 * de; struct ext4_dir_entry_2 * de;
char * dlimit; char * dlimit;
int de_len; int de_len;
const char *name = dentry->d_name.name; const char *name = dentry->d_name.name;
int namelen = dentry->d_name.len; int namelen = dentry->d_name.len;
de = (struct ext3_dir_entry_2 *) bh->b_data; de = (struct ext4_dir_entry_2 *) bh->b_data;
dlimit = bh->b_data + dir->i_sb->s_blocksize; dlimit = bh->b_data + dir->i_sb->s_blocksize;
while ((char *) de < dlimit) { while ((char *) de < dlimit) {
/* this code is executed quadratically often */ /* this code is executed quadratically often */
/* do minimal checking `by hand' */ /* do minimal checking `by hand' */
if ((char *) de + namelen <= dlimit && if ((char *) de + namelen <= dlimit &&
ext3_match (namelen, name, de)) { ext4_match (namelen, name, de)) {
/* found a match - just to be sure, do a full check */ /* found a match - just to be sure, do a full check */
if (!ext3_check_dir_entry("ext3_find_entry", if (!ext4_check_dir_entry("ext4_find_entry",
dir, de, bh, offset)) dir, de, bh, offset))
return -1; return -1;
*res_dir = de; *res_dir = de;
...@@ -788,14 +788,14 @@ static inline int search_dirblock(struct buffer_head * bh, ...@@ -788,14 +788,14 @@ static inline int search_dirblock(struct buffer_head * bh,
if (de_len <= 0) if (de_len <= 0)
return -1; return -1;
offset += de_len; offset += de_len;
de = (struct ext3_dir_entry_2 *) ((char *) de + de_len); de = (struct ext4_dir_entry_2 *) ((char *) de + de_len);
} }
return 0; return 0;
} }
/* /*
* ext3_find_entry() * ext4_find_entry()
* *
* finds an entry in the specified directory with the wanted name. It * finds an entry in the specified directory with the wanted name. It
* returns the cache buffer in which the entry was found, and the entry * 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,8 +805,8 @@ static inline int search_dirblock(struct buffer_head * bh,
* The returned buffer_head has ->b_count elevated. The caller is expected * The returned buffer_head has ->b_count elevated. The caller is expected
* to brelse() it when appropriate. * to brelse() it when appropriate.
*/ */
static struct buffer_head * ext3_find_entry (struct dentry *dentry, static struct buffer_head * ext4_find_entry (struct dentry *dentry,
struct ext3_dir_entry_2 ** res_dir) struct ext4_dir_entry_2 ** res_dir)
{ {
struct super_block * sb; struct super_block * sb;
struct buffer_head * bh_use[NAMEI_RA_SIZE]; struct buffer_head * bh_use[NAMEI_RA_SIZE];
...@@ -828,11 +828,11 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry, ...@@ -828,11 +828,11 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry,
blocksize = sb->s_blocksize; blocksize = sb->s_blocksize;
namelen = dentry->d_name.len; namelen = dentry->d_name.len;
name = dentry->d_name.name; name = dentry->d_name.name;
if (namelen > EXT3_NAME_LEN) if (namelen > EXT4_NAME_LEN)
return NULL; return NULL;
#ifdef CONFIG_EXT3_INDEX #ifdef CONFIG_EXT4_INDEX
if (is_dx(dir)) { if (is_dx(dir)) {
bh = ext3_dx_find_entry(dentry, res_dir, &err); bh = ext4_dx_find_entry(dentry, res_dir, &err);
/* /*
* On success, or if the error was file not found, * On success, or if the error was file not found,
* return. Otherwise, fall back to doing a search the * return. Otherwise, fall back to doing a search the
...@@ -840,11 +840,11 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry, ...@@ -840,11 +840,11 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry,
*/ */
if (bh || (err != ERR_BAD_DX_DIR)) if (bh || (err != ERR_BAD_DX_DIR))
return bh; return bh;
dxtrace(printk("ext3_find_entry: dx failed, falling back\n")); dxtrace(printk("ext4_find_entry: dx failed, falling back\n"));
} }
#endif #endif
nblocks = dir->i_size >> EXT3_BLOCK_SIZE_BITS(sb); nblocks = dir->i_size >> EXT4_BLOCK_SIZE_BITS(sb);
start = EXT3_I(dir)->i_dir_start_lookup; start = EXT4_I(dir)->i_dir_start_lookup;
if (start >= nblocks) if (start >= nblocks)
start = 0; start = 0;
block = start; block = start;
...@@ -868,7 +868,7 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry, ...@@ -868,7 +868,7 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry,
break; break;
} }
num++; num++;
bh = ext3_getblk(NULL, dir, b++, 0, &err); bh = ext4_getblk(NULL, dir, b++, 0, &err);
bh_use[ra_max] = bh; bh_use[ra_max] = bh;
if (bh) if (bh)
ll_rw_block(READ_META, 1, &bh); ll_rw_block(READ_META, 1, &bh);
...@@ -879,15 +879,15 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry, ...@@ -879,15 +879,15 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry,
wait_on_buffer(bh); wait_on_buffer(bh);
if (!buffer_uptodate(bh)) { if (!buffer_uptodate(bh)) {
/* read error, skip block & hope for the best */ /* read error, skip block & hope for the best */
ext3_error(sb, __FUNCTION__, "reading directory #%lu " ext4_error(sb, __FUNCTION__, "reading directory #%lu "
"offset %lu", dir->i_ino, block); "offset %lu", dir->i_ino, block);
brelse(bh); brelse(bh);
goto next; goto next;
} }
i = search_dirblock(bh, dir, dentry, i = search_dirblock(bh, dir, dentry,
block << EXT3_BLOCK_SIZE_BITS(sb), res_dir); block << EXT4_BLOCK_SIZE_BITS(sb), res_dir);
if (i == 1) { if (i == 1) {
EXT3_I(dir)->i_dir_start_lookup = block; EXT4_I(dir)->i_dir_start_lookup = block;
ret = bh; ret = bh;
goto cleanup_and_exit; goto cleanup_and_exit;
} else { } else {
...@@ -905,7 +905,7 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry, ...@@ -905,7 +905,7 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry,
* search the last part of the directory before giving up. * search the last part of the directory before giving up.
*/ */
block = nblocks; block = nblocks;
nblocks = dir->i_size >> EXT3_BLOCK_SIZE_BITS(sb); nblocks = dir->i_size >> EXT4_BLOCK_SIZE_BITS(sb);
if (block < nblocks) { if (block < nblocks) {
start = 0; start = 0;
goto restart; goto restart;
...@@ -918,15 +918,15 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry, ...@@ -918,15 +918,15 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry,
return ret; return ret;
} }
#ifdef CONFIG_EXT3_INDEX #ifdef CONFIG_EXT4_INDEX
static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry, static struct buffer_head * ext4_dx_find_entry(struct dentry *dentry,
struct ext3_dir_entry_2 **res_dir, int *err) struct ext4_dir_entry_2 **res_dir, int *err)
{ {
struct super_block * sb; struct super_block * sb;
struct dx_hash_info hinfo; struct dx_hash_info hinfo;
u32 hash; u32 hash;
struct dx_frame frames[2], *frame; struct dx_frame frames[2], *frame;
struct ext3_dir_entry_2 *de, *top; struct ext4_dir_entry_2 *de, *top;
struct buffer_head *bh; struct buffer_head *bh;
unsigned long block; unsigned long block;
int retval; int retval;
...@@ -948,16 +948,16 @@ static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry, ...@@ -948,16 +948,16 @@ static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry,
hash = hinfo.hash; hash = hinfo.hash;
do { do {
block = dx_get_block(frame->at); block = dx_get_block(frame->at);
if (!(bh = ext3_bread (NULL,dir, block, 0, err))) if (!(bh = ext4_bread (NULL,dir, block, 0, err)))
goto errout; goto errout;
de = (struct ext3_dir_entry_2 *) bh->b_data; de = (struct ext4_dir_entry_2 *) bh->b_data;
top = (struct ext3_dir_entry_2 *) ((char *) de + sb->s_blocksize - top = (struct ext4_dir_entry_2 *) ((char *) de + sb->s_blocksize -
EXT3_DIR_REC_LEN(0)); EXT4_DIR_REC_LEN(0));
for (; de < top; de = ext3_next_entry(de)) for (; de < top; de = ext4_next_entry(de))
if (ext3_match (namelen, name, de)) { if (ext4_match (namelen, name, de)) {
if (!ext3_check_dir_entry("ext3_find_entry", if (!ext4_check_dir_entry("ext4_find_entry",
dir, de, bh, dir, de, bh,
(block<<EXT3_BLOCK_SIZE_BITS(sb)) (block<<EXT4_BLOCK_SIZE_BITS(sb))
+((char *)de - bh->b_data))) { +((char *)de - bh->b_data))) {
brelse (bh); brelse (bh);
goto errout; goto errout;
...@@ -968,10 +968,10 @@ static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry, ...@@ -968,10 +968,10 @@ static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry,
} }
brelse (bh); brelse (bh);
/* Check to see if we should continue to search */ /* Check to see if we should continue to search */
retval = ext3_htree_next_block(dir, hash, frame, retval = ext4_htree_next_block(dir, hash, frame,
frames, NULL); frames, NULL);
if (retval < 0) { if (retval < 0) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"error reading index page in directory #%lu", "error reading index page in directory #%lu",
dir->i_ino); dir->i_ino);
*err = retval; *err = retval;
...@@ -987,22 +987,22 @@ static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry, ...@@ -987,22 +987,22 @@ static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry,
} }
#endif #endif
static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd) static struct dentry *ext4_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
{ {
struct inode * inode; struct inode * inode;
struct ext3_dir_entry_2 * de; struct ext4_dir_entry_2 * de;
struct buffer_head * bh; struct buffer_head * bh;
if (dentry->d_name.len > EXT3_NAME_LEN) if (dentry->d_name.len > EXT4_NAME_LEN)
return ERR_PTR(-ENAMETOOLONG); return ERR_PTR(-ENAMETOOLONG);
bh = ext3_find_entry(dentry, &de); bh = ext4_find_entry(dentry, &de);
inode = NULL; inode = NULL;
if (bh) { if (bh) {
unsigned long ino = le32_to_cpu(de->inode); unsigned long ino = le32_to_cpu(de->inode);
brelse (bh); brelse (bh);
if (!ext3_valid_inum(dir->i_sb, ino)) { if (!ext4_valid_inum(dir->i_sb, ino)) {
ext3_error(dir->i_sb, "ext3_lookup", ext4_error(dir->i_sb, "ext4_lookup",
"bad inode number: %lu", ino); "bad inode number: %lu", ino);
inode = NULL; inode = NULL;
} else } else
...@@ -1015,28 +1015,28 @@ static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, str ...@@ -1015,28 +1015,28 @@ static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, str
} }
struct dentry *ext3_get_parent(struct dentry *child) struct dentry *ext4_get_parent(struct dentry *child)
{ {
unsigned long ino; unsigned long ino;
struct dentry *parent; struct dentry *parent;
struct inode *inode; struct inode *inode;
struct dentry dotdot; struct dentry dotdot;
struct ext3_dir_entry_2 * de; struct ext4_dir_entry_2 * de;
struct buffer_head *bh; struct buffer_head *bh;
dotdot.d_name.name = ".."; dotdot.d_name.name = "..";
dotdot.d_name.len = 2; dotdot.d_name.len = 2;
dotdot.d_parent = child; /* confusing, isn't it! */ dotdot.d_parent = child; /* confusing, isn't it! */
bh = ext3_find_entry(&dotdot, &de); bh = ext4_find_entry(&dotdot, &de);
inode = NULL; inode = NULL;
if (!bh) if (!bh)
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
ino = le32_to_cpu(de->inode); ino = le32_to_cpu(de->inode);
brelse(bh); brelse(bh);
if (!ext3_valid_inum(child->d_inode->i_sb, ino)) { if (!ext4_valid_inum(child->d_inode->i_sb, ino)) {
ext3_error(child->d_inode->i_sb, "ext3_get_parent", ext4_error(child->d_inode->i_sb, "ext4_get_parent",
"bad inode number: %lu", ino); "bad inode number: %lu", ino);
inode = NULL; inode = NULL;
} else } else
...@@ -1054,65 +1054,65 @@ struct dentry *ext3_get_parent(struct dentry *child) ...@@ -1054,65 +1054,65 @@ struct dentry *ext3_get_parent(struct dentry *child)
} }
#define S_SHIFT 12 #define S_SHIFT 12
static unsigned char ext3_type_by_mode[S_IFMT >> S_SHIFT] = { static unsigned char ext4_type_by_mode[S_IFMT >> S_SHIFT] = {
[S_IFREG >> S_SHIFT] = EXT3_FT_REG_FILE, [S_IFREG >> S_SHIFT] = EXT4_FT_REG_FILE,
[S_IFDIR >> S_SHIFT] = EXT3_FT_DIR, [S_IFDIR >> S_SHIFT] = EXT4_FT_DIR,
[S_IFCHR >> S_SHIFT] = EXT3_FT_CHRDEV, [S_IFCHR >> S_SHIFT] = EXT4_FT_CHRDEV,
[S_IFBLK >> S_SHIFT] = EXT3_FT_BLKDEV, [S_IFBLK >> S_SHIFT] = EXT4_FT_BLKDEV,
[S_IFIFO >> S_SHIFT] = EXT3_FT_FIFO, [S_IFIFO >> S_SHIFT] = EXT4_FT_FIFO,
[S_IFSOCK >> S_SHIFT] = EXT3_FT_SOCK, [S_IFSOCK >> S_SHIFT] = EXT4_FT_SOCK,
[S_IFLNK >> S_SHIFT] = EXT3_FT_SYMLINK, [S_IFLNK >> S_SHIFT] = EXT4_FT_SYMLINK,
}; };
static inline void ext3_set_de_type(struct super_block *sb, static inline void ext4_set_de_type(struct super_block *sb,
struct ext3_dir_entry_2 *de, struct ext4_dir_entry_2 *de,
umode_t mode) { umode_t mode) {
if (EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_FILETYPE)) if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FILETYPE))
de->file_type = ext3_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; de->file_type = ext4_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
} }
#ifdef CONFIG_EXT3_INDEX #ifdef CONFIG_EXT4_INDEX
static struct ext3_dir_entry_2 * static struct ext4_dir_entry_2 *
dx_move_dirents(char *from, char *to, struct dx_map_entry *map, int count) dx_move_dirents(char *from, char *to, struct dx_map_entry *map, int count)
{ {
unsigned rec_len = 0; unsigned rec_len = 0;
while (count--) { while (count--) {
struct ext3_dir_entry_2 *de = (struct ext3_dir_entry_2 *) (from + map->offs); struct ext4_dir_entry_2 *de = (struct ext4_dir_entry_2 *) (from + map->offs);
rec_len = EXT3_DIR_REC_LEN(de->name_len); rec_len = EXT4_DIR_REC_LEN(de->name_len);
memcpy (to, de, rec_len); memcpy (to, de, rec_len);
((struct ext3_dir_entry_2 *) to)->rec_len = ((struct ext4_dir_entry_2 *) to)->rec_len =
cpu_to_le16(rec_len); cpu_to_le16(rec_len);
de->inode = 0; de->inode = 0;
map++; map++;
to += rec_len; to += rec_len;
} }
return (struct ext3_dir_entry_2 *) (to - rec_len); return (struct ext4_dir_entry_2 *) (to - rec_len);
} }
static struct ext3_dir_entry_2* dx_pack_dirents(char *base, int size) static struct ext4_dir_entry_2* dx_pack_dirents(char *base, int size)
{ {
struct ext3_dir_entry_2 *next, *to, *prev, *de = (struct ext3_dir_entry_2 *) base; struct ext4_dir_entry_2 *next, *to, *prev, *de = (struct ext4_dir_entry_2 *) base;
unsigned rec_len = 0; unsigned rec_len = 0;
prev = to = de; prev = to = de;
while ((char*)de < base + size) { while ((char*)de < base + size) {
next = (struct ext3_dir_entry_2 *) ((char *) de + next = (struct ext4_dir_entry_2 *) ((char *) de +
le16_to_cpu(de->rec_len)); le16_to_cpu(de->rec_len));
if (de->inode && de->name_len) { if (de->inode && de->name_len) {
rec_len = EXT3_DIR_REC_LEN(de->name_len); rec_len = EXT4_DIR_REC_LEN(de->name_len);
if (de > to) if (de > to)
memmove(to, de, rec_len); memmove(to, de, rec_len);
to->rec_len = cpu_to_le16(rec_len); to->rec_len = cpu_to_le16(rec_len);
prev = to; prev = to;
to = (struct ext3_dir_entry_2 *) (((char *) to) + rec_len); to = (struct ext4_dir_entry_2 *) (((char *) to) + rec_len);
} }
de = next; de = next;
} }
return prev; return prev;
} }
static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir, static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
struct buffer_head **bh,struct dx_frame *frame, struct buffer_head **bh,struct dx_frame *frame,
struct dx_hash_info *hinfo, int *error) struct dx_hash_info *hinfo, int *error)
{ {
...@@ -1124,10 +1124,10 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir, ...@@ -1124,10 +1124,10 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
struct dx_map_entry *map; struct dx_map_entry *map;
char *data1 = (*bh)->b_data, *data2; char *data1 = (*bh)->b_data, *data2;
unsigned split; unsigned split;
struct ext3_dir_entry_2 *de = NULL, *de2; struct ext4_dir_entry_2 *de = NULL, *de2;
int err; int err;
bh2 = ext3_append (handle, dir, &newblock, error); bh2 = ext4_append (handle, dir, &newblock, error);
if (!(bh2)) { if (!(bh2)) {
brelse(*bh); brelse(*bh);
*bh = NULL; *bh = NULL;
...@@ -1135,17 +1135,17 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir, ...@@ -1135,17 +1135,17 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
} }
BUFFER_TRACE(*bh, "get_write_access"); BUFFER_TRACE(*bh, "get_write_access");
err = ext3_journal_get_write_access(handle, *bh); err = ext4_journal_get_write_access(handle, *bh);
if (err) { if (err) {
journal_error: journal_error:
brelse(*bh); brelse(*bh);
brelse(bh2); brelse(bh2);
*bh = NULL; *bh = NULL;
ext3_std_error(dir->i_sb, err); ext4_std_error(dir->i_sb, err);
goto errout; goto errout;
} }
BUFFER_TRACE(frame->bh, "get_write_access"); BUFFER_TRACE(frame->bh, "get_write_access");
err = ext3_journal_get_write_access(handle, frame->bh); err = ext4_journal_get_write_access(handle, frame->bh);
if (err) if (err)
goto journal_error; goto journal_error;
...@@ -1153,7 +1153,7 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir, ...@@ -1153,7 +1153,7 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
/* create map in the end of data2 block */ /* create map in the end of data2 block */
map = (struct dx_map_entry *) (data2 + blocksize); map = (struct dx_map_entry *) (data2 + blocksize);
count = dx_make_map ((struct ext3_dir_entry_2 *) data1, count = dx_make_map ((struct ext4_dir_entry_2 *) data1,
blocksize, hinfo, map); blocksize, hinfo, map);
map -= count; map -= count;
split = count/2; // need to adjust to actual middle 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,8 +1168,8 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
de = dx_pack_dirents(data1,blocksize); de = dx_pack_dirents(data1,blocksize);
de->rec_len = cpu_to_le16(data1 + blocksize - (char *) de); de->rec_len = cpu_to_le16(data1 + blocksize - (char *) de);
de2->rec_len = cpu_to_le16(data2 + blocksize - (char *) de2); de2->rec_len = cpu_to_le16(data2 + blocksize - (char *) de2);
dxtrace(dx_show_leaf (hinfo, (struct ext3_dir_entry_2 *) data1, blocksize, 1)); dxtrace(dx_show_leaf (hinfo, (struct ext4_dir_entry_2 *) data1, blocksize, 1));
dxtrace(dx_show_leaf (hinfo, (struct ext3_dir_entry_2 *) data2, blocksize, 1)); dxtrace(dx_show_leaf (hinfo, (struct ext4_dir_entry_2 *) data2, blocksize, 1));
/* Which block gets the new entry? */ /* Which block gets the new entry? */
if (hinfo->hash >= hash2) if (hinfo->hash >= hash2)
...@@ -1178,10 +1178,10 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir, ...@@ -1178,10 +1178,10 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
de = de2; de = de2;
} }
dx_insert_block (frame, hash2 + continued, newblock); dx_insert_block (frame, hash2 + continued, newblock);
err = ext3_journal_dirty_metadata (handle, bh2); err = ext4_journal_dirty_metadata (handle, bh2);
if (err) if (err)
goto journal_error; goto journal_error;
err = ext3_journal_dirty_metadata (handle, frame->bh); err = ext4_journal_dirty_metadata (handle, frame->bh);
if (err) if (err)
goto journal_error; goto journal_error;
brelse (bh2); brelse (bh2);
...@@ -1204,7 +1204,7 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir, ...@@ -1204,7 +1204,7 @@ static struct ext3_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
* all other cases bh is released. * all other cases bh is released.
*/ */
static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry, static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
struct inode *inode, struct ext3_dir_entry_2 *de, struct inode *inode, struct ext4_dir_entry_2 *de,
struct buffer_head * bh) struct buffer_head * bh)
{ {
struct inode *dir = dentry->d_parent->d_inode; 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,51 +1215,51 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
int nlen, rlen, err; int nlen, rlen, err;
char *top; char *top;
reclen = EXT3_DIR_REC_LEN(namelen); reclen = EXT4_DIR_REC_LEN(namelen);
if (!de) { if (!de) {
de = (struct ext3_dir_entry_2 *)bh->b_data; de = (struct ext4_dir_entry_2 *)bh->b_data;
top = bh->b_data + dir->i_sb->s_blocksize - reclen; top = bh->b_data + dir->i_sb->s_blocksize - reclen;
while ((char *) de <= top) { while ((char *) de <= top) {
if (!ext3_check_dir_entry("ext3_add_entry", dir, de, if (!ext4_check_dir_entry("ext4_add_entry", dir, de,
bh, offset)) { bh, offset)) {
brelse (bh); brelse (bh);
return -EIO; return -EIO;
} }
if (ext3_match (namelen, name, de)) { if (ext4_match (namelen, name, de)) {
brelse (bh); brelse (bh);
return -EEXIST; return -EEXIST;
} }
nlen = EXT3_DIR_REC_LEN(de->name_len); nlen = EXT4_DIR_REC_LEN(de->name_len);
rlen = le16_to_cpu(de->rec_len); rlen = le16_to_cpu(de->rec_len);
if ((de->inode? rlen - nlen: rlen) >= reclen) if ((de->inode? rlen - nlen: rlen) >= reclen)
break; break;
de = (struct ext3_dir_entry_2 *)((char *)de + rlen); de = (struct ext4_dir_entry_2 *)((char *)de + rlen);
offset += rlen; offset += rlen;
} }
if ((char *) de > top) if ((char *) de > top)
return -ENOSPC; return -ENOSPC;
} }
BUFFER_TRACE(bh, "get_write_access"); BUFFER_TRACE(bh, "get_write_access");
err = ext3_journal_get_write_access(handle, bh); err = ext4_journal_get_write_access(handle, bh);
if (err) { if (err) {
ext3_std_error(dir->i_sb, err); ext4_std_error(dir->i_sb, err);
brelse(bh); brelse(bh);
return err; return err;
} }
/* By now the buffer is marked for journaling */ /* By now the buffer is marked for journaling */
nlen = EXT3_DIR_REC_LEN(de->name_len); nlen = EXT4_DIR_REC_LEN(de->name_len);
rlen = le16_to_cpu(de->rec_len); rlen = le16_to_cpu(de->rec_len);
if (de->inode) { if (de->inode) {
struct ext3_dir_entry_2 *de1 = (struct ext3_dir_entry_2 *)((char *)de + nlen); struct ext4_dir_entry_2 *de1 = (struct ext4_dir_entry_2 *)((char *)de + nlen);
de1->rec_len = cpu_to_le16(rlen - nlen); de1->rec_len = cpu_to_le16(rlen - nlen);
de->rec_len = cpu_to_le16(nlen); de->rec_len = cpu_to_le16(nlen);
de = de1; de = de1;
} }
de->file_type = EXT3_FT_UNKNOWN; de->file_type = EXT4_FT_UNKNOWN;
if (inode) { if (inode) {
de->inode = cpu_to_le32(inode->i_ino); de->inode = cpu_to_le32(inode->i_ino);
ext3_set_de_type(dir->i_sb, de, inode->i_mode); ext4_set_de_type(dir->i_sb, de, inode->i_mode);
} else } else
de->inode = 0; de->inode = 0;
de->name_len = namelen; de->name_len = namelen;
...@@ -1270,24 +1270,24 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry, ...@@ -1270,24 +1270,24 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
* on this. * on this.
* *
* XXX similarly, too many callers depend on * XXX similarly, too many callers depend on
* ext3_new_inode() setting the times, but error * ext4_new_inode() setting the times, but error
* recovery deletes the inode, so the worst that can * recovery deletes the inode, so the worst that can
* happen is that the times are slightly out of date * happen is that the times are slightly out of date
* and/or different from the directory change time. * and/or different from the directory change time.
*/ */
dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC; dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
ext3_update_dx_flag(dir); ext4_update_dx_flag(dir);
dir->i_version++; dir->i_version++;
ext3_mark_inode_dirty(handle, dir); ext4_mark_inode_dirty(handle, dir);
BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata"); BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
err = ext3_journal_dirty_metadata(handle, bh); err = ext4_journal_dirty_metadata(handle, bh);
if (err) if (err)
ext3_std_error(dir->i_sb, err); ext4_std_error(dir->i_sb, err);
brelse(bh); brelse(bh);
return 0; return 0;
} }
#ifdef CONFIG_EXT3_INDEX #ifdef CONFIG_EXT4_INDEX
/* /*
* This converts a one block unindexed directory to a 3 block indexed * This converts a one block unindexed directory to a 3 block indexed
* directory, and adds the dentry to the indexed directory. * 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,7 +1302,7 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
struct dx_root *root; struct dx_root *root;
struct dx_frame frames[2], *frame; struct dx_frame frames[2], *frame;
struct dx_entry *entries; struct dx_entry *entries;
struct ext3_dir_entry_2 *de, *de2; struct ext4_dir_entry_2 *de, *de2;
char *data1, *top; char *data1, *top;
unsigned len; unsigned len;
int retval; int retval;
...@@ -1313,38 +1313,38 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry, ...@@ -1313,38 +1313,38 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
blocksize = dir->i_sb->s_blocksize; blocksize = dir->i_sb->s_blocksize;
dxtrace(printk("Creating index\n")); dxtrace(printk("Creating index\n"));
retval = ext3_journal_get_write_access(handle, bh); retval = ext4_journal_get_write_access(handle, bh);
if (retval) { if (retval) {
ext3_std_error(dir->i_sb, retval); ext4_std_error(dir->i_sb, retval);
brelse(bh); brelse(bh);
return retval; return retval;
} }
root = (struct dx_root *) bh->b_data; root = (struct dx_root *) bh->b_data;
bh2 = ext3_append (handle, dir, &block, &retval); bh2 = ext4_append (handle, dir, &block, &retval);
if (!(bh2)) { if (!(bh2)) {
brelse(bh); brelse(bh);
return retval; return retval;
} }
EXT3_I(dir)->i_flags |= EXT3_INDEX_FL; EXT4_I(dir)->i_flags |= EXT4_INDEX_FL;
data1 = bh2->b_data; data1 = bh2->b_data;
/* The 0th block becomes the root, move the dirents out */ /* The 0th block becomes the root, move the dirents out */
fde = &root->dotdot; fde = &root->dotdot;
de = (struct ext3_dir_entry_2 *)((char *)fde + le16_to_cpu(fde->rec_len)); de = (struct ext4_dir_entry_2 *)((char *)fde + le16_to_cpu(fde->rec_len));
len = ((char *) root) + blocksize - (char *) de; len = ((char *) root) + blocksize - (char *) de;
memcpy (data1, de, len); memcpy (data1, de, len);
de = (struct ext3_dir_entry_2 *) data1; de = (struct ext4_dir_entry_2 *) data1;
top = data1 + len; top = data1 + len;
while ((char *)(de2=(void*)de+le16_to_cpu(de->rec_len)) < top) while ((char *)(de2=(void*)de+le16_to_cpu(de->rec_len)) < top)
de = de2; de = de2;
de->rec_len = cpu_to_le16(data1 + blocksize - (char *) de); de->rec_len = cpu_to_le16(data1 + blocksize - (char *) de);
/* Initialize the root; the dot dirents already exist */ /* Initialize the root; the dot dirents already exist */
de = (struct ext3_dir_entry_2 *) (&root->dotdot); de = (struct ext4_dir_entry_2 *) (&root->dotdot);
de->rec_len = cpu_to_le16(blocksize - EXT3_DIR_REC_LEN(2)); de->rec_len = cpu_to_le16(blocksize - EXT4_DIR_REC_LEN(2));
memset (&root->info, 0, sizeof(root->info)); memset (&root->info, 0, sizeof(root->info));
root->info.info_length = sizeof(root->info); root->info.info_length = sizeof(root->info);
root->info.hash_version = EXT3_SB(dir->i_sb)->s_def_hash_version; root->info.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
entries = root->entries; entries = root->entries;
dx_set_block (entries, 1); dx_set_block (entries, 1);
dx_set_count (entries, 1); dx_set_count (entries, 1);
...@@ -1352,8 +1352,8 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry, ...@@ -1352,8 +1352,8 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
/* Initialize as for dx_probe */ /* Initialize as for dx_probe */
hinfo.hash_version = root->info.hash_version; hinfo.hash_version = root->info.hash_version;
hinfo.seed = EXT3_SB(dir->i_sb)->s_hash_seed; hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
ext3fs_dirhash(name, namelen, &hinfo); ext4fs_dirhash(name, namelen, &hinfo);
frame = frames; frame = frames;
frame->entries = entries; frame->entries = entries;
frame->at = entries; frame->at = entries;
...@@ -1369,25 +1369,25 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry, ...@@ -1369,25 +1369,25 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
#endif #endif
/* /*
* ext3_add_entry() * ext4_add_entry()
* *
* adds a file entry to the specified directory, using the same * adds a file entry to the specified directory, using the same
* semantics as ext3_find_entry(). It returns NULL if it failed. * semantics as ext4_find_entry(). It returns NULL if it failed.
* *
* NOTE!! The inode part of 'de' is left at 0 - which means you * NOTE!! The inode part of 'de' is left at 0 - which means you
* may not sleep between calling this and putting something into * may not sleep between calling this and putting something into
* the entry, as someone else might have used it while you slept. * the entry, as someone else might have used it while you slept.
*/ */
static int ext3_add_entry (handle_t *handle, struct dentry *dentry, static int ext4_add_entry (handle_t *handle, struct dentry *dentry,
struct inode *inode) struct inode *inode)
{ {
struct inode *dir = dentry->d_parent->d_inode; struct inode *dir = dentry->d_parent->d_inode;
unsigned long offset; unsigned long offset;
struct buffer_head * bh; struct buffer_head * bh;
struct ext3_dir_entry_2 *de; struct ext4_dir_entry_2 *de;
struct super_block * sb; struct super_block * sb;
int retval; int retval;
#ifdef CONFIG_EXT3_INDEX #ifdef CONFIG_EXT4_INDEX
int dx_fallback=0; int dx_fallback=0;
#endif #endif
unsigned blocksize; unsigned blocksize;
...@@ -1397,46 +1397,46 @@ static int ext3_add_entry (handle_t *handle, struct dentry *dentry, ...@@ -1397,46 +1397,46 @@ static int ext3_add_entry (handle_t *handle, struct dentry *dentry,
blocksize = sb->s_blocksize; blocksize = sb->s_blocksize;
if (!dentry->d_name.len) if (!dentry->d_name.len)
return -EINVAL; return -EINVAL;
#ifdef CONFIG_EXT3_INDEX #ifdef CONFIG_EXT4_INDEX
if (is_dx(dir)) { if (is_dx(dir)) {
retval = ext3_dx_add_entry(handle, dentry, inode); retval = ext4_dx_add_entry(handle, dentry, inode);
if (!retval || (retval != ERR_BAD_DX_DIR)) if (!retval || (retval != ERR_BAD_DX_DIR))
return retval; return retval;
EXT3_I(dir)->i_flags &= ~EXT3_INDEX_FL; EXT4_I(dir)->i_flags &= ~EXT4_INDEX_FL;
dx_fallback++; dx_fallback++;
ext3_mark_inode_dirty(handle, dir); ext4_mark_inode_dirty(handle, dir);
} }
#endif #endif
blocks = dir->i_size >> sb->s_blocksize_bits; blocks = dir->i_size >> sb->s_blocksize_bits;
for (block = 0, offset = 0; block < blocks; block++) { for (block = 0, offset = 0; block < blocks; block++) {
bh = ext3_bread(handle, dir, block, 0, &retval); bh = ext4_bread(handle, dir, block, 0, &retval);
if(!bh) if(!bh)
return retval; return retval;
retval = add_dirent_to_buf(handle, dentry, inode, NULL, bh); retval = add_dirent_to_buf(handle, dentry, inode, NULL, bh);
if (retval != -ENOSPC) if (retval != -ENOSPC)
return retval; return retval;
#ifdef CONFIG_EXT3_INDEX #ifdef CONFIG_EXT4_INDEX
if (blocks == 1 && !dx_fallback && if (blocks == 1 && !dx_fallback &&
EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_DIR_INDEX)) EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_DIR_INDEX))
return make_indexed_dir(handle, dentry, inode, bh); return make_indexed_dir(handle, dentry, inode, bh);
#endif #endif
brelse(bh); brelse(bh);
} }
bh = ext3_append(handle, dir, &block, &retval); bh = ext4_append(handle, dir, &block, &retval);
if (!bh) if (!bh)
return retval; return retval;
de = (struct ext3_dir_entry_2 *) bh->b_data; de = (struct ext4_dir_entry_2 *) bh->b_data;
de->inode = 0; de->inode = 0;
de->rec_len = cpu_to_le16(blocksize); de->rec_len = cpu_to_le16(blocksize);
return add_dirent_to_buf(handle, dentry, inode, de, bh); return add_dirent_to_buf(handle, dentry, inode, de, bh);
} }
#ifdef CONFIG_EXT3_INDEX #ifdef CONFIG_EXT4_INDEX
/* /*
* Returns 0 for success, or a negative error value * Returns 0 for success, or a negative error value
*/ */
static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
struct inode *inode) struct inode *inode)
{ {
struct dx_frame frames[2], *frame; struct dx_frame frames[2], *frame;
...@@ -1445,7 +1445,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -1445,7 +1445,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
struct buffer_head * bh; struct buffer_head * bh;
struct inode *dir = dentry->d_parent->d_inode; struct inode *dir = dentry->d_parent->d_inode;
struct super_block * sb = dir->i_sb; struct super_block * sb = dir->i_sb;
struct ext3_dir_entry_2 *de; struct ext4_dir_entry_2 *de;
int err; int err;
frame = dx_probe(dentry, NULL, &hinfo, frames, &err); 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,11 +1454,11 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
entries = frame->entries; entries = frame->entries;
at = frame->at; at = frame->at;
if (!(bh = ext3_bread(handle,dir, dx_get_block(frame->at), 0, &err))) if (!(bh = ext4_bread(handle,dir, dx_get_block(frame->at), 0, &err)))
goto cleanup; goto cleanup;
BUFFER_TRACE(bh, "get_write_access"); BUFFER_TRACE(bh, "get_write_access");
err = ext3_journal_get_write_access(handle, bh); err = ext4_journal_get_write_access(handle, bh);
if (err) if (err)
goto journal_error; goto journal_error;
...@@ -1482,12 +1482,12 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -1482,12 +1482,12 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
if (levels && (dx_get_count(frames->entries) == if (levels && (dx_get_count(frames->entries) ==
dx_get_limit(frames->entries))) { dx_get_limit(frames->entries))) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"Directory index full!"); "Directory index full!");
err = -ENOSPC; err = -ENOSPC;
goto cleanup; goto cleanup;
} }
bh2 = ext3_append (handle, dir, &newblock, &err); bh2 = ext4_append (handle, dir, &newblock, &err);
if (!(bh2)) if (!(bh2))
goto cleanup; goto cleanup;
node2 = (struct dx_node *)(bh2->b_data); node2 = (struct dx_node *)(bh2->b_data);
...@@ -1495,7 +1495,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -1495,7 +1495,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
node2->fake.rec_len = cpu_to_le16(sb->s_blocksize); node2->fake.rec_len = cpu_to_le16(sb->s_blocksize);
node2->fake.inode = 0; node2->fake.inode = 0;
BUFFER_TRACE(frame->bh, "get_write_access"); BUFFER_TRACE(frame->bh, "get_write_access");
err = ext3_journal_get_write_access(handle, frame->bh); err = ext4_journal_get_write_access(handle, frame->bh);
if (err) if (err)
goto journal_error; goto journal_error;
if (levels) { if (levels) {
...@@ -1504,7 +1504,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -1504,7 +1504,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
dxtrace(printk("Split index %i/%i\n", icount1, icount2)); dxtrace(printk("Split index %i/%i\n", icount1, icount2));
BUFFER_TRACE(frame->bh, "get_write_access"); /* index root */ BUFFER_TRACE(frame->bh, "get_write_access"); /* index root */
err = ext3_journal_get_write_access(handle, err = ext4_journal_get_write_access(handle,
frames[0].bh); frames[0].bh);
if (err) if (err)
goto journal_error; goto journal_error;
...@@ -1525,7 +1525,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -1525,7 +1525,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
dxtrace(dx_show_index ("node", frames[1].entries)); dxtrace(dx_show_index ("node", frames[1].entries));
dxtrace(dx_show_index ("node", dxtrace(dx_show_index ("node",
((struct dx_node *) bh2->b_data)->entries)); ((struct dx_node *) bh2->b_data)->entries));
err = ext3_journal_dirty_metadata(handle, bh2); err = ext4_journal_dirty_metadata(handle, bh2);
if (err) if (err)
goto journal_error; goto journal_error;
brelse (bh2); brelse (bh2);
...@@ -1545,12 +1545,12 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -1545,12 +1545,12 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
frame->at = at = at - entries + entries2; frame->at = at = at - entries + entries2;
frame->entries = entries = entries2; frame->entries = entries = entries2;
frame->bh = bh2; frame->bh = bh2;
err = ext3_journal_get_write_access(handle, err = ext4_journal_get_write_access(handle,
frame->bh); frame->bh);
if (err) if (err)
goto journal_error; goto journal_error;
} }
ext3_journal_dirty_metadata(handle, frames[0].bh); ext4_journal_dirty_metadata(handle, frames[0].bh);
} }
de = do_split(handle, dir, &bh, frame, &hinfo, &err); de = do_split(handle, dir, &bh, frame, &hinfo, &err);
if (!de) if (!de)
...@@ -1560,7 +1560,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -1560,7 +1560,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
goto cleanup; goto cleanup;
journal_error: journal_error:
ext3_std_error(dir->i_sb, err); ext4_std_error(dir->i_sb, err);
cleanup: cleanup:
if (bh) if (bh)
brelse(bh); brelse(bh);
...@@ -1570,26 +1570,26 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -1570,26 +1570,26 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
#endif #endif
/* /*
* ext3_delete_entry deletes a directory entry by merging it with the * ext4_delete_entry deletes a directory entry by merging it with the
* previous entry * previous entry
*/ */
static int ext3_delete_entry (handle_t *handle, static int ext4_delete_entry (handle_t *handle,
struct inode * dir, struct inode * dir,
struct ext3_dir_entry_2 * de_del, struct ext4_dir_entry_2 * de_del,
struct buffer_head * bh) struct buffer_head * bh)
{ {
struct ext3_dir_entry_2 * de, * pde; struct ext4_dir_entry_2 * de, * pde;
int i; int i;
i = 0; i = 0;
pde = NULL; pde = NULL;
de = (struct ext3_dir_entry_2 *) bh->b_data; de = (struct ext4_dir_entry_2 *) bh->b_data;
while (i < bh->b_size) { while (i < bh->b_size) {
if (!ext3_check_dir_entry("ext3_delete_entry", dir, de, bh, i)) if (!ext4_check_dir_entry("ext4_delete_entry", dir, de, bh, i))
return -EIO; return -EIO;
if (de == de_del) { if (de == de_del) {
BUFFER_TRACE(bh, "get_write_access"); BUFFER_TRACE(bh, "get_write_access");
ext3_journal_get_write_access(handle, bh); ext4_journal_get_write_access(handle, bh);
if (pde) if (pde)
pde->rec_len = pde->rec_len =
cpu_to_le16(le16_to_cpu(pde->rec_len) + cpu_to_le16(le16_to_cpu(pde->rec_len) +
...@@ -1597,43 +1597,43 @@ static int ext3_delete_entry (handle_t *handle, ...@@ -1597,43 +1597,43 @@ static int ext3_delete_entry (handle_t *handle,
else else
de->inode = 0; de->inode = 0;
dir->i_version++; dir->i_version++;
BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata"); BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata");
ext3_journal_dirty_metadata(handle, bh); ext4_journal_dirty_metadata(handle, bh);
return 0; return 0;
} }
i += le16_to_cpu(de->rec_len); i += le16_to_cpu(de->rec_len);
pde = de; pde = de;
de = (struct ext3_dir_entry_2 *) de = (struct ext4_dir_entry_2 *)
((char *) de + le16_to_cpu(de->rec_len)); ((char *) de + le16_to_cpu(de->rec_len));
} }
return -ENOENT; return -ENOENT;
} }
/* /*
* ext3_mark_inode_dirty is somewhat expensive, so unlike ext2 we * ext4_mark_inode_dirty is somewhat expensive, so unlike ext2 we
* do not perform it in these functions. We perform it at the call site, * do not perform it in these functions. We perform it at the call site,
* if it is needed. * if it is needed.
*/ */
static inline void ext3_inc_count(handle_t *handle, struct inode *inode) static inline void ext4_inc_count(handle_t *handle, struct inode *inode)
{ {
inc_nlink(inode); inc_nlink(inode);
} }
static inline void ext3_dec_count(handle_t *handle, struct inode *inode) static inline void ext4_dec_count(handle_t *handle, struct inode *inode)
{ {
drop_nlink(inode); drop_nlink(inode);
} }
static int ext3_add_nondir(handle_t *handle, static int ext4_add_nondir(handle_t *handle,
struct dentry *dentry, struct inode *inode) struct dentry *dentry, struct inode *inode)
{ {
int err = ext3_add_entry(handle, dentry, inode); int err = ext4_add_entry(handle, dentry, inode);
if (!err) { if (!err) {
ext3_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
return 0; return 0;
} }
ext3_dec_count(handle, inode); ext4_dec_count(handle, inode);
iput(inode); iput(inode);
return err; return err;
} }
...@@ -1646,7 +1646,7 @@ static int ext3_add_nondir(handle_t *handle, ...@@ -1646,7 +1646,7 @@ static int ext3_add_nondir(handle_t *handle,
* If the create succeeds, we fill in the inode information * If the create succeeds, we fill in the inode information
* with d_instantiate(). * with d_instantiate().
*/ */
static int ext3_create (struct inode * dir, struct dentry * dentry, int mode, static int ext4_create (struct inode * dir, struct dentry * dentry, int mode,
struct nameidata *nd) struct nameidata *nd)
{ {
handle_t *handle; handle_t *handle;
...@@ -1654,30 +1654,30 @@ static int ext3_create (struct inode * dir, struct dentry * dentry, int mode, ...@@ -1654,30 +1654,30 @@ static int ext3_create (struct inode * dir, struct dentry * dentry, int mode,
int err, retries = 0; int err, retries = 0;
retry: retry:
handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
if (IS_DIRSYNC(dir)) if (IS_DIRSYNC(dir))
handle->h_sync = 1; handle->h_sync = 1;
inode = ext3_new_inode (handle, dir, mode); inode = ext4_new_inode (handle, dir, mode);
err = PTR_ERR(inode); err = PTR_ERR(inode);
if (!IS_ERR(inode)) { if (!IS_ERR(inode)) {
inode->i_op = &ext3_file_inode_operations; inode->i_op = &ext4_file_inode_operations;
inode->i_fop = &ext3_file_operations; inode->i_fop = &ext4_file_operations;
ext3_set_aops(inode); ext4_set_aops(inode);
err = ext3_add_nondir(handle, dentry, inode); err = ext4_add_nondir(handle, dentry, inode);
} }
ext3_journal_stop(handle); ext4_journal_stop(handle);
if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries)) if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
goto retry; goto retry;
return err; return err;
} }
static int ext3_mknod (struct inode * dir, struct dentry *dentry, static int ext4_mknod (struct inode * dir, struct dentry *dentry,
int mode, dev_t rdev) int mode, dev_t rdev)
{ {
handle_t *handle; handle_t *handle;
...@@ -1688,100 +1688,100 @@ static int ext3_mknod (struct inode * dir, struct dentry *dentry, ...@@ -1688,100 +1688,100 @@ static int ext3_mknod (struct inode * dir, struct dentry *dentry,
return -EINVAL; return -EINVAL;
retry: retry:
handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
if (IS_DIRSYNC(dir)) if (IS_DIRSYNC(dir))
handle->h_sync = 1; handle->h_sync = 1;
inode = ext3_new_inode (handle, dir, mode); inode = ext4_new_inode (handle, dir, mode);
err = PTR_ERR(inode); err = PTR_ERR(inode);
if (!IS_ERR(inode)) { if (!IS_ERR(inode)) {
init_special_inode(inode, inode->i_mode, rdev); init_special_inode(inode, inode->i_mode, rdev);
#ifdef CONFIG_EXT3_FS_XATTR #ifdef CONFIG_EXT4DEV_FS_XATTR
inode->i_op = &ext3_special_inode_operations; inode->i_op = &ext4_special_inode_operations;
#endif #endif
err = ext3_add_nondir(handle, dentry, inode); err = ext4_add_nondir(handle, dentry, inode);
} }
ext3_journal_stop(handle); ext4_journal_stop(handle);
if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries)) if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
goto retry; goto retry;
return err; return err;
} }
static int ext3_mkdir(struct inode * dir, struct dentry * dentry, int mode) static int ext4_mkdir(struct inode * dir, struct dentry * dentry, int mode)
{ {
handle_t *handle; handle_t *handle;
struct inode * inode; struct inode * inode;
struct buffer_head * dir_block; struct buffer_head * dir_block;
struct ext3_dir_entry_2 * de; struct ext4_dir_entry_2 * de;
int err, retries = 0; int err, retries = 0;
if (dir->i_nlink >= EXT3_LINK_MAX) if (dir->i_nlink >= EXT4_LINK_MAX)
return -EMLINK; return -EMLINK;
retry: retry:
handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
if (IS_DIRSYNC(dir)) if (IS_DIRSYNC(dir))
handle->h_sync = 1; handle->h_sync = 1;
inode = ext3_new_inode (handle, dir, S_IFDIR | mode); inode = ext4_new_inode (handle, dir, S_IFDIR | mode);
err = PTR_ERR(inode); err = PTR_ERR(inode);
if (IS_ERR(inode)) if (IS_ERR(inode))
goto out_stop; goto out_stop;
inode->i_op = &ext3_dir_inode_operations; inode->i_op = &ext4_dir_inode_operations;
inode->i_fop = &ext3_dir_operations; inode->i_fop = &ext4_dir_operations;
inode->i_size = EXT3_I(inode)->i_disksize = inode->i_sb->s_blocksize; inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
dir_block = ext3_bread (handle, inode, 0, 1, &err); dir_block = ext4_bread (handle, inode, 0, 1, &err);
if (!dir_block) { if (!dir_block) {
drop_nlink(inode); /* is this nlink == 0? */ drop_nlink(inode); /* is this nlink == 0? */
ext3_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
iput (inode); iput (inode);
goto out_stop; goto out_stop;
} }
BUFFER_TRACE(dir_block, "get_write_access"); BUFFER_TRACE(dir_block, "get_write_access");
ext3_journal_get_write_access(handle, dir_block); ext4_journal_get_write_access(handle, dir_block);
de = (struct ext3_dir_entry_2 *) dir_block->b_data; de = (struct ext4_dir_entry_2 *) dir_block->b_data;
de->inode = cpu_to_le32(inode->i_ino); de->inode = cpu_to_le32(inode->i_ino);
de->name_len = 1; de->name_len = 1;
de->rec_len = cpu_to_le16(EXT3_DIR_REC_LEN(de->name_len)); de->rec_len = cpu_to_le16(EXT4_DIR_REC_LEN(de->name_len));
strcpy (de->name, "."); strcpy (de->name, ".");
ext3_set_de_type(dir->i_sb, de, S_IFDIR); ext4_set_de_type(dir->i_sb, de, S_IFDIR);
de = (struct ext3_dir_entry_2 *) de = (struct ext4_dir_entry_2 *)
((char *) de + le16_to_cpu(de->rec_len)); ((char *) de + le16_to_cpu(de->rec_len));
de->inode = cpu_to_le32(dir->i_ino); de->inode = cpu_to_le32(dir->i_ino);
de->rec_len = cpu_to_le16(inode->i_sb->s_blocksize-EXT3_DIR_REC_LEN(1)); de->rec_len = cpu_to_le16(inode->i_sb->s_blocksize-EXT4_DIR_REC_LEN(1));
de->name_len = 2; de->name_len = 2;
strcpy (de->name, ".."); strcpy (de->name, "..");
ext3_set_de_type(dir->i_sb, de, S_IFDIR); ext4_set_de_type(dir->i_sb, de, S_IFDIR);
inode->i_nlink = 2; inode->i_nlink = 2;
BUFFER_TRACE(dir_block, "call ext3_journal_dirty_metadata"); BUFFER_TRACE(dir_block, "call ext4_journal_dirty_metadata");
ext3_journal_dirty_metadata(handle, dir_block); ext4_journal_dirty_metadata(handle, dir_block);
brelse (dir_block); brelse (dir_block);
ext3_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
err = ext3_add_entry (handle, dentry, inode); err = ext4_add_entry (handle, dentry, inode);
if (err) { if (err) {
inode->i_nlink = 0; inode->i_nlink = 0;
ext3_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
iput (inode); iput (inode);
goto out_stop; goto out_stop;
} }
inc_nlink(dir); inc_nlink(dir);
ext3_update_dx_flag(dir); ext4_update_dx_flag(dir);
ext3_mark_inode_dirty(handle, dir); ext4_mark_inode_dirty(handle, dir);
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
out_stop: out_stop:
ext3_journal_stop(handle); ext4_journal_stop(handle);
if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries)) if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
goto retry; goto retry;
return err; return err;
} }
...@@ -1793,59 +1793,59 @@ static int empty_dir (struct inode * inode) ...@@ -1793,59 +1793,59 @@ static int empty_dir (struct inode * inode)
{ {
unsigned long offset; unsigned long offset;
struct buffer_head * bh; struct buffer_head * bh;
struct ext3_dir_entry_2 * de, * de1; struct ext4_dir_entry_2 * de, * de1;
struct super_block * sb; struct super_block * sb;
int err = 0; int err = 0;
sb = inode->i_sb; sb = inode->i_sb;
if (inode->i_size < EXT3_DIR_REC_LEN(1) + EXT3_DIR_REC_LEN(2) || if (inode->i_size < EXT4_DIR_REC_LEN(1) + EXT4_DIR_REC_LEN(2) ||
!(bh = ext3_bread (NULL, inode, 0, 0, &err))) { !(bh = ext4_bread (NULL, inode, 0, 0, &err))) {
if (err) if (err)
ext3_error(inode->i_sb, __FUNCTION__, ext4_error(inode->i_sb, __FUNCTION__,
"error %d reading directory #%lu offset 0", "error %d reading directory #%lu offset 0",
err, inode->i_ino); err, inode->i_ino);
else else
ext3_warning(inode->i_sb, __FUNCTION__, ext4_warning(inode->i_sb, __FUNCTION__,
"bad directory (dir #%lu) - no data block", "bad directory (dir #%lu) - no data block",
inode->i_ino); inode->i_ino);
return 1; return 1;
} }
de = (struct ext3_dir_entry_2 *) bh->b_data; de = (struct ext4_dir_entry_2 *) bh->b_data;
de1 = (struct ext3_dir_entry_2 *) de1 = (struct ext4_dir_entry_2 *)
((char *) de + le16_to_cpu(de->rec_len)); ((char *) de + le16_to_cpu(de->rec_len));
if (le32_to_cpu(de->inode) != inode->i_ino || if (le32_to_cpu(de->inode) != inode->i_ino ||
!le32_to_cpu(de1->inode) || !le32_to_cpu(de1->inode) ||
strcmp (".", de->name) || strcmp (".", de->name) ||
strcmp ("..", de1->name)) { strcmp ("..", de1->name)) {
ext3_warning (inode->i_sb, "empty_dir", ext4_warning (inode->i_sb, "empty_dir",
"bad directory (dir #%lu) - no `.' or `..'", "bad directory (dir #%lu) - no `.' or `..'",
inode->i_ino); inode->i_ino);
brelse (bh); brelse (bh);
return 1; return 1;
} }
offset = le16_to_cpu(de->rec_len) + le16_to_cpu(de1->rec_len); offset = le16_to_cpu(de->rec_len) + le16_to_cpu(de1->rec_len);
de = (struct ext3_dir_entry_2 *) de = (struct ext4_dir_entry_2 *)
((char *) de1 + le16_to_cpu(de1->rec_len)); ((char *) de1 + le16_to_cpu(de1->rec_len));
while (offset < inode->i_size ) { while (offset < inode->i_size ) {
if (!bh || if (!bh ||
(void *) de >= (void *) (bh->b_data+sb->s_blocksize)) { (void *) de >= (void *) (bh->b_data+sb->s_blocksize)) {
err = 0; err = 0;
brelse (bh); brelse (bh);
bh = ext3_bread (NULL, inode, bh = ext4_bread (NULL, inode,
offset >> EXT3_BLOCK_SIZE_BITS(sb), 0, &err); offset >> EXT4_BLOCK_SIZE_BITS(sb), 0, &err);
if (!bh) { if (!bh) {
if (err) if (err)
ext3_error(sb, __FUNCTION__, ext4_error(sb, __FUNCTION__,
"error %d reading directory" "error %d reading directory"
" #%lu offset %lu", " #%lu offset %lu",
err, inode->i_ino, offset); err, inode->i_ino, offset);
offset += sb->s_blocksize; offset += sb->s_blocksize;
continue; continue;
} }
de = (struct ext3_dir_entry_2 *) bh->b_data; de = (struct ext4_dir_entry_2 *) bh->b_data;
} }
if (!ext3_check_dir_entry("empty_dir", inode, de, bh, offset)) { if (!ext4_check_dir_entry("empty_dir", inode, de, bh, offset)) {
de = (struct ext3_dir_entry_2 *)(bh->b_data + de = (struct ext4_dir_entry_2 *)(bh->b_data +
sb->s_blocksize); sb->s_blocksize);
offset = (offset | (sb->s_blocksize - 1)) + 1; offset = (offset | (sb->s_blocksize - 1)) + 1;
continue; continue;
...@@ -1855,57 +1855,57 @@ static int empty_dir (struct inode * inode) ...@@ -1855,57 +1855,57 @@ static int empty_dir (struct inode * inode)
return 0; return 0;
} }
offset += le16_to_cpu(de->rec_len); offset += le16_to_cpu(de->rec_len);
de = (struct ext3_dir_entry_2 *) de = (struct ext4_dir_entry_2 *)
((char *) de + le16_to_cpu(de->rec_len)); ((char *) de + le16_to_cpu(de->rec_len));
} }
brelse (bh); brelse (bh);
return 1; return 1;
} }
/* ext3_orphan_add() links an unlinked or truncated inode into a list of /* ext4_orphan_add() links an unlinked or truncated inode into a list of
* such inodes, starting at the superblock, in case we crash before the * such inodes, starting at the superblock, in case we crash before the
* file is closed/deleted, or in case the inode truncate spans multiple * file is closed/deleted, or in case the inode truncate spans multiple
* transactions and the last transaction is not recovered after a crash. * transactions and the last transaction is not recovered after a crash.
* *
* At filesystem recovery time, we walk this list deleting unlinked * At filesystem recovery time, we walk this list deleting unlinked
* inodes and truncating linked inodes in ext3_orphan_cleanup(). * inodes and truncating linked inodes in ext4_orphan_cleanup().
*/ */
int ext3_orphan_add(handle_t *handle, struct inode *inode) int ext4_orphan_add(handle_t *handle, struct inode *inode)
{ {
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
struct ext3_iloc iloc; struct ext4_iloc iloc;
int err = 0, rc; int err = 0, rc;
lock_super(sb); lock_super(sb);
if (!list_empty(&EXT3_I(inode)->i_orphan)) if (!list_empty(&EXT4_I(inode)->i_orphan))
goto out_unlock; goto out_unlock;
/* Orphan handling is only valid for files with data blocks /* Orphan handling is only valid for files with data blocks
* being truncated, or files being unlinked. */ * being truncated, or files being unlinked. */
/* @@@ FIXME: Observation from aviro: /* @@@ FIXME: Observation from aviro:
* I think I can trigger J_ASSERT in ext3_orphan_add(). We block * I think I can trigger J_ASSERT in ext4_orphan_add(). We block
* here (on lock_super()), so race with ext3_link() which might bump * here (on lock_super()), so race with ext4_link() which might bump
* ->i_nlink. For, say it, character device. Not a regular file, * ->i_nlink. For, say it, character device. Not a regular file,
* not a directory, not a symlink and ->i_nlink > 0. * not a directory, not a symlink and ->i_nlink > 0.
*/ */
J_ASSERT ((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || J_ASSERT ((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
S_ISLNK(inode->i_mode)) || inode->i_nlink == 0); S_ISLNK(inode->i_mode)) || inode->i_nlink == 0);
BUFFER_TRACE(EXT3_SB(sb)->s_sbh, "get_write_access"); BUFFER_TRACE(EXT4_SB(sb)->s_sbh, "get_write_access");
err = ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh); err = ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh);
if (err) if (err)
goto out_unlock; goto out_unlock;
err = ext3_reserve_inode_write(handle, inode, &iloc); err = ext4_reserve_inode_write(handle, inode, &iloc);
if (err) if (err)
goto out_unlock; goto out_unlock;
/* Insert this inode at the head of the on-disk orphan list... */ /* Insert this inode at the head of the on-disk orphan list... */
NEXT_ORPHAN(inode) = le32_to_cpu(EXT3_SB(sb)->s_es->s_last_orphan); NEXT_ORPHAN(inode) = le32_to_cpu(EXT4_SB(sb)->s_es->s_last_orphan);
EXT3_SB(sb)->s_es->s_last_orphan = cpu_to_le32(inode->i_ino); EXT4_SB(sb)->s_es->s_last_orphan = cpu_to_le32(inode->i_ino);
err = ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); err = ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh);
rc = ext3_mark_iloc_dirty(handle, inode, &iloc); rc = ext4_mark_iloc_dirty(handle, inode, &iloc);
if (!err) if (!err)
err = rc; err = rc;
...@@ -1918,28 +1918,28 @@ int ext3_orphan_add(handle_t *handle, struct inode *inode) ...@@ -1918,28 +1918,28 @@ int ext3_orphan_add(handle_t *handle, struct inode *inode)
* This is safe: on error we're going to ignore the orphan list * This is safe: on error we're going to ignore the orphan list
* anyway on the next recovery. */ * anyway on the next recovery. */
if (!err) if (!err)
list_add(&EXT3_I(inode)->i_orphan, &EXT3_SB(sb)->s_orphan); list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
jbd_debug(4, "superblock will point to %lu\n", inode->i_ino); jbd_debug(4, "superblock will point to %lu\n", inode->i_ino);
jbd_debug(4, "orphan inode %lu will point to %d\n", jbd_debug(4, "orphan inode %lu will point to %d\n",
inode->i_ino, NEXT_ORPHAN(inode)); inode->i_ino, NEXT_ORPHAN(inode));
out_unlock: out_unlock:
unlock_super(sb); unlock_super(sb);
ext3_std_error(inode->i_sb, err); ext4_std_error(inode->i_sb, err);
return err; return err;
} }
/* /*
* ext3_orphan_del() removes an unlinked or truncated inode from the list * ext4_orphan_del() removes an unlinked or truncated inode from the list
* of such inodes stored on disk, because it is finally being cleaned up. * of such inodes stored on disk, because it is finally being cleaned up.
*/ */
int ext3_orphan_del(handle_t *handle, struct inode *inode) int ext4_orphan_del(handle_t *handle, struct inode *inode)
{ {
struct list_head *prev; struct list_head *prev;
struct ext3_inode_info *ei = EXT3_I(inode); struct ext4_inode_info *ei = EXT4_I(inode);
struct ext3_sb_info *sbi; struct ext4_sb_info *sbi;
unsigned long ino_next; unsigned long ino_next;
struct ext3_iloc iloc; struct ext4_iloc iloc;
int err = 0; int err = 0;
lock_super(inode->i_sb); lock_super(inode->i_sb);
...@@ -1950,7 +1950,7 @@ int ext3_orphan_del(handle_t *handle, struct inode *inode) ...@@ -1950,7 +1950,7 @@ int ext3_orphan_del(handle_t *handle, struct inode *inode)
ino_next = NEXT_ORPHAN(inode); ino_next = NEXT_ORPHAN(inode);
prev = ei->i_orphan.prev; prev = ei->i_orphan.prev;
sbi = EXT3_SB(inode->i_sb); sbi = EXT4_SB(inode->i_sb);
jbd_debug(4, "remove inode %lu from orphan list\n", inode->i_ino); jbd_debug(4, "remove inode %lu from orphan list\n", inode->i_ino);
...@@ -1963,38 +1963,38 @@ int ext3_orphan_del(handle_t *handle, struct inode *inode) ...@@ -1963,38 +1963,38 @@ int ext3_orphan_del(handle_t *handle, struct inode *inode)
if (!handle) if (!handle)
goto out; goto out;
err = ext3_reserve_inode_write(handle, inode, &iloc); err = ext4_reserve_inode_write(handle, inode, &iloc);
if (err) if (err)
goto out_err; goto out_err;
if (prev == &sbi->s_orphan) { if (prev == &sbi->s_orphan) {
jbd_debug(4, "superblock will point to %lu\n", ino_next); jbd_debug(4, "superblock will point to %lu\n", ino_next);
BUFFER_TRACE(sbi->s_sbh, "get_write_access"); BUFFER_TRACE(sbi->s_sbh, "get_write_access");
err = ext3_journal_get_write_access(handle, sbi->s_sbh); err = ext4_journal_get_write_access(handle, sbi->s_sbh);
if (err) if (err)
goto out_brelse; goto out_brelse;
sbi->s_es->s_last_orphan = cpu_to_le32(ino_next); sbi->s_es->s_last_orphan = cpu_to_le32(ino_next);
err = ext3_journal_dirty_metadata(handle, sbi->s_sbh); err = ext4_journal_dirty_metadata(handle, sbi->s_sbh);
} else { } else {
struct ext3_iloc iloc2; struct ext4_iloc iloc2;
struct inode *i_prev = struct inode *i_prev =
&list_entry(prev, struct ext3_inode_info, i_orphan)->vfs_inode; &list_entry(prev, struct ext4_inode_info, i_orphan)->vfs_inode;
jbd_debug(4, "orphan inode %lu will point to %lu\n", jbd_debug(4, "orphan inode %lu will point to %lu\n",
i_prev->i_ino, ino_next); i_prev->i_ino, ino_next);
err = ext3_reserve_inode_write(handle, i_prev, &iloc2); err = ext4_reserve_inode_write(handle, i_prev, &iloc2);
if (err) if (err)
goto out_brelse; goto out_brelse;
NEXT_ORPHAN(i_prev) = ino_next; NEXT_ORPHAN(i_prev) = ino_next;
err = ext3_mark_iloc_dirty(handle, i_prev, &iloc2); err = ext4_mark_iloc_dirty(handle, i_prev, &iloc2);
} }
if (err) if (err)
goto out_brelse; goto out_brelse;
NEXT_ORPHAN(inode) = 0; NEXT_ORPHAN(inode) = 0;
err = ext3_mark_iloc_dirty(handle, inode, &iloc); err = ext4_mark_iloc_dirty(handle, inode, &iloc);
out_err: out_err:
ext3_std_error(inode->i_sb, err); ext4_std_error(inode->i_sb, err);
out: out:
unlock_super(inode->i_sb); unlock_super(inode->i_sb);
return err; return err;
...@@ -2004,23 +2004,23 @@ int ext3_orphan_del(handle_t *handle, struct inode *inode) ...@@ -2004,23 +2004,23 @@ int ext3_orphan_del(handle_t *handle, struct inode *inode)
goto out_err; goto out_err;
} }
static int ext3_rmdir (struct inode * dir, struct dentry *dentry) static int ext4_rmdir (struct inode * dir, struct dentry *dentry)
{ {
int retval; int retval;
struct inode * inode; struct inode * inode;
struct buffer_head * bh; struct buffer_head * bh;
struct ext3_dir_entry_2 * de; struct ext4_dir_entry_2 * de;
handle_t *handle; handle_t *handle;
/* Initialize quotas before so that eventual writes go in /* Initialize quotas before so that eventual writes go in
* separate transaction */ * separate transaction */
DQUOT_INIT(dentry->d_inode); DQUOT_INIT(dentry->d_inode);
handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb)); handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb));
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
retval = -ENOENT; retval = -ENOENT;
bh = ext3_find_entry (dentry, &de); bh = ext4_find_entry (dentry, &de);
if (!bh) if (!bh)
goto end_rmdir; goto end_rmdir;
...@@ -2037,11 +2037,11 @@ static int ext3_rmdir (struct inode * dir, struct dentry *dentry) ...@@ -2037,11 +2037,11 @@ static int ext3_rmdir (struct inode * dir, struct dentry *dentry)
if (!empty_dir (inode)) if (!empty_dir (inode))
goto end_rmdir; goto end_rmdir;
retval = ext3_delete_entry(handle, dir, de, bh); retval = ext4_delete_entry(handle, dir, de, bh);
if (retval) if (retval)
goto end_rmdir; goto end_rmdir;
if (inode->i_nlink != 2) if (inode->i_nlink != 2)
ext3_warning (inode->i_sb, "ext3_rmdir", ext4_warning (inode->i_sb, "ext4_rmdir",
"empty directory has nlink!=2 (%d)", "empty directory has nlink!=2 (%d)",
inode->i_nlink); inode->i_nlink);
inode->i_version++; inode->i_version++;
...@@ -2050,31 +2050,31 @@ static int ext3_rmdir (struct inode * dir, struct dentry *dentry) ...@@ -2050,31 +2050,31 @@ static int ext3_rmdir (struct inode * dir, struct dentry *dentry)
* zero will ensure that the right thing happens during any * zero will ensure that the right thing happens during any
* recovery. */ * recovery. */
inode->i_size = 0; inode->i_size = 0;
ext3_orphan_add(handle, inode); ext4_orphan_add(handle, inode);
inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC; inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
ext3_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
drop_nlink(dir); drop_nlink(dir);
ext3_update_dx_flag(dir); ext4_update_dx_flag(dir);
ext3_mark_inode_dirty(handle, dir); ext4_mark_inode_dirty(handle, dir);
end_rmdir: end_rmdir:
ext3_journal_stop(handle); ext4_journal_stop(handle);
brelse (bh); brelse (bh);
return retval; return retval;
} }
static int ext3_unlink(struct inode * dir, struct dentry *dentry) static int ext4_unlink(struct inode * dir, struct dentry *dentry)
{ {
int retval; int retval;
struct inode * inode; struct inode * inode;
struct buffer_head * bh; struct buffer_head * bh;
struct ext3_dir_entry_2 * de; struct ext4_dir_entry_2 * de;
handle_t *handle; handle_t *handle;
/* Initialize quotas before so that eventual writes go /* Initialize quotas before so that eventual writes go
* in separate transaction */ * in separate transaction */
DQUOT_INIT(dentry->d_inode); DQUOT_INIT(dentry->d_inode);
handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb)); handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb));
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
...@@ -2082,7 +2082,7 @@ static int ext3_unlink(struct inode * dir, struct dentry *dentry) ...@@ -2082,7 +2082,7 @@ static int ext3_unlink(struct inode * dir, struct dentry *dentry)
handle->h_sync = 1; handle->h_sync = 1;
retval = -ENOENT; retval = -ENOENT;
bh = ext3_find_entry (dentry, &de); bh = ext4_find_entry (dentry, &de);
if (!bh) if (!bh)
goto end_unlink; goto end_unlink;
...@@ -2093,31 +2093,31 @@ static int ext3_unlink(struct inode * dir, struct dentry *dentry) ...@@ -2093,31 +2093,31 @@ static int ext3_unlink(struct inode * dir, struct dentry *dentry)
goto end_unlink; goto end_unlink;
if (!inode->i_nlink) { if (!inode->i_nlink) {
ext3_warning (inode->i_sb, "ext3_unlink", ext4_warning (inode->i_sb, "ext4_unlink",
"Deleting nonexistent file (%lu), %d", "Deleting nonexistent file (%lu), %d",
inode->i_ino, inode->i_nlink); inode->i_ino, inode->i_nlink);
inode->i_nlink = 1; inode->i_nlink = 1;
} }
retval = ext3_delete_entry(handle, dir, de, bh); retval = ext4_delete_entry(handle, dir, de, bh);
if (retval) if (retval)
goto end_unlink; goto end_unlink;
dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC; dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
ext3_update_dx_flag(dir); ext4_update_dx_flag(dir);
ext3_mark_inode_dirty(handle, dir); ext4_mark_inode_dirty(handle, dir);
drop_nlink(inode); drop_nlink(inode);
if (!inode->i_nlink) if (!inode->i_nlink)
ext3_orphan_add(handle, inode); ext4_orphan_add(handle, inode);
inode->i_ctime = dir->i_ctime; inode->i_ctime = dir->i_ctime;
ext3_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
retval = 0; retval = 0;
end_unlink: end_unlink:
ext3_journal_stop(handle); ext4_journal_stop(handle);
brelse (bh); brelse (bh);
return retval; return retval;
} }
static int ext3_symlink (struct inode * dir, static int ext4_symlink (struct inode * dir,
struct dentry *dentry, const char * symname) struct dentry *dentry, const char * symname)
{ {
handle_t *handle; handle_t *handle;
...@@ -2129,63 +2129,63 @@ static int ext3_symlink (struct inode * dir, ...@@ -2129,63 +2129,63 @@ static int ext3_symlink (struct inode * dir,
return -ENAMETOOLONG; return -ENAMETOOLONG;
retry: retry:
handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
EXT3_INDEX_EXTRA_TRANS_BLOCKS + 5 + EXT4_INDEX_EXTRA_TRANS_BLOCKS + 5 +
2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); 2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
if (IS_DIRSYNC(dir)) if (IS_DIRSYNC(dir))
handle->h_sync = 1; handle->h_sync = 1;
inode = ext3_new_inode (handle, dir, S_IFLNK|S_IRWXUGO); inode = ext4_new_inode (handle, dir, S_IFLNK|S_IRWXUGO);
err = PTR_ERR(inode); err = PTR_ERR(inode);
if (IS_ERR(inode)) if (IS_ERR(inode))
goto out_stop; goto out_stop;
if (l > sizeof (EXT3_I(inode)->i_data)) { if (l > sizeof (EXT4_I(inode)->i_data)) {
inode->i_op = &ext3_symlink_inode_operations; inode->i_op = &ext4_symlink_inode_operations;
ext3_set_aops(inode); ext4_set_aops(inode);
/* /*
* page_symlink() calls into ext3_prepare/commit_write. * page_symlink() calls into ext4_prepare/commit_write.
* We have a transaction open. All is sweetness. It also sets * We have a transaction open. All is sweetness. It also sets
* i_size in generic_commit_write(). * i_size in generic_commit_write().
*/ */
err = __page_symlink(inode, symname, l, err = __page_symlink(inode, symname, l,
mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS); mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS);
if (err) { if (err) {
ext3_dec_count(handle, inode); ext4_dec_count(handle, inode);
ext3_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
iput (inode); iput (inode);
goto out_stop; goto out_stop;
} }
} else { } else {
inode->i_op = &ext3_fast_symlink_inode_operations; inode->i_op = &ext4_fast_symlink_inode_operations;
memcpy((char*)&EXT3_I(inode)->i_data,symname,l); memcpy((char*)&EXT4_I(inode)->i_data,symname,l);
inode->i_size = l-1; inode->i_size = l-1;
} }
EXT3_I(inode)->i_disksize = inode->i_size; EXT4_I(inode)->i_disksize = inode->i_size;
err = ext3_add_nondir(handle, dentry, inode); err = ext4_add_nondir(handle, dentry, inode);
out_stop: out_stop:
ext3_journal_stop(handle); ext4_journal_stop(handle);
if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries)) if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
goto retry; goto retry;
return err; return err;
} }
static int ext3_link (struct dentry * old_dentry, static int ext4_link (struct dentry * old_dentry,
struct inode * dir, struct dentry *dentry) struct inode * dir, struct dentry *dentry)
{ {
handle_t *handle; handle_t *handle;
struct inode *inode = old_dentry->d_inode; struct inode *inode = old_dentry->d_inode;
int err, retries = 0; int err, retries = 0;
if (inode->i_nlink >= EXT3_LINK_MAX) if (inode->i_nlink >= EXT4_LINK_MAX)
return -EMLINK; return -EMLINK;
retry: retry:
handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
EXT3_INDEX_EXTRA_TRANS_BLOCKS); EXT4_INDEX_EXTRA_TRANS_BLOCKS);
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
...@@ -2193,31 +2193,31 @@ static int ext3_link (struct dentry * old_dentry, ...@@ -2193,31 +2193,31 @@ static int ext3_link (struct dentry * old_dentry,
handle->h_sync = 1; handle->h_sync = 1;
inode->i_ctime = CURRENT_TIME_SEC; inode->i_ctime = CURRENT_TIME_SEC;
ext3_inc_count(handle, inode); ext4_inc_count(handle, inode);
atomic_inc(&inode->i_count); atomic_inc(&inode->i_count);
err = ext3_add_nondir(handle, dentry, inode); err = ext4_add_nondir(handle, dentry, inode);
ext3_journal_stop(handle); ext4_journal_stop(handle);
if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries)) if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
goto retry; goto retry;
return err; return err;
} }
#define PARENT_INO(buffer) \ #define PARENT_INO(buffer) \
((struct ext3_dir_entry_2 *) ((char *) buffer + \ ((struct ext4_dir_entry_2 *) ((char *) buffer + \
le16_to_cpu(((struct ext3_dir_entry_2 *) buffer)->rec_len)))->inode le16_to_cpu(((struct ext4_dir_entry_2 *) buffer)->rec_len)))->inode
/* /*
* Anybody can rename anything with this: the permission checks are left to the * Anybody can rename anything with this: the permission checks are left to the
* higher-level routines. * higher-level routines.
*/ */
static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry, static int ext4_rename (struct inode * old_dir, struct dentry *old_dentry,
struct inode * new_dir,struct dentry *new_dentry) struct inode * new_dir,struct dentry *new_dentry)
{ {
handle_t *handle; handle_t *handle;
struct inode * old_inode, * new_inode; struct inode * old_inode, * new_inode;
struct buffer_head * old_bh, * new_bh, * dir_bh; struct buffer_head * old_bh, * new_bh, * dir_bh;
struct ext3_dir_entry_2 * old_de, * new_de; struct ext4_dir_entry_2 * old_de, * new_de;
int retval; int retval;
old_bh = new_bh = dir_bh = NULL; old_bh = new_bh = dir_bh = NULL;
...@@ -2226,16 +2226,16 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry, ...@@ -2226,16 +2226,16 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
* in separate transaction */ * in separate transaction */
if (new_dentry->d_inode) if (new_dentry->d_inode)
DQUOT_INIT(new_dentry->d_inode); DQUOT_INIT(new_dentry->d_inode);
handle = ext3_journal_start(old_dir, 2 * handle = ext4_journal_start(old_dir, 2 *
EXT3_DATA_TRANS_BLOCKS(old_dir->i_sb) + EXT4_DATA_TRANS_BLOCKS(old_dir->i_sb) +
EXT3_INDEX_EXTRA_TRANS_BLOCKS + 2); EXT4_INDEX_EXTRA_TRANS_BLOCKS + 2);
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir)) if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
handle->h_sync = 1; handle->h_sync = 1;
old_bh = ext3_find_entry (old_dentry, &old_de); old_bh = ext4_find_entry (old_dentry, &old_de);
/* /*
* Check for inode number is _not_ due to possible IO errors. * Check for inode number is _not_ due to possible IO errors.
* We might rmdir the source, keep it as pwd of some process * 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,7 +2248,7 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
goto end_rename; goto end_rename;
new_inode = new_dentry->d_inode; new_inode = new_dentry->d_inode;
new_bh = ext3_find_entry (new_dentry, &new_de); new_bh = ext4_find_entry (new_dentry, &new_de);
if (new_bh) { if (new_bh) {
if (!new_inode) { if (!new_inode) {
brelse (new_bh); brelse (new_bh);
...@@ -2262,30 +2262,30 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry, ...@@ -2262,30 +2262,30 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
goto end_rename; goto end_rename;
} }
retval = -EIO; retval = -EIO;
dir_bh = ext3_bread (handle, old_inode, 0, 0, &retval); dir_bh = ext4_bread (handle, old_inode, 0, 0, &retval);
if (!dir_bh) if (!dir_bh)
goto end_rename; goto end_rename;
if (le32_to_cpu(PARENT_INO(dir_bh->b_data)) != old_dir->i_ino) if (le32_to_cpu(PARENT_INO(dir_bh->b_data)) != old_dir->i_ino)
goto end_rename; goto end_rename;
retval = -EMLINK; retval = -EMLINK;
if (!new_inode && new_dir!=old_dir && if (!new_inode && new_dir!=old_dir &&
new_dir->i_nlink >= EXT3_LINK_MAX) new_dir->i_nlink >= EXT4_LINK_MAX)
goto end_rename; goto end_rename;
} }
if (!new_bh) { if (!new_bh) {
retval = ext3_add_entry (handle, new_dentry, old_inode); retval = ext4_add_entry (handle, new_dentry, old_inode);
if (retval) if (retval)
goto end_rename; goto end_rename;
} else { } else {
BUFFER_TRACE(new_bh, "get write access"); BUFFER_TRACE(new_bh, "get write access");
ext3_journal_get_write_access(handle, new_bh); ext4_journal_get_write_access(handle, new_bh);
new_de->inode = cpu_to_le32(old_inode->i_ino); new_de->inode = cpu_to_le32(old_inode->i_ino);
if (EXT3_HAS_INCOMPAT_FEATURE(new_dir->i_sb, if (EXT4_HAS_INCOMPAT_FEATURE(new_dir->i_sb,
EXT3_FEATURE_INCOMPAT_FILETYPE)) EXT4_FEATURE_INCOMPAT_FILETYPE))
new_de->file_type = old_de->file_type; new_de->file_type = old_de->file_type;
new_dir->i_version++; new_dir->i_version++;
BUFFER_TRACE(new_bh, "call ext3_journal_dirty_metadata"); BUFFER_TRACE(new_bh, "call ext4_journal_dirty_metadata");
ext3_journal_dirty_metadata(handle, new_bh); ext4_journal_dirty_metadata(handle, new_bh);
brelse(new_bh); brelse(new_bh);
new_bh = NULL; new_bh = NULL;
} }
...@@ -2295,7 +2295,7 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry, ...@@ -2295,7 +2295,7 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
* rename. * rename.
*/ */
old_inode->i_ctime = CURRENT_TIME_SEC; old_inode->i_ctime = CURRENT_TIME_SEC;
ext3_mark_inode_dirty(handle, old_inode); ext4_mark_inode_dirty(handle, old_inode);
/* /*
* ok, that's it * ok, that's it
...@@ -2303,24 +2303,24 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry, ...@@ -2303,24 +2303,24 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
if (le32_to_cpu(old_de->inode) != old_inode->i_ino || if (le32_to_cpu(old_de->inode) != old_inode->i_ino ||
old_de->name_len != old_dentry->d_name.len || old_de->name_len != old_dentry->d_name.len ||
strncmp(old_de->name, old_dentry->d_name.name, old_de->name_len) || strncmp(old_de->name, old_dentry->d_name.name, old_de->name_len) ||
(retval = ext3_delete_entry(handle, old_dir, (retval = ext4_delete_entry(handle, old_dir,
old_de, old_bh)) == -ENOENT) { old_de, old_bh)) == -ENOENT) {
/* old_de could have moved from under us during htree split, so /* old_de could have moved from under us during htree split, so
* make sure that we are deleting the right entry. We might * make sure that we are deleting the right entry. We might
* also be pointing to a stale entry in the unused part of * also be pointing to a stale entry in the unused part of
* old_bh so just checking inum and the name isn't enough. */ * old_bh so just checking inum and the name isn't enough. */
struct buffer_head *old_bh2; struct buffer_head *old_bh2;
struct ext3_dir_entry_2 *old_de2; struct ext4_dir_entry_2 *old_de2;
old_bh2 = ext3_find_entry(old_dentry, &old_de2); old_bh2 = ext4_find_entry(old_dentry, &old_de2);
if (old_bh2) { if (old_bh2) {
retval = ext3_delete_entry(handle, old_dir, retval = ext4_delete_entry(handle, old_dir,
old_de2, old_bh2); old_de2, old_bh2);
brelse(old_bh2); brelse(old_bh2);
} }
} }
if (retval) { if (retval) {
ext3_warning(old_dir->i_sb, "ext3_rename", ext4_warning(old_dir->i_sb, "ext4_rename",
"Deleting old file (%lu), %d, error=%d", "Deleting old file (%lu), %d, error=%d",
old_dir->i_ino, old_dir->i_nlink, retval); old_dir->i_ino, old_dir->i_nlink, retval);
} }
...@@ -2330,27 +2330,27 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry, ...@@ -2330,27 +2330,27 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
new_inode->i_ctime = CURRENT_TIME_SEC; new_inode->i_ctime = CURRENT_TIME_SEC;
} }
old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC; old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC;
ext3_update_dx_flag(old_dir); ext4_update_dx_flag(old_dir);
if (dir_bh) { if (dir_bh) {
BUFFER_TRACE(dir_bh, "get_write_access"); BUFFER_TRACE(dir_bh, "get_write_access");
ext3_journal_get_write_access(handle, dir_bh); ext4_journal_get_write_access(handle, dir_bh);
PARENT_INO(dir_bh->b_data) = cpu_to_le32(new_dir->i_ino); PARENT_INO(dir_bh->b_data) = cpu_to_le32(new_dir->i_ino);
BUFFER_TRACE(dir_bh, "call ext3_journal_dirty_metadata"); BUFFER_TRACE(dir_bh, "call ext4_journal_dirty_metadata");
ext3_journal_dirty_metadata(handle, dir_bh); ext4_journal_dirty_metadata(handle, dir_bh);
drop_nlink(old_dir); drop_nlink(old_dir);
if (new_inode) { if (new_inode) {
drop_nlink(new_inode); drop_nlink(new_inode);
} else { } else {
inc_nlink(new_dir); inc_nlink(new_dir);
ext3_update_dx_flag(new_dir); ext4_update_dx_flag(new_dir);
ext3_mark_inode_dirty(handle, new_dir); ext4_mark_inode_dirty(handle, new_dir);
} }
} }
ext3_mark_inode_dirty(handle, old_dir); ext4_mark_inode_dirty(handle, old_dir);
if (new_inode) { if (new_inode) {
ext3_mark_inode_dirty(handle, new_inode); ext4_mark_inode_dirty(handle, new_inode);
if (!new_inode->i_nlink) if (!new_inode->i_nlink)
ext3_orphan_add(handle, new_inode); ext4_orphan_add(handle, new_inode);
} }
retval = 0; retval = 0;
...@@ -2358,40 +2358,40 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry, ...@@ -2358,40 +2358,40 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
brelse (dir_bh); brelse (dir_bh);
brelse (old_bh); brelse (old_bh);
brelse (new_bh); brelse (new_bh);
ext3_journal_stop(handle); ext4_journal_stop(handle);
return retval; return retval;
} }
/* /*
* directories can handle most operations... * directories can handle most operations...
*/ */
struct inode_operations ext3_dir_inode_operations = { struct inode_operations ext4_dir_inode_operations = {
.create = ext3_create, .create = ext4_create,
.lookup = ext3_lookup, .lookup = ext4_lookup,
.link = ext3_link, .link = ext4_link,
.unlink = ext3_unlink, .unlink = ext4_unlink,
.symlink = ext3_symlink, .symlink = ext4_symlink,
.mkdir = ext3_mkdir, .mkdir = ext4_mkdir,
.rmdir = ext3_rmdir, .rmdir = ext4_rmdir,
.mknod = ext3_mknod, .mknod = ext4_mknod,
.rename = ext3_rename, .rename = ext4_rename,
.setattr = ext3_setattr, .setattr = ext4_setattr,
#ifdef CONFIG_EXT3_FS_XATTR #ifdef CONFIG_EXT4DEV_FS_XATTR
.setxattr = generic_setxattr, .setxattr = generic_setxattr,
.getxattr = generic_getxattr, .getxattr = generic_getxattr,
.listxattr = ext3_listxattr, .listxattr = ext4_listxattr,
.removexattr = generic_removexattr, .removexattr = generic_removexattr,
#endif #endif
.permission = ext3_permission, .permission = ext4_permission,
}; };
struct inode_operations ext3_special_inode_operations = { struct inode_operations ext4_special_inode_operations = {
.setattr = ext3_setattr, .setattr = ext4_setattr,
#ifdef CONFIG_EXT3_FS_XATTR #ifdef CONFIG_EXT4DEV_FS_XATTR
.setxattr = generic_setxattr, .setxattr = generic_setxattr,
.getxattr = generic_getxattr, .getxattr = generic_getxattr,
.listxattr = ext3_listxattr, .listxattr = ext4_listxattr,
.removexattr = generic_removexattr, .removexattr = generic_removexattr,
#endif #endif
.permission = ext3_permission, .permission = ext4_permission,
}; };
/* linux/fs/ext3/namei.h /* linux/fs/ext4/namei.h
* *
* Copyright (C) 2005 Simtec Electronics * Copyright (C) 2005 Simtec Electronics
* Ben Dooks <ben@simtec.co.uk> * Ben Dooks <ben@simtec.co.uk>
* *
*/ */
extern struct dentry *ext3_get_parent(struct dentry *child); extern struct dentry *ext4_get_parent(struct dentry *child);
/* /*
* linux/fs/ext3/resize.c * linux/fs/ext4/resize.c
* *
* Support for resizing an ext3 filesystem while it is mounted. * Support for resizing an ext4 filesystem while it is mounted.
* *
* Copyright (C) 2001, 2002 Andreas Dilger <adilger@clusterfs.com> * Copyright (C) 2001, 2002 Andreas Dilger <adilger@clusterfs.com>
* *
...@@ -9,11 +9,11 @@ ...@@ -9,11 +9,11 @@
*/ */
#define EXT3FS_DEBUG #define EXT4FS_DEBUG
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/ext3_jbd.h> #include <linux/ext4_jbd.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -23,87 +23,87 @@ ...@@ -23,87 +23,87 @@
#define inside(b, first, last) ((b) >= (first) && (b) < (last)) #define inside(b, first, last) ((b) >= (first) && (b) < (last))
static int verify_group_input(struct super_block *sb, static int verify_group_input(struct super_block *sb,
struct ext3_new_group_data *input) struct ext4_new_group_data *input)
{ {
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
struct ext3_super_block *es = sbi->s_es; struct ext4_super_block *es = sbi->s_es;
ext3_fsblk_t start = le32_to_cpu(es->s_blocks_count); ext4_fsblk_t start = le32_to_cpu(es->s_blocks_count);
ext3_fsblk_t end = start + input->blocks_count; ext4_fsblk_t end = start + input->blocks_count;
unsigned group = input->group; unsigned group = input->group;
ext3_fsblk_t itend = input->inode_table + sbi->s_itb_per_group; ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
unsigned overhead = ext3_bg_has_super(sb, group) ? unsigned overhead = ext4_bg_has_super(sb, group) ?
(1 + ext3_bg_num_gdb(sb, group) + (1 + ext4_bg_num_gdb(sb, group) +
le16_to_cpu(es->s_reserved_gdt_blocks)) : 0; le16_to_cpu(es->s_reserved_gdt_blocks)) : 0;
ext3_fsblk_t metaend = start + overhead; ext4_fsblk_t metaend = start + overhead;
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
ext3_grpblk_t free_blocks_count; ext4_grpblk_t free_blocks_count;
int err = -EINVAL; int err = -EINVAL;
input->free_blocks_count = free_blocks_count = input->free_blocks_count = free_blocks_count =
input->blocks_count - 2 - overhead - sbi->s_itb_per_group; input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
if (test_opt(sb, DEBUG)) if (test_opt(sb, DEBUG))
printk(KERN_DEBUG "EXT3-fs: adding %s group %u: %u blocks " printk(KERN_DEBUG "EXT4-fs: adding %s group %u: %u blocks "
"(%d free, %u reserved)\n", "(%d free, %u reserved)\n",
ext3_bg_has_super(sb, input->group) ? "normal" : ext4_bg_has_super(sb, input->group) ? "normal" :
"no-super", input->group, input->blocks_count, "no-super", input->group, input->blocks_count,
free_blocks_count, input->reserved_blocks); free_blocks_count, input->reserved_blocks);
if (group != sbi->s_groups_count) if (group != sbi->s_groups_count)
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"Cannot add at group %u (only %lu groups)", "Cannot add at group %u (only %lu groups)",
input->group, sbi->s_groups_count); input->group, sbi->s_groups_count);
else if ((start - le32_to_cpu(es->s_first_data_block)) % else if ((start - le32_to_cpu(es->s_first_data_block)) %
EXT3_BLOCKS_PER_GROUP(sb)) EXT4_BLOCKS_PER_GROUP(sb))
ext3_warning(sb, __FUNCTION__, "Last group not full"); ext4_warning(sb, __FUNCTION__, "Last group not full");
else if (input->reserved_blocks > input->blocks_count / 5) else if (input->reserved_blocks > input->blocks_count / 5)
ext3_warning(sb, __FUNCTION__, "Reserved blocks too high (%u)", ext4_warning(sb, __FUNCTION__, "Reserved blocks too high (%u)",
input->reserved_blocks); input->reserved_blocks);
else if (free_blocks_count < 0) else if (free_blocks_count < 0)
ext3_warning(sb, __FUNCTION__, "Bad blocks count %u", ext4_warning(sb, __FUNCTION__, "Bad blocks count %u",
input->blocks_count); input->blocks_count);
else if (!(bh = sb_bread(sb, end - 1))) else if (!(bh = sb_bread(sb, end - 1)))
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"Cannot read last block ("E3FSBLK")", "Cannot read last block ("E3FSBLK")",
end - 1); end - 1);
else if (outside(input->block_bitmap, start, end)) else if (outside(input->block_bitmap, start, end))
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"Block bitmap not in group (block %u)", "Block bitmap not in group (block %u)",
input->block_bitmap); input->block_bitmap);
else if (outside(input->inode_bitmap, start, end)) else if (outside(input->inode_bitmap, start, end))
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"Inode bitmap not in group (block %u)", "Inode bitmap not in group (block %u)",
input->inode_bitmap); input->inode_bitmap);
else if (outside(input->inode_table, start, end) || else if (outside(input->inode_table, start, end) ||
outside(itend - 1, start, end)) outside(itend - 1, start, end))
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"Inode table not in group (blocks %u-"E3FSBLK")", "Inode table not in group (blocks %u-"E3FSBLK")",
input->inode_table, itend - 1); input->inode_table, itend - 1);
else if (input->inode_bitmap == input->block_bitmap) else if (input->inode_bitmap == input->block_bitmap)
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"Block bitmap same as inode bitmap (%u)", "Block bitmap same as inode bitmap (%u)",
input->block_bitmap); input->block_bitmap);
else if (inside(input->block_bitmap, input->inode_table, itend)) else if (inside(input->block_bitmap, input->inode_table, itend))
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"Block bitmap (%u) in inode table (%u-"E3FSBLK")", "Block bitmap (%u) in inode table (%u-"E3FSBLK")",
input->block_bitmap, input->inode_table, itend-1); input->block_bitmap, input->inode_table, itend-1);
else if (inside(input->inode_bitmap, input->inode_table, itend)) else if (inside(input->inode_bitmap, input->inode_table, itend))
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"Inode bitmap (%u) in inode table (%u-"E3FSBLK")", "Inode bitmap (%u) in inode table (%u-"E3FSBLK")",
input->inode_bitmap, input->inode_table, itend-1); input->inode_bitmap, input->inode_table, itend-1);
else if (inside(input->block_bitmap, start, metaend)) else if (inside(input->block_bitmap, start, metaend))
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"Block bitmap (%u) in GDT table" "Block bitmap (%u) in GDT table"
" ("E3FSBLK"-"E3FSBLK")", " ("E3FSBLK"-"E3FSBLK")",
input->block_bitmap, start, metaend - 1); input->block_bitmap, start, metaend - 1);
else if (inside(input->inode_bitmap, start, metaend)) else if (inside(input->inode_bitmap, start, metaend))
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"Inode bitmap (%u) in GDT table" "Inode bitmap (%u) in GDT table"
" ("E3FSBLK"-"E3FSBLK")", " ("E3FSBLK"-"E3FSBLK")",
input->inode_bitmap, start, metaend - 1); input->inode_bitmap, start, metaend - 1);
else if (inside(input->inode_table, start, metaend) || else if (inside(input->inode_table, start, metaend) ||
inside(itend - 1, start, metaend)) inside(itend - 1, start, metaend))
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"Inode table (%u-"E3FSBLK") overlaps" "Inode table (%u-"E3FSBLK") overlaps"
"GDT table ("E3FSBLK"-"E3FSBLK")", "GDT table ("E3FSBLK"-"E3FSBLK")",
input->inode_table, itend - 1, start, metaend - 1); input->inode_table, itend - 1, start, metaend - 1);
...@@ -115,7 +115,7 @@ static int verify_group_input(struct super_block *sb, ...@@ -115,7 +115,7 @@ static int verify_group_input(struct super_block *sb,
} }
static struct buffer_head *bclean(handle_t *handle, struct super_block *sb, static struct buffer_head *bclean(handle_t *handle, struct super_block *sb,
ext3_fsblk_t blk) ext4_fsblk_t blk)
{ {
struct buffer_head *bh; struct buffer_head *bh;
int err; int err;
...@@ -123,7 +123,7 @@ static struct buffer_head *bclean(handle_t *handle, struct super_block *sb, ...@@ -123,7 +123,7 @@ static struct buffer_head *bclean(handle_t *handle, struct super_block *sb,
bh = sb_getblk(sb, blk); bh = sb_getblk(sb, blk);
if (!bh) if (!bh)
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
if ((err = ext3_journal_get_write_access(handle, bh))) { if ((err = ext4_journal_get_write_access(handle, bh))) {
brelse(bh); brelse(bh);
bh = ERR_PTR(err); bh = ERR_PTR(err);
} else { } else {
...@@ -148,9 +148,9 @@ static void mark_bitmap_end(int start_bit, int end_bit, char *bitmap) ...@@ -148,9 +148,9 @@ static void mark_bitmap_end(int start_bit, int end_bit, char *bitmap)
if (start_bit >= end_bit) if (start_bit >= end_bit)
return; return;
ext3_debug("mark end bits +%d through +%d used\n", start_bit, end_bit); ext4_debug("mark end bits +%d through +%d used\n", start_bit, end_bit);
for (i = start_bit; i < ((start_bit + 7) & ~7UL); i++) for (i = start_bit; i < ((start_bit + 7) & ~7UL); i++)
ext3_set_bit(i, bitmap); ext4_set_bit(i, bitmap);
if (i < end_bit) if (i < end_bit)
memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3); memset(bitmap + (i >> 3), 0xff, (end_bit - i) >> 3);
} }
...@@ -163,21 +163,21 @@ static void mark_bitmap_end(int start_bit, int end_bit, char *bitmap) ...@@ -163,21 +163,21 @@ static void mark_bitmap_end(int start_bit, int end_bit, char *bitmap)
* If any part of this fails, we simply abort the resize. * If any part of this fails, we simply abort the resize.
*/ */
static int setup_new_group_blocks(struct super_block *sb, static int setup_new_group_blocks(struct super_block *sb,
struct ext3_new_group_data *input) struct ext4_new_group_data *input)
{ {
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
ext3_fsblk_t start = ext3_group_first_block_no(sb, input->group); ext4_fsblk_t start = ext4_group_first_block_no(sb, input->group);
int reserved_gdb = ext3_bg_has_super(sb, input->group) ? int reserved_gdb = ext4_bg_has_super(sb, input->group) ?
le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) : 0; le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) : 0;
unsigned long gdblocks = ext3_bg_num_gdb(sb, input->group); unsigned long gdblocks = ext4_bg_num_gdb(sb, input->group);
struct buffer_head *bh; struct buffer_head *bh;
handle_t *handle; handle_t *handle;
ext3_fsblk_t block; ext4_fsblk_t block;
ext3_grpblk_t bit; ext4_grpblk_t bit;
int i; int i;
int err = 0, err2; int err = 0, err2;
handle = ext3_journal_start_sb(sb, reserved_gdb + gdblocks + handle = ext4_journal_start_sb(sb, reserved_gdb + gdblocks +
2 + sbi->s_itb_per_group); 2 + sbi->s_itb_per_group);
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
...@@ -193,9 +193,9 @@ static int setup_new_group_blocks(struct super_block *sb, ...@@ -193,9 +193,9 @@ static int setup_new_group_blocks(struct super_block *sb,
goto exit_journal; goto exit_journal;
} }
if (ext3_bg_has_super(sb, input->group)) { if (ext4_bg_has_super(sb, input->group)) {
ext3_debug("mark backup superblock %#04lx (+0)\n", start); ext4_debug("mark backup superblock %#04lx (+0)\n", start);
ext3_set_bit(0, bh->b_data); ext4_set_bit(0, bh->b_data);
} }
/* Copy all of the GDT blocks into the backup in this group */ /* 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,14 +203,14 @@ static int setup_new_group_blocks(struct super_block *sb,
i < gdblocks; i++, block++, bit++) { i < gdblocks; i++, block++, bit++) {
struct buffer_head *gdb; struct buffer_head *gdb;
ext3_debug("update backup group %#04lx (+%d)\n", block, bit); ext4_debug("update backup group %#04lx (+%d)\n", block, bit);
gdb = sb_getblk(sb, block); gdb = sb_getblk(sb, block);
if (!gdb) { if (!gdb) {
err = -EIO; err = -EIO;
goto exit_bh; goto exit_bh;
} }
if ((err = ext3_journal_get_write_access(handle, gdb))) { if ((err = ext4_journal_get_write_access(handle, gdb))) {
brelse(gdb); brelse(gdb);
goto exit_bh; goto exit_bh;
} }
...@@ -218,8 +218,8 @@ static int setup_new_group_blocks(struct super_block *sb, ...@@ -218,8 +218,8 @@ static int setup_new_group_blocks(struct super_block *sb,
memcpy(gdb->b_data, sbi->s_group_desc[i]->b_data, bh->b_size); memcpy(gdb->b_data, sbi->s_group_desc[i]->b_data, bh->b_size);
set_buffer_uptodate(gdb); set_buffer_uptodate(gdb);
unlock_buffer(bh); unlock_buffer(bh);
ext3_journal_dirty_metadata(handle, gdb); ext4_journal_dirty_metadata(handle, gdb);
ext3_set_bit(bit, bh->b_data); ext4_set_bit(bit, bh->b_data);
brelse(gdb); brelse(gdb);
} }
...@@ -228,59 +228,59 @@ static int setup_new_group_blocks(struct super_block *sb, ...@@ -228,59 +228,59 @@ static int setup_new_group_blocks(struct super_block *sb,
i < reserved_gdb; i++, block++, bit++) { i < reserved_gdb; i++, block++, bit++) {
struct buffer_head *gdb; struct buffer_head *gdb;
ext3_debug("clear reserved block %#04lx (+%d)\n", block, bit); ext4_debug("clear reserved block %#04lx (+%d)\n", block, bit);
if (IS_ERR(gdb = bclean(handle, sb, block))) { if (IS_ERR(gdb = bclean(handle, sb, block))) {
err = PTR_ERR(bh); err = PTR_ERR(bh);
goto exit_bh; goto exit_bh;
} }
ext3_journal_dirty_metadata(handle, gdb); ext4_journal_dirty_metadata(handle, gdb);
ext3_set_bit(bit, bh->b_data); ext4_set_bit(bit, bh->b_data);
brelse(gdb); brelse(gdb);
} }
ext3_debug("mark block bitmap %#04x (+%ld)\n", input->block_bitmap, ext4_debug("mark block bitmap %#04x (+%ld)\n", input->block_bitmap,
input->block_bitmap - start); input->block_bitmap - start);
ext3_set_bit(input->block_bitmap - start, bh->b_data); ext4_set_bit(input->block_bitmap - start, bh->b_data);
ext3_debug("mark inode bitmap %#04x (+%ld)\n", input->inode_bitmap, ext4_debug("mark inode bitmap %#04x (+%ld)\n", input->inode_bitmap,
input->inode_bitmap - start); input->inode_bitmap - start);
ext3_set_bit(input->inode_bitmap - start, bh->b_data); ext4_set_bit(input->inode_bitmap - start, bh->b_data);
/* Zero out all of the inode table blocks */ /* Zero out all of the inode table blocks */
for (i = 0, block = input->inode_table, bit = block - start; for (i = 0, block = input->inode_table, bit = block - start;
i < sbi->s_itb_per_group; i++, bit++, block++) { i < sbi->s_itb_per_group; i++, bit++, block++) {
struct buffer_head *it; struct buffer_head *it;
ext3_debug("clear inode block %#04lx (+%d)\n", block, bit); ext4_debug("clear inode block %#04lx (+%d)\n", block, bit);
if (IS_ERR(it = bclean(handle, sb, block))) { if (IS_ERR(it = bclean(handle, sb, block))) {
err = PTR_ERR(it); err = PTR_ERR(it);
goto exit_bh; goto exit_bh;
} }
ext3_journal_dirty_metadata(handle, it); ext4_journal_dirty_metadata(handle, it);
brelse(it); brelse(it);
ext3_set_bit(bit, bh->b_data); ext4_set_bit(bit, bh->b_data);
} }
mark_bitmap_end(input->blocks_count, EXT3_BLOCKS_PER_GROUP(sb), mark_bitmap_end(input->blocks_count, EXT4_BLOCKS_PER_GROUP(sb),
bh->b_data); bh->b_data);
ext3_journal_dirty_metadata(handle, bh); ext4_journal_dirty_metadata(handle, bh);
brelse(bh); brelse(bh);
/* Mark unused entries in inode bitmap used */ /* Mark unused entries in inode bitmap used */
ext3_debug("clear inode bitmap %#04x (+%ld)\n", ext4_debug("clear inode bitmap %#04x (+%ld)\n",
input->inode_bitmap, input->inode_bitmap - start); input->inode_bitmap, input->inode_bitmap - start);
if (IS_ERR(bh = bclean(handle, sb, input->inode_bitmap))) { if (IS_ERR(bh = bclean(handle, sb, input->inode_bitmap))) {
err = PTR_ERR(bh); err = PTR_ERR(bh);
goto exit_journal; goto exit_journal;
} }
mark_bitmap_end(EXT3_INODES_PER_GROUP(sb), EXT3_BLOCKS_PER_GROUP(sb), mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), EXT4_BLOCKS_PER_GROUP(sb),
bh->b_data); bh->b_data);
ext3_journal_dirty_metadata(handle, bh); ext4_journal_dirty_metadata(handle, bh);
exit_bh: exit_bh:
brelse(bh); brelse(bh);
exit_journal: exit_journal:
unlock_super(sb); unlock_super(sb);
if ((err2 = ext3_journal_stop(handle)) && !err) if ((err2 = ext4_journal_stop(handle)) && !err)
err = err2; err = err2;
return err; return err;
...@@ -288,20 +288,20 @@ static int setup_new_group_blocks(struct super_block *sb, ...@@ -288,20 +288,20 @@ static int setup_new_group_blocks(struct super_block *sb,
/* /*
* Iterate through the groups which hold BACKUP superblock/GDT copies in an * Iterate through the groups which hold BACKUP superblock/GDT copies in an
* ext3 filesystem. The counters should be initialized to 1, 5, and 7 before * ext4 filesystem. The counters should be initialized to 1, 5, and 7 before
* calling this for the first time. In a sparse filesystem it will be the * calling this for the first time. In a sparse filesystem it will be the
* sequence of powers of 3, 5, and 7: 1, 3, 5, 7, 9, 25, 27, 49, 81, ... * sequence of powers of 3, 5, and 7: 1, 3, 5, 7, 9, 25, 27, 49, 81, ...
* For a non-sparse filesystem it will be every group: 1, 2, 3, 4, ... * For a non-sparse filesystem it will be every group: 1, 2, 3, 4, ...
*/ */
static unsigned ext3_list_backups(struct super_block *sb, unsigned *three, static unsigned ext4_list_backups(struct super_block *sb, unsigned *three,
unsigned *five, unsigned *seven) unsigned *five, unsigned *seven)
{ {
unsigned *min = three; unsigned *min = three;
int mult = 3; int mult = 3;
unsigned ret; unsigned ret;
if (!EXT3_HAS_RO_COMPAT_FEATURE(sb, if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)) { EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
ret = *min; ret = *min;
*min += 1; *min += 1;
return ret; return ret;
...@@ -330,8 +330,8 @@ static unsigned ext3_list_backups(struct super_block *sb, unsigned *three, ...@@ -330,8 +330,8 @@ static unsigned ext3_list_backups(struct super_block *sb, unsigned *three,
static int verify_reserved_gdb(struct super_block *sb, static int verify_reserved_gdb(struct super_block *sb,
struct buffer_head *primary) struct buffer_head *primary)
{ {
const ext3_fsblk_t blk = primary->b_blocknr; const ext4_fsblk_t blk = primary->b_blocknr;
const unsigned long end = EXT3_SB(sb)->s_groups_count; const unsigned long end = EXT4_SB(sb)->s_groups_count;
unsigned three = 1; unsigned three = 1;
unsigned five = 5; unsigned five = 5;
unsigned seven = 7; unsigned seven = 7;
...@@ -339,16 +339,16 @@ static int verify_reserved_gdb(struct super_block *sb, ...@@ -339,16 +339,16 @@ static int verify_reserved_gdb(struct super_block *sb,
__le32 *p = (__le32 *)primary->b_data; __le32 *p = (__le32 *)primary->b_data;
int gdbackups = 0; int gdbackups = 0;
while ((grp = ext3_list_backups(sb, &three, &five, &seven)) < end) { while ((grp = ext4_list_backups(sb, &three, &five, &seven)) < end) {
if (le32_to_cpu(*p++) != grp * EXT3_BLOCKS_PER_GROUP(sb) + blk){ if (le32_to_cpu(*p++) != grp * EXT4_BLOCKS_PER_GROUP(sb) + blk){
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"reserved GDT "E3FSBLK "reserved GDT "E3FSBLK
" missing grp %d ("E3FSBLK")", " missing grp %d ("E3FSBLK")",
blk, grp, blk, grp,
grp * EXT3_BLOCKS_PER_GROUP(sb) + blk); grp * EXT4_BLOCKS_PER_GROUP(sb) + blk);
return -EINVAL; return -EINVAL;
} }
if (++gdbackups > EXT3_ADDR_PER_BLOCK(sb)) if (++gdbackups > EXT4_ADDR_PER_BLOCK(sb))
return -EFBIG; return -EFBIG;
} }
...@@ -369,23 +369,23 @@ static int verify_reserved_gdb(struct super_block *sb, ...@@ -369,23 +369,23 @@ static int verify_reserved_gdb(struct super_block *sb,
* fail once we start modifying the data on disk, because JBD has no rollback. * fail once we start modifying the data on disk, because JBD has no rollback.
*/ */
static int add_new_gdb(handle_t *handle, struct inode *inode, static int add_new_gdb(handle_t *handle, struct inode *inode,
struct ext3_new_group_data *input, struct ext4_new_group_data *input,
struct buffer_head **primary) struct buffer_head **primary)
{ {
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
struct ext3_super_block *es = EXT3_SB(sb)->s_es; struct ext4_super_block *es = EXT4_SB(sb)->s_es;
unsigned long gdb_num = input->group / EXT3_DESC_PER_BLOCK(sb); unsigned long gdb_num = input->group / EXT4_DESC_PER_BLOCK(sb);
ext3_fsblk_t gdblock = EXT3_SB(sb)->s_sbh->b_blocknr + 1 + gdb_num; ext4_fsblk_t gdblock = EXT4_SB(sb)->s_sbh->b_blocknr + 1 + gdb_num;
struct buffer_head **o_group_desc, **n_group_desc; struct buffer_head **o_group_desc, **n_group_desc;
struct buffer_head *dind; struct buffer_head *dind;
int gdbackups; int gdbackups;
struct ext3_iloc iloc; struct ext4_iloc iloc;
__le32 *data; __le32 *data;
int err; int err;
if (test_opt(sb, DEBUG)) if (test_opt(sb, DEBUG))
printk(KERN_DEBUG printk(KERN_DEBUG
"EXT3-fs: ext3_add_new_gdb: adding group block %lu\n", "EXT4-fs: ext4_add_new_gdb: adding group block %lu\n",
gdb_num); gdb_num);
/* /*
...@@ -393,11 +393,11 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, ...@@ -393,11 +393,11 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
* because the user tools have no way of handling this. Probably a * because the user tools have no way of handling this. Probably a
* bad time to do it anyways. * bad time to do it anyways.
*/ */
if (EXT3_SB(sb)->s_sbh->b_blocknr != if (EXT4_SB(sb)->s_sbh->b_blocknr !=
le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block)) { le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"won't resize using backup superblock at %llu", "won't resize using backup superblock at %llu",
(unsigned long long)EXT3_SB(sb)->s_sbh->b_blocknr); (unsigned long long)EXT4_SB(sb)->s_sbh->b_blocknr);
return -EPERM; return -EPERM;
} }
...@@ -410,7 +410,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, ...@@ -410,7 +410,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
goto exit_bh; goto exit_bh;
} }
data = EXT3_I(inode)->i_data + EXT3_DIND_BLOCK; data = EXT4_I(inode)->i_data + EXT4_DIND_BLOCK;
dind = sb_bread(sb, le32_to_cpu(*data)); dind = sb_bread(sb, le32_to_cpu(*data));
if (!dind) { if (!dind) {
err = -EIO; err = -EIO;
...@@ -418,32 +418,32 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, ...@@ -418,32 +418,32 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
} }
data = (__le32 *)dind->b_data; data = (__le32 *)dind->b_data;
if (le32_to_cpu(data[gdb_num % EXT3_ADDR_PER_BLOCK(sb)]) != gdblock) { if (le32_to_cpu(data[gdb_num % EXT4_ADDR_PER_BLOCK(sb)]) != gdblock) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"new group %u GDT block "E3FSBLK" not reserved", "new group %u GDT block "E3FSBLK" not reserved",
input->group, gdblock); input->group, gdblock);
err = -EINVAL; err = -EINVAL;
goto exit_dind; goto exit_dind;
} }
if ((err = ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh))) if ((err = ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh)))
goto exit_dind; goto exit_dind;
if ((err = ext3_journal_get_write_access(handle, *primary))) if ((err = ext4_journal_get_write_access(handle, *primary)))
goto exit_sbh; goto exit_sbh;
if ((err = ext3_journal_get_write_access(handle, dind))) if ((err = ext4_journal_get_write_access(handle, dind)))
goto exit_primary; goto exit_primary;
/* ext3_reserve_inode_write() gets a reference on the iloc */ /* ext4_reserve_inode_write() gets a reference on the iloc */
if ((err = ext3_reserve_inode_write(handle, inode, &iloc))) if ((err = ext4_reserve_inode_write(handle, inode, &iloc)))
goto exit_dindj; goto exit_dindj;
n_group_desc = kmalloc((gdb_num + 1) * sizeof(struct buffer_head *), n_group_desc = kmalloc((gdb_num + 1) * sizeof(struct buffer_head *),
GFP_KERNEL); GFP_KERNEL);
if (!n_group_desc) { if (!n_group_desc) {
err = -ENOMEM; err = -ENOMEM;
ext3_warning (sb, __FUNCTION__, ext4_warning (sb, __FUNCTION__,
"not enough memory for %lu groups", gdb_num + 1); "not enough memory for %lu groups", gdb_num + 1);
goto exit_inode; goto exit_inode;
} }
...@@ -457,43 +457,43 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, ...@@ -457,43 +457,43 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
* these blocks, because they are marked as in-use from being in the * these blocks, because they are marked as in-use from being in the
* reserved inode, and will become GDT blocks (primary and backup). * reserved inode, and will become GDT blocks (primary and backup).
*/ */
data[gdb_num % EXT3_ADDR_PER_BLOCK(sb)] = 0; data[gdb_num % EXT4_ADDR_PER_BLOCK(sb)] = 0;
ext3_journal_dirty_metadata(handle, dind); ext4_journal_dirty_metadata(handle, dind);
brelse(dind); brelse(dind);
inode->i_blocks -= (gdbackups + 1) * sb->s_blocksize >> 9; inode->i_blocks -= (gdbackups + 1) * sb->s_blocksize >> 9;
ext3_mark_iloc_dirty(handle, inode, &iloc); ext4_mark_iloc_dirty(handle, inode, &iloc);
memset((*primary)->b_data, 0, sb->s_blocksize); memset((*primary)->b_data, 0, sb->s_blocksize);
ext3_journal_dirty_metadata(handle, *primary); ext4_journal_dirty_metadata(handle, *primary);
o_group_desc = EXT3_SB(sb)->s_group_desc; o_group_desc = EXT4_SB(sb)->s_group_desc;
memcpy(n_group_desc, o_group_desc, memcpy(n_group_desc, o_group_desc,
EXT3_SB(sb)->s_gdb_count * sizeof(struct buffer_head *)); EXT4_SB(sb)->s_gdb_count * sizeof(struct buffer_head *));
n_group_desc[gdb_num] = *primary; n_group_desc[gdb_num] = *primary;
EXT3_SB(sb)->s_group_desc = n_group_desc; EXT4_SB(sb)->s_group_desc = n_group_desc;
EXT3_SB(sb)->s_gdb_count++; EXT4_SB(sb)->s_gdb_count++;
kfree(o_group_desc); kfree(o_group_desc);
es->s_reserved_gdt_blocks = es->s_reserved_gdt_blocks =
cpu_to_le16(le16_to_cpu(es->s_reserved_gdt_blocks) - 1); cpu_to_le16(le16_to_cpu(es->s_reserved_gdt_blocks) - 1);
ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh);
return 0; return 0;
exit_inode: exit_inode:
//ext3_journal_release_buffer(handle, iloc.bh); //ext4_journal_release_buffer(handle, iloc.bh);
brelse(iloc.bh); brelse(iloc.bh);
exit_dindj: exit_dindj:
//ext3_journal_release_buffer(handle, dind); //ext4_journal_release_buffer(handle, dind);
exit_primary: exit_primary:
//ext3_journal_release_buffer(handle, *primary); //ext4_journal_release_buffer(handle, *primary);
exit_sbh: exit_sbh:
//ext3_journal_release_buffer(handle, *primary); //ext4_journal_release_buffer(handle, *primary);
exit_dind: exit_dind:
brelse(dind); brelse(dind);
exit_bh: exit_bh:
brelse(*primary); brelse(*primary);
ext3_debug("leaving with error %d\n", err); ext4_debug("leaving with error %d\n", err);
return err; return err;
} }
...@@ -511,14 +511,14 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, ...@@ -511,14 +511,14 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
* backup GDT blocks are stored in their reserved primary GDT block. * backup GDT blocks are stored in their reserved primary GDT block.
*/ */
static int reserve_backup_gdb(handle_t *handle, struct inode *inode, static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
struct ext3_new_group_data *input) struct ext4_new_group_data *input)
{ {
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
int reserved_gdb =le16_to_cpu(EXT3_SB(sb)->s_es->s_reserved_gdt_blocks); int reserved_gdb =le16_to_cpu(EXT4_SB(sb)->s_es->s_reserved_gdt_blocks);
struct buffer_head **primary; struct buffer_head **primary;
struct buffer_head *dind; struct buffer_head *dind;
struct ext3_iloc iloc; struct ext4_iloc iloc;
ext3_fsblk_t blk; ext4_fsblk_t blk;
__le32 *data, *end; __le32 *data, *end;
int gdbackups = 0; int gdbackups = 0;
int res, i; int res, i;
...@@ -528,21 +528,21 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode, ...@@ -528,21 +528,21 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
if (!primary) if (!primary)
return -ENOMEM; return -ENOMEM;
data = EXT3_I(inode)->i_data + EXT3_DIND_BLOCK; data = EXT4_I(inode)->i_data + EXT4_DIND_BLOCK;
dind = sb_bread(sb, le32_to_cpu(*data)); dind = sb_bread(sb, le32_to_cpu(*data));
if (!dind) { if (!dind) {
err = -EIO; err = -EIO;
goto exit_free; goto exit_free;
} }
blk = EXT3_SB(sb)->s_sbh->b_blocknr + 1 + EXT3_SB(sb)->s_gdb_count; blk = EXT4_SB(sb)->s_sbh->b_blocknr + 1 + EXT4_SB(sb)->s_gdb_count;
data = (__le32 *)dind->b_data + EXT3_SB(sb)->s_gdb_count; data = (__le32 *)dind->b_data + EXT4_SB(sb)->s_gdb_count;
end = (__le32 *)dind->b_data + EXT3_ADDR_PER_BLOCK(sb); end = (__le32 *)dind->b_data + EXT4_ADDR_PER_BLOCK(sb);
/* Get each reserved primary GDT block and verify it holds backups */ /* Get each reserved primary GDT block and verify it holds backups */
for (res = 0; res < reserved_gdb; res++, blk++) { for (res = 0; res < reserved_gdb; res++, blk++) {
if (le32_to_cpu(*data) != blk) { if (le32_to_cpu(*data) != blk) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"reserved block "E3FSBLK "reserved block "E3FSBLK
" not at offset %ld", " not at offset %ld",
blk, blk,
...@@ -565,24 +565,24 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode, ...@@ -565,24 +565,24 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
} }
for (i = 0; i < reserved_gdb; i++) { for (i = 0; i < reserved_gdb; i++) {
if ((err = ext3_journal_get_write_access(handle, primary[i]))) { if ((err = ext4_journal_get_write_access(handle, primary[i]))) {
/* /*
int j; int j;
for (j = 0; j < i; j++) for (j = 0; j < i; j++)
ext3_journal_release_buffer(handle, primary[j]); ext4_journal_release_buffer(handle, primary[j]);
*/ */
goto exit_bh; goto exit_bh;
} }
} }
if ((err = ext3_reserve_inode_write(handle, inode, &iloc))) if ((err = ext4_reserve_inode_write(handle, inode, &iloc)))
goto exit_bh; goto exit_bh;
/* /*
* Finally we can add each of the reserved backup GDT blocks from * Finally we can add each of the reserved backup GDT blocks from
* the new group to its reserved primary GDT block. * the new group to its reserved primary GDT block.
*/ */
blk = input->group * EXT3_BLOCKS_PER_GROUP(sb); blk = input->group * EXT4_BLOCKS_PER_GROUP(sb);
for (i = 0; i < reserved_gdb; i++) { for (i = 0; i < reserved_gdb; i++) {
int err2; int err2;
data = (__le32 *)primary[i]->b_data; data = (__le32 *)primary[i]->b_data;
...@@ -590,12 +590,12 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode, ...@@ -590,12 +590,12 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
primary[i]->b_blocknr, gdbackups, primary[i]->b_blocknr, gdbackups,
blk + primary[i]->b_blocknr); */ blk + primary[i]->b_blocknr); */
data[gdbackups] = cpu_to_le32(blk + primary[i]->b_blocknr); data[gdbackups] = cpu_to_le32(blk + primary[i]->b_blocknr);
err2 = ext3_journal_dirty_metadata(handle, primary[i]); err2 = ext4_journal_dirty_metadata(handle, primary[i]);
if (!err) if (!err)
err = err2; err = err2;
} }
inode->i_blocks += reserved_gdb * sb->s_blocksize >> 9; inode->i_blocks += reserved_gdb * sb->s_blocksize >> 9;
ext3_mark_iloc_dirty(handle, inode, &iloc); ext4_mark_iloc_dirty(handle, inode, &iloc);
exit_bh: exit_bh:
while (--res >= 0) while (--res >= 0)
...@@ -609,7 +609,7 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode, ...@@ -609,7 +609,7 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
} }
/* /*
* Update the backup copies of the ext3 metadata. These don't need to be part * Update the backup copies of the ext4 metadata. These don't need to be part
* of the main resize transaction, because e2fsck will re-write them if there * of the main resize transaction, because e2fsck will re-write them if there
* is a problem (basically only OOM will cause a problem). However, we * is a problem (basically only OOM will cause a problem). However, we
* _should_ update the backups if possible, in case the primary gets trashed * _should_ update the backups if possible, in case the primary gets trashed
...@@ -626,9 +626,9 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode, ...@@ -626,9 +626,9 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
static void update_backups(struct super_block *sb, static void update_backups(struct super_block *sb,
int blk_off, char *data, int size) int blk_off, char *data, int size)
{ {
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
const unsigned long last = sbi->s_groups_count; const unsigned long last = sbi->s_groups_count;
const int bpg = EXT3_BLOCKS_PER_GROUP(sb); const int bpg = EXT4_BLOCKS_PER_GROUP(sb);
unsigned three = 1; unsigned three = 1;
unsigned five = 5; unsigned five = 5;
unsigned seven = 7; unsigned seven = 7;
...@@ -637,20 +637,20 @@ static void update_backups(struct super_block *sb, ...@@ -637,20 +637,20 @@ static void update_backups(struct super_block *sb,
handle_t *handle; handle_t *handle;
int err = 0, err2; int err = 0, err2;
handle = ext3_journal_start_sb(sb, EXT3_MAX_TRANS_DATA); handle = ext4_journal_start_sb(sb, EXT4_MAX_TRANS_DATA);
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
group = 1; group = 1;
err = PTR_ERR(handle); err = PTR_ERR(handle);
goto exit_err; goto exit_err;
} }
while ((group = ext3_list_backups(sb, &three, &five, &seven)) < last) { while ((group = ext4_list_backups(sb, &three, &five, &seven)) < last) {
struct buffer_head *bh; struct buffer_head *bh;
/* Out of journal space, and can't get more - abort - so sad */ /* Out of journal space, and can't get more - abort - so sad */
if (handle->h_buffer_credits == 0 && if (handle->h_buffer_credits == 0 &&
ext3_journal_extend(handle, EXT3_MAX_TRANS_DATA) && ext4_journal_extend(handle, EXT4_MAX_TRANS_DATA) &&
(err = ext3_journal_restart(handle, EXT3_MAX_TRANS_DATA))) (err = ext4_journal_restart(handle, EXT4_MAX_TRANS_DATA)))
break; break;
bh = sb_getblk(sb, group * bpg + blk_off); bh = sb_getblk(sb, group * bpg + blk_off);
...@@ -658,9 +658,9 @@ static void update_backups(struct super_block *sb, ...@@ -658,9 +658,9 @@ static void update_backups(struct super_block *sb,
err = -EIO; err = -EIO;
break; break;
} }
ext3_debug("update metadata backup %#04lx\n", ext4_debug("update metadata backup %#04lx\n",
(unsigned long)bh->b_blocknr); (unsigned long)bh->b_blocknr);
if ((err = ext3_journal_get_write_access(handle, bh))) if ((err = ext4_journal_get_write_access(handle, bh)))
break; break;
lock_buffer(bh); lock_buffer(bh);
memcpy(bh->b_data, data, size); memcpy(bh->b_data, data, size);
...@@ -668,10 +668,10 @@ static void update_backups(struct super_block *sb, ...@@ -668,10 +668,10 @@ static void update_backups(struct super_block *sb,
memset(bh->b_data + size, 0, rest); memset(bh->b_data + size, 0, rest);
set_buffer_uptodate(bh); set_buffer_uptodate(bh);
unlock_buffer(bh); unlock_buffer(bh);
ext3_journal_dirty_metadata(handle, bh); ext4_journal_dirty_metadata(handle, bh);
brelse(bh); brelse(bh);
} }
if ((err2 = ext3_journal_stop(handle)) && !err) if ((err2 = ext4_journal_stop(handle)) && !err)
err = err2; err = err2;
/* /*
...@@ -686,11 +686,11 @@ static void update_backups(struct super_block *sb, ...@@ -686,11 +686,11 @@ static void update_backups(struct super_block *sb,
*/ */
exit_err: exit_err:
if (err) { if (err) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"can't update backup for group %d (err %d), " "can't update backup for group %d (err %d), "
"forcing fsck on next reboot", group, err); "forcing fsck on next reboot", group, err);
sbi->s_mount_state &= ~EXT3_VALID_FS; sbi->s_mount_state &= ~EXT4_VALID_FS;
sbi->s_es->s_state &= cpu_to_le16(~EXT3_VALID_FS); sbi->s_es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
mark_buffer_dirty(sbi->s_sbh); mark_buffer_dirty(sbi->s_sbh);
} }
} }
...@@ -708,51 +708,51 @@ static void update_backups(struct super_block *sb, ...@@ -708,51 +708,51 @@ static void update_backups(struct super_block *sb,
* not really "added" the group at all. We re-check that we are still * not really "added" the group at all. We re-check that we are still
* adding in the last group in case things have changed since verifying. * adding in the last group in case things have changed since verifying.
*/ */
int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
{ {
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
struct ext3_super_block *es = sbi->s_es; struct ext4_super_block *es = sbi->s_es;
int reserved_gdb = ext3_bg_has_super(sb, input->group) ? int reserved_gdb = ext4_bg_has_super(sb, input->group) ?
le16_to_cpu(es->s_reserved_gdt_blocks) : 0; le16_to_cpu(es->s_reserved_gdt_blocks) : 0;
struct buffer_head *primary = NULL; struct buffer_head *primary = NULL;
struct ext3_group_desc *gdp; struct ext4_group_desc *gdp;
struct inode *inode = NULL; struct inode *inode = NULL;
handle_t *handle; handle_t *handle;
int gdb_off, gdb_num; int gdb_off, gdb_num;
int err, err2; int err, err2;
gdb_num = input->group / EXT3_DESC_PER_BLOCK(sb); gdb_num = input->group / EXT4_DESC_PER_BLOCK(sb);
gdb_off = input->group % EXT3_DESC_PER_BLOCK(sb); gdb_off = input->group % EXT4_DESC_PER_BLOCK(sb);
if (gdb_off == 0 && !EXT3_HAS_RO_COMPAT_FEATURE(sb, if (gdb_off == 0 && !EXT4_HAS_RO_COMPAT_FEATURE(sb,
EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)) { EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"Can't resize non-sparse filesystem further"); "Can't resize non-sparse filesystem further");
return -EPERM; return -EPERM;
} }
if (le32_to_cpu(es->s_blocks_count) + input->blocks_count < if (le32_to_cpu(es->s_blocks_count) + input->blocks_count <
le32_to_cpu(es->s_blocks_count)) { le32_to_cpu(es->s_blocks_count)) {
ext3_warning(sb, __FUNCTION__, "blocks_count overflow\n"); ext4_warning(sb, __FUNCTION__, "blocks_count overflow\n");
return -EINVAL; return -EINVAL;
} }
if (le32_to_cpu(es->s_inodes_count) + EXT3_INODES_PER_GROUP(sb) < if (le32_to_cpu(es->s_inodes_count) + EXT4_INODES_PER_GROUP(sb) <
le32_to_cpu(es->s_inodes_count)) { le32_to_cpu(es->s_inodes_count)) {
ext3_warning(sb, __FUNCTION__, "inodes_count overflow\n"); ext4_warning(sb, __FUNCTION__, "inodes_count overflow\n");
return -EINVAL; return -EINVAL;
} }
if (reserved_gdb || gdb_off == 0) { if (reserved_gdb || gdb_off == 0) {
if (!EXT3_HAS_COMPAT_FEATURE(sb, if (!EXT4_HAS_COMPAT_FEATURE(sb,
EXT3_FEATURE_COMPAT_RESIZE_INODE)){ EXT4_FEATURE_COMPAT_RESIZE_INODE)){
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"No reserved GDT blocks, can't resize"); "No reserved GDT blocks, can't resize");
return -EPERM; return -EPERM;
} }
inode = iget(sb, EXT3_RESIZE_INO); inode = iget(sb, EXT4_RESIZE_INO);
if (!inode || is_bad_inode(inode)) { if (!inode || is_bad_inode(inode)) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"Error opening resize inode"); "Error opening resize inode");
iput(inode); iput(inode);
return -ENOENT; return -ENOENT;
...@@ -772,8 +772,8 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) ...@@ -772,8 +772,8 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
* are adding a group with superblock/GDT backups we will also * are adding a group with superblock/GDT backups we will also
* modify each of the reserved GDT dindirect blocks. * modify each of the reserved GDT dindirect blocks.
*/ */
handle = ext3_journal_start_sb(sb, handle = ext4_journal_start_sb(sb,
ext3_bg_has_super(sb, input->group) ? ext4_bg_has_super(sb, input->group) ?
3 + reserved_gdb : 4); 3 + reserved_gdb : 4);
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
err = PTR_ERR(handle); err = PTR_ERR(handle);
...@@ -782,13 +782,13 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) ...@@ -782,13 +782,13 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
lock_super(sb); lock_super(sb);
if (input->group != sbi->s_groups_count) { if (input->group != sbi->s_groups_count) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"multiple resizers run on filesystem!"); "multiple resizers run on filesystem!");
err = -EBUSY; err = -EBUSY;
goto exit_journal; goto exit_journal;
} }
if ((err = ext3_journal_get_write_access(handle, sbi->s_sbh))) if ((err = ext4_journal_get_write_access(handle, sbi->s_sbh)))
goto exit_journal; goto exit_journal;
/* /*
...@@ -799,10 +799,10 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) ...@@ -799,10 +799,10 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
*/ */
if (gdb_off) { if (gdb_off) {
primary = sbi->s_group_desc[gdb_num]; primary = sbi->s_group_desc[gdb_num];
if ((err = ext3_journal_get_write_access(handle, primary))) if ((err = ext4_journal_get_write_access(handle, primary)))
goto exit_journal; goto exit_journal;
if (reserved_gdb && ext3_bg_num_gdb(sb, input->group) && if (reserved_gdb && ext4_bg_num_gdb(sb, input->group) &&
(err = reserve_backup_gdb(handle, inode, input))) (err = reserve_backup_gdb(handle, inode, input)))
goto exit_journal; goto exit_journal;
} else if ((err = add_new_gdb(handle, inode, input, &primary))) } 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,13 +828,13 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
*/ */
/* Update group descriptor block for new group */ /* Update group descriptor block for new group */
gdp = (struct ext3_group_desc *)primary->b_data + gdb_off; gdp = (struct ext4_group_desc *)primary->b_data + gdb_off;
gdp->bg_block_bitmap = cpu_to_le32(input->block_bitmap); gdp->bg_block_bitmap = cpu_to_le32(input->block_bitmap);
gdp->bg_inode_bitmap = cpu_to_le32(input->inode_bitmap); gdp->bg_inode_bitmap = cpu_to_le32(input->inode_bitmap);
gdp->bg_inode_table = cpu_to_le32(input->inode_table); gdp->bg_inode_table = cpu_to_le32(input->inode_table);
gdp->bg_free_blocks_count = cpu_to_le16(input->free_blocks_count); gdp->bg_free_blocks_count = cpu_to_le16(input->free_blocks_count);
gdp->bg_free_inodes_count = cpu_to_le16(EXT3_INODES_PER_GROUP(sb)); gdp->bg_free_inodes_count = cpu_to_le16(EXT4_INODES_PER_GROUP(sb));
/* /*
* Make the new blocks and inodes valid next. We do this before * 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,7 +849,7 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
es->s_blocks_count = cpu_to_le32(le32_to_cpu(es->s_blocks_count) + es->s_blocks_count = cpu_to_le32(le32_to_cpu(es->s_blocks_count) +
input->blocks_count); input->blocks_count);
es->s_inodes_count = cpu_to_le32(le32_to_cpu(es->s_inodes_count) + es->s_inodes_count = cpu_to_le32(le32_to_cpu(es->s_inodes_count) +
EXT3_INODES_PER_GROUP(sb)); EXT4_INODES_PER_GROUP(sb));
/* /*
* We need to protect s_groups_count against other CPUs seeing * 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,7 +878,7 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
/* Update the global fs size fields */ /* Update the global fs size fields */
sbi->s_groups_count++; sbi->s_groups_count++;
ext3_journal_dirty_metadata(handle, primary); ext4_journal_dirty_metadata(handle, primary);
/* Update the reserved block counts only once the new group is /* Update the reserved block counts only once the new group is
* active. */ * active. */
...@@ -889,42 +889,42 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) ...@@ -889,42 +889,42 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
percpu_counter_mod(&sbi->s_freeblocks_counter, percpu_counter_mod(&sbi->s_freeblocks_counter,
input->free_blocks_count); input->free_blocks_count);
percpu_counter_mod(&sbi->s_freeinodes_counter, percpu_counter_mod(&sbi->s_freeinodes_counter,
EXT3_INODES_PER_GROUP(sb)); EXT4_INODES_PER_GROUP(sb));
ext3_journal_dirty_metadata(handle, sbi->s_sbh); ext4_journal_dirty_metadata(handle, sbi->s_sbh);
sb->s_dirt = 1; sb->s_dirt = 1;
exit_journal: exit_journal:
unlock_super(sb); unlock_super(sb);
if ((err2 = ext3_journal_stop(handle)) && !err) if ((err2 = ext4_journal_stop(handle)) && !err)
err = err2; err = err2;
if (!err) { if (!err) {
update_backups(sb, sbi->s_sbh->b_blocknr, (char *)es, update_backups(sb, sbi->s_sbh->b_blocknr, (char *)es,
sizeof(struct ext3_super_block)); sizeof(struct ext4_super_block));
update_backups(sb, primary->b_blocknr, primary->b_data, update_backups(sb, primary->b_blocknr, primary->b_data,
primary->b_size); primary->b_size);
} }
exit_put: exit_put:
iput(inode); iput(inode);
return err; return err;
} /* ext3_group_add */ } /* ext4_group_add */
/* Extend the filesystem to the new number of blocks specified. This entry /* Extend the filesystem to the new number of blocks specified. This entry
* point is only used to extend the current filesystem to the end of the last * point is only used to extend the current filesystem to the end of the last
* existing group. It can be accessed via ioctl, or by "remount,resize=<size>" * existing group. It can be accessed via ioctl, or by "remount,resize=<size>"
* for emergencies (because it has no dependencies on reserved blocks). * for emergencies (because it has no dependencies on reserved blocks).
* *
* If we _really_ wanted, we could use default values to call ext3_group_add() * If we _really_ wanted, we could use default values to call ext4_group_add()
* allow the "remount" trick to work for arbitrary resizing, assuming enough * allow the "remount" trick to work for arbitrary resizing, assuming enough
* GDT blocks are reserved to grow to the desired size. * GDT blocks are reserved to grow to the desired size.
*/ */
int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es, int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
ext3_fsblk_t n_blocks_count) ext4_fsblk_t n_blocks_count)
{ {
ext3_fsblk_t o_blocks_count; ext4_fsblk_t o_blocks_count;
unsigned long o_groups_count; unsigned long o_groups_count;
ext3_grpblk_t last; ext4_grpblk_t last;
ext3_grpblk_t add; ext4_grpblk_t add;
struct buffer_head * bh; struct buffer_head * bh;
handle_t *handle; handle_t *handle;
int err; int err;
...@@ -934,45 +934,45 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es, ...@@ -934,45 +934,45 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
* yet: we're going to revalidate es->s_blocks_count after * yet: we're going to revalidate es->s_blocks_count after
* taking lock_super() below. */ * taking lock_super() below. */
o_blocks_count = le32_to_cpu(es->s_blocks_count); o_blocks_count = le32_to_cpu(es->s_blocks_count);
o_groups_count = EXT3_SB(sb)->s_groups_count; o_groups_count = EXT4_SB(sb)->s_groups_count;
if (test_opt(sb, DEBUG)) if (test_opt(sb, DEBUG))
printk(KERN_DEBUG "EXT3-fs: extending last group from "E3FSBLK" uto "E3FSBLK" blocks\n", printk(KERN_DEBUG "EXT4-fs: extending last group from "E3FSBLK" uto "E3FSBLK" blocks\n",
o_blocks_count, n_blocks_count); o_blocks_count, n_blocks_count);
if (n_blocks_count == 0 || n_blocks_count == o_blocks_count) if (n_blocks_count == 0 || n_blocks_count == o_blocks_count)
return 0; return 0;
if (n_blocks_count > (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) { if (n_blocks_count > (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
printk(KERN_ERR "EXT3-fs: filesystem on %s:" printk(KERN_ERR "EXT4-fs: filesystem on %s:"
" too large to resize to %lu blocks safely\n", " too large to resize to %lu blocks safely\n",
sb->s_id, n_blocks_count); sb->s_id, n_blocks_count);
if (sizeof(sector_t) < 8) if (sizeof(sector_t) < 8)
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"CONFIG_LBD not enabled\n"); "CONFIG_LBD not enabled\n");
return -EINVAL; return -EINVAL;
} }
if (n_blocks_count < o_blocks_count) { if (n_blocks_count < o_blocks_count) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"can't shrink FS - resize aborted"); "can't shrink FS - resize aborted");
return -EBUSY; return -EBUSY;
} }
/* Handle the remaining blocks in the last group only. */ /* Handle the remaining blocks in the last group only. */
last = (o_blocks_count - le32_to_cpu(es->s_first_data_block)) % last = (o_blocks_count - le32_to_cpu(es->s_first_data_block)) %
EXT3_BLOCKS_PER_GROUP(sb); EXT4_BLOCKS_PER_GROUP(sb);
if (last == 0) { if (last == 0) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"need to use ext2online to resize further"); "need to use ext2online to resize further");
return -EPERM; return -EPERM;
} }
add = EXT3_BLOCKS_PER_GROUP(sb) - last; add = EXT4_BLOCKS_PER_GROUP(sb) - last;
if (o_blocks_count + add < o_blocks_count) { if (o_blocks_count + add < o_blocks_count) {
ext3_warning(sb, __FUNCTION__, "blocks_count overflow"); ext4_warning(sb, __FUNCTION__, "blocks_count overflow");
return -EINVAL; return -EINVAL;
} }
...@@ -980,7 +980,7 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es, ...@@ -980,7 +980,7 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
add = n_blocks_count - o_blocks_count; add = n_blocks_count - o_blocks_count;
if (o_blocks_count + add < n_blocks_count) if (o_blocks_count + add < n_blocks_count)
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"will only finish group ("E3FSBLK "will only finish group ("E3FSBLK
" blocks, %u new)", " blocks, %u new)",
o_blocks_count + add, add); o_blocks_count + add, add);
...@@ -988,55 +988,55 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es, ...@@ -988,55 +988,55 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es,
/* See if the device is actually as big as what was requested */ /* See if the device is actually as big as what was requested */
bh = sb_bread(sb, o_blocks_count + add -1); bh = sb_bread(sb, o_blocks_count + add -1);
if (!bh) { if (!bh) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"can't read last block, resize aborted"); "can't read last block, resize aborted");
return -ENOSPC; return -ENOSPC;
} }
brelse(bh); brelse(bh);
/* We will update the superblock, one block bitmap, and /* We will update the superblock, one block bitmap, and
* one group descriptor via ext3_free_blocks(). * one group descriptor via ext4_free_blocks().
*/ */
handle = ext3_journal_start_sb(sb, 3); handle = ext4_journal_start_sb(sb, 3);
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
err = PTR_ERR(handle); err = PTR_ERR(handle);
ext3_warning(sb, __FUNCTION__, "error %d on journal start",err); ext4_warning(sb, __FUNCTION__, "error %d on journal start",err);
goto exit_put; goto exit_put;
} }
lock_super(sb); lock_super(sb);
if (o_blocks_count != le32_to_cpu(es->s_blocks_count)) { if (o_blocks_count != le32_to_cpu(es->s_blocks_count)) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"multiple resizers run on filesystem!"); "multiple resizers run on filesystem!");
unlock_super(sb); unlock_super(sb);
err = -EBUSY; err = -EBUSY;
goto exit_put; goto exit_put;
} }
if ((err = ext3_journal_get_write_access(handle, if ((err = ext4_journal_get_write_access(handle,
EXT3_SB(sb)->s_sbh))) { EXT4_SB(sb)->s_sbh))) {
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"error %d on journal write access", err); "error %d on journal write access", err);
unlock_super(sb); unlock_super(sb);
ext3_journal_stop(handle); ext4_journal_stop(handle);
goto exit_put; goto exit_put;
} }
es->s_blocks_count = cpu_to_le32(o_blocks_count + add); es->s_blocks_count = cpu_to_le32(o_blocks_count + add);
ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh);
sb->s_dirt = 1; sb->s_dirt = 1;
unlock_super(sb); unlock_super(sb);
ext3_debug("freeing blocks %lu through "E3FSBLK"\n", o_blocks_count, ext4_debug("freeing blocks %lu through "E3FSBLK"\n", o_blocks_count,
o_blocks_count + add); o_blocks_count + add);
ext3_free_blocks_sb(handle, sb, o_blocks_count, add, &freed_blocks); ext4_free_blocks_sb(handle, sb, o_blocks_count, add, &freed_blocks);
ext3_debug("freed blocks "E3FSBLK" through "E3FSBLK"\n", o_blocks_count, ext4_debug("freed blocks "E3FSBLK" through "E3FSBLK"\n", o_blocks_count,
o_blocks_count + add); o_blocks_count + add);
if ((err = ext3_journal_stop(handle))) if ((err = ext4_journal_stop(handle)))
goto exit_put; goto exit_put;
if (test_opt(sb, DEBUG)) if (test_opt(sb, DEBUG))
printk(KERN_DEBUG "EXT3-fs: extended group to %u blocks\n", printk(KERN_DEBUG "EXT4-fs: extended group to %u blocks\n",
le32_to_cpu(es->s_blocks_count)); le32_to_cpu(es->s_blocks_count));
update_backups(sb, EXT3_SB(sb)->s_sbh->b_blocknr, (char *)es, update_backups(sb, EXT4_SB(sb)->s_sbh->b_blocknr, (char *)es,
sizeof(struct ext3_super_block)); sizeof(struct ext4_super_block));
exit_put: exit_put:
return err; return err;
} /* ext3_group_extend */ } /* ext4_group_extend */
/* /*
* linux/fs/ext3/super.c * linux/fs/ext4/super.c
* *
* Copyright (C) 1992, 1993, 1994, 1995 * Copyright (C) 1992, 1993, 1994, 1995
* Remy Card (card@masi.ibp.fr) * Remy Card (card@masi.ibp.fr)
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/time.h> #include <linux/time.h>
#include <linux/jbd.h> #include <linux/jbd.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#include <linux/ext3_jbd.h> #include <linux/ext4_jbd.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
...@@ -42,25 +42,25 @@ ...@@ -42,25 +42,25 @@
#include "acl.h" #include "acl.h"
#include "namei.h" #include "namei.h"
static int ext3_load_journal(struct super_block *, struct ext3_super_block *, static int ext4_load_journal(struct super_block *, struct ext4_super_block *,
unsigned long journal_devnum); unsigned long journal_devnum);
static int ext3_create_journal(struct super_block *, struct ext3_super_block *, static int ext4_create_journal(struct super_block *, struct ext4_super_block *,
unsigned int); unsigned int);
static void ext3_commit_super (struct super_block * sb, static void ext4_commit_super (struct super_block * sb,
struct ext3_super_block * es, struct ext4_super_block * es,
int sync); int sync);
static void ext3_mark_recovery_complete(struct super_block * sb, static void ext4_mark_recovery_complete(struct super_block * sb,
struct ext3_super_block * es); struct ext4_super_block * es);
static void ext3_clear_journal_err(struct super_block * sb, static void ext4_clear_journal_err(struct super_block * sb,
struct ext3_super_block * es); struct ext4_super_block * es);
static int ext3_sync_fs(struct super_block *sb, int wait); static int ext4_sync_fs(struct super_block *sb, int wait);
static const char *ext3_decode_error(struct super_block * sb, int errno, static const char *ext4_decode_error(struct super_block * sb, int errno,
char nbuf[16]); char nbuf[16]);
static int ext3_remount (struct super_block * sb, int * flags, char * data); static int ext4_remount (struct super_block * sb, int * flags, char * data);
static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf); static int ext4_statfs (struct dentry * dentry, struct kstatfs * buf);
static void ext3_unlockfs(struct super_block *sb); static void ext4_unlockfs(struct super_block *sb);
static void ext3_write_super (struct super_block * sb); static void ext4_write_super (struct super_block * sb);
static void ext3_write_super_lockfs(struct super_block *sb); static void ext4_write_super_lockfs(struct super_block *sb);
/* /*
* Wrappers for journal_start/end. * Wrappers for journal_start/end.
...@@ -70,7 +70,7 @@ static void ext3_write_super_lockfs(struct super_block *sb); ...@@ -70,7 +70,7 @@ static void ext3_write_super_lockfs(struct super_block *sb);
* that sync() will call the filesystem's write_super callback if * that sync() will call the filesystem's write_super callback if
* appropriate. * appropriate.
*/ */
handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks) handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
{ {
journal_t *journal; journal_t *journal;
...@@ -80,9 +80,9 @@ handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks) ...@@ -80,9 +80,9 @@ handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks)
/* Special case here: if the journal has aborted behind our /* Special case here: if the journal has aborted behind our
* backs (eg. EIO in the commit thread), then we still need to * backs (eg. EIO in the commit thread), then we still need to
* take the FS itself readonly cleanly. */ * take the FS itself readonly cleanly. */
journal = EXT3_SB(sb)->s_journal; journal = EXT4_SB(sb)->s_journal;
if (is_journal_aborted(journal)) { if (is_journal_aborted(journal)) {
ext3_abort(sb, __FUNCTION__, ext4_abort(sb, __FUNCTION__,
"Detected aborted journal"); "Detected aborted journal");
return ERR_PTR(-EROFS); return ERR_PTR(-EROFS);
} }
...@@ -96,7 +96,7 @@ handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks) ...@@ -96,7 +96,7 @@ handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks)
* that sync() will call the filesystem's write_super callback if * that sync() will call the filesystem's write_super callback if
* appropriate. * appropriate.
*/ */
int __ext3_journal_stop(const char *where, handle_t *handle) int __ext4_journal_stop(const char *where, handle_t *handle)
{ {
struct super_block *sb; struct super_block *sb;
int err; int err;
...@@ -109,15 +109,15 @@ int __ext3_journal_stop(const char *where, handle_t *handle) ...@@ -109,15 +109,15 @@ int __ext3_journal_stop(const char *where, handle_t *handle)
if (!err) if (!err)
err = rc; err = rc;
if (err) if (err)
__ext3_std_error(sb, where, err); __ext4_std_error(sb, where, err);
return err; return err;
} }
void ext3_journal_abort_handle(const char *caller, const char *err_fn, void ext4_journal_abort_handle(const char *caller, const char *err_fn,
struct buffer_head *bh, handle_t *handle, int err) struct buffer_head *bh, handle_t *handle, int err)
{ {
char nbuf[16]; char nbuf[16];
const char *errstr = ext3_decode_error(NULL, err, nbuf); const char *errstr = ext4_decode_error(NULL, err, nbuf);
if (bh) if (bh)
BUFFER_TRACE(bh, "abort"); BUFFER_TRACE(bh, "abort");
...@@ -138,7 +138,7 @@ void ext3_journal_abort_handle(const char *caller, const char *err_fn, ...@@ -138,7 +138,7 @@ void ext3_journal_abort_handle(const char *caller, const char *err_fn,
* inconsistencies detected or read IO failures. * inconsistencies detected or read IO failures.
* *
* On ext2, we can store the error state of the filesystem in the * On ext2, we can store the error state of the filesystem in the
* superblock. That is not possible on ext3, because we may have other * superblock. That is not possible on ext4, because we may have other
* write ordering constraints on the superblock which prevent us from * write ordering constraints on the superblock which prevent us from
* writing it out straight away; and given that the journal is about to * writing it out straight away; and given that the journal is about to
* be aborted, we can't rely on the current, or future, transactions to * 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,20 +149,20 @@ void ext3_journal_abort_handle(const char *caller, const char *err_fn,
* that error until we've noted it down and cleared it. * that error until we've noted it down and cleared it.
*/ */
static void ext3_handle_error(struct super_block *sb) static void ext4_handle_error(struct super_block *sb)
{ {
struct ext3_super_block *es = EXT3_SB(sb)->s_es; struct ext4_super_block *es = EXT4_SB(sb)->s_es;
EXT3_SB(sb)->s_mount_state |= EXT3_ERROR_FS; EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
es->s_state |= cpu_to_le16(EXT3_ERROR_FS); es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
if (sb->s_flags & MS_RDONLY) if (sb->s_flags & MS_RDONLY)
return; return;
if (!test_opt (sb, ERRORS_CONT)) { if (!test_opt (sb, ERRORS_CONT)) {
journal_t *journal = EXT3_SB(sb)->s_journal; journal_t *journal = EXT4_SB(sb)->s_journal;
EXT3_SB(sb)->s_mount_opt |= EXT3_MOUNT_ABORT; EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT;
if (journal) if (journal)
journal_abort(journal, -EIO); journal_abort(journal, -EIO);
} }
...@@ -170,27 +170,27 @@ static void ext3_handle_error(struct super_block *sb) ...@@ -170,27 +170,27 @@ static void ext3_handle_error(struct super_block *sb)
printk (KERN_CRIT "Remounting filesystem read-only\n"); printk (KERN_CRIT "Remounting filesystem read-only\n");
sb->s_flags |= MS_RDONLY; sb->s_flags |= MS_RDONLY;
} }
ext3_commit_super(sb, es, 1); ext4_commit_super(sb, es, 1);
if (test_opt(sb, ERRORS_PANIC)) if (test_opt(sb, ERRORS_PANIC))
panic("EXT3-fs (device %s): panic forced after error\n", panic("EXT4-fs (device %s): panic forced after error\n",
sb->s_id); sb->s_id);
} }
void ext3_error (struct super_block * sb, const char * function, void ext4_error (struct super_block * sb, const char * function,
const char * fmt, ...) const char * fmt, ...)
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
printk(KERN_CRIT "EXT3-fs error (device %s): %s: ",sb->s_id, function); printk(KERN_CRIT "EXT4-fs error (device %s): %s: ",sb->s_id, function);
vprintk(fmt, args); vprintk(fmt, args);
printk("\n"); printk("\n");
va_end(args); va_end(args);
ext3_handle_error(sb); ext4_handle_error(sb);
} }
static const char *ext3_decode_error(struct super_block * sb, int errno, static const char *ext4_decode_error(struct super_block * sb, int errno,
char nbuf[16]) char nbuf[16])
{ {
char *errstr = NULL; char *errstr = NULL;
...@@ -203,7 +203,7 @@ static const char *ext3_decode_error(struct super_block * sb, int errno, ...@@ -203,7 +203,7 @@ static const char *ext3_decode_error(struct super_block * sb, int errno,
errstr = "Out of memory"; errstr = "Out of memory";
break; break;
case -EROFS: case -EROFS:
if (!sb || EXT3_SB(sb)->s_journal->j_flags & JFS_ABORT) if (!sb || EXT4_SB(sb)->s_journal->j_flags & JFS_ABORT)
errstr = "Journal has aborted"; errstr = "Journal has aborted";
else else
errstr = "Readonly filesystem"; errstr = "Readonly filesystem";
...@@ -223,10 +223,10 @@ static const char *ext3_decode_error(struct super_block * sb, int errno, ...@@ -223,10 +223,10 @@ static const char *ext3_decode_error(struct super_block * sb, int errno,
return errstr; return errstr;
} }
/* __ext3_std_error decodes expected errors from journaling functions /* __ext4_std_error decodes expected errors from journaling functions
* automatically and invokes the appropriate error response. */ * automatically and invokes the appropriate error response. */
void __ext3_std_error (struct super_block * sb, const char * function, void __ext4_std_error (struct super_block * sb, const char * function,
int errno) int errno)
{ {
char nbuf[16]; char nbuf[16];
...@@ -239,15 +239,15 @@ void __ext3_std_error (struct super_block * sb, const char * function, ...@@ -239,15 +239,15 @@ void __ext3_std_error (struct super_block * sb, const char * function,
(sb->s_flags & MS_RDONLY)) (sb->s_flags & MS_RDONLY))
return; return;
errstr = ext3_decode_error(sb, errno, nbuf); errstr = ext4_decode_error(sb, errno, nbuf);
printk (KERN_CRIT "EXT3-fs error (device %s) in %s: %s\n", printk (KERN_CRIT "EXT4-fs error (device %s) in %s: %s\n",
sb->s_id, function, errstr); sb->s_id, function, errstr);
ext3_handle_error(sb); ext4_handle_error(sb);
} }
/* /*
* ext3_abort is a much stronger failure handler than ext3_error. The * ext4_abort is a much stronger failure handler than ext4_error. The
* abort function may be used to deal with unrecoverable failures such * abort function may be used to deal with unrecoverable failures such
* as journal IO errors or ENOMEM at a critical moment in log management. * as journal IO errors or ENOMEM at a critical moment in log management.
* *
...@@ -256,60 +256,60 @@ void __ext3_std_error (struct super_block * sb, const char * function, ...@@ -256,60 +256,60 @@ void __ext3_std_error (struct super_block * sb, const char * function,
* case we take the easy way out and panic immediately. * case we take the easy way out and panic immediately.
*/ */
void ext3_abort (struct super_block * sb, const char * function, void ext4_abort (struct super_block * sb, const char * function,
const char * fmt, ...) const char * fmt, ...)
{ {
va_list args; va_list args;
printk (KERN_CRIT "ext3_abort called.\n"); printk (KERN_CRIT "ext4_abort called.\n");
va_start(args, fmt); va_start(args, fmt);
printk(KERN_CRIT "EXT3-fs error (device %s): %s: ",sb->s_id, function); printk(KERN_CRIT "EXT4-fs error (device %s): %s: ",sb->s_id, function);
vprintk(fmt, args); vprintk(fmt, args);
printk("\n"); printk("\n");
va_end(args); va_end(args);
if (test_opt(sb, ERRORS_PANIC)) if (test_opt(sb, ERRORS_PANIC))
panic("EXT3-fs panic from previous error\n"); panic("EXT4-fs panic from previous error\n");
if (sb->s_flags & MS_RDONLY) if (sb->s_flags & MS_RDONLY)
return; return;
printk(KERN_CRIT "Remounting filesystem read-only\n"); printk(KERN_CRIT "Remounting filesystem read-only\n");
EXT3_SB(sb)->s_mount_state |= EXT3_ERROR_FS; EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
sb->s_flags |= MS_RDONLY; sb->s_flags |= MS_RDONLY;
EXT3_SB(sb)->s_mount_opt |= EXT3_MOUNT_ABORT; EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT;
journal_abort(EXT3_SB(sb)->s_journal, -EIO); journal_abort(EXT4_SB(sb)->s_journal, -EIO);
} }
void ext3_warning (struct super_block * sb, const char * function, void ext4_warning (struct super_block * sb, const char * function,
const char * fmt, ...) const char * fmt, ...)
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
printk(KERN_WARNING "EXT3-fs warning (device %s): %s: ", printk(KERN_WARNING "EXT4-fs warning (device %s): %s: ",
sb->s_id, function); sb->s_id, function);
vprintk(fmt, args); vprintk(fmt, args);
printk("\n"); printk("\n");
va_end(args); va_end(args);
} }
void ext3_update_dynamic_rev(struct super_block *sb) void ext4_update_dynamic_rev(struct super_block *sb)
{ {
struct ext3_super_block *es = EXT3_SB(sb)->s_es; struct ext4_super_block *es = EXT4_SB(sb)->s_es;
if (le32_to_cpu(es->s_rev_level) > EXT3_GOOD_OLD_REV) if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV)
return; return;
ext3_warning(sb, __FUNCTION__, ext4_warning(sb, __FUNCTION__,
"updating to rev %d because of new feature flag, " "updating to rev %d because of new feature flag, "
"running e2fsck is recommended", "running e2fsck is recommended",
EXT3_DYNAMIC_REV); EXT4_DYNAMIC_REV);
es->s_first_ino = cpu_to_le32(EXT3_GOOD_OLD_FIRST_INO); es->s_first_ino = cpu_to_le32(EXT4_GOOD_OLD_FIRST_INO);
es->s_inode_size = cpu_to_le16(EXT3_GOOD_OLD_INODE_SIZE); es->s_inode_size = cpu_to_le16(EXT4_GOOD_OLD_INODE_SIZE);
es->s_rev_level = cpu_to_le32(EXT3_DYNAMIC_REV); es->s_rev_level = cpu_to_le32(EXT4_DYNAMIC_REV);
/* leave es->s_feature_*compat flags alone */ /* leave es->s_feature_*compat flags alone */
/* es->s_uuid will be set by e2fsck if empty */ /* es->s_uuid will be set by e2fsck if empty */
...@@ -323,7 +323,7 @@ void ext3_update_dynamic_rev(struct super_block *sb) ...@@ -323,7 +323,7 @@ void ext3_update_dynamic_rev(struct super_block *sb)
/* /*
* Open the external journal device * Open the external journal device
*/ */
static struct block_device *ext3_blkdev_get(dev_t dev) static struct block_device *ext4_blkdev_get(dev_t dev)
{ {
struct block_device *bdev; struct block_device *bdev;
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
...@@ -334,7 +334,7 @@ static struct block_device *ext3_blkdev_get(dev_t dev) ...@@ -334,7 +334,7 @@ static struct block_device *ext3_blkdev_get(dev_t dev)
return bdev; return bdev;
fail: fail:
printk(KERN_ERR "EXT3: failed to open journal device %s: %ld\n", printk(KERN_ERR "EXT4: failed to open journal device %s: %ld\n",
__bdevname(dev, b), PTR_ERR(bdev)); __bdevname(dev, b), PTR_ERR(bdev));
return NULL; return NULL;
} }
...@@ -342,20 +342,20 @@ static struct block_device *ext3_blkdev_get(dev_t dev) ...@@ -342,20 +342,20 @@ static struct block_device *ext3_blkdev_get(dev_t dev)
/* /*
* Release the journal device * Release the journal device
*/ */
static int ext3_blkdev_put(struct block_device *bdev) static int ext4_blkdev_put(struct block_device *bdev)
{ {
bd_release(bdev); bd_release(bdev);
return blkdev_put(bdev); return blkdev_put(bdev);
} }
static int ext3_blkdev_remove(struct ext3_sb_info *sbi) static int ext4_blkdev_remove(struct ext4_sb_info *sbi)
{ {
struct block_device *bdev; struct block_device *bdev;
int ret = -ENODEV; int ret = -ENODEV;
bdev = sbi->journal_bdev; bdev = sbi->journal_bdev;
if (bdev) { if (bdev) {
ret = ext3_blkdev_put(bdev); ret = ext4_blkdev_put(bdev);
sbi->journal_bdev = NULL; sbi->journal_bdev = NULL;
} }
return ret; return ret;
...@@ -363,10 +363,10 @@ static int ext3_blkdev_remove(struct ext3_sb_info *sbi) ...@@ -363,10 +363,10 @@ static int ext3_blkdev_remove(struct ext3_sb_info *sbi)
static inline struct inode *orphan_list_entry(struct list_head *l) static inline struct inode *orphan_list_entry(struct list_head *l)
{ {
return &list_entry(l, struct ext3_inode_info, i_orphan)->vfs_inode; return &list_entry(l, struct ext4_inode_info, i_orphan)->vfs_inode;
} }
static void dump_orphan_list(struct super_block *sb, struct ext3_sb_info *sbi) static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi)
{ {
struct list_head *l; struct list_head *l;
...@@ -384,20 +384,20 @@ static void dump_orphan_list(struct super_block *sb, struct ext3_sb_info *sbi) ...@@ -384,20 +384,20 @@ static void dump_orphan_list(struct super_block *sb, struct ext3_sb_info *sbi)
} }
} }
static void ext3_put_super (struct super_block * sb) static void ext4_put_super (struct super_block * sb)
{ {
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
struct ext3_super_block *es = sbi->s_es; struct ext4_super_block *es = sbi->s_es;
int i; int i;
ext3_xattr_put_super(sb); ext4_xattr_put_super(sb);
journal_destroy(sbi->s_journal); journal_destroy(sbi->s_journal);
if (!(sb->s_flags & MS_RDONLY)) { if (!(sb->s_flags & MS_RDONLY)) {
EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
es->s_state = cpu_to_le16(sbi->s_mount_state); es->s_state = cpu_to_le16(sbi->s_mount_state);
BUFFER_TRACE(sbi->s_sbh, "marking dirty"); BUFFER_TRACE(sbi->s_sbh, "marking dirty");
mark_buffer_dirty(sbi->s_sbh); mark_buffer_dirty(sbi->s_sbh);
ext3_commit_super(sb, es, 1); ext4_commit_super(sb, es, 1);
} }
for (i = 0; i < sbi->s_gdb_count; i++) for (i = 0; i < sbi->s_gdb_count; i++)
...@@ -429,47 +429,47 @@ static void ext3_put_super (struct super_block * sb) ...@@ -429,47 +429,47 @@ static void ext3_put_super (struct super_block * sb)
*/ */
sync_blockdev(sbi->journal_bdev); sync_blockdev(sbi->journal_bdev);
invalidate_bdev(sbi->journal_bdev, 0); invalidate_bdev(sbi->journal_bdev, 0);
ext3_blkdev_remove(sbi); ext4_blkdev_remove(sbi);
} }
sb->s_fs_info = NULL; sb->s_fs_info = NULL;
kfree(sbi); kfree(sbi);
return; return;
} }
static kmem_cache_t *ext3_inode_cachep; static kmem_cache_t *ext4_inode_cachep;
/* /*
* Called inside transaction, so use GFP_NOFS * Called inside transaction, so use GFP_NOFS
*/ */
static struct inode *ext3_alloc_inode(struct super_block *sb) static struct inode *ext4_alloc_inode(struct super_block *sb)
{ {
struct ext3_inode_info *ei; struct ext4_inode_info *ei;
ei = kmem_cache_alloc(ext3_inode_cachep, SLAB_NOFS); ei = kmem_cache_alloc(ext4_inode_cachep, SLAB_NOFS);
if (!ei) if (!ei)
return NULL; return NULL;
#ifdef CONFIG_EXT3_FS_POSIX_ACL #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
ei->i_acl = EXT3_ACL_NOT_CACHED; ei->i_acl = EXT4_ACL_NOT_CACHED;
ei->i_default_acl = EXT3_ACL_NOT_CACHED; ei->i_default_acl = EXT4_ACL_NOT_CACHED;
#endif #endif
ei->i_block_alloc_info = NULL; ei->i_block_alloc_info = NULL;
ei->vfs_inode.i_version = 1; ei->vfs_inode.i_version = 1;
return &ei->vfs_inode; return &ei->vfs_inode;
} }
static void ext3_destroy_inode(struct inode *inode) static void ext4_destroy_inode(struct inode *inode)
{ {
kmem_cache_free(ext3_inode_cachep, EXT3_I(inode)); kmem_cache_free(ext4_inode_cachep, EXT4_I(inode));
} }
static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags) static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
{ {
struct ext3_inode_info *ei = (struct ext3_inode_info *) foo; struct ext4_inode_info *ei = (struct ext4_inode_info *) foo;
if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
SLAB_CTOR_CONSTRUCTOR) { SLAB_CTOR_CONSTRUCTOR) {
INIT_LIST_HEAD(&ei->i_orphan); INIT_LIST_HEAD(&ei->i_orphan);
#ifdef CONFIG_EXT3_FS_XATTR #ifdef CONFIG_EXT4DEV_FS_XATTR
init_rwsem(&ei->xattr_sem); init_rwsem(&ei->xattr_sem);
#endif #endif
mutex_init(&ei->truncate_mutex); mutex_init(&ei->truncate_mutex);
...@@ -479,46 +479,46 @@ static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags) ...@@ -479,46 +479,46 @@ static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
static int init_inodecache(void) static int init_inodecache(void)
{ {
ext3_inode_cachep = kmem_cache_create("ext3_inode_cache", ext4_inode_cachep = kmem_cache_create("ext4_inode_cache",
sizeof(struct ext3_inode_info), sizeof(struct ext4_inode_info),
0, (SLAB_RECLAIM_ACCOUNT| 0, (SLAB_RECLAIM_ACCOUNT|
SLAB_MEM_SPREAD), SLAB_MEM_SPREAD),
init_once, NULL); init_once, NULL);
if (ext3_inode_cachep == NULL) if (ext4_inode_cachep == NULL)
return -ENOMEM; return -ENOMEM;
return 0; return 0;
} }
static void destroy_inodecache(void) static void destroy_inodecache(void)
{ {
kmem_cache_destroy(ext3_inode_cachep); kmem_cache_destroy(ext4_inode_cachep);
} }
static void ext3_clear_inode(struct inode *inode) static void ext4_clear_inode(struct inode *inode)
{ {
struct ext3_block_alloc_info *rsv = EXT3_I(inode)->i_block_alloc_info; struct ext4_block_alloc_info *rsv = EXT4_I(inode)->i_block_alloc_info;
#ifdef CONFIG_EXT3_FS_POSIX_ACL #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
if (EXT3_I(inode)->i_acl && if (EXT4_I(inode)->i_acl &&
EXT3_I(inode)->i_acl != EXT3_ACL_NOT_CACHED) { EXT4_I(inode)->i_acl != EXT4_ACL_NOT_CACHED) {
posix_acl_release(EXT3_I(inode)->i_acl); posix_acl_release(EXT4_I(inode)->i_acl);
EXT3_I(inode)->i_acl = EXT3_ACL_NOT_CACHED; EXT4_I(inode)->i_acl = EXT4_ACL_NOT_CACHED;
} }
if (EXT3_I(inode)->i_default_acl && if (EXT4_I(inode)->i_default_acl &&
EXT3_I(inode)->i_default_acl != EXT3_ACL_NOT_CACHED) { EXT4_I(inode)->i_default_acl != EXT4_ACL_NOT_CACHED) {
posix_acl_release(EXT3_I(inode)->i_default_acl); posix_acl_release(EXT4_I(inode)->i_default_acl);
EXT3_I(inode)->i_default_acl = EXT3_ACL_NOT_CACHED; EXT4_I(inode)->i_default_acl = EXT4_ACL_NOT_CACHED;
} }
#endif #endif
ext3_discard_reservation(inode); ext4_discard_reservation(inode);
EXT3_I(inode)->i_block_alloc_info = NULL; EXT4_I(inode)->i_block_alloc_info = NULL;
if (unlikely(rsv)) if (unlikely(rsv))
kfree(rsv); kfree(rsv);
} }
static inline void ext3_show_quota_options(struct seq_file *seq, struct super_block *sb) static inline void ext4_show_quota_options(struct seq_file *seq, struct super_block *sb)
{ {
#if defined(CONFIG_QUOTA) #if defined(CONFIG_QUOTA)
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
if (sbi->s_jquota_fmt) if (sbi->s_jquota_fmt)
seq_printf(seq, ",jqfmt=%s", seq_printf(seq, ",jqfmt=%s",
...@@ -530,32 +530,32 @@ static inline void ext3_show_quota_options(struct seq_file *seq, struct super_bl ...@@ -530,32 +530,32 @@ static inline void ext3_show_quota_options(struct seq_file *seq, struct super_bl
if (sbi->s_qf_names[GRPQUOTA]) if (sbi->s_qf_names[GRPQUOTA])
seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]); seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]);
if (sbi->s_mount_opt & EXT3_MOUNT_USRQUOTA) if (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA)
seq_puts(seq, ",usrquota"); seq_puts(seq, ",usrquota");
if (sbi->s_mount_opt & EXT3_MOUNT_GRPQUOTA) if (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)
seq_puts(seq, ",grpquota"); seq_puts(seq, ",grpquota");
#endif #endif
} }
static int ext3_show_options(struct seq_file *seq, struct vfsmount *vfs) static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
{ {
struct super_block *sb = vfs->mnt_sb; struct super_block *sb = vfs->mnt_sb;
if (test_opt(sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA) if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
seq_puts(seq, ",data=journal"); seq_puts(seq, ",data=journal");
else if (test_opt(sb, DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA) else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
seq_puts(seq, ",data=ordered"); seq_puts(seq, ",data=ordered");
else if (test_opt(sb, DATA_FLAGS) == EXT3_MOUNT_WRITEBACK_DATA) else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
seq_puts(seq, ",data=writeback"); seq_puts(seq, ",data=writeback");
ext3_show_quota_options(seq, sb); ext4_show_quota_options(seq, sb);
return 0; return 0;
} }
static struct dentry *ext3_get_dentry(struct super_block *sb, void *vobjp) static struct dentry *ext4_get_dentry(struct super_block *sb, void *vobjp)
{ {
__u32 *objp = vobjp; __u32 *objp = vobjp;
unsigned long ino = objp[0]; unsigned long ino = objp[0];
...@@ -563,14 +563,14 @@ static struct dentry *ext3_get_dentry(struct super_block *sb, void *vobjp) ...@@ -563,14 +563,14 @@ static struct dentry *ext3_get_dentry(struct super_block *sb, void *vobjp)
struct inode *inode; struct inode *inode;
struct dentry *result; struct dentry *result;
if (ino < EXT3_FIRST_INO(sb) && ino != EXT3_ROOT_INO) if (ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO)
return ERR_PTR(-ESTALE); return ERR_PTR(-ESTALE);
if (ino > le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count)) if (ino > le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count))
return ERR_PTR(-ESTALE); return ERR_PTR(-ESTALE);
/* iget isn't really right if the inode is currently unallocated!! /* iget isn't really right if the inode is currently unallocated!!
* *
* ext3_read_inode will return a bad_inode if the inode had been * ext4_read_inode will return a bad_inode if the inode had been
* deleted, so we should be safe. * deleted, so we should be safe.
* *
* Currently we don't know the generation for parent directory, so * 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,37 +599,37 @@ static struct dentry *ext3_get_dentry(struct super_block *sb, void *vobjp)
#define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group") #define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
#define QTYPE2MOPT(on, t) ((t)==USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA)) #define QTYPE2MOPT(on, t) ((t)==USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA))
static int ext3_dquot_initialize(struct inode *inode, int type); static int ext4_dquot_initialize(struct inode *inode, int type);
static int ext3_dquot_drop(struct inode *inode); static int ext4_dquot_drop(struct inode *inode);
static int ext3_write_dquot(struct dquot *dquot); static int ext4_write_dquot(struct dquot *dquot);
static int ext3_acquire_dquot(struct dquot *dquot); static int ext4_acquire_dquot(struct dquot *dquot);
static int ext3_release_dquot(struct dquot *dquot); static int ext4_release_dquot(struct dquot *dquot);
static int ext3_mark_dquot_dirty(struct dquot *dquot); static int ext4_mark_dquot_dirty(struct dquot *dquot);
static int ext3_write_info(struct super_block *sb, int type); static int ext4_write_info(struct super_block *sb, int type);
static int ext3_quota_on(struct super_block *sb, int type, int format_id, char *path); static int ext4_quota_on(struct super_block *sb, int type, int format_id, char *path);
static int ext3_quota_on_mount(struct super_block *sb, int type); static int ext4_quota_on_mount(struct super_block *sb, int type);
static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data, static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
size_t len, loff_t off); size_t len, loff_t off);
static ssize_t ext3_quota_write(struct super_block *sb, int type, static ssize_t ext4_quota_write(struct super_block *sb, int type,
const char *data, size_t len, loff_t off); const char *data, size_t len, loff_t off);
static struct dquot_operations ext3_quota_operations = { static struct dquot_operations ext4_quota_operations = {
.initialize = ext3_dquot_initialize, .initialize = ext4_dquot_initialize,
.drop = ext3_dquot_drop, .drop = ext4_dquot_drop,
.alloc_space = dquot_alloc_space, .alloc_space = dquot_alloc_space,
.alloc_inode = dquot_alloc_inode, .alloc_inode = dquot_alloc_inode,
.free_space = dquot_free_space, .free_space = dquot_free_space,
.free_inode = dquot_free_inode, .free_inode = dquot_free_inode,
.transfer = dquot_transfer, .transfer = dquot_transfer,
.write_dquot = ext3_write_dquot, .write_dquot = ext4_write_dquot,
.acquire_dquot = ext3_acquire_dquot, .acquire_dquot = ext4_acquire_dquot,
.release_dquot = ext3_release_dquot, .release_dquot = ext4_release_dquot,
.mark_dirty = ext3_mark_dquot_dirty, .mark_dirty = ext4_mark_dquot_dirty,
.write_info = ext3_write_info .write_info = ext4_write_info
}; };
static struct quotactl_ops ext3_qctl_operations = { static struct quotactl_ops ext4_qctl_operations = {
.quota_on = ext3_quota_on, .quota_on = ext4_quota_on,
.quota_off = vfs_quota_off, .quota_off = vfs_quota_off,
.quota_sync = vfs_quota_sync, .quota_sync = vfs_quota_sync,
.get_info = vfs_get_dqinfo, .get_info = vfs_get_dqinfo,
...@@ -639,31 +639,31 @@ static struct quotactl_ops ext3_qctl_operations = { ...@@ -639,31 +639,31 @@ static struct quotactl_ops ext3_qctl_operations = {
}; };
#endif #endif
static struct super_operations ext3_sops = { static struct super_operations ext4_sops = {
.alloc_inode = ext3_alloc_inode, .alloc_inode = ext4_alloc_inode,
.destroy_inode = ext3_destroy_inode, .destroy_inode = ext4_destroy_inode,
.read_inode = ext3_read_inode, .read_inode = ext4_read_inode,
.write_inode = ext3_write_inode, .write_inode = ext4_write_inode,
.dirty_inode = ext3_dirty_inode, .dirty_inode = ext4_dirty_inode,
.delete_inode = ext3_delete_inode, .delete_inode = ext4_delete_inode,
.put_super = ext3_put_super, .put_super = ext4_put_super,
.write_super = ext3_write_super, .write_super = ext4_write_super,
.sync_fs = ext3_sync_fs, .sync_fs = ext4_sync_fs,
.write_super_lockfs = ext3_write_super_lockfs, .write_super_lockfs = ext4_write_super_lockfs,
.unlockfs = ext3_unlockfs, .unlockfs = ext4_unlockfs,
.statfs = ext3_statfs, .statfs = ext4_statfs,
.remount_fs = ext3_remount, .remount_fs = ext4_remount,
.clear_inode = ext3_clear_inode, .clear_inode = ext4_clear_inode,
.show_options = ext3_show_options, .show_options = ext4_show_options,
#ifdef CONFIG_QUOTA #ifdef CONFIG_QUOTA
.quota_read = ext3_quota_read, .quota_read = ext4_quota_read,
.quota_write = ext3_quota_write, .quota_write = ext4_quota_write,
#endif #endif
}; };
static struct export_operations ext3_export_ops = { static struct export_operations ext4_export_ops = {
.get_parent = ext3_get_parent, .get_parent = ext4_get_parent,
.get_dentry = ext3_get_dentry, .get_dentry = ext4_get_dentry,
}; };
enum { enum {
...@@ -731,18 +731,18 @@ static match_table_t tokens = { ...@@ -731,18 +731,18 @@ static match_table_t tokens = {
{Opt_resize, "resize"}, {Opt_resize, "resize"},
}; };
static ext3_fsblk_t get_sb_block(void **data) static ext4_fsblk_t get_sb_block(void **data)
{ {
ext3_fsblk_t sb_block; ext4_fsblk_t sb_block;
char *options = (char *) *data; char *options = (char *) *data;
if (!options || strncmp(options, "sb=", 3) != 0) if (!options || strncmp(options, "sb=", 3) != 0)
return 1; /* Default location */ return 1; /* Default location */
options += 3; options += 3;
/*todo: use simple_strtoll with >32bit ext3 */ /*todo: use simple_strtoll with >32bit ext4 */
sb_block = simple_strtoul(options, &options, 0); sb_block = simple_strtoul(options, &options, 0);
if (*options && *options != ',') { if (*options && *options != ',') {
printk("EXT3-fs: Invalid sb specification: %s\n", printk("EXT4-fs: Invalid sb specification: %s\n",
(char *) *data); (char *) *data);
return 1; return 1;
} }
...@@ -754,9 +754,9 @@ static ext3_fsblk_t get_sb_block(void **data) ...@@ -754,9 +754,9 @@ static ext3_fsblk_t get_sb_block(void **data)
static int parse_options (char *options, struct super_block *sb, static int parse_options (char *options, struct super_block *sb,
unsigned int *inum, unsigned long *journal_devnum, unsigned int *inum, unsigned long *journal_devnum,
ext3_fsblk_t *n_blocks_count, int is_remount) ext4_fsblk_t *n_blocks_count, int is_remount)
{ {
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
char * p; char * p;
substring_t args[MAX_OPT_ARGS]; substring_t args[MAX_OPT_ARGS];
int data_opt = 0; int data_opt = 0;
...@@ -832,7 +832,7 @@ static int parse_options (char *options, struct super_block *sb, ...@@ -832,7 +832,7 @@ static int parse_options (char *options, struct super_block *sb,
case Opt_orlov: case Opt_orlov:
clear_opt (sbi->s_mount_opt, OLDALLOC); clear_opt (sbi->s_mount_opt, OLDALLOC);
break; break;
#ifdef CONFIG_EXT3_FS_XATTR #ifdef CONFIG_EXT4DEV_FS_XATTR
case Opt_user_xattr: case Opt_user_xattr:
set_opt (sbi->s_mount_opt, XATTR_USER); set_opt (sbi->s_mount_opt, XATTR_USER);
break; break;
...@@ -842,10 +842,10 @@ static int parse_options (char *options, struct super_block *sb, ...@@ -842,10 +842,10 @@ static int parse_options (char *options, struct super_block *sb,
#else #else
case Opt_user_xattr: case Opt_user_xattr:
case Opt_nouser_xattr: case Opt_nouser_xattr:
printk("EXT3 (no)user_xattr options not supported\n"); printk("EXT4 (no)user_xattr options not supported\n");
break; break;
#endif #endif
#ifdef CONFIG_EXT3_FS_POSIX_ACL #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
case Opt_acl: case Opt_acl:
set_opt(sbi->s_mount_opt, POSIX_ACL); set_opt(sbi->s_mount_opt, POSIX_ACL);
break; break;
...@@ -855,7 +855,7 @@ static int parse_options (char *options, struct super_block *sb, ...@@ -855,7 +855,7 @@ static int parse_options (char *options, struct super_block *sb,
#else #else
case Opt_acl: case Opt_acl:
case Opt_noacl: case Opt_noacl:
printk("EXT3 (no)acl options not supported\n"); printk("EXT4 (no)acl options not supported\n");
break; break;
#endif #endif
case Opt_reservation: case Opt_reservation:
...@@ -871,7 +871,7 @@ static int parse_options (char *options, struct super_block *sb, ...@@ -871,7 +871,7 @@ static int parse_options (char *options, struct super_block *sb,
user to specify an existing inode to be the user to specify an existing inode to be the
journal file. */ journal file. */
if (is_remount) { if (is_remount) {
printk(KERN_ERR "EXT3-fs: cannot specify " printk(KERN_ERR "EXT4-fs: cannot specify "
"journal on remount\n"); "journal on remount\n");
return 0; return 0;
} }
...@@ -879,7 +879,7 @@ static int parse_options (char *options, struct super_block *sb, ...@@ -879,7 +879,7 @@ static int parse_options (char *options, struct super_block *sb,
break; break;
case Opt_journal_inum: case Opt_journal_inum:
if (is_remount) { if (is_remount) {
printk(KERN_ERR "EXT3-fs: cannot specify " printk(KERN_ERR "EXT4-fs: cannot specify "
"journal on remount\n"); "journal on remount\n");
return 0; return 0;
} }
...@@ -889,7 +889,7 @@ static int parse_options (char *options, struct super_block *sb, ...@@ -889,7 +889,7 @@ static int parse_options (char *options, struct super_block *sb,
break; break;
case Opt_journal_dev: case Opt_journal_dev:
if (is_remount) { if (is_remount) {
printk(KERN_ERR "EXT3-fs: cannot specify " printk(KERN_ERR "EXT4-fs: cannot specify "
"journal on remount\n"); "journal on remount\n");
return 0; return 0;
} }
...@@ -910,24 +910,24 @@ static int parse_options (char *options, struct super_block *sb, ...@@ -910,24 +910,24 @@ static int parse_options (char *options, struct super_block *sb,
sbi->s_commit_interval = HZ * option; sbi->s_commit_interval = HZ * option;
break; break;
case Opt_data_journal: case Opt_data_journal:
data_opt = EXT3_MOUNT_JOURNAL_DATA; data_opt = EXT4_MOUNT_JOURNAL_DATA;
goto datacheck; goto datacheck;
case Opt_data_ordered: case Opt_data_ordered:
data_opt = EXT3_MOUNT_ORDERED_DATA; data_opt = EXT4_MOUNT_ORDERED_DATA;
goto datacheck; goto datacheck;
case Opt_data_writeback: case Opt_data_writeback:
data_opt = EXT3_MOUNT_WRITEBACK_DATA; data_opt = EXT4_MOUNT_WRITEBACK_DATA;
datacheck: datacheck:
if (is_remount) { if (is_remount) {
if ((sbi->s_mount_opt & EXT3_MOUNT_DATA_FLAGS) if ((sbi->s_mount_opt & EXT4_MOUNT_DATA_FLAGS)
!= data_opt) { != data_opt) {
printk(KERN_ERR printk(KERN_ERR
"EXT3-fs: cannot change data " "EXT4-fs: cannot change data "
"mode on remount\n"); "mode on remount\n");
return 0; return 0;
} }
} else { } else {
sbi->s_mount_opt &= ~EXT3_MOUNT_DATA_FLAGS; sbi->s_mount_opt &= ~EXT4_MOUNT_DATA_FLAGS;
sbi->s_mount_opt |= data_opt; sbi->s_mount_opt |= data_opt;
} }
break; break;
...@@ -940,21 +940,21 @@ static int parse_options (char *options, struct super_block *sb, ...@@ -940,21 +940,21 @@ static int parse_options (char *options, struct super_block *sb,
set_qf_name: set_qf_name:
if (sb_any_quota_enabled(sb)) { if (sb_any_quota_enabled(sb)) {
printk(KERN_ERR printk(KERN_ERR
"EXT3-fs: Cannot change journalled " "EXT4-fs: Cannot change journalled "
"quota options when quota turned on.\n"); "quota options when quota turned on.\n");
return 0; return 0;
} }
qname = match_strdup(&args[0]); qname = match_strdup(&args[0]);
if (!qname) { if (!qname) {
printk(KERN_ERR printk(KERN_ERR
"EXT3-fs: not enough memory for " "EXT4-fs: not enough memory for "
"storing quotafile name.\n"); "storing quotafile name.\n");
return 0; return 0;
} }
if (sbi->s_qf_names[qtype] && if (sbi->s_qf_names[qtype] &&
strcmp(sbi->s_qf_names[qtype], qname)) { strcmp(sbi->s_qf_names[qtype], qname)) {
printk(KERN_ERR printk(KERN_ERR
"EXT3-fs: %s quota file already " "EXT4-fs: %s quota file already "
"specified.\n", QTYPE2NAME(qtype)); "specified.\n", QTYPE2NAME(qtype));
kfree(qname); kfree(qname);
return 0; return 0;
...@@ -962,7 +962,7 @@ static int parse_options (char *options, struct super_block *sb, ...@@ -962,7 +962,7 @@ static int parse_options (char *options, struct super_block *sb,
sbi->s_qf_names[qtype] = qname; sbi->s_qf_names[qtype] = qname;
if (strchr(sbi->s_qf_names[qtype], '/')) { if (strchr(sbi->s_qf_names[qtype], '/')) {
printk(KERN_ERR printk(KERN_ERR
"EXT3-fs: quotafile must be on " "EXT4-fs: quotafile must be on "
"filesystem root.\n"); "filesystem root.\n");
kfree(sbi->s_qf_names[qtype]); kfree(sbi->s_qf_names[qtype]);
sbi->s_qf_names[qtype] = NULL; sbi->s_qf_names[qtype] = NULL;
...@@ -977,7 +977,7 @@ static int parse_options (char *options, struct super_block *sb, ...@@ -977,7 +977,7 @@ static int parse_options (char *options, struct super_block *sb,
qtype = GRPQUOTA; qtype = GRPQUOTA;
clear_qf_name: clear_qf_name:
if (sb_any_quota_enabled(sb)) { if (sb_any_quota_enabled(sb)) {
printk(KERN_ERR "EXT3-fs: Cannot change " printk(KERN_ERR "EXT4-fs: Cannot change "
"journalled quota options when " "journalled quota options when "
"quota turned on.\n"); "quota turned on.\n");
return 0; return 0;
...@@ -1005,7 +1005,7 @@ static int parse_options (char *options, struct super_block *sb, ...@@ -1005,7 +1005,7 @@ static int parse_options (char *options, struct super_block *sb,
break; break;
case Opt_noquota: case Opt_noquota:
if (sb_any_quota_enabled(sb)) { if (sb_any_quota_enabled(sb)) {
printk(KERN_ERR "EXT3-fs: Cannot change quota " printk(KERN_ERR "EXT4-fs: Cannot change quota "
"options when quota turned on.\n"); "options when quota turned on.\n");
return 0; return 0;
} }
...@@ -1024,7 +1024,7 @@ static int parse_options (char *options, struct super_block *sb, ...@@ -1024,7 +1024,7 @@ static int parse_options (char *options, struct super_block *sb,
case Opt_jqfmt_vfsold: case Opt_jqfmt_vfsold:
case Opt_jqfmt_vfsv0: case Opt_jqfmt_vfsv0:
printk(KERN_ERR printk(KERN_ERR
"EXT3-fs: journalled quota options not " "EXT4-fs: journalled quota options not "
"supported.\n"); "supported.\n");
break; break;
case Opt_noquota: case Opt_noquota:
...@@ -1045,7 +1045,7 @@ static int parse_options (char *options, struct super_block *sb, ...@@ -1045,7 +1045,7 @@ static int parse_options (char *options, struct super_block *sb,
break; break;
case Opt_resize: case Opt_resize:
if (!is_remount) { if (!is_remount) {
printk("EXT3-fs: resize option only available " printk("EXT4-fs: resize option only available "
"for remount\n"); "for remount\n");
return 0; return 0;
} }
...@@ -1061,38 +1061,38 @@ static int parse_options (char *options, struct super_block *sb, ...@@ -1061,38 +1061,38 @@ static int parse_options (char *options, struct super_block *sb,
break; break;
default: default:
printk (KERN_ERR printk (KERN_ERR
"EXT3-fs: Unrecognized mount option \"%s\" " "EXT4-fs: Unrecognized mount option \"%s\" "
"or missing value\n", p); "or missing value\n", p);
return 0; return 0;
} }
} }
#ifdef CONFIG_QUOTA #ifdef CONFIG_QUOTA
if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) { if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) {
if ((sbi->s_mount_opt & EXT3_MOUNT_USRQUOTA) && if ((sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA) &&
sbi->s_qf_names[USRQUOTA]) sbi->s_qf_names[USRQUOTA])
clear_opt(sbi->s_mount_opt, USRQUOTA); clear_opt(sbi->s_mount_opt, USRQUOTA);
if ((sbi->s_mount_opt & EXT3_MOUNT_GRPQUOTA) && if ((sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA) &&
sbi->s_qf_names[GRPQUOTA]) sbi->s_qf_names[GRPQUOTA])
clear_opt(sbi->s_mount_opt, GRPQUOTA); clear_opt(sbi->s_mount_opt, GRPQUOTA);
if ((sbi->s_qf_names[USRQUOTA] && if ((sbi->s_qf_names[USRQUOTA] &&
(sbi->s_mount_opt & EXT3_MOUNT_GRPQUOTA)) || (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)) ||
(sbi->s_qf_names[GRPQUOTA] && (sbi->s_qf_names[GRPQUOTA] &&
(sbi->s_mount_opt & EXT3_MOUNT_USRQUOTA))) { (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA))) {
printk(KERN_ERR "EXT3-fs: old and new quota " printk(KERN_ERR "EXT4-fs: old and new quota "
"format mixing.\n"); "format mixing.\n");
return 0; return 0;
} }
if (!sbi->s_jquota_fmt) { if (!sbi->s_jquota_fmt) {
printk(KERN_ERR "EXT3-fs: journalled quota format " printk(KERN_ERR "EXT4-fs: journalled quota format "
"not specified.\n"); "not specified.\n");
return 0; return 0;
} }
} else { } else {
if (sbi->s_jquota_fmt) { if (sbi->s_jquota_fmt) {
printk(KERN_ERR "EXT3-fs: journalled quota format " printk(KERN_ERR "EXT4-fs: journalled quota format "
"specified with no journalling " "specified with no journalling "
"enabled.\n"); "enabled.\n");
return 0; return 0;
...@@ -1102,68 +1102,68 @@ static int parse_options (char *options, struct super_block *sb, ...@@ -1102,68 +1102,68 @@ static int parse_options (char *options, struct super_block *sb,
return 1; return 1;
} }
static int ext3_setup_super(struct super_block *sb, struct ext3_super_block *es, static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
int read_only) int read_only)
{ {
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
int res = 0; int res = 0;
if (le32_to_cpu(es->s_rev_level) > EXT3_MAX_SUPP_REV) { if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) {
printk (KERN_ERR "EXT3-fs warning: revision level too high, " printk (KERN_ERR "EXT4-fs warning: revision level too high, "
"forcing read-only mode\n"); "forcing read-only mode\n");
res = MS_RDONLY; res = MS_RDONLY;
} }
if (read_only) if (read_only)
return res; return res;
if (!(sbi->s_mount_state & EXT3_VALID_FS)) if (!(sbi->s_mount_state & EXT4_VALID_FS))
printk (KERN_WARNING "EXT3-fs warning: mounting unchecked fs, " printk (KERN_WARNING "EXT4-fs warning: mounting unchecked fs, "
"running e2fsck is recommended\n"); "running e2fsck is recommended\n");
else if ((sbi->s_mount_state & EXT3_ERROR_FS)) else if ((sbi->s_mount_state & EXT4_ERROR_FS))
printk (KERN_WARNING printk (KERN_WARNING
"EXT3-fs warning: mounting fs with errors, " "EXT4-fs warning: mounting fs with errors, "
"running e2fsck is recommended\n"); "running e2fsck is recommended\n");
else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 && else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 &&
le16_to_cpu(es->s_mnt_count) >= le16_to_cpu(es->s_mnt_count) >=
(unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count)) (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count))
printk (KERN_WARNING printk (KERN_WARNING
"EXT3-fs warning: maximal mount count reached, " "EXT4-fs warning: maximal mount count reached, "
"running e2fsck is recommended\n"); "running e2fsck is recommended\n");
else if (le32_to_cpu(es->s_checkinterval) && else if (le32_to_cpu(es->s_checkinterval) &&
(le32_to_cpu(es->s_lastcheck) + (le32_to_cpu(es->s_lastcheck) +
le32_to_cpu(es->s_checkinterval) <= get_seconds())) le32_to_cpu(es->s_checkinterval) <= get_seconds()))
printk (KERN_WARNING printk (KERN_WARNING
"EXT3-fs warning: checktime reached, " "EXT4-fs warning: checktime reached, "
"running e2fsck is recommended\n"); "running e2fsck is recommended\n");
#if 0 #if 0
/* @@@ We _will_ want to clear the valid bit if we find /* @@@ We _will_ want to clear the valid bit if we find
inconsistencies, to force a fsck at reboot. But for inconsistencies, to force a fsck at reboot. But for
a plain journaled filesystem we can keep it set as a plain journaled filesystem we can keep it set as
valid forever! :) */ valid forever! :) */
es->s_state = cpu_to_le16(le16_to_cpu(es->s_state) & ~EXT3_VALID_FS); es->s_state = cpu_to_le16(le16_to_cpu(es->s_state) & ~EXT4_VALID_FS);
#endif #endif
if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
es->s_max_mnt_count = cpu_to_le16(EXT3_DFL_MAX_MNT_COUNT); es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
es->s_mnt_count=cpu_to_le16(le16_to_cpu(es->s_mnt_count) + 1); es->s_mnt_count=cpu_to_le16(le16_to_cpu(es->s_mnt_count) + 1);
es->s_mtime = cpu_to_le32(get_seconds()); es->s_mtime = cpu_to_le32(get_seconds());
ext3_update_dynamic_rev(sb); ext4_update_dynamic_rev(sb);
EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
ext3_commit_super(sb, es, 1); ext4_commit_super(sb, es, 1);
if (test_opt(sb, DEBUG)) if (test_opt(sb, DEBUG))
printk(KERN_INFO "[EXT3 FS bs=%lu, gc=%lu, " printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%lu, "
"bpg=%lu, ipg=%lu, mo=%04lx]\n", "bpg=%lu, ipg=%lu, mo=%04lx]\n",
sb->s_blocksize, sb->s_blocksize,
sbi->s_groups_count, sbi->s_groups_count,
EXT3_BLOCKS_PER_GROUP(sb), EXT4_BLOCKS_PER_GROUP(sb),
EXT3_INODES_PER_GROUP(sb), EXT4_INODES_PER_GROUP(sb),
sbi->s_mount_opt); sbi->s_mount_opt);
printk(KERN_INFO "EXT3 FS on %s, ", sb->s_id); printk(KERN_INFO "EXT4 FS on %s, ", sb->s_id);
if (EXT3_SB(sb)->s_journal->j_inode == NULL) { if (EXT4_SB(sb)->s_journal->j_inode == NULL) {
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
printk("external journal on %s\n", printk("external journal on %s\n",
bdevname(EXT3_SB(sb)->s_journal->j_dev, b)); bdevname(EXT4_SB(sb)->s_journal->j_dev, b));
} else { } else {
printk("internal journal\n"); printk("internal journal\n");
} }
...@@ -1171,16 +1171,16 @@ static int ext3_setup_super(struct super_block *sb, struct ext3_super_block *es, ...@@ -1171,16 +1171,16 @@ static int ext3_setup_super(struct super_block *sb, struct ext3_super_block *es,
} }
/* Called at mount-time, super-block is locked */ /* Called at mount-time, super-block is locked */
static int ext3_check_descriptors (struct super_block * sb) static int ext4_check_descriptors (struct super_block * sb)
{ {
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
ext3_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block); ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
ext3_fsblk_t last_block; ext4_fsblk_t last_block;
struct ext3_group_desc * gdp = NULL; struct ext4_group_desc * gdp = NULL;
int desc_block = 0; int desc_block = 0;
int i; int i;
ext3_debug ("Checking group descriptors"); ext4_debug ("Checking group descriptors");
for (i = 0; i < sbi->s_groups_count; i++) for (i = 0; i < sbi->s_groups_count; i++)
{ {
...@@ -1188,15 +1188,15 @@ static int ext3_check_descriptors (struct super_block * sb) ...@@ -1188,15 +1188,15 @@ static int ext3_check_descriptors (struct super_block * sb)
last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1; last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1;
else else
last_block = first_block + last_block = first_block +
(EXT3_BLOCKS_PER_GROUP(sb) - 1); (EXT4_BLOCKS_PER_GROUP(sb) - 1);
if ((i % EXT3_DESC_PER_BLOCK(sb)) == 0) if ((i % EXT4_DESC_PER_BLOCK(sb)) == 0)
gdp = (struct ext3_group_desc *) gdp = (struct ext4_group_desc *)
sbi->s_group_desc[desc_block++]->b_data; sbi->s_group_desc[desc_block++]->b_data;
if (le32_to_cpu(gdp->bg_block_bitmap) < first_block || if (le32_to_cpu(gdp->bg_block_bitmap) < first_block ||
le32_to_cpu(gdp->bg_block_bitmap) > last_block) le32_to_cpu(gdp->bg_block_bitmap) > last_block)
{ {
ext3_error (sb, "ext3_check_descriptors", ext4_error (sb, "ext4_check_descriptors",
"Block bitmap for group %d" "Block bitmap for group %d"
" not in group (block %lu)!", " not in group (block %lu)!",
i, (unsigned long) i, (unsigned long)
...@@ -1206,7 +1206,7 @@ static int ext3_check_descriptors (struct super_block * sb) ...@@ -1206,7 +1206,7 @@ static int ext3_check_descriptors (struct super_block * sb)
if (le32_to_cpu(gdp->bg_inode_bitmap) < first_block || if (le32_to_cpu(gdp->bg_inode_bitmap) < first_block ||
le32_to_cpu(gdp->bg_inode_bitmap) > last_block) le32_to_cpu(gdp->bg_inode_bitmap) > last_block)
{ {
ext3_error (sb, "ext3_check_descriptors", ext4_error (sb, "ext4_check_descriptors",
"Inode bitmap for group %d" "Inode bitmap for group %d"
" not in group (block %lu)!", " not in group (block %lu)!",
i, (unsigned long) i, (unsigned long)
...@@ -1217,24 +1217,24 @@ static int ext3_check_descriptors (struct super_block * sb) ...@@ -1217,24 +1217,24 @@ static int ext3_check_descriptors (struct super_block * sb)
le32_to_cpu(gdp->bg_inode_table) + sbi->s_itb_per_group > le32_to_cpu(gdp->bg_inode_table) + sbi->s_itb_per_group >
last_block) last_block)
{ {
ext3_error (sb, "ext3_check_descriptors", ext4_error (sb, "ext4_check_descriptors",
"Inode table for group %d" "Inode table for group %d"
" not in group (block %lu)!", " not in group (block %lu)!",
i, (unsigned long) i, (unsigned long)
le32_to_cpu(gdp->bg_inode_table)); le32_to_cpu(gdp->bg_inode_table));
return 0; return 0;
} }
first_block += EXT3_BLOCKS_PER_GROUP(sb); first_block += EXT4_BLOCKS_PER_GROUP(sb);
gdp++; gdp++;
} }
sbi->s_es->s_free_blocks_count=cpu_to_le32(ext3_count_free_blocks(sb)); sbi->s_es->s_free_blocks_count=cpu_to_le32(ext4_count_free_blocks(sb));
sbi->s_es->s_free_inodes_count=cpu_to_le32(ext3_count_free_inodes(sb)); sbi->s_es->s_free_inodes_count=cpu_to_le32(ext4_count_free_inodes(sb));
return 1; return 1;
} }
/* ext3_orphan_cleanup() walks a singly-linked list of inodes (starting at /* ext4_orphan_cleanup() walks a singly-linked list of inodes (starting at
* the superblock) which were deleted from all directories, but held open by * the superblock) which were deleted from all directories, but held open by
* a process at the time of a crash. We walk the list and try to delete these * a process at the time of a crash. We walk the list and try to delete these
* inodes at recovery time (only with a read-write filesystem). * inodes at recovery time (only with a read-write filesystem).
...@@ -1247,12 +1247,12 @@ static int ext3_check_descriptors (struct super_block * sb) ...@@ -1247,12 +1247,12 @@ static int ext3_check_descriptors (struct super_block * sb)
* We only do an iget() and an iput() on each inode, which is very safe if we * We only do an iget() and an iput() on each inode, which is very safe if we
* accidentally point at an in-use or already deleted inode. The worst that * accidentally point at an in-use or already deleted inode. The worst that
* can happen in this case is that we get a "bit already cleared" message from * can happen in this case is that we get a "bit already cleared" message from
* ext3_free_inode(). The only reason we would point at a wrong inode is if * ext4_free_inode(). The only reason we would point at a wrong inode is if
* e2fsck was run on this filesystem, and it must have already done the orphan * e2fsck was run on this filesystem, and it must have already done the orphan
* inode cleanup for us, so we can safely abort without any further action. * inode cleanup for us, so we can safely abort without any further action.
*/ */
static void ext3_orphan_cleanup (struct super_block * sb, static void ext4_orphan_cleanup (struct super_block * sb,
struct ext3_super_block * es) struct ext4_super_block * es)
{ {
unsigned int s_flags = sb->s_flags; unsigned int s_flags = sb->s_flags;
int nr_orphans = 0, nr_truncates = 0; int nr_orphans = 0, nr_truncates = 0;
...@@ -1264,7 +1264,7 @@ static void ext3_orphan_cleanup (struct super_block * sb, ...@@ -1264,7 +1264,7 @@ static void ext3_orphan_cleanup (struct super_block * sb,
return; return;
} }
if (EXT3_SB(sb)->s_mount_state & EXT3_ERROR_FS) { if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) {
if (es->s_last_orphan) if (es->s_last_orphan)
jbd_debug(1, "Errors on filesystem, " jbd_debug(1, "Errors on filesystem, "
"clearing orphan list.\n"); "clearing orphan list.\n");
...@@ -1274,7 +1274,7 @@ static void ext3_orphan_cleanup (struct super_block * sb, ...@@ -1274,7 +1274,7 @@ static void ext3_orphan_cleanup (struct super_block * sb,
} }
if (s_flags & MS_RDONLY) { if (s_flags & MS_RDONLY) {
printk(KERN_INFO "EXT3-fs: %s: orphan cleanup on readonly fs\n", printk(KERN_INFO "EXT4-fs: %s: orphan cleanup on readonly fs\n",
sb->s_id); sb->s_id);
sb->s_flags &= ~MS_RDONLY; sb->s_flags &= ~MS_RDONLY;
} }
...@@ -1283,11 +1283,11 @@ static void ext3_orphan_cleanup (struct super_block * sb, ...@@ -1283,11 +1283,11 @@ static void ext3_orphan_cleanup (struct super_block * sb,
sb->s_flags |= MS_ACTIVE; sb->s_flags |= MS_ACTIVE;
/* Turn on quotas so that they are updated correctly */ /* Turn on quotas so that they are updated correctly */
for (i = 0; i < MAXQUOTAS; i++) { for (i = 0; i < MAXQUOTAS; i++) {
if (EXT3_SB(sb)->s_qf_names[i]) { if (EXT4_SB(sb)->s_qf_names[i]) {
int ret = ext3_quota_on_mount(sb, i); int ret = ext4_quota_on_mount(sb, i);
if (ret < 0) if (ret < 0)
printk(KERN_ERR printk(KERN_ERR
"EXT3-fs: Cannot turn on journalled " "EXT4-fs: Cannot turn on journalled "
"quota: error %d\n", ret); "quota: error %d\n", ret);
} }
} }
...@@ -1297,12 +1297,12 @@ static void ext3_orphan_cleanup (struct super_block * sb, ...@@ -1297,12 +1297,12 @@ static void ext3_orphan_cleanup (struct super_block * sb,
struct inode *inode; struct inode *inode;
if (!(inode = if (!(inode =
ext3_orphan_get(sb, le32_to_cpu(es->s_last_orphan)))) { ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan)))) {
es->s_last_orphan = 0; es->s_last_orphan = 0;
break; break;
} }
list_add(&EXT3_I(inode)->i_orphan, &EXT3_SB(sb)->s_orphan); list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
DQUOT_INIT(inode); DQUOT_INIT(inode);
if (inode->i_nlink) { if (inode->i_nlink) {
printk(KERN_DEBUG printk(KERN_DEBUG
...@@ -1310,7 +1310,7 @@ static void ext3_orphan_cleanup (struct super_block * sb, ...@@ -1310,7 +1310,7 @@ static void ext3_orphan_cleanup (struct super_block * sb,
__FUNCTION__, inode->i_ino, inode->i_size); __FUNCTION__, inode->i_ino, inode->i_size);
jbd_debug(2, "truncating inode %lu to %Ld bytes\n", jbd_debug(2, "truncating inode %lu to %Ld bytes\n",
inode->i_ino, inode->i_size); inode->i_ino, inode->i_size);
ext3_truncate(inode); ext4_truncate(inode);
nr_truncates++; nr_truncates++;
} else { } else {
printk(KERN_DEBUG printk(KERN_DEBUG
...@@ -1326,10 +1326,10 @@ static void ext3_orphan_cleanup (struct super_block * sb, ...@@ -1326,10 +1326,10 @@ static void ext3_orphan_cleanup (struct super_block * sb,
#define PLURAL(x) (x), ((x)==1) ? "" : "s" #define PLURAL(x) (x), ((x)==1) ? "" : "s"
if (nr_orphans) if (nr_orphans)
printk(KERN_INFO "EXT3-fs: %s: %d orphan inode%s deleted\n", printk(KERN_INFO "EXT4-fs: %s: %d orphan inode%s deleted\n",
sb->s_id, PLURAL(nr_orphans)); sb->s_id, PLURAL(nr_orphans));
if (nr_truncates) if (nr_truncates)
printk(KERN_INFO "EXT3-fs: %s: %d truncate%s cleaned up\n", printk(KERN_INFO "EXT4-fs: %s: %d truncate%s cleaned up\n",
sb->s_id, PLURAL(nr_truncates)); sb->s_id, PLURAL(nr_truncates));
#ifdef CONFIG_QUOTA #ifdef CONFIG_QUOTA
/* Turn quotas off */ /* Turn quotas off */
...@@ -1348,9 +1348,9 @@ static void ext3_orphan_cleanup (struct super_block * sb, ...@@ -1348,9 +1348,9 @@ static void ext3_orphan_cleanup (struct super_block * sb,
* block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks. * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks.
* We need to be 1 filesystem block less than the 2^32 sector limit. * We need to be 1 filesystem block less than the 2^32 sector limit.
*/ */
static loff_t ext3_max_size(int bits) static loff_t ext4_max_size(int bits)
{ {
loff_t res = EXT3_NDIR_BLOCKS; loff_t res = EXT4_NDIR_BLOCKS;
/* This constant is calculated to be the largest file size for a /* This constant is calculated to be the largest file size for a
* dense, 4k-blocksize file such that the total number of * dense, 4k-blocksize file such that the total number of
* sectors in the file, including data and all indirect blocks, * sectors in the file, including data and all indirect blocks,
...@@ -1366,34 +1366,34 @@ static loff_t ext3_max_size(int bits) ...@@ -1366,34 +1366,34 @@ static loff_t ext3_max_size(int bits)
return res; return res;
} }
static ext3_fsblk_t descriptor_loc(struct super_block *sb, static ext4_fsblk_t descriptor_loc(struct super_block *sb,
ext3_fsblk_t logic_sb_block, ext4_fsblk_t logic_sb_block,
int nr) int nr)
{ {
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
unsigned long bg, first_meta_bg; unsigned long bg, first_meta_bg;
int has_super = 0; int has_super = 0;
first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg); first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg);
if (!EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_META_BG) || if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_META_BG) ||
nr < first_meta_bg) nr < first_meta_bg)
return (logic_sb_block + nr + 1); return (logic_sb_block + nr + 1);
bg = sbi->s_desc_per_block * nr; bg = sbi->s_desc_per_block * nr;
if (ext3_bg_has_super(sb, bg)) if (ext4_bg_has_super(sb, bg))
has_super = 1; has_super = 1;
return (has_super + ext3_group_first_block_no(sb, bg)); return (has_super + ext4_group_first_block_no(sb, bg));
} }
static int ext3_fill_super (struct super_block *sb, void *data, int silent) static int ext4_fill_super (struct super_block *sb, void *data, int silent)
{ {
struct buffer_head * bh; struct buffer_head * bh;
struct ext3_super_block *es = NULL; struct ext4_super_block *es = NULL;
struct ext3_sb_info *sbi; struct ext4_sb_info *sbi;
ext3_fsblk_t block; ext4_fsblk_t block;
ext3_fsblk_t sb_block = get_sb_block(&data); ext4_fsblk_t sb_block = get_sb_block(&data);
ext3_fsblk_t logic_sb_block; ext4_fsblk_t logic_sb_block;
unsigned long offset = 0; unsigned long offset = 0;
unsigned int journal_inum = 0; unsigned int journal_inum = 0;
unsigned long journal_devnum = 0; unsigned long journal_devnum = 0;
...@@ -1411,64 +1411,64 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) ...@@ -1411,64 +1411,64 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
return -ENOMEM; return -ENOMEM;
sb->s_fs_info = sbi; sb->s_fs_info = sbi;
sbi->s_mount_opt = 0; sbi->s_mount_opt = 0;
sbi->s_resuid = EXT3_DEF_RESUID; sbi->s_resuid = EXT4_DEF_RESUID;
sbi->s_resgid = EXT3_DEF_RESGID; sbi->s_resgid = EXT4_DEF_RESGID;
unlock_kernel(); unlock_kernel();
blocksize = sb_min_blocksize(sb, EXT3_MIN_BLOCK_SIZE); blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);
if (!blocksize) { if (!blocksize) {
printk(KERN_ERR "EXT3-fs: unable to set blocksize\n"); printk(KERN_ERR "EXT4-fs: unable to set blocksize\n");
goto out_fail; goto out_fail;
} }
/* /*
* The ext3 superblock will not be buffer aligned for other than 1kB * The ext4 superblock will not be buffer aligned for other than 1kB
* block sizes. We need to calculate the offset from buffer start. * block sizes. We need to calculate the offset from buffer start.
*/ */
if (blocksize != EXT3_MIN_BLOCK_SIZE) { if (blocksize != EXT4_MIN_BLOCK_SIZE) {
logic_sb_block = (sb_block * EXT3_MIN_BLOCK_SIZE) / blocksize; logic_sb_block = (sb_block * EXT4_MIN_BLOCK_SIZE) / blocksize;
offset = (sb_block * EXT3_MIN_BLOCK_SIZE) % blocksize; offset = (sb_block * EXT4_MIN_BLOCK_SIZE) % blocksize;
} else { } else {
logic_sb_block = sb_block; logic_sb_block = sb_block;
} }
if (!(bh = sb_bread(sb, logic_sb_block))) { if (!(bh = sb_bread(sb, logic_sb_block))) {
printk (KERN_ERR "EXT3-fs: unable to read superblock\n"); printk (KERN_ERR "EXT4-fs: unable to read superblock\n");
goto out_fail; goto out_fail;
} }
/* /*
* Note: s_es must be initialized as soon as possible because * Note: s_es must be initialized as soon as possible because
* some ext3 macro-instructions depend on its value * some ext4 macro-instructions depend on its value
*/ */
es = (struct ext3_super_block *) (((char *)bh->b_data) + offset); es = (struct ext4_super_block *) (((char *)bh->b_data) + offset);
sbi->s_es = es; sbi->s_es = es;
sb->s_magic = le16_to_cpu(es->s_magic); sb->s_magic = le16_to_cpu(es->s_magic);
if (sb->s_magic != EXT3_SUPER_MAGIC) if (sb->s_magic != EXT4_SUPER_MAGIC)
goto cantfind_ext3; goto cantfind_ext4;
/* Set defaults before we parse the mount options */ /* Set defaults before we parse the mount options */
def_mount_opts = le32_to_cpu(es->s_default_mount_opts); def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
if (def_mount_opts & EXT3_DEFM_DEBUG) if (def_mount_opts & EXT4_DEFM_DEBUG)
set_opt(sbi->s_mount_opt, DEBUG); set_opt(sbi->s_mount_opt, DEBUG);
if (def_mount_opts & EXT3_DEFM_BSDGROUPS) if (def_mount_opts & EXT4_DEFM_BSDGROUPS)
set_opt(sbi->s_mount_opt, GRPID); set_opt(sbi->s_mount_opt, GRPID);
if (def_mount_opts & EXT3_DEFM_UID16) if (def_mount_opts & EXT4_DEFM_UID16)
set_opt(sbi->s_mount_opt, NO_UID32); set_opt(sbi->s_mount_opt, NO_UID32);
if (def_mount_opts & EXT3_DEFM_XATTR_USER) if (def_mount_opts & EXT4_DEFM_XATTR_USER)
set_opt(sbi->s_mount_opt, XATTR_USER); set_opt(sbi->s_mount_opt, XATTR_USER);
if (def_mount_opts & EXT3_DEFM_ACL) if (def_mount_opts & EXT4_DEFM_ACL)
set_opt(sbi->s_mount_opt, POSIX_ACL); set_opt(sbi->s_mount_opt, POSIX_ACL);
if ((def_mount_opts & EXT3_DEFM_JMODE) == EXT3_DEFM_JMODE_DATA) if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_DATA)
sbi->s_mount_opt |= EXT3_MOUNT_JOURNAL_DATA; sbi->s_mount_opt |= EXT4_MOUNT_JOURNAL_DATA;
else if ((def_mount_opts & EXT3_DEFM_JMODE) == EXT3_DEFM_JMODE_ORDERED) else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_ORDERED)
sbi->s_mount_opt |= EXT3_MOUNT_ORDERED_DATA; sbi->s_mount_opt |= EXT4_MOUNT_ORDERED_DATA;
else if ((def_mount_opts & EXT3_DEFM_JMODE) == EXT3_DEFM_JMODE_WBACK) else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_WBACK)
sbi->s_mount_opt |= EXT3_MOUNT_WRITEBACK_DATA; sbi->s_mount_opt |= EXT4_MOUNT_WRITEBACK_DATA;
if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_PANIC) if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC)
set_opt(sbi->s_mount_opt, ERRORS_PANIC); set_opt(sbi->s_mount_opt, ERRORS_PANIC);
else if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_RO) else if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_RO)
set_opt(sbi->s_mount_opt, ERRORS_RO); set_opt(sbi->s_mount_opt, ERRORS_RO);
sbi->s_resuid = le16_to_cpu(es->s_def_resuid); 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,40 +1481,40 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
goto failed_mount; goto failed_mount;
sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
if (le32_to_cpu(es->s_rev_level) == EXT3_GOOD_OLD_REV && if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV &&
(EXT3_HAS_COMPAT_FEATURE(sb, ~0U) || (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) ||
EXT3_HAS_RO_COMPAT_FEATURE(sb, ~0U) || EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
EXT3_HAS_INCOMPAT_FEATURE(sb, ~0U))) EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U)))
printk(KERN_WARNING printk(KERN_WARNING
"EXT3-fs warning: feature flags set on rev 0 fs, " "EXT4-fs warning: feature flags set on rev 0 fs, "
"running e2fsck is recommended\n"); "running e2fsck is recommended\n");
/* /*
* Check feature flags regardless of the revision level, since we * Check feature flags regardless of the revision level, since we
* previously didn't change the revision level when setting the flags, * previously didn't change the revision level when setting the flags,
* so there is a chance incompat flags are set on a rev 0 filesystem. * so there is a chance incompat flags are set on a rev 0 filesystem.
*/ */
features = EXT3_HAS_INCOMPAT_FEATURE(sb, ~EXT3_FEATURE_INCOMPAT_SUPP); features = EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP);
if (features) { if (features) {
printk(KERN_ERR "EXT3-fs: %s: couldn't mount because of " printk(KERN_ERR "EXT4-fs: %s: couldn't mount because of "
"unsupported optional features (%x).\n", "unsupported optional features (%x).\n",
sb->s_id, le32_to_cpu(features)); sb->s_id, le32_to_cpu(features));
goto failed_mount; goto failed_mount;
} }
features = EXT3_HAS_RO_COMPAT_FEATURE(sb, ~EXT3_FEATURE_RO_COMPAT_SUPP); features = EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP);
if (!(sb->s_flags & MS_RDONLY) && features) { if (!(sb->s_flags & MS_RDONLY) && features) {
printk(KERN_ERR "EXT3-fs: %s: couldn't mount RDWR because of " printk(KERN_ERR "EXT4-fs: %s: couldn't mount RDWR because of "
"unsupported optional features (%x).\n", "unsupported optional features (%x).\n",
sb->s_id, le32_to_cpu(features)); sb->s_id, le32_to_cpu(features));
goto failed_mount; goto failed_mount;
} }
blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size); blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size);
if (blocksize < EXT3_MIN_BLOCK_SIZE || if (blocksize < EXT4_MIN_BLOCK_SIZE ||
blocksize > EXT3_MAX_BLOCK_SIZE) { blocksize > EXT4_MAX_BLOCK_SIZE) {
printk(KERN_ERR printk(KERN_ERR
"EXT3-fs: Unsupported filesystem blocksize %d on %s.\n", "EXT4-fs: Unsupported filesystem blocksize %d on %s.\n",
blocksize, sb->s_id); blocksize, sb->s_id);
goto failed_mount; goto failed_mount;
} }
...@@ -1526,52 +1526,52 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) ...@@ -1526,52 +1526,52 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
* than the hardware sectorsize for the machine. * than the hardware sectorsize for the machine.
*/ */
if (blocksize < hblock) { if (blocksize < hblock) {
printk(KERN_ERR "EXT3-fs: blocksize %d too small for " printk(KERN_ERR "EXT4-fs: blocksize %d too small for "
"device blocksize %d.\n", blocksize, hblock); "device blocksize %d.\n", blocksize, hblock);
goto failed_mount; goto failed_mount;
} }
brelse (bh); brelse (bh);
sb_set_blocksize(sb, blocksize); sb_set_blocksize(sb, blocksize);
logic_sb_block = (sb_block * EXT3_MIN_BLOCK_SIZE) / blocksize; logic_sb_block = (sb_block * EXT4_MIN_BLOCK_SIZE) / blocksize;
offset = (sb_block * EXT3_MIN_BLOCK_SIZE) % blocksize; offset = (sb_block * EXT4_MIN_BLOCK_SIZE) % blocksize;
bh = sb_bread(sb, logic_sb_block); bh = sb_bread(sb, logic_sb_block);
if (!bh) { if (!bh) {
printk(KERN_ERR printk(KERN_ERR
"EXT3-fs: Can't read superblock on 2nd try.\n"); "EXT4-fs: Can't read superblock on 2nd try.\n");
goto failed_mount; goto failed_mount;
} }
es = (struct ext3_super_block *)(((char *)bh->b_data) + offset); es = (struct ext4_super_block *)(((char *)bh->b_data) + offset);
sbi->s_es = es; sbi->s_es = es;
if (es->s_magic != cpu_to_le16(EXT3_SUPER_MAGIC)) { if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) {
printk (KERN_ERR printk (KERN_ERR
"EXT3-fs: Magic mismatch, very weird !\n"); "EXT4-fs: Magic mismatch, very weird !\n");
goto failed_mount; goto failed_mount;
} }
} }
sb->s_maxbytes = ext3_max_size(sb->s_blocksize_bits); sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits);
if (le32_to_cpu(es->s_rev_level) == EXT3_GOOD_OLD_REV) { if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) {
sbi->s_inode_size = EXT3_GOOD_OLD_INODE_SIZE; sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE;
sbi->s_first_ino = EXT3_GOOD_OLD_FIRST_INO; sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO;
} else { } else {
sbi->s_inode_size = le16_to_cpu(es->s_inode_size); sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
sbi->s_first_ino = le32_to_cpu(es->s_first_ino); sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
if ((sbi->s_inode_size < EXT3_GOOD_OLD_INODE_SIZE) || if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) ||
(sbi->s_inode_size & (sbi->s_inode_size - 1)) || (sbi->s_inode_size & (sbi->s_inode_size - 1)) ||
(sbi->s_inode_size > blocksize)) { (sbi->s_inode_size > blocksize)) {
printk (KERN_ERR printk (KERN_ERR
"EXT3-fs: unsupported inode size: %d\n", "EXT4-fs: unsupported inode size: %d\n",
sbi->s_inode_size); sbi->s_inode_size);
goto failed_mount; goto failed_mount;
} }
} }
sbi->s_frag_size = EXT3_MIN_FRAG_SIZE << sbi->s_frag_size = EXT4_MIN_FRAG_SIZE <<
le32_to_cpu(es->s_log_frag_size); le32_to_cpu(es->s_log_frag_size);
if (blocksize != sbi->s_frag_size) { if (blocksize != sbi->s_frag_size) {
printk(KERN_ERR printk(KERN_ERR
"EXT3-fs: fragsize %lu != blocksize %u (unsupported)\n", "EXT4-fs: fragsize %lu != blocksize %u (unsupported)\n",
sbi->s_frag_size, blocksize); sbi->s_frag_size, blocksize);
goto failed_mount; goto failed_mount;
} }
...@@ -1579,62 +1579,62 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) ...@@ -1579,62 +1579,62 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group); sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
sbi->s_frags_per_group = le32_to_cpu(es->s_frags_per_group); sbi->s_frags_per_group = le32_to_cpu(es->s_frags_per_group);
sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group); sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
if (EXT3_INODE_SIZE(sb) == 0) if (EXT4_INODE_SIZE(sb) == 0)
goto cantfind_ext3; goto cantfind_ext4;
sbi->s_inodes_per_block = blocksize / EXT3_INODE_SIZE(sb); sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb);
if (sbi->s_inodes_per_block == 0) if (sbi->s_inodes_per_block == 0)
goto cantfind_ext3; goto cantfind_ext4;
sbi->s_itb_per_group = sbi->s_inodes_per_group / sbi->s_itb_per_group = sbi->s_inodes_per_group /
sbi->s_inodes_per_block; sbi->s_inodes_per_block;
sbi->s_desc_per_block = blocksize / sizeof(struct ext3_group_desc); sbi->s_desc_per_block = blocksize / sizeof(struct ext4_group_desc);
sbi->s_sbh = bh; sbi->s_sbh = bh;
sbi->s_mount_state = le16_to_cpu(es->s_state); sbi->s_mount_state = le16_to_cpu(es->s_state);
sbi->s_addr_per_block_bits = log2(EXT3_ADDR_PER_BLOCK(sb)); sbi->s_addr_per_block_bits = log2(EXT4_ADDR_PER_BLOCK(sb));
sbi->s_desc_per_block_bits = log2(EXT3_DESC_PER_BLOCK(sb)); sbi->s_desc_per_block_bits = log2(EXT4_DESC_PER_BLOCK(sb));
for (i=0; i < 4; i++) for (i=0; i < 4; i++)
sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
sbi->s_def_hash_version = es->s_def_hash_version; sbi->s_def_hash_version = es->s_def_hash_version;
if (sbi->s_blocks_per_group > blocksize * 8) { if (sbi->s_blocks_per_group > blocksize * 8) {
printk (KERN_ERR printk (KERN_ERR
"EXT3-fs: #blocks per group too big: %lu\n", "EXT4-fs: #blocks per group too big: %lu\n",
sbi->s_blocks_per_group); sbi->s_blocks_per_group);
goto failed_mount; goto failed_mount;
} }
if (sbi->s_frags_per_group > blocksize * 8) { if (sbi->s_frags_per_group > blocksize * 8) {
printk (KERN_ERR printk (KERN_ERR
"EXT3-fs: #fragments per group too big: %lu\n", "EXT4-fs: #fragments per group too big: %lu\n",
sbi->s_frags_per_group); sbi->s_frags_per_group);
goto failed_mount; goto failed_mount;
} }
if (sbi->s_inodes_per_group > blocksize * 8) { if (sbi->s_inodes_per_group > blocksize * 8) {
printk (KERN_ERR printk (KERN_ERR
"EXT3-fs: #inodes per group too big: %lu\n", "EXT4-fs: #inodes per group too big: %lu\n",
sbi->s_inodes_per_group); sbi->s_inodes_per_group);
goto failed_mount; goto failed_mount;
} }
if (le32_to_cpu(es->s_blocks_count) > if (le32_to_cpu(es->s_blocks_count) >
(sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) { (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
printk(KERN_ERR "EXT3-fs: filesystem on %s:" printk(KERN_ERR "EXT4-fs: filesystem on %s:"
" too large to mount safely\n", sb->s_id); " too large to mount safely\n", sb->s_id);
if (sizeof(sector_t) < 8) if (sizeof(sector_t) < 8)
printk(KERN_WARNING "EXT3-fs: CONFIG_LBD not " printk(KERN_WARNING "EXT4-fs: CONFIG_LBD not "
"enabled\n"); "enabled\n");
goto failed_mount; goto failed_mount;
} }
if (EXT3_BLOCKS_PER_GROUP(sb) == 0) if (EXT4_BLOCKS_PER_GROUP(sb) == 0)
goto cantfind_ext3; goto cantfind_ext4;
sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) - sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) -
le32_to_cpu(es->s_first_data_block) - 1) le32_to_cpu(es->s_first_data_block) - 1)
/ EXT3_BLOCKS_PER_GROUP(sb)) + 1; / EXT4_BLOCKS_PER_GROUP(sb)) + 1;
db_count = (sbi->s_groups_count + EXT3_DESC_PER_BLOCK(sb) - 1) / db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
EXT3_DESC_PER_BLOCK(sb); EXT4_DESC_PER_BLOCK(sb);
sbi->s_group_desc = kmalloc(db_count * sizeof (struct buffer_head *), sbi->s_group_desc = kmalloc(db_count * sizeof (struct buffer_head *),
GFP_KERNEL); GFP_KERNEL);
if (sbi->s_group_desc == NULL) { if (sbi->s_group_desc == NULL) {
printk (KERN_ERR "EXT3-fs: not enough memory\n"); printk (KERN_ERR "EXT4-fs: not enough memory\n");
goto failed_mount; goto failed_mount;
} }
...@@ -1644,14 +1644,14 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) ...@@ -1644,14 +1644,14 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
block = descriptor_loc(sb, logic_sb_block, i); block = descriptor_loc(sb, logic_sb_block, i);
sbi->s_group_desc[i] = sb_bread(sb, block); sbi->s_group_desc[i] = sb_bread(sb, block);
if (!sbi->s_group_desc[i]) { if (!sbi->s_group_desc[i]) {
printk (KERN_ERR "EXT3-fs: " printk (KERN_ERR "EXT4-fs: "
"can't read group descriptor %d\n", i); "can't read group descriptor %d\n", i);
db_count = i; db_count = i;
goto failed_mount2; goto failed_mount2;
} }
} }
if (!ext3_check_descriptors (sb)) { if (!ext4_check_descriptors (sb)) {
printk(KERN_ERR "EXT3-fs: group descriptors corrupted!\n"); printk(KERN_ERR "EXT4-fs: group descriptors corrupted!\n");
goto failed_mount2; goto failed_mount2;
} }
sbi->s_gdb_count = db_count; sbi->s_gdb_count = db_count;
...@@ -1659,11 +1659,11 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) ...@@ -1659,11 +1659,11 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
spin_lock_init(&sbi->s_next_gen_lock); spin_lock_init(&sbi->s_next_gen_lock);
percpu_counter_init(&sbi->s_freeblocks_counter, percpu_counter_init(&sbi->s_freeblocks_counter,
ext3_count_free_blocks(sb)); ext4_count_free_blocks(sb));
percpu_counter_init(&sbi->s_freeinodes_counter, percpu_counter_init(&sbi->s_freeinodes_counter,
ext3_count_free_inodes(sb)); ext4_count_free_inodes(sb));
percpu_counter_init(&sbi->s_dirs_counter, percpu_counter_init(&sbi->s_dirs_counter,
ext3_count_dirs(sb)); ext4_count_dirs(sb));
/* per fileystem reservation list head & lock */ /* per fileystem reservation list head & lock */
spin_lock_init(&sbi->s_rsv_window_lock); 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,45 +1672,45 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
* reservation window list --- it gives us a placeholder for * reservation window list --- it gives us a placeholder for
* append-at-start-of-list which makes the allocation logic * append-at-start-of-list which makes the allocation logic
* _much_ simpler. */ * _much_ simpler. */
sbi->s_rsv_window_head.rsv_start = EXT3_RESERVE_WINDOW_NOT_ALLOCATED; sbi->s_rsv_window_head.rsv_start = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
sbi->s_rsv_window_head.rsv_end = EXT3_RESERVE_WINDOW_NOT_ALLOCATED; sbi->s_rsv_window_head.rsv_end = EXT4_RESERVE_WINDOW_NOT_ALLOCATED;
sbi->s_rsv_window_head.rsv_alloc_hit = 0; sbi->s_rsv_window_head.rsv_alloc_hit = 0;
sbi->s_rsv_window_head.rsv_goal_size = 0; sbi->s_rsv_window_head.rsv_goal_size = 0;
ext3_rsv_window_add(sb, &sbi->s_rsv_window_head); ext4_rsv_window_add(sb, &sbi->s_rsv_window_head);
/* /*
* set up enough so that it can read an inode * set up enough so that it can read an inode
*/ */
sb->s_op = &ext3_sops; sb->s_op = &ext4_sops;
sb->s_export_op = &ext3_export_ops; sb->s_export_op = &ext4_export_ops;
sb->s_xattr = ext3_xattr_handlers; sb->s_xattr = ext4_xattr_handlers;
#ifdef CONFIG_QUOTA #ifdef CONFIG_QUOTA
sb->s_qcop = &ext3_qctl_operations; sb->s_qcop = &ext4_qctl_operations;
sb->dq_op = &ext3_quota_operations; sb->dq_op = &ext4_quota_operations;
#endif #endif
INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */ INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
sb->s_root = NULL; sb->s_root = NULL;
needs_recovery = (es->s_last_orphan != 0 || needs_recovery = (es->s_last_orphan != 0 ||
EXT3_HAS_INCOMPAT_FEATURE(sb, EXT4_HAS_INCOMPAT_FEATURE(sb,
EXT3_FEATURE_INCOMPAT_RECOVER)); EXT4_FEATURE_INCOMPAT_RECOVER));
/* /*
* The first inode we look at is the journal inode. Don't try * The first inode we look at is the journal inode. Don't try
* root first: it may be modified in the journal! * root first: it may be modified in the journal!
*/ */
if (!test_opt(sb, NOLOAD) && if (!test_opt(sb, NOLOAD) &&
EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) { EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) {
if (ext3_load_journal(sb, es, journal_devnum)) if (ext4_load_journal(sb, es, journal_devnum))
goto failed_mount3; goto failed_mount3;
} else if (journal_inum) { } else if (journal_inum) {
if (ext3_create_journal(sb, es, journal_inum)) if (ext4_create_journal(sb, es, journal_inum))
goto failed_mount3; goto failed_mount3;
} else { } else {
if (!silent) if (!silent)
printk (KERN_ERR printk (KERN_ERR
"ext3: No journal on filesystem on %s\n", "ext4: No journal on filesystem on %s\n",
sb->s_id); sb->s_id);
goto failed_mount3; goto failed_mount3;
} }
...@@ -1729,11 +1729,11 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) ...@@ -1729,11 +1729,11 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
set_opt(sbi->s_mount_opt, JOURNAL_DATA); set_opt(sbi->s_mount_opt, JOURNAL_DATA);
break; break;
case EXT3_MOUNT_ORDERED_DATA: case EXT4_MOUNT_ORDERED_DATA:
case EXT3_MOUNT_WRITEBACK_DATA: case EXT4_MOUNT_WRITEBACK_DATA:
if (!journal_check_available_features if (!journal_check_available_features
(sbi->s_journal, 0, 0, JFS_FEATURE_INCOMPAT_REVOKE)) { (sbi->s_journal, 0, 0, JFS_FEATURE_INCOMPAT_REVOKE)) {
printk(KERN_ERR "EXT3-fs: Journal does not support " printk(KERN_ERR "EXT4-fs: Journal does not support "
"requested data journaling mode\n"); "requested data journaling mode\n");
goto failed_mount4; goto failed_mount4;
} }
...@@ -1742,8 +1742,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) ...@@ -1742,8 +1742,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
} }
if (test_opt(sb, NOBH)) { if (test_opt(sb, NOBH)) {
if (!(test_opt(sb, DATA_FLAGS) == EXT3_MOUNT_WRITEBACK_DATA)) { if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) {
printk(KERN_WARNING "EXT3-fs: Ignoring nobh option - " printk(KERN_WARNING "EXT4-fs: Ignoring nobh option - "
"its supported only with writeback mode\n"); "its supported only with writeback mode\n");
clear_opt(sbi->s_mount_opt, NOBH); clear_opt(sbi->s_mount_opt, NOBH);
} }
...@@ -1753,21 +1753,21 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) ...@@ -1753,21 +1753,21 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
* so we can safely mount the rest of the filesystem now. * so we can safely mount the rest of the filesystem now.
*/ */
root = iget(sb, EXT3_ROOT_INO); root = iget(sb, EXT4_ROOT_INO);
sb->s_root = d_alloc_root(root); sb->s_root = d_alloc_root(root);
if (!sb->s_root) { if (!sb->s_root) {
printk(KERN_ERR "EXT3-fs: get root inode failed\n"); printk(KERN_ERR "EXT4-fs: get root inode failed\n");
iput(root); iput(root);
goto failed_mount4; goto failed_mount4;
} }
if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
dput(sb->s_root); dput(sb->s_root);
sb->s_root = NULL; sb->s_root = NULL;
printk(KERN_ERR "EXT3-fs: corrupt root inode, run e2fsck\n"); printk(KERN_ERR "EXT4-fs: corrupt root inode, run e2fsck\n");
goto failed_mount4; goto failed_mount4;
} }
ext3_setup_super (sb, es, sb->s_flags & MS_RDONLY); ext4_setup_super (sb, es, sb->s_flags & MS_RDONLY);
/* /*
* akpm: core read_super() calls in here with the superblock locked. * akpm: core read_super() calls in here with the superblock locked.
* That deadlocks, because orphan cleanup needs to lock the superblock * 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,23 +1776,23 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
* and aviro says that's the only reason for hanging onto the * and aviro says that's the only reason for hanging onto the
* superblock lock. * superblock lock.
*/ */
EXT3_SB(sb)->s_mount_state |= EXT3_ORPHAN_FS; EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
ext3_orphan_cleanup(sb, es); ext4_orphan_cleanup(sb, es);
EXT3_SB(sb)->s_mount_state &= ~EXT3_ORPHAN_FS; EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
if (needs_recovery) if (needs_recovery)
printk (KERN_INFO "EXT3-fs: recovery complete.\n"); printk (KERN_INFO "EXT4-fs: recovery complete.\n");
ext3_mark_recovery_complete(sb, es); ext4_mark_recovery_complete(sb, es);
printk (KERN_INFO "EXT3-fs: mounted filesystem with %s data mode.\n", printk (KERN_INFO "EXT4-fs: mounted filesystem with %s data mode.\n",
test_opt(sb,DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA ? "journal": test_opt(sb,DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA ? "journal":
test_opt(sb,DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA ? "ordered": test_opt(sb,DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA ? "ordered":
"writeback"); "writeback");
lock_kernel(); lock_kernel();
return 0; return 0;
cantfind_ext3: cantfind_ext4:
if (!silent) if (!silent)
printk(KERN_ERR "VFS: Can't find ext3 filesystem on dev %s.\n", printk(KERN_ERR "VFS: Can't find ext4 filesystem on dev %s.\n",
sb->s_id); sb->s_id);
goto failed_mount; goto failed_mount;
...@@ -1811,7 +1811,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) ...@@ -1811,7 +1811,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
for (i = 0; i < MAXQUOTAS; i++) for (i = 0; i < MAXQUOTAS; i++)
kfree(sbi->s_qf_names[i]); kfree(sbi->s_qf_names[i]);
#endif #endif
ext3_blkdev_remove(sbi); ext4_blkdev_remove(sbi);
brelse(bh); brelse(bh);
out_fail: out_fail:
sb->s_fs_info = NULL; sb->s_fs_info = NULL;
...@@ -1825,13 +1825,13 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) ...@@ -1825,13 +1825,13 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
* initial mount, once the journal has been initialised but before we've * initial mount, once the journal has been initialised but before we've
* done any recovery; and again on any subsequent remount. * done any recovery; and again on any subsequent remount.
*/ */
static void ext3_init_journal_params(struct super_block *sb, journal_t *journal) static void ext4_init_journal_params(struct super_block *sb, journal_t *journal)
{ {
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
if (sbi->s_commit_interval) if (sbi->s_commit_interval)
journal->j_commit_interval = sbi->s_commit_interval; journal->j_commit_interval = sbi->s_commit_interval;
/* We could also set up an ext3-specific default for the commit /* We could also set up an ext4-specific default for the commit
* interval here, but for now we'll just fall back to the jbd * interval here, but for now we'll just fall back to the jbd
* default. */ * default. */
...@@ -1843,7 +1843,7 @@ static void ext3_init_journal_params(struct super_block *sb, journal_t *journal) ...@@ -1843,7 +1843,7 @@ static void ext3_init_journal_params(struct super_block *sb, journal_t *journal)
spin_unlock(&journal->j_state_lock); spin_unlock(&journal->j_state_lock);
} }
static journal_t *ext3_get_journal(struct super_block *sb, static journal_t *ext4_get_journal(struct super_block *sb,
unsigned int journal_inum) unsigned int journal_inum)
{ {
struct inode *journal_inode; struct inode *journal_inode;
...@@ -1855,55 +1855,55 @@ static journal_t *ext3_get_journal(struct super_block *sb, ...@@ -1855,55 +1855,55 @@ static journal_t *ext3_get_journal(struct super_block *sb,
journal_inode = iget(sb, journal_inum); journal_inode = iget(sb, journal_inum);
if (!journal_inode) { if (!journal_inode) {
printk(KERN_ERR "EXT3-fs: no journal found.\n"); printk(KERN_ERR "EXT4-fs: no journal found.\n");
return NULL; return NULL;
} }
if (!journal_inode->i_nlink) { if (!journal_inode->i_nlink) {
make_bad_inode(journal_inode); make_bad_inode(journal_inode);
iput(journal_inode); iput(journal_inode);
printk(KERN_ERR "EXT3-fs: journal inode is deleted.\n"); printk(KERN_ERR "EXT4-fs: journal inode is deleted.\n");
return NULL; return NULL;
} }
jbd_debug(2, "Journal inode found at %p: %Ld bytes\n", jbd_debug(2, "Journal inode found at %p: %Ld bytes\n",
journal_inode, journal_inode->i_size); journal_inode, journal_inode->i_size);
if (is_bad_inode(journal_inode) || !S_ISREG(journal_inode->i_mode)) { if (is_bad_inode(journal_inode) || !S_ISREG(journal_inode->i_mode)) {
printk(KERN_ERR "EXT3-fs: invalid journal inode.\n"); printk(KERN_ERR "EXT4-fs: invalid journal inode.\n");
iput(journal_inode); iput(journal_inode);
return NULL; return NULL;
} }
journal = journal_init_inode(journal_inode); journal = journal_init_inode(journal_inode);
if (!journal) { if (!journal) {
printk(KERN_ERR "EXT3-fs: Could not load journal inode\n"); printk(KERN_ERR "EXT4-fs: Could not load journal inode\n");
iput(journal_inode); iput(journal_inode);
return NULL; return NULL;
} }
journal->j_private = sb; journal->j_private = sb;
ext3_init_journal_params(sb, journal); ext4_init_journal_params(sb, journal);
return journal; return journal;
} }
static journal_t *ext3_get_dev_journal(struct super_block *sb, static journal_t *ext4_get_dev_journal(struct super_block *sb,
dev_t j_dev) dev_t j_dev)
{ {
struct buffer_head * bh; struct buffer_head * bh;
journal_t *journal; journal_t *journal;
ext3_fsblk_t start; ext4_fsblk_t start;
ext3_fsblk_t len; ext4_fsblk_t len;
int hblock, blocksize; int hblock, blocksize;
ext3_fsblk_t sb_block; ext4_fsblk_t sb_block;
unsigned long offset; unsigned long offset;
struct ext3_super_block * es; struct ext4_super_block * es;
struct block_device *bdev; struct block_device *bdev;
bdev = ext3_blkdev_get(j_dev); bdev = ext4_blkdev_get(j_dev);
if (bdev == NULL) if (bdev == NULL)
return NULL; return NULL;
if (bd_claim(bdev, sb)) { if (bd_claim(bdev, sb)) {
printk(KERN_ERR printk(KERN_ERR
"EXT3: failed to claim external journal device.\n"); "EXT4: failed to claim external journal device.\n");
blkdev_put(bdev); blkdev_put(bdev);
return NULL; return NULL;
} }
...@@ -1912,31 +1912,31 @@ static journal_t *ext3_get_dev_journal(struct super_block *sb, ...@@ -1912,31 +1912,31 @@ static journal_t *ext3_get_dev_journal(struct super_block *sb,
hblock = bdev_hardsect_size(bdev); hblock = bdev_hardsect_size(bdev);
if (blocksize < hblock) { if (blocksize < hblock) {
printk(KERN_ERR printk(KERN_ERR
"EXT3-fs: blocksize too small for journal device.\n"); "EXT4-fs: blocksize too small for journal device.\n");
goto out_bdev; goto out_bdev;
} }
sb_block = EXT3_MIN_BLOCK_SIZE / blocksize; sb_block = EXT4_MIN_BLOCK_SIZE / blocksize;
offset = EXT3_MIN_BLOCK_SIZE % blocksize; offset = EXT4_MIN_BLOCK_SIZE % blocksize;
set_blocksize(bdev, blocksize); set_blocksize(bdev, blocksize);
if (!(bh = __bread(bdev, sb_block, blocksize))) { if (!(bh = __bread(bdev, sb_block, blocksize))) {
printk(KERN_ERR "EXT3-fs: couldn't read superblock of " printk(KERN_ERR "EXT4-fs: couldn't read superblock of "
"external journal\n"); "external journal\n");
goto out_bdev; goto out_bdev;
} }
es = (struct ext3_super_block *) (((char *)bh->b_data) + offset); es = (struct ext4_super_block *) (((char *)bh->b_data) + offset);
if ((le16_to_cpu(es->s_magic) != EXT3_SUPER_MAGIC) || if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) ||
!(le32_to_cpu(es->s_feature_incompat) & !(le32_to_cpu(es->s_feature_incompat) &
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) { EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) {
printk(KERN_ERR "EXT3-fs: external journal has " printk(KERN_ERR "EXT4-fs: external journal has "
"bad superblock\n"); "bad superblock\n");
brelse(bh); brelse(bh);
goto out_bdev; goto out_bdev;
} }
if (memcmp(EXT3_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) { if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) {
printk(KERN_ERR "EXT3-fs: journal UUID does not match\n"); printk(KERN_ERR "EXT4-fs: journal UUID does not match\n");
brelse(bh); brelse(bh);
goto out_bdev; goto out_bdev;
} }
...@@ -1948,34 +1948,34 @@ static journal_t *ext3_get_dev_journal(struct super_block *sb, ...@@ -1948,34 +1948,34 @@ static journal_t *ext3_get_dev_journal(struct super_block *sb,
journal = journal_init_dev(bdev, sb->s_bdev, journal = journal_init_dev(bdev, sb->s_bdev,
start, len, blocksize); start, len, blocksize);
if (!journal) { if (!journal) {
printk(KERN_ERR "EXT3-fs: failed to create device journal\n"); printk(KERN_ERR "EXT4-fs: failed to create device journal\n");
goto out_bdev; goto out_bdev;
} }
journal->j_private = sb; journal->j_private = sb;
ll_rw_block(READ, 1, &journal->j_sb_buffer); ll_rw_block(READ, 1, &journal->j_sb_buffer);
wait_on_buffer(journal->j_sb_buffer); wait_on_buffer(journal->j_sb_buffer);
if (!buffer_uptodate(journal->j_sb_buffer)) { if (!buffer_uptodate(journal->j_sb_buffer)) {
printk(KERN_ERR "EXT3-fs: I/O error on journal device\n"); printk(KERN_ERR "EXT4-fs: I/O error on journal device\n");
goto out_journal; goto out_journal;
} }
if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) { if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) {
printk(KERN_ERR "EXT3-fs: External journal has more than one " printk(KERN_ERR "EXT4-fs: External journal has more than one "
"user (unsupported) - %d\n", "user (unsupported) - %d\n",
be32_to_cpu(journal->j_superblock->s_nr_users)); be32_to_cpu(journal->j_superblock->s_nr_users));
goto out_journal; goto out_journal;
} }
EXT3_SB(sb)->journal_bdev = bdev; EXT4_SB(sb)->journal_bdev = bdev;
ext3_init_journal_params(sb, journal); ext4_init_journal_params(sb, journal);
return journal; return journal;
out_journal: out_journal:
journal_destroy(journal); journal_destroy(journal);
out_bdev: out_bdev:
ext3_blkdev_put(bdev); ext4_blkdev_put(bdev);
return NULL; return NULL;
} }
static int ext3_load_journal(struct super_block *sb, static int ext4_load_journal(struct super_block *sb,
struct ext3_super_block *es, struct ext4_super_block *es,
unsigned long journal_devnum) unsigned long journal_devnum)
{ {
journal_t *journal; journal_t *journal;
...@@ -1986,7 +1986,7 @@ static int ext3_load_journal(struct super_block *sb, ...@@ -1986,7 +1986,7 @@ static int ext3_load_journal(struct super_block *sb,
if (journal_devnum && if (journal_devnum &&
journal_devnum != le32_to_cpu(es->s_journal_dev)) { journal_devnum != le32_to_cpu(es->s_journal_dev)) {
printk(KERN_INFO "EXT3-fs: external journal device major/minor " printk(KERN_INFO "EXT4-fs: external journal device major/minor "
"numbers have changed\n"); "numbers have changed\n");
journal_dev = new_decode_dev(journal_devnum); journal_dev = new_decode_dev(journal_devnum);
} else } else
...@@ -2000,56 +2000,56 @@ static int ext3_load_journal(struct super_block *sb, ...@@ -2000,56 +2000,56 @@ static int ext3_load_journal(struct super_block *sb,
* can get read-write access to the device. * can get read-write access to the device.
*/ */
if (EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER)) { if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
if (sb->s_flags & MS_RDONLY) { if (sb->s_flags & MS_RDONLY) {
printk(KERN_INFO "EXT3-fs: INFO: recovery " printk(KERN_INFO "EXT4-fs: INFO: recovery "
"required on readonly filesystem.\n"); "required on readonly filesystem.\n");
if (really_read_only) { if (really_read_only) {
printk(KERN_ERR "EXT3-fs: write access " printk(KERN_ERR "EXT4-fs: write access "
"unavailable, cannot proceed.\n"); "unavailable, cannot proceed.\n");
return -EROFS; return -EROFS;
} }
printk (KERN_INFO "EXT3-fs: write access will " printk (KERN_INFO "EXT4-fs: write access will "
"be enabled during recovery.\n"); "be enabled during recovery.\n");
} }
} }
if (journal_inum && journal_dev) { if (journal_inum && journal_dev) {
printk(KERN_ERR "EXT3-fs: filesystem has both journal " printk(KERN_ERR "EXT4-fs: filesystem has both journal "
"and inode journals!\n"); "and inode journals!\n");
return -EINVAL; return -EINVAL;
} }
if (journal_inum) { if (journal_inum) {
if (!(journal = ext3_get_journal(sb, journal_inum))) if (!(journal = ext4_get_journal(sb, journal_inum)))
return -EINVAL; return -EINVAL;
} else { } else {
if (!(journal = ext3_get_dev_journal(sb, journal_dev))) if (!(journal = ext4_get_dev_journal(sb, journal_dev)))
return -EINVAL; return -EINVAL;
} }
if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) { if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) {
err = journal_update_format(journal); err = journal_update_format(journal);
if (err) { if (err) {
printk(KERN_ERR "EXT3-fs: error updating journal.\n"); printk(KERN_ERR "EXT4-fs: error updating journal.\n");
journal_destroy(journal); journal_destroy(journal);
return err; return err;
} }
} }
if (!EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER)) if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER))
err = journal_wipe(journal, !really_read_only); err = journal_wipe(journal, !really_read_only);
if (!err) if (!err)
err = journal_load(journal); err = journal_load(journal);
if (err) { if (err) {
printk(KERN_ERR "EXT3-fs: error loading journal.\n"); printk(KERN_ERR "EXT4-fs: error loading journal.\n");
journal_destroy(journal); journal_destroy(journal);
return err; return err;
} }
EXT3_SB(sb)->s_journal = journal; EXT4_SB(sb)->s_journal = journal;
ext3_clear_journal_err(sb, es); ext4_clear_journal_err(sb, es);
if (journal_devnum && if (journal_devnum &&
journal_devnum != le32_to_cpu(es->s_journal_dev)) { journal_devnum != le32_to_cpu(es->s_journal_dev)) {
...@@ -2057,62 +2057,62 @@ static int ext3_load_journal(struct super_block *sb, ...@@ -2057,62 +2057,62 @@ static int ext3_load_journal(struct super_block *sb,
sb->s_dirt = 1; sb->s_dirt = 1;
/* Make sure we flush the recovery flag to disk. */ /* Make sure we flush the recovery flag to disk. */
ext3_commit_super(sb, es, 1); ext4_commit_super(sb, es, 1);
} }
return 0; return 0;
} }
static int ext3_create_journal(struct super_block * sb, static int ext4_create_journal(struct super_block * sb,
struct ext3_super_block * es, struct ext4_super_block * es,
unsigned int journal_inum) unsigned int journal_inum)
{ {
journal_t *journal; journal_t *journal;
if (sb->s_flags & MS_RDONLY) { if (sb->s_flags & MS_RDONLY) {
printk(KERN_ERR "EXT3-fs: readonly filesystem when trying to " printk(KERN_ERR "EXT4-fs: readonly filesystem when trying to "
"create journal.\n"); "create journal.\n");
return -EROFS; return -EROFS;
} }
if (!(journal = ext3_get_journal(sb, journal_inum))) if (!(journal = ext4_get_journal(sb, journal_inum)))
return -EINVAL; return -EINVAL;
printk(KERN_INFO "EXT3-fs: creating new journal on inode %u\n", printk(KERN_INFO "EXT4-fs: creating new journal on inode %u\n",
journal_inum); journal_inum);
if (journal_create(journal)) { if (journal_create(journal)) {
printk(KERN_ERR "EXT3-fs: error creating journal.\n"); printk(KERN_ERR "EXT4-fs: error creating journal.\n");
journal_destroy(journal); journal_destroy(journal);
return -EIO; return -EIO;
} }
EXT3_SB(sb)->s_journal = journal; EXT4_SB(sb)->s_journal = journal;
ext3_update_dynamic_rev(sb); ext4_update_dynamic_rev(sb);
EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
EXT3_SET_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL); EXT4_SET_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL);
es->s_journal_inum = cpu_to_le32(journal_inum); es->s_journal_inum = cpu_to_le32(journal_inum);
sb->s_dirt = 1; sb->s_dirt = 1;
/* Make sure we flush the recovery flag to disk. */ /* Make sure we flush the recovery flag to disk. */
ext3_commit_super(sb, es, 1); ext4_commit_super(sb, es, 1);
return 0; return 0;
} }
static void ext3_commit_super (struct super_block * sb, static void ext4_commit_super (struct super_block * sb,
struct ext3_super_block * es, struct ext4_super_block * es,
int sync) int sync)
{ {
struct buffer_head *sbh = EXT3_SB(sb)->s_sbh; struct buffer_head *sbh = EXT4_SB(sb)->s_sbh;
if (!sbh) if (!sbh)
return; return;
es->s_wtime = cpu_to_le32(get_seconds()); es->s_wtime = cpu_to_le32(get_seconds());
es->s_free_blocks_count = cpu_to_le32(ext3_count_free_blocks(sb)); es->s_free_blocks_count = cpu_to_le32(ext4_count_free_blocks(sb));
es->s_free_inodes_count = cpu_to_le32(ext3_count_free_inodes(sb)); es->s_free_inodes_count = cpu_to_le32(ext4_count_free_inodes(sb));
BUFFER_TRACE(sbh, "marking dirty"); BUFFER_TRACE(sbh, "marking dirty");
mark_buffer_dirty(sbh); mark_buffer_dirty(sbh);
if (sync) if (sync)
...@@ -2125,18 +2125,18 @@ static void ext3_commit_super (struct super_block * sb, ...@@ -2125,18 +2125,18 @@ static void ext3_commit_super (struct super_block * sb,
* remounting) the filesystem readonly, then we will end up with a * remounting) the filesystem readonly, then we will end up with a
* consistent fs on disk. Record that fact. * consistent fs on disk. Record that fact.
*/ */
static void ext3_mark_recovery_complete(struct super_block * sb, static void ext4_mark_recovery_complete(struct super_block * sb,
struct ext3_super_block * es) struct ext4_super_block * es)
{ {
journal_t *journal = EXT3_SB(sb)->s_journal; journal_t *journal = EXT4_SB(sb)->s_journal;
journal_lock_updates(journal); journal_lock_updates(journal);
journal_flush(journal); journal_flush(journal);
if (EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER) && if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) &&
sb->s_flags & MS_RDONLY) { sb->s_flags & MS_RDONLY) {
EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
sb->s_dirt = 0; sb->s_dirt = 0;
ext3_commit_super(sb, es, 1); ext4_commit_super(sb, es, 1);
} }
journal_unlock_updates(journal); journal_unlock_updates(journal);
} }
...@@ -2146,33 +2146,33 @@ static void ext3_mark_recovery_complete(struct super_block * sb, ...@@ -2146,33 +2146,33 @@ static void ext3_mark_recovery_complete(struct super_block * sb,
* has recorded an error from a previous lifetime, move that error to the * has recorded an error from a previous lifetime, move that error to the
* main filesystem now. * main filesystem now.
*/ */
static void ext3_clear_journal_err(struct super_block * sb, static void ext4_clear_journal_err(struct super_block * sb,
struct ext3_super_block * es) struct ext4_super_block * es)
{ {
journal_t *journal; journal_t *journal;
int j_errno; int j_errno;
const char *errstr; const char *errstr;
journal = EXT3_SB(sb)->s_journal; journal = EXT4_SB(sb)->s_journal;
/* /*
* Now check for any error status which may have been recorded in the * Now check for any error status which may have been recorded in the
* journal by a prior ext3_error() or ext3_abort() * journal by a prior ext4_error() or ext4_abort()
*/ */
j_errno = journal_errno(journal); j_errno = journal_errno(journal);
if (j_errno) { if (j_errno) {
char nbuf[16]; char nbuf[16];
errstr = ext3_decode_error(sb, j_errno, nbuf); errstr = ext4_decode_error(sb, j_errno, nbuf);
ext3_warning(sb, __FUNCTION__, "Filesystem error recorded " ext4_warning(sb, __FUNCTION__, "Filesystem error recorded "
"from previous mount: %s", errstr); "from previous mount: %s", errstr);
ext3_warning(sb, __FUNCTION__, "Marking fs in need of " ext4_warning(sb, __FUNCTION__, "Marking fs in need of "
"filesystem check."); "filesystem check.");
EXT3_SB(sb)->s_mount_state |= EXT3_ERROR_FS; EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
es->s_state |= cpu_to_le16(EXT3_ERROR_FS); es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
ext3_commit_super (sb, es, 1); ext4_commit_super (sb, es, 1);
journal_clear_err(journal); journal_clear_err(journal);
} }
...@@ -2182,7 +2182,7 @@ static void ext3_clear_journal_err(struct super_block * sb, ...@@ -2182,7 +2182,7 @@ static void ext3_clear_journal_err(struct super_block * sb,
* Force the running and committing transactions to commit, * Force the running and committing transactions to commit,
* and wait on the commit. * and wait on the commit.
*/ */
int ext3_force_commit(struct super_block *sb) int ext4_force_commit(struct super_block *sb)
{ {
journal_t *journal; journal_t *journal;
int ret; int ret;
...@@ -2190,14 +2190,14 @@ int ext3_force_commit(struct super_block *sb) ...@@ -2190,14 +2190,14 @@ int ext3_force_commit(struct super_block *sb)
if (sb->s_flags & MS_RDONLY) if (sb->s_flags & MS_RDONLY)
return 0; return 0;
journal = EXT3_SB(sb)->s_journal; journal = EXT4_SB(sb)->s_journal;
sb->s_dirt = 0; sb->s_dirt = 0;
ret = ext3_journal_force_commit(journal); ret = ext4_journal_force_commit(journal);
return ret; return ret;
} }
/* /*
* Ext3 always journals updates to the superblock itself, so we don't * Ext4 always journals updates to the superblock itself, so we don't
* have to propagate any other updates to the superblock on disk at this * have to propagate any other updates to the superblock on disk at this
* point. Just start an async writeback to get the buffers on their way * point. Just start an async writeback to get the buffers on their way
* to the disk. * to the disk.
...@@ -2205,21 +2205,21 @@ int ext3_force_commit(struct super_block *sb) ...@@ -2205,21 +2205,21 @@ int ext3_force_commit(struct super_block *sb)
* This implicitly triggers the writebehind on sync(). * This implicitly triggers the writebehind on sync().
*/ */
static void ext3_write_super (struct super_block * sb) static void ext4_write_super (struct super_block * sb)
{ {
if (mutex_trylock(&sb->s_lock) != 0) if (mutex_trylock(&sb->s_lock) != 0)
BUG(); BUG();
sb->s_dirt = 0; sb->s_dirt = 0;
} }
static int ext3_sync_fs(struct super_block *sb, int wait) static int ext4_sync_fs(struct super_block *sb, int wait)
{ {
tid_t target; tid_t target;
sb->s_dirt = 0; sb->s_dirt = 0;
if (journal_start_commit(EXT3_SB(sb)->s_journal, &target)) { if (journal_start_commit(EXT4_SB(sb)->s_journal, &target)) {
if (wait) if (wait)
log_wait_commit(EXT3_SB(sb)->s_journal, target); log_wait_commit(EXT4_SB(sb)->s_journal, target);
} }
return 0; return 0;
} }
...@@ -2228,20 +2228,20 @@ static int ext3_sync_fs(struct super_block *sb, int wait) ...@@ -2228,20 +2228,20 @@ static int ext3_sync_fs(struct super_block *sb, int wait)
* LVM calls this function before a (read-only) snapshot is created. This * LVM calls this function before a (read-only) snapshot is created. This
* gives us a chance to flush the journal completely and mark the fs clean. * gives us a chance to flush the journal completely and mark the fs clean.
*/ */
static void ext3_write_super_lockfs(struct super_block *sb) static void ext4_write_super_lockfs(struct super_block *sb)
{ {
sb->s_dirt = 0; sb->s_dirt = 0;
if (!(sb->s_flags & MS_RDONLY)) { if (!(sb->s_flags & MS_RDONLY)) {
journal_t *journal = EXT3_SB(sb)->s_journal; journal_t *journal = EXT4_SB(sb)->s_journal;
/* Now we set up the journal barrier. */ /* Now we set up the journal barrier. */
journal_lock_updates(journal); journal_lock_updates(journal);
journal_flush(journal); journal_flush(journal);
/* Journal blocked and flushed, clear needs_recovery flag. */ /* Journal blocked and flushed, clear needs_recovery flag. */
EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1); ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1);
} }
} }
...@@ -2249,25 +2249,25 @@ static void ext3_write_super_lockfs(struct super_block *sb) ...@@ -2249,25 +2249,25 @@ static void ext3_write_super_lockfs(struct super_block *sb)
* Called by LVM after the snapshot is done. We need to reset the RECOVER * Called by LVM after the snapshot is done. We need to reset the RECOVER
* flag here, even though the filesystem is not technically dirty yet. * flag here, even though the filesystem is not technically dirty yet.
*/ */
static void ext3_unlockfs(struct super_block *sb) static void ext4_unlockfs(struct super_block *sb)
{ {
if (!(sb->s_flags & MS_RDONLY)) { if (!(sb->s_flags & MS_RDONLY)) {
lock_super(sb); lock_super(sb);
/* Reser the needs_recovery flag before the fs is unlocked. */ /* Reser the needs_recovery flag before the fs is unlocked. */
EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1); ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1);
unlock_super(sb); unlock_super(sb);
journal_unlock_updates(EXT3_SB(sb)->s_journal); journal_unlock_updates(EXT4_SB(sb)->s_journal);
} }
} }
static int ext3_remount (struct super_block * sb, int * flags, char * data) static int ext4_remount (struct super_block * sb, int * flags, char * data)
{ {
struct ext3_super_block * es; struct ext4_super_block * es;
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
ext3_fsblk_t n_blocks_count = 0; ext4_fsblk_t n_blocks_count = 0;
unsigned long old_sb_flags; unsigned long old_sb_flags;
struct ext3_mount_options old_opts; struct ext4_mount_options old_opts;
int err; int err;
#ifdef CONFIG_QUOTA #ifdef CONFIG_QUOTA
int i; int i;
...@@ -2293,19 +2293,19 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data) ...@@ -2293,19 +2293,19 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
goto restore_opts; goto restore_opts;
} }
if (sbi->s_mount_opt & EXT3_MOUNT_ABORT) if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
ext3_abort(sb, __FUNCTION__, "Abort forced by user"); ext4_abort(sb, __FUNCTION__, "Abort forced by user");
sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
es = sbi->s_es; es = sbi->s_es;
ext3_init_journal_params(sb, sbi->s_journal); ext4_init_journal_params(sb, sbi->s_journal);
if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) || if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) ||
n_blocks_count > le32_to_cpu(es->s_blocks_count)) { n_blocks_count > le32_to_cpu(es->s_blocks_count)) {
if (sbi->s_mount_opt & EXT3_MOUNT_ABORT) { if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) {
err = -EROFS; err = -EROFS;
goto restore_opts; goto restore_opts;
} }
...@@ -2322,16 +2322,16 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data) ...@@ -2322,16 +2322,16 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
* readonly, and if so set the rdonly flag and then * readonly, and if so set the rdonly flag and then
* mark the partition as valid again. * mark the partition as valid again.
*/ */
if (!(es->s_state & cpu_to_le16(EXT3_VALID_FS)) && if (!(es->s_state & cpu_to_le16(EXT4_VALID_FS)) &&
(sbi->s_mount_state & EXT3_VALID_FS)) (sbi->s_mount_state & EXT4_VALID_FS))
es->s_state = cpu_to_le16(sbi->s_mount_state); es->s_state = cpu_to_le16(sbi->s_mount_state);
ext3_mark_recovery_complete(sb, es); ext4_mark_recovery_complete(sb, es);
} else { } else {
__le32 ret; __le32 ret;
if ((ret = EXT3_HAS_RO_COMPAT_FEATURE(sb, if ((ret = EXT4_HAS_RO_COMPAT_FEATURE(sb,
~EXT3_FEATURE_RO_COMPAT_SUPP))) { ~EXT4_FEATURE_RO_COMPAT_SUPP))) {
printk(KERN_WARNING "EXT3-fs: %s: couldn't " printk(KERN_WARNING "EXT4-fs: %s: couldn't "
"remount RDWR because of unsupported " "remount RDWR because of unsupported "
"optional features (%x).\n", "optional features (%x).\n",
sb->s_id, le32_to_cpu(ret)); sb->s_id, le32_to_cpu(ret));
...@@ -2344,11 +2344,11 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data) ...@@ -2344,11 +2344,11 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
* been changed by e2fsck since we originally mounted * been changed by e2fsck since we originally mounted
* the partition.) * the partition.)
*/ */
ext3_clear_journal_err(sb, es); ext4_clear_journal_err(sb, es);
sbi->s_mount_state = le16_to_cpu(es->s_state); sbi->s_mount_state = le16_to_cpu(es->s_state);
if ((err = ext3_group_extend(sb, es, n_blocks_count))) if ((err = ext4_group_extend(sb, es, n_blocks_count)))
goto restore_opts; goto restore_opts;
if (!ext3_setup_super (sb, es, 0)) if (!ext4_setup_super (sb, es, 0))
sb->s_flags &= ~MS_RDONLY; sb->s_flags &= ~MS_RDONLY;
} }
} }
...@@ -2378,19 +2378,19 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data) ...@@ -2378,19 +2378,19 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data)
return err; return err;
} }
static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf) static int ext4_statfs (struct dentry * dentry, struct kstatfs * buf)
{ {
struct super_block *sb = dentry->d_sb; struct super_block *sb = dentry->d_sb;
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
struct ext3_super_block *es = sbi->s_es; struct ext4_super_block *es = sbi->s_es;
ext3_fsblk_t overhead; ext4_fsblk_t overhead;
int i; int i;
if (test_opt (sb, MINIX_DF)) if (test_opt (sb, MINIX_DF))
overhead = 0; overhead = 0;
else { else {
unsigned long ngroups; unsigned long ngroups;
ngroups = EXT3_SB(sb)->s_groups_count; ngroups = EXT4_SB(sb)->s_groups_count;
smp_rmb(); smp_rmb();
/* /*
...@@ -2409,8 +2409,8 @@ static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf) ...@@ -2409,8 +2409,8 @@ static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf)
* feature is turned on, then not all groups have this. * feature is turned on, then not all groups have this.
*/ */
for (i = 0; i < ngroups; i++) { for (i = 0; i < ngroups; i++) {
overhead += ext3_bg_has_super(sb, i) + overhead += ext4_bg_has_super(sb, i) +
ext3_bg_num_gdb(sb, i); ext4_bg_num_gdb(sb, i);
cond_resched(); cond_resched();
} }
...@@ -2418,10 +2418,10 @@ static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf) ...@@ -2418,10 +2418,10 @@ static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf)
* Every block group has an inode bitmap, a block * Every block group has an inode bitmap, a block
* bitmap, and an inode table. * bitmap, and an inode table.
*/ */
overhead += (ngroups * (2 + EXT3_SB(sb)->s_itb_per_group)); overhead += (ngroups * (2 + EXT4_SB(sb)->s_itb_per_group));
} }
buf->f_type = EXT3_SUPER_MAGIC; buf->f_type = EXT4_SUPER_MAGIC;
buf->f_bsize = sb->s_blocksize; buf->f_bsize = sb->s_blocksize;
buf->f_blocks = le32_to_cpu(es->s_blocks_count) - overhead; buf->f_blocks = le32_to_cpu(es->s_blocks_count) - overhead;
buf->f_bfree = percpu_counter_sum(&sbi->s_freeblocks_counter); 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,14 +2430,14 @@ static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf)
buf->f_bavail = 0; buf->f_bavail = 0;
buf->f_files = le32_to_cpu(es->s_inodes_count); buf->f_files = le32_to_cpu(es->s_inodes_count);
buf->f_ffree = percpu_counter_sum(&sbi->s_freeinodes_counter); buf->f_ffree = percpu_counter_sum(&sbi->s_freeinodes_counter);
buf->f_namelen = EXT3_NAME_LEN; buf->f_namelen = EXT4_NAME_LEN;
return 0; return 0;
} }
/* Helper function for writing quotas on sync - we need to start transaction before quota file /* Helper function for writing quotas on sync - we need to start transaction before quota file
* is locked for write. Otherwise the are possible deadlocks: * is locked for write. Otherwise the are possible deadlocks:
* Process 1 Process 2 * Process 1 Process 2
* ext3_create() quota_sync() * ext4_create() quota_sync()
* journal_start() write_dquot() * journal_start() write_dquot()
* DQUOT_INIT() down(dqio_mutex) * DQUOT_INIT() down(dqio_mutex)
* down(dqio_mutex) journal_start() * down(dqio_mutex) journal_start()
...@@ -2451,111 +2451,111 @@ static inline struct inode *dquot_to_inode(struct dquot *dquot) ...@@ -2451,111 +2451,111 @@ static inline struct inode *dquot_to_inode(struct dquot *dquot)
return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type]; return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
} }
static int ext3_dquot_initialize(struct inode *inode, int type) static int ext4_dquot_initialize(struct inode *inode, int type)
{ {
handle_t *handle; handle_t *handle;
int ret, err; int ret, err;
/* We may create quota structure so we need to reserve enough blocks */ /* We may create quota structure so we need to reserve enough blocks */
handle = ext3_journal_start(inode, 2*EXT3_QUOTA_INIT_BLOCKS(inode->i_sb)); handle = ext4_journal_start(inode, 2*EXT4_QUOTA_INIT_BLOCKS(inode->i_sb));
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
ret = dquot_initialize(inode, type); ret = dquot_initialize(inode, type);
err = ext3_journal_stop(handle); err = ext4_journal_stop(handle);
if (!ret) if (!ret)
ret = err; ret = err;
return ret; return ret;
} }
static int ext3_dquot_drop(struct inode *inode) static int ext4_dquot_drop(struct inode *inode)
{ {
handle_t *handle; handle_t *handle;
int ret, err; int ret, err;
/* We may delete quota structure so we need to reserve enough blocks */ /* We may delete quota structure so we need to reserve enough blocks */
handle = ext3_journal_start(inode, 2*EXT3_QUOTA_DEL_BLOCKS(inode->i_sb)); handle = ext4_journal_start(inode, 2*EXT4_QUOTA_DEL_BLOCKS(inode->i_sb));
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
ret = dquot_drop(inode); ret = dquot_drop(inode);
err = ext3_journal_stop(handle); err = ext4_journal_stop(handle);
if (!ret) if (!ret)
ret = err; ret = err;
return ret; return ret;
} }
static int ext3_write_dquot(struct dquot *dquot) static int ext4_write_dquot(struct dquot *dquot)
{ {
int ret, err; int ret, err;
handle_t *handle; handle_t *handle;
struct inode *inode; struct inode *inode;
inode = dquot_to_inode(dquot); inode = dquot_to_inode(dquot);
handle = ext3_journal_start(inode, handle = ext4_journal_start(inode,
EXT3_QUOTA_TRANS_BLOCKS(dquot->dq_sb)); EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
ret = dquot_commit(dquot); ret = dquot_commit(dquot);
err = ext3_journal_stop(handle); err = ext4_journal_stop(handle);
if (!ret) if (!ret)
ret = err; ret = err;
return ret; return ret;
} }
static int ext3_acquire_dquot(struct dquot *dquot) static int ext4_acquire_dquot(struct dquot *dquot)
{ {
int ret, err; int ret, err;
handle_t *handle; handle_t *handle;
handle = ext3_journal_start(dquot_to_inode(dquot), handle = ext4_journal_start(dquot_to_inode(dquot),
EXT3_QUOTA_INIT_BLOCKS(dquot->dq_sb)); EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb));
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
ret = dquot_acquire(dquot); ret = dquot_acquire(dquot);
err = ext3_journal_stop(handle); err = ext4_journal_stop(handle);
if (!ret) if (!ret)
ret = err; ret = err;
return ret; return ret;
} }
static int ext3_release_dquot(struct dquot *dquot) static int ext4_release_dquot(struct dquot *dquot)
{ {
int ret, err; int ret, err;
handle_t *handle; handle_t *handle;
handle = ext3_journal_start(dquot_to_inode(dquot), handle = ext4_journal_start(dquot_to_inode(dquot),
EXT3_QUOTA_DEL_BLOCKS(dquot->dq_sb)); EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb));
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
ret = dquot_release(dquot); ret = dquot_release(dquot);
err = ext3_journal_stop(handle); err = ext4_journal_stop(handle);
if (!ret) if (!ret)
ret = err; ret = err;
return ret; return ret;
} }
static int ext3_mark_dquot_dirty(struct dquot *dquot) static int ext4_mark_dquot_dirty(struct dquot *dquot)
{ {
/* Are we journalling quotas? */ /* Are we journalling quotas? */
if (EXT3_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] || if (EXT4_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] ||
EXT3_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) { EXT4_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) {
dquot_mark_dquot_dirty(dquot); dquot_mark_dquot_dirty(dquot);
return ext3_write_dquot(dquot); return ext4_write_dquot(dquot);
} else { } else {
return dquot_mark_dquot_dirty(dquot); return dquot_mark_dquot_dirty(dquot);
} }
} }
static int ext3_write_info(struct super_block *sb, int type) static int ext4_write_info(struct super_block *sb, int type)
{ {
int ret, err; int ret, err;
handle_t *handle; handle_t *handle;
/* Data block + inode block */ /* Data block + inode block */
handle = ext3_journal_start(sb->s_root->d_inode, 2); handle = ext4_journal_start(sb->s_root->d_inode, 2);
if (IS_ERR(handle)) if (IS_ERR(handle))
return PTR_ERR(handle); return PTR_ERR(handle);
ret = dquot_commit_info(sb, type); ret = dquot_commit_info(sb, type);
err = ext3_journal_stop(handle); err = ext4_journal_stop(handle);
if (!ret) if (!ret)
ret = err; ret = err;
return ret; return ret;
...@@ -2565,16 +2565,16 @@ static int ext3_write_info(struct super_block *sb, int type) ...@@ -2565,16 +2565,16 @@ static int ext3_write_info(struct super_block *sb, int type)
* Turn on quotas during mount time - we need to find * Turn on quotas during mount time - we need to find
* the quota file and such... * the quota file and such...
*/ */
static int ext3_quota_on_mount(struct super_block *sb, int type) static int ext4_quota_on_mount(struct super_block *sb, int type)
{ {
return vfs_quota_on_mount(sb, EXT3_SB(sb)->s_qf_names[type], return vfs_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type],
EXT3_SB(sb)->s_jquota_fmt, type); EXT4_SB(sb)->s_jquota_fmt, type);
} }
/* /*
* Standard function to be called on quota_on * Standard function to be called on quota_on
*/ */
static int ext3_quota_on(struct super_block *sb, int type, int format_id, static int ext4_quota_on(struct super_block *sb, int type, int format_id,
char *path) char *path)
{ {
int err; int err;
...@@ -2583,8 +2583,8 @@ static int ext3_quota_on(struct super_block *sb, int type, int format_id, ...@@ -2583,8 +2583,8 @@ static int ext3_quota_on(struct super_block *sb, int type, int format_id,
if (!test_opt(sb, QUOTA)) if (!test_opt(sb, QUOTA))
return -EINVAL; return -EINVAL;
/* Not journalling quota? */ /* Not journalling quota? */
if (!EXT3_SB(sb)->s_qf_names[USRQUOTA] && if (!EXT4_SB(sb)->s_qf_names[USRQUOTA] &&
!EXT3_SB(sb)->s_qf_names[GRPQUOTA]) !EXT4_SB(sb)->s_qf_names[GRPQUOTA])
return vfs_quota_on(sb, type, format_id, path); return vfs_quota_on(sb, type, format_id, path);
err = path_lookup(path, LOOKUP_FOLLOW, &nd); err = path_lookup(path, LOOKUP_FOLLOW, &nd);
if (err) if (err)
...@@ -2597,7 +2597,7 @@ static int ext3_quota_on(struct super_block *sb, int type, int format_id, ...@@ -2597,7 +2597,7 @@ static int ext3_quota_on(struct super_block *sb, int type, int format_id,
/* Quotafile not of fs root? */ /* Quotafile not of fs root? */
if (nd.dentry->d_parent->d_inode != sb->s_root->d_inode) if (nd.dentry->d_parent->d_inode != sb->s_root->d_inode)
printk(KERN_WARNING printk(KERN_WARNING
"EXT3-fs: Quota file not on filesystem root. " "EXT4-fs: Quota file not on filesystem root. "
"Journalled quota will not work.\n"); "Journalled quota will not work.\n");
path_release(&nd); path_release(&nd);
return vfs_quota_on(sb, type, format_id, path); 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,11 +2607,11 @@ static int ext3_quota_on(struct super_block *sb, int type, int format_id,
* acquiring the locks... As quota files are never truncated and quota code * acquiring the locks... As quota files are never truncated and quota code
* itself serializes the operations (and noone else should touch the files) * itself serializes the operations (and noone else should touch the files)
* we don't have to be afraid of races */ * we don't have to be afraid of races */
static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data, static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
size_t len, loff_t off) size_t len, loff_t off)
{ {
struct inode *inode = sb_dqopt(sb)->files[type]; struct inode *inode = sb_dqopt(sb)->files[type];
sector_t blk = off >> EXT3_BLOCK_SIZE_BITS(sb); sector_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
int err = 0; int err = 0;
int offset = off & (sb->s_blocksize - 1); int offset = off & (sb->s_blocksize - 1);
int tocopy; int tocopy;
...@@ -2627,7 +2627,7 @@ static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data, ...@@ -2627,7 +2627,7 @@ static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data,
while (toread > 0) { while (toread > 0) {
tocopy = sb->s_blocksize - offset < toread ? tocopy = sb->s_blocksize - offset < toread ?
sb->s_blocksize - offset : toread; sb->s_blocksize - offset : toread;
bh = ext3_bread(NULL, inode, blk, 0, &err); bh = ext4_bread(NULL, inode, blk, 0, &err);
if (err) if (err)
return err; return err;
if (!bh) /* A hole? */ if (!bh) /* A hole? */
...@@ -2645,15 +2645,15 @@ static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data, ...@@ -2645,15 +2645,15 @@ static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data,
/* Write to quotafile (we know the transaction is already started and has /* Write to quotafile (we know the transaction is already started and has
* enough credits) */ * enough credits) */
static ssize_t ext3_quota_write(struct super_block *sb, int type, static ssize_t ext4_quota_write(struct super_block *sb, int type,
const char *data, size_t len, loff_t off) const char *data, size_t len, loff_t off)
{ {
struct inode *inode = sb_dqopt(sb)->files[type]; struct inode *inode = sb_dqopt(sb)->files[type];
sector_t blk = off >> EXT3_BLOCK_SIZE_BITS(sb); sector_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
int err = 0; int err = 0;
int offset = off & (sb->s_blocksize - 1); int offset = off & (sb->s_blocksize - 1);
int tocopy; int tocopy;
int journal_quota = EXT3_SB(sb)->s_qf_names[type] != NULL; int journal_quota = EXT4_SB(sb)->s_qf_names[type] != NULL;
size_t towrite = len; size_t towrite = len;
struct buffer_head *bh; struct buffer_head *bh;
handle_t *handle = journal_current_handle(); handle_t *handle = journal_current_handle();
...@@ -2662,11 +2662,11 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type, ...@@ -2662,11 +2662,11 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type,
while (towrite > 0) { while (towrite > 0) {
tocopy = sb->s_blocksize - offset < towrite ? tocopy = sb->s_blocksize - offset < towrite ?
sb->s_blocksize - offset : towrite; sb->s_blocksize - offset : towrite;
bh = ext3_bread(handle, inode, blk, 1, &err); bh = ext4_bread(handle, inode, blk, 1, &err);
if (!bh) if (!bh)
goto out; goto out;
if (journal_quota) { if (journal_quota) {
err = ext3_journal_get_write_access(handle, bh); err = ext4_journal_get_write_access(handle, bh);
if (err) { if (err) {
brelse(bh); brelse(bh);
goto out; goto out;
...@@ -2677,10 +2677,10 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type, ...@@ -2677,10 +2677,10 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type,
flush_dcache_page(bh->b_page); flush_dcache_page(bh->b_page);
unlock_buffer(bh); unlock_buffer(bh);
if (journal_quota) if (journal_quota)
err = ext3_journal_dirty_metadata(handle, bh); err = ext4_journal_dirty_metadata(handle, bh);
else { else {
/* Always do at least ordered writes for quotas */ /* Always do at least ordered writes for quotas */
err = ext3_journal_dirty_data(handle, bh); err = ext4_journal_dirty_data(handle, bh);
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
} }
brelse(bh); brelse(bh);
...@@ -2696,59 +2696,59 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type, ...@@ -2696,59 +2696,59 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type,
return err; return err;
if (inode->i_size < off+len-towrite) { if (inode->i_size < off+len-towrite) {
i_size_write(inode, off+len-towrite); i_size_write(inode, off+len-towrite);
EXT3_I(inode)->i_disksize = inode->i_size; EXT4_I(inode)->i_disksize = inode->i_size;
} }
inode->i_version++; inode->i_version++;
inode->i_mtime = inode->i_ctime = CURRENT_TIME; inode->i_mtime = inode->i_ctime = CURRENT_TIME;
ext3_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
return len - towrite; return len - towrite;
} }
#endif #endif
static int ext3_get_sb(struct file_system_type *fs_type, static int ext4_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt) int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{ {
return get_sb_bdev(fs_type, flags, dev_name, data, ext3_fill_super, mnt); return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt);
} }
static struct file_system_type ext3_fs_type = { static struct file_system_type ext4dev_fs_type = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "ext3", .name = "ext4dev",
.get_sb = ext3_get_sb, .get_sb = ext4_get_sb,
.kill_sb = kill_block_super, .kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV, .fs_flags = FS_REQUIRES_DEV,
}; };
static int __init init_ext3_fs(void) static int __init init_ext4_fs(void)
{ {
int err = init_ext3_xattr(); int err = init_ext4_xattr();
if (err) if (err)
return err; return err;
err = init_inodecache(); err = init_inodecache();
if (err) if (err)
goto out1; goto out1;
err = register_filesystem(&ext3_fs_type); err = register_filesystem(&ext4dev_fs_type);
if (err) if (err)
goto out; goto out;
return 0; return 0;
out: out:
destroy_inodecache(); destroy_inodecache();
out1: out1:
exit_ext3_xattr(); exit_ext4_xattr();
return err; return err;
} }
static void __exit exit_ext3_fs(void) static void __exit exit_ext4_fs(void)
{ {
unregister_filesystem(&ext3_fs_type); unregister_filesystem(&ext4dev_fs_type);
destroy_inodecache(); destroy_inodecache();
exit_ext3_xattr(); exit_ext4_xattr();
} }
MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
MODULE_DESCRIPTION("Second Extended Filesystem with journaling extensions"); MODULE_DESCRIPTION("Fourth Extended Filesystem with extents");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
module_init(init_ext3_fs) module_init(init_ext4_fs)
module_exit(exit_ext3_fs) module_exit(exit_ext4_fs)
/* /*
* linux/fs/ext3/symlink.c * linux/fs/ext4/symlink.c
* *
* Only fast symlinks left here - the rest is done by generic code. AV, 1999 * Only fast symlinks left here - the rest is done by generic code. AV, 1999
* *
...@@ -14,41 +14,41 @@ ...@@ -14,41 +14,41 @@
* *
* Copyright (C) 1991, 1992 Linus Torvalds * Copyright (C) 1991, 1992 Linus Torvalds
* *
* ext3 symlink handling code * ext4 symlink handling code
*/ */
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/jbd.h> #include <linux/jbd.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#include <linux/namei.h> #include <linux/namei.h>
#include "xattr.h" #include "xattr.h"
static void * ext3_follow_link(struct dentry *dentry, struct nameidata *nd) static void * ext4_follow_link(struct dentry *dentry, struct nameidata *nd)
{ {
struct ext3_inode_info *ei = EXT3_I(dentry->d_inode); struct ext4_inode_info *ei = EXT4_I(dentry->d_inode);
nd_set_link(nd, (char*)ei->i_data); nd_set_link(nd, (char*)ei->i_data);
return NULL; return NULL;
} }
struct inode_operations ext3_symlink_inode_operations = { struct inode_operations ext4_symlink_inode_operations = {
.readlink = generic_readlink, .readlink = generic_readlink,
.follow_link = page_follow_link_light, .follow_link = page_follow_link_light,
.put_link = page_put_link, .put_link = page_put_link,
#ifdef CONFIG_EXT3_FS_XATTR #ifdef CONFIG_EXT4DEV_FS_XATTR
.setxattr = generic_setxattr, .setxattr = generic_setxattr,
.getxattr = generic_getxattr, .getxattr = generic_getxattr,
.listxattr = ext3_listxattr, .listxattr = ext4_listxattr,
.removexattr = generic_removexattr, .removexattr = generic_removexattr,
#endif #endif
}; };
struct inode_operations ext3_fast_symlink_inode_operations = { struct inode_operations ext4_fast_symlink_inode_operations = {
.readlink = generic_readlink, .readlink = generic_readlink,
.follow_link = ext3_follow_link, .follow_link = ext4_follow_link,
#ifdef CONFIG_EXT3_FS_XATTR #ifdef CONFIG_EXT4DEV_FS_XATTR
.setxattr = generic_setxattr, .setxattr = generic_setxattr,
.getxattr = generic_getxattr, .getxattr = generic_getxattr,
.listxattr = ext3_listxattr, .listxattr = ext4_listxattr,
.removexattr = generic_removexattr, .removexattr = generic_removexattr,
#endif #endif
}; };
/* /*
* linux/fs/ext3/xattr.c * linux/fs/ext4/xattr.c
* *
* Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de> * Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de>
* *
* Fix by Harrison Xing <harrison@mountainviewdata.com>. * Fix by Harrison Xing <harrison@mountainviewdata.com>.
* Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>. * Ext4 code with a lot of help from Eric Jarman <ejarman@acm.org>.
* Extended attributes for symlinks and special files added per * Extended attributes for symlinks and special files added per
* suggestion of Luka Renko <luka.renko@hermes.si>. * suggestion of Luka Renko <luka.renko@hermes.si>.
* xattr consolidation Copyright (c) 2004 James Morris <jmorris@redhat.com>, * xattr consolidation Copyright (c) 2004 James Morris <jmorris@redhat.com>,
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
* *
* Locking strategy * Locking strategy
* ---------------- * ----------------
* EXT3_I(inode)->i_file_acl is protected by EXT3_I(inode)->xattr_sem. * EXT4_I(inode)->i_file_acl is protected by EXT4_I(inode)->xattr_sem.
* EA blocks are only changed if they are exclusive to an inode, so * EA blocks are only changed if they are exclusive to an inode, so
* holding xattr_sem also means that nothing but the EA block's reference * holding xattr_sem also means that nothing but the EA block's reference
* count can change. Multiple writers to the same block are synchronized * count can change. Multiple writers to the same block are synchronized
...@@ -53,27 +53,27 @@ ...@@ -53,27 +53,27 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/ext3_jbd.h> #include <linux/ext4_jbd.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#include <linux/mbcache.h> #include <linux/mbcache.h>
#include <linux/quotaops.h> #include <linux/quotaops.h>
#include <linux/rwsem.h> #include <linux/rwsem.h>
#include "xattr.h" #include "xattr.h"
#include "acl.h" #include "acl.h"
#define BHDR(bh) ((struct ext3_xattr_header *)((bh)->b_data)) #define BHDR(bh) ((struct ext4_xattr_header *)((bh)->b_data))
#define ENTRY(ptr) ((struct ext3_xattr_entry *)(ptr)) #define ENTRY(ptr) ((struct ext4_xattr_entry *)(ptr))
#define BFIRST(bh) ENTRY(BHDR(bh)+1) #define BFIRST(bh) ENTRY(BHDR(bh)+1)
#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0) #define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
#define IHDR(inode, raw_inode) \ #define IHDR(inode, raw_inode) \
((struct ext3_xattr_ibody_header *) \ ((struct ext4_xattr_ibody_header *) \
((void *)raw_inode + \ ((void *)raw_inode + \
EXT3_GOOD_OLD_INODE_SIZE + \ EXT4_GOOD_OLD_INODE_SIZE + \
EXT3_I(inode)->i_extra_isize)) EXT4_I(inode)->i_extra_isize))
#define IFIRST(hdr) ((struct ext3_xattr_entry *)((hdr)+1)) #define IFIRST(hdr) ((struct ext4_xattr_entry *)((hdr)+1))
#ifdef EXT3_XATTR_DEBUG #ifdef EXT4_XATTR_DEBUG
# define ea_idebug(inode, f...) do { \ # define ea_idebug(inode, f...) do { \
printk(KERN_DEBUG "inode %s:%lu: ", \ printk(KERN_DEBUG "inode %s:%lu: ", \
inode->i_sb->s_id, inode->i_ino); \ inode->i_sb->s_id, inode->i_ino); \
...@@ -93,47 +93,47 @@ ...@@ -93,47 +93,47 @@
# define ea_bdebug(f...) # define ea_bdebug(f...)
#endif #endif
static void ext3_xattr_cache_insert(struct buffer_head *); static void ext4_xattr_cache_insert(struct buffer_head *);
static struct buffer_head *ext3_xattr_cache_find(struct inode *, static struct buffer_head *ext4_xattr_cache_find(struct inode *,
struct ext3_xattr_header *, struct ext4_xattr_header *,
struct mb_cache_entry **); struct mb_cache_entry **);
static void ext3_xattr_rehash(struct ext3_xattr_header *, static void ext4_xattr_rehash(struct ext4_xattr_header *,
struct ext3_xattr_entry *); struct ext4_xattr_entry *);
static struct mb_cache *ext3_xattr_cache; static struct mb_cache *ext4_xattr_cache;
static struct xattr_handler *ext3_xattr_handler_map[] = { static struct xattr_handler *ext4_xattr_handler_map[] = {
[EXT3_XATTR_INDEX_USER] = &ext3_xattr_user_handler, [EXT4_XATTR_INDEX_USER] = &ext4_xattr_user_handler,
#ifdef CONFIG_EXT3_FS_POSIX_ACL #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
[EXT3_XATTR_INDEX_POSIX_ACL_ACCESS] = &ext3_xattr_acl_access_handler, [EXT4_XATTR_INDEX_POSIX_ACL_ACCESS] = &ext4_xattr_acl_access_handler,
[EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT] = &ext3_xattr_acl_default_handler, [EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT] = &ext4_xattr_acl_default_handler,
#endif #endif
[EXT3_XATTR_INDEX_TRUSTED] = &ext3_xattr_trusted_handler, [EXT4_XATTR_INDEX_TRUSTED] = &ext4_xattr_trusted_handler,
#ifdef CONFIG_EXT3_FS_SECURITY #ifdef CONFIG_EXT4DEV_FS_SECURITY
[EXT3_XATTR_INDEX_SECURITY] = &ext3_xattr_security_handler, [EXT4_XATTR_INDEX_SECURITY] = &ext4_xattr_security_handler,
#endif #endif
}; };
struct xattr_handler *ext3_xattr_handlers[] = { struct xattr_handler *ext4_xattr_handlers[] = {
&ext3_xattr_user_handler, &ext4_xattr_user_handler,
&ext3_xattr_trusted_handler, &ext4_xattr_trusted_handler,
#ifdef CONFIG_EXT3_FS_POSIX_ACL #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
&ext3_xattr_acl_access_handler, &ext4_xattr_acl_access_handler,
&ext3_xattr_acl_default_handler, &ext4_xattr_acl_default_handler,
#endif #endif
#ifdef CONFIG_EXT3_FS_SECURITY #ifdef CONFIG_EXT4DEV_FS_SECURITY
&ext3_xattr_security_handler, &ext4_xattr_security_handler,
#endif #endif
NULL NULL
}; };
static inline struct xattr_handler * static inline struct xattr_handler *
ext3_xattr_handler(int name_index) ext4_xattr_handler(int name_index)
{ {
struct xattr_handler *handler = NULL; struct xattr_handler *handler = NULL;
if (name_index > 0 && name_index < ARRAY_SIZE(ext3_xattr_handler_map)) if (name_index > 0 && name_index < ARRAY_SIZE(ext4_xattr_handler_map))
handler = ext3_xattr_handler_map[name_index]; handler = ext4_xattr_handler_map[name_index];
return handler; return handler;
} }
...@@ -143,16 +143,16 @@ ext3_xattr_handler(int name_index) ...@@ -143,16 +143,16 @@ ext3_xattr_handler(int name_index)
* dentry->d_inode->i_mutex: don't care * dentry->d_inode->i_mutex: don't care
*/ */
ssize_t ssize_t
ext3_listxattr(struct dentry *dentry, char *buffer, size_t size) ext4_listxattr(struct dentry *dentry, char *buffer, size_t size)
{ {
return ext3_xattr_list(dentry->d_inode, buffer, size); return ext4_xattr_list(dentry->d_inode, buffer, size);
} }
static int static int
ext3_xattr_check_names(struct ext3_xattr_entry *entry, void *end) ext4_xattr_check_names(struct ext4_xattr_entry *entry, void *end)
{ {
while (!IS_LAST_ENTRY(entry)) { while (!IS_LAST_ENTRY(entry)) {
struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(entry); struct ext4_xattr_entry *next = EXT4_XATTR_NEXT(entry);
if ((void *)next >= end) if ((void *)next >= end)
return -EIO; return -EIO;
entry = next; entry = next;
...@@ -161,19 +161,19 @@ ext3_xattr_check_names(struct ext3_xattr_entry *entry, void *end) ...@@ -161,19 +161,19 @@ ext3_xattr_check_names(struct ext3_xattr_entry *entry, void *end)
} }
static inline int static inline int
ext3_xattr_check_block(struct buffer_head *bh) ext4_xattr_check_block(struct buffer_head *bh)
{ {
int error; int error;
if (BHDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) || if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
BHDR(bh)->h_blocks != cpu_to_le32(1)) BHDR(bh)->h_blocks != cpu_to_le32(1))
return -EIO; return -EIO;
error = ext3_xattr_check_names(BFIRST(bh), bh->b_data + bh->b_size); error = ext4_xattr_check_names(BFIRST(bh), bh->b_data + bh->b_size);
return error; return error;
} }
static inline int static inline int
ext3_xattr_check_entry(struct ext3_xattr_entry *entry, size_t size) ext4_xattr_check_entry(struct ext4_xattr_entry *entry, size_t size)
{ {
size_t value_size = le32_to_cpu(entry->e_value_size); size_t value_size = le32_to_cpu(entry->e_value_size);
...@@ -184,10 +184,10 @@ ext3_xattr_check_entry(struct ext3_xattr_entry *entry, size_t size) ...@@ -184,10 +184,10 @@ ext3_xattr_check_entry(struct ext3_xattr_entry *entry, size_t size)
} }
static int static int
ext3_xattr_find_entry(struct ext3_xattr_entry **pentry, int name_index, ext4_xattr_find_entry(struct ext4_xattr_entry **pentry, int name_index,
const char *name, size_t size, int sorted) const char *name, size_t size, int sorted)
{ {
struct ext3_xattr_entry *entry; struct ext4_xattr_entry *entry;
size_t name_len; size_t name_len;
int cmp = 1; int cmp = 1;
...@@ -195,7 +195,7 @@ ext3_xattr_find_entry(struct ext3_xattr_entry **pentry, int name_index, ...@@ -195,7 +195,7 @@ ext3_xattr_find_entry(struct ext3_xattr_entry **pentry, int name_index,
return -EINVAL; return -EINVAL;
name_len = strlen(name); name_len = strlen(name);
entry = *pentry; entry = *pentry;
for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) { for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
cmp = name_index - entry->e_name_index; cmp = name_index - entry->e_name_index;
if (!cmp) if (!cmp)
cmp = name_len - entry->e_name_len; cmp = name_len - entry->e_name_len;
...@@ -205,17 +205,17 @@ ext3_xattr_find_entry(struct ext3_xattr_entry **pentry, int name_index, ...@@ -205,17 +205,17 @@ ext3_xattr_find_entry(struct ext3_xattr_entry **pentry, int name_index,
break; break;
} }
*pentry = entry; *pentry = entry;
if (!cmp && ext3_xattr_check_entry(entry, size)) if (!cmp && ext4_xattr_check_entry(entry, size))
return -EIO; return -EIO;
return cmp ? -ENODATA : 0; return cmp ? -ENODATA : 0;
} }
static int static int
ext3_xattr_block_get(struct inode *inode, int name_index, const char *name, ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
void *buffer, size_t buffer_size) void *buffer, size_t buffer_size)
{ {
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
struct ext3_xattr_entry *entry; struct ext4_xattr_entry *entry;
size_t size; size_t size;
int error; int error;
...@@ -223,24 +223,24 @@ ext3_xattr_block_get(struct inode *inode, int name_index, const char *name, ...@@ -223,24 +223,24 @@ ext3_xattr_block_get(struct inode *inode, int name_index, const char *name,
name_index, name, buffer, (long)buffer_size); name_index, name, buffer, (long)buffer_size);
error = -ENODATA; error = -ENODATA;
if (!EXT3_I(inode)->i_file_acl) if (!EXT4_I(inode)->i_file_acl)
goto cleanup; goto cleanup;
ea_idebug(inode, "reading block %u", EXT3_I(inode)->i_file_acl); ea_idebug(inode, "reading block %u", EXT4_I(inode)->i_file_acl);
bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl); bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
if (!bh) if (!bh)
goto cleanup; goto cleanup;
ea_bdebug(bh, "b_count=%d, refcount=%d", ea_bdebug(bh, "b_count=%d, refcount=%d",
atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
if (ext3_xattr_check_block(bh)) { if (ext4_xattr_check_block(bh)) {
bad_block: ext3_error(inode->i_sb, __FUNCTION__, bad_block: ext4_error(inode->i_sb, __FUNCTION__,
"inode %lu: bad block "E3FSBLK, inode->i_ino, "inode %lu: bad block "E3FSBLK, inode->i_ino,
EXT3_I(inode)->i_file_acl); EXT4_I(inode)->i_file_acl);
error = -EIO; error = -EIO;
goto cleanup; goto cleanup;
} }
ext3_xattr_cache_insert(bh); ext4_xattr_cache_insert(bh);
entry = BFIRST(bh); entry = BFIRST(bh);
error = ext3_xattr_find_entry(&entry, name_index, name, bh->b_size, 1); error = ext4_xattr_find_entry(&entry, name_index, name, bh->b_size, 1);
if (error == -EIO) if (error == -EIO)
goto bad_block; goto bad_block;
if (error) if (error)
...@@ -261,30 +261,30 @@ bad_block: ext3_error(inode->i_sb, __FUNCTION__, ...@@ -261,30 +261,30 @@ bad_block: ext3_error(inode->i_sb, __FUNCTION__,
} }
static int static int
ext3_xattr_ibody_get(struct inode *inode, int name_index, const char *name, ext4_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
void *buffer, size_t buffer_size) void *buffer, size_t buffer_size)
{ {
struct ext3_xattr_ibody_header *header; struct ext4_xattr_ibody_header *header;
struct ext3_xattr_entry *entry; struct ext4_xattr_entry *entry;
struct ext3_inode *raw_inode; struct ext4_inode *raw_inode;
struct ext3_iloc iloc; struct ext4_iloc iloc;
size_t size; size_t size;
void *end; void *end;
int error; int error;
if (!(EXT3_I(inode)->i_state & EXT3_STATE_XATTR)) if (!(EXT4_I(inode)->i_state & EXT4_STATE_XATTR))
return -ENODATA; return -ENODATA;
error = ext3_get_inode_loc(inode, &iloc); error = ext4_get_inode_loc(inode, &iloc);
if (error) if (error)
return error; return error;
raw_inode = ext3_raw_inode(&iloc); raw_inode = ext4_raw_inode(&iloc);
header = IHDR(inode, raw_inode); header = IHDR(inode, raw_inode);
entry = IFIRST(header); entry = IFIRST(header);
end = (void *)raw_inode + EXT3_SB(inode->i_sb)->s_inode_size; end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size;
error = ext3_xattr_check_names(entry, end); error = ext4_xattr_check_names(entry, end);
if (error) if (error)
goto cleanup; goto cleanup;
error = ext3_xattr_find_entry(&entry, name_index, name, error = ext4_xattr_find_entry(&entry, name_index, name,
end - (void *)entry, 0); end - (void *)entry, 0);
if (error) if (error)
goto cleanup; goto cleanup;
...@@ -304,7 +304,7 @@ ext3_xattr_ibody_get(struct inode *inode, int name_index, const char *name, ...@@ -304,7 +304,7 @@ ext3_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
} }
/* /*
* ext3_xattr_get() * ext4_xattr_get()
* *
* Copy an extended attribute into the buffer * Copy an extended attribute into the buffer
* provided, or compute the buffer size required. * provided, or compute the buffer size required.
...@@ -314,30 +314,30 @@ ext3_xattr_ibody_get(struct inode *inode, int name_index, const char *name, ...@@ -314,30 +314,30 @@ ext3_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
* used / required on success. * used / required on success.
*/ */
int int
ext3_xattr_get(struct inode *inode, int name_index, const char *name, ext4_xattr_get(struct inode *inode, int name_index, const char *name,
void *buffer, size_t buffer_size) void *buffer, size_t buffer_size)
{ {
int error; int error;
down_read(&EXT3_I(inode)->xattr_sem); down_read(&EXT4_I(inode)->xattr_sem);
error = ext3_xattr_ibody_get(inode, name_index, name, buffer, error = ext4_xattr_ibody_get(inode, name_index, name, buffer,
buffer_size); buffer_size);
if (error == -ENODATA) if (error == -ENODATA)
error = ext3_xattr_block_get(inode, name_index, name, buffer, error = ext4_xattr_block_get(inode, name_index, name, buffer,
buffer_size); buffer_size);
up_read(&EXT3_I(inode)->xattr_sem); up_read(&EXT4_I(inode)->xattr_sem);
return error; return error;
} }
static int static int
ext3_xattr_list_entries(struct inode *inode, struct ext3_xattr_entry *entry, ext4_xattr_list_entries(struct inode *inode, struct ext4_xattr_entry *entry,
char *buffer, size_t buffer_size) char *buffer, size_t buffer_size)
{ {
size_t rest = buffer_size; size_t rest = buffer_size;
for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) { for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
struct xattr_handler *handler = struct xattr_handler *handler =
ext3_xattr_handler(entry->e_name_index); ext4_xattr_handler(entry->e_name_index);
if (handler) { if (handler) {
size_t size = handler->list(inode, buffer, rest, 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,7 +355,7 @@ ext3_xattr_list_entries(struct inode *inode, struct ext3_xattr_entry *entry,
} }
static int static int
ext3_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size) ext4_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size)
{ {
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
int error; int error;
...@@ -364,24 +364,24 @@ ext3_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size) ...@@ -364,24 +364,24 @@ ext3_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size)
buffer, (long)buffer_size); buffer, (long)buffer_size);
error = 0; error = 0;
if (!EXT3_I(inode)->i_file_acl) if (!EXT4_I(inode)->i_file_acl)
goto cleanup; goto cleanup;
ea_idebug(inode, "reading block %u", EXT3_I(inode)->i_file_acl); ea_idebug(inode, "reading block %u", EXT4_I(inode)->i_file_acl);
bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl); bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
error = -EIO; error = -EIO;
if (!bh) if (!bh)
goto cleanup; goto cleanup;
ea_bdebug(bh, "b_count=%d, refcount=%d", ea_bdebug(bh, "b_count=%d, refcount=%d",
atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
if (ext3_xattr_check_block(bh)) { if (ext4_xattr_check_block(bh)) {
ext3_error(inode->i_sb, __FUNCTION__, ext4_error(inode->i_sb, __FUNCTION__,
"inode %lu: bad block "E3FSBLK, inode->i_ino, "inode %lu: bad block "E3FSBLK, inode->i_ino,
EXT3_I(inode)->i_file_acl); EXT4_I(inode)->i_file_acl);
error = -EIO; error = -EIO;
goto cleanup; goto cleanup;
} }
ext3_xattr_cache_insert(bh); ext4_xattr_cache_insert(bh);
error = ext3_xattr_list_entries(inode, BFIRST(bh), buffer, buffer_size); error = ext4_xattr_list_entries(inode, BFIRST(bh), buffer, buffer_size);
cleanup: cleanup:
brelse(bh); brelse(bh);
...@@ -390,26 +390,26 @@ ext3_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size) ...@@ -390,26 +390,26 @@ ext3_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size)
} }
static int static int
ext3_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size) ext4_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size)
{ {
struct ext3_xattr_ibody_header *header; struct ext4_xattr_ibody_header *header;
struct ext3_inode *raw_inode; struct ext4_inode *raw_inode;
struct ext3_iloc iloc; struct ext4_iloc iloc;
void *end; void *end;
int error; int error;
if (!(EXT3_I(inode)->i_state & EXT3_STATE_XATTR)) if (!(EXT4_I(inode)->i_state & EXT4_STATE_XATTR))
return 0; return 0;
error = ext3_get_inode_loc(inode, &iloc); error = ext4_get_inode_loc(inode, &iloc);
if (error) if (error)
return error; return error;
raw_inode = ext3_raw_inode(&iloc); raw_inode = ext4_raw_inode(&iloc);
header = IHDR(inode, raw_inode); header = IHDR(inode, raw_inode);
end = (void *)raw_inode + EXT3_SB(inode->i_sb)->s_inode_size; end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size;
error = ext3_xattr_check_names(IFIRST(header), end); error = ext4_xattr_check_names(IFIRST(header), end);
if (error) if (error)
goto cleanup; goto cleanup;
error = ext3_xattr_list_entries(inode, IFIRST(header), error = ext4_xattr_list_entries(inode, IFIRST(header),
buffer, buffer_size); buffer, buffer_size);
cleanup: cleanup:
...@@ -418,7 +418,7 @@ ext3_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size) ...@@ -418,7 +418,7 @@ ext3_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size)
} }
/* /*
* ext3_xattr_list() * ext4_xattr_list()
* *
* Copy a list of attribute names into the buffer * Copy a list of attribute names into the buffer
* provided, or compute the buffer size required. * provided, or compute the buffer size required.
...@@ -428,12 +428,12 @@ ext3_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size) ...@@ -428,12 +428,12 @@ ext3_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size)
* used / required on success. * used / required on success.
*/ */
int int
ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size) ext4_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
{ {
int i_error, b_error; int i_error, b_error;
down_read(&EXT3_I(inode)->xattr_sem); down_read(&EXT4_I(inode)->xattr_sem);
i_error = ext3_xattr_ibody_list(inode, buffer, buffer_size); i_error = ext4_xattr_ibody_list(inode, buffer, buffer_size);
if (i_error < 0) { if (i_error < 0) {
b_error = 0; b_error = 0;
} else { } else {
...@@ -441,30 +441,30 @@ ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size) ...@@ -441,30 +441,30 @@ ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
buffer += i_error; buffer += i_error;
buffer_size -= i_error; buffer_size -= i_error;
} }
b_error = ext3_xattr_block_list(inode, buffer, buffer_size); b_error = ext4_xattr_block_list(inode, buffer, buffer_size);
if (b_error < 0) if (b_error < 0)
i_error = 0; i_error = 0;
} }
up_read(&EXT3_I(inode)->xattr_sem); up_read(&EXT4_I(inode)->xattr_sem);
return i_error + b_error; return i_error + b_error;
} }
/* /*
* If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is * If the EXT4_FEATURE_COMPAT_EXT_ATTR feature of this file system is
* not set, set it. * not set, set it.
*/ */
static void ext3_xattr_update_super_block(handle_t *handle, static void ext4_xattr_update_super_block(handle_t *handle,
struct super_block *sb) struct super_block *sb)
{ {
if (EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_EXT_ATTR)) if (EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_EXT_ATTR))
return; return;
lock_super(sb); lock_super(sb);
if (ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh) == 0) { if (ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh) == 0) {
EXT3_SB(sb)->s_es->s_feature_compat |= EXT4_SB(sb)->s_es->s_feature_compat |=
cpu_to_le32(EXT3_FEATURE_COMPAT_EXT_ATTR); cpu_to_le32(EXT4_FEATURE_COMPAT_EXT_ATTR);
sb->s_dirt = 1; sb->s_dirt = 1;
ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh);
} }
unlock_super(sb); unlock_super(sb);
} }
...@@ -474,25 +474,25 @@ static void ext3_xattr_update_super_block(handle_t *handle, ...@@ -474,25 +474,25 @@ static void ext3_xattr_update_super_block(handle_t *handle,
* it; otherwise free the block. * it; otherwise free the block.
*/ */
static void static void
ext3_xattr_release_block(handle_t *handle, struct inode *inode, ext4_xattr_release_block(handle_t *handle, struct inode *inode,
struct buffer_head *bh) struct buffer_head *bh)
{ {
struct mb_cache_entry *ce = NULL; struct mb_cache_entry *ce = NULL;
ce = mb_cache_entry_get(ext3_xattr_cache, bh->b_bdev, bh->b_blocknr); ce = mb_cache_entry_get(ext4_xattr_cache, bh->b_bdev, bh->b_blocknr);
if (BHDR(bh)->h_refcount == cpu_to_le32(1)) { if (BHDR(bh)->h_refcount == cpu_to_le32(1)) {
ea_bdebug(bh, "refcount now=0; freeing"); ea_bdebug(bh, "refcount now=0; freeing");
if (ce) if (ce)
mb_cache_entry_free(ce); mb_cache_entry_free(ce);
ext3_free_blocks(handle, inode, bh->b_blocknr, 1); ext4_free_blocks(handle, inode, bh->b_blocknr, 1);
get_bh(bh); get_bh(bh);
ext3_forget(handle, 1, inode, bh, bh->b_blocknr); ext4_forget(handle, 1, inode, bh, bh->b_blocknr);
} else { } else {
if (ext3_journal_get_write_access(handle, bh) == 0) { if (ext4_journal_get_write_access(handle, bh) == 0) {
lock_buffer(bh); lock_buffer(bh);
BHDR(bh)->h_refcount = cpu_to_le32( BHDR(bh)->h_refcount = cpu_to_le32(
le32_to_cpu(BHDR(bh)->h_refcount) - 1); le32_to_cpu(BHDR(bh)->h_refcount) - 1);
ext3_journal_dirty_metadata(handle, bh); ext4_journal_dirty_metadata(handle, bh);
if (IS_SYNC(inode)) if (IS_SYNC(inode))
handle->h_sync = 1; handle->h_sync = 1;
DQUOT_FREE_BLOCK(inode, 1); DQUOT_FREE_BLOCK(inode, 1);
...@@ -505,30 +505,30 @@ ext3_xattr_release_block(handle_t *handle, struct inode *inode, ...@@ -505,30 +505,30 @@ ext3_xattr_release_block(handle_t *handle, struct inode *inode,
} }
} }
struct ext3_xattr_info { struct ext4_xattr_info {
int name_index; int name_index;
const char *name; const char *name;
const void *value; const void *value;
size_t value_len; size_t value_len;
}; };
struct ext3_xattr_search { struct ext4_xattr_search {
struct ext3_xattr_entry *first; struct ext4_xattr_entry *first;
void *base; void *base;
void *end; void *end;
struct ext3_xattr_entry *here; struct ext4_xattr_entry *here;
int not_found; int not_found;
}; };
static int static int
ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s) ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s)
{ {
struct ext3_xattr_entry *last; struct ext4_xattr_entry *last;
size_t free, min_offs = s->end - s->base, name_len = strlen(i->name); size_t free, min_offs = s->end - s->base, name_len = strlen(i->name);
/* Compute min_offs and last. */ /* Compute min_offs and last. */
last = s->first; last = s->first;
for (; !IS_LAST_ENTRY(last); last = EXT3_XATTR_NEXT(last)) { for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
if (!last->e_value_block && last->e_value_size) { if (!last->e_value_block && last->e_value_size) {
size_t offs = le16_to_cpu(last->e_value_offs); size_t offs = le16_to_cpu(last->e_value_offs);
if (offs < min_offs) if (offs < min_offs)
...@@ -539,20 +539,20 @@ ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s) ...@@ -539,20 +539,20 @@ ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s)
if (!s->not_found) { if (!s->not_found) {
if (!s->here->e_value_block && s->here->e_value_size) { if (!s->here->e_value_block && s->here->e_value_size) {
size_t size = le32_to_cpu(s->here->e_value_size); size_t size = le32_to_cpu(s->here->e_value_size);
free += EXT3_XATTR_SIZE(size); free += EXT4_XATTR_SIZE(size);
} }
free += EXT3_XATTR_LEN(name_len); free += EXT4_XATTR_LEN(name_len);
} }
if (i->value) { if (i->value) {
if (free < EXT3_XATTR_SIZE(i->value_len) || if (free < EXT4_XATTR_SIZE(i->value_len) ||
free < EXT3_XATTR_LEN(name_len) + free < EXT4_XATTR_LEN(name_len) +
EXT3_XATTR_SIZE(i->value_len)) EXT4_XATTR_SIZE(i->value_len))
return -ENOSPC; return -ENOSPC;
} }
if (i->value && s->not_found) { if (i->value && s->not_found) {
/* Insert the new name. */ /* Insert the new name. */
size_t size = EXT3_XATTR_LEN(name_len); size_t size = EXT4_XATTR_LEN(name_len);
size_t rest = (void *)last - (void *)s->here + sizeof(__u32); size_t rest = (void *)last - (void *)s->here + sizeof(__u32);
memmove((void *)s->here + size, s->here, rest); memmove((void *)s->here + size, s->here, rest);
memset(s->here, 0, size); memset(s->here, 0, size);
...@@ -564,16 +564,16 @@ ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s) ...@@ -564,16 +564,16 @@ ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s)
void *first_val = s->base + min_offs; void *first_val = s->base + min_offs;
size_t offs = le16_to_cpu(s->here->e_value_offs); size_t offs = le16_to_cpu(s->here->e_value_offs);
void *val = s->base + offs; void *val = s->base + offs;
size_t size = EXT3_XATTR_SIZE( size_t size = EXT4_XATTR_SIZE(
le32_to_cpu(s->here->e_value_size)); le32_to_cpu(s->here->e_value_size));
if (i->value && size == EXT3_XATTR_SIZE(i->value_len)) { if (i->value && size == EXT4_XATTR_SIZE(i->value_len)) {
/* The old and the new value have the same /* The old and the new value have the same
size. Just replace. */ size. Just replace. */
s->here->e_value_size = s->here->e_value_size =
cpu_to_le32(i->value_len); cpu_to_le32(i->value_len);
memset(val + size - EXT3_XATTR_PAD, 0, memset(val + size - EXT4_XATTR_PAD, 0,
EXT3_XATTR_PAD); /* Clear pad bytes. */ EXT4_XATTR_PAD); /* Clear pad bytes. */
memcpy(val, i->value, i->value_len); memcpy(val, i->value, i->value_len);
return 0; return 0;
} }
...@@ -593,12 +593,12 @@ ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s) ...@@ -593,12 +593,12 @@ ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s)
last->e_value_size && o < offs) last->e_value_size && o < offs)
last->e_value_offs = last->e_value_offs =
cpu_to_le16(o + size); cpu_to_le16(o + size);
last = EXT3_XATTR_NEXT(last); last = EXT4_XATTR_NEXT(last);
} }
} }
if (!i->value) { if (!i->value) {
/* Remove the old name. */ /* Remove the old name. */
size_t size = EXT3_XATTR_LEN(name_len); size_t size = EXT4_XATTR_LEN(name_len);
last = ENTRY((void *)last - size); last = ENTRY((void *)last - size);
memmove(s->here, (void *)s->here + size, memmove(s->here, (void *)s->here + size,
(void *)last - (void *)s->here + sizeof(__u32)); (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,25 +610,25 @@ ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s)
/* Insert the new value. */ /* Insert the new value. */
s->here->e_value_size = cpu_to_le32(i->value_len); s->here->e_value_size = cpu_to_le32(i->value_len);
if (i->value_len) { if (i->value_len) {
size_t size = EXT3_XATTR_SIZE(i->value_len); size_t size = EXT4_XATTR_SIZE(i->value_len);
void *val = s->base + min_offs - size; void *val = s->base + min_offs - size;
s->here->e_value_offs = cpu_to_le16(min_offs - size); s->here->e_value_offs = cpu_to_le16(min_offs - size);
memset(val + size - EXT3_XATTR_PAD, 0, memset(val + size - EXT4_XATTR_PAD, 0,
EXT3_XATTR_PAD); /* Clear the pad bytes. */ EXT4_XATTR_PAD); /* Clear the pad bytes. */
memcpy(val, i->value, i->value_len); memcpy(val, i->value, i->value_len);
} }
} }
return 0; return 0;
} }
struct ext3_xattr_block_find { struct ext4_xattr_block_find {
struct ext3_xattr_search s; struct ext4_xattr_search s;
struct buffer_head *bh; struct buffer_head *bh;
}; };
static int static int
ext3_xattr_block_find(struct inode *inode, struct ext3_xattr_info *i, ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i,
struct ext3_xattr_block_find *bs) struct ext4_xattr_block_find *bs)
{ {
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
int error; int error;
...@@ -636,19 +636,19 @@ ext3_xattr_block_find(struct inode *inode, struct ext3_xattr_info *i, ...@@ -636,19 +636,19 @@ ext3_xattr_block_find(struct inode *inode, struct ext3_xattr_info *i,
ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld", ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
i->name_index, i->name, i->value, (long)i->value_len); i->name_index, i->name, i->value, (long)i->value_len);
if (EXT3_I(inode)->i_file_acl) { if (EXT4_I(inode)->i_file_acl) {
/* The inode already has an extended attribute block. */ /* The inode already has an extended attribute block. */
bs->bh = sb_bread(sb, EXT3_I(inode)->i_file_acl); bs->bh = sb_bread(sb, EXT4_I(inode)->i_file_acl);
error = -EIO; error = -EIO;
if (!bs->bh) if (!bs->bh)
goto cleanup; goto cleanup;
ea_bdebug(bs->bh, "b_count=%d, refcount=%d", ea_bdebug(bs->bh, "b_count=%d, refcount=%d",
atomic_read(&(bs->bh->b_count)), atomic_read(&(bs->bh->b_count)),
le32_to_cpu(BHDR(bs->bh)->h_refcount)); le32_to_cpu(BHDR(bs->bh)->h_refcount));
if (ext3_xattr_check_block(bs->bh)) { if (ext4_xattr_check_block(bs->bh)) {
ext3_error(sb, __FUNCTION__, ext4_error(sb, __FUNCTION__,
"inode %lu: bad block "E3FSBLK, inode->i_ino, "inode %lu: bad block "E3FSBLK, inode->i_ino,
EXT3_I(inode)->i_file_acl); EXT4_I(inode)->i_file_acl);
error = -EIO; error = -EIO;
goto cleanup; goto cleanup;
} }
...@@ -657,7 +657,7 @@ ext3_xattr_block_find(struct inode *inode, struct ext3_xattr_info *i, ...@@ -657,7 +657,7 @@ ext3_xattr_block_find(struct inode *inode, struct ext3_xattr_info *i,
bs->s.first = BFIRST(bs->bh); bs->s.first = BFIRST(bs->bh);
bs->s.end = bs->bh->b_data + bs->bh->b_size; bs->s.end = bs->bh->b_data + bs->bh->b_size;
bs->s.here = bs->s.first; bs->s.here = bs->s.first;
error = ext3_xattr_find_entry(&bs->s.here, i->name_index, error = ext4_xattr_find_entry(&bs->s.here, i->name_index,
i->name, bs->bh->b_size, 1); i->name, bs->bh->b_size, 1);
if (error && error != -ENODATA) if (error && error != -ENODATA)
goto cleanup; goto cleanup;
...@@ -670,22 +670,22 @@ ext3_xattr_block_find(struct inode *inode, struct ext3_xattr_info *i, ...@@ -670,22 +670,22 @@ ext3_xattr_block_find(struct inode *inode, struct ext3_xattr_info *i,
} }
static int static int
ext3_xattr_block_set(handle_t *handle, struct inode *inode, ext4_xattr_block_set(handle_t *handle, struct inode *inode,
struct ext3_xattr_info *i, struct ext4_xattr_info *i,
struct ext3_xattr_block_find *bs) struct ext4_xattr_block_find *bs)
{ {
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
struct buffer_head *new_bh = NULL; struct buffer_head *new_bh = NULL;
struct ext3_xattr_search *s = &bs->s; struct ext4_xattr_search *s = &bs->s;
struct mb_cache_entry *ce = NULL; struct mb_cache_entry *ce = NULL;
int error; int error;
#define header(x) ((struct ext3_xattr_header *)(x)) #define header(x) ((struct ext4_xattr_header *)(x))
if (i->value && i->value_len > sb->s_blocksize) if (i->value && i->value_len > sb->s_blocksize)
return -ENOSPC; return -ENOSPC;
if (s->base) { if (s->base) {
ce = mb_cache_entry_get(ext3_xattr_cache, bs->bh->b_bdev, ce = mb_cache_entry_get(ext4_xattr_cache, bs->bh->b_bdev,
bs->bh->b_blocknr); bs->bh->b_blocknr);
if (header(s->base)->h_refcount == cpu_to_le32(1)) { if (header(s->base)->h_refcount == cpu_to_le32(1)) {
if (ce) { if (ce) {
...@@ -693,22 +693,22 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode, ...@@ -693,22 +693,22 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
ce = NULL; ce = NULL;
} }
ea_bdebug(bs->bh, "modifying in-place"); ea_bdebug(bs->bh, "modifying in-place");
error = ext3_journal_get_write_access(handle, bs->bh); error = ext4_journal_get_write_access(handle, bs->bh);
if (error) if (error)
goto cleanup; goto cleanup;
lock_buffer(bs->bh); lock_buffer(bs->bh);
error = ext3_xattr_set_entry(i, s); error = ext4_xattr_set_entry(i, s);
if (!error) { if (!error) {
if (!IS_LAST_ENTRY(s->first)) if (!IS_LAST_ENTRY(s->first))
ext3_xattr_rehash(header(s->base), ext4_xattr_rehash(header(s->base),
s->here); s->here);
ext3_xattr_cache_insert(bs->bh); ext4_xattr_cache_insert(bs->bh);
} }
unlock_buffer(bs->bh); unlock_buffer(bs->bh);
if (error == -EIO) if (error == -EIO)
goto bad_block; goto bad_block;
if (!error) if (!error)
error = ext3_journal_dirty_metadata(handle, error = ext4_journal_dirty_metadata(handle,
bs->bh); bs->bh);
if (error) if (error)
goto cleanup; goto cleanup;
...@@ -739,7 +739,7 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode, ...@@ -739,7 +739,7 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
if (s->base == NULL) if (s->base == NULL)
goto cleanup; goto cleanup;
memset(s->base, 0, sb->s_blocksize); memset(s->base, 0, sb->s_blocksize);
header(s->base)->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC); header(s->base)->h_magic = cpu_to_le32(EXT4_XATTR_MAGIC);
header(s->base)->h_blocks = cpu_to_le32(1); header(s->base)->h_blocks = cpu_to_le32(1);
header(s->base)->h_refcount = cpu_to_le32(1); header(s->base)->h_refcount = cpu_to_le32(1);
s->first = ENTRY(header(s->base)+1); s->first = ENTRY(header(s->base)+1);
...@@ -747,17 +747,17 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode, ...@@ -747,17 +747,17 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
s->end = s->base + sb->s_blocksize; s->end = s->base + sb->s_blocksize;
} }
error = ext3_xattr_set_entry(i, s); error = ext4_xattr_set_entry(i, s);
if (error == -EIO) if (error == -EIO)
goto bad_block; goto bad_block;
if (error) if (error)
goto cleanup; goto cleanup;
if (!IS_LAST_ENTRY(s->first)) if (!IS_LAST_ENTRY(s->first))
ext3_xattr_rehash(header(s->base), s->here); ext4_xattr_rehash(header(s->base), s->here);
inserted: inserted:
if (!IS_LAST_ENTRY(s->first)) { if (!IS_LAST_ENTRY(s->first)) {
new_bh = ext3_xattr_cache_find(inode, header(s->base), &ce); new_bh = ext4_xattr_cache_find(inode, header(s->base), &ce);
if (new_bh) { if (new_bh) {
/* We found an identical block in the cache. */ /* We found an identical block in the cache. */
if (new_bh == bs->bh) if (new_bh == bs->bh)
...@@ -768,7 +768,7 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode, ...@@ -768,7 +768,7 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
error = -EDQUOT; error = -EDQUOT;
if (DQUOT_ALLOC_BLOCK(inode, 1)) if (DQUOT_ALLOC_BLOCK(inode, 1))
goto cleanup; goto cleanup;
error = ext3_journal_get_write_access(handle, error = ext4_journal_get_write_access(handle,
new_bh); new_bh);
if (error) if (error)
goto cleanup_dquot; goto cleanup_dquot;
...@@ -778,7 +778,7 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode, ...@@ -778,7 +778,7 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
ea_bdebug(new_bh, "reusing; refcount now=%d", ea_bdebug(new_bh, "reusing; refcount now=%d",
le32_to_cpu(BHDR(new_bh)->h_refcount)); le32_to_cpu(BHDR(new_bh)->h_refcount));
unlock_buffer(new_bh); unlock_buffer(new_bh);
error = ext3_journal_dirty_metadata(handle, error = ext4_journal_dirty_metadata(handle,
new_bh); new_bh);
if (error) if (error)
goto cleanup_dquot; goto cleanup_dquot;
...@@ -792,11 +792,11 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode, ...@@ -792,11 +792,11 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
get_bh(new_bh); get_bh(new_bh);
} else { } else {
/* We need to allocate a new block */ /* We need to allocate a new block */
ext3_fsblk_t goal = le32_to_cpu( ext4_fsblk_t goal = le32_to_cpu(
EXT3_SB(sb)->s_es->s_first_data_block) + EXT4_SB(sb)->s_es->s_first_data_block) +
(ext3_fsblk_t)EXT3_I(inode)->i_block_group * (ext4_fsblk_t)EXT4_I(inode)->i_block_group *
EXT3_BLOCKS_PER_GROUP(sb); EXT4_BLOCKS_PER_GROUP(sb);
ext3_fsblk_t block = ext3_new_block(handle, inode, ext4_fsblk_t block = ext4_new_block(handle, inode,
goal, &error); goal, &error);
if (error) if (error)
goto cleanup; goto cleanup;
...@@ -805,12 +805,12 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode, ...@@ -805,12 +805,12 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
new_bh = sb_getblk(sb, block); new_bh = sb_getblk(sb, block);
if (!new_bh) { if (!new_bh) {
getblk_failed: getblk_failed:
ext3_free_blocks(handle, inode, block, 1); ext4_free_blocks(handle, inode, block, 1);
error = -EIO; error = -EIO;
goto cleanup; goto cleanup;
} }
lock_buffer(new_bh); lock_buffer(new_bh);
error = ext3_journal_get_create_access(handle, new_bh); error = ext4_journal_get_create_access(handle, new_bh);
if (error) { if (error) {
unlock_buffer(new_bh); unlock_buffer(new_bh);
goto getblk_failed; goto getblk_failed;
...@@ -818,19 +818,19 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode, ...@@ -818,19 +818,19 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
memcpy(new_bh->b_data, s->base, new_bh->b_size); memcpy(new_bh->b_data, s->base, new_bh->b_size);
set_buffer_uptodate(new_bh); set_buffer_uptodate(new_bh);
unlock_buffer(new_bh); unlock_buffer(new_bh);
ext3_xattr_cache_insert(new_bh); ext4_xattr_cache_insert(new_bh);
error = ext3_journal_dirty_metadata(handle, new_bh); error = ext4_journal_dirty_metadata(handle, new_bh);
if (error) if (error)
goto cleanup; goto cleanup;
} }
} }
/* Update the inode. */ /* Update the inode. */
EXT3_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0; EXT4_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
/* Drop the previous xattr block. */ /* Drop the previous xattr block. */
if (bs->bh && bs->bh != new_bh) if (bs->bh && bs->bh != new_bh)
ext3_xattr_release_block(handle, inode, bs->bh); ext4_xattr_release_block(handle, inode, bs->bh);
error = 0; error = 0;
cleanup: cleanup:
...@@ -847,40 +847,40 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode, ...@@ -847,40 +847,40 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
goto cleanup; goto cleanup;
bad_block: bad_block:
ext3_error(inode->i_sb, __FUNCTION__, ext4_error(inode->i_sb, __FUNCTION__,
"inode %lu: bad block "E3FSBLK, inode->i_ino, "inode %lu: bad block "E3FSBLK, inode->i_ino,
EXT3_I(inode)->i_file_acl); EXT4_I(inode)->i_file_acl);
goto cleanup; goto cleanup;
#undef header #undef header
} }
struct ext3_xattr_ibody_find { struct ext4_xattr_ibody_find {
struct ext3_xattr_search s; struct ext4_xattr_search s;
struct ext3_iloc iloc; struct ext4_iloc iloc;
}; };
static int static int
ext3_xattr_ibody_find(struct inode *inode, struct ext3_xattr_info *i, ext4_xattr_ibody_find(struct inode *inode, struct ext4_xattr_info *i,
struct ext3_xattr_ibody_find *is) struct ext4_xattr_ibody_find *is)
{ {
struct ext3_xattr_ibody_header *header; struct ext4_xattr_ibody_header *header;
struct ext3_inode *raw_inode; struct ext4_inode *raw_inode;
int error; int error;
if (EXT3_I(inode)->i_extra_isize == 0) if (EXT4_I(inode)->i_extra_isize == 0)
return 0; return 0;
raw_inode = ext3_raw_inode(&is->iloc); raw_inode = ext4_raw_inode(&is->iloc);
header = IHDR(inode, raw_inode); header = IHDR(inode, raw_inode);
is->s.base = is->s.first = IFIRST(header); is->s.base = is->s.first = IFIRST(header);
is->s.here = is->s.first; is->s.here = is->s.first;
is->s.end = (void *)raw_inode + EXT3_SB(inode->i_sb)->s_inode_size; is->s.end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size;
if (EXT3_I(inode)->i_state & EXT3_STATE_XATTR) { if (EXT4_I(inode)->i_state & EXT4_STATE_XATTR) {
error = ext3_xattr_check_names(IFIRST(header), is->s.end); error = ext4_xattr_check_names(IFIRST(header), is->s.end);
if (error) if (error)
return error; return error;
/* Find the named attribute. */ /* Find the named attribute. */
error = ext3_xattr_find_entry(&is->s.here, i->name_index, error = ext4_xattr_find_entry(&is->s.here, i->name_index,
i->name, is->s.end - i->name, is->s.end -
(void *)is->s.base, 0); (void *)is->s.base, 0);
if (error && error != -ENODATA) if (error && error != -ENODATA)
...@@ -891,32 +891,32 @@ ext3_xattr_ibody_find(struct inode *inode, struct ext3_xattr_info *i, ...@@ -891,32 +891,32 @@ ext3_xattr_ibody_find(struct inode *inode, struct ext3_xattr_info *i,
} }
static int static int
ext3_xattr_ibody_set(handle_t *handle, struct inode *inode, ext4_xattr_ibody_set(handle_t *handle, struct inode *inode,
struct ext3_xattr_info *i, struct ext4_xattr_info *i,
struct ext3_xattr_ibody_find *is) struct ext4_xattr_ibody_find *is)
{ {
struct ext3_xattr_ibody_header *header; struct ext4_xattr_ibody_header *header;
struct ext3_xattr_search *s = &is->s; struct ext4_xattr_search *s = &is->s;
int error; int error;
if (EXT3_I(inode)->i_extra_isize == 0) if (EXT4_I(inode)->i_extra_isize == 0)
return -ENOSPC; return -ENOSPC;
error = ext3_xattr_set_entry(i, s); error = ext4_xattr_set_entry(i, s);
if (error) if (error)
return error; return error;
header = IHDR(inode, ext3_raw_inode(&is->iloc)); header = IHDR(inode, ext4_raw_inode(&is->iloc));
if (!IS_LAST_ENTRY(s->first)) { if (!IS_LAST_ENTRY(s->first)) {
header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC); header->h_magic = cpu_to_le32(EXT4_XATTR_MAGIC);
EXT3_I(inode)->i_state |= EXT3_STATE_XATTR; EXT4_I(inode)->i_state |= EXT4_STATE_XATTR;
} else { } else {
header->h_magic = cpu_to_le32(0); header->h_magic = cpu_to_le32(0);
EXT3_I(inode)->i_state &= ~EXT3_STATE_XATTR; EXT4_I(inode)->i_state &= ~EXT4_STATE_XATTR;
} }
return 0; return 0;
} }
/* /*
* ext3_xattr_set_handle() * ext4_xattr_set_handle()
* *
* Create, replace or remove an extended attribute for this inode. Buffer * Create, replace or remove an extended attribute for this inode. Buffer
* is NULL to remove an existing extended attribute, and non-NULL to * 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,21 +928,21 @@ ext3_xattr_ibody_set(handle_t *handle, struct inode *inode,
* Returns 0, or a negative error number on failure. * Returns 0, or a negative error number on failure.
*/ */
int int
ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index, ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
const char *name, const void *value, size_t value_len, const char *name, const void *value, size_t value_len,
int flags) int flags)
{ {
struct ext3_xattr_info i = { struct ext4_xattr_info i = {
.name_index = name_index, .name_index = name_index,
.name = name, .name = name,
.value = value, .value = value,
.value_len = value_len, .value_len = value_len,
}; };
struct ext3_xattr_ibody_find is = { struct ext4_xattr_ibody_find is = {
.s = { .not_found = -ENODATA, }, .s = { .not_found = -ENODATA, },
}; };
struct ext3_xattr_block_find bs = { struct ext4_xattr_block_find bs = {
.s = { .not_found = -ENODATA, }, .s = { .not_found = -ENODATA, },
}; };
int error; int error;
...@@ -951,22 +951,22 @@ ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index, ...@@ -951,22 +951,22 @@ ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
return -EINVAL; return -EINVAL;
if (strlen(name) > 255) if (strlen(name) > 255)
return -ERANGE; return -ERANGE;
down_write(&EXT3_I(inode)->xattr_sem); down_write(&EXT4_I(inode)->xattr_sem);
error = ext3_get_inode_loc(inode, &is.iloc); error = ext4_get_inode_loc(inode, &is.iloc);
if (error) if (error)
goto cleanup; goto cleanup;
if (EXT3_I(inode)->i_state & EXT3_STATE_NEW) { if (EXT4_I(inode)->i_state & EXT4_STATE_NEW) {
struct ext3_inode *raw_inode = ext3_raw_inode(&is.iloc); struct ext4_inode *raw_inode = ext4_raw_inode(&is.iloc);
memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size); memset(raw_inode, 0, EXT4_SB(inode->i_sb)->s_inode_size);
EXT3_I(inode)->i_state &= ~EXT3_STATE_NEW; EXT4_I(inode)->i_state &= ~EXT4_STATE_NEW;
} }
error = ext3_xattr_ibody_find(inode, &i, &is); error = ext4_xattr_ibody_find(inode, &i, &is);
if (error) if (error)
goto cleanup; goto cleanup;
if (is.s.not_found) if (is.s.not_found)
error = ext3_xattr_block_find(inode, &i, &bs); error = ext4_xattr_block_find(inode, &i, &bs);
if (error) if (error)
goto cleanup; goto cleanup;
if (is.s.not_found && bs.s.not_found) { 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,36 +981,36 @@ ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
if (flags & XATTR_CREATE) if (flags & XATTR_CREATE)
goto cleanup; goto cleanup;
} }
error = ext3_journal_get_write_access(handle, is.iloc.bh); error = ext4_journal_get_write_access(handle, is.iloc.bh);
if (error) if (error)
goto cleanup; goto cleanup;
if (!value) { if (!value) {
if (!is.s.not_found) if (!is.s.not_found)
error = ext3_xattr_ibody_set(handle, inode, &i, &is); error = ext4_xattr_ibody_set(handle, inode, &i, &is);
else if (!bs.s.not_found) else if (!bs.s.not_found)
error = ext3_xattr_block_set(handle, inode, &i, &bs); error = ext4_xattr_block_set(handle, inode, &i, &bs);
} else { } else {
error = ext3_xattr_ibody_set(handle, inode, &i, &is); error = ext4_xattr_ibody_set(handle, inode, &i, &is);
if (!error && !bs.s.not_found) { if (!error && !bs.s.not_found) {
i.value = NULL; i.value = NULL;
error = ext3_xattr_block_set(handle, inode, &i, &bs); error = ext4_xattr_block_set(handle, inode, &i, &bs);
} else if (error == -ENOSPC) { } else if (error == -ENOSPC) {
error = ext3_xattr_block_set(handle, inode, &i, &bs); error = ext4_xattr_block_set(handle, inode, &i, &bs);
if (error) if (error)
goto cleanup; goto cleanup;
if (!is.s.not_found) { if (!is.s.not_found) {
i.value = NULL; i.value = NULL;
error = ext3_xattr_ibody_set(handle, inode, &i, error = ext4_xattr_ibody_set(handle, inode, &i,
&is); &is);
} }
} }
} }
if (!error) { if (!error) {
ext3_xattr_update_super_block(handle, inode->i_sb); ext4_xattr_update_super_block(handle, inode->i_sb);
inode->i_ctime = CURRENT_TIME_SEC; inode->i_ctime = CURRENT_TIME_SEC;
error = ext3_mark_iloc_dirty(handle, inode, &is.iloc); error = ext4_mark_iloc_dirty(handle, inode, &is.iloc);
/* /*
* The bh is consumed by ext3_mark_iloc_dirty, even with * The bh is consumed by ext4_mark_iloc_dirty, even with
* error != 0. * error != 0.
*/ */
is.iloc.bh = NULL; is.iloc.bh = NULL;
...@@ -1021,37 +1021,37 @@ ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index, ...@@ -1021,37 +1021,37 @@ ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
cleanup: cleanup:
brelse(is.iloc.bh); brelse(is.iloc.bh);
brelse(bs.bh); brelse(bs.bh);
up_write(&EXT3_I(inode)->xattr_sem); up_write(&EXT4_I(inode)->xattr_sem);
return error; return error;
} }
/* /*
* ext3_xattr_set() * ext4_xattr_set()
* *
* Like ext3_xattr_set_handle, but start from an inode. This extended * Like ext4_xattr_set_handle, but start from an inode. This extended
* attribute modification is a filesystem transaction by itself. * attribute modification is a filesystem transaction by itself.
* *
* Returns 0, or a negative error number on failure. * Returns 0, or a negative error number on failure.
*/ */
int int
ext3_xattr_set(struct inode *inode, int name_index, const char *name, ext4_xattr_set(struct inode *inode, int name_index, const char *name,
const void *value, size_t value_len, int flags) const void *value, size_t value_len, int flags)
{ {
handle_t *handle; handle_t *handle;
int error, retries = 0; int error, retries = 0;
retry: retry:
handle = ext3_journal_start(inode, EXT3_DATA_TRANS_BLOCKS(inode->i_sb)); handle = ext4_journal_start(inode, EXT4_DATA_TRANS_BLOCKS(inode->i_sb));
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
error = PTR_ERR(handle); error = PTR_ERR(handle);
} else { } else {
int error2; int error2;
error = ext3_xattr_set_handle(handle, inode, name_index, name, error = ext4_xattr_set_handle(handle, inode, name_index, name,
value, value_len, flags); value, value_len, flags);
error2 = ext3_journal_stop(handle); error2 = ext4_journal_stop(handle);
if (error == -ENOSPC && if (error == -ENOSPC &&
ext3_should_retry_alloc(inode->i_sb, &retries)) ext4_should_retry_alloc(inode->i_sb, &retries))
goto retry; goto retry;
if (error == 0) if (error == 0)
error = error2; error = error2;
...@@ -1061,53 +1061,53 @@ ext3_xattr_set(struct inode *inode, int name_index, const char *name, ...@@ -1061,53 +1061,53 @@ ext3_xattr_set(struct inode *inode, int name_index, const char *name,
} }
/* /*
* ext3_xattr_delete_inode() * ext4_xattr_delete_inode()
* *
* Free extended attribute resources associated with this inode. This * Free extended attribute resources associated with this inode. This
* is called immediately before an inode is freed. We have exclusive * is called immediately before an inode is freed. We have exclusive
* access to the inode. * access to the inode.
*/ */
void void
ext3_xattr_delete_inode(handle_t *handle, struct inode *inode) ext4_xattr_delete_inode(handle_t *handle, struct inode *inode)
{ {
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
if (!EXT3_I(inode)->i_file_acl) if (!EXT4_I(inode)->i_file_acl)
goto cleanup; goto cleanup;
bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl); bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
if (!bh) { if (!bh) {
ext3_error(inode->i_sb, __FUNCTION__, ext4_error(inode->i_sb, __FUNCTION__,
"inode %lu: block "E3FSBLK" read error", inode->i_ino, "inode %lu: block "E3FSBLK" read error", inode->i_ino,
EXT3_I(inode)->i_file_acl); EXT4_I(inode)->i_file_acl);
goto cleanup; goto cleanup;
} }
if (BHDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) || if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
BHDR(bh)->h_blocks != cpu_to_le32(1)) { BHDR(bh)->h_blocks != cpu_to_le32(1)) {
ext3_error(inode->i_sb, __FUNCTION__, ext4_error(inode->i_sb, __FUNCTION__,
"inode %lu: bad block "E3FSBLK, inode->i_ino, "inode %lu: bad block "E3FSBLK, inode->i_ino,
EXT3_I(inode)->i_file_acl); EXT4_I(inode)->i_file_acl);
goto cleanup; goto cleanup;
} }
ext3_xattr_release_block(handle, inode, bh); ext4_xattr_release_block(handle, inode, bh);
EXT3_I(inode)->i_file_acl = 0; EXT4_I(inode)->i_file_acl = 0;
cleanup: cleanup:
brelse(bh); brelse(bh);
} }
/* /*
* ext3_xattr_put_super() * ext4_xattr_put_super()
* *
* This is called when a file system is unmounted. * This is called when a file system is unmounted.
*/ */
void void
ext3_xattr_put_super(struct super_block *sb) ext4_xattr_put_super(struct super_block *sb)
{ {
mb_cache_shrink(sb->s_bdev); mb_cache_shrink(sb->s_bdev);
} }
/* /*
* ext3_xattr_cache_insert() * ext4_xattr_cache_insert()
* *
* Create a new entry in the extended attribute cache, and insert * Create a new entry in the extended attribute cache, and insert
* it unless such an entry is already in the cache. * it unless such an entry is already in the cache.
...@@ -1115,13 +1115,13 @@ ext3_xattr_put_super(struct super_block *sb) ...@@ -1115,13 +1115,13 @@ ext3_xattr_put_super(struct super_block *sb)
* Returns 0, or a negative error number on failure. * Returns 0, or a negative error number on failure.
*/ */
static void static void
ext3_xattr_cache_insert(struct buffer_head *bh) ext4_xattr_cache_insert(struct buffer_head *bh)
{ {
__u32 hash = le32_to_cpu(BHDR(bh)->h_hash); __u32 hash = le32_to_cpu(BHDR(bh)->h_hash);
struct mb_cache_entry *ce; struct mb_cache_entry *ce;
int error; int error;
ce = mb_cache_entry_alloc(ext3_xattr_cache); ce = mb_cache_entry_alloc(ext4_xattr_cache);
if (!ce) { if (!ce) {
ea_bdebug(bh, "out of memory"); ea_bdebug(bh, "out of memory");
return; return;
...@@ -1140,7 +1140,7 @@ ext3_xattr_cache_insert(struct buffer_head *bh) ...@@ -1140,7 +1140,7 @@ ext3_xattr_cache_insert(struct buffer_head *bh)
} }
/* /*
* ext3_xattr_cmp() * ext4_xattr_cmp()
* *
* Compare two extended attribute blocks for equality. * Compare two extended attribute blocks for equality.
* *
...@@ -1148,10 +1148,10 @@ ext3_xattr_cache_insert(struct buffer_head *bh) ...@@ -1148,10 +1148,10 @@ ext3_xattr_cache_insert(struct buffer_head *bh)
* a negative error number on errors. * a negative error number on errors.
*/ */
static int static int
ext3_xattr_cmp(struct ext3_xattr_header *header1, ext4_xattr_cmp(struct ext4_xattr_header *header1,
struct ext3_xattr_header *header2) struct ext4_xattr_header *header2)
{ {
struct ext3_xattr_entry *entry1, *entry2; struct ext4_xattr_entry *entry1, *entry2;
entry1 = ENTRY(header1+1); entry1 = ENTRY(header1+1);
entry2 = ENTRY(header2+1); entry2 = ENTRY(header2+1);
...@@ -1171,8 +1171,8 @@ ext3_xattr_cmp(struct ext3_xattr_header *header1, ...@@ -1171,8 +1171,8 @@ ext3_xattr_cmp(struct ext3_xattr_header *header1,
le32_to_cpu(entry1->e_value_size))) le32_to_cpu(entry1->e_value_size)))
return 1; return 1;
entry1 = EXT3_XATTR_NEXT(entry1); entry1 = EXT4_XATTR_NEXT(entry1);
entry2 = EXT3_XATTR_NEXT(entry2); entry2 = EXT4_XATTR_NEXT(entry2);
} }
if (!IS_LAST_ENTRY(entry2)) if (!IS_LAST_ENTRY(entry2))
return 1; return 1;
...@@ -1180,7 +1180,7 @@ ext3_xattr_cmp(struct ext3_xattr_header *header1, ...@@ -1180,7 +1180,7 @@ ext3_xattr_cmp(struct ext3_xattr_header *header1,
} }
/* /*
* ext3_xattr_cache_find() * ext4_xattr_cache_find()
* *
* Find an identical extended attribute block. * Find an identical extended attribute block.
* *
...@@ -1188,7 +1188,7 @@ ext3_xattr_cmp(struct ext3_xattr_header *header1, ...@@ -1188,7 +1188,7 @@ ext3_xattr_cmp(struct ext3_xattr_header *header1,
* not found or an error occurred. * not found or an error occurred.
*/ */
static struct buffer_head * static struct buffer_head *
ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header, ext4_xattr_cache_find(struct inode *inode, struct ext4_xattr_header *header,
struct mb_cache_entry **pce) struct mb_cache_entry **pce)
{ {
__u32 hash = le32_to_cpu(header->h_hash); __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,7 +1198,7 @@ ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header,
return NULL; /* never share */ return NULL; /* never share */
ea_idebug(inode, "looking for cached blocks [%x]", (int)hash); ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
again: again:
ce = mb_cache_entry_find_first(ext3_xattr_cache, 0, ce = mb_cache_entry_find_first(ext4_xattr_cache, 0,
inode->i_sb->s_bdev, hash); inode->i_sb->s_bdev, hash);
while (ce) { while (ce) {
struct buffer_head *bh; struct buffer_head *bh;
...@@ -1210,16 +1210,16 @@ ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header, ...@@ -1210,16 +1210,16 @@ ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header,
} }
bh = sb_bread(inode->i_sb, ce->e_block); bh = sb_bread(inode->i_sb, ce->e_block);
if (!bh) { if (!bh) {
ext3_error(inode->i_sb, __FUNCTION__, ext4_error(inode->i_sb, __FUNCTION__,
"inode %lu: block %lu read error", "inode %lu: block %lu read error",
inode->i_ino, (unsigned long) ce->e_block); inode->i_ino, (unsigned long) ce->e_block);
} else if (le32_to_cpu(BHDR(bh)->h_refcount) >= } else if (le32_to_cpu(BHDR(bh)->h_refcount) >=
EXT3_XATTR_REFCOUNT_MAX) { EXT4_XATTR_REFCOUNT_MAX) {
ea_idebug(inode, "block %lu refcount %d>=%d", ea_idebug(inode, "block %lu refcount %d>=%d",
(unsigned long) ce->e_block, (unsigned long) ce->e_block,
le32_to_cpu(BHDR(bh)->h_refcount), le32_to_cpu(BHDR(bh)->h_refcount),
EXT3_XATTR_REFCOUNT_MAX); EXT4_XATTR_REFCOUNT_MAX);
} else if (ext3_xattr_cmp(header, BHDR(bh)) == 0) { } else if (ext4_xattr_cmp(header, BHDR(bh)) == 0) {
*pce = ce; *pce = ce;
return bh; return bh;
} }
...@@ -1233,12 +1233,12 @@ ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header, ...@@ -1233,12 +1233,12 @@ ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header,
#define VALUE_HASH_SHIFT 16 #define VALUE_HASH_SHIFT 16
/* /*
* ext3_xattr_hash_entry() * ext4_xattr_hash_entry()
* *
* Compute the hash of an extended attribute. * Compute the hash of an extended attribute.
*/ */
static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header, static inline void ext4_xattr_hash_entry(struct ext4_xattr_header *header,
struct ext3_xattr_entry *entry) struct ext4_xattr_entry *entry)
{ {
__u32 hash = 0; __u32 hash = 0;
char *name = entry->e_name; char *name = entry->e_name;
...@@ -1254,7 +1254,7 @@ static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header, ...@@ -1254,7 +1254,7 @@ static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
__le32 *value = (__le32 *)((char *)header + __le32 *value = (__le32 *)((char *)header +
le16_to_cpu(entry->e_value_offs)); le16_to_cpu(entry->e_value_offs));
for (n = (le32_to_cpu(entry->e_value_size) + for (n = (le32_to_cpu(entry->e_value_size) +
EXT3_XATTR_ROUND) >> EXT3_XATTR_PAD_BITS; n; n--) { EXT4_XATTR_ROUND) >> EXT4_XATTR_PAD_BITS; n; n--) {
hash = (hash << VALUE_HASH_SHIFT) ^ hash = (hash << VALUE_HASH_SHIFT) ^
(hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^ (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
le32_to_cpu(*value++); le32_to_cpu(*value++);
...@@ -1269,17 +1269,17 @@ static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header, ...@@ -1269,17 +1269,17 @@ static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
#define BLOCK_HASH_SHIFT 16 #define BLOCK_HASH_SHIFT 16
/* /*
* ext3_xattr_rehash() * ext4_xattr_rehash()
* *
* Re-compute the extended attribute hash value after an entry has changed. * Re-compute the extended attribute hash value after an entry has changed.
*/ */
static void ext3_xattr_rehash(struct ext3_xattr_header *header, static void ext4_xattr_rehash(struct ext4_xattr_header *header,
struct ext3_xattr_entry *entry) struct ext4_xattr_entry *entry)
{ {
struct ext3_xattr_entry *here; struct ext4_xattr_entry *here;
__u32 hash = 0; __u32 hash = 0;
ext3_xattr_hash_entry(header, entry); ext4_xattr_hash_entry(header, entry);
here = ENTRY(header+1); here = ENTRY(header+1);
while (!IS_LAST_ENTRY(here)) { while (!IS_LAST_ENTRY(here)) {
if (!here->e_hash) { if (!here->e_hash) {
...@@ -1290,7 +1290,7 @@ static void ext3_xattr_rehash(struct ext3_xattr_header *header, ...@@ -1290,7 +1290,7 @@ static void ext3_xattr_rehash(struct ext3_xattr_header *header,
hash = (hash << BLOCK_HASH_SHIFT) ^ hash = (hash << BLOCK_HASH_SHIFT) ^
(hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^ (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
le32_to_cpu(here->e_hash); le32_to_cpu(here->e_hash);
here = EXT3_XATTR_NEXT(here); here = EXT4_XATTR_NEXT(here);
} }
header->h_hash = cpu_to_le32(hash); header->h_hash = cpu_to_le32(hash);
} }
...@@ -1298,20 +1298,20 @@ static void ext3_xattr_rehash(struct ext3_xattr_header *header, ...@@ -1298,20 +1298,20 @@ static void ext3_xattr_rehash(struct ext3_xattr_header *header,
#undef BLOCK_HASH_SHIFT #undef BLOCK_HASH_SHIFT
int __init int __init
init_ext3_xattr(void) init_ext4_xattr(void)
{ {
ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL, ext4_xattr_cache = mb_cache_create("ext4_xattr", NULL,
sizeof(struct mb_cache_entry) + sizeof(struct mb_cache_entry) +
sizeof(((struct mb_cache_entry *) 0)->e_indexes[0]), 1, 6); sizeof(((struct mb_cache_entry *) 0)->e_indexes[0]), 1, 6);
if (!ext3_xattr_cache) if (!ext4_xattr_cache)
return -ENOMEM; return -ENOMEM;
return 0; return 0;
} }
void void
exit_ext3_xattr(void) exit_ext4_xattr(void)
{ {
if (ext3_xattr_cache) if (ext4_xattr_cache)
mb_cache_destroy(ext3_xattr_cache); mb_cache_destroy(ext4_xattr_cache);
ext3_xattr_cache = NULL; ext4_xattr_cache = NULL;
} }
/* /*
File: fs/ext3/xattr.h File: fs/ext4/xattr.h
On-disk format of extended attributes for the ext3 filesystem. On-disk format of extended attributes for the ext4 filesystem.
(C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org> (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
*/ */
...@@ -9,20 +9,20 @@ ...@@ -9,20 +9,20 @@
#include <linux/xattr.h> #include <linux/xattr.h>
/* Magic value in attribute blocks */ /* Magic value in attribute blocks */
#define EXT3_XATTR_MAGIC 0xEA020000 #define EXT4_XATTR_MAGIC 0xEA020000
/* Maximum number of references to one attribute block */ /* Maximum number of references to one attribute block */
#define EXT3_XATTR_REFCOUNT_MAX 1024 #define EXT4_XATTR_REFCOUNT_MAX 1024
/* Name indexes */ /* Name indexes */
#define EXT3_XATTR_INDEX_USER 1 #define EXT4_XATTR_INDEX_USER 1
#define EXT3_XATTR_INDEX_POSIX_ACL_ACCESS 2 #define EXT4_XATTR_INDEX_POSIX_ACL_ACCESS 2
#define EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT 3 #define EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT 3
#define EXT3_XATTR_INDEX_TRUSTED 4 #define EXT4_XATTR_INDEX_TRUSTED 4
#define EXT3_XATTR_INDEX_LUSTRE 5 #define EXT4_XATTR_INDEX_LUSTRE 5
#define EXT3_XATTR_INDEX_SECURITY 6 #define EXT4_XATTR_INDEX_SECURITY 6
struct ext3_xattr_header { struct ext4_xattr_header {
__le32 h_magic; /* magic number for identification */ __le32 h_magic; /* magic number for identification */
__le32 h_refcount; /* reference count */ __le32 h_refcount; /* reference count */
__le32 h_blocks; /* number of disk blocks used */ __le32 h_blocks; /* number of disk blocks used */
...@@ -30,11 +30,11 @@ struct ext3_xattr_header { ...@@ -30,11 +30,11 @@ struct ext3_xattr_header {
__u32 h_reserved[4]; /* zero right now */ __u32 h_reserved[4]; /* zero right now */
}; };
struct ext3_xattr_ibody_header { struct ext4_xattr_ibody_header {
__le32 h_magic; /* magic number for identification */ __le32 h_magic; /* magic number for identification */
}; };
struct ext3_xattr_entry { struct ext4_xattr_entry {
__u8 e_name_len; /* length of name */ __u8 e_name_len; /* length of name */
__u8 e_name_index; /* attribute name index */ __u8 e_name_index; /* attribute name index */
__le16 e_value_offs; /* offset in disk block of value */ __le16 e_value_offs; /* offset in disk block of value */
...@@ -44,100 +44,100 @@ struct ext3_xattr_entry { ...@@ -44,100 +44,100 @@ struct ext3_xattr_entry {
char e_name[0]; /* attribute name */ char e_name[0]; /* attribute name */
}; };
#define EXT3_XATTR_PAD_BITS 2 #define EXT4_XATTR_PAD_BITS 2
#define EXT3_XATTR_PAD (1<<EXT3_XATTR_PAD_BITS) #define EXT4_XATTR_PAD (1<<EXT4_XATTR_PAD_BITS)
#define EXT3_XATTR_ROUND (EXT3_XATTR_PAD-1) #define EXT4_XATTR_ROUND (EXT4_XATTR_PAD-1)
#define EXT3_XATTR_LEN(name_len) \ #define EXT4_XATTR_LEN(name_len) \
(((name_len) + EXT3_XATTR_ROUND + \ (((name_len) + EXT4_XATTR_ROUND + \
sizeof(struct ext3_xattr_entry)) & ~EXT3_XATTR_ROUND) sizeof(struct ext4_xattr_entry)) & ~EXT4_XATTR_ROUND)
#define EXT3_XATTR_NEXT(entry) \ #define EXT4_XATTR_NEXT(entry) \
( (struct ext3_xattr_entry *)( \ ( (struct ext4_xattr_entry *)( \
(char *)(entry) + EXT3_XATTR_LEN((entry)->e_name_len)) ) (char *)(entry) + EXT4_XATTR_LEN((entry)->e_name_len)) )
#define EXT3_XATTR_SIZE(size) \ #define EXT4_XATTR_SIZE(size) \
(((size) + EXT3_XATTR_ROUND) & ~EXT3_XATTR_ROUND) (((size) + EXT4_XATTR_ROUND) & ~EXT4_XATTR_ROUND)
# ifdef CONFIG_EXT3_FS_XATTR # ifdef CONFIG_EXT4DEV_FS_XATTR
extern struct xattr_handler ext3_xattr_user_handler; extern struct xattr_handler ext4_xattr_user_handler;
extern struct xattr_handler ext3_xattr_trusted_handler; extern struct xattr_handler ext4_xattr_trusted_handler;
extern struct xattr_handler ext3_xattr_acl_access_handler; extern struct xattr_handler ext4_xattr_acl_access_handler;
extern struct xattr_handler ext3_xattr_acl_default_handler; extern struct xattr_handler ext4_xattr_acl_default_handler;
extern struct xattr_handler ext3_xattr_security_handler; extern struct xattr_handler ext4_xattr_security_handler;
extern ssize_t ext3_listxattr(struct dentry *, char *, size_t); extern ssize_t ext4_listxattr(struct dentry *, char *, size_t);
extern int ext3_xattr_get(struct inode *, int, const char *, void *, size_t); extern int ext4_xattr_get(struct inode *, int, const char *, void *, size_t);
extern int ext3_xattr_list(struct inode *, char *, size_t); extern int ext4_xattr_list(struct inode *, char *, size_t);
extern int ext3_xattr_set(struct inode *, int, const char *, const void *, size_t, int); extern int ext4_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
extern int ext3_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int); extern int ext4_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int);
extern void ext3_xattr_delete_inode(handle_t *, struct inode *); extern void ext4_xattr_delete_inode(handle_t *, struct inode *);
extern void ext3_xattr_put_super(struct super_block *); extern void ext4_xattr_put_super(struct super_block *);
extern int init_ext3_xattr(void); extern int init_ext4_xattr(void);
extern void exit_ext3_xattr(void); extern void exit_ext4_xattr(void);
extern struct xattr_handler *ext3_xattr_handlers[]; extern struct xattr_handler *ext4_xattr_handlers[];
# else /* CONFIG_EXT3_FS_XATTR */ # else /* CONFIG_EXT4DEV_FS_XATTR */
static inline int static inline int
ext3_xattr_get(struct inode *inode, int name_index, const char *name, ext4_xattr_get(struct inode *inode, int name_index, const char *name,
void *buffer, size_t size, int flags) void *buffer, size_t size, int flags)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static inline int static inline int
ext3_xattr_list(struct inode *inode, void *buffer, size_t size) ext4_xattr_list(struct inode *inode, void *buffer, size_t size)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static inline int static inline int
ext3_xattr_set(struct inode *inode, int name_index, const char *name, ext4_xattr_set(struct inode *inode, int name_index, const char *name,
const void *value, size_t size, int flags) const void *value, size_t size, int flags)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static inline int static inline int
ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index, ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
const char *name, const void *value, size_t size, int flags) const char *name, const void *value, size_t size, int flags)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static inline void static inline void
ext3_xattr_delete_inode(handle_t *handle, struct inode *inode) ext4_xattr_delete_inode(handle_t *handle, struct inode *inode)
{ {
} }
static inline void static inline void
ext3_xattr_put_super(struct super_block *sb) ext4_xattr_put_super(struct super_block *sb)
{ {
} }
static inline int static inline int
init_ext3_xattr(void) init_ext4_xattr(void)
{ {
return 0; return 0;
} }
static inline void static inline void
exit_ext3_xattr(void) exit_ext4_xattr(void)
{ {
} }
#define ext3_xattr_handlers NULL #define ext4_xattr_handlers NULL
# endif /* CONFIG_EXT3_FS_XATTR */ # endif /* CONFIG_EXT4DEV_FS_XATTR */
#ifdef CONFIG_EXT3_FS_SECURITY #ifdef CONFIG_EXT4DEV_FS_SECURITY
extern int ext3_init_security(handle_t *handle, struct inode *inode, extern int ext4_init_security(handle_t *handle, struct inode *inode,
struct inode *dir); struct inode *dir);
#else #else
static inline int ext3_init_security(handle_t *handle, struct inode *inode, static inline int ext4_init_security(handle_t *handle, struct inode *inode,
struct inode *dir) struct inode *dir)
{ {
return 0; return 0;
......
/* /*
* linux/fs/ext3/xattr_security.c * linux/fs/ext4/xattr_security.c
* Handler for storing security labels as extended attributes. * Handler for storing security labels as extended attributes.
*/ */
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
#include <linux/string.h> #include <linux/string.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/ext3_jbd.h> #include <linux/ext4_jbd.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#include <linux/security.h> #include <linux/security.h>
#include "xattr.h" #include "xattr.h"
static size_t static size_t
ext3_xattr_security_list(struct inode *inode, char *list, size_t list_size, ext4_xattr_security_list(struct inode *inode, char *list, size_t list_size,
const char *name, size_t name_len) const char *name, size_t name_len)
{ {
const size_t prefix_len = sizeof(XATTR_SECURITY_PREFIX)-1; 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,27 +29,27 @@ ext3_xattr_security_list(struct inode *inode, char *list, size_t list_size,
} }
static int static int
ext3_xattr_security_get(struct inode *inode, const char *name, ext4_xattr_security_get(struct inode *inode, const char *name,
void *buffer, size_t size) void *buffer, size_t size)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
return ext3_xattr_get(inode, EXT3_XATTR_INDEX_SECURITY, name, return ext4_xattr_get(inode, EXT4_XATTR_INDEX_SECURITY, name,
buffer, size); buffer, size);
} }
static int static int
ext3_xattr_security_set(struct inode *inode, const char *name, ext4_xattr_security_set(struct inode *inode, const char *name,
const void *value, size_t size, int flags) const void *value, size_t size, int flags)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
return ext3_xattr_set(inode, EXT3_XATTR_INDEX_SECURITY, name, return ext4_xattr_set(inode, EXT4_XATTR_INDEX_SECURITY, name,
value, size, flags); value, size, flags);
} }
int int
ext3_init_security(handle_t *handle, struct inode *inode, struct inode *dir) ext4_init_security(handle_t *handle, struct inode *inode, struct inode *dir)
{ {
int err; int err;
size_t len; size_t len;
...@@ -62,16 +62,16 @@ ext3_init_security(handle_t *handle, struct inode *inode, struct inode *dir) ...@@ -62,16 +62,16 @@ ext3_init_security(handle_t *handle, struct inode *inode, struct inode *dir)
return 0; return 0;
return err; return err;
} }
err = ext3_xattr_set_handle(handle, inode, EXT3_XATTR_INDEX_SECURITY, err = ext4_xattr_set_handle(handle, inode, EXT4_XATTR_INDEX_SECURITY,
name, value, len, 0); name, value, len, 0);
kfree(name); kfree(name);
kfree(value); kfree(value);
return err; return err;
} }
struct xattr_handler ext3_xattr_security_handler = { struct xattr_handler ext4_xattr_security_handler = {
.prefix = XATTR_SECURITY_PREFIX, .prefix = XATTR_SECURITY_PREFIX,
.list = ext3_xattr_security_list, .list = ext4_xattr_security_list,
.get = ext3_xattr_security_get, .get = ext4_xattr_security_get,
.set = ext3_xattr_security_set, .set = ext4_xattr_security_set,
}; };
/* /*
* linux/fs/ext3/xattr_trusted.c * linux/fs/ext4/xattr_trusted.c
* Handler for trusted extended attributes. * Handler for trusted extended attributes.
* *
* Copyright (C) 2003 by Andreas Gruenbacher, <a.gruenbacher@computer.org> * Copyright (C) 2003 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
...@@ -10,14 +10,14 @@ ...@@ -10,14 +10,14 @@
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/ext3_jbd.h> #include <linux/ext4_jbd.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#include "xattr.h" #include "xattr.h"
#define XATTR_TRUSTED_PREFIX "trusted." #define XATTR_TRUSTED_PREFIX "trusted."
static size_t static size_t
ext3_xattr_trusted_list(struct inode *inode, char *list, size_t list_size, ext4_xattr_trusted_list(struct inode *inode, char *list, size_t list_size,
const char *name, size_t name_len) const char *name, size_t name_len)
{ {
const size_t prefix_len = sizeof(XATTR_TRUSTED_PREFIX)-1; 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,28 +35,28 @@ ext3_xattr_trusted_list(struct inode *inode, char *list, size_t list_size,
} }
static int static int
ext3_xattr_trusted_get(struct inode *inode, const char *name, ext4_xattr_trusted_get(struct inode *inode, const char *name,
void *buffer, size_t size) void *buffer, size_t size)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
return ext3_xattr_get(inode, EXT3_XATTR_INDEX_TRUSTED, name, return ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED, name,
buffer, size); buffer, size);
} }
static int static int
ext3_xattr_trusted_set(struct inode *inode, const char *name, ext4_xattr_trusted_set(struct inode *inode, const char *name,
const void *value, size_t size, int flags) const void *value, size_t size, int flags)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
return ext3_xattr_set(inode, EXT3_XATTR_INDEX_TRUSTED, name, return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED, name,
value, size, flags); value, size, flags);
} }
struct xattr_handler ext3_xattr_trusted_handler = { struct xattr_handler ext4_xattr_trusted_handler = {
.prefix = XATTR_TRUSTED_PREFIX, .prefix = XATTR_TRUSTED_PREFIX,
.list = ext3_xattr_trusted_list, .list = ext4_xattr_trusted_list,
.get = ext3_xattr_trusted_get, .get = ext4_xattr_trusted_get,
.set = ext3_xattr_trusted_set, .set = ext4_xattr_trusted_set,
}; };
/* /*
* linux/fs/ext3/xattr_user.c * linux/fs/ext4/xattr_user.c
* Handler for extended user attributes. * Handler for extended user attributes.
* *
* Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org> * Copyright (C) 2001 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
...@@ -9,14 +9,14 @@ ...@@ -9,14 +9,14 @@
#include <linux/string.h> #include <linux/string.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/ext3_jbd.h> #include <linux/ext4_jbd.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#include "xattr.h" #include "xattr.h"
#define XATTR_USER_PREFIX "user." #define XATTR_USER_PREFIX "user."
static size_t static size_t
ext3_xattr_user_list(struct inode *inode, char *list, size_t list_size, ext4_xattr_user_list(struct inode *inode, char *list, size_t list_size,
const char *name, size_t name_len) const char *name, size_t name_len)
{ {
const size_t prefix_len = sizeof(XATTR_USER_PREFIX)-1; 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,31 +34,31 @@ ext3_xattr_user_list(struct inode *inode, char *list, size_t list_size,
} }
static int static int
ext3_xattr_user_get(struct inode *inode, const char *name, ext4_xattr_user_get(struct inode *inode, const char *name,
void *buffer, size_t size) void *buffer, size_t size)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
if (!test_opt(inode->i_sb, XATTR_USER)) if (!test_opt(inode->i_sb, XATTR_USER))
return -EOPNOTSUPP; return -EOPNOTSUPP;
return ext3_xattr_get(inode, EXT3_XATTR_INDEX_USER, name, buffer, size); return ext4_xattr_get(inode, EXT4_XATTR_INDEX_USER, name, buffer, size);
} }
static int static int
ext3_xattr_user_set(struct inode *inode, const char *name, ext4_xattr_user_set(struct inode *inode, const char *name,
const void *value, size_t size, int flags) const void *value, size_t size, int flags)
{ {
if (strcmp(name, "") == 0) if (strcmp(name, "") == 0)
return -EINVAL; return -EINVAL;
if (!test_opt(inode->i_sb, XATTR_USER)) if (!test_opt(inode->i_sb, XATTR_USER))
return -EOPNOTSUPP; return -EOPNOTSUPP;
return ext3_xattr_set(inode, EXT3_XATTR_INDEX_USER, name, return ext4_xattr_set(inode, EXT4_XATTR_INDEX_USER, name,
value, size, flags); value, size, flags);
} }
struct xattr_handler ext3_xattr_user_handler = { struct xattr_handler ext4_xattr_user_handler = {
.prefix = XATTR_USER_PREFIX, .prefix = XATTR_USER_PREFIX,
.list = ext3_xattr_user_list, .list = ext4_xattr_user_list,
.get = ext3_xattr_user_get, .get = ext4_xattr_user_get,
.set = ext3_xattr_user_set, .set = ext4_xattr_user_set,
}; };
/* /*
* linux/include/linux/ext3_fs.h * linux/include/linux/ext4_fs.h
* *
* Copyright (C) 1992, 1993, 1994, 1995 * Copyright (C) 1992, 1993, 1994, 1995
* Remy Card (card@masi.ibp.fr) * Remy Card (card@masi.ibp.fr)
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* Copyright (C) 1991, 1992 Linus Torvalds * Copyright (C) 1991, 1992 Linus Torvalds
*/ */
#ifndef _LINUX_EXT3_FS_H #ifndef _LINUX_EXT4_FS_H
#define _LINUX_EXT3_FS_H #define _LINUX_EXT4_FS_H
#include <linux/types.h> #include <linux/types.h>
#include <linux/magic.h> #include <linux/magic.h>
...@@ -24,102 +24,102 @@ ...@@ -24,102 +24,102 @@
*/ */
/* /*
* Define EXT3FS_DEBUG to produce debug messages * Define EXT4FS_DEBUG to produce debug messages
*/ */
#undef EXT3FS_DEBUG #undef EXT4FS_DEBUG
/* /*
* Define EXT3_RESERVATION to reserve data blocks for expanding files * Define EXT4_RESERVATION to reserve data blocks for expanding files
*/ */
#define EXT3_DEFAULT_RESERVE_BLOCKS 8 #define EXT4_DEFAULT_RESERVE_BLOCKS 8
/*max window size: 1024(direct blocks) + 3([t,d]indirect blocks) */ /*max window size: 1024(direct blocks) + 3([t,d]indirect blocks) */
#define EXT3_MAX_RESERVE_BLOCKS 1027 #define EXT4_MAX_RESERVE_BLOCKS 1027
#define EXT3_RESERVE_WINDOW_NOT_ALLOCATED 0 #define EXT4_RESERVE_WINDOW_NOT_ALLOCATED 0
/* /*
* Always enable hashed directories * Always enable hashed directories
*/ */
#define CONFIG_EXT3_INDEX #define CONFIG_EXT4_INDEX
/* /*
* Debug code * Debug code
*/ */
#ifdef EXT3FS_DEBUG #ifdef EXT4FS_DEBUG
#define ext3_debug(f, a...) \ #define ext4_debug(f, a...) \
do { \ do { \
printk (KERN_DEBUG "EXT3-fs DEBUG (%s, %d): %s:", \ printk (KERN_DEBUG "EXT4-fs DEBUG (%s, %d): %s:", \
__FILE__, __LINE__, __FUNCTION__); \ __FILE__, __LINE__, __FUNCTION__); \
printk (KERN_DEBUG f, ## a); \ printk (KERN_DEBUG f, ## a); \
} while (0) } while (0)
#else #else
#define ext3_debug(f, a...) do {} while (0) #define ext4_debug(f, a...) do {} while (0)
#endif #endif
/* /*
* Special inodes numbers * Special inodes numbers
*/ */
#define EXT3_BAD_INO 1 /* Bad blocks inode */ #define EXT4_BAD_INO 1 /* Bad blocks inode */
#define EXT3_ROOT_INO 2 /* Root inode */ #define EXT4_ROOT_INO 2 /* Root inode */
#define EXT3_BOOT_LOADER_INO 5 /* Boot loader inode */ #define EXT4_BOOT_LOADER_INO 5 /* Boot loader inode */
#define EXT3_UNDEL_DIR_INO 6 /* Undelete directory inode */ #define EXT4_UNDEL_DIR_INO 6 /* Undelete directory inode */
#define EXT3_RESIZE_INO 7 /* Reserved group descriptors inode */ #define EXT4_RESIZE_INO 7 /* Reserved group descriptors inode */
#define EXT3_JOURNAL_INO 8 /* Journal inode */ #define EXT4_JOURNAL_INO 8 /* Journal inode */
/* First non-reserved inode for old ext3 filesystems */ /* First non-reserved inode for old ext4 filesystems */
#define EXT3_GOOD_OLD_FIRST_INO 11 #define EXT4_GOOD_OLD_FIRST_INO 11
/* /*
* Maximal count of links to a file * Maximal count of links to a file
*/ */
#define EXT3_LINK_MAX 32000 #define EXT4_LINK_MAX 32000
/* /*
* Macro-instructions used to manage several block sizes * Macro-instructions used to manage several block sizes
*/ */
#define EXT3_MIN_BLOCK_SIZE 1024 #define EXT4_MIN_BLOCK_SIZE 1024
#define EXT3_MAX_BLOCK_SIZE 4096 #define EXT4_MAX_BLOCK_SIZE 4096
#define EXT3_MIN_BLOCK_LOG_SIZE 10 #define EXT4_MIN_BLOCK_LOG_SIZE 10
#ifdef __KERNEL__ #ifdef __KERNEL__
# define EXT3_BLOCK_SIZE(s) ((s)->s_blocksize) # define EXT4_BLOCK_SIZE(s) ((s)->s_blocksize)
#else #else
# define EXT3_BLOCK_SIZE(s) (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size) # define EXT4_BLOCK_SIZE(s) (EXT4_MIN_BLOCK_SIZE << (s)->s_log_block_size)
#endif #endif
#define EXT3_ADDR_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (__u32)) #define EXT4_ADDR_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / sizeof (__u32))
#ifdef __KERNEL__ #ifdef __KERNEL__
# define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits) # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
#else #else
# define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10) # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
#endif #endif
#ifdef __KERNEL__ #ifdef __KERNEL__
#define EXT3_ADDR_PER_BLOCK_BITS(s) (EXT3_SB(s)->s_addr_per_block_bits) #define EXT4_ADDR_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_addr_per_block_bits)
#define EXT3_INODE_SIZE(s) (EXT3_SB(s)->s_inode_size) #define EXT4_INODE_SIZE(s) (EXT4_SB(s)->s_inode_size)
#define EXT3_FIRST_INO(s) (EXT3_SB(s)->s_first_ino) #define EXT4_FIRST_INO(s) (EXT4_SB(s)->s_first_ino)
#else #else
#define EXT3_INODE_SIZE(s) (((s)->s_rev_level == EXT3_GOOD_OLD_REV) ? \ #define EXT4_INODE_SIZE(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \
EXT3_GOOD_OLD_INODE_SIZE : \ EXT4_GOOD_OLD_INODE_SIZE : \
(s)->s_inode_size) (s)->s_inode_size)
#define EXT3_FIRST_INO(s) (((s)->s_rev_level == EXT3_GOOD_OLD_REV) ? \ #define EXT4_FIRST_INO(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \
EXT3_GOOD_OLD_FIRST_INO : \ EXT4_GOOD_OLD_FIRST_INO : \
(s)->s_first_ino) (s)->s_first_ino)
#endif #endif
/* /*
* Macro-instructions used to manage fragments * Macro-instructions used to manage fragments
*/ */
#define EXT3_MIN_FRAG_SIZE 1024 #define EXT4_MIN_FRAG_SIZE 1024
#define EXT3_MAX_FRAG_SIZE 4096 #define EXT4_MAX_FRAG_SIZE 4096
#define EXT3_MIN_FRAG_LOG_SIZE 10 #define EXT4_MIN_FRAG_LOG_SIZE 10
#ifdef __KERNEL__ #ifdef __KERNEL__
# define EXT3_FRAG_SIZE(s) (EXT3_SB(s)->s_frag_size) # define EXT4_FRAG_SIZE(s) (EXT4_SB(s)->s_frag_size)
# define EXT3_FRAGS_PER_BLOCK(s) (EXT3_SB(s)->s_frags_per_block) # define EXT4_FRAGS_PER_BLOCK(s) (EXT4_SB(s)->s_frags_per_block)
#else #else
# define EXT3_FRAG_SIZE(s) (EXT3_MIN_FRAG_SIZE << (s)->s_log_frag_size) # define EXT4_FRAG_SIZE(s) (EXT4_MIN_FRAG_SIZE << (s)->s_log_frag_size)
# define EXT3_FRAGS_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / EXT3_FRAG_SIZE(s)) # define EXT4_FRAGS_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / EXT4_FRAG_SIZE(s))
#endif #endif
/* /*
* Structure of a blocks group descriptor * Structure of a blocks group descriptor
*/ */
struct ext3_group_desc struct ext4_group_desc
{ {
__le32 bg_block_bitmap; /* Blocks bitmap block */ __le32 bg_block_bitmap; /* Blocks bitmap block */
__le32 bg_inode_bitmap; /* Inodes bitmap block */ __le32 bg_inode_bitmap; /* Inodes bitmap block */
...@@ -135,62 +135,62 @@ struct ext3_group_desc ...@@ -135,62 +135,62 @@ struct ext3_group_desc
* Macro-instructions used to manage group descriptors * Macro-instructions used to manage group descriptors
*/ */
#ifdef __KERNEL__ #ifdef __KERNEL__
# define EXT3_BLOCKS_PER_GROUP(s) (EXT3_SB(s)->s_blocks_per_group) # define EXT4_BLOCKS_PER_GROUP(s) (EXT4_SB(s)->s_blocks_per_group)
# define EXT3_DESC_PER_BLOCK(s) (EXT3_SB(s)->s_desc_per_block) # define EXT4_DESC_PER_BLOCK(s) (EXT4_SB(s)->s_desc_per_block)
# define EXT3_INODES_PER_GROUP(s) (EXT3_SB(s)->s_inodes_per_group) # define EXT4_INODES_PER_GROUP(s) (EXT4_SB(s)->s_inodes_per_group)
# define EXT3_DESC_PER_BLOCK_BITS(s) (EXT3_SB(s)->s_desc_per_block_bits) # define EXT4_DESC_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_desc_per_block_bits)
#else #else
# define EXT3_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group) # define EXT4_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)
# define EXT3_DESC_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_group_desc)) # define EXT4_DESC_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / sizeof (struct ext4_group_desc))
# define EXT3_INODES_PER_GROUP(s) ((s)->s_inodes_per_group) # define EXT4_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)
#endif #endif
/* /*
* Constants relative to the data blocks * Constants relative to the data blocks
*/ */
#define EXT3_NDIR_BLOCKS 12 #define EXT4_NDIR_BLOCKS 12
#define EXT3_IND_BLOCK EXT3_NDIR_BLOCKS #define EXT4_IND_BLOCK EXT4_NDIR_BLOCKS
#define EXT3_DIND_BLOCK (EXT3_IND_BLOCK + 1) #define EXT4_DIND_BLOCK (EXT4_IND_BLOCK + 1)
#define EXT3_TIND_BLOCK (EXT3_DIND_BLOCK + 1) #define EXT4_TIND_BLOCK (EXT4_DIND_BLOCK + 1)
#define EXT3_N_BLOCKS (EXT3_TIND_BLOCK + 1) #define EXT4_N_BLOCKS (EXT4_TIND_BLOCK + 1)
/* /*
* Inode flags * Inode flags
*/ */
#define EXT3_SECRM_FL 0x00000001 /* Secure deletion */ #define EXT4_SECRM_FL 0x00000001 /* Secure deletion */
#define EXT3_UNRM_FL 0x00000002 /* Undelete */ #define EXT4_UNRM_FL 0x00000002 /* Undelete */
#define EXT3_COMPR_FL 0x00000004 /* Compress file */ #define EXT4_COMPR_FL 0x00000004 /* Compress file */
#define EXT3_SYNC_FL 0x00000008 /* Synchronous updates */ #define EXT4_SYNC_FL 0x00000008 /* Synchronous updates */
#define EXT3_IMMUTABLE_FL 0x00000010 /* Immutable file */ #define EXT4_IMMUTABLE_FL 0x00000010 /* Immutable file */
#define EXT3_APPEND_FL 0x00000020 /* writes to file may only append */ #define EXT4_APPEND_FL 0x00000020 /* writes to file may only append */
#define EXT3_NODUMP_FL 0x00000040 /* do not dump file */ #define EXT4_NODUMP_FL 0x00000040 /* do not dump file */
#define EXT3_NOATIME_FL 0x00000080 /* do not update atime */ #define EXT4_NOATIME_FL 0x00000080 /* do not update atime */
/* Reserved for compression usage... */ /* Reserved for compression usage... */
#define EXT3_DIRTY_FL 0x00000100 #define EXT4_DIRTY_FL 0x00000100
#define EXT3_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ #define EXT4_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
#define EXT3_NOCOMPR_FL 0x00000400 /* Don't compress */ #define EXT4_NOCOMPR_FL 0x00000400 /* Don't compress */
#define EXT3_ECOMPR_FL 0x00000800 /* Compression error */ #define EXT4_ECOMPR_FL 0x00000800 /* Compression error */
/* End compression flags --- maybe not all used */ /* End compression flags --- maybe not all used */
#define EXT3_INDEX_FL 0x00001000 /* hash-indexed directory */ #define EXT4_INDEX_FL 0x00001000 /* hash-indexed directory */
#define EXT3_IMAGIC_FL 0x00002000 /* AFS directory */ #define EXT4_IMAGIC_FL 0x00002000 /* AFS directory */
#define EXT3_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */ #define EXT4_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */
#define EXT3_NOTAIL_FL 0x00008000 /* file tail should not be merged */ #define EXT4_NOTAIL_FL 0x00008000 /* file tail should not be merged */
#define EXT3_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ #define EXT4_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
#define EXT3_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ #define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
#define EXT3_RESERVED_FL 0x80000000 /* reserved for ext3 lib */ #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
#define EXT3_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ #define EXT4_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
#define EXT3_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */ #define EXT4_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
/* /*
* Inode dynamic state flags * Inode dynamic state flags
*/ */
#define EXT3_STATE_JDATA 0x00000001 /* journaled data exists */ #define EXT4_STATE_JDATA 0x00000001 /* journaled data exists */
#define EXT3_STATE_NEW 0x00000002 /* inode is newly created */ #define EXT4_STATE_NEW 0x00000002 /* inode is newly created */
#define EXT3_STATE_XATTR 0x00000004 /* has in-inode xattrs */ #define EXT4_STATE_XATTR 0x00000004 /* has in-inode xattrs */
/* Used to pass group descriptor data when online resize is done */ /* Used to pass group descriptor data when online resize is done */
struct ext3_new_group_input { struct ext4_new_group_input {
__u32 group; /* Group number for this data */ __u32 group; /* Group number for this data */
__u32 block_bitmap; /* Absolute block number of block bitmap */ __u32 block_bitmap; /* Absolute block number of block bitmap */
__u32 inode_bitmap; /* Absolute block number of inode bitmap */ __u32 inode_bitmap; /* Absolute block number of inode bitmap */
...@@ -200,8 +200,8 @@ struct ext3_new_group_input { ...@@ -200,8 +200,8 @@ struct ext3_new_group_input {
__u16 unused; __u16 unused;
}; };
/* The struct ext3_new_group_input in kernel space, with free_blocks_count */ /* The struct ext4_new_group_input in kernel space, with free_blocks_count */
struct ext3_new_group_data { struct ext4_new_group_data {
__u32 group; __u32 group;
__u32 block_bitmap; __u32 block_bitmap;
__u32 inode_bitmap; __u32 inode_bitmap;
...@@ -216,41 +216,41 @@ struct ext3_new_group_data { ...@@ -216,41 +216,41 @@ struct ext3_new_group_data {
/* /*
* ioctl commands * ioctl commands
*/ */
#define EXT3_IOC_GETFLAGS FS_IOC_GETFLAGS #define EXT4_IOC_GETFLAGS FS_IOC_GETFLAGS
#define EXT3_IOC_SETFLAGS FS_IOC_SETFLAGS #define EXT4_IOC_SETFLAGS FS_IOC_SETFLAGS
#define EXT3_IOC_GETVERSION _IOR('f', 3, long) #define EXT4_IOC_GETVERSION _IOR('f', 3, long)
#define EXT3_IOC_SETVERSION _IOW('f', 4, long) #define EXT4_IOC_SETVERSION _IOW('f', 4, long)
#define EXT3_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long) #define EXT4_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long)
#define EXT3_IOC_GROUP_ADD _IOW('f', 8,struct ext3_new_group_input) #define EXT4_IOC_GROUP_ADD _IOW('f', 8,struct ext4_new_group_input)
#define EXT3_IOC_GETVERSION_OLD FS_IOC_GETVERSION #define EXT4_IOC_GETVERSION_OLD FS_IOC_GETVERSION
#define EXT3_IOC_SETVERSION_OLD FS_IOC_SETVERSION #define EXT4_IOC_SETVERSION_OLD FS_IOC_SETVERSION
#ifdef CONFIG_JBD_DEBUG #ifdef CONFIG_JBD_DEBUG
#define EXT3_IOC_WAIT_FOR_READONLY _IOR('f', 99, long) #define EXT4_IOC_WAIT_FOR_READONLY _IOR('f', 99, long)
#endif #endif
#define EXT3_IOC_GETRSVSZ _IOR('f', 5, long) #define EXT4_IOC_GETRSVSZ _IOR('f', 5, long)
#define EXT3_IOC_SETRSVSZ _IOW('f', 6, long) #define EXT4_IOC_SETRSVSZ _IOW('f', 6, long)
/* /*
* ioctl commands in 32 bit emulation * ioctl commands in 32 bit emulation
*/ */
#define EXT3_IOC32_GETFLAGS FS_IOC32_GETFLAGS #define EXT4_IOC32_GETFLAGS FS_IOC32_GETFLAGS
#define EXT3_IOC32_SETFLAGS FS_IOC32_SETFLAGS #define EXT4_IOC32_SETFLAGS FS_IOC32_SETFLAGS
#define EXT3_IOC32_GETVERSION _IOR('f', 3, int) #define EXT4_IOC32_GETVERSION _IOR('f', 3, int)
#define EXT3_IOC32_SETVERSION _IOW('f', 4, int) #define EXT4_IOC32_SETVERSION _IOW('f', 4, int)
#define EXT3_IOC32_GETRSVSZ _IOR('f', 5, int) #define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int)
#define EXT3_IOC32_SETRSVSZ _IOW('f', 6, int) #define EXT4_IOC32_SETRSVSZ _IOW('f', 6, int)
#define EXT3_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int) #define EXT4_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int)
#ifdef CONFIG_JBD_DEBUG #ifdef CONFIG_JBD_DEBUG
#define EXT3_IOC32_WAIT_FOR_READONLY _IOR('f', 99, int) #define EXT4_IOC32_WAIT_FOR_READONLY _IOR('f', 99, int)
#endif #endif
#define EXT3_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION #define EXT4_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION
#define EXT3_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION #define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION
/* /*
* Mount options * Mount options
*/ */
struct ext3_mount_options { struct ext4_mount_options {
unsigned long s_mount_opt; unsigned long s_mount_opt;
uid_t s_resuid; uid_t s_resuid;
gid_t s_resgid; gid_t s_resgid;
...@@ -264,7 +264,7 @@ struct ext3_mount_options { ...@@ -264,7 +264,7 @@ struct ext3_mount_options {
/* /*
* Structure of an inode on the disk * Structure of an inode on the disk
*/ */
struct ext3_inode { struct ext4_inode {
__le16 i_mode; /* File mode */ __le16 i_mode; /* File mode */
__le16 i_uid; /* Low 16 bits of Owner Uid */ __le16 i_uid; /* Low 16 bits of Owner Uid */
__le32 i_size; /* Size in bytes */ __le32 i_size; /* Size in bytes */
...@@ -287,7 +287,7 @@ struct ext3_inode { ...@@ -287,7 +287,7 @@ struct ext3_inode {
__u32 m_i_reserved1; __u32 m_i_reserved1;
} masix1; } masix1;
} osd1; /* OS dependent 1 */ } osd1; /* OS dependent 1 */
__le32 i_block[EXT3_N_BLOCKS];/* Pointers to blocks */ __le32 i_block[EXT4_N_BLOCKS];/* Pointers to blocks */
__le32 i_generation; /* File version (for NFS) */ __le32 i_generation; /* File version (for NFS) */
__le32 i_file_acl; /* File ACL */ __le32 i_file_acl; /* File ACL */
__le32 i_dir_acl; /* Directory ACL */ __le32 i_dir_acl; /* Directory ACL */
...@@ -353,76 +353,76 @@ struct ext3_inode { ...@@ -353,76 +353,76 @@ struct ext3_inode {
/* /*
* File system states * File system states
*/ */
#define EXT3_VALID_FS 0x0001 /* Unmounted cleanly */ #define EXT4_VALID_FS 0x0001 /* Unmounted cleanly */
#define EXT3_ERROR_FS 0x0002 /* Errors detected */ #define EXT4_ERROR_FS 0x0002 /* Errors detected */
#define EXT3_ORPHAN_FS 0x0004 /* Orphans being recovered */ #define EXT4_ORPHAN_FS 0x0004 /* Orphans being recovered */
/* /*
* Mount flags * Mount flags
*/ */
#define EXT3_MOUNT_CHECK 0x00001 /* Do mount-time checks */ #define EXT4_MOUNT_CHECK 0x00001 /* Do mount-time checks */
#define EXT3_MOUNT_OLDALLOC 0x00002 /* Don't use the new Orlov allocator */ #define EXT4_MOUNT_OLDALLOC 0x00002 /* Don't use the new Orlov allocator */
#define EXT3_MOUNT_GRPID 0x00004 /* Create files with directory's group */ #define EXT4_MOUNT_GRPID 0x00004 /* Create files with directory's group */
#define EXT3_MOUNT_DEBUG 0x00008 /* Some debugging messages */ #define EXT4_MOUNT_DEBUG 0x00008 /* Some debugging messages */
#define EXT3_MOUNT_ERRORS_CONT 0x00010 /* Continue on errors */ #define EXT4_MOUNT_ERRORS_CONT 0x00010 /* Continue on errors */
#define EXT3_MOUNT_ERRORS_RO 0x00020 /* Remount fs ro on errors */ #define EXT4_MOUNT_ERRORS_RO 0x00020 /* Remount fs ro on errors */
#define EXT3_MOUNT_ERRORS_PANIC 0x00040 /* Panic on errors */ #define EXT4_MOUNT_ERRORS_PANIC 0x00040 /* Panic on errors */
#define EXT3_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */ #define EXT4_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */
#define EXT3_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/ #define EXT4_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/
#define EXT3_MOUNT_ABORT 0x00200 /* Fatal error detected */ #define EXT4_MOUNT_ABORT 0x00200 /* Fatal error detected */
#define EXT3_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */ #define EXT4_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */
#define EXT3_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */ #define EXT4_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */
#define EXT3_MOUNT_ORDERED_DATA 0x00800 /* Flush data before commit */ #define EXT4_MOUNT_ORDERED_DATA 0x00800 /* Flush data before commit */
#define EXT3_MOUNT_WRITEBACK_DATA 0x00C00 /* No data ordering */ #define EXT4_MOUNT_WRITEBACK_DATA 0x00C00 /* No data ordering */
#define EXT3_MOUNT_UPDATE_JOURNAL 0x01000 /* Update the journal format */ #define EXT4_MOUNT_UPDATE_JOURNAL 0x01000 /* Update the journal format */
#define EXT3_MOUNT_NO_UID32 0x02000 /* Disable 32-bit UIDs */ #define EXT4_MOUNT_NO_UID32 0x02000 /* Disable 32-bit UIDs */
#define EXT3_MOUNT_XATTR_USER 0x04000 /* Extended user attributes */ #define EXT4_MOUNT_XATTR_USER 0x04000 /* Extended user attributes */
#define EXT3_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */ #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
#define EXT3_MOUNT_RESERVATION 0x10000 /* Preallocation */ #define EXT4_MOUNT_RESERVATION 0x10000 /* Preallocation */
#define EXT3_MOUNT_BARRIER 0x20000 /* Use block barriers */ #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */
#define EXT3_MOUNT_NOBH 0x40000 /* No bufferheads */ #define EXT4_MOUNT_NOBH 0x40000 /* No bufferheads */
#define EXT3_MOUNT_QUOTA 0x80000 /* Some quota option set */ #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */
#define EXT3_MOUNT_USRQUOTA 0x100000 /* "old" user quota */ #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
#define EXT3_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */ #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
/* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */ /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
#ifndef _LINUX_EXT2_FS_H #ifndef _LINUX_EXT2_FS_H
#define clear_opt(o, opt) o &= ~EXT3_MOUNT_##opt #define clear_opt(o, opt) o &= ~EXT4_MOUNT_##opt
#define set_opt(o, opt) o |= EXT3_MOUNT_##opt #define set_opt(o, opt) o |= EXT4_MOUNT_##opt
#define test_opt(sb, opt) (EXT3_SB(sb)->s_mount_opt & \ #define test_opt(sb, opt) (EXT4_SB(sb)->s_mount_opt & \
EXT3_MOUNT_##opt) EXT4_MOUNT_##opt)
#else #else
#define EXT2_MOUNT_NOLOAD EXT3_MOUNT_NOLOAD #define EXT2_MOUNT_NOLOAD EXT4_MOUNT_NOLOAD
#define EXT2_MOUNT_ABORT EXT3_MOUNT_ABORT #define EXT2_MOUNT_ABORT EXT4_MOUNT_ABORT
#define EXT2_MOUNT_DATA_FLAGS EXT3_MOUNT_DATA_FLAGS #define EXT2_MOUNT_DATA_FLAGS EXT4_MOUNT_DATA_FLAGS
#endif #endif
#define ext3_set_bit ext2_set_bit #define ext4_set_bit ext2_set_bit
#define ext3_set_bit_atomic ext2_set_bit_atomic #define ext4_set_bit_atomic ext2_set_bit_atomic
#define ext3_clear_bit ext2_clear_bit #define ext4_clear_bit ext2_clear_bit
#define ext3_clear_bit_atomic ext2_clear_bit_atomic #define ext4_clear_bit_atomic ext2_clear_bit_atomic
#define ext3_test_bit ext2_test_bit #define ext4_test_bit ext2_test_bit
#define ext3_find_first_zero_bit ext2_find_first_zero_bit #define ext4_find_first_zero_bit ext2_find_first_zero_bit
#define ext3_find_next_zero_bit ext2_find_next_zero_bit #define ext4_find_next_zero_bit ext2_find_next_zero_bit
/* /*
* Maximal mount counts between two filesystem checks * Maximal mount counts between two filesystem checks
*/ */
#define EXT3_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */ #define EXT4_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
#define EXT3_DFL_CHECKINTERVAL 0 /* Don't use interval check */ #define EXT4_DFL_CHECKINTERVAL 0 /* Don't use interval check */
/* /*
* Behaviour when detecting errors * Behaviour when detecting errors
*/ */
#define EXT3_ERRORS_CONTINUE 1 /* Continue execution */ #define EXT4_ERRORS_CONTINUE 1 /* Continue execution */
#define EXT3_ERRORS_RO 2 /* Remount fs read-only */ #define EXT4_ERRORS_RO 2 /* Remount fs read-only */
#define EXT3_ERRORS_PANIC 3 /* Panic */ #define EXT4_ERRORS_PANIC 3 /* Panic */
#define EXT3_ERRORS_DEFAULT EXT3_ERRORS_CONTINUE #define EXT4_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE
/* /*
* Structure of the super block * Structure of the super block
*/ */
struct ext3_super_block { struct ext4_super_block {
/*00*/ __le32 s_inodes_count; /* Inodes count */ /*00*/ __le32 s_inodes_count; /* Inodes count */
__le32 s_blocks_count; /* Blocks count */ __le32 s_blocks_count; /* Blocks count */
__le32 s_r_blocks_count; /* Reserved blocks count */ __le32 s_r_blocks_count; /* Reserved blocks count */
...@@ -449,7 +449,7 @@ struct ext3_super_block { ...@@ -449,7 +449,7 @@ struct ext3_super_block {
/*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */ /*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */
__le16 s_def_resgid; /* Default gid for reserved blocks */ __le16 s_def_resgid; /* Default gid for reserved blocks */
/* /*
* These fields are for EXT3_DYNAMIC_REV superblocks only. * These fields are for EXT4_DYNAMIC_REV superblocks only.
* *
* Note: the difference between the compatible feature set and * Note: the difference between the compatible feature set and
* the incompatible feature set is that if there is a bit set * the incompatible feature set is that if there is a bit set
...@@ -473,13 +473,13 @@ struct ext3_super_block { ...@@ -473,13 +473,13 @@ struct ext3_super_block {
/*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */ /*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */
/* /*
* Performance hints. Directory preallocation should only * Performance hints. Directory preallocation should only
* happen if the EXT3_FEATURE_COMPAT_DIR_PREALLOC flag is on. * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on.
*/ */
__u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
__u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
__le16 s_reserved_gdt_blocks; /* Per group desc for online growth */ __le16 s_reserved_gdt_blocks; /* Per group desc for online growth */
/* /*
* Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set. * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set.
*/ */
/*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */ /*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */
/*E0*/ __le32 s_journal_inum; /* inode number of journal file */ /*E0*/ __le32 s_journal_inum; /* inode number of journal file */
...@@ -495,186 +495,186 @@ struct ext3_super_block { ...@@ -495,186 +495,186 @@ struct ext3_super_block {
}; };
#ifdef __KERNEL__ #ifdef __KERNEL__
#include <linux/ext3_fs_i.h> #include <linux/ext4_fs_i.h>
#include <linux/ext3_fs_sb.h> #include <linux/ext4_fs_sb.h>
static inline struct ext3_sb_info * EXT3_SB(struct super_block *sb) static inline struct ext4_sb_info * EXT4_SB(struct super_block *sb)
{ {
return sb->s_fs_info; return sb->s_fs_info;
} }
static inline struct ext3_inode_info *EXT3_I(struct inode *inode) static inline struct ext4_inode_info *EXT4_I(struct inode *inode)
{ {
return container_of(inode, struct ext3_inode_info, vfs_inode); return container_of(inode, struct ext4_inode_info, vfs_inode);
} }
static inline int ext3_valid_inum(struct super_block *sb, unsigned long ino) static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
{ {
return ino == EXT3_ROOT_INO || return ino == EXT4_ROOT_INO ||
ino == EXT3_JOURNAL_INO || ino == EXT4_JOURNAL_INO ||
ino == EXT3_RESIZE_INO || ino == EXT4_RESIZE_INO ||
(ino >= EXT3_FIRST_INO(sb) && (ino >= EXT4_FIRST_INO(sb) &&
ino <= le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count)); ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count));
} }
#else #else
/* Assume that user mode programs are passing in an ext3fs superblock, not /* Assume that user mode programs are passing in an ext4fs superblock, not
* a kernel struct super_block. This will allow us to call the feature-test * a kernel struct super_block. This will allow us to call the feature-test
* macros from user land. */ * macros from user land. */
#define EXT3_SB(sb) (sb) #define EXT4_SB(sb) (sb)
#endif #endif
#define NEXT_ORPHAN(inode) EXT3_I(inode)->i_dtime #define NEXT_ORPHAN(inode) EXT4_I(inode)->i_dtime
/* /*
* Codes for operating systems * Codes for operating systems
*/ */
#define EXT3_OS_LINUX 0 #define EXT4_OS_LINUX 0
#define EXT3_OS_HURD 1 #define EXT4_OS_HURD 1
#define EXT3_OS_MASIX 2 #define EXT4_OS_MASIX 2
#define EXT3_OS_FREEBSD 3 #define EXT4_OS_FREEBSD 3
#define EXT3_OS_LITES 4 #define EXT4_OS_LITES 4
/* /*
* Revision levels * Revision levels
*/ */
#define EXT3_GOOD_OLD_REV 0 /* The good old (original) format */ #define EXT4_GOOD_OLD_REV 0 /* The good old (original) format */
#define EXT3_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */ #define EXT4_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
#define EXT3_CURRENT_REV EXT3_GOOD_OLD_REV #define EXT4_CURRENT_REV EXT4_GOOD_OLD_REV
#define EXT3_MAX_SUPP_REV EXT3_DYNAMIC_REV #define EXT4_MAX_SUPP_REV EXT4_DYNAMIC_REV
#define EXT3_GOOD_OLD_INODE_SIZE 128 #define EXT4_GOOD_OLD_INODE_SIZE 128
/* /*
* Feature set definitions * Feature set definitions
*/ */
#define EXT3_HAS_COMPAT_FEATURE(sb,mask) \ #define EXT4_HAS_COMPAT_FEATURE(sb,mask) \
( EXT3_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) ) ( EXT4_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
#define EXT3_HAS_RO_COMPAT_FEATURE(sb,mask) \ #define EXT4_HAS_RO_COMPAT_FEATURE(sb,mask) \
( EXT3_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) ) ( EXT4_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
#define EXT3_HAS_INCOMPAT_FEATURE(sb,mask) \ #define EXT4_HAS_INCOMPAT_FEATURE(sb,mask) \
( EXT3_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) ) ( EXT4_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
#define EXT3_SET_COMPAT_FEATURE(sb,mask) \ #define EXT4_SET_COMPAT_FEATURE(sb,mask) \
EXT3_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask) EXT4_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
#define EXT3_SET_RO_COMPAT_FEATURE(sb,mask) \ #define EXT4_SET_RO_COMPAT_FEATURE(sb,mask) \
EXT3_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask) EXT4_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
#define EXT3_SET_INCOMPAT_FEATURE(sb,mask) \ #define EXT4_SET_INCOMPAT_FEATURE(sb,mask) \
EXT3_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask) EXT4_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
#define EXT3_CLEAR_COMPAT_FEATURE(sb,mask) \ #define EXT4_CLEAR_COMPAT_FEATURE(sb,mask) \
EXT3_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask) EXT4_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
#define EXT3_CLEAR_RO_COMPAT_FEATURE(sb,mask) \ #define EXT4_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
EXT3_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask) EXT4_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
#define EXT3_CLEAR_INCOMPAT_FEATURE(sb,mask) \ #define EXT4_CLEAR_INCOMPAT_FEATURE(sb,mask) \
EXT3_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask) EXT4_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
#define EXT3_FEATURE_COMPAT_DIR_PREALLOC 0x0001 #define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001
#define EXT3_FEATURE_COMPAT_IMAGIC_INODES 0x0002 #define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002
#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 #define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004
#define EXT3_FEATURE_COMPAT_EXT_ATTR 0x0008 #define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008
#define EXT3_FEATURE_COMPAT_RESIZE_INODE 0x0010 #define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010
#define EXT3_FEATURE_COMPAT_DIR_INDEX 0x0020 #define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020
#define EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 #define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
#define EXT3_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 #define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
#define EXT3_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 #define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
#define EXT3_FEATURE_INCOMPAT_COMPRESSION 0x0001 #define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001
#define EXT3_FEATURE_INCOMPAT_FILETYPE 0x0002 #define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002
#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */ #define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */ #define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
#define EXT3_FEATURE_INCOMPAT_META_BG 0x0010 #define EXT4_FEATURE_INCOMPAT_META_BG 0x0010
#define EXT3_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR #define EXT4_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
#define EXT3_FEATURE_INCOMPAT_SUPP (EXT3_FEATURE_INCOMPAT_FILETYPE| \ #define EXT4_FEATURE_INCOMPAT_SUPP (EXT4_FEATURE_INCOMPAT_FILETYPE| \
EXT3_FEATURE_INCOMPAT_RECOVER| \ EXT4_FEATURE_INCOMPAT_RECOVER| \
EXT3_FEATURE_INCOMPAT_META_BG) EXT4_FEATURE_INCOMPAT_META_BG)
#define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \ #define EXT4_FEATURE_RO_COMPAT_SUPP (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \
EXT3_FEATURE_RO_COMPAT_LARGE_FILE| \ EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \
EXT3_FEATURE_RO_COMPAT_BTREE_DIR) EXT4_FEATURE_RO_COMPAT_BTREE_DIR)
/* /*
* Default values for user and/or group using reserved blocks * Default values for user and/or group using reserved blocks
*/ */
#define EXT3_DEF_RESUID 0 #define EXT4_DEF_RESUID 0
#define EXT3_DEF_RESGID 0 #define EXT4_DEF_RESGID 0
/* /*
* Default mount options * Default mount options
*/ */
#define EXT3_DEFM_DEBUG 0x0001 #define EXT4_DEFM_DEBUG 0x0001
#define EXT3_DEFM_BSDGROUPS 0x0002 #define EXT4_DEFM_BSDGROUPS 0x0002
#define EXT3_DEFM_XATTR_USER 0x0004 #define EXT4_DEFM_XATTR_USER 0x0004
#define EXT3_DEFM_ACL 0x0008 #define EXT4_DEFM_ACL 0x0008
#define EXT3_DEFM_UID16 0x0010 #define EXT4_DEFM_UID16 0x0010
#define EXT3_DEFM_JMODE 0x0060 #define EXT4_DEFM_JMODE 0x0060
#define EXT3_DEFM_JMODE_DATA 0x0020 #define EXT4_DEFM_JMODE_DATA 0x0020
#define EXT3_DEFM_JMODE_ORDERED 0x0040 #define EXT4_DEFM_JMODE_ORDERED 0x0040
#define EXT3_DEFM_JMODE_WBACK 0x0060 #define EXT4_DEFM_JMODE_WBACK 0x0060
/* /*
* Structure of a directory entry * Structure of a directory entry
*/ */
#define EXT3_NAME_LEN 255 #define EXT4_NAME_LEN 255
struct ext3_dir_entry { struct ext4_dir_entry {
__le32 inode; /* Inode number */ __le32 inode; /* Inode number */
__le16 rec_len; /* Directory entry length */ __le16 rec_len; /* Directory entry length */
__le16 name_len; /* Name length */ __le16 name_len; /* Name length */
char name[EXT3_NAME_LEN]; /* File name */ char name[EXT4_NAME_LEN]; /* File name */
}; };
/* /*
* The new version of the directory entry. Since EXT3 structures are * The new version of the directory entry. Since EXT4 structures are
* stored in intel byte order, and the name_len field could never be * stored in intel byte order, and the name_len field could never be
* bigger than 255 chars, it's safe to reclaim the extra byte for the * bigger than 255 chars, it's safe to reclaim the extra byte for the
* file_type field. * file_type field.
*/ */
struct ext3_dir_entry_2 { struct ext4_dir_entry_2 {
__le32 inode; /* Inode number */ __le32 inode; /* Inode number */
__le16 rec_len; /* Directory entry length */ __le16 rec_len; /* Directory entry length */
__u8 name_len; /* Name length */ __u8 name_len; /* Name length */
__u8 file_type; __u8 file_type;
char name[EXT3_NAME_LEN]; /* File name */ char name[EXT4_NAME_LEN]; /* File name */
}; };
/* /*
* Ext3 directory file types. Only the low 3 bits are used. The * Ext4 directory file types. Only the low 3 bits are used. The
* other bits are reserved for now. * other bits are reserved for now.
*/ */
#define EXT3_FT_UNKNOWN 0 #define EXT4_FT_UNKNOWN 0
#define EXT3_FT_REG_FILE 1 #define EXT4_FT_REG_FILE 1
#define EXT3_FT_DIR 2 #define EXT4_FT_DIR 2
#define EXT3_FT_CHRDEV 3 #define EXT4_FT_CHRDEV 3
#define EXT3_FT_BLKDEV 4 #define EXT4_FT_BLKDEV 4
#define EXT3_FT_FIFO 5 #define EXT4_FT_FIFO 5
#define EXT3_FT_SOCK 6 #define EXT4_FT_SOCK 6
#define EXT3_FT_SYMLINK 7 #define EXT4_FT_SYMLINK 7
#define EXT3_FT_MAX 8 #define EXT4_FT_MAX 8
/* /*
* EXT3_DIR_PAD defines the directory entries boundaries * EXT4_DIR_PAD defines the directory entries boundaries
* *
* NOTE: It must be a multiple of 4 * NOTE: It must be a multiple of 4
*/ */
#define EXT3_DIR_PAD 4 #define EXT4_DIR_PAD 4
#define EXT3_DIR_ROUND (EXT3_DIR_PAD - 1) #define EXT4_DIR_ROUND (EXT4_DIR_PAD - 1)
#define EXT3_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT3_DIR_ROUND) & \ #define EXT4_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT4_DIR_ROUND) & \
~EXT3_DIR_ROUND) ~EXT4_DIR_ROUND)
/* /*
* Hash Tree Directory indexing * Hash Tree Directory indexing
* (c) Daniel Phillips, 2001 * (c) Daniel Phillips, 2001
*/ */
#ifdef CONFIG_EXT3_INDEX #ifdef CONFIG_EXT4_INDEX
#define is_dx(dir) (EXT3_HAS_COMPAT_FEATURE(dir->i_sb, \ #define is_dx(dir) (EXT4_HAS_COMPAT_FEATURE(dir->i_sb, \
EXT3_FEATURE_COMPAT_DIR_INDEX) && \ EXT4_FEATURE_COMPAT_DIR_INDEX) && \
(EXT3_I(dir)->i_flags & EXT3_INDEX_FL)) (EXT4_I(dir)->i_flags & EXT4_INDEX_FL))
#define EXT3_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT3_LINK_MAX) #define EXT4_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT4_LINK_MAX)
#define EXT3_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1) #define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1)
#else #else
#define is_dx(dir) 0 #define is_dx(dir) 0
#define EXT3_DIR_LINK_MAX(dir) ((dir)->i_nlink >= EXT3_LINK_MAX) #define EXT4_DIR_LINK_MAX(dir) ((dir)->i_nlink >= EXT4_LINK_MAX)
#define EXT3_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2) #define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2)
#endif #endif
/* Legal values for the dx_root hash_version field: */ /* Legal values for the dx_root hash_version field: */
...@@ -694,10 +694,10 @@ struct dx_hash_info ...@@ -694,10 +694,10 @@ struct dx_hash_info
u32 *seed; u32 *seed;
}; };
#define EXT3_HTREE_EOF 0x7fffffff #define EXT4_HTREE_EOF 0x7fffffff
/* /*
* Control parameters used by ext3_htree_next_block * Control parameters used by ext4_htree_next_block
*/ */
#define HASH_NB_ALWAYS 1 #define HASH_NB_ALWAYS 1
...@@ -705,16 +705,16 @@ struct dx_hash_info ...@@ -705,16 +705,16 @@ struct dx_hash_info
/* /*
* Describe an inode's exact location on disk and in memory * Describe an inode's exact location on disk and in memory
*/ */
struct ext3_iloc struct ext4_iloc
{ {
struct buffer_head *bh; struct buffer_head *bh;
unsigned long offset; unsigned long offset;
unsigned long block_group; unsigned long block_group;
}; };
static inline struct ext3_inode *ext3_raw_inode(struct ext3_iloc *iloc) static inline struct ext4_inode *ext4_raw_inode(struct ext4_iloc *iloc)
{ {
return (struct ext3_inode *) (iloc->bh->b_data + iloc->offset); return (struct ext4_inode *) (iloc->bh->b_data + iloc->offset);
} }
/* /*
...@@ -733,11 +733,11 @@ struct dir_private_info { ...@@ -733,11 +733,11 @@ struct dir_private_info {
}; };
/* calculate the first block number of the group */ /* calculate the first block number of the group */
static inline ext3_fsblk_t static inline ext4_fsblk_t
ext3_group_first_block_no(struct super_block *sb, unsigned long group_no) ext4_group_first_block_no(struct super_block *sb, unsigned long group_no)
{ {
return group_no * (ext3_fsblk_t)EXT3_BLOCKS_PER_GROUP(sb) + return group_no * (ext4_fsblk_t)EXT4_BLOCKS_PER_GROUP(sb) +
le32_to_cpu(EXT3_SB(sb)->s_es->s_first_data_block); le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
} }
/* /*
...@@ -751,113 +751,113 @@ ext3_group_first_block_no(struct super_block *sb, unsigned long group_no) ...@@ -751,113 +751,113 @@ ext3_group_first_block_no(struct super_block *sb, unsigned long group_no)
/* /*
* Ok, these declarations are also in <linux/kernel.h> but none of the * Ok, these declarations are also in <linux/kernel.h> but none of the
* ext3 source programs needs to include it so they are duplicated here. * ext4 source programs needs to include it so they are duplicated here.
*/ */
# define NORET_TYPE /**/ # define NORET_TYPE /**/
# define ATTRIB_NORET __attribute__((noreturn)) # define ATTRIB_NORET __attribute__((noreturn))
# define NORET_AND noreturn, # define NORET_AND noreturn,
/* balloc.c */ /* balloc.c */
extern int ext3_bg_has_super(struct super_block *sb, int group); extern int ext4_bg_has_super(struct super_block *sb, int group);
extern unsigned long ext3_bg_num_gdb(struct super_block *sb, int group); extern unsigned long ext4_bg_num_gdb(struct super_block *sb, int group);
extern ext3_fsblk_t ext3_new_block (handle_t *handle, struct inode *inode, extern ext4_fsblk_t ext4_new_block (handle_t *handle, struct inode *inode,
ext3_fsblk_t goal, int *errp); ext4_fsblk_t goal, int *errp);
extern ext3_fsblk_t ext3_new_blocks (handle_t *handle, struct inode *inode, extern ext4_fsblk_t ext4_new_blocks (handle_t *handle, struct inode *inode,
ext3_fsblk_t goal, unsigned long *count, int *errp); ext4_fsblk_t goal, unsigned long *count, int *errp);
extern void ext3_free_blocks (handle_t *handle, struct inode *inode, extern void ext4_free_blocks (handle_t *handle, struct inode *inode,
ext3_fsblk_t block, unsigned long count); ext4_fsblk_t block, unsigned long count);
extern void ext3_free_blocks_sb (handle_t *handle, struct super_block *sb, extern void ext4_free_blocks_sb (handle_t *handle, struct super_block *sb,
ext3_fsblk_t block, unsigned long count, ext4_fsblk_t block, unsigned long count,
unsigned long *pdquot_freed_blocks); unsigned long *pdquot_freed_blocks);
extern ext3_fsblk_t ext3_count_free_blocks (struct super_block *); extern ext4_fsblk_t ext4_count_free_blocks (struct super_block *);
extern void ext3_check_blocks_bitmap (struct super_block *); extern void ext4_check_blocks_bitmap (struct super_block *);
extern struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb, extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
unsigned int block_group, unsigned int block_group,
struct buffer_head ** bh); struct buffer_head ** bh);
extern int ext3_should_retry_alloc(struct super_block *sb, int *retries); extern int ext4_should_retry_alloc(struct super_block *sb, int *retries);
extern void ext3_init_block_alloc_info(struct inode *); extern void ext4_init_block_alloc_info(struct inode *);
extern void ext3_rsv_window_add(struct super_block *sb, struct ext3_reserve_window_node *rsv); extern void ext4_rsv_window_add(struct super_block *sb, struct ext4_reserve_window_node *rsv);
/* dir.c */ /* dir.c */
extern int ext3_check_dir_entry(const char *, struct inode *, extern int ext4_check_dir_entry(const char *, struct inode *,
struct ext3_dir_entry_2 *, struct ext4_dir_entry_2 *,
struct buffer_head *, unsigned long); struct buffer_head *, unsigned long);
extern int ext3_htree_store_dirent(struct file *dir_file, __u32 hash, extern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
__u32 minor_hash, __u32 minor_hash,
struct ext3_dir_entry_2 *dirent); struct ext4_dir_entry_2 *dirent);
extern void ext3_htree_free_dir_info(struct dir_private_info *p); extern void ext4_htree_free_dir_info(struct dir_private_info *p);
/* fsync.c */ /* fsync.c */
extern int ext3_sync_file (struct file *, struct dentry *, int); extern int ext4_sync_file (struct file *, struct dentry *, int);
/* hash.c */ /* hash.c */
extern int ext3fs_dirhash(const char *name, int len, struct extern int ext4fs_dirhash(const char *name, int len, struct
dx_hash_info *hinfo); dx_hash_info *hinfo);
/* ialloc.c */ /* ialloc.c */
extern struct inode * ext3_new_inode (handle_t *, struct inode *, int); extern struct inode * ext4_new_inode (handle_t *, struct inode *, int);
extern void ext3_free_inode (handle_t *, struct inode *); extern void ext4_free_inode (handle_t *, struct inode *);
extern struct inode * ext3_orphan_get (struct super_block *, unsigned long); extern struct inode * ext4_orphan_get (struct super_block *, unsigned long);
extern unsigned long ext3_count_free_inodes (struct super_block *); extern unsigned long ext4_count_free_inodes (struct super_block *);
extern unsigned long ext3_count_dirs (struct super_block *); extern unsigned long ext4_count_dirs (struct super_block *);
extern void ext3_check_inodes_bitmap (struct super_block *); extern void ext4_check_inodes_bitmap (struct super_block *);
extern unsigned long ext3_count_free (struct buffer_head *, unsigned); extern unsigned long ext4_count_free (struct buffer_head *, unsigned);
/* inode.c */ /* inode.c */
int ext3_forget(handle_t *handle, int is_metadata, struct inode *inode, int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode,
struct buffer_head *bh, ext3_fsblk_t blocknr); struct buffer_head *bh, ext4_fsblk_t blocknr);
struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *); struct buffer_head * ext4_getblk (handle_t *, struct inode *, long, int, int *);
struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *); struct buffer_head * ext4_bread (handle_t *, struct inode *, int, int, int *);
int ext3_get_blocks_handle(handle_t *handle, struct inode *inode, int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result, sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
int create, int extend_disksize); int create, int extend_disksize);
extern void ext3_read_inode (struct inode *); extern void ext4_read_inode (struct inode *);
extern int ext3_write_inode (struct inode *, int); extern int ext4_write_inode (struct inode *, int);
extern int ext3_setattr (struct dentry *, struct iattr *); extern int ext4_setattr (struct dentry *, struct iattr *);
extern void ext3_delete_inode (struct inode *); extern void ext4_delete_inode (struct inode *);
extern int ext3_sync_inode (handle_t *, struct inode *); extern int ext4_sync_inode (handle_t *, struct inode *);
extern void ext3_discard_reservation (struct inode *); extern void ext4_discard_reservation (struct inode *);
extern void ext3_dirty_inode(struct inode *); extern void ext4_dirty_inode(struct inode *);
extern int ext3_change_inode_journal_flag(struct inode *, int); extern int ext4_change_inode_journal_flag(struct inode *, int);
extern int ext3_get_inode_loc(struct inode *, struct ext3_iloc *); extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *);
extern void ext3_truncate (struct inode *); extern void ext4_truncate (struct inode *);
extern void ext3_set_inode_flags(struct inode *); extern void ext4_set_inode_flags(struct inode *);
extern void ext3_set_aops(struct inode *inode); extern void ext4_set_aops(struct inode *inode);
/* ioctl.c */ /* ioctl.c */
extern int ext3_ioctl (struct inode *, struct file *, unsigned int, extern int ext4_ioctl (struct inode *, struct file *, unsigned int,
unsigned long); unsigned long);
extern long ext3_compat_ioctl (struct file *, unsigned int, unsigned long); extern long ext4_compat_ioctl (struct file *, unsigned int, unsigned long);
/* namei.c */ /* namei.c */
extern int ext3_orphan_add(handle_t *, struct inode *); extern int ext4_orphan_add(handle_t *, struct inode *);
extern int ext3_orphan_del(handle_t *, struct inode *); extern int ext4_orphan_del(handle_t *, struct inode *);
extern int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash, extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
__u32 start_minor_hash, __u32 *next_hash); __u32 start_minor_hash, __u32 *next_hash);
/* resize.c */ /* resize.c */
extern int ext3_group_add(struct super_block *sb, extern int ext4_group_add(struct super_block *sb,
struct ext3_new_group_data *input); struct ext4_new_group_data *input);
extern int ext3_group_extend(struct super_block *sb, extern int ext4_group_extend(struct super_block *sb,
struct ext3_super_block *es, struct ext4_super_block *es,
ext3_fsblk_t n_blocks_count); ext4_fsblk_t n_blocks_count);
/* super.c */ /* super.c */
extern void ext3_error (struct super_block *, const char *, const char *, ...) extern void ext4_error (struct super_block *, const char *, const char *, ...)
__attribute__ ((format (printf, 3, 4))); __attribute__ ((format (printf, 3, 4)));
extern void __ext3_std_error (struct super_block *, const char *, int); extern void __ext4_std_error (struct super_block *, const char *, int);
extern void ext3_abort (struct super_block *, const char *, const char *, ...) extern void ext4_abort (struct super_block *, const char *, const char *, ...)
__attribute__ ((format (printf, 3, 4))); __attribute__ ((format (printf, 3, 4)));
extern void ext3_warning (struct super_block *, const char *, const char *, ...) extern void ext4_warning (struct super_block *, const char *, const char *, ...)
__attribute__ ((format (printf, 3, 4))); __attribute__ ((format (printf, 3, 4)));
extern void ext3_update_dynamic_rev (struct super_block *sb); extern void ext4_update_dynamic_rev (struct super_block *sb);
#define ext3_std_error(sb, errno) \ #define ext4_std_error(sb, errno) \
do { \ do { \
if ((errno)) \ if ((errno)) \
__ext3_std_error((sb), __FUNCTION__, (errno)); \ __ext4_std_error((sb), __FUNCTION__, (errno)); \
} while (0) } while (0)
/* /*
...@@ -865,21 +865,21 @@ do { \ ...@@ -865,21 +865,21 @@ do { \
*/ */
/* dir.c */ /* dir.c */
extern const struct file_operations ext3_dir_operations; extern const struct file_operations ext4_dir_operations;
/* file.c */ /* file.c */
extern struct inode_operations ext3_file_inode_operations; extern struct inode_operations ext4_file_inode_operations;
extern const struct file_operations ext3_file_operations; extern const struct file_operations ext4_file_operations;
/* namei.c */ /* namei.c */
extern struct inode_operations ext3_dir_inode_operations; extern struct inode_operations ext4_dir_inode_operations;
extern struct inode_operations ext3_special_inode_operations; extern struct inode_operations ext4_special_inode_operations;
/* symlink.c */ /* symlink.c */
extern struct inode_operations ext3_symlink_inode_operations; extern struct inode_operations ext4_symlink_inode_operations;
extern struct inode_operations ext3_fast_symlink_inode_operations; extern struct inode_operations ext4_fast_symlink_inode_operations;
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
#endif /* _LINUX_EXT3_FS_H */ #endif /* _LINUX_EXT4_FS_H */
/* /*
* linux/include/linux/ext3_fs_i.h * linux/include/linux/ext4_fs_i.h
* *
* Copyright (C) 1992, 1993, 1994, 1995 * Copyright (C) 1992, 1993, 1994, 1995
* Remy Card (card@masi.ibp.fr) * Remy Card (card@masi.ibp.fr)
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* Copyright (C) 1991, 1992 Linus Torvalds * Copyright (C) 1991, 1992 Linus Torvalds
*/ */
#ifndef _LINUX_EXT3_FS_I #ifndef _LINUX_EXT4_FS_I
#define _LINUX_EXT3_FS_I #define _LINUX_EXT4_FS_I
#include <linux/rwsem.h> #include <linux/rwsem.h>
#include <linux/rbtree.h> #include <linux/rbtree.h>
...@@ -22,43 +22,43 @@ ...@@ -22,43 +22,43 @@
#include <linux/mutex.h> #include <linux/mutex.h>
/* data type for block offset of block group */ /* data type for block offset of block group */
typedef int ext3_grpblk_t; typedef int ext4_grpblk_t;
/* data type for filesystem-wide blocks number */ /* data type for filesystem-wide blocks number */
typedef unsigned long ext3_fsblk_t; typedef unsigned long ext4_fsblk_t;
#define E3FSBLK "%lu" #define E3FSBLK "%lu"
struct ext3_reserve_window { struct ext4_reserve_window {
ext3_fsblk_t _rsv_start; /* First byte reserved */ ext4_fsblk_t _rsv_start; /* First byte reserved */
ext3_fsblk_t _rsv_end; /* Last byte reserved or 0 */ ext4_fsblk_t _rsv_end; /* Last byte reserved or 0 */
}; };
struct ext3_reserve_window_node { struct ext4_reserve_window_node {
struct rb_node rsv_node; struct rb_node rsv_node;
__u32 rsv_goal_size; __u32 rsv_goal_size;
__u32 rsv_alloc_hit; __u32 rsv_alloc_hit;
struct ext3_reserve_window rsv_window; struct ext4_reserve_window rsv_window;
}; };
struct ext3_block_alloc_info { struct ext4_block_alloc_info {
/* information about reservation window */ /* information about reservation window */
struct ext3_reserve_window_node rsv_window_node; struct ext4_reserve_window_node rsv_window_node;
/* /*
* was i_next_alloc_block in ext3_inode_info * was i_next_alloc_block in ext4_inode_info
* is the logical (file-relative) number of the * is the logical (file-relative) number of the
* most-recently-allocated block in this file. * most-recently-allocated block in this file.
* We use this for detecting linearly ascending allocation requests. * We use this for detecting linearly ascending allocation requests.
*/ */
__u32 last_alloc_logical_block; __u32 last_alloc_logical_block;
/* /*
* Was i_next_alloc_goal in ext3_inode_info * Was i_next_alloc_goal in ext4_inode_info
* is the *physical* companion to i_next_alloc_block. * is the *physical* companion to i_next_alloc_block.
* it the the physical block number of the block which was most-recentl * it the the physical block number of the block which was most-recentl
* allocated to this file. This give us the goal (target) for the next * allocated to this file. This give us the goal (target) for the next
* allocation when we detect linearly ascending requests. * allocation when we detect linearly ascending requests.
*/ */
ext3_fsblk_t last_alloc_physical_block; ext4_fsblk_t last_alloc_physical_block;
}; };
#define rsv_start rsv_window._rsv_start #define rsv_start rsv_window._rsv_start
...@@ -67,15 +67,15 @@ struct ext3_block_alloc_info { ...@@ -67,15 +67,15 @@ struct ext3_block_alloc_info {
/* /*
* third extended file system inode data in memory * third extended file system inode data in memory
*/ */
struct ext3_inode_info { struct ext4_inode_info {
__le32 i_data[15]; /* unconverted */ __le32 i_data[15]; /* unconverted */
__u32 i_flags; __u32 i_flags;
#ifdef EXT3_FRAGMENTS #ifdef EXT4_FRAGMENTS
__u32 i_faddr; __u32 i_faddr;
__u8 i_frag_no; __u8 i_frag_no;
__u8 i_frag_size; __u8 i_frag_size;
#endif #endif
ext3_fsblk_t i_file_acl; ext4_fsblk_t i_file_acl;
__u32 i_dir_acl; __u32 i_dir_acl;
__u32 i_dtime; __u32 i_dtime;
...@@ -87,13 +87,13 @@ struct ext3_inode_info { ...@@ -87,13 +87,13 @@ struct ext3_inode_info {
* near to their parent directory's inode. * near to their parent directory's inode.
*/ */
__u32 i_block_group; __u32 i_block_group;
__u32 i_state; /* Dynamic state flags for ext3 */ __u32 i_state; /* Dynamic state flags for ext4 */
/* block reservation info */ /* block reservation info */
struct ext3_block_alloc_info *i_block_alloc_info; struct ext4_block_alloc_info *i_block_alloc_info;
__u32 i_dir_start_lookup; __u32 i_dir_start_lookup;
#ifdef CONFIG_EXT3_FS_XATTR #ifdef CONFIG_EXT4DEV_FS_XATTR
/* /*
* Extended attributes can be read independently of the main file * Extended attributes can be read independently of the main file
* data. Taking i_mutex even when reading would cause contention * data. Taking i_mutex even when reading would cause contention
...@@ -103,7 +103,7 @@ struct ext3_inode_info { ...@@ -103,7 +103,7 @@ struct ext3_inode_info {
*/ */
struct rw_semaphore xattr_sem; struct rw_semaphore xattr_sem;
#endif #endif
#ifdef CONFIG_EXT3_FS_POSIX_ACL #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
struct posix_acl *i_acl; struct posix_acl *i_acl;
struct posix_acl *i_default_acl; struct posix_acl *i_default_acl;
#endif #endif
...@@ -113,7 +113,7 @@ struct ext3_inode_info { ...@@ -113,7 +113,7 @@ struct ext3_inode_info {
/* /*
* i_disksize keeps track of what the inode size is ON DISK, not * i_disksize keeps track of what the inode size is ON DISK, not
* in memory. During truncate, i_size is set to the new size by * in memory. During truncate, i_size is set to the new size by
* the VFS prior to calling ext3_truncate(), but the filesystem won't * the VFS prior to calling ext4_truncate(), but the filesystem won't
* set i_disksize to 0 until the truncate is actually under way. * set i_disksize to 0 until the truncate is actually under way.
* *
* The intent is that i_disksize always represents the blocks which * The intent is that i_disksize always represents the blocks which
...@@ -123,7 +123,7 @@ struct ext3_inode_info { ...@@ -123,7 +123,7 @@ struct ext3_inode_info {
* *
* The only time when i_disksize and i_size may be different is when * The only time when i_disksize and i_size may be different is when
* a truncate is in progress. The only things which change i_disksize * a truncate is in progress. The only things which change i_disksize
* are ext3_get_block (growth) and ext3_truncate (shrinkth). * are ext4_get_block (growth) and ext4_truncate (shrinkth).
*/ */
loff_t i_disksize; loff_t i_disksize;
...@@ -131,10 +131,10 @@ struct ext3_inode_info { ...@@ -131,10 +131,10 @@ struct ext3_inode_info {
__u16 i_extra_isize; __u16 i_extra_isize;
/* /*
* truncate_mutex is for serialising ext3_truncate() against * truncate_mutex is for serialising ext4_truncate() against
* ext3_getblock(). In the 2.4 ext2 design, great chunks of inode's * ext4_getblock(). In the 2.4 ext2 design, great chunks of inode's
* data tree are chopped off during truncate. We can't do that in * data tree are chopped off during truncate. We can't do that in
* ext3 because whenever we perform intermediate commits during * ext4 because whenever we perform intermediate commits during
* truncate, the inode and all the metadata blocks *must* be in a * truncate, the inode and all the metadata blocks *must* be in a
* consistent state which allows truncation of the orphans to restart * consistent state which allows truncation of the orphans to restart
* during recovery. Hence we must fix the get_block-vs-truncate race * during recovery. Hence we must fix the get_block-vs-truncate race
...@@ -144,4 +144,4 @@ struct ext3_inode_info { ...@@ -144,4 +144,4 @@ struct ext3_inode_info {
struct inode vfs_inode; struct inode vfs_inode;
}; };
#endif /* _LINUX_EXT3_FS_I */ #endif /* _LINUX_EXT4_FS_I */
/* /*
* linux/include/linux/ext3_fs_sb.h * linux/include/linux/ext4_fs_sb.h
* *
* Copyright (C) 1992, 1993, 1994, 1995 * Copyright (C) 1992, 1993, 1994, 1995
* Remy Card (card@masi.ibp.fr) * Remy Card (card@masi.ibp.fr)
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* Copyright (C) 1991, 1992 Linus Torvalds * Copyright (C) 1991, 1992 Linus Torvalds
*/ */
#ifndef _LINUX_EXT3_FS_SB #ifndef _LINUX_EXT4_FS_SB
#define _LINUX_EXT3_FS_SB #define _LINUX_EXT4_FS_SB
#ifdef __KERNEL__ #ifdef __KERNEL__
#include <linux/timer.h> #include <linux/timer.h>
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
/* /*
* third extended-fs super-block data in memory * third extended-fs super-block data in memory
*/ */
struct ext3_sb_info { struct ext4_sb_info {
unsigned long s_frag_size; /* Size of a fragment in bytes */ unsigned long s_frag_size; /* Size of a fragment in bytes */
unsigned long s_frags_per_block;/* Number of fragments per block */ unsigned long s_frags_per_block;/* Number of fragments per block */
unsigned long s_inodes_per_block;/* Number of inodes per block */ unsigned long s_inodes_per_block;/* Number of inodes per block */
...@@ -39,7 +39,7 @@ struct ext3_sb_info { ...@@ -39,7 +39,7 @@ struct ext3_sb_info {
unsigned long s_desc_per_block; /* Number of group descriptors per block */ unsigned long s_desc_per_block; /* Number of group descriptors per block */
unsigned long s_groups_count; /* Number of groups in the fs */ unsigned long s_groups_count; /* Number of groups in the fs */
struct buffer_head * s_sbh; /* Buffer containing the super block */ struct buffer_head * s_sbh; /* Buffer containing the super block */
struct ext3_super_block * s_es; /* Pointer to the super block in the buffer */ struct ext4_super_block * s_es; /* Pointer to the super block in the buffer */
struct buffer_head ** s_group_desc; struct buffer_head ** s_group_desc;
unsigned long s_mount_opt; unsigned long s_mount_opt;
uid_t s_resuid; uid_t s_resuid;
...@@ -62,7 +62,7 @@ struct ext3_sb_info { ...@@ -62,7 +62,7 @@ struct ext3_sb_info {
/* root of the per fs reservation window tree */ /* root of the per fs reservation window tree */
spinlock_t s_rsv_window_lock; spinlock_t s_rsv_window_lock;
struct rb_root s_rsv_window_root; struct rb_root s_rsv_window_root;
struct ext3_reserve_window_node s_rsv_window_head; struct ext4_reserve_window_node s_rsv_window_head;
/* Journaling */ /* Journaling */
struct inode * s_journal_inode; struct inode * s_journal_inode;
...@@ -80,4 +80,4 @@ struct ext3_sb_info { ...@@ -80,4 +80,4 @@ struct ext3_sb_info {
#endif #endif
}; };
#endif /* _LINUX_EXT3_FS_SB */ #endif /* _LINUX_EXT4_FS_SB */
/* /*
* linux/include/linux/ext3_jbd.h * linux/include/linux/ext4_jbd.h
* *
* Written by Stephen C. Tweedie <sct@redhat.com>, 1999 * Written by Stephen C. Tweedie <sct@redhat.com>, 1999
* *
...@@ -9,17 +9,17 @@ ...@@ -9,17 +9,17 @@
* the terms of the GNU General Public License, version 2, or at your * the terms of the GNU General Public License, version 2, or at your
* option, any later version, incorporated herein by reference. * option, any later version, incorporated herein by reference.
* *
* Ext3-specific journaling extensions. * Ext4-specific journaling extensions.
*/ */
#ifndef _LINUX_EXT3_JBD_H #ifndef _LINUX_EXT4_JBD_H
#define _LINUX_EXT3_JBD_H #define _LINUX_EXT4_JBD_H
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/jbd.h> #include <linux/jbd.h>
#include <linux/ext3_fs.h> #include <linux/ext4_fs.h>
#define EXT3_JOURNAL(inode) (EXT3_SB((inode)->i_sb)->s_journal) #define EXT4_JOURNAL(inode) (EXT4_SB((inode)->i_sb)->s_journal)
/* Define the number of blocks we need to account to a transaction to /* Define the number of blocks we need to account to a transaction to
* modify one block of data. * modify one block of data.
...@@ -28,13 +28,13 @@ ...@@ -28,13 +28,13 @@
* indirection blocks, the group and superblock summaries, and the data * indirection blocks, the group and superblock summaries, and the data
* block to complete the transaction. */ * block to complete the transaction. */
#define EXT3_SINGLEDATA_TRANS_BLOCKS 8U #define EXT4_SINGLEDATA_TRANS_BLOCKS 8U
/* Extended attribute operations touch at most two data buffers, /* Extended attribute operations touch at most two data buffers,
* two bitmap buffers, and two group summaries, in addition to the inode * two bitmap buffers, and two group summaries, in addition to the inode
* and the superblock, which are already accounted for. */ * and the superblock, which are already accounted for. */
#define EXT3_XATTR_TRANS_BLOCKS 6U #define EXT4_XATTR_TRANS_BLOCKS 6U
/* Define the minimum size for a transaction which modifies data. This /* Define the minimum size for a transaction which modifies data. This
* needs to take into account the fact that we may end up modifying two * needs to take into account the fact that we may end up modifying two
...@@ -42,15 +42,15 @@ ...@@ -42,15 +42,15 @@
* superblock only gets updated once, of course, so don't bother * superblock only gets updated once, of course, so don't bother
* counting that again for the quota updates. */ * counting that again for the quota updates. */
#define EXT3_DATA_TRANS_BLOCKS(sb) (EXT3_SINGLEDATA_TRANS_BLOCKS + \ #define EXT4_DATA_TRANS_BLOCKS(sb) (EXT4_SINGLEDATA_TRANS_BLOCKS + \
EXT3_XATTR_TRANS_BLOCKS - 2 + \ EXT4_XATTR_TRANS_BLOCKS - 2 + \
2*EXT3_QUOTA_TRANS_BLOCKS(sb)) 2*EXT4_QUOTA_TRANS_BLOCKS(sb))
/* Delete operations potentially hit one directory's namespace plus an /* Delete operations potentially hit one directory's namespace plus an
* entire inode, plus arbitrary amounts of bitmap/indirection data. Be * entire inode, plus arbitrary amounts of bitmap/indirection data. Be
* generous. We can grow the delete transaction later if necessary. */ * generous. We can grow the delete transaction later if necessary. */
#define EXT3_DELETE_TRANS_BLOCKS(sb) (2 * EXT3_DATA_TRANS_BLOCKS(sb) + 64) #define EXT4_DELETE_TRANS_BLOCKS(sb) (2 * EXT4_DATA_TRANS_BLOCKS(sb) + 64)
/* Define an arbitrary limit for the amount of data we will anticipate /* Define an arbitrary limit for the amount of data we will anticipate
* writing to any given transaction. For unbounded transactions such as * writing to any given transaction. For unbounded transactions such as
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
* start off at the maximum transaction size and grow the transaction * start off at the maximum transaction size and grow the transaction
* optimistically as we go. */ * optimistically as we go. */
#define EXT3_MAX_TRANS_DATA 64U #define EXT4_MAX_TRANS_DATA 64U
/* We break up a large truncate or write transaction once the handle's /* We break up a large truncate or write transaction once the handle's
* buffer credits gets this low, we need either to extend the * buffer credits gets this low, we need either to extend the
...@@ -67,202 +67,202 @@ ...@@ -67,202 +67,202 @@
* one block, plus two quota updates. Quota allocations are not * one block, plus two quota updates. Quota allocations are not
* needed. */ * needed. */
#define EXT3_RESERVE_TRANS_BLOCKS 12U #define EXT4_RESERVE_TRANS_BLOCKS 12U
#define EXT3_INDEX_EXTRA_TRANS_BLOCKS 8 #define EXT4_INDEX_EXTRA_TRANS_BLOCKS 8
#ifdef CONFIG_QUOTA #ifdef CONFIG_QUOTA
/* Amount of blocks needed for quota update - we know that the structure was /* Amount of blocks needed for quota update - we know that the structure was
* allocated so we need to update only inode+data */ * allocated so we need to update only inode+data */
#define EXT3_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 2 : 0) #define EXT4_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 2 : 0)
/* Amount of blocks needed for quota insert/delete - we do some block writes /* Amount of blocks needed for quota insert/delete - we do some block writes
* but inode, sb and group updates are done only once */ * but inode, sb and group updates are done only once */
#define EXT3_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\ #define EXT4_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\
(EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_INIT_REWRITE) : 0) (EXT4_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_INIT_REWRITE) : 0)
#define EXT3_QUOTA_DEL_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_DEL_ALLOC*\ #define EXT4_QUOTA_DEL_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_DEL_ALLOC*\
(EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_DEL_REWRITE) : 0) (EXT4_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_DEL_REWRITE) : 0)
#else #else
#define EXT3_QUOTA_TRANS_BLOCKS(sb) 0 #define EXT4_QUOTA_TRANS_BLOCKS(sb) 0
#define EXT3_QUOTA_INIT_BLOCKS(sb) 0 #define EXT4_QUOTA_INIT_BLOCKS(sb) 0
#define EXT3_QUOTA_DEL_BLOCKS(sb) 0 #define EXT4_QUOTA_DEL_BLOCKS(sb) 0
#endif #endif
int int
ext3_mark_iloc_dirty(handle_t *handle, ext4_mark_iloc_dirty(handle_t *handle,
struct inode *inode, struct inode *inode,
struct ext3_iloc *iloc); struct ext4_iloc *iloc);
/* /*
* On success, We end up with an outstanding reference count against * On success, We end up with an outstanding reference count against
* iloc->bh. This _must_ be cleaned up later. * iloc->bh. This _must_ be cleaned up later.
*/ */
int ext3_reserve_inode_write(handle_t *handle, struct inode *inode, int ext4_reserve_inode_write(handle_t *handle, struct inode *inode,
struct ext3_iloc *iloc); struct ext4_iloc *iloc);
int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode); int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode);
/* /*
* Wrapper functions with which ext3 calls into JBD. The intent here is * Wrapper functions with which ext4 calls into JBD. The intent here is
* to allow these to be turned into appropriate stubs so ext3 can control * to allow these to be turned into appropriate stubs so ext4 can control
* ext2 filesystems, so ext2+ext3 systems only nee one fs. This work hasn't * ext2 filesystems, so ext2+ext4 systems only nee one fs. This work hasn't
* been done yet. * been done yet.
*/ */
void ext3_journal_abort_handle(const char *caller, const char *err_fn, void ext4_journal_abort_handle(const char *caller, const char *err_fn,
struct buffer_head *bh, handle_t *handle, int err); struct buffer_head *bh, handle_t *handle, int err);
static inline int static inline int
__ext3_journal_get_undo_access(const char *where, handle_t *handle, __ext4_journal_get_undo_access(const char *where, handle_t *handle,
struct buffer_head *bh) struct buffer_head *bh)
{ {
int err = journal_get_undo_access(handle, bh); int err = journal_get_undo_access(handle, bh);
if (err) if (err)
ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err); ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
return err; return err;
} }
static inline int static inline int
__ext3_journal_get_write_access(const char *where, handle_t *handle, __ext4_journal_get_write_access(const char *where, handle_t *handle,
struct buffer_head *bh) struct buffer_head *bh)
{ {
int err = journal_get_write_access(handle, bh); int err = journal_get_write_access(handle, bh);
if (err) if (err)
ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err); ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
return err; return err;
} }
static inline void static inline void
ext3_journal_release_buffer(handle_t *handle, struct buffer_head *bh) ext4_journal_release_buffer(handle_t *handle, struct buffer_head *bh)
{ {
journal_release_buffer(handle, bh); journal_release_buffer(handle, bh);
} }
static inline int static inline int
__ext3_journal_forget(const char *where, handle_t *handle, struct buffer_head *bh) __ext4_journal_forget(const char *where, handle_t *handle, struct buffer_head *bh)
{ {
int err = journal_forget(handle, bh); int err = journal_forget(handle, bh);
if (err) if (err)
ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err); ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
return err; return err;
} }
static inline int static inline int
__ext3_journal_revoke(const char *where, handle_t *handle, __ext4_journal_revoke(const char *where, handle_t *handle,
unsigned long blocknr, struct buffer_head *bh) unsigned long blocknr, struct buffer_head *bh)
{ {
int err = journal_revoke(handle, blocknr, bh); int err = journal_revoke(handle, blocknr, bh);
if (err) if (err)
ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err); ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
return err; return err;
} }
static inline int static inline int
__ext3_journal_get_create_access(const char *where, __ext4_journal_get_create_access(const char *where,
handle_t *handle, struct buffer_head *bh) handle_t *handle, struct buffer_head *bh)
{ {
int err = journal_get_create_access(handle, bh); int err = journal_get_create_access(handle, bh);
if (err) if (err)
ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err); ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
return err; return err;
} }
static inline int static inline int
__ext3_journal_dirty_metadata(const char *where, __ext4_journal_dirty_metadata(const char *where,
handle_t *handle, struct buffer_head *bh) handle_t *handle, struct buffer_head *bh)
{ {
int err = journal_dirty_metadata(handle, bh); int err = journal_dirty_metadata(handle, bh);
if (err) if (err)
ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err); ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
return err; return err;
} }
#define ext3_journal_get_undo_access(handle, bh) \ #define ext4_journal_get_undo_access(handle, bh) \
__ext3_journal_get_undo_access(__FUNCTION__, (handle), (bh)) __ext4_journal_get_undo_access(__FUNCTION__, (handle), (bh))
#define ext3_journal_get_write_access(handle, bh) \ #define ext4_journal_get_write_access(handle, bh) \
__ext3_journal_get_write_access(__FUNCTION__, (handle), (bh)) __ext4_journal_get_write_access(__FUNCTION__, (handle), (bh))
#define ext3_journal_revoke(handle, blocknr, bh) \ #define ext4_journal_revoke(handle, blocknr, bh) \
__ext3_journal_revoke(__FUNCTION__, (handle), (blocknr), (bh)) __ext4_journal_revoke(__FUNCTION__, (handle), (blocknr), (bh))
#define ext3_journal_get_create_access(handle, bh) \ #define ext4_journal_get_create_access(handle, bh) \
__ext3_journal_get_create_access(__FUNCTION__, (handle), (bh)) __ext4_journal_get_create_access(__FUNCTION__, (handle), (bh))
#define ext3_journal_dirty_metadata(handle, bh) \ #define ext4_journal_dirty_metadata(handle, bh) \
__ext3_journal_dirty_metadata(__FUNCTION__, (handle), (bh)) __ext4_journal_dirty_metadata(__FUNCTION__, (handle), (bh))
#define ext3_journal_forget(handle, bh) \ #define ext4_journal_forget(handle, bh) \
__ext3_journal_forget(__FUNCTION__, (handle), (bh)) __ext4_journal_forget(__FUNCTION__, (handle), (bh))
int ext3_journal_dirty_data(handle_t *handle, struct buffer_head *bh); int ext4_journal_dirty_data(handle_t *handle, struct buffer_head *bh);
handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks); handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks);
int __ext3_journal_stop(const char *where, handle_t *handle); int __ext4_journal_stop(const char *where, handle_t *handle);
static inline handle_t *ext3_journal_start(struct inode *inode, int nblocks) static inline handle_t *ext4_journal_start(struct inode *inode, int nblocks)
{ {
return ext3_journal_start_sb(inode->i_sb, nblocks); return ext4_journal_start_sb(inode->i_sb, nblocks);
} }
#define ext3_journal_stop(handle) \ #define ext4_journal_stop(handle) \
__ext3_journal_stop(__FUNCTION__, (handle)) __ext4_journal_stop(__FUNCTION__, (handle))
static inline handle_t *ext3_journal_current_handle(void) static inline handle_t *ext4_journal_current_handle(void)
{ {
return journal_current_handle(); return journal_current_handle();
} }
static inline int ext3_journal_extend(handle_t *handle, int nblocks) static inline int ext4_journal_extend(handle_t *handle, int nblocks)
{ {
return journal_extend(handle, nblocks); return journal_extend(handle, nblocks);
} }
static inline int ext3_journal_restart(handle_t *handle, int nblocks) static inline int ext4_journal_restart(handle_t *handle, int nblocks)
{ {
return journal_restart(handle, nblocks); return journal_restart(handle, nblocks);
} }
static inline int ext3_journal_blocks_per_page(struct inode *inode) static inline int ext4_journal_blocks_per_page(struct inode *inode)
{ {
return journal_blocks_per_page(inode); return journal_blocks_per_page(inode);
} }
static inline int ext3_journal_force_commit(journal_t *journal) static inline int ext4_journal_force_commit(journal_t *journal)
{ {
return journal_force_commit(journal); return journal_force_commit(journal);
} }
/* super.c */ /* super.c */
int ext3_force_commit(struct super_block *sb); int ext4_force_commit(struct super_block *sb);
static inline int ext3_should_journal_data(struct inode *inode) static inline int ext4_should_journal_data(struct inode *inode)
{ {
if (!S_ISREG(inode->i_mode)) if (!S_ISREG(inode->i_mode))
return 1; return 1;
if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA) if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
return 1; return 1;
if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL) if (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL)
return 1; return 1;
return 0; return 0;
} }
static inline int ext3_should_order_data(struct inode *inode) static inline int ext4_should_order_data(struct inode *inode)
{ {
if (!S_ISREG(inode->i_mode)) if (!S_ISREG(inode->i_mode))
return 0; return 0;
if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL) if (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL)
return 0; return 0;
if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA) if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
return 1; return 1;
return 0; return 0;
} }
static inline int ext3_should_writeback_data(struct inode *inode) static inline int ext4_should_writeback_data(struct inode *inode)
{ {
if (!S_ISREG(inode->i_mode)) if (!S_ISREG(inode->i_mode))
return 0; return 0;
if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL) if (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL)
return 0; return 0;
if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_WRITEBACK_DATA) if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
return 1; return 1;
return 0; return 0;
} }
#endif /* _LINUX_EXT3_JBD_H */ #endif /* _LINUX_EXT4_JBD_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册