ref: 1ba0937309fac055b6c0eb5bbcdbb6f7d0947e0f
parent: 1cfa0f2e3d86321b41a424074fa585d806f99e96
author: gkostka <kostka.grzegorz@gmail.com>
date: Tue Jun 16 06:00:41 EDT 2015
Stop generating Eclipse project files by default
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@
#Check: http://www.cmake.org/Wiki/CMake_Generator_Specific_Information
#"Unix Makefiles"
#"Eclipse CDT4 - Unix Makefiles"
-PROJECT_SETUP = "Eclipse CDT4 - Unix Makefiles"
+PROJECT_SETUP = "Unix Makefiles"
generic:
rm -R -f build_generic
@@ -67,4 +67,4 @@
-
\ No newline at end of file
+
--- a/lwext4/ext4_dir.h
+++ b/lwext4/ext4_dir.h
@@ -53,30 +53,28 @@
* @param de Directory entry
* @return I-node number
*/
-static inline uint32_t ext4_dir_entry_ll_get_inode(
- struct ext4_directory_entry_ll *de)
+static inline uint32_t
+ext4_dir_entry_ll_get_inode(struct ext4_directory_entry_ll *de)
{
return to_le32(de->inode);
}
-
/**@brief Set i-node number to directory entry.
* @param de Directory entry
* @param inode I-node number
*/
-static inline void ext4_dir_entry_ll_set_inode(
- struct ext4_directory_entry_ll *de, uint32_t inode)
+static inline void
+ext4_dir_entry_ll_set_inode(struct ext4_directory_entry_ll *de, uint32_t inode)
{
de->inode = to_le32(inode);
}
-
/**@brief Get directory entry length.
* @param de Directory entry
* @return Entry length
*/
-static inline uint16_t ext4_dir_entry_ll_get_entry_length(
- struct ext4_directory_entry_ll *de)
+static inline uint16_t
+ext4_dir_entry_ll_get_entry_length(struct ext4_directory_entry_ll *de)
{
return to_le16(de->entry_length);
}
@@ -85,25 +83,26 @@
* @param de Directory entry
* @param length Entry length
*/
-static inline void ext4_dir_entry_ll_set_entry_length(
- struct ext4_directory_entry_ll *de, uint16_t len)
+static inline void
+ext4_dir_entry_ll_set_entry_length(struct ext4_directory_entry_ll *de,
+ uint16_t len)
{
de->entry_length = to_le16(len);
}
-
/**@brief Get directory entry name length.
* @param sb Superblock
* @param de Directory entry
* @return Entry name length
*/
-static inline uint16_t ext4_dir_entry_ll_get_name_length(struct ext4_sblock *sb,
- struct ext4_directory_entry_ll *de)
+static inline uint16_t
+ext4_dir_entry_ll_get_name_length(struct ext4_sblock *sb,
+ struct ext4_directory_entry_ll *de)
{
uint16_t v = de->name_length;
if ((ext4_get32(sb, rev_level) == 0) &&
- (ext4_get32(sb, minor_rev_level) < 5))
+ (ext4_get32(sb, minor_rev_level) < 5))
v |= ((uint16_t)de->in.name_length_high) << 8;
return v;
@@ -114,27 +113,27 @@
* @param de Directory entry
* @param length Entry name length
*/
-static inline void ext4_dir_entry_ll_set_name_length(struct ext4_sblock *sb,
- struct ext4_directory_entry_ll *de, uint16_t len)
+static inline void ext4_dir_entry_ll_set_name_length(
+ struct ext4_sblock *sb, struct ext4_directory_entry_ll *de, uint16_t len)
{
de->name_length = (len << 8) >> 8;
if ((ext4_get32(sb, rev_level) == 0) &&
- (ext4_get32(sb, minor_rev_level) < 5))
+ (ext4_get32(sb, minor_rev_level) < 5))
de->in.name_length_high = len >> 8;
}
-
/**@brief Get i-node type of directory entry.
* @param sb Superblock
* @param de Directory entry
* @return I-node type (file, dir, etc.)
*/
-static inline uint8_t ext4_dir_entry_ll_get_inode_type(struct ext4_sblock *sb,
- struct ext4_directory_entry_ll *de)
+static inline uint8_t
+ext4_dir_entry_ll_get_inode_type(struct ext4_sblock *sb,
+ struct ext4_directory_entry_ll *de)
{
if ((ext4_get32(sb, rev_level) > 0) ||
- (ext4_get32(sb, minor_rev_level) >= 5))
+ (ext4_get32(sb, minor_rev_level) >= 5))
return de->in.inode_type;
return EXT4_DIRECTORY_FILETYPE_UNKNOWN;
@@ -145,11 +144,11 @@
* @param type I-node type (file, dir, etc.)
*/
-static inline void ext4_dir_entry_ll_set_inode_type(struct ext4_sblock *sb,
- struct ext4_directory_entry_ll *de, uint8_t type)
+static inline void ext4_dir_entry_ll_set_inode_type(
+ struct ext4_sblock *sb, struct ext4_directory_entry_ll *de, uint8_t type)
{
if ((ext4_get32(sb, rev_level) > 0) ||
- (ext4_get32(sb, minor_rev_level) >= 5))
+ (ext4_get32(sb, minor_rev_level) >= 5))
de->in.inode_type = type;
}
@@ -161,7 +160,7 @@
* @return Error code
*/
int ext4_dir_iterator_init(struct ext4_directory_iterator *it,
- struct ext4_inode_ref *inode_ref, uint64_t pos);
+ struct ext4_inode_ref *inode_ref, uint64_t pos);
/**@brief Jump to the next valid entry
* @param it Initialized iterator
@@ -185,8 +184,9 @@
* @param name_len Length of entry name
*/
void ext4_dir_write_entry(struct ext4_sblock *sb,
- struct ext4_directory_entry_ll *entry, uint16_t entry_len,
- struct ext4_inode_ref *child, const char *name, size_t name_len);
+ struct ext4_directory_entry_ll *entry,
+ uint16_t entry_len, struct ext4_inode_ref *child,
+ const char *name, size_t name_len);
/**@brief Add new entry to the directory.
* @param parent Directory i-node
@@ -195,7 +195,7 @@
* @return Error code
*/
int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,
- uint32_t name_len, struct ext4_inode_ref *child);
+ uint32_t name_len, struct ext4_inode_ref *child);
/**@brief Find directory entry with passed name.
* @param result Result structure to be returned if entry found
@@ -205,7 +205,8 @@
* @return Error code
*/
int ext4_dir_find_entry(struct ext4_directory_search_result *result,
- struct ext4_inode_ref *parent, const char *name, uint32_t name_len);
+ struct ext4_inode_ref *parent, const char *name,
+ uint32_t name_len);
/**@brief Remove directory entry.
* @param parent Directory i-node
@@ -214,7 +215,7 @@
* @return Error code
*/
int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,
- uint32_t name_len);
+ uint32_t name_len);
/**@brief Try to insert entry to concrete data block.
* @param sb Superblock
@@ -225,8 +226,9 @@
* @return Error code
*/
int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
- struct ext4_block *target_block, struct ext4_inode_ref *child,
- const char *name, uint32_t name_len);
+ struct ext4_block *target_block,
+ struct ext4_inode_ref *child, const char *name,
+ uint32_t name_len);
/**@brief Try to find entry in block by name.
* @param block Block containing entries
@@ -237,8 +239,8 @@
* @return Error code
*/
int ext4_dir_find_in_block(struct ext4_block *block, struct ext4_sblock *sb,
- size_t name_len, const char *name,
- struct ext4_directory_entry_ll **res_entry);
+ size_t name_len, const char *name,
+ struct ext4_directory_entry_ll **res_entry);
/**@brief Simple function to release allocated data from result.
* @param parent Parent inode
@@ -247,7 +249,7 @@
*
*/
int ext4_dir_destroy_result(struct ext4_inode_ref *parent,
- struct ext4_directory_search_result *result);
+ struct ext4_directory_search_result *result);
#endif /* EXT4_DIR_H_ */
@@ -254,5 +256,3 @@
/**
* @}
*/
-
-
--- a/lwext4/ext4_dir_idx.c
+++ b/lwext4/ext4_dir_idx.c
@@ -60,7 +60,7 @@
* @param v Hash algorithm version
*/
static inline void ext4_dir_dx_root_info_set_hash_version(
- struct ext4_directory_dx_root_info *root_info, uint8_t v)
+ struct ext4_directory_dx_root_info *root_info, uint8_t v)
{
root_info->hash_version = v;
}
@@ -80,7 +80,7 @@
* @param info_length Length of the structure
*/
static inline void ext4_dir_dx_root_info_set_info_length(
- struct ext4_directory_dx_root_info *root_info, uint8_t len)
+ struct ext4_directory_dx_root_info *root_info, uint8_t len)
{
root_info->info_length = len;
}
@@ -109,8 +109,8 @@
* @param climit Pointer to counlimit structure
* @return Maximum of entries in node
*/
-static inline uint16_t ext4_dir_dx_countlimit_get_limit(
- struct ext4_directory_dx_countlimit *climit)
+static inline uint16_t
+ext4_dir_dx_countlimit_get_limit(struct ext4_directory_dx_countlimit *climit)
{
return to_le16(climit->limit);
}
@@ -119,19 +119,19 @@
* @param climit Pointer to counlimit structure
* @param limit Maximum of entries in node
*/
-static inline void ext4_dir_dx_countlimit_set_limit(
- struct ext4_directory_dx_countlimit *climit, uint16_t limit)
+static inline void
+ext4_dir_dx_countlimit_set_limit(struct ext4_directory_dx_countlimit *climit,
+ uint16_t limit)
{
climit->limit = to_le16(limit);
}
-
/**@brief Get current number of index node entries.
* @param climit Pointer to counlimit structure
* @return Number of entries in node
*/
-static inline uint16_t ext4_dir_dx_countlimit_get_count(
- struct ext4_directory_dx_countlimit *climit)
+static inline uint16_t
+ext4_dir_dx_countlimit_get_count(struct ext4_directory_dx_countlimit *climit)
{
return to_le16(climit->count);
}
@@ -140,8 +140,9 @@
* @param climit Pointer to counlimit structure
* @param count Number of entries in node
*/
-static inline void ext4_dir_dx_countlimit_set_count(
- struct ext4_directory_dx_countlimit *climit, uint16_t count)
+static inline void
+ext4_dir_dx_countlimit_set_count(struct ext4_directory_dx_countlimit *climit,
+ uint16_t count)
{
climit->count = to_le16(count);
}
@@ -150,8 +151,8 @@
* @param entry Pointer to index entry
* @return Hash value
*/
-static inline uint32_t ext4_dir_dx_entry_get_hash(
- struct ext4_directory_dx_entry *entry)
+static inline uint32_t
+ext4_dir_dx_entry_get_hash(struct ext4_directory_dx_entry *entry)
{
return to_le32(entry->hash);
}
@@ -160,8 +161,8 @@
* @param entry Pointer to index entry
* @param hash Hash value
*/
-static inline void ext4_dir_dx_entry_set_hash(
- struct ext4_directory_dx_entry *entry, uint32_t hash)
+static inline void
+ext4_dir_dx_entry_set_hash(struct ext4_directory_dx_entry *entry, uint32_t hash)
{
entry->hash = to_le32(hash);
}
@@ -170,8 +171,8 @@
* @param entry Pointer to index entry
* @return Block address of child node
*/
-static inline uint32_t ext4_dir_dx_entry_get_block(
- struct ext4_directory_dx_entry *entry)
+static inline uint32_t
+ext4_dir_dx_entry_get_block(struct ext4_directory_dx_entry *entry)
{
return to_le32(entry->block);
}
@@ -180,29 +181,28 @@
* @param entry Pointer to index entry
* @param block Block address of child node
*/
-static inline void ext4_dir_dx_entry_set_block(
- struct ext4_directory_dx_entry *entry, uint32_t block)
+static inline void
+ext4_dir_dx_entry_set_block(struct ext4_directory_dx_entry *entry,
+ uint32_t block)
{
entry->block = to_le32(block);
}
/**@brief Sort entry item.*/
-struct ext4_dx_sort_entry {
+struct ext4_dx_sort_entry
+{
uint32_t hash;
uint32_t rec_len;
void *dentry;
};
-
static int ext4_dir_dx_hash_string(struct ext4_hash_info *hinfo, int len,
- const char *name)
+ const char *name)
{
return ext2_htree_hash(name, len, hinfo->seed, hinfo->hash_version,
- &hinfo->hash, &hinfo->minor_hash);
+ &hinfo->hash, &hinfo->minor_hash);
}
-
-
/****************************************************************************/
int ext4_dir_dx_init(struct ext4_inode_ref *dir)
@@ -209,8 +209,7 @@
{
/* Load block 0, where will be index root located */
uint32_t fblock;
- int rc = ext4_fs_get_inode_data_block_index(dir, 0,
- &fblock);
+ int rc = ext4_fs_get_inode_data_block_index(dir, 0, &fblock);
if (rc != EOK)
return rc;
@@ -232,15 +231,14 @@
/* Set limit and current number of entries */
struct ext4_directory_dx_countlimit *countlimit =
- (struct ext4_directory_dx_countlimit *) &root->entries;
+ (struct ext4_directory_dx_countlimit *)&root->entries;
ext4_dir_dx_countlimit_set_count(countlimit, 1);
- uint32_t block_size =
- ext4_sb_get_block_size(&dir->fs->sb);
- uint32_t entry_space =
- block_size - 2 * sizeof(struct ext4_directory_dx_dot_entry) -
- sizeof(struct ext4_directory_dx_root_info);
+ uint32_t block_size = ext4_sb_get_block_size(&dir->fs->sb);
+ uint32_t entry_space = block_size -
+ 2 * sizeof(struct ext4_directory_dx_dot_entry) -
+ sizeof(struct ext4_directory_dx_root_info);
uint16_t root_limit = entry_space / sizeof(struct ext4_directory_dx_entry);
ext4_dir_dx_countlimit_set_limit(countlimit, root_limit);
@@ -291,15 +289,16 @@
* @return Standard error code
*/
static int ext4_dir_hinfo_init(struct ext4_hash_info *hinfo,
- struct ext4_block *root_block, struct ext4_sblock *sb, size_t name_len,
- const char *name)
+ struct ext4_block *root_block,
+ struct ext4_sblock *sb, size_t name_len,
+ const char *name)
{
struct ext4_directory_dx_root *root =
- (struct ext4_directory_dx_root *) root_block->data;
+ (struct ext4_directory_dx_root *)root_block->data;
if ((root->info.hash_version != EXT2_HTREE_LEGACY) &&
- (root->info.hash_version != EXT2_HTREE_HALF_MD4) &&
- (root->info.hash_version != EXT2_HTREE_TEA))
+ (root->info.hash_version != EXT2_HTREE_HALF_MD4) &&
+ (root->info.hash_version != EXT2_HTREE_TEA))
return EXT4_ERR_BAD_DX_DIR;
/* Check unused flags */
@@ -318,15 +317,14 @@
entry_space = entry_space / sizeof(struct ext4_directory_dx_entry);
uint16_t limit = ext4_dir_dx_countlimit_get_limit(
- (struct ext4_directory_dx_countlimit *) &root->entries);
+ (struct ext4_directory_dx_countlimit *)&root->entries);
if (limit != entry_space)
return EXT4_ERR_BAD_DX_DIR;
/* Check hash version and modify if necessary */
- hinfo->hash_version =
- ext4_dir_dx_root_info_get_hash_version(&root->info);
+ hinfo->hash_version = ext4_dir_dx_root_info_get_hash_version(&root->info);
if ((hinfo->hash_version <= EXT2_HTREE_TEA) &&
- (ext4_sb_check_flag(sb, EXT4_SUPERBLOCK_FLAGS_UNSIGNED_HASH))) {
+ (ext4_sb_check_flag(sb, EXT4_SUPERBLOCK_FLAGS_UNSIGNED_HASH))) {
/* Use unsigned hash */
hinfo->hash_version += 3;
}
@@ -351,20 +349,21 @@
* @return Standard error code
*/
static int ext4_dir_dx_get_leaf(struct ext4_hash_info *hinfo,
- struct ext4_inode_ref *inode_ref, struct ext4_block *root_block,
- struct ext4_directory_dx_block **dx_block,
- struct ext4_directory_dx_block *dx_blocks)
+ struct ext4_inode_ref *inode_ref,
+ struct ext4_block *root_block,
+ struct ext4_directory_dx_block **dx_block,
+ struct ext4_directory_dx_block *dx_blocks)
{
struct ext4_directory_dx_block *tmp_dx_block = dx_blocks;
struct ext4_directory_dx_root *root =
- (struct ext4_directory_dx_root *) root_block->data;
+ (struct ext4_directory_dx_root *)root_block->data;
struct ext4_directory_dx_entry *entries =
- (struct ext4_directory_dx_entry *) &root->entries;
+ (struct ext4_directory_dx_entry *)&root->entries;
uint16_t limit = ext4_dir_dx_countlimit_get_limit(
- (struct ext4_directory_dx_countlimit *) entries);
+ (struct ext4_directory_dx_countlimit *)entries);
uint8_t indirect_level =
- ext4_dir_dx_root_info_get_indirect_levels(&root->info);
+ ext4_dir_dx_root_info_get_indirect_levels(&root->info);
struct ext4_block *tmp_block = root_block;
struct ext4_directory_dx_entry *p;
@@ -375,7 +374,7 @@
/* Walk through the index tree */
while (true) {
uint16_t count = ext4_dir_dx_countlimit_get_count(
- (struct ext4_directory_dx_countlimit *) entries);
+ (struct ext4_directory_dx_countlimit *)entries);
if ((count == 0) || (count > limit))
return EXT4_ERR_BAD_DX_DIR;
@@ -411,8 +410,8 @@
indirect_level--;
uint32_t fblock;
- int rc = ext4_fs_get_inode_data_block_index(inode_ref,
- next_block, &fblock);
+ int rc =
+ ext4_fs_get_inode_data_block_index(inode_ref, next_block, &fblock);
if (rc != EOK)
return rc;
@@ -420,13 +419,12 @@
if (rc != EOK)
return rc;
- entries = ((struct ext4_directory_dx_node *) tmp_block->data)->entries;
+ entries = ((struct ext4_directory_dx_node *)tmp_block->data)->entries;
limit = ext4_dir_dx_countlimit_get_limit(
- (struct ext4_directory_dx_countlimit *) entries);
+ (struct ext4_directory_dx_countlimit *)entries);
- uint16_t entry_space =
- ext4_sb_get_block_size(&inode_ref->fs->sb) -
- sizeof(struct ext4_fake_directory_entry);
+ uint16_t entry_space = ext4_sb_get_block_size(&inode_ref->fs->sb) -
+ sizeof(struct ext4_fake_directory_entry);
entry_space = entry_space / sizeof(struct ext4_directory_dx_entry);
@@ -450,8 +448,9 @@
* @return Standard Error codee
*/
static int ext4_dir_dx_next_block(struct ext4_inode_ref *inode_ref,
- uint32_t hash, struct ext4_directory_dx_block *dx_block,
- struct ext4_directory_dx_block *dx_blocks)
+ uint32_t hash,
+ struct ext4_directory_dx_block *dx_block,
+ struct ext4_directory_dx_block *dx_blocks)
{
uint32_t num_handles = 0;
struct ext4_directory_dx_block *p = dx_block;
@@ -460,7 +459,7 @@
while (true) {
p->position++;
uint16_t count = ext4_dir_dx_countlimit_get_count(
- (struct ext4_directory_dx_countlimit *) p->entries);
+ (struct ext4_directory_dx_countlimit *)p->entries);
if (p->position < p->entries + count)
break;
@@ -481,16 +480,14 @@
/* Fill new path */
while (num_handles--) {
- uint32_t block_idx =
- ext4_dir_dx_entry_get_block(p->position);
+ uint32_t block_idx = ext4_dir_dx_entry_get_block(p->position);
uint32_t block_addr;
- int rc = ext4_fs_get_inode_data_block_index(inode_ref,
- block_idx, &block_addr);
- if(rc != EOK)
+ int rc = ext4_fs_get_inode_data_block_index(inode_ref, block_idx,
+ &block_addr);
+ if (rc != EOK)
return rc;
-
struct ext4_block block;
rc = ext4_block_get(inode_ref->fs->bdev, &block, block_addr);
if (rc != EOK)
@@ -500,12 +497,11 @@
/* Don't forget to put old block (prevent memory leak) */
rc = ext4_block_set(inode_ref->fs->bdev, &p->block);
- if(rc != EOK)
+ if (rc != EOK)
return rc;
-
memcpy(&p->block, &p->block, sizeof(block));
- p->entries = ((struct ext4_directory_dx_node *) block.data)->entries;
+ p->entries = ((struct ext4_directory_dx_node *)block.data)->entries;
p->position = p->entries;
}
@@ -512,16 +508,14 @@
return ENOENT;
}
-
-
-int ext4_dir_dx_find_entry(struct ext4_directory_search_result * result,
- struct ext4_inode_ref *inode_ref, size_t name_len, const char *name)
+int ext4_dir_dx_find_entry(struct ext4_directory_search_result *result,
+ struct ext4_inode_ref *inode_ref, size_t name_len,
+ const char *name)
{
/* Load direct block 0 (index root) */
uint32_t root_block_addr;
int rc2;
- int rc = ext4_fs_get_inode_data_block_index(inode_ref, 0,
- &root_block_addr);
+ int rc = ext4_fs_get_inode_data_block_index(inode_ref, 0, &root_block_addr);
if (rc != EOK)
return rc;
@@ -534,8 +528,7 @@
/* Initialize hash info (compute hash value) */
struct ext4_hash_info hinfo;
- rc = ext4_dir_hinfo_init(&hinfo, &root_block, &fs->sb,
- name_len, name);
+ rc = ext4_dir_hinfo_init(&hinfo, &root_block, &fs->sb, name_len, name);
if (rc != EOK) {
ext4_block_set(fs->bdev, &root_block);
return EXT4_ERR_BAD_DX_DIR;
@@ -549,8 +542,8 @@
struct ext4_directory_dx_block *dx_block;
struct ext4_directory_dx_block *tmp;
- rc = ext4_dir_dx_get_leaf(&hinfo, inode_ref, &root_block,
- &dx_block, dx_blocks);
+ rc = ext4_dir_dx_get_leaf(&hinfo, inode_ref, &root_block, &dx_block,
+ dx_blocks);
if (rc != EOK) {
ext4_block_set(fs->bdev, &root_block);
return EXT4_ERR_BAD_DX_DIR;
@@ -559,11 +552,11 @@
do {
/* Load leaf block */
uint32_t leaf_block_idx =
- ext4_dir_dx_entry_get_block(dx_block->position);
+ ext4_dir_dx_entry_get_block(dx_block->position);
uint32_t leaf_block_addr;
- rc = ext4_fs_get_inode_data_block_index(inode_ref,
- leaf_block_idx, &leaf_block_addr);
+ rc = ext4_fs_get_inode_data_block_index(inode_ref, leaf_block_idx,
+ &leaf_block_addr);
if (rc != EOK)
goto cleanup;
@@ -574,8 +567,8 @@
/* Linear search inside block */
struct ext4_directory_entry_ll *res_dentry;
- rc = ext4_dir_find_in_block(&leaf_block, &fs->sb,
- name_len, name, &res_dentry);
+ rc = ext4_dir_find_in_block(&leaf_block, &fs->sb, name_len, name,
+ &res_dentry);
/* Found => return it */
if (rc == EOK) {
@@ -586,7 +579,7 @@
/* Not found, leave untouched */
rc2 = ext4_block_set(fs->bdev, &leaf_block);
- if(rc2 != EOK)
+ if (rc2 != EOK)
goto cleanup;
if (rc != ENOENT)
@@ -593,8 +586,8 @@
goto cleanup;
/* check if the next block could be checked */
- rc = ext4_dir_dx_next_block(inode_ref, hinfo.hash,
- dx_block, &dx_blocks[0]);
+ rc = ext4_dir_dx_next_block(inode_ref, hinfo.hash, dx_block,
+ &dx_blocks[0]);
if (rc < 0)
goto cleanup;
} while (rc == ENOENT);
@@ -617,36 +610,38 @@
}
#if CONFIG_DIR_INDEX_COMB_SORT
-#define SWAP_ENTRY(se1, se2) do { \
- struct ext4_dx_sort_entry tmp = se1; \
- se1 = se2; \
- se2 = tmp; \
-}while(0)
+#define SWAP_ENTRY(se1, se2) \
+ do { \
+ struct ext4_dx_sort_entry tmp = se1; \
+ se1 = se2; \
+ se2 = tmp; \
+ \
+} while (0)
static void comb_sort(struct ext4_dx_sort_entry *se, uint32_t count)
{
- struct ext4_dx_sort_entry *p, *q, *top = se + count - 1;
- bool more;
- /* Combsort */
- while (count > 2) {
- count = (count * 10) / 13;
- if (count - 9 < 2)
- count = 11;
- for (p = top, q = p - count; q >= se; p--, q--)
- if (p->hash < q->hash)
- SWAP_ENTRY(*p, *q);
- }
- /* Bubblesort */
- do {
- more = 0;
- q = top;
- while (q-- > se) {
- if (q[1].hash >= q[0].hash)
- continue;
- SWAP_ENTRY(*(q+1), *q);
- more = 1;
- }
- } while(more);
+ struct ext4_dx_sort_entry *p, *q, *top = se + count - 1;
+ bool more;
+ /* Combsort */
+ while (count > 2) {
+ count = (count * 10) / 13;
+ if (count - 9 < 2)
+ count = 11;
+ for (p = top, q = p - count; q >= se; p--, q--)
+ if (p->hash < q->hash)
+ SWAP_ENTRY(*p, *q);
+ }
+ /* Bubblesort */
+ do {
+ more = 0;
+ q = top;
+ while (q-- > se) {
+ if (q[1].hash >= q[0].hash)
+ continue;
+ SWAP_ENTRY(*(q + 1), *q);
+ more = 1;
+ }
+ } while (more);
}
#else
@@ -681,19 +676,20 @@
* @param iblock Logical number of child block
*
*/
-static void ext4_dir_dx_insert_entry(
- struct ext4_directory_dx_block *index_block, uint32_t hash,
- uint32_t iblock)
+static void
+ext4_dir_dx_insert_entry(struct ext4_directory_dx_block *index_block,
+ uint32_t hash, uint32_t iblock)
{
struct ext4_directory_dx_entry *old_index_entry = index_block->position;
struct ext4_directory_dx_entry *new_index_entry = old_index_entry + 1;
struct ext4_directory_dx_countlimit *countlimit =
- (struct ext4_directory_dx_countlimit *) index_block->entries;
+ (struct ext4_directory_dx_countlimit *)index_block->entries;
uint32_t count = ext4_dir_dx_countlimit_get_count(countlimit);
struct ext4_directory_dx_entry *start_index = index_block->entries;
- size_t bytes = (uint8_t *) (start_index + count) - (uint8_t *) (new_index_entry);
+ size_t bytes =
+ (uint8_t *)(start_index + count) - (uint8_t *)(new_index_entry);
memmove(new_index_entry + 1, new_index_entry, bytes);
@@ -713,15 +709,15 @@
* @param new_data_block Output value for newly allocated data block
*/
static int ext4_dir_dx_split_data(struct ext4_inode_ref *inode_ref,
- struct ext4_hash_info *hinfo, struct ext4_block *old_data_block,
- struct ext4_directory_dx_block *index_block,
- struct ext4_block *new_data_block)
+ struct ext4_hash_info *hinfo,
+ struct ext4_block *old_data_block,
+ struct ext4_directory_dx_block *index_block,
+ struct ext4_block *new_data_block)
{
int rc = EOK;
/* Allocate buffer for directory entries */
- uint32_t block_size =
- ext4_sb_get_block_size(&inode_ref->fs->sb);
+ uint32_t block_size = ext4_sb_get_block_size(&inode_ref->fs->sb);
uint8_t *entry_buffer = malloc(block_size);
if (entry_buffer == NULL)
@@ -729,11 +725,11 @@
/* dot entry has the smallest size available */
uint32_t max_entry_count =
- block_size / sizeof(struct ext4_directory_dx_dot_entry);
+ block_size / sizeof(struct ext4_directory_dx_dot_entry);
/* Allocate sort entry */
struct ext4_dx_sort_entry *sort_array =
- malloc(max_entry_count * sizeof(struct ext4_dx_sort_entry));
+ malloc(max_entry_count * sizeof(struct ext4_dx_sort_entry));
if (sort_array == NULL) {
free(entry_buffer);
@@ -753,11 +749,11 @@
while ((void *)dentry < (void *)(old_data_block->data + block_size)) {
/* Read only valid entries */
if (ext4_dir_entry_ll_get_inode(dentry) && dentry->name_length) {
- uint8_t len = ext4_dir_entry_ll_get_name_length(
- &inode_ref->fs->sb, dentry);
+ uint8_t len =
+ ext4_dir_entry_ll_get_name_length(&inode_ref->fs->sb, dentry);
- rc = ext4_dir_dx_hash_string(&tmp_hinfo, len, (char*)dentry->name);
- if(rc != EOK) {
+ rc = ext4_dir_dx_hash_string(&tmp_hinfo, len, (char *)dentry->name);
+ if (rc != EOK) {
free(sort_array);
free(entry_buffer);
return rc;
@@ -780,21 +776,20 @@
}
dentry = (void *)((uint8_t *)dentry +
- ext4_dir_entry_ll_get_entry_length(dentry));
+ ext4_dir_entry_ll_get_entry_length(dentry));
}
- /* Sort all entries */
+/* Sort all entries */
#if CONFIG_DIR_INDEX_COMB_SORT
comb_sort(sort_array, idx);
#else
qsort(sort_array, idx, sizeof(struct ext4_dx_sort_entry),
- ext4_dir_dx_entry_comparator);
+ ext4_dir_dx_entry_comparator);
#endif
/* Allocate new block for store the second part of entries */
uint32_t new_fblock;
uint32_t new_iblock;
- rc = ext4_fs_append_inode_block(inode_ref, &new_fblock,
- &new_iblock);
+ rc = ext4_fs_append_inode_block(inode_ref, &new_fblock, &new_iblock);
if (rc != EOK) {
free(sort_array);
free(entry_buffer);
@@ -803,8 +798,7 @@
/* Load new block */
struct ext4_block new_data_block_tmp;
- rc = ext4_block_get(inode_ref->fs->bdev, &new_data_block_tmp,
- new_fblock);
+ rc = ext4_block_get(inode_ref->fs->bdev, &new_data_block_tmp, new_fblock);
if (rc != EOK) {
free(sort_array);
free(entry_buffer);
@@ -819,7 +813,7 @@
uint32_t current_size = 0;
uint32_t mid = 0;
uint32_t i;
- for ( i = 0; i < idx; ++i) {
+ for (i = 0; i < idx; ++i) {
if ((current_size + sort_array[i].rec_len) > (block_size / 2)) {
new_hash = sort_array[i].hash;
mid = i;
@@ -831,7 +825,7 @@
/* Check hash collision */
uint32_t continued = 0;
- if (new_hash == sort_array[mid-1].hash)
+ if (new_hash == sort_array[mid - 1].hash)
continued = 1;
uint32_t offset = 0;
@@ -844,11 +838,9 @@
struct ext4_directory_entry_ll *tmp = ptr;
if (i < (mid - 1))
- ext4_dir_entry_ll_set_entry_length(tmp,
- sort_array[i].rec_len);
+ ext4_dir_entry_ll_set_entry_length(tmp, sort_array[i].rec_len);
else
- ext4_dir_entry_ll_set_entry_length(tmp,
- block_size - offset);
+ ext4_dir_entry_ll_set_entry_length(tmp, block_size - offset);
offset += sort_array[i].rec_len;
}
@@ -861,11 +853,9 @@
struct ext4_directory_entry_ll *tmp = ptr;
if (i < (idx - 1))
- ext4_dir_entry_ll_set_entry_length(tmp,
- sort_array[i].rec_len);
+ ext4_dir_entry_ll_set_entry_length(tmp, sort_array[i].rec_len);
else
- ext4_dir_entry_ll_set_entry_length(tmp,
- block_size - offset);
+ ext4_dir_entry_ll_set_entry_length(tmp, block_size - offset);
offset += sort_array[i].rec_len;
}
@@ -877,8 +867,7 @@
free(sort_array);
free(entry_buffer);
- ext4_dir_dx_insert_entry(index_block, new_hash + continued,
- new_iblock);
+ ext4_dir_dx_insert_entry(index_block, new_hash + continued, new_iblock);
*new_data_block = new_data_block_tmp;
@@ -891,27 +880,26 @@
* @param dx_block Leaf block to be split if needed
* @return Error code
*/
-static int ext4_dir_dx_split_index(struct ext4_inode_ref *inode_ref,
- struct ext4_directory_dx_block *dx_blocks,
- struct ext4_directory_dx_block *dx_block,
- struct ext4_directory_dx_block **new_dx_block)
+static int
+ext4_dir_dx_split_index(struct ext4_inode_ref *inode_ref,
+ struct ext4_directory_dx_block *dx_blocks,
+ struct ext4_directory_dx_block *dx_block,
+ struct ext4_directory_dx_block **new_dx_block)
{
struct ext4_directory_dx_entry *entries;
if (dx_block == dx_blocks)
entries =
- ((struct ext4_directory_dx_root *) dx_block->block.data)->entries;
+ ((struct ext4_directory_dx_root *)dx_block->block.data)->entries;
else
entries =
- ((struct ext4_directory_dx_node *) dx_block->block.data)->entries;
+ ((struct ext4_directory_dx_node *)dx_block->block.data)->entries;
struct ext4_directory_dx_countlimit *countlimit =
- (struct ext4_directory_dx_countlimit *) entries;
+ (struct ext4_directory_dx_countlimit *)entries;
- uint16_t leaf_limit =
- ext4_dir_dx_countlimit_get_limit(countlimit);
- uint16_t leaf_count =
- ext4_dir_dx_countlimit_get_count(countlimit);
+ uint16_t leaf_limit = ext4_dir_dx_countlimit_get_limit(countlimit);
+ uint16_t leaf_count = ext4_dir_dx_countlimit_get_count(countlimit);
/* Check if is necessary to split index block */
if (leaf_limit == leaf_count) {
@@ -918,14 +906,12 @@
size_t levels = dx_block - dx_blocks;
struct ext4_directory_dx_entry *root_entries =
- ((struct ext4_directory_dx_root *) dx_blocks[0].block.data)->entries;
+ ((struct ext4_directory_dx_root *)dx_blocks[0].block.data)->entries;
struct ext4_directory_dx_countlimit *root_countlimit =
- (struct ext4_directory_dx_countlimit *) root_entries;
- uint16_t root_limit =
- ext4_dir_dx_countlimit_get_limit(root_countlimit);
- uint16_t root_count =
- ext4_dir_dx_countlimit_get_count(root_countlimit);
+ (struct ext4_directory_dx_countlimit *)root_entries;
+ uint16_t root_limit = ext4_dir_dx_countlimit_get_limit(root_countlimit);
+ uint16_t root_count = ext4_dir_dx_countlimit_get_count(root_countlimit);
/* Linux limitation */
if ((levels > 0) && (root_limit == root_count))
@@ -934,25 +920,23 @@
/* Add new block to directory */
uint32_t new_fblock;
uint32_t new_iblock;
- int rc = ext4_fs_append_inode_block(inode_ref,
- &new_fblock, &new_iblock);
+ int rc =
+ ext4_fs_append_inode_block(inode_ref, &new_fblock, &new_iblock);
if (rc != EOK)
return rc;
/* load new block */
struct ext4_block new_block;
- rc = ext4_block_get(inode_ref->fs->bdev, &new_block,
- new_fblock);
+ rc = ext4_block_get(inode_ref->fs->bdev, &new_block, new_fblock);
if (rc != EOK)
return rc;
- struct ext4_directory_dx_node *new_node = (void *)new_block.data;
+ struct ext4_directory_dx_node *new_node = (void *)new_block.data;
struct ext4_directory_dx_entry *new_entries = new_node->entries;
memset(&new_node->fake, 0, sizeof(struct ext4_fake_directory_entry));
- uint32_t block_size =
- ext4_sb_get_block_size(&inode_ref->fs->sb);
+ uint32_t block_size = ext4_sb_get_block_size(&inode_ref->fs->sb);
new_node->fake.entry_length = block_size;
@@ -961,25 +945,25 @@
uint32_t count_left = leaf_count / 2;
uint32_t count_right = leaf_count - count_left;
uint32_t hash_right =
- ext4_dir_dx_entry_get_hash(entries + count_left);
+ ext4_dir_dx_entry_get_hash(entries + count_left);
/* Copy data to new node */
- memcpy((void *) new_entries, (void *) (entries + count_left),
- count_right * sizeof(struct ext4_directory_dx_entry));
+ memcpy((void *)new_entries, (void *)(entries + count_left),
+ count_right * sizeof(struct ext4_directory_dx_entry));
/* Initialize new node */
struct ext4_directory_dx_countlimit *left_countlimit =
- (struct ext4_directory_dx_countlimit *) entries;
+ (struct ext4_directory_dx_countlimit *)entries;
struct ext4_directory_dx_countlimit *right_countlimit =
- (struct ext4_directory_dx_countlimit *) new_entries;
+ (struct ext4_directory_dx_countlimit *)new_entries;
ext4_dir_dx_countlimit_set_count(left_countlimit, count_left);
ext4_dir_dx_countlimit_set_count(right_countlimit, count_right);
uint32_t entry_space =
- block_size - sizeof(struct ext4_fake_directory_entry);
+ block_size - sizeof(struct ext4_fake_directory_entry);
uint32_t node_limit =
- entry_space / sizeof(struct ext4_directory_dx_entry);
+ entry_space / sizeof(struct ext4_directory_dx_entry);
ext4_dir_dx_countlimit_set_limit(right_countlimit, node_limit);
/* Which index block is target for new entry */
@@ -989,11 +973,9 @@
struct ext4_block block_tmp = dx_block->block;
-
dx_block->block = new_block;
- dx_block->position =
- new_entries + position_index - count_left;
+ dx_block->position = new_entries + position_index - count_left;
dx_block->entries = new_entries;
new_block = block_tmp;
@@ -1010,27 +992,27 @@
/* Create second level index */
/* Copy data from root to child block */
- memcpy((void *) new_entries, (void *) entries,
- leaf_count * sizeof(struct ext4_directory_dx_entry));
+ memcpy((void *)new_entries, (void *)entries,
+ leaf_count * sizeof(struct ext4_directory_dx_entry));
struct ext4_directory_dx_countlimit *new_countlimit =
- (struct ext4_directory_dx_countlimit *) new_entries;
+ (struct ext4_directory_dx_countlimit *)new_entries;
uint32_t entry_space =
- block_size - sizeof(struct ext4_fake_directory_entry);
+ block_size - sizeof(struct ext4_fake_directory_entry);
uint32_t node_limit =
- entry_space / sizeof(struct ext4_directory_dx_entry);
+ entry_space / sizeof(struct ext4_directory_dx_entry);
ext4_dir_dx_countlimit_set_limit(new_countlimit, node_limit);
/* Set values in root node */
struct ext4_directory_dx_countlimit *new_root_countlimit =
- (struct ext4_directory_dx_countlimit *) entries;
+ (struct ext4_directory_dx_countlimit *)entries;
ext4_dir_dx_countlimit_set_count(new_root_countlimit, 1);
ext4_dir_dx_entry_set_block(entries, new_iblock);
- ((struct ext4_directory_dx_root *)
- dx_blocks[0].block.data)->info.indirect_levels = 1;
+ ((struct ext4_directory_dx_root *)dx_blocks[0].block.data)
+ ->info.indirect_levels = 1;
/* Add new entry to the path */
dx_block = dx_blocks + 1;
@@ -1049,14 +1031,13 @@
}
int ext4_dir_dx_add_entry(struct ext4_inode_ref *parent,
- struct ext4_inode_ref *child, const char *name)
+ struct ext4_inode_ref *child, const char *name)
{
int rc2 = EOK;
/* Get direct block 0 (index root) */
uint32_t root_block_addr;
- int rc = ext4_fs_get_inode_data_block_index(parent, 0,
- &root_block_addr);
+ int rc = ext4_fs_get_inode_data_block_index(parent, 0, &root_block_addr);
if (rc != EOK)
return rc;
@@ -1070,8 +1051,7 @@
/* Initialize hinfo structure (mainly compute hash) */
uint32_t name_len = strlen(name);
struct ext4_hash_info hinfo;
- rc = ext4_dir_hinfo_init(&hinfo, &root_block, &fs->sb,
- name_len, name);
+ rc = ext4_dir_hinfo_init(&hinfo, &root_block, &fs->sb, name_len, name);
if (rc != EOK) {
ext4_block_set(fs->bdev, &root_block);
return EXT4_ERR_BAD_DX_DIR;
@@ -1085,8 +1065,8 @@
struct ext4_directory_dx_block *dx_block;
struct ext4_directory_dx_block *dx_it;
- rc = ext4_dir_dx_get_leaf(&hinfo, parent, &root_block,
- &dx_block, dx_blocks);
+ rc =
+ ext4_dir_dx_get_leaf(&hinfo, parent, &root_block, &dx_block, dx_blocks);
if (rc != EOK) {
rc = EXT4_ERR_BAD_DX_DIR;
goto release_index;
@@ -1093,11 +1073,10 @@
}
/* Try to insert to existing data block */
- uint32_t leaf_block_idx =
- ext4_dir_dx_entry_get_block(dx_block->position);
+ uint32_t leaf_block_idx = ext4_dir_dx_entry_get_block(dx_block->position);
uint32_t leaf_block_addr;
rc = ext4_fs_get_inode_data_block_index(parent, leaf_block_idx,
- &leaf_block_addr);
+ &leaf_block_addr);
if (rc != EOK)
goto release_index;
@@ -1114,18 +1093,16 @@
if (rc != EOK)
goto release_index;
-
/* Check if insert operation passed */
- rc = ext4_dir_try_insert_entry(&fs->sb, &target_block, child,
- name, name_len);
+ rc = ext4_dir_try_insert_entry(&fs->sb, &target_block, child, name,
+ name_len);
if (rc == EOK)
goto release_target_index;
-
/* Split entries to two blocks (includes sorting by hash value) */
struct ext4_block new_block;
- rc = ext4_dir_dx_split_data(parent, &hinfo, &target_block,
- dx_block, &new_block);
+ rc = ext4_dir_dx_split_data(parent, &hinfo, &target_block, dx_block,
+ &new_block);
if (rc != EOK) {
rc2 = rc;
goto release_target_index;
@@ -1133,13 +1110,13 @@
/* Where to save new entry */
uint32_t new_block_hash =
- ext4_dir_dx_entry_get_hash(dx_block->position + 1);
+ ext4_dir_dx_entry_get_hash(dx_block->position + 1);
if (hinfo.hash >= new_block_hash)
- rc = ext4_dir_try_insert_entry(&fs->sb, &new_block,
- child, name, name_len);
+ rc = ext4_dir_try_insert_entry(&fs->sb, &new_block, child, name,
+ name_len);
else
- rc = ext4_dir_try_insert_entry(&fs->sb, &target_block,
- child, name, name_len);
+ rc = ext4_dir_try_insert_entry(&fs->sb, &target_block, child, name,
+ name_len);
/* Cleanup */
rc = ext4_block_set(fs->bdev, &new_block);
@@ -1146,9 +1123,9 @@
if (rc != EOK)
return rc;
- /* Cleanup operations */
+/* Cleanup operations */
- release_target_index:
+release_target_index:
rc2 = rc;
rc = ext4_block_set(fs->bdev, &target_block);
@@ -1155,7 +1132,7 @@
if (rc != EOK)
return rc;
- release_index:
+release_index:
if (rc != EOK)
rc2 = rc;
@@ -1175,4 +1152,3 @@
/**
* @}
*/
-
--- a/lwext4/ext4_dir_idx.h
+++ b/lwext4/ext4_dir_idx.h
@@ -62,8 +62,9 @@
* @param name Name to be found
* @return Error code
*/
-int ext4_dir_dx_find_entry(struct ext4_directory_search_result * result,
- struct ext4_inode_ref *inode_ref, size_t name_len, const char *name);
+int ext4_dir_dx_find_entry(struct ext4_directory_search_result *result,
+ struct ext4_inode_ref *inode_ref, size_t name_len,
+ const char *name);
/**@brief Add new entry to indexed directory
* @param parent Directory i-node
@@ -72,7 +73,7 @@
* @return Error code
*/
int ext4_dir_dx_add_entry(struct ext4_inode_ref *parent,
- struct ext4_inode_ref *child, const char *name);
+ struct ext4_inode_ref *child, const char *name);
#endif /* EXT4_DIR_IDX_H_ */
@@ -79,4 +80,3 @@
/**
* @}
*/
-
--- a/lwext4/ext4_errno.h
+++ b/lwext4/ext4_errno.h
@@ -41,49 +41,49 @@
#if !CONFIG_HAVE_OWN_ERRNO
#include <errno.h>
#else
-#define EPERM 1 /* Operation not permitted */
-#define ENOENT 2 /* No such file or directory */
-#define ESRCH 3 /* No such process */
-#define EINTR 4 /* Interrupted system call */
-#define EIO 5 /* I/O error */
-#define ENXIO 6 /* No such device or address */
-#define E2BIG 7 /* Argument list too long */
-#define ENOEXEC 8 /* Exec format error */
-#define EBADF 9 /* Bad file number */
-#define ECHILD 10 /* No child processes */
-#define EAGAIN 11 /* Try again */
-#define ENOMEM 12 /* Out of memory */
-#define EACCES 13 /* Permission denied */
-#define EFAULT 14 /* Bad address */
-#define ENOTBLK 15 /* Block device required */
-#define EBUSY 16 /* Device or resource busy */
-#define EEXIST 17 /* File exists */
-#define EXDEV 18 /* Cross-device link */
-#define ENODEV 19 /* No such device */
-#define ENOTDIR 20 /* Not a directory */
-#define EISDIR 21 /* Is a directory */
-#define EINVAL 22 /* Invalid argument */
-#define ENFILE 23 /* File table overflow */
-#define EMFILE 24 /* Too many open files */
-#define ENOTTY 25 /* Not a typewriter */
-#define ETXTBSY 26 /* Text file busy */
-#define EFBIG 27 /* File too large */
-#define ENOSPC 28 /* No space left on device */
-#define ESPIPE 29 /* Illegal seek */
-#define EROFS 30 /* Read-only file system */
-#define EMLINK 31 /* Too many links */
-#define EPIPE 32 /* Broken pipe */
-#define EDOM 33 /* Math argument out of domain of func */
-#define ERANGE 34 /* Math result not representable */
-#define ENOTSUP 95 /* Not supported */
+#define EPERM 1 /* Operation not permitted */
+#define ENOENT 2 /* No such file or directory */
+#define ESRCH 3 /* No such process */
+#define EINTR 4 /* Interrupted system call */
+#define EIO 5 /* I/O error */
+#define ENXIO 6 /* No such device or address */
+#define E2BIG 7 /* Argument list too long */
+#define ENOEXEC 8 /* Exec format error */
+#define EBADF 9 /* Bad file number */
+#define ECHILD 10 /* No child processes */
+#define EAGAIN 11 /* Try again */
+#define ENOMEM 12 /* Out of memory */
+#define EACCES 13 /* Permission denied */
+#define EFAULT 14 /* Bad address */
+#define ENOTBLK 15 /* Block device required */
+#define EBUSY 16 /* Device or resource busy */
+#define EEXIST 17 /* File exists */
+#define EXDEV 18 /* Cross-device link */
+#define ENODEV 19 /* No such device */
+#define ENOTDIR 20 /* Not a directory */
+#define EISDIR 21 /* Is a directory */
+#define EINVAL 22 /* Invalid argument */
+#define ENFILE 23 /* File table overflow */
+#define EMFILE 24 /* Too many open files */
+#define ENOTTY 25 /* Not a typewriter */
+#define ETXTBSY 26 /* Text file busy */
+#define EFBIG 27 /* File too large */
+#define ENOSPC 28 /* No space left on device */
+#define ESPIPE 29 /* Illegal seek */
+#define EROFS 30 /* Read-only file system */
+#define EMLINK 31 /* Too many links */
+#define EPIPE 32 /* Broken pipe */
+#define EDOM 33 /* Math argument out of domain of func */
+#define ERANGE 34 /* Math result not representable */
+#define ENOTSUP 95 /* Not supported */
#endif
#ifndef ENOTSUP
-#define ENOTSUP 95
+#define ENOTSUP 95
#endif
#ifndef EOK
-#define EOK 0
+#define EOK 0
#endif
#endif /* EXT4_ERRNO_H_ */
--- a/lwext4/ext4_extent.c
+++ b/lwext4/ext4_extent.c
@@ -54,32 +54,27 @@
return to_le32(extent->first_block);
}
-
void ext4_extent_set_first_block(struct ext4_extent *extent, uint32_t iblock)
{
extent->first_block = to_le32(iblock);
}
-
uint16_t ext4_extent_get_block_count(struct ext4_extent *extent)
{
return to_le16(extent->block_count);
}
-
void ext4_extent_set_block_count(struct ext4_extent *extent, uint16_t count)
{
extent->block_count = to_le16(count);
}
-
uint64_t ext4_extent_get_start(struct ext4_extent *extent)
{
return ((uint64_t)to_le16(extent->start_hi)) << 32 |
- ((uint64_t)to_le32(extent->start_lo));
+ ((uint64_t)to_le32(extent->start_lo));
}
-
void ext4_extent_set_start(struct ext4_extent *extent, uint64_t fblock)
{
extent->start_lo = to_le32((fblock << 32) >> 32);
@@ -86,94 +81,82 @@
extent->start_hi = to_le16((uint16_t)(fblock >> 32));
}
-
uint32_t ext4_extent_index_get_first_block(struct ext4_extent_index *index)
{
return to_le32(index->first_block);
}
-
void ext4_extent_index_set_first_block(struct ext4_extent_index *index,
- uint32_t iblock)
+ uint32_t iblock)
{
index->first_block = to_le32(iblock);
}
-
uint64_t ext4_extent_index_get_leaf(struct ext4_extent_index *index)
{
- return ((uint64_t) to_le16(index->leaf_hi)) << 32 |
- ((uint64_t)to_le32(index->leaf_lo));
+ return ((uint64_t)to_le16(index->leaf_hi)) << 32 |
+ ((uint64_t)to_le32(index->leaf_lo));
}
void ext4_extent_index_set_leaf(struct ext4_extent_index *index,
- uint64_t fblock)
+ uint64_t fblock)
{
index->leaf_lo = to_le32((fblock << 32) >> 32);
- index->leaf_hi = to_le16((uint16_t) (fblock >> 32));
+ index->leaf_hi = to_le16((uint16_t)(fblock >> 32));
}
-
uint16_t ext4_extent_header_get_magic(struct ext4_extent_header *header)
{
return to_le16(header->magic);
}
-
void ext4_extent_header_set_magic(struct ext4_extent_header *header,
- uint16_t magic)
+ uint16_t magic)
{
header->magic = to_le16(magic);
}
-
uint16_t ext4_extent_header_get_entries_count(struct ext4_extent_header *header)
{
return to_le16(header->entries_count);
}
-
void ext4_extent_header_set_entries_count(struct ext4_extent_header *header,
- uint16_t count)
+ uint16_t count)
{
header->entries_count = to_le16(count);
}
-
-uint16_t ext4_extent_header_get_max_entries_count(struct ext4_extent_header *header)
+uint16_t
+ext4_extent_header_get_max_entries_count(struct ext4_extent_header *header)
{
return to_le16(header->max_entries_count);
}
-
void ext4_extent_header_set_max_entries_count(struct ext4_extent_header *header,
- uint16_t max_count)
+ uint16_t max_count)
{
header->max_entries_count = to_le16(max_count);
}
-
uint16_t ext4_extent_header_get_depth(struct ext4_extent_header *header)
{
return to_le16(header->depth);
}
-
void ext4_extent_header_set_depth(struct ext4_extent_header *header,
- uint16_t depth)
+ uint16_t depth)
{
header->depth = to_le16(depth);
}
-
uint32_t ext4_extent_header_get_generation(struct ext4_extent_header *header)
{
return to_le32(header->generation);
}
-
void ext4_extent_header_set_generation(struct ext4_extent_header *header,
- uint32_t generation)
+ uint32_t generation)
{
header->generation = to_le32(generation);
}
@@ -183,14 +166,14 @@
* @param index Output value - found index will be set here
* @param iblock Logical block number to find in index node */
static void ext4_extent_binsearch_idx(struct ext4_extent_header *header,
- struct ext4_extent_index **index, uint32_t iblock)
+ struct ext4_extent_index **index,
+ uint32_t iblock)
{
struct ext4_extent_index *r;
struct ext4_extent_index *l;
struct ext4_extent_index *m;
- uint16_t entries_count =
- ext4_extent_header_get_entries_count(header);
+ uint16_t entries_count = ext4_extent_header_get_entries_count(header);
/* Initialize bounds */
l = EXT4_EXTENT_FIRST_INDEX(header) + 1;
@@ -217,14 +200,13 @@
* or NULL if node is empty
* @param iblock Logical block number to find in leaf node */
static void ext4_extent_binsearch(struct ext4_extent_header *header,
- struct ext4_extent **extent, uint32_t iblock)
+ struct ext4_extent **extent, uint32_t iblock)
{
struct ext4_extent *r;
struct ext4_extent *l;
struct ext4_extent *m;
- uint16_t entries_count =
- ext4_extent_header_get_entries_count(header);
+ uint16_t entries_count = ext4_extent_header_get_entries_count(header);
if (entries_count == 0) {
/* this leaf is empty */
@@ -251,9 +233,8 @@
*extent = l - 1;
}
-
int ext4_extent_find_block(struct ext4_inode_ref *inode_ref, uint32_t iblock,
- uint32_t *fblock)
+ uint32_t *fblock)
{
int rc;
/* Compute bound defined by i-node size */
@@ -260,8 +241,7 @@
uint64_t inode_size =
ext4_inode_get_size(&inode_ref->fs->sb, inode_ref->inode);
- uint32_t block_size =
- ext4_sb_get_block_size(&inode_ref->fs->sb);
+ uint32_t block_size = ext4_sb_get_block_size(&inode_ref->fs->sb);
uint32_t last_idx = (inode_size - 1) / block_size;
@@ -286,13 +266,12 @@
/* Load child node and set values for the next iteration */
uint64_t child = ext4_extent_index_get_leaf(index);
- if (block.lb_id){
+ if (block.lb_id) {
rc = ext4_block_set(inode_ref->fs->bdev, &block);
- if(rc != EOK)
+ if (rc != EOK)
return rc;
}
-
int rc = ext4_block_get(inode_ref->fs->bdev, &block, child);
if (rc != EOK)
return rc;
@@ -301,7 +280,7 @@
}
/* Search extent in the leaf block */
- struct ext4_extent* extent = NULL;
+ struct ext4_extent *extent = NULL;
ext4_extent_binsearch(header, &extent, iblock);
/* Prevent empty leaf */
@@ -317,9 +296,9 @@
}
/* Cleanup */
- if (block.lb_id){
+ if (block.lb_id) {
rc = ext4_block_set(inode_ref->fs->bdev, &block);
- if(rc != EOK)
+ if (rc != EOK)
return rc;
}
@@ -334,7 +313,8 @@
* @param ret_path Output value for loaded path from extent tree
* @return Error code */
static int ext4_extent_find_extent(struct ext4_inode_ref *inode_ref,
- uint32_t iblock, struct ext4_extent_path **ret_path)
+ uint32_t iblock,
+ struct ext4_extent_path **ret_path)
{
struct ext4_extent_header *eh =
ext4_inode_get_extent_header(inode_ref->inode);
@@ -357,8 +337,8 @@
int rc;
while (ext4_extent_header_get_depth(eh) != 0) {
/* Search index in index node by iblock */
- ext4_extent_binsearch_idx(tmp_path[pos].header,
- &tmp_path[pos].index, iblock);
+ ext4_extent_binsearch_idx(tmp_path[pos].header, &tmp_path[pos].index,
+ iblock);
tmp_path[pos].depth = depth;
tmp_path[pos].extent = NULL;
@@ -396,9 +376,9 @@
* From 1: 0 is a block with inode data
*/
for (i = 1; i < tmp_path->depth; ++i) {
- if (tmp_path[i].block.lb_id){
+ if (tmp_path[i].block.lb_id) {
int r = ext4_block_set(inode_ref->fs->bdev, &tmp_path[i].block);
- if(r != EOK)
+ if (r != EOK)
rc = r;
}
}
@@ -414,7 +394,7 @@
* @param extent Extent to release
* @return Error code */
static int ext4_extent_release(struct ext4_inode_ref *inode_ref,
- struct ext4_extent *extent)
+ struct ext4_extent *extent)
{
/* Compute number of the first physical block to release */
uint64_t start = ext4_extent_get_start(extent);
@@ -431,7 +411,7 @@
* with the whole subtree
* @return Error code */
static int ext4_extent_release_branch(struct ext4_inode_ref *inode_ref,
- struct ext4_extent_index *index)
+ struct ext4_extent_index *index)
{
uint32_t fblock = ext4_extent_index_get_leaf(index);
uint32_t i;
@@ -448,7 +428,7 @@
/* Release all subbranches */
for (i = 0; i < ext4_extent_header_get_entries_count(header);
- ++i, ++idx) {
+ ++i, ++idx) {
rc = ext4_extent_release_branch(inode_ref, idx);
if (rc != EOK)
return rc;
@@ -459,7 +439,7 @@
/* Release all extents and stop recursion */
for (i = 0; i < ext4_extent_header_get_entries_count(header);
- ++i, ++ext) {
+ ++i, ++ext) {
rc = ext4_extent_release(inode_ref, ext);
if (rc != EOK)
return rc;
@@ -475,9 +455,8 @@
return ext4_balloc_free_block(inode_ref, fblock);
}
-
int ext4_extent_release_blocks_from(struct ext4_inode_ref *inode_ref,
- uint32_t iblock_from)
+ uint32_t iblock_from)
{
/* Find the first extent to modify */
struct ext4_extent_path *path;
@@ -494,15 +473,14 @@
ext4_assert(path_ptr->extent != NULL);
/* First extent maybe released partially */
- uint32_t first_iblock =
- ext4_extent_get_first_block(path_ptr->extent);
+ uint32_t first_iblock = ext4_extent_get_first_block(path_ptr->extent);
uint32_t first_fblock =
ext4_extent_get_start(path_ptr->extent) + iblock_from - first_iblock;
uint16_t block_count = ext4_extent_get_block_count(path_ptr->extent);
- uint16_t delete_count = block_count -
- (ext4_extent_get_start(path_ptr->extent) - first_fblock);
+ uint16_t delete_count =
+ block_count - (ext4_extent_get_start(path_ptr->extent) - first_fblock);
/* Release all blocks */
rc = ext4_balloc_free_blocks(inode_ref, first_fblock, delete_count);
@@ -514,10 +492,10 @@
ext4_extent_set_block_count(path_ptr->extent, block_count);
/* Initialize the following loop */
- uint16_t entries =
- ext4_extent_header_get_entries_count(path_ptr->header);
+ uint16_t entries = ext4_extent_header_get_entries_count(path_ptr->header);
struct ext4_extent *tmp_ext = path_ptr->extent + 1;
- struct ext4_extent *stop_ext = EXT4_EXTENT_FIRST(path_ptr->header) + entries;
+ struct ext4_extent *stop_ext =
+ EXT4_EXTENT_FIRST(path_ptr->header) + entries;
/* If first extent empty, release it */
if (block_count == 0)
@@ -592,7 +570,7 @@
--path_ptr;
}
- if(!entries)
+ if (!entries)
ext4_extent_header_set_depth(path->header, 0);
cleanup:
@@ -601,9 +579,9 @@
* starting from 1: 0 is a block with inode data
*/
for (i = 1; i <= path->depth; ++i) {
- if (path[i].block.lb_id){
+ if (path[i].block.lb_id) {
int r = ext4_block_set(inode_ref->fs->bdev, &path[i].block);
- if(r != EOK)
+ if (r != EOK)
rc = r;
}
}
@@ -622,12 +600,12 @@
* @param iblock Logical index of block to append extent for
* @return Error code */
static int ext4_extent_append_extent(struct ext4_inode_ref *inode_ref,
- struct ext4_extent_path *path, uint32_t iblock)
+ struct ext4_extent_path *path,
+ uint32_t iblock)
{
struct ext4_extent_path *path_ptr = path + path->depth;
- uint32_t block_size =
- ext4_sb_get_block_size(&inode_ref->fs->sb);
+ uint32_t block_size = ext4_sb_get_block_size(&inode_ref->fs->sb);
/* Start splitting */
while (path_ptr > path) {
@@ -667,14 +645,14 @@
path_ptr->index = EXT4_EXTENT_FIRST_INDEX(path_ptr->header);
ext4_extent_index_set_first_block(path_ptr->index, iblock);
ext4_extent_index_set_leaf(path_ptr->index,
- (path_ptr + 1)->block.lb_id);
+ (path_ptr + 1)->block.lb_id);
limit = (block_size - sizeof(struct ext4_extent_header)) /
- sizeof(struct ext4_extent_index);
+ sizeof(struct ext4_extent_index);
} else {
path_ptr->extent = EXT4_EXTENT_FIRST(path_ptr->header);
ext4_extent_set_first_block(path_ptr->extent, iblock);
limit = (block_size - sizeof(struct ext4_extent_header)) /
- sizeof(struct ext4_extent);
+ sizeof(struct ext4_extent);
}
/* Initialize on-disk structure (header) */
@@ -691,12 +669,14 @@
} else {
/* Node with free space */
if (path_ptr->depth) {
- path_ptr->index = EXT4_EXTENT_FIRST_INDEX(path_ptr->header) + entries;
+ path_ptr->index =
+ EXT4_EXTENT_FIRST_INDEX(path_ptr->header) + entries;
ext4_extent_index_set_first_block(path_ptr->index, iblock);
ext4_extent_index_set_leaf(path_ptr->index,
- (path_ptr + 1)->block.lb_id);
+ (path_ptr + 1)->block.lb_id);
} else {
- path_ptr->extent = EXT4_EXTENT_FIRST(path_ptr->header) + entries;
+ path_ptr->extent =
+ EXT4_EXTENT_FIRST(path_ptr->header) + entries;
ext4_extent_set_first_block(path_ptr->extent, iblock);
}
@@ -731,7 +711,7 @@
/* Move data from root to the new block */
memcpy(block.data, inode_ref->inode->blocks,
- EXT4_INODE_BLOCKS * sizeof(uint32_t));
+ EXT4_INODE_BLOCKS * sizeof(uint32_t));
/* Data block is initialized */
@@ -754,15 +734,16 @@
/* Add new entry and update limit for entries */
if (old_root->depth) {
limit = (block_size - sizeof(struct ext4_extent_header)) /
- sizeof(struct ext4_extent_index);
- old_root->index = EXT4_EXTENT_FIRST_INDEX(old_root->header) + entries;
+ sizeof(struct ext4_extent_index);
+ old_root->index =
+ EXT4_EXTENT_FIRST_INDEX(old_root->header) + entries;
ext4_extent_index_set_first_block(old_root->index, iblock);
ext4_extent_index_set_leaf(old_root->index,
- (old_root + 1)->block.lb_id);
+ (old_root + 1)->block.lb_id);
old_root->extent = NULL;
} else {
limit = (block_size - sizeof(struct ext4_extent_header)) /
- sizeof(struct ext4_extent);
+ sizeof(struct ext4_extent);
old_root->extent = EXT4_EXTENT_FIRST(old_root->header) + entries;
ext4_extent_set_first_block(old_root->extent, iblock);
old_root->index = NULL;
@@ -805,9 +786,8 @@
return EOK;
}
-
-int ext4_extent_append_block(struct ext4_inode_ref *inode_ref,
- uint32_t *iblock, uint32_t *fblock, bool update_size)
+int ext4_extent_append_block(struct ext4_inode_ref *inode_ref, uint32_t *iblock,
+ uint32_t *fblock, bool update_size)
{
uint16_t i;
struct ext4_sblock *sb = &inode_ref->fs->sb;
@@ -876,7 +856,8 @@
goto finish;
if (!free) {
- /* Target is not free, new block must be appended to new extent */
+ /* Target is not free, new block must be appended to new extent
+ */
goto append_extent;
}
@@ -895,7 +876,6 @@
}
}
-
append_extent:
/* Append new extent to the tree */
phys_block = 0;
@@ -938,9 +918,9 @@
* starting from 1: 0 is a block with inode data
*/
for (i = 1; i <= path->depth; ++i) {
- if (path[i].block.lb_id){
+ if (path[i].block.lb_id) {
int r = ext4_block_set(inode_ref->fs->bdev, &path[i].block);
- if(r != EOK)
+ if (r != EOK)
rc = r;
}
}
--- a/lwext4/ext4_extent.h
+++ b/lwext4/ext4_extent.h
@@ -74,7 +74,6 @@
* @param fblock Physical number of the first block covered by extent */
void ext4_extent_set_start(struct ext4_extent *extent, uint64_t fblock);
-
/**@brief Get logical number of the block covered by extent index.
* @param index Extent index to load number from
* @return Logical number of the first block covered by extent index */
@@ -84,7 +83,7 @@
* @param index Extent index to set number to
* @param iblock Logical number of the first block covered by extent index */
void ext4_extent_index_set_first_block(struct ext4_extent_index *index,
- uint32_t iblock);
+ uint32_t iblock);
/**@brief Get physical number of block where the child node is located.
* @param index Extent index to load number from
@@ -91,14 +90,12 @@
* @return Physical number of the block with child node */
uint64_t ext4_extent_index_get_leaf(struct ext4_extent_index *index);
-
/**@brief Set physical number of block where the child node is located.
* @param index Extent index to set number to
* @param fblock Ohysical number of the block with child node */
void ext4_extent_index_set_leaf(struct ext4_extent_index *index,
- uint64_t fblock);
+ uint64_t fblock);
-
/**@brief Get magic value from extent header.
* @param header Extent header to load value from
* @return Magic value of extent header */
@@ -108,29 +105,31 @@
* @param header Extent header to set value to
* @param magic Magic value of extent header */
void ext4_extent_header_set_magic(struct ext4_extent_header *header,
- uint16_t magic);
+ uint16_t magic);
/**@brief Get number of entries from extent header
* @param header Extent header to get value from
* @return Number of entries covered by extent header */
-uint16_t ext4_extent_header_get_entries_count(struct ext4_extent_header *header);
+uint16_t
+ext4_extent_header_get_entries_count(struct ext4_extent_header *header);
/**@brief Set number of entries to extent header
* @param header Extent header to set value to
* @param count Number of entries covered by extent header */
void ext4_extent_header_set_entries_count(struct ext4_extent_header *header,
- uint16_t count);
+ uint16_t count);
/**@brief Get maximum number of entries from extent header
* @param header Extent header to get value from
* @return Maximum number of entries covered by extent header */
-uint16_t ext4_extent_header_get_max_entries_count(struct ext4_extent_header *header);
+uint16_t
+ext4_extent_header_get_max_entries_count(struct ext4_extent_header *header);
/**@brief Set maximum number of entries to extent header
* @param header Extent header to set value to
* @param max_count Maximum number of entries covered by extent header */
void ext4_extent_header_set_max_entries_count(struct ext4_extent_header *header,
- uint16_t max_count);
+ uint16_t max_count);
/**@brief Get depth of extent subtree.
* @param header Extent header to get value from
@@ -141,7 +140,7 @@
* @param header Extent header to set value to
* @param depth Depth of extent subtree */
void ext4_extent_header_set_depth(struct ext4_extent_header *header,
- uint16_t depth);
+ uint16_t depth);
/**@brief Get generation from extent header
* @param header Extent header to get value from
@@ -152,7 +151,7 @@
* @param header Extent header to set value to
* @param generation Generation */
void ext4_extent_header_set_generation(struct ext4_extent_header *header,
- uint32_t generation);
+ uint32_t generation);
/**@brief Find physical block in the extent tree by logical block number.
* There is no need to save path in the tree during this algorithm.
@@ -161,7 +160,7 @@
* @param fblock Output value for physical block number
* @return Error code*/
int ext4_extent_find_block(struct ext4_inode_ref *inode_ref, uint32_t iblock,
- uint32_t *fblock);
+ uint32_t *fblock);
/**@brief Release all data blocks starting from specified logical block.
* @param inode_ref I-node to release blocks from
@@ -168,7 +167,7 @@
* @param iblock_from First logical block to release
* @return Error code */
int ext4_extent_release_blocks_from(struct ext4_inode_ref *inode_ref,
- uint32_t iblock_from);
+ uint32_t iblock_from);
/**@brief Append data block to the i-node.
* This function allocates data block, tries to append it
@@ -179,11 +178,10 @@
* @param fblock Output physical block address of newly allocated block
*
* @return Error code*/
-int ext4_extent_append_block(struct ext4_inode_ref *inode_ref,
- uint32_t *iblock, uint32_t *fblock, bool update_size);
+int ext4_extent_append_block(struct ext4_inode_ref *inode_ref, uint32_t *iblock,
+ uint32_t *fblock, bool update_size);
-
#endif /* EXT4_EXTENT_H_ */
-/**
- * @}
- */
+ /**
+ * @}
+ */
--- a/lwext4/ext4_fs.c
+++ b/lwext4/ext4_fs.c
@@ -65,10 +65,10 @@
fs->bdev = bdev;
r = ext4_sb_read(fs->bdev, &fs->sb);
- if(r != EOK)
+ if (r != EOK)
return r;
- if(!ext4_sb_check(&fs->sb))
+ if (!ext4_sb_check(&fs->sb))
return ENOTSUP;
bsize = ext4_sb_get_block_size(&fs->sb);
@@ -76,10 +76,10 @@
return ENXIO;
r = ext4_fs_check_features(fs, &read_only);
- if(r != EOK)
+ if (r != EOK)
return r;
- if(read_only)
+ if (read_only)
return ENOTSUP;
/* Compute limits for indirect block levels */
@@ -89,17 +89,16 @@
fs->inode_blocks_per_level[0] = 1;
for (i = 1; i < 4; i++) {
- fs->inode_blocks_per_level[i] = fs->inode_blocks_per_level[i - 1] *
- blocks_id;
- fs->inode_block_limits[i] = fs->inode_block_limits[i - 1] +
- fs->inode_blocks_per_level[i];
+ fs->inode_blocks_per_level[i] =
+ fs->inode_blocks_per_level[i - 1] * blocks_id;
+ fs->inode_block_limits[i] =
+ fs->inode_block_limits[i - 1] + fs->inode_blocks_per_level[i];
}
/*Validate FS*/
tmp = ext4_get16(&fs->sb, state);
if (tmp & EXT4_SUPERBLOCK_STATE_ERROR_FS) {
- ext4_dprintf(EXT4_DEBUG_FS,
- "last umount error\n");
+ ext4_dprintf(EXT4_DEBUG_FS, "last umount error\n");
}
/* Mark system as mounted */
@@ -108,7 +107,6 @@
if (r != EOK)
return r;
-
/*Update mount count*/
ext4_set16(&fs->sb, mount_count, ext4_get16(&fs->sb, mount_count) + 1);
@@ -115,7 +113,6 @@
return r;
}
-
int ext4_fs_fini(struct ext4_fs *fs)
{
ext4_assert(fs);
@@ -129,87 +126,67 @@
static void ext4_fs_debug_features_incomp(uint32_t features_incompatible)
{
- if(features_incompatible &
- EXT4_FEATURE_INCOMPAT_COMPRESSION){
+ if (features_incompatible & EXT4_FEATURE_INCOMPAT_COMPRESSION) {
ext4_dprintf(EXT4_DEBUG_FS, "compression\n");
}
- if(features_incompatible &
- EXT4_FEATURE_INCOMPAT_FILETYPE){
+ if (features_incompatible & EXT4_FEATURE_INCOMPAT_FILETYPE) {
ext4_dprintf(EXT4_DEBUG_FS, "filetype\n");
}
- if(features_incompatible &
- EXT4_FEATURE_INCOMPAT_RECOVER){
+ if (features_incompatible & EXT4_FEATURE_INCOMPAT_RECOVER) {
ext4_dprintf(EXT4_DEBUG_FS, "recover\n");
}
- if(features_incompatible &
- EXT4_FEATURE_INCOMPAT_JOURNAL_DEV){
- ext4_dprintf(EXT4_DEBUG_FS,"journal_dev\n");
+ if (features_incompatible & EXT4_FEATURE_INCOMPAT_JOURNAL_DEV) {
+ ext4_dprintf(EXT4_DEBUG_FS, "journal_dev\n");
}
- if(features_incompatible &
- EXT4_FEATURE_INCOMPAT_META_BG){
+ if (features_incompatible & EXT4_FEATURE_INCOMPAT_META_BG) {
ext4_dprintf(EXT4_DEBUG_FS, "meta_bg\n");
}
- if(features_incompatible &
- EXT4_FEATURE_INCOMPAT_EXTENTS){
+ if (features_incompatible & EXT4_FEATURE_INCOMPAT_EXTENTS) {
ext4_dprintf(EXT4_DEBUG_FS, "extents\n");
}
- if(features_incompatible &
- EXT4_FEATURE_INCOMPAT_64BIT){
+ if (features_incompatible & EXT4_FEATURE_INCOMPAT_64BIT) {
ext4_dprintf(EXT4_DEBUG_FS, "64bit\n");
}
- if(features_incompatible &
- EXT4_FEATURE_INCOMPAT_MMP){
+ if (features_incompatible & EXT4_FEATURE_INCOMPAT_MMP) {
ext4_dprintf(EXT4_DEBUG_FS, "mnp\n");
}
- if(features_incompatible &
- EXT4_FEATURE_INCOMPAT_FLEX_BG){
+ if (features_incompatible & EXT4_FEATURE_INCOMPAT_FLEX_BG) {
ext4_dprintf(EXT4_DEBUG_FS, "flex_bg\n");
}
- if(features_incompatible &
- EXT4_FEATURE_INCOMPAT_EA_INODE){
+ if (features_incompatible & EXT4_FEATURE_INCOMPAT_EA_INODE) {
ext4_dprintf(EXT4_DEBUG_FS, "ea_inode\n");
}
- if(features_incompatible &
- EXT4_FEATURE_INCOMPAT_DIRDATA){
+ if (features_incompatible & EXT4_FEATURE_INCOMPAT_DIRDATA) {
ext4_dprintf(EXT4_DEBUG_FS, "dirdata\n");
}
- if(features_incompatible &
- EXT4_FEATURE_INCOMPAT_BG_USE_META_CSUM){
+ if (features_incompatible & EXT4_FEATURE_INCOMPAT_BG_USE_META_CSUM) {
ext4_dprintf(EXT4_DEBUG_FS, "meta_csum\n");
}
- if(features_incompatible &
- EXT4_FEATURE_INCOMPAT_LARGEDIR){
+ if (features_incompatible & EXT4_FEATURE_INCOMPAT_LARGEDIR) {
ext4_dprintf(EXT4_DEBUG_FS, "largedir\n");
}
- if(features_incompatible &
- EXT4_FEATURE_INCOMPAT_INLINE_DATA){
+ if (features_incompatible & EXT4_FEATURE_INCOMPAT_INLINE_DATA) {
ext4_dprintf(EXT4_DEBUG_FS, "inline_data\n");
}
}
static void ext4_fs_debug_features_comp(uint32_t features_compatible)
{
- if(features_compatible &
- EXT4_FEATURE_COMPAT_DIR_PREALLOC){
+ if (features_compatible & EXT4_FEATURE_COMPAT_DIR_PREALLOC) {
ext4_dprintf(EXT4_DEBUG_FS, " dir_prealloc\n");
}
- if(features_compatible &
- EXT4_FEATURE_COMPAT_IMAGIC_INODES){
+ if (features_compatible & EXT4_FEATURE_COMPAT_IMAGIC_INODES) {
ext4_dprintf(EXT4_DEBUG_FS, "imagic_inodes\n");
}
- if(features_compatible &
- EXT4_FEATURE_COMPAT_HAS_JOURNAL){
+ if (features_compatible & EXT4_FEATURE_COMPAT_HAS_JOURNAL) {
ext4_dprintf(EXT4_DEBUG_FS, "has_journal\n");
}
- if(features_compatible &
- EXT4_FEATURE_COMPAT_EXT_ATTR){
+ if (features_compatible & EXT4_FEATURE_COMPAT_EXT_ATTR) {
ext4_dprintf(EXT4_DEBUG_FS, "ext_attr\n");
}
- if(features_compatible &
- EXT4_FEATURE_COMPAT_RESIZE_INODE){
+ if (features_compatible & EXT4_FEATURE_COMPAT_RESIZE_INODE) {
ext4_dprintf(EXT4_DEBUG_FS, "resize_inode\n");
}
- if(features_compatible &
- EXT4_FEATURE_COMPAT_DIR_INDEX){
+ if (features_compatible & EXT4_FEATURE_COMPAT_DIR_INDEX) {
ext4_dprintf(EXT4_DEBUG_FS, "dir_index\n");
}
}
@@ -216,44 +193,34 @@
static void ext4_fs_debug_features_ro(uint32_t features_ro)
{
- if(features_ro &
- EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER){
+ if (features_ro & EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) {
ext4_dprintf(EXT4_DEBUG_FS, "sparse_super\n");
}
- if(features_ro &
- EXT4_FEATURE_RO_COMPAT_LARGE_FILE){
+ if (features_ro & EXT4_FEATURE_RO_COMPAT_LARGE_FILE) {
ext4_dprintf(EXT4_DEBUG_FS, "large_file\n");
}
- if(features_ro &
- EXT4_FEATURE_RO_COMPAT_BTREE_DIR){
+ if (features_ro & EXT4_FEATURE_RO_COMPAT_BTREE_DIR) {
ext4_dprintf(EXT4_DEBUG_FS, "btree_dir\n");
}
- if(features_ro &
- EXT4_FEATURE_RO_COMPAT_HUGE_FILE){
+ if (features_ro & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) {
ext4_dprintf(EXT4_DEBUG_FS, "huge_file\n");
}
- if(features_ro &
- EXT4_FEATURE_RO_COMPAT_GDT_CSUM){
+ if (features_ro & EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
ext4_dprintf(EXT4_DEBUG_FS, "gtd_csum\n");
}
- if(features_ro &
- EXT4_FEATURE_RO_COMPAT_DIR_NLINK){
+ if (features_ro & EXT4_FEATURE_RO_COMPAT_DIR_NLINK) {
ext4_dprintf(EXT4_DEBUG_FS, "dir_nlink\n");
}
- if(features_ro &
- EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE){
+ if (features_ro & EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE) {
ext4_dprintf(EXT4_DEBUG_FS, "extra_isize\n");
}
- if(features_ro &
- EXT4_FEATURE_RO_COMPAT_QUOTA){
+ if (features_ro & EXT4_FEATURE_RO_COMPAT_QUOTA) {
ext4_dprintf(EXT4_DEBUG_FS, "quota\n");
}
- if(features_ro &
- EXT4_FEATURE_RO_COMPAT_BIGALLOC){
+ if (features_ro & EXT4_FEATURE_RO_COMPAT_BIGALLOC) {
ext4_dprintf(EXT4_DEBUG_FS, "bigalloc\n");
}
- if(features_ro &
- EXT4_FEATURE_RO_COMPAT_METADATA_CSUM){
+ if (features_ro & EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) {
ext4_dprintf(EXT4_DEBUG_FS, "metadata_csum\n");
}
}
@@ -262,40 +229,35 @@
{
ext4_assert(fs && read_only);
uint32_t v;
- if(ext4_get32(&fs->sb, rev_level) == 0){
+ if (ext4_get32(&fs->sb, rev_level) == 0) {
*read_only = false;
return EOK;
}
- ext4_dprintf(EXT4_DEBUG_FS,
- "\nSB features_incompatible:\n");
+ ext4_dprintf(EXT4_DEBUG_FS, "\nSB features_incompatible:\n");
ext4_fs_debug_features_incomp(ext4_get32(&fs->sb, features_incompatible));
- ext4_dprintf(EXT4_DEBUG_FS,
- "\nSB features_compatible:\n");
+ ext4_dprintf(EXT4_DEBUG_FS, "\nSB features_compatible:\n");
ext4_fs_debug_features_comp(ext4_get32(&fs->sb, features_compatible));
- ext4_dprintf(EXT4_DEBUG_FS,
- "\nSB features_read_only:\n");
+ ext4_dprintf(EXT4_DEBUG_FS, "\nSB features_read_only:\n");
ext4_fs_debug_features_ro(ext4_get32(&fs->sb, features_read_only));
/*Check features_incompatible*/
v = (ext4_get32(&fs->sb, features_incompatible) &
- (~CONFIG_FEATURE_INCOMPAT_SUPP));
- if (v){
- ext4_dprintf(EXT4_DEBUG_FS,
- "SB features_incompatible: fail\n");
+ (~CONFIG_FEATURE_INCOMPAT_SUPP));
+ if (v) {
+ ext4_dprintf(EXT4_DEBUG_FS, "SB features_incompatible: fail\n");
ext4_fs_debug_features_incomp(v);
return ENOTSUP;
}
-
/*Check features_read_only*/
v = (ext4_get32(&fs->sb, features_read_only) &
- (~CONFIG_FEATURE_RO_COMPAT_SUPP));
- if (v){
+ (~CONFIG_FEATURE_RO_COMPAT_SUPP));
+ if (v) {
ext4_dprintf(EXT4_DEBUG_FS,
- "\nERROR sblock features_read_only . Unsupported:\n");
+ "\nERROR sblock features_read_only . Unsupported:\n");
ext4_fs_debug_features_incomp(v);
*read_only = true;
@@ -306,7 +268,6 @@
return EOK;
}
-
/**@brief Initialize block bitmap in block group.
* @param bg_ref Reference to block group
* @return Error code
@@ -314,25 +275,23 @@
static int ext4_fs_init_block_bitmap(struct ext4_block_group_ref *bg_ref)
{
uint32_t i;
- uint32_t bitmap_block_addr = ext4_bg_get_block_bitmap(
- bg_ref->block_group, &bg_ref->fs->sb);
+ uint32_t bitmap_block_addr =
+ ext4_bg_get_block_bitmap(bg_ref->block_group, &bg_ref->fs->sb);
struct ext4_block block_bitmap;
- int rc = ext4_block_get(bg_ref->fs->bdev, &block_bitmap,
- bitmap_block_addr);
+ int rc = ext4_block_get(bg_ref->fs->bdev, &block_bitmap, bitmap_block_addr);
if (rc != EOK)
return rc;
-
memset(block_bitmap.data, 0, ext4_sb_get_block_size(&bg_ref->fs->sb));
/* Determine first block and first data block in group */
uint32_t first_idx = 0;
- uint32_t first_data = ext4_balloc_get_first_data_block_in_group(
- &bg_ref->fs->sb, bg_ref);
- uint32_t first_data_idx = ext4_fs_baddr2_index_in_group(
- &bg_ref->fs->sb, first_data);
+ uint32_t first_data =
+ ext4_balloc_get_first_data_block_in_group(&bg_ref->fs->sb, bg_ref);
+ uint32_t first_data_idx =
+ ext4_fs_baddr2_index_in_group(&bg_ref->fs->sb, first_data);
/*Set bits from to first block to first data block - 1 to one (allocated)*/
/*TODO: Optimize it*/
@@ -339,7 +298,6 @@
for (i = first_idx; i < first_data_idx; ++i)
ext4_bmap_bit_set(block_bitmap.data, i);
-
block_bitmap.dirty = true;
/* Save bitmap */
@@ -353,12 +311,11 @@
static int ext4_fs_init_inode_bitmap(struct ext4_block_group_ref *bg_ref)
{
/* Load bitmap */
- uint32_t bitmap_block_addr = ext4_bg_get_inode_bitmap(
- bg_ref->block_group, &bg_ref->fs->sb);
+ uint32_t bitmap_block_addr =
+ ext4_bg_get_inode_bitmap(bg_ref->block_group, &bg_ref->fs->sb);
struct ext4_block block_bitmap;
- int rc = ext4_block_get(bg_ref->fs->bdev, &block_bitmap,
- bitmap_block_addr);
+ int rc = ext4_block_get(bg_ref->fs->bdev, &block_bitmap, bitmap_block_addr);
if (rc != EOK)
return rc;
@@ -395,7 +352,7 @@
uint32_t inode_size = ext4_get32(sb, inode_size);
uint32_t block_size = ext4_sb_get_block_size(sb);
uint32_t inodes_per_block = block_size / inode_size;
- uint32_t inodes_in_group = ext4_inodes_in_group_cnt(sb, bg_ref->index);
+ uint32_t inodes_in_group = ext4_inodes_in_group_cnt(sb, bg_ref->index);
uint32_t table_blocks = inodes_in_group / inodes_per_block;
uint32_t fblock;
@@ -403,8 +360,8 @@
table_blocks++;
/* Compute initialization bounds */
- uint32_t first_block = ext4_bg_get_inode_table_first_block(
- bg_ref->block_group, sb);
+ uint32_t first_block =
+ ext4_bg_get_inode_table_first_block(bg_ref->block_group, sb);
uint32_t last_block = first_block + table_blocks - 1;
@@ -428,7 +385,8 @@
}
static uint64_t ext4_fs_get_descriptor_block(struct ext4_sblock *s,
- uint32_t bgid, uint32_t dsc_per_block)
+ uint32_t bgid,
+ uint32_t dsc_per_block)
{
uint32_t first_meta_bg, dsc_id;
@@ -438,7 +396,7 @@
first_meta_bg = ext4_sb_first_meta_bg(s);
if (!ext4_sb_has_feature_incompatible(s, EXT4_FEATURE_INCOMPAT_META_BG) ||
- dsc_id < first_meta_bg)
+ dsc_id < first_meta_bg)
return ext4_get32(s, first_data_block) + dsc_id + 1;
if (ext4_sb_is_super_in_bg(s, bgid))
@@ -447,20 +405,18 @@
return (has_super + ext4_fs_first_bg_block_no(s, bgid));
}
-
int ext4_fs_get_block_group_ref(struct ext4_fs *fs, uint32_t bgid,
- struct ext4_block_group_ref *ref)
+ struct ext4_block_group_ref *ref)
{
/* Compute number of descriptors, that fits in one data block */
- uint32_t dsc_per_block = ext4_sb_get_block_size(&fs->sb) /
- ext4_sb_get_desc_size(&fs->sb);
+ uint32_t dsc_per_block =
+ ext4_sb_get_block_size(&fs->sb) / ext4_sb_get_desc_size(&fs->sb);
/* Block group descriptor table starts at the next block after superblock */
- uint64_t block_id = ext4_fs_get_descriptor_block(&fs->sb, bgid,
- dsc_per_block);
+ uint64_t block_id =
+ ext4_fs_get_descriptor_block(&fs->sb, bgid, dsc_per_block);
- uint32_t offset = (bgid % dsc_per_block) *
- ext4_sb_get_desc_size(&fs->sb);
+ uint32_t offset = (bgid % dsc_per_block) * ext4_sb_get_desc_size(&fs->sb);
int rc = ext4_block_get(fs->bdev, &ref->block, block_id);
if (rc != EOK)
@@ -471,21 +427,18 @@
ref->index = bgid;
ref->dirty = false;
- if (ext4_bg_has_flag(ref->block_group,
- EXT4_BLOCK_GROUP_BLOCK_UNINIT)) {
+ if (ext4_bg_has_flag(ref->block_group, EXT4_BLOCK_GROUP_BLOCK_UNINIT)) {
rc = ext4_fs_init_block_bitmap(ref);
if (rc != EOK) {
ext4_block_set(fs->bdev, &ref->block);
return rc;
}
- ext4_bg_clear_flag(ref->block_group,
- EXT4_BLOCK_GROUP_BLOCK_UNINIT);
+ ext4_bg_clear_flag(ref->block_group, EXT4_BLOCK_GROUP_BLOCK_UNINIT);
ref->dirty = true;
}
- if (ext4_bg_has_flag(ref->block_group,
- EXT4_BLOCK_GROUP_INODE_UNINIT)) {
+ if (ext4_bg_has_flag(ref->block_group, EXT4_BLOCK_GROUP_INODE_UNINIT)) {
rc = ext4_fs_init_inode_bitmap(ref);
if (rc != EOK) {
ext4_block_set(ref->fs->bdev, &ref->block);
@@ -492,19 +445,17 @@
return rc;
}
- ext4_bg_clear_flag(ref->block_group,
- EXT4_BLOCK_GROUP_INODE_UNINIT);
+ ext4_bg_clear_flag(ref->block_group, EXT4_BLOCK_GROUP_INODE_UNINIT);
if (!ext4_bg_has_flag(ref->block_group,
- EXT4_BLOCK_GROUP_ITABLE_ZEROED)) {
+ EXT4_BLOCK_GROUP_ITABLE_ZEROED)) {
rc = ext4_fs_init_inode_table(ref);
- if (rc != EOK){
+ if (rc != EOK) {
ext4_block_set(fs->bdev, &ref->block);
return rc;
}
- ext4_bg_set_flag(ref->block_group,
- EXT4_BLOCK_GROUP_ITABLE_ZEROED);
+ ext4_bg_set_flag(ref->block_group, EXT4_BLOCK_GROUP_ITABLE_ZEROED);
}
ref->dirty = true;
@@ -520,18 +471,17 @@
* @return Checksum value
*/
static uint16_t ext4_fs_bg_checksum(struct ext4_sblock *sb, uint32_t bgid,
- struct ext4_bgroup *bg)
+ struct ext4_bgroup *bg)
{
/* If checksum not supported, 0 will be returned */
uint16_t crc = 0;
/* Compute the checksum only if the filesystem supports it */
- if (ext4_sb_has_feature_read_only(sb,
- EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
- uint8_t *base = (uint8_t *)bg;
- uint8_t *checksum = (uint8_t *)&bg->checksum;
+ if (ext4_sb_has_feature_read_only(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
+ uint8_t *base = (uint8_t *)bg;
+ uint8_t *checksum = (uint8_t *)&bg->checksum;
- uint32_t offset = (uint32_t) (checksum - base);
+ uint32_t offset = (uint32_t)(checksum - base);
/* Convert block group index to little endian */
uint32_t le_group = to_le32(bgid);
@@ -540,10 +490,10 @@
crc = ext4_bg_crc16(~0, sb->uuid, sizeof(sb->uuid));
/* Include index of block group */
- crc = ext4_bg_crc16(crc, (uint8_t *) &le_group, sizeof(le_group));
+ crc = ext4_bg_crc16(crc, (uint8_t *)&le_group, sizeof(le_group));
/* Compute crc from the first part (stop before checksum field) */
- crc = ext4_bg_crc16(crc, (uint8_t *) bg, offset);
+ crc = ext4_bg_crc16(crc, (uint8_t *)bg, offset);
/* Skip checksum */
offset += sizeof(bg->checksum);
@@ -550,11 +500,11 @@
/* Checksum of the rest of block group descriptor */
if ((ext4_sb_has_feature_incompatible(sb,
- EXT4_FEATURE_INCOMPAT_64BIT)) &&
- (offset < ext4_sb_get_desc_size(sb)))
+ EXT4_FEATURE_INCOMPAT_64BIT)) &&
+ (offset < ext4_sb_get_desc_size(sb)))
- crc = ext4_bg_crc16(crc, ((uint8_t *) bg) + offset,
- ext4_sb_get_desc_size(sb) - offset);
+ crc = ext4_bg_crc16(crc, ((uint8_t *)bg) + offset,
+ ext4_sb_get_desc_size(sb) - offset);
}
return crc;
}
@@ -565,8 +515,7 @@
if (ref->dirty) {
/* Compute new checksum of block group */
uint16_t checksum =
- ext4_fs_bg_checksum(&ref->fs->sb, ref->index,
- ref->block_group);
+ ext4_fs_bg_checksum(&ref->fs->sb, ref->index, ref->block_group);
ref->block_group->checksum = to_le16(checksum);
@@ -579,7 +528,7 @@
}
int ext4_fs_get_inode_ref(struct ext4_fs *fs, uint32_t index,
- struct ext4_inode_ref *ref)
+ struct ext4_inode_ref *ref)
{
/* Compute number of i-nodes, that fits in one data block */
uint32_t inodes_per_group = ext4_get32(&fs->sb, inodes_per_group);
@@ -602,8 +551,7 @@
/* Load block address, where i-node table is located */
uint32_t inode_table_start =
- ext4_bg_get_inode_table_first_block(bg_ref.block_group,
- &fs->sb);
+ ext4_bg_get_inode_table_first_block(bg_ref.block_group, &fs->sb);
/* Put back block group reference (not needed more) */
rc = ext4_fs_put_block_group_ref(&bg_ref);
@@ -617,10 +565,8 @@
uint32_t byte_offset_in_group = offset_in_group * inode_size;
/* Compute block address */
- uint64_t block_id = inode_table_start +
- (byte_offset_in_group / block_size);
+ uint64_t block_id = inode_table_start + (byte_offset_in_group / block_size);
-
rc = ext4_block_get(fs->bdev, &ref->block, block_id);
if (rc != EOK) {
return rc;
@@ -647,11 +593,11 @@
}
/* Put back block, that contains i-node */
- return ext4_block_set(ref->fs->bdev, &ref->block);
+ return ext4_block_set(ref->fs->bdev, &ref->block);
}
int ext4_fs_alloc_inode(struct ext4_fs *fs, struct ext4_inode_ref *inode_ref,
- bool is_directory)
+ bool is_directory)
{
/* Check if newly allocated i-node will be a directory */
uint32_t i;
@@ -699,7 +645,6 @@
ext4_inode_set_links_count(inode, 1);
}
-
ext4_inode_set_uid(inode, 0);
ext4_inode_set_gid(inode, 0);
ext4_inode_set_size(inode, 0);
@@ -717,11 +662,10 @@
#if CONFIG_EXTENT_ENABLE
/* Initialize extents if needed */
- if (ext4_sb_has_feature_incompatible(
- &fs->sb, EXT4_FEATURE_INCOMPAT_EXTENTS)) {
+ if (ext4_sb_has_feature_incompatible(&fs->sb,
+ EXT4_FEATURE_INCOMPAT_EXTENTS)) {
ext4_inode_set_flag(inode, EXT4_INODE_FLAG_EXTENTS);
-
/* Initialize extent root header */
struct ext4_extent_header *header = ext4_inode_get_extent_header(inode);
ext4_extent_header_set_depth(header, 0);
@@ -730,7 +674,8 @@
ext4_extent_header_set_magic(header, EXT4_EXTENT_MAGIC);
uint16_t max_entries = (EXT4_INODE_BLOCKS * sizeof(uint32_t) -
- sizeof(struct ext4_extent_header)) / sizeof(struct ext4_extent);
+ sizeof(struct ext4_extent_header)) /
+ sizeof(struct ext4_extent);
ext4_extent_header_set_max_entries_count(header, max_entries);
}
@@ -749,8 +694,8 @@
#if CONFIG_EXTENT_ENABLE
/* For extents must be data block destroyed by other way */
if ((ext4_sb_has_feature_incompatible(&fs->sb,
- EXT4_FEATURE_INCOMPAT_EXTENTS)) &&
- (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS))){
+ EXT4_FEATURE_INCOMPAT_EXTENTS)) &&
+ (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS))) {
/* Data structures are released during truncate operation... */
goto finish;
}
@@ -770,7 +715,7 @@
uint32_t block_size = ext4_sb_get_block_size(&fs->sb);
uint32_t count = block_size / sizeof(uint32_t);
- struct ext4_block block;
+ struct ext4_block block;
/* 2) Double indirect */
fblock = ext4_inode_get_indirect_block(inode_ref->inode, 1);
@@ -781,7 +726,7 @@
uint32_t ind_block;
for (offset = 0; offset < count; ++offset) {
- ind_block = to_le32(((uint32_t *) block.data)[offset]);
+ ind_block = to_le32(((uint32_t *)block.data)[offset]);
if (ind_block != 0) {
rc = ext4_balloc_free_block(inode_ref, ind_block);
@@ -801,7 +746,7 @@
}
/* 3) Tripple indirect */
- struct ext4_block subblock;
+ struct ext4_block subblock;
fblock = ext4_inode_get_indirect_block(inode_ref->inode, 2);
if (fblock != 0) {
int rc = ext4_block_get(fs->bdev, &block, fblock);
@@ -809,8 +754,8 @@
return rc;
uint32_t ind_block;
- for ( offset = 0; offset < count; ++offset) {
- ind_block = to_le32(((uint32_t *) block.data)[offset]);
+ for (offset = 0; offset < count; ++offset) {
+ ind_block = to_le32(((uint32_t *)block.data)[offset]);
if (ind_block != 0) {
rc = ext4_block_get(fs->bdev, &subblock, ind_block);
@@ -820,10 +765,9 @@
}
uint32_t ind_subblock;
- for (suboffset = 0; suboffset < count;
- ++suboffset) {
- ind_subblock = to_le32(((uint32_t *)
- subblock.data)[suboffset]);
+ for (suboffset = 0; suboffset < count; ++suboffset) {
+ ind_subblock =
+ to_le32(((uint32_t *)subblock.data)[suboffset]);
if (ind_subblock != 0) {
rc = ext4_balloc_free_block(inode_ref, ind_subblock);
@@ -837,7 +781,6 @@
ext4_block_set(fs->bdev, &subblock);
-
rc = ext4_balloc_free_block(inode_ref, ind_block);
if (rc != EOK) {
ext4_block_set(fs->bdev, &block);
@@ -854,14 +797,13 @@
ext4_inode_set_indirect_block(inode_ref->inode, 2, 0);
}
#if CONFIG_EXTENT_ENABLE
- finish:
+finish:
#endif
/* Mark inode dirty for writing to the physical device */
inode_ref->dirty = true;
/* Free block with extended attributes if present */
- uint32_t xattr_block = ext4_inode_get_file_acl(
- inode_ref->inode, &fs->sb);
+ uint32_t xattr_block = ext4_inode_get_file_acl(inode_ref->inode, &fs->sb);
if (xattr_block) {
int rc = ext4_balloc_free_block(inode_ref, xattr_block);
if (rc != EOK)
@@ -873,7 +815,7 @@
/* Free inode by allocator */
int rc;
if (ext4_inode_is_type(&fs->sb, inode_ref->inode,
- EXT4_INODE_MODE_DIRECTORY))
+ EXT4_INODE_MODE_DIRECTORY))
rc = ext4_ialloc_free_inode(fs, inode_ref->index, true);
else
rc = ext4_ialloc_free_inode(fs, inode_ref->index, false);
@@ -881,8 +823,7 @@
return rc;
}
-int ext4_fs_truncate_inode(struct ext4_inode_ref *inode_ref,
- uint64_t new_size)
+int ext4_fs_truncate_inode(struct ext4_inode_ref *inode_ref, uint64_t new_size)
{
struct ext4_sblock *sb = &inode_ref->fs->sb;
uint32_t i;
@@ -902,7 +843,7 @@
/* Compute how many blocks will be released */
uint64_t size_diff = old_size - new_size;
- uint32_t block_size = ext4_sb_get_block_size(sb);
+ uint32_t block_size = ext4_sb_get_block_size(sb);
uint32_t diff_blocks_count = size_diff / block_size;
if (size_diff % block_size != 0)
diff_blocks_count++;
@@ -911,13 +852,12 @@
if (old_size % block_size != 0)
old_blocks_count++;
#if CONFIG_EXTENT_ENABLE
- if ((ext4_sb_has_feature_incompatible(sb,
- EXT4_FEATURE_INCOMPAT_EXTENTS)) &&
- (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS))) {
+ if ((ext4_sb_has_feature_incompatible(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)) &&
+ (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS))) {
/* Extents require special operation */
- int rc = ext4_extent_release_blocks_from(inode_ref,
- old_blocks_count - diff_blocks_count);
+ int rc = ext4_extent_release_blocks_from(
+ inode_ref, old_blocks_count - diff_blocks_count);
if (rc != EOK)
return rc;
@@ -928,8 +868,8 @@
/* Starting from 1 because of logical blocks are numbered from 0 */
for (i = 1; i <= diff_blocks_count; ++i) {
- int rc = ext4_fs_release_inode_block(inode_ref,
- old_blocks_count - i);
+ int rc =
+ ext4_fs_release_inode_block(inode_ref, old_blocks_count - i);
if (rc != EOK)
return rc;
}
@@ -943,7 +883,7 @@
}
int ext4_fs_get_inode_data_block_index(struct ext4_inode_ref *inode_ref,
- uint64_t iblock, uint32_t *fblock)
+ uint64_t iblock, uint32_t *fblock)
{
struct ext4_fs *fs = inode_ref->fs;
@@ -957,10 +897,9 @@
#if CONFIG_EXTENT_ENABLE
/* Handle i-node using extents */
if ((ext4_sb_has_feature_incompatible(&fs->sb,
- EXT4_FEATURE_INCOMPAT_EXTENTS)) &&
- (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS))) {
+ EXT4_FEATURE_INCOMPAT_EXTENTS)) &&
+ (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS))) {
-
int rc = ext4_extent_find_block(inode_ref, iblock, ¤t_block);
if (rc != EOK)
return rc;
@@ -974,7 +913,7 @@
/* Direct block are read directly from array in i-node structure */
if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
- current_block = ext4_inode_get_direct_block(inode, (uint32_t) iblock);
+ current_block = ext4_inode_get_direct_block(inode, (uint32_t)iblock);
*fblock = current_block;
return EOK;
}
@@ -993,11 +932,10 @@
return EIO;
/* Compute offsets for the topmost level */
- uint64_t block_offset_in_level =
- iblock - fs->inode_block_limits[level - 1];
+ uint64_t block_offset_in_level = iblock - fs->inode_block_limits[level - 1];
current_block = ext4_inode_get_indirect_block(inode, level - 1);
uint32_t offset_in_block =
- block_offset_in_level / fs->inode_blocks_per_level[level - 1];
+ block_offset_in_level / fs->inode_blocks_per_level[level - 1];
/* Sparse file */
if (current_block == 0) {
@@ -1018,8 +956,7 @@
return rc;
/* Read block address from indirect block */
- current_block =
- to_le32(((uint32_t *) block.data)[offset_in_block]);
+ current_block = to_le32(((uint32_t *)block.data)[offset_in_block]);
/* Put back indirect block untouched */
rc = ext4_block_set(fs->bdev, &block);
@@ -1042,7 +979,7 @@
/* Visit the next level */
block_offset_in_level %= fs->inode_blocks_per_level[level];
offset_in_block =
- block_offset_in_level / fs->inode_blocks_per_level[level - 1];
+ block_offset_in_level / fs->inode_blocks_per_level[level - 1];
}
*fblock = current_block;
@@ -1051,7 +988,7 @@
}
int ext4_fs_set_inode_data_block_index(struct ext4_inode_ref *inode_ref,
- uint64_t iblock, uint32_t fblock)
+ uint64_t iblock, uint32_t fblock)
{
struct ext4_fs *fs = inode_ref->fs;
@@ -1058,8 +995,8 @@
#if CONFIG_EXTENT_ENABLE
/* Handle inode using extents */
if ((ext4_sb_has_feature_incompatible(&fs->sb,
- EXT4_FEATURE_INCOMPAT_EXTENTS)) &&
- (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS))) {
+ EXT4_FEATURE_INCOMPAT_EXTENTS)) &&
+ (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS))) {
/* Not reachable */
return ENOTSUP;
}
@@ -1067,8 +1004,7 @@
/* Handle simple case when we are dealing with direct reference */
if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
- ext4_inode_set_direct_block(inode_ref->inode, (uint32_t) iblock,
- fblock);
+ ext4_inode_set_direct_block(inode_ref->inode, (uint32_t)iblock, fblock);
inode_ref->dirty = true;
return EOK;
@@ -1090,12 +1026,11 @@
uint32_t block_size = ext4_sb_get_block_size(&fs->sb);
/* Compute offsets for the topmost level */
- uint64_t block_offset_in_level =
- iblock - fs->inode_block_limits[level - 1];
+ uint64_t block_offset_in_level = iblock - fs->inode_block_limits[level - 1];
uint32_t current_block =
- ext4_inode_get_indirect_block(inode_ref->inode, level - 1);
+ ext4_inode_get_indirect_block(inode_ref->inode, level - 1);
uint32_t offset_in_block =
- block_offset_in_level / fs->inode_blocks_per_level[level - 1];
+ block_offset_in_level / fs->inode_blocks_per_level[level - 1];
uint32_t new_block_addr;
@@ -1111,7 +1046,7 @@
/* Update i-node */
ext4_inode_set_indirect_block(inode_ref->inode, level - 1,
- new_block_addr);
+ new_block_addr);
inode_ref->dirty = true;
/* Load newly allocated block */
@@ -1142,8 +1077,7 @@
if (rc != EOK)
return rc;
- current_block =
- to_le32(((uint32_t *) block.data)[offset_in_block]);
+ current_block = to_le32(((uint32_t *)block.data)[offset_in_block]);
if ((level > 1) && (current_block == 0)) {
/* Allocate new block */
@@ -1172,8 +1106,7 @@
}
/* Write block address to the parent */
- ((uint32_t *) block.data)[offset_in_block] =
- to_le32(new_block_addr);
+ ((uint32_t *)block.data)[offset_in_block] = to_le32(new_block_addr);
block.dirty = true;
current_block = new_block_addr;
}
@@ -1180,8 +1113,7 @@
/* Will be finished, write the fblock address */
if (level == 1) {
- ((uint32_t *) block.data)[offset_in_block] =
- to_le32(fblock);
+ ((uint32_t *)block.data)[offset_in_block] = to_le32(fblock);
block.dirty = true;
}
@@ -1201,7 +1133,7 @@
/* Visit the next level */
block_offset_in_level %= fs->inode_blocks_per_level[level];
offset_in_block =
- block_offset_in_level / fs->inode_blocks_per_level[level - 1];
+ block_offset_in_level / fs->inode_blocks_per_level[level - 1];
}
return EOK;
@@ -1208,7 +1140,7 @@
}
int ext4_fs_release_inode_block(struct ext4_inode_ref *inode_ref,
- uint32_t iblock)
+ uint32_t iblock)
{
uint32_t fblock;
@@ -1215,9 +1147,10 @@
struct ext4_fs *fs = inode_ref->fs;
/* Extents are handled otherwise = there is not support in this function */
- ext4_assert(!(ext4_sb_has_feature_incompatible(&fs->sb,
- EXT4_FEATURE_INCOMPAT_EXTENTS) &&
- (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS))));
+ ext4_assert(
+ !(ext4_sb_has_feature_incompatible(&fs->sb,
+ EXT4_FEATURE_INCOMPAT_EXTENTS) &&
+ (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS))));
struct ext4_inode *inode = inode_ref->inode;
@@ -1247,12 +1180,10 @@
return EIO;
/* Compute offsets for the topmost level */
- uint64_t block_offset_in_level =
- iblock - fs->inode_block_limits[level - 1];
- uint32_t current_block =
- ext4_inode_get_indirect_block(inode, level - 1);
+ uint64_t block_offset_in_level = iblock - fs->inode_block_limits[level - 1];
+ uint32_t current_block = ext4_inode_get_indirect_block(inode, level - 1);
uint32_t offset_in_block =
- block_offset_in_level / fs->inode_blocks_per_level[level - 1];
+ block_offset_in_level / fs->inode_blocks_per_level[level - 1];
/*
* Navigate through other levels, until we find the block number
@@ -1270,13 +1201,11 @@
if (rc != EOK)
return rc;
- current_block =
- to_le32(((uint32_t *) block.data)[offset_in_block]);
+ current_block = to_le32(((uint32_t *)block.data)[offset_in_block]);
/* Set zero if physical data block address found */
if (level == 1) {
- ((uint32_t *) block.data)[offset_in_block] =
- to_le32(0);
+ ((uint32_t *)block.data)[offset_in_block] = to_le32(0);
block.dirty = true;
}
@@ -1296,7 +1225,7 @@
/* Visit the next level */
block_offset_in_level %= fs->inode_blocks_per_level[level];
offset_in_block =
- block_offset_in_level / fs->inode_blocks_per_level[level - 1];
+ block_offset_in_level / fs->inode_blocks_per_level[level - 1];
}
fblock = current_block;
@@ -1307,15 +1236,14 @@
return ext4_balloc_free_block(inode_ref, fblock);
}
-
int ext4_fs_append_inode_block(struct ext4_inode_ref *inode_ref,
- uint32_t *fblock, uint32_t *iblock)
+ uint32_t *fblock, uint32_t *iblock)
{
#if CONFIG_EXTENT_ENABLE
/* Handle extents separately */
if ((ext4_sb_has_feature_incompatible(&inode_ref->fs->sb,
- EXT4_FEATURE_INCOMPAT_EXTENTS)) &&
- (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS))){
+ EXT4_FEATURE_INCOMPAT_EXTENTS)) &&
+ (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS))) {
return ext4_extent_append_block(inode_ref, iblock, fblock, true);
}
#endif
@@ -1339,8 +1267,8 @@
return rc;
/* Add physical block address to the i-node */
- rc = ext4_fs_set_inode_data_block_index(inode_ref,
- new_block_idx, phys_block);
+ rc = ext4_fs_set_inode_data_block_index(inode_ref, new_block_idx,
+ phys_block);
if (rc != EOK) {
ext4_balloc_free_block(inode_ref, phys_block);
return rc;
@@ -1359,8 +1287,8 @@
void ext4_fs_inode_links_count_inc(struct ext4_inode_ref *inode_ref)
{
uint16_t link;
- if(!ext4_inode_is_type(&inode_ref->fs->sb, inode_ref->inode,
- EXT4_INODE_MODE_DIRECTORY)){
+ if (!ext4_inode_is_type(&inode_ref->fs->sb, inode_ref->inode,
+ EXT4_INODE_MODE_DIRECTORY)) {
ext4_inode_set_links_count(inode_ref->inode, 0);
return;
}
@@ -1369,13 +1297,12 @@
link++;
ext4_inode_set_links_count(inode_ref->inode, link);
-
- bool is_dx = ext4_sb_has_feature_compatible(&inode_ref->fs->sb,
- EXT4_FEATURE_COMPAT_DIR_INDEX) &&
+ bool is_dx = ext4_sb_has_feature_compatible(
+ &inode_ref->fs->sb, EXT4_FEATURE_COMPAT_DIR_INDEX) &&
ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_INDEX);
- if(is_dx && link > 1){
- if(link >= EXT4_LINK_MAX || link == 2){
+ if (is_dx && link > 1) {
+ if (link >= EXT4_LINK_MAX || link == 2) {
ext4_inode_set_links_count(inode_ref->inode, 1);
uint32_t v = ext4_get32(&inode_ref->fs->sb, features_read_only);
@@ -1387,8 +1314,8 @@
void ext4_fs_inode_links_count_dec(struct ext4_inode_ref *inode_ref)
{
- if(!ext4_inode_is_type(&inode_ref->fs->sb, inode_ref->inode,
- EXT4_INODE_MODE_DIRECTORY)){
+ if (!ext4_inode_is_type(&inode_ref->fs->sb, inode_ref->inode,
+ EXT4_INODE_MODE_DIRECTORY)) {
ext4_inode_set_links_count(inode_ref->inode, 0);
return;
}
@@ -1395,14 +1322,10 @@
uint16_t links = ext4_inode_get_links_count(inode_ref->inode);
-
- if(links > 2)
+ if (links > 2)
ext4_inode_set_links_count(inode_ref->inode, links - 1);
-
}
-
/**
* @}
*/
-
--- a/lwext4/ext4_fs.h
+++ b/lwext4/ext4_fs.h
@@ -54,16 +54,15 @@
* @return Relative number of block
*/
static inline uint32_t ext4_fs_baddr2_index_in_group(struct ext4_sblock *s,
- uint32_t baddr)
+ uint32_t baddr)
{
ext4_assert(baddr);
- if(ext4_get32(s, first_data_block))
+ if (ext4_get32(s, first_data_block))
baddr--;
- return baddr % ext4_get32(s, blocks_per_group);
+ return baddr % ext4_get32(s, blocks_per_group);
}
-
/**@brief Convert relative block address in group to absolute address.
* @param s Superblock pointer
* @param index Relative block address
@@ -71,9 +70,10 @@
* @return Absolute block address
*/
static inline uint32_t ext4_fs_index_in_group2_baddr(struct ext4_sblock *s,
- uint32_t index, uint32_t bgid)
+ uint32_t index,
+ uint32_t bgid)
{
- if(ext4_get32(s, first_data_block))
+ if (ext4_get32(s, first_data_block))
index++;
return ext4_get32(s, blocks_per_group) * bgid + index;
@@ -81,10 +81,10 @@
/**@brief TODO: */
static inline uint64_t ext4_fs_first_bg_block_no(struct ext4_sblock *s,
- uint32_t bgid)
+ uint32_t bgid)
{
return (uint64_t)bgid * ext4_get32(s, blocks_per_group) +
- ext4_get32(s, first_data_block);
+ ext4_get32(s, first_data_block);
}
/**@brief Initialize filesystem and read all needed data.
@@ -117,7 +117,7 @@
* @return Error code
*/
int ext4_fs_get_block_group_ref(struct ext4_fs *fs, uint32_t bgid,
- struct ext4_block_group_ref *ref);
+ struct ext4_block_group_ref *ref);
/**@brief Put reference to block group.
* @param ref Pointer for reference to be put back
@@ -132,7 +132,7 @@
* @return Error code
*/
int ext4_fs_get_inode_ref(struct ext4_fs *fs, uint32_t index,
- struct ext4_inode_ref *ref);
+ struct ext4_inode_ref *ref);
/**@brief Put reference to i-node.
* @param ref Pointer for reference to be put back
@@ -147,7 +147,7 @@
* @return Error code
*/
int ext4_fs_alloc_inode(struct ext4_fs *fs, struct ext4_inode_ref *inode_ref,
- bool is_directory);
+ bool is_directory);
/**@brief Release i-node and mark it as free.
* @param inode_ref I-node to be released
@@ -160,8 +160,7 @@
* @param new_size New size of inode (must be < current size)
* @return Error code
*/
-int ext4_fs_truncate_inode(struct ext4_inode_ref *inode_ref,
- uint64_t new_size);
+int ext4_fs_truncate_inode(struct ext4_inode_ref *inode_ref, uint64_t new_size);
/**@brief Get physical block address by logical index of the block.
* @param inode_ref I-node to read block address from
@@ -170,9 +169,10 @@
* @return Error code
*/
int ext4_fs_get_inode_data_block_index(struct ext4_inode_ref *inode_ref,
- uint64_t iblock, uint32_t *fblock);
+ uint64_t iblock, uint32_t *fblock);
-/**@brief Set physical block address for the block logical address into the i-node.
+/**@brief Set physical block address for the block logical address into the
+ * i-node.
* @param inode_ref I-node to set block address to
* @param iblock Logical index of block
* @param fblock Physical block address
@@ -179,7 +179,7 @@
* @return Error code
*/
int ext4_fs_set_inode_data_block_index(struct ext4_inode_ref *inode_ref,
- uint64_t iblock, uint32_t fblock);
+ uint64_t iblock, uint32_t fblock);
/**@brief Release data block from i-node
* @param inode_ref I-node to release block from
@@ -187,7 +187,7 @@
* @return Error code
*/
int ext4_fs_release_inode_block(struct ext4_inode_ref *inode_ref,
- uint32_t iblock);
+ uint32_t iblock);
/**@brief Append following logical block to the i-node.
* @param inode_ref I-node to append block to
@@ -196,8 +196,7 @@
* @return Error code
*/
int ext4_fs_append_inode_block(struct ext4_inode_ref *inode_ref,
- uint32_t *fblock, uint32_t *iblock);
-
+ uint32_t *fblock, uint32_t *iblock);
/**@brief Increment inode link count.
* @param inode none handle
--- a/lwext4/ext4_hash.c
+++ b/lwext4/ext4_hash.c
@@ -78,19 +78,25 @@
* FF, GG, and HH are transformations for rounds 1, 2, and 3.
* Rotation is separated from addition to prevent recomputation.
*/
-#define FF(a, b, c, d, x, s) { \
- (a) += F ((b), (c), (d)) + (x); \
- (a) = ROTATE_LEFT ((a), (s)); \
+#define FF(a, b, c, d, x, s) \
+ { \
+ (a) += F((b), (c), (d)) + (x); \
+ (a) = ROTATE_LEFT((a), (s)); \
+ \
}
-#define GG(a, b, c, d, x, s) { \
- (a) += G ((b), (c), (d)) + (x) + (uint32_t)0x5A827999; \
- (a) = ROTATE_LEFT ((a), (s)); \
+#define GG(a, b, c, d, x, s) \
+ { \
+ (a) += G((b), (c), (d)) + (x) + (uint32_t)0x5A827999; \
+ (a) = ROTATE_LEFT((a), (s)); \
+ \
}
-#define HH(a, b, c, d, x, s) { \
- (a) += H ((b), (c), (d)) + (x) + (uint32_t)0x6ED9EBA1; \
- (a) = ROTATE_LEFT ((a), (s)); \
+#define HH(a, b, c, d, x, s) \
+ { \
+ (a) += H((b), (c), (d)) + (x) + (uint32_t)0x6ED9EBA1; \
+ (a) = ROTATE_LEFT((a), (s)); \
+ \
}
/*
@@ -104,38 +110,37 @@
* need to check this value, so in our version this function doesn't return any
* value.
*/
-static void
-ext2_half_md4(uint32_t hash[4], uint32_t data[8])
+static void ext2_half_md4(uint32_t hash[4], uint32_t data[8])
{
uint32_t a = hash[0], b = hash[1], c = hash[2], d = hash[3];
/* Round 1 */
- FF(a, b, c, d, data[0], 3);
- FF(d, a, b, c, data[1], 7);
+ FF(a, b, c, d, data[0], 3);
+ FF(d, a, b, c, data[1], 7);
FF(c, d, a, b, data[2], 11);
FF(b, c, d, a, data[3], 19);
- FF(a, b, c, d, data[4], 3);
- FF(d, a, b, c, data[5], 7);
+ FF(a, b, c, d, data[4], 3);
+ FF(d, a, b, c, data[5], 7);
FF(c, d, a, b, data[6], 11);
FF(b, c, d, a, data[7], 19);
/* Round 2 */
- GG(a, b, c, d, data[1], 3);
- GG(d, a, b, c, data[3], 5);
- GG(c, d, a, b, data[5], 9);
+ GG(a, b, c, d, data[1], 3);
+ GG(d, a, b, c, data[3], 5);
+ GG(c, d, a, b, data[5], 9);
GG(b, c, d, a, data[7], 13);
- GG(a, b, c, d, data[0], 3);
- GG(d, a, b, c, data[2], 5);
- GG(c, d, a, b, data[4], 9);
+ GG(a, b, c, d, data[0], 3);
+ GG(d, a, b, c, data[2], 5);
+ GG(c, d, a, b, data[4], 9);
GG(b, c, d, a, data[6], 13);
/* Round 3 */
- HH(a, b, c, d, data[3], 3);
- HH(d, a, b, c, data[7], 9);
+ HH(a, b, c, d, data[3], 3);
+ HH(d, a, b, c, data[7], 9);
HH(c, d, a, b, data[2], 11);
HH(b, c, d, a, data[6], 15);
- HH(a, b, c, d, data[1], 3);
- HH(d, a, b, c, data[5], 9);
+ HH(a, b, c, d, data[1], 3);
+ HH(d, a, b, c, data[5], 9);
HH(c, d, a, b, data[0], 11);
HH(b, c, d, a, data[4], 15);
@@ -148,8 +153,7 @@
/*
* Tiny Encryption Algorithm.
*/
-static void
-ext2_tea(uint32_t hash[4], uint32_t data[8])
+static void ext2_tea(uint32_t hash[4], uint32_t data[8])
{
uint32_t tea_delta = 0x9E3779B9;
uint32_t sum;
@@ -168,8 +172,7 @@
hash[1] += y;
}
-static uint32_t
-ext2_legacy_hash(const char *name, int len, int unsigned_char)
+static uint32_t ext2_legacy_hash(const char *name, int len, int unsigned_char)
{
uint32_t h0, h1 = 0x12A3FE2D, h2 = 0x37ABE8F9;
uint32_t multi = 0x6D22F5;
@@ -193,9 +196,8 @@
return (h1 << 1);
}
-static void
-ext2_prep_hashbuf(const char *src, uint32_t slen, uint32_t *dst, int dlen,
- int unsigned_char)
+static void ext2_prep_hashbuf(const char *src, uint32_t slen, uint32_t *dst,
+ int dlen, int unsigned_char)
{
uint32_t padding = slen | (slen << 8) | (slen << 16) | (slen << 24);
uint32_t buf_val;
@@ -241,10 +243,9 @@
}
}
-int
-ext2_htree_hash(const char *name, int len,
- const uint32_t *hash_seed, int hash_version,
- uint32_t *hash_major, uint32_t *hash_minor)
+int ext2_htree_hash(const char *name, int len, const uint32_t *hash_seed,
+ int hash_version, uint32_t *hash_major,
+ uint32_t *hash_minor)
{
uint32_t hash[4];
uint32_t data[8];
@@ -308,7 +309,7 @@
return EOK;
- error:
+error:
*hash_major = 0;
if (hash_minor)
*hash_minor = 0;
--- a/lwext4/ext4_hash.h
+++ b/lwext4/ext4_hash.h
@@ -49,10 +49,9 @@
* @param hash_minor output value
* @param hash_major output value
* @return standard error code*/
-int ext2_htree_hash(const char *name, int len,
- const uint32_t *hash_seed, int hash_version,
- uint32_t *hash_major, uint32_t *hash_minor);
-
+int ext2_htree_hash(const char *name, int len, const uint32_t *hash_seed,
+ int hash_version, uint32_t *hash_major,
+ uint32_t *hash_minor);
#endif /* EXT4_HASH_H_ */
--- a/lwext4/ext4_ialloc.c
+++ b/lwext4/ext4_ialloc.c
@@ -48,7 +48,6 @@
#include <ext4_block_group.h>
#include <ext4_bitmap.h>
-
/**@brief Convert i-node number to relative index in block group.
* @param sb Superblock
* @param inode I-node number to be converted
@@ -55,7 +54,7 @@
* @return Index of the i-node in the block group
*/
static uint32_t ext4_ialloc_inode2index_in_group(struct ext4_sblock *sb,
- uint32_t inode)
+ uint32_t inode)
{
uint32_t inodes_per_group = ext4_get32(sb, inodes_per_group);
return (inode - 1) % inodes_per_group;
@@ -68,13 +67,12 @@
*
*/
static uint32_t ext4_ialloc_index_in_group2inode(struct ext4_sblock *sb,
- uint32_t index, uint32_t bgid)
+ uint32_t index, uint32_t bgid)
{
uint32_t inodes_per_group = ext4_get32(sb, inodes_per_group);
return bgid * inodes_per_group + (index + 1);
}
-
/**@brief Compute block group number from the i-node number.
* @param sb Superblock
* @param inode I-node number to be found the block group for
@@ -81,13 +79,12 @@
* @return Block group number computed from i-node number
*/
static uint32_t ext4_ialloc_get_bgid_of_inode(struct ext4_sblock *sb,
- uint32_t inode)
+ uint32_t inode)
{
uint32_t inodes_per_group = ext4_get32(sb, inodes_per_group);
return (inode - 1) / inodes_per_group;
}
-
int ext4_ialloc_free_inode(struct ext4_fs *fs, uint32_t index, bool is_dir)
{
struct ext4_sblock *sb = &fs->sb;
@@ -101,8 +98,8 @@
return rc;
/* Load i-node bitmap */
- uint32_t bitmap_block_addr = ext4_bg_get_inode_bitmap(
- bg_ref.block_group, sb);
+ uint32_t bitmap_block_addr =
+ ext4_bg_get_inode_bitmap(bg_ref.block_group, sb);
struct ext4_block bitmap_block;
rc = ext4_block_get(fs->bdev, &bitmap_block, bitmap_block_addr);
@@ -124,19 +121,17 @@
/* If released i-node is a directory, decrement used directories count */
if (is_dir) {
- uint32_t bg_used_dirs = ext4_bg_get_used_dirs_count(
- bg_ref.block_group, sb);
+ uint32_t bg_used_dirs =
+ ext4_bg_get_used_dirs_count(bg_ref.block_group, sb);
bg_used_dirs--;
- ext4_bg_set_used_dirs_count(bg_ref.block_group, sb,
- bg_used_dirs);
+ ext4_bg_set_used_dirs_count(bg_ref.block_group, sb, bg_used_dirs);
}
/* Update block group free inodes count */
- uint32_t free_inodes = ext4_bg_get_free_inodes_count(
- bg_ref.block_group, sb);
+ uint32_t free_inodes =
+ ext4_bg_get_free_inodes_count(bg_ref.block_group, sb);
free_inodes++;
- ext4_bg_set_free_inodes_count(bg_ref.block_group, sb,
- free_inodes);
+ ext4_bg_set_free_inodes_count(bg_ref.block_group, sb, free_inodes);
bg_ref.dirty = true;
@@ -158,13 +153,13 @@
uint32_t bgid = fs->last_inode_bg_id;
uint32_t bg_count = ext4_block_group_cnt(sb);
uint32_t sb_free_inodes = ext4_get32(sb, free_inodes_count);
- bool rewind = false;
+ bool rewind = false;
/* Try to find free i-node in all block groups */
while (bgid <= bg_count) {
- if(bgid == bg_count){
- if(rewind)
+ if (bgid == bg_count) {
+ if (rewind)
break;
bg_count = fs->last_inode_bg_id;
bgid = 0;
@@ -187,12 +182,12 @@
/* Check if this block group is good candidate for allocation */
if (free_inodes > 0) {
/* Load block with bitmap */
- uint32_t bitmap_block_addr = ext4_bg_get_inode_bitmap(
- bg_ref.block_group, sb);
+ uint32_t bitmap_block_addr =
+ ext4_bg_get_inode_bitmap(bg_ref.block_group, sb);
struct ext4_block bitmap_block;
rc = ext4_block_get(fs->bdev, &bitmap_block, bitmap_block_addr);
- if (rc != EOK){
+ if (rc != EOK) {
ext4_fs_put_block_group_ref(&bg_ref);
return rc;
}
@@ -202,11 +197,11 @@
uint32_t index_in_group;
rc = ext4_bmap_bit_find_clr(bitmap_block.data, 0, inodes_in_group,
- &index_in_group);
+ &index_in_group);
/* Block group has not any free i-node */
if (rc == ENOSPC) {
rc = ext4_block_set(fs->bdev, &bitmap_block);
- if(rc != EOK){
+ if (rc != EOK) {
ext4_fs_put_block_group_ref(&bg_ref);
return rc;
}
@@ -224,7 +219,7 @@
bitmap_block.dirty = true;
ext4_block_set(fs->bdev, &bitmap_block);
- if (rc != EOK){
+ if (rc != EOK) {
ext4_fs_put_block_group_ref(&bg_ref);
return rc;
}
@@ -240,13 +235,10 @@
}
/* Decrease unused inodes count */
- if (ext4_bg_has_flag(bg,
- EXT4_BLOCK_GROUP_ITABLE_ZEROED)) {
- uint32_t unused =
- ext4_bg_get_itable_unused(bg, sb);
+ if (ext4_bg_has_flag(bg, EXT4_BLOCK_GROUP_ITABLE_ZEROED)) {
+ uint32_t unused = ext4_bg_get_itable_unused(bg, sb);
- uint32_t inodes_in_group =
- ext4_inodes_in_group_cnt(sb, bgid);
+ uint32_t inodes_in_group = ext4_inodes_in_group_cnt(sb, bgid);
uint32_t free = inodes_in_group - unused;
@@ -267,10 +259,8 @@
sb_free_inodes--;
ext4_set32(sb, free_inodes_count, sb_free_inodes);
-
/* Compute the absolute i-nodex number */
- *index = ext4_ialloc_index_in_group2inode(sb,
- index_in_group, bgid);
+ *index = ext4_ialloc_index_in_group2inode(sb, index_in_group, bgid);
fs->last_inode_bg_id = bgid;
@@ -291,4 +281,3 @@
/**
* @}
*/
-
--- a/lwext4/ext4_inode.c
+++ b/lwext4/ext4_inode.c
@@ -65,8 +65,8 @@
{
uint32_t v = to_le16(inode->mode);
- if(ext4_get32(sb, creator_os) == EXT4_SUPERBLOCK_OS_HURD){
- v |= ((uint32_t) to_le16(inode->osd2.hurd2.mode_high)) << 16;
+ if (ext4_get32(sb, creator_os) == EXT4_SUPERBLOCK_OS_HURD) {
+ v |= ((uint32_t)to_le16(inode->osd2.hurd2.mode_high)) << 16;
}
return v;
@@ -73,11 +73,11 @@
}
void ext4_inode_set_mode(struct ext4_sblock *sb, struct ext4_inode *inode,
- uint32_t mode)
+ uint32_t mode)
{
inode->mode = to_le16((mode << 16) >> 16);
- if(ext4_get32(sb, creator_os) == EXT4_SUPERBLOCK_OS_HURD)
+ if (ext4_get32(sb, creator_os) == EXT4_SUPERBLOCK_OS_HURD)
inode->osd2.hurd2.mode_high = to_le16(mode >> 16);
}
@@ -95,8 +95,8 @@
{
uint64_t v = to_le32(inode->size_lo);
- if ((ext4_get32(sb, rev_level) > 0) && (ext4_inode_is_type(sb, inode,
- EXT4_INODE_MODE_FILE)))
+ if ((ext4_get32(sb, rev_level) > 0) &&
+ (ext4_inode_is_type(sb, inode, EXT4_INODE_MODE_FILE)))
v |= ((uint64_t)to_le32(inode->size_hi)) << 32;
return v;
@@ -117,30 +117,25 @@
inode->access_time = to_le32(time);
}
-
uint32_t ext4_inode_get_change_inode_time(struct ext4_inode *inode)
{
return to_le32(inode->change_inode_time);
}
-void ext4_inode_set_change_inode_time(struct ext4_inode *inode,
- uint32_t time)
+void ext4_inode_set_change_inode_time(struct ext4_inode *inode, uint32_t time)
{
inode->change_inode_time = to_le32(time);
}
-
uint32_t ext4_inode_get_modification_time(struct ext4_inode *inode)
{
return to_le32(inode->modification_time);
}
-void ext4_inode_set_modification_time(struct ext4_inode *inode,
- uint32_t time)
+void ext4_inode_set_modification_time(struct ext4_inode *inode, uint32_t time)
{
inode->modification_time = to_le32(time);
}
-
uint32_t ext4_inode_get_deletion_time(struct ext4_inode *inode)
{
return to_le32(inode->deletion_time);
@@ -170,20 +165,19 @@
}
uint64_t ext4_inode_get_blocks_count(struct ext4_sblock *sb,
- struct ext4_inode *inode)
+ struct ext4_inode *inode)
{
uint64_t count = to_le32(inode->blocks_count_lo);
- if (ext4_sb_has_feature_read_only(sb,
- EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
+ if (ext4_sb_has_feature_read_only(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
/* 48-bit field */
- count |= ((uint64_t) to_le16(inode->osd2.linux2.blocks_high)) << 32;
+ count |= ((uint64_t)to_le16(inode->osd2.linux2.blocks_high)) << 32;
if (ext4_inode_has_flag(inode, EXT4_INODE_FLAG_HUGE_FILE)) {
uint32_t block_bits =
- ext4_inode_block_bits_count(ext4_sb_get_block_size(sb));
+ ext4_inode_block_bits_count(ext4_sb_get_block_size(sb));
return count << (block_bits - 9);
}
}
@@ -192,7 +186,7 @@
}
int ext4_inode_set_blocks_count(struct ext4_sblock *sb,
- struct ext4_inode *inode, uint64_t count)
+ struct ext4_inode *inode, uint64_t count)
{
/* 32-bit maximum */
uint64_t max = 0;
@@ -207,8 +201,7 @@
}
/* Check if there can be used huge files (many blocks) */
- if (!ext4_sb_has_feature_read_only(sb,
- EXT4_FEATURE_RO_COMPAT_HUGE_FILE))
+ if (!ext4_sb_has_feature_read_only(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE))
return EINVAL;
/* 48-bit maximum */
@@ -220,7 +213,8 @@
inode->osd2.linux2.blocks_high = to_le16(count >> 32);
ext4_inode_clear_flag(inode, EXT4_INODE_FLAG_HUGE_FILE);
} else {
- uint32_t block_bits = ext4_inode_block_bits_count(ext4_sb_get_block_size(sb));
+ uint32_t block_bits =
+ ext4_inode_block_bits_count(ext4_sb_get_block_size(sb));
ext4_inode_set_flag(inode, EXT4_INODE_FLAG_HUGE_FILE);
count = count >> (block_bits - 9);
@@ -250,20 +244,19 @@
}
uint64_t ext4_inode_get_file_acl(struct ext4_inode *inode,
- struct ext4_sblock *sb)
+ struct ext4_sblock *sb)
{
/*TODO: Verify it*/
uint64_t v = to_le32(inode->file_acl_lo);
if (ext4_get32(sb, creator_os) == EXT4_SUPERBLOCK_OS_LINUX)
- v |= ((uint32_t) to_le16(inode->osd2.linux2.file_acl_high)) << 16;
+ v |= ((uint32_t)to_le16(inode->osd2.linux2.file_acl_high)) << 16;
-
return v;
}
void ext4_inode_set_file_acl(struct ext4_inode *inode, struct ext4_sblock *sb,
- uint64_t acl)
+ uint64_t acl)
{
/*TODO: Verify it*/
inode->file_acl_lo = to_le32((acl << 32) >> 32);
@@ -277,7 +270,7 @@
return to_le32(inode->blocks[idx]);
}
void ext4_inode_set_direct_block(struct ext4_inode *inode, uint32_t idx,
- uint32_t block)
+ uint32_t block)
{
inode->blocks[idx] = to_le32(block);
}
@@ -288,16 +281,15 @@
}
void ext4_inode_set_indirect_block(struct ext4_inode *inode, uint32_t idx,
- uint32_t block)
+ uint32_t block)
{
inode->blocks[idx + EXT4_INODE_INDIRECT_BLOCK] = to_le32(block);
}
bool ext4_inode_is_type(struct ext4_sblock *sb, struct ext4_inode *inode,
- uint32_t type)
+ uint32_t type)
{
- return (ext4_inode_get_mode(sb, inode) &
- EXT4_INODE_MODE_TYPE_MASK) == type;
+ return (ext4_inode_get_mode(sb, inode) & EXT4_INODE_MODE_TYPE_MASK) == type;
}
bool ext4_inode_has_flag(struct ext4_inode *inode, uint32_t f)
@@ -319,24 +311,23 @@
ext4_inode_set_flags(inode, flags);
}
-bool ext4_inode_can_truncate(struct ext4_sblock *sb,
- struct ext4_inode *inode)
+bool ext4_inode_can_truncate(struct ext4_sblock *sb, struct ext4_inode *inode)
{
if ((ext4_inode_has_flag(inode, EXT4_INODE_FLAG_APPEND)) ||
- (ext4_inode_has_flag(inode, EXT4_INODE_FLAG_IMMUTABLE)))
+ (ext4_inode_has_flag(inode, EXT4_INODE_FLAG_IMMUTABLE)))
return false;
if ((ext4_inode_is_type(sb, inode, EXT4_INODE_MODE_FILE)) ||
- (ext4_inode_is_type(sb, inode, EXT4_INODE_MODE_DIRECTORY)))
+ (ext4_inode_is_type(sb, inode, EXT4_INODE_MODE_DIRECTORY)))
return true;
return false;
}
-struct ext4_extent_header * ext4_inode_get_extent_header(
- struct ext4_inode *inode)
+struct ext4_extent_header *
+ext4_inode_get_extent_header(struct ext4_inode *inode)
{
- return (struct ext4_extent_header *) inode->blocks;
+ return (struct ext4_extent_header *)inode->blocks;
}
/**
--- a/lwext4/ext4_inode.h
+++ b/lwext4/ext4_inode.h
@@ -58,7 +58,7 @@
* @param mode Mode to set to i-node
*/
void ext4_inode_set_mode(struct ext4_sblock *sb, struct ext4_inode *inode,
- uint32_t mode);
+ uint32_t mode);
/**@brief Get ID of the i-node owner (user id).
* @param inode I-node to load uid from
@@ -107,8 +107,7 @@
* @param inode I-node
* @param time Time of the last change (POSIX)
*/
-void ext4_inode_set_change_inode_time(struct ext4_inode *inode,
- uint32_t time);
+void ext4_inode_set_change_inode_time(struct ext4_inode *inode, uint32_t time);
/**@brief Get time, when i-node content was last modified.
* @param inode I-node
@@ -164,7 +163,7 @@
* @return Number of 512-bytes blocks
*/
uint64_t ext4_inode_get_blocks_count(struct ext4_sblock *sb,
- struct ext4_inode *inode);
+ struct ext4_inode *inode);
/**@brief Set number of 512-bytes blocks used for i-node.
* @param sb Superblock
@@ -173,7 +172,7 @@
* @return Error code
*/
int ext4_inode_set_blocks_count(struct ext4_sblock *sb,
- struct ext4_inode *inode, uint64_t cnt);
+ struct ext4_inode *inode, uint64_t cnt);
/**@brief Get flags (features) of i-node.
* @param inode I-node to get flags from
@@ -205,7 +204,7 @@
* @return Block address
*/
uint64_t ext4_inode_get_file_acl(struct ext4_inode *inode,
- struct ext4_sblock *sb);
+ struct ext4_sblock *sb);
/**@brief Set address of block, where are extended attributes located.
* @param inode I-node
@@ -212,8 +211,8 @@
* @param sb Superblock
* @param file_acl Block address
*/
-void ext4_inode_set_file_acl(struct ext4_inode *inode,
- struct ext4_sblock *sb, uint64_t acl);
+void ext4_inode_set_file_acl(struct ext4_inode *inode, struct ext4_sblock *sb,
+ uint64_t acl);
/**@brief Get block address of specified direct block.
* @param inode I-node to load block from
@@ -228,7 +227,7 @@
* @param fblock Physical block address
*/
void ext4_inode_set_direct_block(struct ext4_inode *inode, uint32_t idx,
- uint32_t block);
+ uint32_t block);
/**@brief Get block address of specified indirect block.
* @param inode I-node to get block address from
@@ -243,7 +242,7 @@
* @param fblock Physical block address
*/
void ext4_inode_set_indirect_block(struct ext4_inode *inode, uint32_t idx,
- uint32_t block);
+ uint32_t block);
/**@brief Check if i-node has specified type.
* @param sb Superblock
@@ -252,7 +251,7 @@
* @return Result of check operation
*/
bool ext4_inode_is_type(struct ext4_sblock *sb, struct ext4_inode *inode,
- uint32_t type);
+ uint32_t type);
/**@brief Check if i-node has specified flag.
* @param inode I-node to check flags of
@@ -284,7 +283,8 @@
* @param inode I-node to get extent header from
* @return Pointer to extent header of the root node
*/
-struct ext4_extent_header * ext4_inode_get_extent_header(struct ext4_inode *inode);
+struct ext4_extent_header *
+ext4_inode_get_extent_header(struct ext4_inode *inode);
#endif /* EXT4_INODE_H_ */
@@ -291,4 +291,3 @@
/**
* @}
*/
-
--- a/lwext4/ext4_super.c
+++ b/lwext4/ext4_super.c
@@ -42,7 +42,6 @@
#include <ext4_config.h>
#include <ext4_super.h>
-
uint32_t ext4_block_group_cnt(struct ext4_sblock *s)
{
uint64_t blocks_count = ext4_sb_get_blocks_cnt(s);
@@ -65,7 +64,6 @@
if (bgid < block_group_count - 1)
return blocks_per_group;
-
return (total_blocks - ((block_group_count - 1) * blocks_per_group));
}
@@ -72,10 +70,9 @@
uint32_t ext4_inodes_in_group_cnt(struct ext4_sblock *s, uint32_t bgid)
{
uint32_t block_group_count = ext4_block_group_cnt(s);
- uint32_t inodes_per_group = ext4_get32(s, inodes_per_group);
+ uint32_t inodes_per_group = ext4_get32(s, inodes_per_group);
uint32_t total_inodes = ext4_get32(s, inodes_count);
-
if (bgid < block_group_count - 1)
return inodes_per_group;
@@ -84,14 +81,14 @@
int ext4_sb_write(struct ext4_blockdev *bdev, struct ext4_sblock *s)
{
- return ext4_block_writebytes(bdev, EXT4_SUPERBLOCK_OFFSET,
- s, EXT4_SUPERBLOCK_SIZE);
+ return ext4_block_writebytes(bdev, EXT4_SUPERBLOCK_OFFSET, s,
+ EXT4_SUPERBLOCK_SIZE);
}
int ext4_sb_read(struct ext4_blockdev *bdev, struct ext4_sblock *s)
{
- return ext4_block_readbytes(bdev, EXT4_SUPERBLOCK_OFFSET,
- s, EXT4_SUPERBLOCK_SIZE);
+ return ext4_block_readbytes(bdev, EXT4_SUPERBLOCK_OFFSET, s,
+ EXT4_SUPERBLOCK_SIZE);
}
bool ext4_sb_check(struct ext4_sblock *s)
@@ -151,21 +148,18 @@
is_multiple(group, 3));
}
-
bool ext4_sb_is_super_in_bg(struct ext4_sblock *s, uint32_t group)
{
- if (ext4_sb_has_feature_read_only(s,
- EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
- !ext4_sb_sparse(group))
+ if (ext4_sb_has_feature_read_only(s, EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
+ !ext4_sb_sparse(group))
return false;
return true;
}
-static uint32_t ext4_bg_num_gdb_meta(struct ext4_sblock *s,
- uint32_t group)
+static uint32_t ext4_bg_num_gdb_meta(struct ext4_sblock *s, uint32_t group)
{
- uint32_t dsc_per_block = ext4_sb_get_block_size(s) /
- ext4_sb_get_desc_size(s);
+ uint32_t dsc_per_block =
+ ext4_sb_get_block_size(s) / ext4_sb_get_desc_size(s);
uint32_t metagroup = group / dsc_per_block;
uint32_t first = metagroup * dsc_per_block;
@@ -176,18 +170,16 @@
return 0;
}
-static uint32_t ext4_bg_num_gdb_nometa(struct ext4_sblock *s,
- uint32_t group)
+static uint32_t ext4_bg_num_gdb_nometa(struct ext4_sblock *s, uint32_t group)
{
if (!ext4_sb_is_super_in_bg(s, group))
return 0;
- uint32_t dsc_per_block = ext4_sb_get_block_size(s) /
- ext4_sb_get_desc_size(s);
+ uint32_t dsc_per_block =
+ ext4_sb_get_block_size(s) / ext4_sb_get_desc_size(s);
- uint32_t db_count = (ext4_block_group_cnt(s) + dsc_per_block - 1) /
- dsc_per_block;
+ uint32_t db_count =
+ (ext4_block_group_cnt(s) + dsc_per_block - 1) / dsc_per_block;
-
if (ext4_sb_has_feature_incompatible(s, EXT4_FEATURE_INCOMPAT_META_BG))
return ext4_sb_first_meta_bg(s);
@@ -196,32 +188,29 @@
uint32_t ext4_bg_num_gdb(struct ext4_sblock *s, uint32_t group)
{
- uint32_t dsc_per_block = ext4_sb_get_block_size(s) /
- ext4_sb_get_desc_size(s);
+ uint32_t dsc_per_block =
+ ext4_sb_get_block_size(s) / ext4_sb_get_desc_size(s);
uint32_t first_meta_bg = ext4_sb_first_meta_bg(s);
uint32_t metagroup = group / dsc_per_block;
if (!ext4_sb_has_feature_incompatible(s, EXT4_FEATURE_INCOMPAT_META_BG) ||
- metagroup < first_meta_bg)
+ metagroup < first_meta_bg)
return ext4_bg_num_gdb_nometa(s, group);
return ext4_bg_num_gdb_meta(s, group);
-
}
uint32_t ext4_num_base_meta_clusters(struct ext4_sblock *s,
- uint32_t block_group)
+ uint32_t block_group)
{
uint32_t num;
- uint32_t dsc_per_block = ext4_sb_get_block_size(s) /
- ext4_sb_get_desc_size(s);
+ uint32_t dsc_per_block =
+ ext4_sb_get_block_size(s) / ext4_sb_get_desc_size(s);
-
num = ext4_sb_is_super_in_bg(s, block_group);
if (!ext4_sb_has_feature_incompatible(s, EXT4_FEATURE_INCOMPAT_META_BG) ||
- block_group < ext4_sb_first_meta_bg(s) *
- dsc_per_block) {
+ block_group < ext4_sb_first_meta_bg(s) * dsc_per_block) {
if (num) {
num += ext4_bg_num_gdb(s, block_group);
num += ext4_get16(s, s_reserved_gdt_blocks);
--- a/lwext4/ext4_super.h
+++ b/lwext4/ext4_super.h
@@ -42,19 +42,16 @@
#ifndef EXT4_SUPER_H_
#define EXT4_SUPER_H_
-
#include <ext4_config.h>
#include <ext4_types.h>
-
-
/**@brief Blocks count get stored in superblock.
* @param s superblock descriptor
* @return count of blocks*/
static inline uint64_t ext4_sb_get_blocks_cnt(struct ext4_sblock *s)
{
- return ((uint64_t) to_le32(s->blocks_count_hi) << 32) |
- to_le32(s->blocks_count_lo);
+ return ((uint64_t)to_le32(s->blocks_count_hi) << 32) |
+ to_le32(s->blocks_count_lo);
}
/**@brief Free blocks count get stored in superblock.
@@ -62,8 +59,8 @@
* @return free blocks*/
static inline uint64_t ext4_sb_get_free_blocks_cnt(struct ext4_sblock *s)
{
- return ((uint64_t) to_le32(s->free_blocks_count_hi) << 32) |
- to_le32(s->free_blocks_count_lo);
+ return ((uint64_t)to_le32(s->free_blocks_count_hi) << 32) |
+ to_le32(s->free_blocks_count_lo);
}
/**@brief Free blocks count set.
@@ -70,7 +67,7 @@
* @param s superblock descriptor
* @param cnt new value of free blocks*/
static inline void ext4_sb_set_free_blocks_cnt(struct ext4_sblock *s,
- uint64_t cnt)
+ uint64_t cnt)
{
s->free_blocks_count_lo = to_le32((cnt << 32) >> 32);
s->free_blocks_count_hi = to_le32(cnt >> 32);
@@ -91,8 +88,9 @@
{
uint16_t size = to_le16(s->desc_size);
- return size < EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE ?
- EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE : size;
+ return size < EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE
+ ? EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE
+ : size;
}
/*************************Flags and features*********************************/
@@ -111,29 +109,27 @@
* @param v feature to check
* @return true if feature is supported*/
static inline bool ext4_sb_has_feature_compatible(struct ext4_sblock *s,
- uint32_t v)
+ uint32_t v)
{
return to_le32(s->features_compatible) & v;
}
-
/**@brief Support check of feature incompatible.
* @param s superblock descriptor
* @param v feature to check
* @return true if feature is supported*/
static inline bool ext4_sb_has_feature_incompatible(struct ext4_sblock *s,
- uint32_t v)
+ uint32_t v)
{
return to_le32(s->features_incompatible) & v;
}
-
/**@brief Support check of read only flag.
* @param s superblock descriptor
* @param v flag to check
* @return true if flag is supported*/
static inline bool ext4_sb_has_feature_read_only(struct ext4_sblock *s,
- uint32_t v)
+ uint32_t v)
{
return to_le32(s->features_read_only) & v;
}
@@ -143,7 +139,7 @@
* @param block_group block group
* @return flex group id*/
static inline uint32_t ext4_sb_bg_to_flex(struct ext4_sblock *s,
- uint32_t block_group)
+ uint32_t block_group)
{
return block_group >> to_le32(s->log_groups_per_flex);
}
@@ -210,13 +206,12 @@
* @return true if block group has superblock*/
bool ext4_sb_is_super_in_bg(struct ext4_sblock *s, uint32_t block_group);
-
/**@brief TODO:*/
uint32_t ext4_bg_num_gdb(struct ext4_sblock *s, uint32_t group);
/**@brief TODO:*/
uint32_t ext4_num_base_meta_clusters(struct ext4_sblock *s,
- uint32_t block_group);
+ uint32_t block_group);
#endif /* EXT4_SUPER_H_ */
@@ -223,4 +218,3 @@
/**
* @}
*/
-
--- a/lwext4/ext4_types.h
+++ b/lwext4/ext4_types.h
@@ -47,241 +47,229 @@
#include <stdint.h>
-
/*
* Structure of the super block
*/
-struct ext4_sblock {
- uint32_t inodes_count; /* I-nodes count */
- uint32_t blocks_count_lo; /* Blocks count */
- uint32_t reserved_blocks_count_lo; /* Reserved blocks count */
- uint32_t free_blocks_count_lo; /* Free blocks count */
- uint32_t free_inodes_count; /* Free inodes count */
- uint32_t first_data_block; /* First Data Block */
- uint32_t log_block_size; /* Block size */
- uint32_t log_cluster_size; /* Obsoleted fragment size */
- uint32_t blocks_per_group; /* Number of blocks per group */
- uint32_t frags_per_group; /* Obsoleted fragments per group */
- uint32_t inodes_per_group; /* Number of inodes per group */
- uint32_t mount_time; /* Mount time */
- uint32_t write_time; /* Write time */
- uint16_t mount_count; /* Mount count */
- uint16_t max_mount_count; /* Maximal mount count */
- uint16_t magic; /* Magic signature */
- uint16_t state; /* File system state */
- uint16_t errors; /* Behaviour when detecting errors */
- uint16_t minor_rev_level; /* Minor revision level */
- uint32_t last_check_time; /* Time of last check */
- uint32_t check_interval; /* Maximum time between checks */
- uint32_t creator_os; /* Creator OS */
- uint32_t rev_level; /* Revision level */
- uint16_t def_resuid; /* Default uid for reserved blocks */
- uint16_t def_resgid; /* Default gid for reserved blocks */
+struct ext4_sblock
+{
+ uint32_t inodes_count; /* I-nodes count */
+ uint32_t blocks_count_lo; /* Blocks count */
+ uint32_t reserved_blocks_count_lo; /* Reserved blocks count */
+ uint32_t free_blocks_count_lo; /* Free blocks count */
+ uint32_t free_inodes_count; /* Free inodes count */
+ uint32_t first_data_block; /* First Data Block */
+ uint32_t log_block_size; /* Block size */
+ uint32_t log_cluster_size; /* Obsoleted fragment size */
+ uint32_t blocks_per_group; /* Number of blocks per group */
+ uint32_t frags_per_group; /* Obsoleted fragments per group */
+ uint32_t inodes_per_group; /* Number of inodes per group */
+ uint32_t mount_time; /* Mount time */
+ uint32_t write_time; /* Write time */
+ uint16_t mount_count; /* Mount count */
+ uint16_t max_mount_count; /* Maximal mount count */
+ uint16_t magic; /* Magic signature */
+ uint16_t state; /* File system state */
+ uint16_t errors; /* Behaviour when detecting errors */
+ uint16_t minor_rev_level; /* Minor revision level */
+ uint32_t last_check_time; /* Time of last check */
+ uint32_t check_interval; /* Maximum time between checks */
+ uint32_t creator_os; /* Creator OS */
+ uint32_t rev_level; /* Revision level */
+ uint16_t def_resuid; /* Default uid for reserved blocks */
+ uint16_t def_resgid; /* Default gid for reserved blocks */
/* Fields for EXT4_DYNAMIC_REV superblocks only. */
- uint32_t first_inode; /* First non-reserved inode */
- uint16_t inode_size; /* Size of inode structure */
- uint16_t block_group_index; /* Block group index of this superblock */
- uint32_t features_compatible; /* Compatible feature set */
- uint32_t features_incompatible; /* Incompatible feature set */
- uint32_t features_read_only; /* Readonly-compatible feature set */
- uint8_t uuid[16]; /* 128-bit uuid for volume */
- char volume_name[16]; /* Volume name */
- char last_mounted[64]; /* Directory where last mounted */
- uint32_t algorithm_usage_bitmap; /* For compression */
+ uint32_t first_inode; /* First non-reserved inode */
+ uint16_t inode_size; /* Size of inode structure */
+ uint16_t block_group_index; /* Block group index of this superblock */
+ uint32_t features_compatible; /* Compatible feature set */
+ uint32_t features_incompatible; /* Incompatible feature set */
+ uint32_t features_read_only; /* Readonly-compatible feature set */
+ uint8_t uuid[16]; /* 128-bit uuid for volume */
+ char volume_name[16]; /* Volume name */
+ char last_mounted[64]; /* Directory where last mounted */
+ uint32_t algorithm_usage_bitmap; /* For compression */
/*
* Performance hints. Directory preallocation should only
* happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on.
*/
- uint8_t s_prealloc_blocks; /* Number of blocks to try to preallocate */
- uint8_t s_prealloc_dir_blocks; /* Number to preallocate for dirs */
- uint16_t s_reserved_gdt_blocks; /* Per group desc for online growth */
+ uint8_t s_prealloc_blocks; /* Number of blocks to try to preallocate */
+ uint8_t s_prealloc_dir_blocks; /* Number to preallocate for dirs */
+ uint16_t s_reserved_gdt_blocks; /* Per group desc for online growth */
/*
* Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set.
*/
- uint8_t journal_uuid[16]; /* UUID of journal superblock */
- uint32_t journal_inode_number; /* Inode number of journal file */
- uint32_t journal_dev; /* Device number of journal file */
- uint32_t last_orphan; /* Head of list of inodes to delete */
- uint32_t hash_seed[4]; /* HTREE hash seed */
- uint8_t default_hash_version; /* Default hash version to use */
+ uint8_t journal_uuid[16]; /* UUID of journal superblock */
+ uint32_t journal_inode_number; /* Inode number of journal file */
+ uint32_t journal_dev; /* Device number of journal file */
+ uint32_t last_orphan; /* Head of list of inodes to delete */
+ uint32_t hash_seed[4]; /* HTREE hash seed */
+ uint8_t default_hash_version; /* Default hash version to use */
uint8_t journal_backup_type;
- uint16_t desc_size; /* Size of group descriptor */
- uint32_t default_mount_opts; /* Default mount options */
- uint32_t first_meta_bg; /* First metablock block group */
- uint32_t mkfs_time; /* When the filesystem was created */
- uint32_t journal_blocks[17]; /* Backup of the journal inode */
+ uint16_t desc_size; /* Size of group descriptor */
+ uint32_t default_mount_opts; /* Default mount options */
+ uint32_t first_meta_bg; /* First metablock block group */
+ uint32_t mkfs_time; /* When the filesystem was created */
+ uint32_t journal_blocks[17]; /* Backup of the journal inode */
/* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */
- uint32_t blocks_count_hi; /* Blocks count */
- uint32_t reserved_blocks_count_hi; /* Reserved blocks count */
- uint32_t free_blocks_count_hi; /* Free blocks count */
- uint16_t min_extra_isize; /* All inodes have at least # bytes */
- uint16_t want_extra_isize; /* New inodes should reserve # bytes */
- uint32_t flags; /* Miscellaneous flags */
- uint16_t raid_stride; /* RAID stride */
- uint16_t mmp_interval; /* # seconds to wait in MMP checking */
- uint64_t mmp_block; /* Block for multi-mount protection */
- uint32_t raid_stripe_width; /* Blocks on all data disks (N * stride) */
- uint8_t log_groups_per_flex; /* FLEX_BG group size */
+ uint32_t blocks_count_hi; /* Blocks count */
+ uint32_t reserved_blocks_count_hi; /* Reserved blocks count */
+ uint32_t free_blocks_count_hi; /* Free blocks count */
+ uint16_t min_extra_isize; /* All inodes have at least # bytes */
+ uint16_t want_extra_isize; /* New inodes should reserve # bytes */
+ uint32_t flags; /* Miscellaneous flags */
+ uint16_t raid_stride; /* RAID stride */
+ uint16_t mmp_interval; /* # seconds to wait in MMP checking */
+ uint64_t mmp_block; /* Block for multi-mount protection */
+ uint32_t raid_stripe_width; /* Blocks on all data disks (N * stride) */
+ uint8_t log_groups_per_flex; /* FLEX_BG group size */
uint8_t reserved_char_pad;
uint16_t reserved_pad;
- uint64_t kbytes_written; /* Number of lifetime kilobytes written */
- uint32_t snapshot_inum; /* I-node number of active snapshot */
- uint32_t snapshot_id; /* Sequential ID of active snapshot */
- uint64_t snapshot_r_blocks_count; /* Reserved blocks for active snapshot's future use */
- uint32_t snapshot_list; /* I-node number of the head of the on-disk snapshot list */
- uint32_t error_count; /* Number of file system errors */
- uint32_t first_error_time; /* First time an error happened */
- uint32_t first_error_ino; /* I-node involved in first error */
- uint64_t first_error_block; /* Block involved of first error */
- uint8_t first_error_func[32]; /* Function where the error happened */
- uint32_t first_error_line; /* Line number where error happened */
- uint32_t last_error_time; /* Most recent time of an error */
- uint32_t last_error_ino; /* I-node involved in last error */
- uint32_t last_error_line; /* Line number where error happened */
- uint64_t last_error_block; /* Block involved of last error */
- uint8_t last_error_func[32]; /* Function where the error happened */
+ uint64_t kbytes_written; /* Number of lifetime kilobytes written */
+ uint32_t snapshot_inum; /* I-node number of active snapshot */
+ uint32_t snapshot_id; /* Sequential ID of active snapshot */
+ uint64_t snapshot_r_blocks_count; /* Reserved blocks for active snapshot's
+ future use */
+ uint32_t snapshot_list; /* I-node number of the head of the on-disk snapshot
+ list */
+ uint32_t error_count; /* Number of file system errors */
+ uint32_t first_error_time; /* First time an error happened */
+ uint32_t first_error_ino; /* I-node involved in first error */
+ uint64_t first_error_block; /* Block involved of first error */
+ uint8_t first_error_func[32]; /* Function where the error happened */
+ uint32_t first_error_line; /* Line number where error happened */
+ uint32_t last_error_time; /* Most recent time of an error */
+ uint32_t last_error_ino; /* I-node involved in last error */
+ uint32_t last_error_line; /* Line number where error happened */
+ uint64_t last_error_block; /* Block involved of last error */
+ uint8_t last_error_func[32]; /* Function where the error happened */
uint8_t mount_opts[64];
- uint32_t padding[112]; /* Padding to the end of the block */
+ uint32_t padding[112]; /* Padding to the end of the block */
} __attribute__((packed));
+#define EXT4_SUPERBLOCK_MAGIC 0xEF53
+#define EXT4_SUPERBLOCK_SIZE 1024
+#define EXT4_SUPERBLOCK_OFFSET 1024
-#define EXT4_SUPERBLOCK_MAGIC 0xEF53
-#define EXT4_SUPERBLOCK_SIZE 1024
-#define EXT4_SUPERBLOCK_OFFSET 1024
+#define EXT4_SUPERBLOCK_OS_LINUX 0
+#define EXT4_SUPERBLOCK_OS_HURD 1
-#define EXT4_SUPERBLOCK_OS_LINUX 0
-#define EXT4_SUPERBLOCK_OS_HURD 1
-
/*
* Misc. filesystem flags
*/
-#define EXT4_SUPERBLOCK_FLAGS_SIGNED_HASH 0x0001 /* Signed dirhash in use */
-#define EXT4_SUPERBLOCK_FLAGS_UNSIGNED_HASH 0x0002 /* Unsigned dirhash in use */
-#define EXT4_SUPERBLOCK_FLAGS_TEST_FILESYS 0x0004 /* to test development code */
+#define EXT4_SUPERBLOCK_FLAGS_SIGNED_HASH 0x0001 /* Signed dirhash in use */
+#define EXT4_SUPERBLOCK_FLAGS_UNSIGNED_HASH 0x0002 /* Unsigned dirhash in use \
+ */
+#define EXT4_SUPERBLOCK_FLAGS_TEST_FILESYS 0x0004 /* to test development code \
+ */
/*
* Filesystem states
*/
-#define EXT4_SUPERBLOCK_STATE_VALID_FS 0x0001 /* Unmounted cleanly */
-#define EXT4_SUPERBLOCK_STATE_ERROR_FS 0x0002 /* Errors detected */
-#define EXT4_SUPERBLOCK_STATE_ORPHAN_FS 0x0004 /* Orphans being recovered */
+#define EXT4_SUPERBLOCK_STATE_VALID_FS 0x0001 /* Unmounted cleanly */
+#define EXT4_SUPERBLOCK_STATE_ERROR_FS 0x0002 /* Errors detected */
+#define EXT4_SUPERBLOCK_STATE_ORPHAN_FS 0x0004 /* Orphans being recovered */
/*
* Behaviour when errors detected
*/
-#define EXT4_SUPERBLOCK_ERRORS_CONTINUE 1 /* Continue execution */
-#define EXT4_SUPERBLOCK_ERRORS_RO 2 /* Remount fs read-only */
-#define EXT4_SUPERBLOCK_ERRORS_PANIC 3 /* Panic */
-#define EXT4_SUPERBLOCK_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE
+#define EXT4_SUPERBLOCK_ERRORS_CONTINUE 1 /* Continue execution */
+#define EXT4_SUPERBLOCK_ERRORS_RO 2 /* Remount fs read-only */
+#define EXT4_SUPERBLOCK_ERRORS_PANIC 3 /* Panic */
+#define EXT4_SUPERBLOCK_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE
/*
* Compatible features
*/
-#define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001
-#define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002
-#define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004
-#define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008
-#define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010
-#define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020
+#define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001
+#define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002
+#define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004
+#define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008
+#define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010
+#define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020
-
/*
* Read-only compatible features
*/
-#define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
-#define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
-#define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
-#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008
-#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
-#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020
-#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040
-#define EXT4_FEATURE_RO_COMPAT_QUOTA 0x0100
-#define EXT4_FEATURE_RO_COMPAT_BIGALLOC 0x0200
+#define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
+#define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
+#define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
+#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008
+#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
+#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020
+#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040
+#define EXT4_FEATURE_RO_COMPAT_QUOTA 0x0100
+#define EXT4_FEATURE_RO_COMPAT_BIGALLOC 0x0200
#define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400
/*
* Incompatible features
*/
-#define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001
-#define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002
-#define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
-#define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
-#define EXT4_FEATURE_INCOMPAT_META_BG 0x0010
-#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */
-#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
-#define EXT4_FEATURE_INCOMPAT_MMP 0x0100
-#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
-#define EXT4_FEATURE_INCOMPAT_EA_INODE 0x0400 /* EA in inode */
-#define EXT4_FEATURE_INCOMPAT_DIRDATA 0x1000 /* data in dirent */
-#define EXT4_FEATURE_INCOMPAT_BG_USE_META_CSUM 0x2000 /* use crc32c for bg */
-#define EXT4_FEATURE_INCOMPAT_LARGEDIR 0x4000 /* >2GB or 3-lvl htree */
-#define EXT4_FEATURE_INCOMPAT_INLINE_DATA 0x8000 /* data in inode */
+#define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001
+#define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002
+#define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
+#define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
+#define EXT4_FEATURE_INCOMPAT_META_BG 0x0010
+#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */
+#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
+#define EXT4_FEATURE_INCOMPAT_MMP 0x0100
+#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
+#define EXT4_FEATURE_INCOMPAT_EA_INODE 0x0400 /* EA in inode */
+#define EXT4_FEATURE_INCOMPAT_DIRDATA 0x1000 /* data in dirent */
+#define EXT4_FEATURE_INCOMPAT_BG_USE_META_CSUM 0x2000 /* use crc32c for bg */
+#define EXT4_FEATURE_INCOMPAT_LARGEDIR 0x4000 /* >2GB or 3-lvl htree */
+#define EXT4_FEATURE_INCOMPAT_INLINE_DATA 0x8000 /* data in inode */
-
/*
* EXT2 supported feature set
*/
-#define EXT2_FEATURE_COMPAT_SUPP 0x0000
+#define EXT2_FEATURE_COMPAT_SUPP 0x0000
-#define EXT2_FEATURE_INCOMPAT_SUPP \
- (EXT4_FEATURE_INCOMPAT_FILETYPE | \
- EXT4_FEATURE_INCOMPAT_META_BG)
+#define EXT2_FEATURE_INCOMPAT_SUPP \
+ (EXT4_FEATURE_INCOMPAT_FILETYPE | EXT4_FEATURE_INCOMPAT_META_BG)
-#define EXT2_FEATURE_RO_COMPAT_SUPP \
- (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER | \
- EXT4_FEATURE_RO_COMPAT_LARGE_FILE | \
- EXT4_FEATURE_RO_COMPAT_BTREE_DIR)
+#define EXT2_FEATURE_RO_COMPAT_SUPP \
+ (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER | EXT4_FEATURE_RO_COMPAT_LARGE_FILE | \
+ EXT4_FEATURE_RO_COMPAT_BTREE_DIR)
/*
* EXT3 supported feature set
*/
-#define EXT3_FEATURE_COMPAT_SUPP \
- (EXT4_FEATURE_COMPAT_DIR_INDEX)
+#define EXT3_FEATURE_COMPAT_SUPP (EXT4_FEATURE_COMPAT_DIR_INDEX)
-#define EXT3_FEATURE_INCOMPAT_SUPP \
- (EXT4_FEATURE_INCOMPAT_FILETYPE | \
- EXT4_FEATURE_INCOMPAT_META_BG)
+#define EXT3_FEATURE_INCOMPAT_SUPP \
+ (EXT4_FEATURE_INCOMPAT_FILETYPE | EXT4_FEATURE_INCOMPAT_META_BG)
-#define EXT3_FEATURE_RO_COMPAT_SUPP \
- (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER | \
- EXT4_FEATURE_RO_COMPAT_LARGE_FILE | \
- EXT4_FEATURE_RO_COMPAT_BTREE_DIR)
+#define EXT3_FEATURE_RO_COMPAT_SUPP \
+ (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER | EXT4_FEATURE_RO_COMPAT_LARGE_FILE | \
+ EXT4_FEATURE_RO_COMPAT_BTREE_DIR)
/*
* EXT4 supported feature set
*/
-#define EXT4_FEATURE_COMPAT_SUPP \
- (EXT4_FEATURE_COMPAT_DIR_INDEX)
+#define EXT4_FEATURE_COMPAT_SUPP (EXT4_FEATURE_COMPAT_DIR_INDEX)
-#define EXT4_FEATURE_INCOMPAT_SUPP \
- (EXT4_FEATURE_INCOMPAT_FILETYPE | \
- EXT4_FEATURE_INCOMPAT_META_BG | \
- EXT4_FEATURE_INCOMPAT_EXTENTS | \
- EXT4_FEATURE_INCOMPAT_FLEX_BG | \
- EXT4_FEATURE_INCOMPAT_64BIT)
+#define EXT4_FEATURE_INCOMPAT_SUPP \
+ (EXT4_FEATURE_INCOMPAT_FILETYPE | EXT4_FEATURE_INCOMPAT_META_BG | \
+ EXT4_FEATURE_INCOMPAT_EXTENTS | EXT4_FEATURE_INCOMPAT_FLEX_BG | \
+ EXT4_FEATURE_INCOMPAT_64BIT)
-#define EXT4_FEATURE_RO_COMPAT_SUPP \
- (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER | \
- EXT4_FEATURE_RO_COMPAT_LARGE_FILE | \
- EXT4_FEATURE_RO_COMPAT_GDT_CSUM | \
- EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \
- EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \
- EXT4_FEATURE_RO_COMPAT_BTREE_DIR | \
- EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
+#define EXT4_FEATURE_RO_COMPAT_SUPP \
+ (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER | EXT4_FEATURE_RO_COMPAT_LARGE_FILE | \
+ EXT4_FEATURE_RO_COMPAT_GDT_CSUM | EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \
+ EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | EXT4_FEATURE_RO_COMPAT_BTREE_DIR | \
+ EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
-
/*Ignored features:
* RECOVER - journaling in lwext4 is not supported
* (probably won,t be ever...)
* MMP - multi mout protection (impossible scenario)
* */
-#define FEATURE_INCOMPAT_IGNORED \
- EXT4_FEATURE_INCOMPAT_RECOVER | \
- EXT4_FEATURE_INCOMPAT_MMP
+#define FEATURE_INCOMPAT_IGNORED \
+ EXT4_FEATURE_INCOMPAT_RECOVER | EXT4_FEATURE_INCOMPAT_MMP
#if 0
/*TODO: Features incompatible to implement*/
@@ -295,8 +283,9 @@
EXT4_FEATURE_RO_COMPAT_QUOTA)
#endif
-struct ext4_fs {
- struct ext4_blockdev*bdev;
+struct ext4_fs
+{
+ struct ext4_blockdev *bdev;
struct ext4_sblock sb;
uint64_t inode_block_limits[4];
@@ -305,42 +294,45 @@
uint32_t last_inode_bg_id;
};
+#define EXT4_BLOCK_GROUP_INODE_UNINIT 0x0001 /* Inode table/bitmap not in use \
+ */
+#define EXT4_BLOCK_GROUP_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */
+#define EXT4_BLOCK_GROUP_ITABLE_ZEROED \
+ 0x0004 /* On-disk itable initialized to zero */
-#define EXT4_BLOCK_GROUP_INODE_UNINIT 0x0001 /* Inode table/bitmap not in use */
-#define EXT4_BLOCK_GROUP_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */
-#define EXT4_BLOCK_GROUP_ITABLE_ZEROED 0x0004 /* On-disk itable initialized to zero */
-
/*
* Structure of a blocks group descriptor
*/
-struct ext4_bgroup {
- uint32_t block_bitmap_lo; /* Blocks bitmap block */
- uint32_t inode_bitmap_lo; /* Inodes bitmap block */
- uint32_t inode_table_first_block_lo; /* Inodes table block */
- uint16_t free_blocks_count_lo; /* Free blocks count */
- uint16_t free_inodes_count_lo; /* Free inodes count */
- uint16_t used_dirs_count_lo; /* Directories count */
- uint16_t flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */
- uint32_t exclude_bitmap_lo; /* Exclude bitmap for snapshots */
- uint16_t block_bitmap_csum_lo; /* crc32c(s_uuid+grp_num+bbitmap) LE */
- uint16_t inode_bitmap_csum_lo; /* crc32c(s_uuid+grp_num+ibitmap) LE */
- uint16_t itable_unused_lo; /* Unused inodes count */
- uint16_t checksum; /* crc16(sb_uuid+group+desc) */
+struct ext4_bgroup
+{
+ uint32_t block_bitmap_lo; /* Blocks bitmap block */
+ uint32_t inode_bitmap_lo; /* Inodes bitmap block */
+ uint32_t inode_table_first_block_lo; /* Inodes table block */
+ uint16_t free_blocks_count_lo; /* Free blocks count */
+ uint16_t free_inodes_count_lo; /* Free inodes count */
+ uint16_t used_dirs_count_lo; /* Directories count */
+ uint16_t flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */
+ uint32_t exclude_bitmap_lo; /* Exclude bitmap for snapshots */
+ uint16_t block_bitmap_csum_lo; /* crc32c(s_uuid+grp_num+bbitmap) LE */
+ uint16_t inode_bitmap_csum_lo; /* crc32c(s_uuid+grp_num+ibitmap) LE */
+ uint16_t itable_unused_lo; /* Unused inodes count */
+ uint16_t checksum; /* crc16(sb_uuid+group+desc) */
- uint32_t block_bitmap_hi; /* Blocks bitmap block MSB */
- uint32_t inode_bitmap_hi; /* I-nodes bitmap block MSB */
- uint32_t inode_table_first_block_hi; /* I-nodes table block MSB */
- uint16_t free_blocks_count_hi; /* Free blocks count MSB */
- uint16_t free_inodes_count_hi; /* Free i-nodes count MSB */
- uint16_t used_dirs_count_hi; /* Directories count MSB */
- uint16_t itable_unused_hi; /* Unused inodes count MSB */
- uint32_t exclude_bitmap_hi; /* Exclude bitmap block MSB */
- uint16_t block_bitmap_csum_hi; /* crc32c(s_uuid+grp_num+bbitmap) BE */
- uint16_t inode_bitmap_csum_hi; /* crc32c(s_uuid+grp_num+ibitmap) BE */
- uint32_t reserved; /* Padding */
-} ;
+ uint32_t block_bitmap_hi; /* Blocks bitmap block MSB */
+ uint32_t inode_bitmap_hi; /* I-nodes bitmap block MSB */
+ uint32_t inode_table_first_block_hi; /* I-nodes table block MSB */
+ uint16_t free_blocks_count_hi; /* Free blocks count MSB */
+ uint16_t free_inodes_count_hi; /* Free i-nodes count MSB */
+ uint16_t used_dirs_count_hi; /* Directories count MSB */
+ uint16_t itable_unused_hi; /* Unused inodes count MSB */
+ uint32_t exclude_bitmap_hi; /* Exclude bitmap block MSB */
+ uint16_t block_bitmap_csum_hi; /* crc32c(s_uuid+grp_num+bbitmap) BE */
+ uint16_t inode_bitmap_csum_hi; /* crc32c(s_uuid+grp_num+ibitmap) BE */
+ uint32_t reserved; /* Padding */
+};
-struct ext4_block_group_ref {
+struct ext4_block_group_ref
+{
struct ext4_block block;
struct ext4_bgroup *block_group;
struct ext4_fs *fs;
@@ -348,46 +340,50 @@
bool dirty;
};
-#define EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE 32
-#define EXT4_MAX_BLOCK_GROUP_DESCRIPTOR_SIZE 64
+#define EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE 32
+#define EXT4_MAX_BLOCK_GROUP_DESCRIPTOR_SIZE 64
-#define EXT4_MIN_BLOCK_SIZE 1024 /* 1 KiB */
-#define EXT4_MAX_BLOCK_SIZE 65536 /* 64 KiB */
-#define EXT4_REV0_INODE_SIZE 128
+#define EXT4_MIN_BLOCK_SIZE 1024 /* 1 KiB */
+#define EXT4_MAX_BLOCK_SIZE 65536 /* 64 KiB */
+#define EXT4_REV0_INODE_SIZE 128
-#define EXT4_INODE_BLOCK_SIZE 512
+#define EXT4_INODE_BLOCK_SIZE 512
-#define EXT4_INODE_DIRECT_BLOCK_COUNT 12
-#define EXT4_INODE_INDIRECT_BLOCK EXT4_INODE_DIRECT_BLOCK_COUNT
-#define EXT4_INODE_DOUBLE_INDIRECT_BLOCK (EXT4_INODE_INDIRECT_BLOCK + 1)
-#define EXT4_INODE_TRIPPLE_INDIRECT_BLOCK (EXT4_INODE_DOUBLE_INDIRECT_BLOCK + 1)
-#define EXT4_INODE_BLOCKS (EXT4_INODE_TRIPPLE_INDIRECT_BLOCK + 1)
-#define EXT4_INODE_INDIRECT_BLOCK_COUNT (EXT4_INODE_BLOCKS - EXT4_INODE_DIRECT_BLOCK_COUNT)
+#define EXT4_INODE_DIRECT_BLOCK_COUNT 12
+#define EXT4_INODE_INDIRECT_BLOCK EXT4_INODE_DIRECT_BLOCK_COUNT
+#define EXT4_INODE_DOUBLE_INDIRECT_BLOCK (EXT4_INODE_INDIRECT_BLOCK + 1)
+#define EXT4_INODE_TRIPPLE_INDIRECT_BLOCK (EXT4_INODE_DOUBLE_INDIRECT_BLOCK + 1)
+#define EXT4_INODE_BLOCKS (EXT4_INODE_TRIPPLE_INDIRECT_BLOCK + 1)
+#define EXT4_INODE_INDIRECT_BLOCK_COUNT \
+ (EXT4_INODE_BLOCKS - EXT4_INODE_DIRECT_BLOCK_COUNT)
/*
* Structure of an inode on the disk
*/
-struct ext4_inode {
- uint16_t mode; /* File mode */
- uint16_t uid; /* Low 16 bits of owner uid */
- uint32_t size_lo; /* Size in bytes */
- uint32_t access_time; /* Access time */
- uint32_t change_inode_time; /* I-node change time */
- uint32_t modification_time; /* Modification time */
- uint32_t deletion_time; /* Deletion time */
- uint16_t gid; /* Low 16 bits of group id */
- uint16_t links_count; /* Links count */
- uint32_t blocks_count_lo; /* Blocks count */
- uint32_t flags; /* File flags */
- uint32_t unused_osd1; /* OS dependent - not used in HelenOS */
- uint32_t blocks[EXT4_INODE_BLOCKS]; /* Pointers to blocks */
- uint32_t generation; /* File version (for NFS) */
- uint32_t file_acl_lo; /* File ACL */
+struct ext4_inode
+{
+ uint16_t mode; /* File mode */
+ uint16_t uid; /* Low 16 bits of owner uid */
+ uint32_t size_lo; /* Size in bytes */
+ uint32_t access_time; /* Access time */
+ uint32_t change_inode_time; /* I-node change time */
+ uint32_t modification_time; /* Modification time */
+ uint32_t deletion_time; /* Deletion time */
+ uint16_t gid; /* Low 16 bits of group id */
+ uint16_t links_count; /* Links count */
+ uint32_t blocks_count_lo; /* Blocks count */
+ uint32_t flags; /* File flags */
+ uint32_t unused_osd1; /* OS dependent - not used in HelenOS */
+ uint32_t blocks[EXT4_INODE_BLOCKS]; /* Pointers to blocks */
+ uint32_t generation; /* File version (for NFS) */
+ uint32_t file_acl_lo; /* File ACL */
uint32_t size_hi;
- uint32_t obso_faddr; /* Obsoleted fragment address */
+ uint32_t obso_faddr; /* Obsoleted fragment address */
- union {
- struct {
+ union
+ {
+ struct
+ {
uint16_t blocks_high;
uint16_t file_acl_high;
uint16_t uid_high;
@@ -394,7 +390,8 @@
uint16_t gid_high;
uint32_t reserved2;
} linux2;
- struct {
+ struct
+ {
uint16_t reserved1;
uint16_t mode_high;
uint16_t uid_high;
@@ -401,105 +398,112 @@
uint16_t gid_high;
uint32_t author;
} hurd2;
- } __attribute__ ((packed)) osd2;
+ } __attribute__((packed)) osd2;
uint16_t extra_isize;
uint16_t pad1;
- uint32_t ctime_extra; /* Extra change time (nsec << 2 | epoch) */
- uint32_t mtime_extra; /* Extra Modification time (nsec << 2 | epoch) */
- uint32_t atime_extra; /* Extra Access time (nsec << 2 | epoch) */
- uint32_t crtime; /* File creation time */
- uint32_t crtime_extra; /* Extra file creation time (nsec << 2 | epoch) */
- uint32_t version_hi; /* High 32 bits for 64-bit version */
-} __attribute__ ((packed)) ;
+ uint32_t ctime_extra; /* Extra change time (nsec << 2 | epoch) */
+ uint32_t mtime_extra; /* Extra Modification time (nsec << 2 | epoch) */
+ uint32_t atime_extra; /* Extra Access time (nsec << 2 | epoch) */
+ uint32_t crtime; /* File creation time */
+ uint32_t crtime_extra; /* Extra file creation time (nsec << 2 | epoch) */
+ uint32_t version_hi; /* High 32 bits for 64-bit version */
+} __attribute__((packed));
-#define EXT4_INODE_MODE_FIFO 0x1000
-#define EXT4_INODE_MODE_CHARDEV 0x2000
-#define EXT4_INODE_MODE_DIRECTORY 0x4000
-#define EXT4_INODE_MODE_BLOCKDEV 0x6000
-#define EXT4_INODE_MODE_FILE 0x8000
-#define EXT4_INODE_MODE_SOFTLINK 0xA000
-#define EXT4_INODE_MODE_SOCKET 0xC000
-#define EXT4_INODE_MODE_TYPE_MASK 0xF000
+#define EXT4_INODE_MODE_FIFO 0x1000
+#define EXT4_INODE_MODE_CHARDEV 0x2000
+#define EXT4_INODE_MODE_DIRECTORY 0x4000
+#define EXT4_INODE_MODE_BLOCKDEV 0x6000
+#define EXT4_INODE_MODE_FILE 0x8000
+#define EXT4_INODE_MODE_SOFTLINK 0xA000
+#define EXT4_INODE_MODE_SOCKET 0xC000
+#define EXT4_INODE_MODE_TYPE_MASK 0xF000
/*
* Inode flags
*/
-#define EXT4_INODE_FLAG_SECRM 0x00000001 /* Secure deletion */
-#define EXT4_INODE_FLAG_UNRM 0x00000002 /* Undelete */
-#define EXT4_INODE_FLAG_COMPR 0x00000004 /* Compress file */
-#define EXT4_INODE_FLAG_SYNC 0x00000008 /* Synchronous updates */
-#define EXT4_INODE_FLAG_IMMUTABLE 0x00000010 /* Immutable file */
-#define EXT4_INODE_FLAG_APPEND 0x00000020 /* writes to file may only append */
-#define EXT4_INODE_FLAG_NODUMP 0x00000040 /* do not dump file */
-#define EXT4_INODE_FLAG_NOATIME 0x00000080 /* do not update atime */
+#define EXT4_INODE_FLAG_SECRM 0x00000001 /* Secure deletion */
+#define EXT4_INODE_FLAG_UNRM 0x00000002 /* Undelete */
+#define EXT4_INODE_FLAG_COMPR 0x00000004 /* Compress file */
+#define EXT4_INODE_FLAG_SYNC 0x00000008 /* Synchronous updates */
+#define EXT4_INODE_FLAG_IMMUTABLE 0x00000010 /* Immutable file */
+#define EXT4_INODE_FLAG_APPEND 0x00000020 /* writes to file may only append */
+#define EXT4_INODE_FLAG_NODUMP 0x00000040 /* do not dump file */
+#define EXT4_INODE_FLAG_NOATIME 0x00000080 /* do not update atime */
/* Compression flags */
-#define EXT4_INODE_FLAG_DIRTY 0x00000100
-#define EXT4_INODE_FLAG_COMPRBLK 0x00000200 /* One or more compressed clusters */
-#define EXT4_INODE_FLAG_NOCOMPR 0x00000400 /* Don't compress */
-#define EXT4_INODE_FLAG_ECOMPR 0x00000800 /* Compression error */
+#define EXT4_INODE_FLAG_DIRTY 0x00000100
+#define EXT4_INODE_FLAG_COMPRBLK \
+ 0x00000200 /* One or more compressed clusters */
+#define EXT4_INODE_FLAG_NOCOMPR 0x00000400 /* Don't compress */
+#define EXT4_INODE_FLAG_ECOMPR 0x00000800 /* Compression error */
-#define EXT4_INODE_FLAG_INDEX 0x00001000 /* hash-indexed directory */
-#define EXT4_INODE_FLAG_IMAGIC 0x00002000 /* AFS directory */
-#define EXT4_INODE_FLAG_JOURNAL_DATA 0x00004000 /* File data should be journaled */
-#define EXT4_INODE_FLAG_NOTAIL 0x00008000 /* File tail should not be merged */
-#define EXT4_INODE_FLAG_DIRSYNC 0x00010000 /* Dirsync behaviour (directories only) */
-#define EXT4_INODE_FLAG_TOPDIR 0x00020000 /* Top of directory hierarchies */
-#define EXT4_INODE_FLAG_HUGE_FILE 0x00040000 /* Set to each huge file */
-#define EXT4_INODE_FLAG_EXTENTS 0x00080000 /* Inode uses extents */
-#define EXT4_INODE_FLAG_EA_INODE 0x00200000 /* Inode used for large EA */
-#define EXT4_INODE_FLAG_EOFBLOCKS 0x00400000 /* Blocks allocated beyond EOF */
-#define EXT4_INODE_FLAG_RESERVED 0x80000000 /* reserved for ext4 lib */
+#define EXT4_INODE_FLAG_INDEX 0x00001000 /* hash-indexed directory */
+#define EXT4_INODE_FLAG_IMAGIC 0x00002000 /* AFS directory */
+#define EXT4_INODE_FLAG_JOURNAL_DATA \
+ 0x00004000 /* File data should be journaled */
+#define EXT4_INODE_FLAG_NOTAIL 0x00008000 /* File tail should not be merged */
+#define EXT4_INODE_FLAG_DIRSYNC \
+ 0x00010000 /* Dirsync behaviour (directories only) */
+#define EXT4_INODE_FLAG_TOPDIR 0x00020000 /* Top of directory hierarchies */
+#define EXT4_INODE_FLAG_HUGE_FILE 0x00040000 /* Set to each huge file */
+#define EXT4_INODE_FLAG_EXTENTS 0x00080000 /* Inode uses extents */
+#define EXT4_INODE_FLAG_EA_INODE 0x00200000 /* Inode used for large EA */
+#define EXT4_INODE_FLAG_EOFBLOCKS 0x00400000 /* Blocks allocated beyond EOF */
+#define EXT4_INODE_FLAG_RESERVED 0x80000000 /* reserved for ext4 lib */
-#define EXT4_INODE_ROOT_INDEX 2
+#define EXT4_INODE_ROOT_INDEX 2
-struct ext4_inode_ref {
- struct ext4_block block;
+struct ext4_inode_ref
+{
+ struct ext4_block block;
struct ext4_inode *inode;
- struct ext4_fs *fs;
+ struct ext4_fs *fs;
uint32_t index;
bool dirty;
-} ;
+};
+#define EXT4_DIRECTORY_FILENAME_LEN 255
-#define EXT4_DIRECTORY_FILENAME_LEN 255
+#define EXT4_DIRECTORY_FILETYPE_UNKNOWN 0
+#define EXT4_DIRECTORY_FILETYPE_REG_FILE 1
+#define EXT4_DIRECTORY_FILETYPE_DIR 2
+#define EXT4_DIRECTORY_FILETYPE_CHRDEV 3
+#define EXT4_DIRECTORY_FILETYPE_BLKDEV 4
+#define EXT4_DIRECTORY_FILETYPE_FIFO 5
+#define EXT4_DIRECTORY_FILETYPE_SOCK 6
+#define EXT4_DIRECTORY_FILETYPE_SYMLINK 7
-#define EXT4_DIRECTORY_FILETYPE_UNKNOWN 0
-#define EXT4_DIRECTORY_FILETYPE_REG_FILE 1
-#define EXT4_DIRECTORY_FILETYPE_DIR 2
-#define EXT4_DIRECTORY_FILETYPE_CHRDEV 3
-#define EXT4_DIRECTORY_FILETYPE_BLKDEV 4
-#define EXT4_DIRECTORY_FILETYPE_FIFO 5
-#define EXT4_DIRECTORY_FILETYPE_SOCK 6
-#define EXT4_DIRECTORY_FILETYPE_SYMLINK 7
+union ext4_directory_entry_ll_internal
+{
+ uint8_t name_length_high; /* Higher 8 bits of name length */
+ uint8_t inode_type; /* Type of referenced inode (in rev >= 0.5) */
+} __attribute__((packed));
-union ext4_directory_entry_ll_internal{
- uint8_t name_length_high; /* Higher 8 bits of name length */
- uint8_t inode_type; /* Type of referenced inode (in rev >= 0.5) */
-} __attribute__ ((packed));
-
/**
* Linked list directory entry structure
*/
-struct ext4_directory_entry_ll {
- uint32_t inode; /* I-node for the entry */
- uint16_t entry_length; /* Distance to the next directory entry */
- uint8_t name_length; /* Lower 8 bits of name length */
+struct ext4_directory_entry_ll
+{
+ uint32_t inode; /* I-node for the entry */
+ uint16_t entry_length; /* Distance to the next directory entry */
+ uint8_t name_length; /* Lower 8 bits of name length */
union ext4_directory_entry_ll_internal in;
- uint8_t name[EXT4_DIRECTORY_FILENAME_LEN]; /* Entry name */
-} __attribute__((packed)) ;
+ uint8_t name[EXT4_DIRECTORY_FILENAME_LEN]; /* Entry name */
+} __attribute__((packed));
-struct ext4_directory_iterator {
+struct ext4_directory_iterator
+{
struct ext4_inode_ref *inode_ref;
struct ext4_block current_block;
uint64_t current_offset;
- struct ext4_directory_entry_ll *current;
+ struct ext4_directory_entry_ll *current;
};
-struct ext4_directory_search_result {
+struct ext4_directory_search_result
+{
struct ext4_block block;
struct ext4_directory_entry_ll *dentry;
};
@@ -506,39 +510,45 @@
/* Structures for indexed directory */
-struct ext4_directory_dx_countlimit {
+struct ext4_directory_dx_countlimit
+{
uint16_t limit;
uint16_t count;
-} ;
+};
-struct ext4_directory_dx_dot_entry {
+struct ext4_directory_dx_dot_entry
+{
uint32_t inode;
uint16_t entry_length;
uint8_t name_length;
uint8_t inode_type;
uint8_t name[4];
-} ;
+};
-struct ext4_directory_dx_root_info {
+struct ext4_directory_dx_root_info
+{
uint32_t reserved_zero;
uint8_t hash_version;
uint8_t info_length;
uint8_t indirect_levels;
uint8_t unused_flags;
-} ;
+};
-struct ext4_directory_dx_entry {
+struct ext4_directory_dx_entry
+{
uint32_t hash;
uint32_t block;
-} ;
+};
-struct ext4_directory_dx_root {
+struct ext4_directory_dx_root
+{
struct ext4_directory_dx_dot_entry dots[2];
struct ext4_directory_dx_root_info info;
struct ext4_directory_dx_entry entries[];
};
-struct ext4_fake_directory_entry {
+struct ext4_fake_directory_entry
+{
uint32_t inode;
uint16_t entry_length;
uint8_t name_length;
@@ -545,38 +555,42 @@
uint8_t inode_type;
};
-struct ext4_directory_dx_node {
+struct ext4_directory_dx_node
+{
struct ext4_fake_directory_entry fake;
struct ext4_directory_dx_entry entries[];
};
-struct ext4_directory_dx_block {
+struct ext4_directory_dx_block
+{
struct ext4_block block;
struct ext4_directory_dx_entry *entries;
struct ext4_directory_dx_entry *position;
-} ;
+};
-#define EXT4_ERR_BAD_DX_DIR (-25000)
+#define EXT4_ERR_BAD_DX_DIR (-25000)
-#define EXT4_LINK_MAX 65000
+#define EXT4_LINK_MAX 65000
/*
* This is the extent on-disk structure.
* It's used at the bottom of the tree.
*/
-struct ext4_extent {
- uint32_t first_block; /* First logical block extent covers */
- uint16_t block_count; /* Number of blocks covered by extent */
- uint16_t start_hi; /* High 16 bits of physical block */
- uint32_t start_lo; /* Low 32 bits of physical block */
-} ;
+struct ext4_extent
+{
+ uint32_t first_block; /* First logical block extent covers */
+ uint16_t block_count; /* Number of blocks covered by extent */
+ uint16_t start_hi; /* High 16 bits of physical block */
+ uint32_t start_lo; /* Low 32 bits of physical block */
+};
/*
* This is index on-disk structure.
* It's used at all the levels except the bottom.
*/
-struct ext4_extent_index {
- uint32_t first_block; /* Index covers logical blocks from 'block' */
+struct ext4_extent_index
+{
+ uint32_t first_block; /* Index covers logical blocks from 'block' */
/**
* Pointer to the physical block of the next
@@ -586,48 +600,51 @@
uint32_t leaf_lo;
uint16_t leaf_hi;
uint16_t padding;
-} ;
+};
/*
* Each block (leaves and indexes), even inode-stored has header.
*/
-struct ext4_extent_header {
+struct ext4_extent_header
+{
uint16_t magic;
- uint16_t entries_count; /* Number of valid entries */
- uint16_t max_entries_count; /* Capacity of store in entries */
- uint16_t depth; /* Has tree real underlying blocks? */
- uint32_t generation; /* generation of the tree */
-} ;
+ uint16_t entries_count; /* Number of valid entries */
+ uint16_t max_entries_count; /* Capacity of store in entries */
+ uint16_t depth; /* Has tree real underlying blocks? */
+ uint32_t generation; /* generation of the tree */
+};
-struct ext4_extent_path {
+struct ext4_extent_path
+{
struct ext4_block block;
uint16_t depth;
struct ext4_extent_header *header;
struct ext4_extent_index *index;
struct ext4_extent *extent;
-} ;
+};
-#define EXT4_EXTENT_MAGIC 0xF30A
+#define EXT4_EXTENT_MAGIC 0xF30A
-#define EXT4_EXTENT_FIRST(header) \
- ((struct ext4_extent *) (((char *) (header)) + sizeof(struct ext4_extent_header)))
+#define EXT4_EXTENT_FIRST(header) \
+ ((struct ext4_extent *)(((char *)(header)) + \
+ sizeof(struct ext4_extent_header)))
-#define EXT4_EXTENT_FIRST_INDEX(header) \
- ((struct ext4_extent_index *) (((char *) (header)) + sizeof(struct ext4_extent_header)))
+#define EXT4_EXTENT_FIRST_INDEX(header) \
+ ((struct ext4_extent_index *)(((char *)(header)) + \
+ sizeof(struct ext4_extent_header)))
-
/* EXT3 HTree directory indexing */
-#define EXT2_HTREE_LEGACY 0
-#define EXT2_HTREE_HALF_MD4 1
-#define EXT2_HTREE_TEA 2
-#define EXT2_HTREE_LEGACY_UNSIGNED 3
-#define EXT2_HTREE_HALF_MD4_UNSIGNED 4
-#define EXT2_HTREE_TEA_UNSIGNED 5
+#define EXT2_HTREE_LEGACY 0
+#define EXT2_HTREE_HALF_MD4 1
+#define EXT2_HTREE_TEA 2
+#define EXT2_HTREE_LEGACY_UNSIGNED 3
+#define EXT2_HTREE_HALF_MD4_UNSIGNED 4
+#define EXT2_HTREE_TEA_UNSIGNED 5
-#define EXT2_HTREE_EOF 0x7FFFFFFFUL
+#define EXT2_HTREE_EOF 0x7FFFFFFFUL
-
-struct ext4_hash_info {
+struct ext4_hash_info
+{
uint32_t hash;
uint32_t minor_hash;
uint32_t hash_version;
@@ -636,35 +653,26 @@
/*****************************************************************************/
-
#ifdef CONFIG_BIG_ENDIAN
static inline uint64_t to_le64(uint64_t n)
{
- return ((n & 0xff) << 56) |
- ((n & 0xff00) << 40) |
- ((n & 0xff0000) << 24) |
- ((n & 0xff000000LL) << 8) |
- ((n & 0xff00000000LL) >> 8) |
- ((n & 0xff0000000000LL) >> 24) |
- ((n & 0xff000000000000LL) >> 40) |
- ((n & 0xff00000000000000LL) >> 56);
+ return ((n & 0xff) << 56) | ((n & 0xff00) << 40) | ((n & 0xff0000) << 24) |
+ ((n & 0xff000000LL) << 8) | ((n & 0xff00000000LL) >> 8) |
+ ((n & 0xff0000000000LL) >> 24) | ((n & 0xff000000000000LL) >> 40) |
+ ((n & 0xff00000000000000LL) >> 56);
}
static inline uint32_t to_le32(uint32_t n)
{
- return ((n & 0xff) << 24) |
- ((n & 0xff00) << 8) |
- ((n & 0xff0000) >> 8) |
- ((n & 0xff000000) >> 24);
+ return ((n & 0xff) << 24) | ((n & 0xff00) << 8) | ((n & 0xff0000) >> 8) |
+ ((n & 0xff000000) >> 24);
}
static inline uint16_t to_le16(uint16_t n)
{
- return ((n & 0xff) << 8) |
- ((n & 0xff00) >> 8);
+ return ((n & 0xff) << 8) | ((n & 0xff00) >> 8);
}
-
#else
#define to_le64(_n) _n
#define to_le32(_n) _n
@@ -673,14 +681,21 @@
/****************************Access macros to ext4 structures*****************/
-#define ext4_get32(s, f) to_le32((s)->f)
-#define ext4_get16(s, f) to_le16((s)->f)
-#define ext4_get8(s, f) (s)->f
+#define ext4_get32(s, f) to_le32((s)->f)
+#define ext4_get16(s, f) to_le16((s)->f)
+#define ext4_get8(s, f) (s)->f
-
-#define ext4_set32(s, f, v) do { (s)->f = to_le32(v); }while(0)
-#define ext4_set16(s, f, v) do { (s)->f = to_le16(v); }while(0)
-#define ext4_set8 (s, f, v) do { (s)->f = (v); }while(0)
+#define ext4_set32(s, f, v) \
+ do { \
+ (s)->f = to_le32(v); \
+ } while (0)
+#define ext4_set16(s, f, v) \
+ do { \
+ (s)->f = to_le16(v); \
+ } while (0)
+#define ext4_set8 \
+ (s, f, v) do { (s)->f = (v); } \
+ while (0)
#endif /* EXT4_TYPES_H_ */