#Check: http://www.cmake.org/Wiki/CMake_Generator_Specific_Information\r
#"Unix Makefiles"\r
#"Eclipse CDT4 - Unix Makefiles"\r
-PROJECT_SETUP = "Eclipse CDT4 - Unix Makefiles"\r
+PROJECT_SETUP = "Unix Makefiles"\r
\r
generic:\r
rm -R -f build_generic\r
\r
\r
\r
-
\ No newline at end of file
+ \r
* @param de Directory entry\r
* @return I-node number\r
*/\r
-static inline uint32_t ext4_dir_entry_ll_get_inode(\r
- struct ext4_directory_entry_ll *de)\r
+static inline uint32_t\r
+ext4_dir_entry_ll_get_inode(struct ext4_directory_entry_ll *de)\r
{\r
return to_le32(de->inode);\r
}\r
\r
-\r
/**@brief Set i-node number to directory entry.\r
* @param de Directory entry\r
* @param inode I-node number\r
*/\r
-static inline void ext4_dir_entry_ll_set_inode(\r
- struct ext4_directory_entry_ll *de, uint32_t inode)\r
+static inline void\r
+ext4_dir_entry_ll_set_inode(struct ext4_directory_entry_ll *de, uint32_t inode)\r
{\r
de->inode = to_le32(inode);\r
}\r
\r
-\r
/**@brief Get directory entry length.\r
* @param de Directory entry\r
* @return Entry length\r
*/\r
-static inline uint16_t ext4_dir_entry_ll_get_entry_length(\r
- struct ext4_directory_entry_ll *de)\r
+static inline uint16_t\r
+ext4_dir_entry_ll_get_entry_length(struct ext4_directory_entry_ll *de)\r
{\r
return to_le16(de->entry_length);\r
}\r
* @param de Directory entry\r
* @param length Entry length\r
*/\r
-static inline void ext4_dir_entry_ll_set_entry_length(\r
- struct ext4_directory_entry_ll *de, uint16_t len)\r
+static inline void\r
+ext4_dir_entry_ll_set_entry_length(struct ext4_directory_entry_ll *de,\r
+ uint16_t len)\r
{\r
de->entry_length = to_le16(len);\r
}\r
\r
-\r
/**@brief Get directory entry name length.\r
* @param sb Superblock\r
* @param de Directory entry\r
* @return Entry name length\r
*/\r
-static inline uint16_t ext4_dir_entry_ll_get_name_length(struct ext4_sblock *sb,\r
- struct ext4_directory_entry_ll *de)\r
+static inline uint16_t\r
+ext4_dir_entry_ll_get_name_length(struct ext4_sblock *sb,\r
+ struct ext4_directory_entry_ll *de)\r
{\r
uint16_t v = de->name_length;\r
\r
if ((ext4_get32(sb, rev_level) == 0) &&\r
- (ext4_get32(sb, minor_rev_level) < 5))\r
+ (ext4_get32(sb, minor_rev_level) < 5))\r
v |= ((uint16_t)de->in.name_length_high) << 8;\r
\r
return v;\r
* @param de Directory entry\r
* @param length Entry name length\r
*/\r
-static inline void ext4_dir_entry_ll_set_name_length(struct ext4_sblock *sb,\r
- struct ext4_directory_entry_ll *de, uint16_t len)\r
+static inline void ext4_dir_entry_ll_set_name_length(\r
+ struct ext4_sblock *sb, struct ext4_directory_entry_ll *de, uint16_t len)\r
{\r
de->name_length = (len << 8) >> 8;\r
\r
if ((ext4_get32(sb, rev_level) == 0) &&\r
- (ext4_get32(sb, minor_rev_level) < 5))\r
+ (ext4_get32(sb, minor_rev_level) < 5))\r
de->in.name_length_high = len >> 8;\r
}\r
\r
-\r
/**@brief Get i-node type of directory entry.\r
* @param sb Superblock\r
* @param de Directory entry\r
* @return I-node type (file, dir, etc.)\r
*/\r
-static inline uint8_t ext4_dir_entry_ll_get_inode_type(struct ext4_sblock *sb,\r
- struct ext4_directory_entry_ll *de)\r
+static inline uint8_t\r
+ext4_dir_entry_ll_get_inode_type(struct ext4_sblock *sb,\r
+ struct ext4_directory_entry_ll *de)\r
{\r
if ((ext4_get32(sb, rev_level) > 0) ||\r
- (ext4_get32(sb, minor_rev_level) >= 5))\r
+ (ext4_get32(sb, minor_rev_level) >= 5))\r
return de->in.inode_type;\r
\r
return EXT4_DIRECTORY_FILETYPE_UNKNOWN;\r
* @param type I-node type (file, dir, etc.)\r
*/\r
\r
-static inline void ext4_dir_entry_ll_set_inode_type(struct ext4_sblock *sb,\r
- struct ext4_directory_entry_ll *de, uint8_t type)\r
+static inline void ext4_dir_entry_ll_set_inode_type(\r
+ struct ext4_sblock *sb, struct ext4_directory_entry_ll *de, uint8_t type)\r
{\r
if ((ext4_get32(sb, rev_level) > 0) ||\r
- (ext4_get32(sb, minor_rev_level) >= 5))\r
+ (ext4_get32(sb, minor_rev_level) >= 5))\r
de->in.inode_type = type;\r
}\r
\r
* @return Error code\r
*/\r
int ext4_dir_iterator_init(struct ext4_directory_iterator *it,\r
- struct ext4_inode_ref *inode_ref, uint64_t pos);\r
+ struct ext4_inode_ref *inode_ref, uint64_t pos);\r
\r
/**@brief Jump to the next valid entry\r
* @param it Initialized iterator\r
* @param name_len Length of entry name\r
*/\r
void ext4_dir_write_entry(struct ext4_sblock *sb,\r
- struct ext4_directory_entry_ll *entry, uint16_t entry_len,\r
- struct ext4_inode_ref *child, const char *name, size_t name_len);\r
+ struct ext4_directory_entry_ll *entry,\r
+ uint16_t entry_len, struct ext4_inode_ref *child,\r
+ const char *name, size_t name_len);\r
\r
/**@brief Add new entry to the directory.\r
* @param parent Directory i-node\r
* @return Error code\r
*/\r
int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,\r
- uint32_t name_len, struct ext4_inode_ref *child);\r
+ uint32_t name_len, struct ext4_inode_ref *child);\r
\r
/**@brief Find directory entry with passed name.\r
* @param result Result structure to be returned if entry found\r
* @return Error code\r
*/\r
int ext4_dir_find_entry(struct ext4_directory_search_result *result,\r
- struct ext4_inode_ref *parent, const char *name, uint32_t name_len);\r
+ struct ext4_inode_ref *parent, const char *name,\r
+ uint32_t name_len);\r
\r
/**@brief Remove directory entry.\r
* @param parent Directory i-node\r
* @return Error code\r
*/\r
int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,\r
- uint32_t name_len);\r
+ uint32_t name_len);\r
\r
/**@brief Try to insert entry to concrete data block.\r
* @param sb Superblock\r
* @return Error code\r
*/\r
int ext4_dir_try_insert_entry(struct ext4_sblock *sb,\r
- struct ext4_block *target_block, struct ext4_inode_ref *child,\r
- const char *name, uint32_t name_len);\r
+ struct ext4_block *target_block,\r
+ struct ext4_inode_ref *child, const char *name,\r
+ uint32_t name_len);\r
\r
/**@brief Try to find entry in block by name.\r
* @param block Block containing entries\r
* @return Error code\r
*/\r
int ext4_dir_find_in_block(struct ext4_block *block, struct ext4_sblock *sb,\r
- size_t name_len, const char *name,\r
- struct ext4_directory_entry_ll **res_entry);\r
+ size_t name_len, const char *name,\r
+ struct ext4_directory_entry_ll **res_entry);\r
\r
/**@brief Simple function to release allocated data from result.\r
* @param parent Parent inode\r
*\r
*/\r
int ext4_dir_destroy_result(struct ext4_inode_ref *parent,\r
- struct ext4_directory_search_result *result);\r
+ struct ext4_directory_search_result *result);\r
\r
#endif /* EXT4_DIR_H_ */\r
\r
/**\r
* @}\r
*/\r
-\r
-\r
* @param v Hash algorithm version\r
*/\r
static inline void ext4_dir_dx_root_info_set_hash_version(\r
- struct ext4_directory_dx_root_info *root_info, uint8_t v)\r
+ struct ext4_directory_dx_root_info *root_info, uint8_t v)\r
{\r
root_info->hash_version = v;\r
}\r
* @param info_length Length of the structure\r
*/\r
static inline void ext4_dir_dx_root_info_set_info_length(\r
- struct ext4_directory_dx_root_info *root_info, uint8_t len)\r
+ struct ext4_directory_dx_root_info *root_info, uint8_t len)\r
{\r
root_info->info_length = len;\r
}\r
* @param climit Pointer to counlimit structure\r
* @return Maximum of entries in node\r
*/\r
-static inline uint16_t ext4_dir_dx_countlimit_get_limit(\r
- struct ext4_directory_dx_countlimit *climit)\r
+static inline uint16_t\r
+ext4_dir_dx_countlimit_get_limit(struct ext4_directory_dx_countlimit *climit)\r
{\r
return to_le16(climit->limit);\r
}\r
* @param climit Pointer to counlimit structure\r
* @param limit Maximum of entries in node\r
*/\r
-static inline void ext4_dir_dx_countlimit_set_limit(\r
- struct ext4_directory_dx_countlimit *climit, uint16_t limit)\r
+static inline void\r
+ext4_dir_dx_countlimit_set_limit(struct ext4_directory_dx_countlimit *climit,\r
+ uint16_t limit)\r
{\r
climit->limit = to_le16(limit);\r
}\r
\r
-\r
/**@brief Get current number of index node entries.\r
* @param climit Pointer to counlimit structure\r
* @return Number of entries in node\r
*/\r
-static inline uint16_t ext4_dir_dx_countlimit_get_count(\r
- struct ext4_directory_dx_countlimit *climit)\r
+static inline uint16_t\r
+ext4_dir_dx_countlimit_get_count(struct ext4_directory_dx_countlimit *climit)\r
{\r
return to_le16(climit->count);\r
}\r
* @param climit Pointer to counlimit structure\r
* @param count Number of entries in node\r
*/\r
-static inline void ext4_dir_dx_countlimit_set_count(\r
- struct ext4_directory_dx_countlimit *climit, uint16_t count)\r
+static inline void\r
+ext4_dir_dx_countlimit_set_count(struct ext4_directory_dx_countlimit *climit,\r
+ uint16_t count)\r
{\r
climit->count = to_le16(count);\r
}\r
* @param entry Pointer to index entry\r
* @return Hash value\r
*/\r
-static inline uint32_t ext4_dir_dx_entry_get_hash(\r
- struct ext4_directory_dx_entry *entry)\r
+static inline uint32_t\r
+ext4_dir_dx_entry_get_hash(struct ext4_directory_dx_entry *entry)\r
{\r
return to_le32(entry->hash);\r
}\r
* @param entry Pointer to index entry\r
* @param hash Hash value\r
*/\r
-static inline void ext4_dir_dx_entry_set_hash(\r
- struct ext4_directory_dx_entry *entry, uint32_t hash)\r
+static inline void\r
+ext4_dir_dx_entry_set_hash(struct ext4_directory_dx_entry *entry, uint32_t hash)\r
{\r
entry->hash = to_le32(hash);\r
}\r
* @param entry Pointer to index entry\r
* @return Block address of child node\r
*/\r
-static inline uint32_t ext4_dir_dx_entry_get_block(\r
- struct ext4_directory_dx_entry *entry)\r
+static inline uint32_t\r
+ext4_dir_dx_entry_get_block(struct ext4_directory_dx_entry *entry)\r
{\r
return to_le32(entry->block);\r
}\r
* @param entry Pointer to index entry\r
* @param block Block address of child node\r
*/\r
-static inline void ext4_dir_dx_entry_set_block(\r
- struct ext4_directory_dx_entry *entry, uint32_t block)\r
+static inline void\r
+ext4_dir_dx_entry_set_block(struct ext4_directory_dx_entry *entry,\r
+ uint32_t block)\r
{\r
entry->block = to_le32(block);\r
}\r
\r
/**@brief Sort entry item.*/\r
-struct ext4_dx_sort_entry {\r
+struct ext4_dx_sort_entry\r
+{\r
uint32_t hash;\r
uint32_t rec_len;\r
void *dentry;\r
};\r
\r
-\r
static int ext4_dir_dx_hash_string(struct ext4_hash_info *hinfo, int len,\r
- const char *name)\r
+ const char *name)\r
{\r
return ext2_htree_hash(name, len, hinfo->seed, hinfo->hash_version,\r
- &hinfo->hash, &hinfo->minor_hash);\r
+ &hinfo->hash, &hinfo->minor_hash);\r
}\r
\r
-\r
-\r
/****************************************************************************/\r
\r
int ext4_dir_dx_init(struct ext4_inode_ref *dir)\r
{\r
/* Load block 0, where will be index root located */\r
uint32_t fblock;\r
- int rc = ext4_fs_get_inode_data_block_index(dir, 0,\r
- &fblock);\r
+ int rc = ext4_fs_get_inode_data_block_index(dir, 0, &fblock);\r
if (rc != EOK)\r
return rc;\r
\r
\r
/* Set limit and current number of entries */\r
struct ext4_directory_dx_countlimit *countlimit =\r
- (struct ext4_directory_dx_countlimit *) &root->entries;\r
+ (struct ext4_directory_dx_countlimit *)&root->entries;\r
\r
ext4_dir_dx_countlimit_set_count(countlimit, 1);\r
\r
- uint32_t block_size =\r
- ext4_sb_get_block_size(&dir->fs->sb);\r
- uint32_t entry_space =\r
- block_size - 2 * sizeof(struct ext4_directory_dx_dot_entry) -\r
- sizeof(struct ext4_directory_dx_root_info);\r
+ uint32_t block_size = ext4_sb_get_block_size(&dir->fs->sb);\r
+ uint32_t entry_space = block_size -\r
+ 2 * sizeof(struct ext4_directory_dx_dot_entry) -\r
+ sizeof(struct ext4_directory_dx_root_info);\r
uint16_t root_limit = entry_space / sizeof(struct ext4_directory_dx_entry);\r
ext4_dir_dx_countlimit_set_limit(countlimit, root_limit);\r
\r
* @return Standard error code\r
*/\r
static int ext4_dir_hinfo_init(struct ext4_hash_info *hinfo,\r
- struct ext4_block *root_block, struct ext4_sblock *sb, size_t name_len,\r
- const char *name)\r
+ struct ext4_block *root_block,\r
+ struct ext4_sblock *sb, size_t name_len,\r
+ const char *name)\r
{\r
struct ext4_directory_dx_root *root =\r
- (struct ext4_directory_dx_root *) root_block->data;\r
+ (struct ext4_directory_dx_root *)root_block->data;\r
\r
if ((root->info.hash_version != EXT2_HTREE_LEGACY) &&\r
- (root->info.hash_version != EXT2_HTREE_HALF_MD4) &&\r
- (root->info.hash_version != EXT2_HTREE_TEA))\r
+ (root->info.hash_version != EXT2_HTREE_HALF_MD4) &&\r
+ (root->info.hash_version != EXT2_HTREE_TEA))\r
return EXT4_ERR_BAD_DX_DIR;\r
\r
/* Check unused flags */\r
entry_space = entry_space / sizeof(struct ext4_directory_dx_entry);\r
\r
uint16_t limit = ext4_dir_dx_countlimit_get_limit(\r
- (struct ext4_directory_dx_countlimit *) &root->entries);\r
+ (struct ext4_directory_dx_countlimit *)&root->entries);\r
if (limit != entry_space)\r
return EXT4_ERR_BAD_DX_DIR;\r
\r
/* Check hash version and modify if necessary */\r
- hinfo->hash_version =\r
- ext4_dir_dx_root_info_get_hash_version(&root->info);\r
+ hinfo->hash_version = ext4_dir_dx_root_info_get_hash_version(&root->info);\r
if ((hinfo->hash_version <= EXT2_HTREE_TEA) &&\r
- (ext4_sb_check_flag(sb, EXT4_SUPERBLOCK_FLAGS_UNSIGNED_HASH))) {\r
+ (ext4_sb_check_flag(sb, EXT4_SUPERBLOCK_FLAGS_UNSIGNED_HASH))) {\r
/* Use unsigned hash */\r
hinfo->hash_version += 3;\r
}\r
* @return Standard error code\r
*/\r
static int ext4_dir_dx_get_leaf(struct ext4_hash_info *hinfo,\r
- struct ext4_inode_ref *inode_ref, struct ext4_block *root_block,\r
- struct ext4_directory_dx_block **dx_block,\r
- struct ext4_directory_dx_block *dx_blocks)\r
+ struct ext4_inode_ref *inode_ref,\r
+ struct ext4_block *root_block,\r
+ struct ext4_directory_dx_block **dx_block,\r
+ struct ext4_directory_dx_block *dx_blocks)\r
{\r
struct ext4_directory_dx_block *tmp_dx_block = dx_blocks;\r
struct ext4_directory_dx_root *root =\r
- (struct ext4_directory_dx_root *) root_block->data;\r
+ (struct ext4_directory_dx_root *)root_block->data;\r
struct ext4_directory_dx_entry *entries =\r
- (struct ext4_directory_dx_entry *) &root->entries;\r
+ (struct ext4_directory_dx_entry *)&root->entries;\r
\r
uint16_t limit = ext4_dir_dx_countlimit_get_limit(\r
- (struct ext4_directory_dx_countlimit *) entries);\r
+ (struct ext4_directory_dx_countlimit *)entries);\r
uint8_t indirect_level =\r
- ext4_dir_dx_root_info_get_indirect_levels(&root->info);\r
+ ext4_dir_dx_root_info_get_indirect_levels(&root->info);\r
\r
struct ext4_block *tmp_block = root_block;\r
struct ext4_directory_dx_entry *p;\r
/* Walk through the index tree */\r
while (true) {\r
uint16_t count = ext4_dir_dx_countlimit_get_count(\r
- (struct ext4_directory_dx_countlimit *) entries);\r
+ (struct ext4_directory_dx_countlimit *)entries);\r
if ((count == 0) || (count > limit))\r
return EXT4_ERR_BAD_DX_DIR;\r
\r
indirect_level--;\r
\r
uint32_t fblock;\r
- int rc = ext4_fs_get_inode_data_block_index(inode_ref,\r
- next_block, &fblock);\r
+ int rc =\r
+ ext4_fs_get_inode_data_block_index(inode_ref, next_block, &fblock);\r
if (rc != EOK)\r
return rc;\r
\r
if (rc != EOK)\r
return rc;\r
\r
- entries = ((struct ext4_directory_dx_node *) tmp_block->data)->entries;\r
+ entries = ((struct ext4_directory_dx_node *)tmp_block->data)->entries;\r
limit = ext4_dir_dx_countlimit_get_limit(\r
- (struct ext4_directory_dx_countlimit *) entries);\r
+ (struct ext4_directory_dx_countlimit *)entries);\r
\r
- uint16_t entry_space =\r
- ext4_sb_get_block_size(&inode_ref->fs->sb) -\r
- sizeof(struct ext4_fake_directory_entry);\r
+ uint16_t entry_space = ext4_sb_get_block_size(&inode_ref->fs->sb) -\r
+ sizeof(struct ext4_fake_directory_entry);\r
\r
entry_space = entry_space / sizeof(struct ext4_directory_dx_entry);\r
\r
* @return Standard Error codee\r
*/\r
static int ext4_dir_dx_next_block(struct ext4_inode_ref *inode_ref,\r
- uint32_t hash, struct ext4_directory_dx_block *dx_block,\r
- struct ext4_directory_dx_block *dx_blocks)\r
+ uint32_t hash,\r
+ struct ext4_directory_dx_block *dx_block,\r
+ struct ext4_directory_dx_block *dx_blocks)\r
{\r
uint32_t num_handles = 0;\r
struct ext4_directory_dx_block *p = dx_block;\r
while (true) {\r
p->position++;\r
uint16_t count = ext4_dir_dx_countlimit_get_count(\r
- (struct ext4_directory_dx_countlimit *) p->entries);\r
+ (struct ext4_directory_dx_countlimit *)p->entries);\r
\r
if (p->position < p->entries + count)\r
break;\r
\r
/* Fill new path */\r
while (num_handles--) {\r
- uint32_t block_idx =\r
- ext4_dir_dx_entry_get_block(p->position);\r
+ uint32_t block_idx = ext4_dir_dx_entry_get_block(p->position);\r
uint32_t block_addr;\r
\r
- int rc = ext4_fs_get_inode_data_block_index(inode_ref,\r
- block_idx, &block_addr);\r
- if(rc != EOK)\r
+ int rc = ext4_fs_get_inode_data_block_index(inode_ref, block_idx,\r
+ &block_addr);\r
+ if (rc != EOK)\r
return rc;\r
\r
-\r
struct ext4_block block;\r
rc = ext4_block_get(inode_ref->fs->bdev, &block, block_addr);\r
if (rc != EOK)\r
\r
/* Don't forget to put old block (prevent memory leak) */\r
rc = ext4_block_set(inode_ref->fs->bdev, &p->block);\r
- if(rc != EOK)\r
+ if (rc != EOK)\r
return rc;\r
\r
-\r
memcpy(&p->block, &p->block, sizeof(block));\r
- p->entries = ((struct ext4_directory_dx_node *) block.data)->entries;\r
+ p->entries = ((struct ext4_directory_dx_node *)block.data)->entries;\r
p->position = p->entries;\r
}\r
\r
return ENOENT;\r
}\r
\r
-\r
-\r
-int ext4_dir_dx_find_entry(struct ext4_directory_search_result * result,\r
- struct ext4_inode_ref *inode_ref, size_t name_len, const char *name)\r
+int ext4_dir_dx_find_entry(struct ext4_directory_search_result *result,\r
+ struct ext4_inode_ref *inode_ref, size_t name_len,\r
+ const char *name)\r
{\r
/* Load direct block 0 (index root) */\r
uint32_t root_block_addr;\r
int rc2;\r
- int rc = ext4_fs_get_inode_data_block_index(inode_ref, 0,\r
- &root_block_addr);\r
+ int rc = ext4_fs_get_inode_data_block_index(inode_ref, 0, &root_block_addr);\r
if (rc != EOK)\r
return rc;\r
\r
\r
/* Initialize hash info (compute hash value) */\r
struct ext4_hash_info hinfo;\r
- rc = ext4_dir_hinfo_init(&hinfo, &root_block, &fs->sb,\r
- name_len, name);\r
+ rc = ext4_dir_hinfo_init(&hinfo, &root_block, &fs->sb, name_len, name);\r
if (rc != EOK) {\r
ext4_block_set(fs->bdev, &root_block);\r
return EXT4_ERR_BAD_DX_DIR;\r
struct ext4_directory_dx_block *dx_block;\r
struct ext4_directory_dx_block *tmp;\r
\r
- rc = ext4_dir_dx_get_leaf(&hinfo, inode_ref, &root_block,\r
- &dx_block, dx_blocks);\r
+ rc = ext4_dir_dx_get_leaf(&hinfo, inode_ref, &root_block, &dx_block,\r
+ dx_blocks);\r
if (rc != EOK) {\r
ext4_block_set(fs->bdev, &root_block);\r
return EXT4_ERR_BAD_DX_DIR;\r
do {\r
/* Load leaf block */\r
uint32_t leaf_block_idx =\r
- ext4_dir_dx_entry_get_block(dx_block->position);\r
+ ext4_dir_dx_entry_get_block(dx_block->position);\r
uint32_t leaf_block_addr;\r
\r
- rc = ext4_fs_get_inode_data_block_index(inode_ref,\r
- leaf_block_idx, &leaf_block_addr);\r
+ rc = ext4_fs_get_inode_data_block_index(inode_ref, leaf_block_idx,\r
+ &leaf_block_addr);\r
if (rc != EOK)\r
goto cleanup;\r
\r
\r
/* Linear search inside block */\r
struct ext4_directory_entry_ll *res_dentry;\r
- rc = ext4_dir_find_in_block(&leaf_block, &fs->sb,\r
- name_len, name, &res_dentry);\r
+ rc = ext4_dir_find_in_block(&leaf_block, &fs->sb, name_len, name,\r
+ &res_dentry);\r
\r
/* Found => return it */\r
if (rc == EOK) {\r
\r
/* Not found, leave untouched */\r
rc2 = ext4_block_set(fs->bdev, &leaf_block);\r
- if(rc2 != EOK)\r
+ if (rc2 != EOK)\r
goto cleanup;\r
\r
if (rc != ENOENT)\r
goto cleanup;\r
\r
/* check if the next block could be checked */\r
- rc = ext4_dir_dx_next_block(inode_ref, hinfo.hash,\r
- dx_block, &dx_blocks[0]);\r
+ rc = ext4_dir_dx_next_block(inode_ref, hinfo.hash, dx_block,\r
+ &dx_blocks[0]);\r
if (rc < 0)\r
goto cleanup;\r
} while (rc == ENOENT);\r
}\r
\r
#if CONFIG_DIR_INDEX_COMB_SORT\r
-#define SWAP_ENTRY(se1, se2) do { \\r
- struct ext4_dx_sort_entry tmp = se1; \\r
- se1 = se2; \\r
- se2 = tmp; \\r
-}while(0)\r
+#define SWAP_ENTRY(se1, se2) \\r
+ do { \\r
+ struct ext4_dx_sort_entry tmp = se1; \\r
+ se1 = se2; \\r
+ se2 = tmp; \\r
+ \\r
+} while (0)\r
\r
static void comb_sort(struct ext4_dx_sort_entry *se, uint32_t count)\r
{\r
- struct ext4_dx_sort_entry *p, *q, *top = se + count - 1;\r
- bool more;\r
- /* Combsort */\r
- while (count > 2) {\r
- count = (count * 10) / 13;\r
- if (count - 9 < 2)\r
- count = 11;\r
- for (p = top, q = p - count; q >= se; p--, q--)\r
- if (p->hash < q->hash)\r
- SWAP_ENTRY(*p, *q);\r
- }\r
- /* Bubblesort */\r
- do {\r
- more = 0;\r
- q = top;\r
- while (q-- > se) {\r
- if (q[1].hash >= q[0].hash)\r
- continue;\r
- SWAP_ENTRY(*(q+1), *q);\r
- more = 1;\r
- }\r
- } while(more);\r
+ struct ext4_dx_sort_entry *p, *q, *top = se + count - 1;\r
+ bool more;\r
+ /* Combsort */\r
+ while (count > 2) {\r
+ count = (count * 10) / 13;\r
+ if (count - 9 < 2)\r
+ count = 11;\r
+ for (p = top, q = p - count; q >= se; p--, q--)\r
+ if (p->hash < q->hash)\r
+ SWAP_ENTRY(*p, *q);\r
+ }\r
+ /* Bubblesort */\r
+ do {\r
+ more = 0;\r
+ q = top;\r
+ while (q-- > se) {\r
+ if (q[1].hash >= q[0].hash)\r
+ continue;\r
+ SWAP_ENTRY(*(q + 1), *q);\r
+ more = 1;\r
+ }\r
+ } while (more);\r
}\r
#else\r
\r
* @param iblock Logical number of child block\r
*\r
*/\r
-static void ext4_dir_dx_insert_entry(\r
- struct ext4_directory_dx_block *index_block, uint32_t hash,\r
- uint32_t iblock)\r
+static void\r
+ext4_dir_dx_insert_entry(struct ext4_directory_dx_block *index_block,\r
+ uint32_t hash, uint32_t iblock)\r
{\r
struct ext4_directory_dx_entry *old_index_entry = index_block->position;\r
struct ext4_directory_dx_entry *new_index_entry = old_index_entry + 1;\r
\r
struct ext4_directory_dx_countlimit *countlimit =\r
- (struct ext4_directory_dx_countlimit *) index_block->entries;\r
+ (struct ext4_directory_dx_countlimit *)index_block->entries;\r
uint32_t count = ext4_dir_dx_countlimit_get_count(countlimit);\r
\r
struct ext4_directory_dx_entry *start_index = index_block->entries;\r
- size_t bytes = (uint8_t *) (start_index + count) - (uint8_t *) (new_index_entry);\r
+ size_t bytes =\r
+ (uint8_t *)(start_index + count) - (uint8_t *)(new_index_entry);\r
\r
memmove(new_index_entry + 1, new_index_entry, bytes);\r
\r
* @param new_data_block Output value for newly allocated data block\r
*/\r
static int ext4_dir_dx_split_data(struct ext4_inode_ref *inode_ref,\r
- struct ext4_hash_info *hinfo, struct ext4_block *old_data_block,\r
- struct ext4_directory_dx_block *index_block,\r
- struct ext4_block *new_data_block)\r
+ struct ext4_hash_info *hinfo,\r
+ struct ext4_block *old_data_block,\r
+ struct ext4_directory_dx_block *index_block,\r
+ struct ext4_block *new_data_block)\r
{\r
int rc = EOK;\r
\r
/* Allocate buffer for directory entries */\r
- uint32_t block_size =\r
- ext4_sb_get_block_size(&inode_ref->fs->sb);\r
+ uint32_t block_size = ext4_sb_get_block_size(&inode_ref->fs->sb);\r
\r
uint8_t *entry_buffer = malloc(block_size);\r
if (entry_buffer == NULL)\r
\r
/* dot entry has the smallest size available */\r
uint32_t max_entry_count =\r
- block_size / sizeof(struct ext4_directory_dx_dot_entry);\r
+ block_size / sizeof(struct ext4_directory_dx_dot_entry);\r
\r
/* Allocate sort entry */\r
struct ext4_dx_sort_entry *sort_array =\r
- malloc(max_entry_count * sizeof(struct ext4_dx_sort_entry));\r
+ malloc(max_entry_count * sizeof(struct ext4_dx_sort_entry));\r
\r
if (sort_array == NULL) {\r
free(entry_buffer);\r
while ((void *)dentry < (void *)(old_data_block->data + block_size)) {\r
/* Read only valid entries */\r
if (ext4_dir_entry_ll_get_inode(dentry) && dentry->name_length) {\r
- uint8_t len = ext4_dir_entry_ll_get_name_length(\r
- &inode_ref->fs->sb, dentry);\r
+ uint8_t len =\r
+ ext4_dir_entry_ll_get_name_length(&inode_ref->fs->sb, dentry);\r
\r
- rc = ext4_dir_dx_hash_string(&tmp_hinfo, len, (char*)dentry->name);\r
- if(rc != EOK) {\r
+ rc = ext4_dir_dx_hash_string(&tmp_hinfo, len, (char *)dentry->name);\r
+ if (rc != EOK) {\r
free(sort_array);\r
free(entry_buffer);\r
return rc;\r
}\r
\r
dentry = (void *)((uint8_t *)dentry +\r
- ext4_dir_entry_ll_get_entry_length(dentry));\r
+ ext4_dir_entry_ll_get_entry_length(dentry));\r
}\r
\r
- /* Sort all entries */\r
+/* Sort all entries */\r
#if CONFIG_DIR_INDEX_COMB_SORT\r
comb_sort(sort_array, idx);\r
#else\r
qsort(sort_array, idx, sizeof(struct ext4_dx_sort_entry),\r
- ext4_dir_dx_entry_comparator);\r
+ ext4_dir_dx_entry_comparator);\r
#endif\r
/* Allocate new block for store the second part of entries */\r
uint32_t new_fblock;\r
uint32_t new_iblock;\r
- rc = ext4_fs_append_inode_block(inode_ref, &new_fblock,\r
- &new_iblock);\r
+ rc = ext4_fs_append_inode_block(inode_ref, &new_fblock, &new_iblock);\r
if (rc != EOK) {\r
free(sort_array);\r
free(entry_buffer);\r
\r
/* Load new block */\r
struct ext4_block new_data_block_tmp;\r
- rc = ext4_block_get(inode_ref->fs->bdev, &new_data_block_tmp,\r
- new_fblock);\r
+ rc = ext4_block_get(inode_ref->fs->bdev, &new_data_block_tmp, new_fblock);\r
if (rc != EOK) {\r
free(sort_array);\r
free(entry_buffer);\r
uint32_t current_size = 0;\r
uint32_t mid = 0;\r
uint32_t i;\r
- for ( i = 0; i < idx; ++i) {\r
+ for (i = 0; i < idx; ++i) {\r
if ((current_size + sort_array[i].rec_len) > (block_size / 2)) {\r
new_hash = sort_array[i].hash;\r
mid = i;\r
\r
/* Check hash collision */\r
uint32_t continued = 0;\r
- if (new_hash == sort_array[mid-1].hash)\r
+ if (new_hash == sort_array[mid - 1].hash)\r
continued = 1;\r
\r
uint32_t offset = 0;\r
\r
struct ext4_directory_entry_ll *tmp = ptr;\r
if (i < (mid - 1))\r
- ext4_dir_entry_ll_set_entry_length(tmp,\r
- sort_array[i].rec_len);\r
+ ext4_dir_entry_ll_set_entry_length(tmp, sort_array[i].rec_len);\r
else\r
- ext4_dir_entry_ll_set_entry_length(tmp,\r
- block_size - offset);\r
+ ext4_dir_entry_ll_set_entry_length(tmp, block_size - offset);\r
\r
offset += sort_array[i].rec_len;\r
}\r
\r
struct ext4_directory_entry_ll *tmp = ptr;\r
if (i < (idx - 1))\r
- ext4_dir_entry_ll_set_entry_length(tmp,\r
- sort_array[i].rec_len);\r
+ ext4_dir_entry_ll_set_entry_length(tmp, sort_array[i].rec_len);\r
else\r
- ext4_dir_entry_ll_set_entry_length(tmp,\r
- block_size - offset);\r
+ ext4_dir_entry_ll_set_entry_length(tmp, block_size - offset);\r
\r
offset += sort_array[i].rec_len;\r
}\r
free(sort_array);\r
free(entry_buffer);\r
\r
- ext4_dir_dx_insert_entry(index_block, new_hash + continued,\r
- new_iblock);\r
+ ext4_dir_dx_insert_entry(index_block, new_hash + continued, new_iblock);\r
\r
*new_data_block = new_data_block_tmp;\r
\r
* @param dx_block Leaf block to be split if needed\r
* @return Error code\r
*/\r
-static int ext4_dir_dx_split_index(struct ext4_inode_ref *inode_ref,\r
- struct ext4_directory_dx_block *dx_blocks,\r
- struct ext4_directory_dx_block *dx_block,\r
- struct ext4_directory_dx_block **new_dx_block)\r
+static int\r
+ext4_dir_dx_split_index(struct ext4_inode_ref *inode_ref,\r
+ struct ext4_directory_dx_block *dx_blocks,\r
+ struct ext4_directory_dx_block *dx_block,\r
+ struct ext4_directory_dx_block **new_dx_block)\r
{\r
struct ext4_directory_dx_entry *entries;\r
\r
if (dx_block == dx_blocks)\r
entries =\r
- ((struct ext4_directory_dx_root *) dx_block->block.data)->entries;\r
+ ((struct ext4_directory_dx_root *)dx_block->block.data)->entries;\r
else\r
entries =\r
- ((struct ext4_directory_dx_node *) dx_block->block.data)->entries;\r
+ ((struct ext4_directory_dx_node *)dx_block->block.data)->entries;\r
\r
struct ext4_directory_dx_countlimit *countlimit =\r
- (struct ext4_directory_dx_countlimit *) entries;\r
+ (struct ext4_directory_dx_countlimit *)entries;\r
\r
- uint16_t leaf_limit =\r
- ext4_dir_dx_countlimit_get_limit(countlimit);\r
- uint16_t leaf_count =\r
- ext4_dir_dx_countlimit_get_count(countlimit);\r
+ uint16_t leaf_limit = ext4_dir_dx_countlimit_get_limit(countlimit);\r
+ uint16_t leaf_count = ext4_dir_dx_countlimit_get_count(countlimit);\r
\r
/* Check if is necessary to split index block */\r
if (leaf_limit == leaf_count) {\r
size_t levels = dx_block - dx_blocks;\r
\r
struct ext4_directory_dx_entry *root_entries =\r
- ((struct ext4_directory_dx_root *) dx_blocks[0].block.data)->entries;\r
+ ((struct ext4_directory_dx_root *)dx_blocks[0].block.data)->entries;\r
\r
struct ext4_directory_dx_countlimit *root_countlimit =\r
- (struct ext4_directory_dx_countlimit *) root_entries;\r
- uint16_t root_limit =\r
- ext4_dir_dx_countlimit_get_limit(root_countlimit);\r
- uint16_t root_count =\r
- ext4_dir_dx_countlimit_get_count(root_countlimit);\r
+ (struct ext4_directory_dx_countlimit *)root_entries;\r
+ uint16_t root_limit = ext4_dir_dx_countlimit_get_limit(root_countlimit);\r
+ uint16_t root_count = ext4_dir_dx_countlimit_get_count(root_countlimit);\r
\r
/* Linux limitation */\r
if ((levels > 0) && (root_limit == root_count))\r
/* Add new block to directory */\r
uint32_t new_fblock;\r
uint32_t new_iblock;\r
- int rc = ext4_fs_append_inode_block(inode_ref,\r
- &new_fblock, &new_iblock);\r
+ int rc =\r
+ ext4_fs_append_inode_block(inode_ref, &new_fblock, &new_iblock);\r
if (rc != EOK)\r
return rc;\r
\r
/* load new block */\r
struct ext4_block new_block;\r
- rc = ext4_block_get(inode_ref->fs->bdev, &new_block,\r
- new_fblock);\r
+ rc = ext4_block_get(inode_ref->fs->bdev, &new_block, new_fblock);\r
if (rc != EOK)\r
return rc;\r
\r
- struct ext4_directory_dx_node *new_node = (void *)new_block.data;\r
+ struct ext4_directory_dx_node *new_node = (void *)new_block.data;\r
struct ext4_directory_dx_entry *new_entries = new_node->entries;\r
\r
memset(&new_node->fake, 0, sizeof(struct ext4_fake_directory_entry));\r
\r
- uint32_t block_size =\r
- ext4_sb_get_block_size(&inode_ref->fs->sb);\r
+ uint32_t block_size = ext4_sb_get_block_size(&inode_ref->fs->sb);\r
\r
new_node->fake.entry_length = block_size;\r
\r
uint32_t count_left = leaf_count / 2;\r
uint32_t count_right = leaf_count - count_left;\r
uint32_t hash_right =\r
- ext4_dir_dx_entry_get_hash(entries + count_left);\r
+ ext4_dir_dx_entry_get_hash(entries + count_left);\r
\r
/* Copy data to new node */\r
- memcpy((void *) new_entries, (void *) (entries + count_left),\r
- count_right * sizeof(struct ext4_directory_dx_entry));\r
+ memcpy((void *)new_entries, (void *)(entries + count_left),\r
+ count_right * sizeof(struct ext4_directory_dx_entry));\r
\r
/* Initialize new node */\r
struct ext4_directory_dx_countlimit *left_countlimit =\r
- (struct ext4_directory_dx_countlimit *) entries;\r
+ (struct ext4_directory_dx_countlimit *)entries;\r
struct ext4_directory_dx_countlimit *right_countlimit =\r
- (struct ext4_directory_dx_countlimit *) new_entries;\r
+ (struct ext4_directory_dx_countlimit *)new_entries;\r
\r
ext4_dir_dx_countlimit_set_count(left_countlimit, count_left);\r
ext4_dir_dx_countlimit_set_count(right_countlimit, count_right);\r
\r
uint32_t entry_space =\r
- block_size - sizeof(struct ext4_fake_directory_entry);\r
+ block_size - sizeof(struct ext4_fake_directory_entry);\r
uint32_t node_limit =\r
- entry_space / sizeof(struct ext4_directory_dx_entry);\r
+ entry_space / sizeof(struct ext4_directory_dx_entry);\r
ext4_dir_dx_countlimit_set_limit(right_countlimit, node_limit);\r
\r
/* Which index block is target for new entry */\r
\r
struct ext4_block block_tmp = dx_block->block;\r
\r
-\r
dx_block->block = new_block;\r
\r
- dx_block->position =\r
- new_entries + position_index - count_left;\r
+ dx_block->position = new_entries + position_index - count_left;\r
dx_block->entries = new_entries;\r
\r
new_block = block_tmp;\r
/* Create second level index */\r
\r
/* Copy data from root to child block */\r
- memcpy((void *) new_entries, (void *) entries,\r
- leaf_count * sizeof(struct ext4_directory_dx_entry));\r
+ memcpy((void *)new_entries, (void *)entries,\r
+ leaf_count * sizeof(struct ext4_directory_dx_entry));\r
\r
struct ext4_directory_dx_countlimit *new_countlimit =\r
- (struct ext4_directory_dx_countlimit *) new_entries;\r
+ (struct ext4_directory_dx_countlimit *)new_entries;\r
\r
uint32_t entry_space =\r
- block_size - sizeof(struct ext4_fake_directory_entry);\r
+ block_size - sizeof(struct ext4_fake_directory_entry);\r
uint32_t node_limit =\r
- entry_space / sizeof(struct ext4_directory_dx_entry);\r
+ entry_space / sizeof(struct ext4_directory_dx_entry);\r
ext4_dir_dx_countlimit_set_limit(new_countlimit, node_limit);\r
\r
/* Set values in root node */\r
struct ext4_directory_dx_countlimit *new_root_countlimit =\r
- (struct ext4_directory_dx_countlimit *) entries;\r
+ (struct ext4_directory_dx_countlimit *)entries;\r
\r
ext4_dir_dx_countlimit_set_count(new_root_countlimit, 1);\r
ext4_dir_dx_entry_set_block(entries, new_iblock);\r
\r
- ((struct ext4_directory_dx_root *)\r
- dx_blocks[0].block.data)->info.indirect_levels = 1;\r
+ ((struct ext4_directory_dx_root *)dx_blocks[0].block.data)\r
+ ->info.indirect_levels = 1;\r
\r
/* Add new entry to the path */\r
dx_block = dx_blocks + 1;\r
}\r
\r
int ext4_dir_dx_add_entry(struct ext4_inode_ref *parent,\r
- struct ext4_inode_ref *child, const char *name)\r
+ struct ext4_inode_ref *child, const char *name)\r
{\r
int rc2 = EOK;\r
\r
/* Get direct block 0 (index root) */\r
uint32_t root_block_addr;\r
- int rc = ext4_fs_get_inode_data_block_index(parent, 0,\r
- &root_block_addr);\r
+ int rc = ext4_fs_get_inode_data_block_index(parent, 0, &root_block_addr);\r
if (rc != EOK)\r
return rc;\r
\r
/* Initialize hinfo structure (mainly compute hash) */\r
uint32_t name_len = strlen(name);\r
struct ext4_hash_info hinfo;\r
- rc = ext4_dir_hinfo_init(&hinfo, &root_block, &fs->sb,\r
- name_len, name);\r
+ rc = ext4_dir_hinfo_init(&hinfo, &root_block, &fs->sb, name_len, name);\r
if (rc != EOK) {\r
ext4_block_set(fs->bdev, &root_block);\r
return EXT4_ERR_BAD_DX_DIR;\r
struct ext4_directory_dx_block *dx_block;\r
struct ext4_directory_dx_block *dx_it;\r
\r
- rc = ext4_dir_dx_get_leaf(&hinfo, parent, &root_block,\r
- &dx_block, dx_blocks);\r
+ rc =\r
+ ext4_dir_dx_get_leaf(&hinfo, parent, &root_block, &dx_block, dx_blocks);\r
if (rc != EOK) {\r
rc = EXT4_ERR_BAD_DX_DIR;\r
goto release_index;\r
}\r
\r
/* Try to insert to existing data block */\r
- uint32_t leaf_block_idx =\r
- ext4_dir_dx_entry_get_block(dx_block->position);\r
+ uint32_t leaf_block_idx = ext4_dir_dx_entry_get_block(dx_block->position);\r
uint32_t leaf_block_addr;\r
rc = ext4_fs_get_inode_data_block_index(parent, leaf_block_idx,\r
- &leaf_block_addr);\r
+ &leaf_block_addr);\r
if (rc != EOK)\r
goto release_index;\r
\r
if (rc != EOK)\r
goto release_index;\r
\r
-\r
/* Check if insert operation passed */\r
- rc = ext4_dir_try_insert_entry(&fs->sb, &target_block, child,\r
- name, name_len);\r
+ rc = ext4_dir_try_insert_entry(&fs->sb, &target_block, child, name,\r
+ name_len);\r
if (rc == EOK)\r
goto release_target_index;\r
\r
-\r
/* Split entries to two blocks (includes sorting by hash value) */\r
struct ext4_block new_block;\r
- rc = ext4_dir_dx_split_data(parent, &hinfo, &target_block,\r
- dx_block, &new_block);\r
+ rc = ext4_dir_dx_split_data(parent, &hinfo, &target_block, dx_block,\r
+ &new_block);\r
if (rc != EOK) {\r
rc2 = rc;\r
goto release_target_index;\r
\r
/* Where to save new entry */\r
uint32_t new_block_hash =\r
- ext4_dir_dx_entry_get_hash(dx_block->position + 1);\r
+ ext4_dir_dx_entry_get_hash(dx_block->position + 1);\r
if (hinfo.hash >= new_block_hash)\r
- rc = ext4_dir_try_insert_entry(&fs->sb, &new_block,\r
- child, name, name_len);\r
+ rc = ext4_dir_try_insert_entry(&fs->sb, &new_block, child, name,\r
+ name_len);\r
else\r
- rc = ext4_dir_try_insert_entry(&fs->sb, &target_block,\r
- child, name, name_len);\r
+ rc = ext4_dir_try_insert_entry(&fs->sb, &target_block, child, name,\r
+ name_len);\r
\r
/* Cleanup */\r
rc = ext4_block_set(fs->bdev, &new_block);\r
if (rc != EOK)\r
return rc;\r
\r
- /* Cleanup operations */\r
+/* Cleanup operations */\r
\r
- release_target_index:\r
+release_target_index:\r
rc2 = rc;\r
\r
rc = ext4_block_set(fs->bdev, &target_block);\r
if (rc != EOK)\r
return rc;\r
\r
- release_index:\r
+release_index:\r
if (rc != EOK)\r
rc2 = rc;\r
\r
/**\r
* @}\r
*/\r
-\r
* @param name Name to be found\r
* @return Error code\r
*/\r
-int ext4_dir_dx_find_entry(struct ext4_directory_search_result * result,\r
- struct ext4_inode_ref *inode_ref, size_t name_len, const char *name);\r
+int ext4_dir_dx_find_entry(struct ext4_directory_search_result *result,\r
+ struct ext4_inode_ref *inode_ref, size_t name_len,\r
+ const char *name);\r
\r
/**@brief Add new entry to indexed directory\r
* @param parent Directory i-node\r
* @return Error code\r
*/\r
int ext4_dir_dx_add_entry(struct ext4_inode_ref *parent,\r
- struct ext4_inode_ref *child, const char *name);\r
+ struct ext4_inode_ref *child, const char *name);\r
\r
#endif /* EXT4_DIR_IDX_H_ */\r
\r
/**\r
* @}\r
*/\r
-\r
#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_ */
return to_le32(extent->first_block);\r
}\r
\r
-\r
void ext4_extent_set_first_block(struct ext4_extent *extent, uint32_t iblock)\r
{\r
extent->first_block = to_le32(iblock);\r
}\r
\r
-\r
uint16_t ext4_extent_get_block_count(struct ext4_extent *extent)\r
{\r
return to_le16(extent->block_count);\r
}\r
\r
-\r
void ext4_extent_set_block_count(struct ext4_extent *extent, uint16_t count)\r
{\r
extent->block_count = to_le16(count);\r
}\r
\r
-\r
uint64_t ext4_extent_get_start(struct ext4_extent *extent)\r
{\r
return ((uint64_t)to_le16(extent->start_hi)) << 32 |\r
- ((uint64_t)to_le32(extent->start_lo));\r
+ ((uint64_t)to_le32(extent->start_lo));\r
}\r
\r
-\r
void ext4_extent_set_start(struct ext4_extent *extent, uint64_t fblock)\r
{\r
extent->start_lo = to_le32((fblock << 32) >> 32);\r
extent->start_hi = to_le16((uint16_t)(fblock >> 32));\r
}\r
\r
-\r
uint32_t ext4_extent_index_get_first_block(struct ext4_extent_index *index)\r
{\r
return to_le32(index->first_block);\r
}\r
\r
-\r
void ext4_extent_index_set_first_block(struct ext4_extent_index *index,\r
- uint32_t iblock)\r
+ uint32_t iblock)\r
{\r
index->first_block = to_le32(iblock);\r
}\r
\r
-\r
uint64_t ext4_extent_index_get_leaf(struct ext4_extent_index *index)\r
{\r
- return ((uint64_t) to_le16(index->leaf_hi)) << 32 |\r
- ((uint64_t)to_le32(index->leaf_lo));\r
+ return ((uint64_t)to_le16(index->leaf_hi)) << 32 |\r
+ ((uint64_t)to_le32(index->leaf_lo));\r
}\r
\r
void ext4_extent_index_set_leaf(struct ext4_extent_index *index,\r
- uint64_t fblock)\r
+ uint64_t fblock)\r
{\r
index->leaf_lo = to_le32((fblock << 32) >> 32);\r
- index->leaf_hi = to_le16((uint16_t) (fblock >> 32));\r
+ index->leaf_hi = to_le16((uint16_t)(fblock >> 32));\r
}\r
\r
-\r
uint16_t ext4_extent_header_get_magic(struct ext4_extent_header *header)\r
{\r
return to_le16(header->magic);\r
}\r
\r
-\r
void ext4_extent_header_set_magic(struct ext4_extent_header *header,\r
- uint16_t magic)\r
+ uint16_t magic)\r
{\r
header->magic = to_le16(magic);\r
}\r
\r
-\r
uint16_t ext4_extent_header_get_entries_count(struct ext4_extent_header *header)\r
{\r
return to_le16(header->entries_count);\r
}\r
\r
-\r
void ext4_extent_header_set_entries_count(struct ext4_extent_header *header,\r
- uint16_t count)\r
+ uint16_t count)\r
{\r
header->entries_count = to_le16(count);\r
}\r
\r
-\r
-uint16_t ext4_extent_header_get_max_entries_count(struct ext4_extent_header *header)\r
+uint16_t\r
+ext4_extent_header_get_max_entries_count(struct ext4_extent_header *header)\r
{\r
return to_le16(header->max_entries_count);\r
}\r
\r
-\r
void ext4_extent_header_set_max_entries_count(struct ext4_extent_header *header,\r
- uint16_t max_count)\r
+ uint16_t max_count)\r
{\r
header->max_entries_count = to_le16(max_count);\r
}\r
\r
-\r
uint16_t ext4_extent_header_get_depth(struct ext4_extent_header *header)\r
{\r
return to_le16(header->depth);\r
}\r
\r
-\r
void ext4_extent_header_set_depth(struct ext4_extent_header *header,\r
- uint16_t depth)\r
+ uint16_t depth)\r
{\r
header->depth = to_le16(depth);\r
}\r
\r
-\r
uint32_t ext4_extent_header_get_generation(struct ext4_extent_header *header)\r
{\r
return to_le32(header->generation);\r
}\r
\r
-\r
void ext4_extent_header_set_generation(struct ext4_extent_header *header,\r
- uint32_t generation)\r
+ uint32_t generation)\r
{\r
header->generation = to_le32(generation);\r
}\r
* @param index Output value - found index will be set here\r
* @param iblock Logical block number to find in index node */\r
static void ext4_extent_binsearch_idx(struct ext4_extent_header *header,\r
- struct ext4_extent_index **index, uint32_t iblock)\r
+ struct ext4_extent_index **index,\r
+ uint32_t iblock)\r
{\r
struct ext4_extent_index *r;\r
struct ext4_extent_index *l;\r
struct ext4_extent_index *m;\r
\r
- uint16_t entries_count =\r
- ext4_extent_header_get_entries_count(header);\r
+ uint16_t entries_count = ext4_extent_header_get_entries_count(header);\r
\r
/* Initialize bounds */\r
l = EXT4_EXTENT_FIRST_INDEX(header) + 1;\r
* or NULL if node is empty\r
* @param iblock Logical block number to find in leaf node */\r
static void ext4_extent_binsearch(struct ext4_extent_header *header,\r
- struct ext4_extent **extent, uint32_t iblock)\r
+ struct ext4_extent **extent, uint32_t iblock)\r
{\r
struct ext4_extent *r;\r
struct ext4_extent *l;\r
struct ext4_extent *m;\r
\r
- uint16_t entries_count =\r
- ext4_extent_header_get_entries_count(header);\r
+ uint16_t entries_count = ext4_extent_header_get_entries_count(header);\r
\r
if (entries_count == 0) {\r
/* this leaf is empty */\r
*extent = l - 1;\r
}\r
\r
-\r
int ext4_extent_find_block(struct ext4_inode_ref *inode_ref, uint32_t iblock,\r
- uint32_t *fblock)\r
+ uint32_t *fblock)\r
{\r
int rc;\r
/* Compute bound defined by i-node size */\r
uint64_t inode_size =\r
ext4_inode_get_size(&inode_ref->fs->sb, inode_ref->inode);\r
\r
- uint32_t block_size =\r
- ext4_sb_get_block_size(&inode_ref->fs->sb);\r
+ uint32_t block_size = ext4_sb_get_block_size(&inode_ref->fs->sb);\r
\r
uint32_t last_idx = (inode_size - 1) / block_size;\r
\r
/* Load child node and set values for the next iteration */\r
uint64_t child = ext4_extent_index_get_leaf(index);\r
\r
- if (block.lb_id){\r
+ if (block.lb_id) {\r
rc = ext4_block_set(inode_ref->fs->bdev, &block);\r
- if(rc != EOK)\r
+ if (rc != EOK)\r
return rc;\r
}\r
\r
-\r
int rc = ext4_block_get(inode_ref->fs->bdev, &block, child);\r
if (rc != EOK)\r
return rc;\r
}\r
\r
/* Search extent in the leaf block */\r
- struct ext4_extent* extent = NULL;\r
+ struct ext4_extent *extent = NULL;\r
ext4_extent_binsearch(header, &extent, iblock);\r
\r
/* Prevent empty leaf */\r
}\r
\r
/* Cleanup */\r
- if (block.lb_id){\r
+ if (block.lb_id) {\r
rc = ext4_block_set(inode_ref->fs->bdev, &block);\r
- if(rc != EOK)\r
+ if (rc != EOK)\r
return rc;\r
}\r
\r
* @param ret_path Output value for loaded path from extent tree\r
* @return Error code */\r
static int ext4_extent_find_extent(struct ext4_inode_ref *inode_ref,\r
- uint32_t iblock, struct ext4_extent_path **ret_path)\r
+ uint32_t iblock,\r
+ struct ext4_extent_path **ret_path)\r
{\r
struct ext4_extent_header *eh =\r
ext4_inode_get_extent_header(inode_ref->inode);\r
int rc;\r
while (ext4_extent_header_get_depth(eh) != 0) {\r
/* Search index in index node by iblock */\r
- ext4_extent_binsearch_idx(tmp_path[pos].header,\r
- &tmp_path[pos].index, iblock);\r
+ ext4_extent_binsearch_idx(tmp_path[pos].header, &tmp_path[pos].index,\r
+ iblock);\r
\r
tmp_path[pos].depth = depth;\r
tmp_path[pos].extent = NULL;\r
* From 1: 0 is a block with inode data\r
*/\r
for (i = 1; i < tmp_path->depth; ++i) {\r
- if (tmp_path[i].block.lb_id){\r
+ if (tmp_path[i].block.lb_id) {\r
int r = ext4_block_set(inode_ref->fs->bdev, &tmp_path[i].block);\r
- if(r != EOK)\r
+ if (r != EOK)\r
rc = r;\r
}\r
}\r
* @param extent Extent to release\r
* @return Error code */\r
static int ext4_extent_release(struct ext4_inode_ref *inode_ref,\r
- struct ext4_extent *extent)\r
+ struct ext4_extent *extent)\r
{\r
/* Compute number of the first physical block to release */\r
uint64_t start = ext4_extent_get_start(extent);\r
* with the whole subtree\r
* @return Error code */\r
static int ext4_extent_release_branch(struct ext4_inode_ref *inode_ref,\r
- struct ext4_extent_index *index)\r
+ struct ext4_extent_index *index)\r
{\r
uint32_t fblock = ext4_extent_index_get_leaf(index);\r
uint32_t i;\r
\r
/* Release all subbranches */\r
for (i = 0; i < ext4_extent_header_get_entries_count(header);\r
- ++i, ++idx) {\r
+ ++i, ++idx) {\r
rc = ext4_extent_release_branch(inode_ref, idx);\r
if (rc != EOK)\r
return rc;\r
\r
/* Release all extents and stop recursion */\r
for (i = 0; i < ext4_extent_header_get_entries_count(header);\r
- ++i, ++ext) {\r
+ ++i, ++ext) {\r
rc = ext4_extent_release(inode_ref, ext);\r
if (rc != EOK)\r
return rc;\r
return ext4_balloc_free_block(inode_ref, fblock);\r
}\r
\r
-\r
int ext4_extent_release_blocks_from(struct ext4_inode_ref *inode_ref,\r
- uint32_t iblock_from)\r
+ uint32_t iblock_from)\r
{\r
/* Find the first extent to modify */\r
struct ext4_extent_path *path;\r
ext4_assert(path_ptr->extent != NULL);\r
\r
/* First extent maybe released partially */\r
- uint32_t first_iblock =\r
- ext4_extent_get_first_block(path_ptr->extent);\r
+ uint32_t first_iblock = ext4_extent_get_first_block(path_ptr->extent);\r
uint32_t first_fblock =\r
ext4_extent_get_start(path_ptr->extent) + iblock_from - first_iblock;\r
\r
uint16_t block_count = ext4_extent_get_block_count(path_ptr->extent);\r
\r
- uint16_t delete_count = block_count -\r
- (ext4_extent_get_start(path_ptr->extent) - first_fblock);\r
+ uint16_t delete_count =\r
+ block_count - (ext4_extent_get_start(path_ptr->extent) - first_fblock);\r
\r
/* Release all blocks */\r
rc = ext4_balloc_free_blocks(inode_ref, first_fblock, delete_count);\r
ext4_extent_set_block_count(path_ptr->extent, block_count);\r
\r
/* Initialize the following loop */\r
- uint16_t entries =\r
- ext4_extent_header_get_entries_count(path_ptr->header);\r
+ uint16_t entries = ext4_extent_header_get_entries_count(path_ptr->header);\r
struct ext4_extent *tmp_ext = path_ptr->extent + 1;\r
- struct ext4_extent *stop_ext = EXT4_EXTENT_FIRST(path_ptr->header) + entries;\r
+ struct ext4_extent *stop_ext =\r
+ EXT4_EXTENT_FIRST(path_ptr->header) + entries;\r
\r
/* If first extent empty, release it */\r
if (block_count == 0)\r
--path_ptr;\r
}\r
\r
- if(!entries)\r
+ if (!entries)\r
ext4_extent_header_set_depth(path->header, 0);\r
\r
cleanup:\r
* starting from 1: 0 is a block with inode data\r
*/\r
for (i = 1; i <= path->depth; ++i) {\r
- if (path[i].block.lb_id){\r
+ if (path[i].block.lb_id) {\r
int r = ext4_block_set(inode_ref->fs->bdev, &path[i].block);\r
- if(r != EOK)\r
+ if (r != EOK)\r
rc = r;\r
}\r
}\r
* @param iblock Logical index of block to append extent for\r
* @return Error code */\r
static int ext4_extent_append_extent(struct ext4_inode_ref *inode_ref,\r
- struct ext4_extent_path *path, uint32_t iblock)\r
+ struct ext4_extent_path *path,\r
+ uint32_t iblock)\r
{\r
struct ext4_extent_path *path_ptr = path + path->depth;\r
\r
- uint32_t block_size =\r
- ext4_sb_get_block_size(&inode_ref->fs->sb);\r
+ uint32_t block_size = ext4_sb_get_block_size(&inode_ref->fs->sb);\r
\r
/* Start splitting */\r
while (path_ptr > path) {\r
path_ptr->index = EXT4_EXTENT_FIRST_INDEX(path_ptr->header);\r
ext4_extent_index_set_first_block(path_ptr->index, iblock);\r
ext4_extent_index_set_leaf(path_ptr->index,\r
- (path_ptr + 1)->block.lb_id);\r
+ (path_ptr + 1)->block.lb_id);\r
limit = (block_size - sizeof(struct ext4_extent_header)) /\r
- sizeof(struct ext4_extent_index);\r
+ sizeof(struct ext4_extent_index);\r
} else {\r
path_ptr->extent = EXT4_EXTENT_FIRST(path_ptr->header);\r
ext4_extent_set_first_block(path_ptr->extent, iblock);\r
limit = (block_size - sizeof(struct ext4_extent_header)) /\r
- sizeof(struct ext4_extent);\r
+ sizeof(struct ext4_extent);\r
}\r
\r
/* Initialize on-disk structure (header) */\r
} else {\r
/* Node with free space */\r
if (path_ptr->depth) {\r
- path_ptr->index = EXT4_EXTENT_FIRST_INDEX(path_ptr->header) + entries;\r
+ path_ptr->index =\r
+ EXT4_EXTENT_FIRST_INDEX(path_ptr->header) + entries;\r
ext4_extent_index_set_first_block(path_ptr->index, iblock);\r
ext4_extent_index_set_leaf(path_ptr->index,\r
- (path_ptr + 1)->block.lb_id);\r
+ (path_ptr + 1)->block.lb_id);\r
} else {\r
- path_ptr->extent = EXT4_EXTENT_FIRST(path_ptr->header) + entries;\r
+ path_ptr->extent =\r
+ EXT4_EXTENT_FIRST(path_ptr->header) + entries;\r
ext4_extent_set_first_block(path_ptr->extent, iblock);\r
}\r
\r
\r
/* Move data from root to the new block */\r
memcpy(block.data, inode_ref->inode->blocks,\r
- EXT4_INODE_BLOCKS * sizeof(uint32_t));\r
+ EXT4_INODE_BLOCKS * sizeof(uint32_t));\r
\r
/* Data block is initialized */\r
\r
/* Add new entry and update limit for entries */\r
if (old_root->depth) {\r
limit = (block_size - sizeof(struct ext4_extent_header)) /\r
- sizeof(struct ext4_extent_index);\r
- old_root->index = EXT4_EXTENT_FIRST_INDEX(old_root->header) + entries;\r
+ sizeof(struct ext4_extent_index);\r
+ old_root->index =\r
+ EXT4_EXTENT_FIRST_INDEX(old_root->header) + entries;\r
ext4_extent_index_set_first_block(old_root->index, iblock);\r
ext4_extent_index_set_leaf(old_root->index,\r
- (old_root + 1)->block.lb_id);\r
+ (old_root + 1)->block.lb_id);\r
old_root->extent = NULL;\r
} else {\r
limit = (block_size - sizeof(struct ext4_extent_header)) /\r
- sizeof(struct ext4_extent);\r
+ sizeof(struct ext4_extent);\r
old_root->extent = EXT4_EXTENT_FIRST(old_root->header) + entries;\r
ext4_extent_set_first_block(old_root->extent, iblock);\r
old_root->index = NULL;\r
return EOK;\r
}\r
\r
-\r
-int ext4_extent_append_block(struct ext4_inode_ref *inode_ref,\r
- uint32_t *iblock, uint32_t *fblock, bool update_size)\r
+int ext4_extent_append_block(struct ext4_inode_ref *inode_ref, uint32_t *iblock,\r
+ uint32_t *fblock, bool update_size)\r
{\r
uint16_t i;\r
struct ext4_sblock *sb = &inode_ref->fs->sb;\r
goto finish;\r
\r
if (!free) {\r
- /* Target is not free, new block must be appended to new extent */\r
+ /* Target is not free, new block must be appended to new extent\r
+ */\r
goto append_extent;\r
}\r
\r
}\r
}\r
\r
-\r
append_extent:\r
/* Append new extent to the tree */\r
phys_block = 0;\r
* starting from 1: 0 is a block with inode data\r
*/\r
for (i = 1; i <= path->depth; ++i) {\r
- if (path[i].block.lb_id){\r
+ if (path[i].block.lb_id) {\r
int r = ext4_block_set(inode_ref->fs->bdev, &path[i].block);\r
- if(r != EOK)\r
+ if (r != EOK)\r
rc = r;\r
}\r
}\r
* @param fblock Physical number of the first block covered by extent */\r
void ext4_extent_set_start(struct ext4_extent *extent, uint64_t fblock);\r
\r
-\r
/**@brief Get logical number of the block covered by extent index.\r
* @param index Extent index to load number from\r
* @return Logical number of the first block covered by extent index */\r
* @param index Extent index to set number to\r
* @param iblock Logical number of the first block covered by extent index */\r
void ext4_extent_index_set_first_block(struct ext4_extent_index *index,\r
- uint32_t iblock);\r
+ uint32_t iblock);\r
\r
/**@brief Get physical number of block where the child node is located.\r
* @param index Extent index to load number from\r
* @return Physical number of the block with child node */\r
uint64_t ext4_extent_index_get_leaf(struct ext4_extent_index *index);\r
\r
-\r
/**@brief Set physical number of block where the child node is located.\r
* @param index Extent index to set number to\r
* @param fblock Ohysical number of the block with child node */\r
void ext4_extent_index_set_leaf(struct ext4_extent_index *index,\r
- uint64_t fblock);\r
-\r
+ uint64_t fblock);\r
\r
/**@brief Get magic value from extent header.\r
* @param header Extent header to load value from\r
* @param header Extent header to set value to\r
* @param magic Magic value of extent header */\r
void ext4_extent_header_set_magic(struct ext4_extent_header *header,\r
- uint16_t magic);\r
+ uint16_t magic);\r
\r
/**@brief Get number of entries from extent header\r
* @param header Extent header to get value from\r
* @return Number of entries covered by extent header */\r
-uint16_t ext4_extent_header_get_entries_count(struct ext4_extent_header *header);\r
+uint16_t\r
+ext4_extent_header_get_entries_count(struct ext4_extent_header *header);\r
\r
/**@brief Set number of entries to extent header\r
* @param header Extent header to set value to\r
* @param count Number of entries covered by extent header */\r
void ext4_extent_header_set_entries_count(struct ext4_extent_header *header,\r
- uint16_t count);\r
+ uint16_t count);\r
\r
/**@brief Get maximum number of entries from extent header\r
* @param header Extent header to get value from\r
* @return Maximum number of entries covered by extent header */\r
-uint16_t ext4_extent_header_get_max_entries_count(struct ext4_extent_header *header);\r
+uint16_t\r
+ext4_extent_header_get_max_entries_count(struct ext4_extent_header *header);\r
\r
/**@brief Set maximum number of entries to extent header\r
* @param header Extent header to set value to\r
* @param max_count Maximum number of entries covered by extent header */\r
void ext4_extent_header_set_max_entries_count(struct ext4_extent_header *header,\r
- uint16_t max_count);\r
+ uint16_t max_count);\r
\r
/**@brief Get depth of extent subtree.\r
* @param header Extent header to get value from\r
* @param header Extent header to set value to\r
* @param depth Depth of extent subtree */\r
void ext4_extent_header_set_depth(struct ext4_extent_header *header,\r
- uint16_t depth);\r
+ uint16_t depth);\r
\r
/**@brief Get generation from extent header\r
* @param header Extent header to get value from\r
* @param header Extent header to set value to\r
* @param generation Generation */\r
void ext4_extent_header_set_generation(struct ext4_extent_header *header,\r
- uint32_t generation);\r
+ uint32_t generation);\r
\r
/**@brief Find physical block in the extent tree by logical block number.\r
* There is no need to save path in the tree during this algorithm.\r
* @param fblock Output value for physical block number\r
* @return Error code*/\r
int ext4_extent_find_block(struct ext4_inode_ref *inode_ref, uint32_t iblock,\r
- uint32_t *fblock);\r
+ uint32_t *fblock);\r
\r
/**@brief Release all data blocks starting from specified logical block.\r
* @param inode_ref I-node to release blocks from\r
* @param iblock_from First logical block to release\r
* @return Error code */\r
int ext4_extent_release_blocks_from(struct ext4_inode_ref *inode_ref,\r
- uint32_t iblock_from);\r
+ uint32_t iblock_from);\r
\r
/**@brief Append data block to the i-node.\r
* This function allocates data block, tries to append it\r
* @param fblock Output physical block address of newly allocated block\r
*\r
* @return Error code*/\r
-int ext4_extent_append_block(struct ext4_inode_ref *inode_ref,\r
- uint32_t *iblock, uint32_t *fblock, bool update_size);\r
-\r
+int ext4_extent_append_block(struct ext4_inode_ref *inode_ref, uint32_t *iblock,\r
+ uint32_t *fblock, bool update_size);\r
\r
#endif /* EXT4_EXTENT_H_ */\r
-/**\r
- * @}\r
- */\r
+ /**\r
+ * @}\r
+ */\r
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);
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 */
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 */
if (r != EOK)
return r;
-
/*Update mount count*/
ext4_set16(&fs->sb, mount_count, ext4_get16(&fs->sb, mount_count) + 1);
return r;
}
-
int ext4_fs_fini(struct ext4_fs *fs)
{
ext4_assert(fs);
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");
}
}
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");
}
}
{
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;
return EOK;
}
-
/**@brief Initialize block bitmap in block group.
* @param bg_ref Reference to block group
* @return Error code
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*/
for (i = first_idx; i < first_data_idx; ++i)
ext4_bmap_bit_set(block_bitmap.data, i);
-
block_bitmap.dirty = true;
/* Save bitmap */
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;
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;
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;
}
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;
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))
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)
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);
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;
* @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);
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);
/* 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;
}
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);
}
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);
/* 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);
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) {
}
/* 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;
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);
#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);
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);
}
#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;
}
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);
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);
}
/* 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);
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);
}
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);
ext4_block_set(fs->bdev, &subblock);
-
rc = ext4_balloc_free_block(inode_ref, ind_block);
if (rc != EOK) {
ext4_block_set(fs->bdev, &block);
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)
/* 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);
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;
/* 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++;
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;
/* 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;
}
}
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;
#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)
/* 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;
}
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) {
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);
/* 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;
}
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;
#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;
}
/* 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;
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;
/* 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 */
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 */
}
/* 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;
}
/* 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;
}
/* 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;
}
int ext4_fs_release_inode_block(struct ext4_inode_ref *inode_ref,
- uint32_t iblock)
+ uint32_t iblock)
{
uint32_t fblock;
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;
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
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;
}
/* 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;
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
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;
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;
}
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);
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;
}
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);
-
}
-
/**
* @}
*/
-
* @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
* @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;
/**@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.
* @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
* @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
* @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
* @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
* @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
* @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
* @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
* @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
* FF, GG, and HH are transformations for rounds 1, 2, and 3.\r
* Rotation is separated from addition to prevent recomputation.\r
*/\r
-#define FF(a, b, c, d, x, s) { \\r
- (a) += F ((b), (c), (d)) + (x); \\r
- (a) = ROTATE_LEFT ((a), (s)); \\r
+#define FF(a, b, c, d, x, s) \\r
+ { \\r
+ (a) += F((b), (c), (d)) + (x); \\r
+ (a) = ROTATE_LEFT((a), (s)); \\r
+ \\r
}\r
\r
-#define GG(a, b, c, d, x, s) { \\r
- (a) += G ((b), (c), (d)) + (x) + (uint32_t)0x5A827999; \\r
- (a) = ROTATE_LEFT ((a), (s)); \\r
+#define GG(a, b, c, d, x, s) \\r
+ { \\r
+ (a) += G((b), (c), (d)) + (x) + (uint32_t)0x5A827999; \\r
+ (a) = ROTATE_LEFT((a), (s)); \\r
+ \\r
}\r
\r
-#define HH(a, b, c, d, x, s) { \\r
- (a) += H ((b), (c), (d)) + (x) + (uint32_t)0x6ED9EBA1; \\r
- (a) = ROTATE_LEFT ((a), (s)); \\r
+#define HH(a, b, c, d, x, s) \\r
+ { \\r
+ (a) += H((b), (c), (d)) + (x) + (uint32_t)0x6ED9EBA1; \\r
+ (a) = ROTATE_LEFT((a), (s)); \\r
+ \\r
}\r
\r
/*\r
* need to check this value, so in our version this function doesn't return any\r
* value.\r
*/\r
-static void\r
-ext2_half_md4(uint32_t hash[4], uint32_t data[8])\r
+static void ext2_half_md4(uint32_t hash[4], uint32_t data[8])\r
{\r
uint32_t a = hash[0], b = hash[1], c = hash[2], d = hash[3];\r
\r
/* Round 1 */\r
- FF(a, b, c, d, data[0], 3);\r
- FF(d, a, b, c, data[1], 7);\r
+ FF(a, b, c, d, data[0], 3);\r
+ FF(d, a, b, c, data[1], 7);\r
FF(c, d, a, b, data[2], 11);\r
FF(b, c, d, a, data[3], 19);\r
- FF(a, b, c, d, data[4], 3);\r
- FF(d, a, b, c, data[5], 7);\r
+ FF(a, b, c, d, data[4], 3);\r
+ FF(d, a, b, c, data[5], 7);\r
FF(c, d, a, b, data[6], 11);\r
FF(b, c, d, a, data[7], 19);\r
\r
/* Round 2 */\r
- GG(a, b, c, d, data[1], 3);\r
- GG(d, a, b, c, data[3], 5);\r
- GG(c, d, a, b, data[5], 9);\r
+ GG(a, b, c, d, data[1], 3);\r
+ GG(d, a, b, c, data[3], 5);\r
+ GG(c, d, a, b, data[5], 9);\r
GG(b, c, d, a, data[7], 13);\r
- GG(a, b, c, d, data[0], 3);\r
- GG(d, a, b, c, data[2], 5);\r
- GG(c, d, a, b, data[4], 9);\r
+ GG(a, b, c, d, data[0], 3);\r
+ GG(d, a, b, c, data[2], 5);\r
+ GG(c, d, a, b, data[4], 9);\r
GG(b, c, d, a, data[6], 13);\r
\r
/* Round 3 */\r
- HH(a, b, c, d, data[3], 3);\r
- HH(d, a, b, c, data[7], 9);\r
+ HH(a, b, c, d, data[3], 3);\r
+ HH(d, a, b, c, data[7], 9);\r
HH(c, d, a, b, data[2], 11);\r
HH(b, c, d, a, data[6], 15);\r
- HH(a, b, c, d, data[1], 3);\r
- HH(d, a, b, c, data[5], 9);\r
+ HH(a, b, c, d, data[1], 3);\r
+ HH(d, a, b, c, data[5], 9);\r
HH(c, d, a, b, data[0], 11);\r
HH(b, c, d, a, data[4], 15);\r
\r
/*\r
* Tiny Encryption Algorithm.\r
*/\r
-static void\r
-ext2_tea(uint32_t hash[4], uint32_t data[8])\r
+static void ext2_tea(uint32_t hash[4], uint32_t data[8])\r
{\r
uint32_t tea_delta = 0x9E3779B9;\r
uint32_t sum;\r
hash[1] += y;\r
}\r
\r
-static uint32_t\r
-ext2_legacy_hash(const char *name, int len, int unsigned_char)\r
+static uint32_t ext2_legacy_hash(const char *name, int len, int unsigned_char)\r
{\r
uint32_t h0, h1 = 0x12A3FE2D, h2 = 0x37ABE8F9;\r
uint32_t multi = 0x6D22F5;\r
return (h1 << 1);\r
}\r
\r
-static void\r
-ext2_prep_hashbuf(const char *src, uint32_t slen, uint32_t *dst, int dlen,\r
- int unsigned_char)\r
+static void ext2_prep_hashbuf(const char *src, uint32_t slen, uint32_t *dst,\r
+ int dlen, int unsigned_char)\r
{\r
uint32_t padding = slen | (slen << 8) | (slen << 16) | (slen << 24);\r
uint32_t buf_val;\r
}\r
}\r
\r
-int\r
-ext2_htree_hash(const char *name, int len,\r
- const uint32_t *hash_seed, int hash_version,\r
- uint32_t *hash_major, uint32_t *hash_minor)\r
+int ext2_htree_hash(const char *name, int len, const uint32_t *hash_seed,\r
+ int hash_version, uint32_t *hash_major,\r
+ uint32_t *hash_minor)\r
{\r
uint32_t hash[4];\r
uint32_t data[8];\r
\r
return EOK;\r
\r
- error:\r
+error:\r
*hash_major = 0;\r
if (hash_minor)\r
*hash_minor = 0;\r
* @param hash_minor output value\r
* @param hash_major output value\r
* @return standard error code*/\r
-int ext2_htree_hash(const char *name, int len,\r
- const uint32_t *hash_seed, int hash_version,\r
- uint32_t *hash_major, uint32_t *hash_minor);\r
-\r
+int ext2_htree_hash(const char *name, int len, const uint32_t *hash_seed,\r
+ int hash_version, uint32_t *hash_major,\r
+ uint32_t *hash_minor);\r
\r
#endif /* EXT4_HASH_H_ */\r
\r
#include <ext4_block_group.h>\r
#include <ext4_bitmap.h>\r
\r
-\r
/**@brief Convert i-node number to relative index in block group.\r
* @param sb Superblock\r
* @param inode I-node number to be converted\r
* @return Index of the i-node in the block group\r
*/\r
static uint32_t ext4_ialloc_inode2index_in_group(struct ext4_sblock *sb,\r
- uint32_t inode)\r
+ uint32_t inode)\r
{\r
uint32_t inodes_per_group = ext4_get32(sb, inodes_per_group);\r
return (inode - 1) % inodes_per_group;\r
*\r
*/\r
static uint32_t ext4_ialloc_index_in_group2inode(struct ext4_sblock *sb,\r
- uint32_t index, uint32_t bgid)\r
+ uint32_t index, uint32_t bgid)\r
{\r
uint32_t inodes_per_group = ext4_get32(sb, inodes_per_group);\r
return bgid * inodes_per_group + (index + 1);\r
}\r
\r
-\r
/**@brief Compute block group number from the i-node number.\r
* @param sb Superblock\r
* @param inode I-node number to be found the block group for\r
* @return Block group number computed from i-node number\r
*/\r
static uint32_t ext4_ialloc_get_bgid_of_inode(struct ext4_sblock *sb,\r
- uint32_t inode)\r
+ uint32_t inode)\r
{\r
uint32_t inodes_per_group = ext4_get32(sb, inodes_per_group);\r
return (inode - 1) / inodes_per_group;\r
}\r
\r
-\r
int ext4_ialloc_free_inode(struct ext4_fs *fs, uint32_t index, bool is_dir)\r
{\r
struct ext4_sblock *sb = &fs->sb;\r
return rc;\r
\r
/* Load i-node bitmap */\r
- uint32_t bitmap_block_addr = ext4_bg_get_inode_bitmap(\r
- bg_ref.block_group, sb);\r
+ uint32_t bitmap_block_addr =\r
+ ext4_bg_get_inode_bitmap(bg_ref.block_group, sb);\r
\r
struct ext4_block bitmap_block;\r
rc = ext4_block_get(fs->bdev, &bitmap_block, bitmap_block_addr);\r
\r
/* If released i-node is a directory, decrement used directories count */\r
if (is_dir) {\r
- uint32_t bg_used_dirs = ext4_bg_get_used_dirs_count(\r
- bg_ref.block_group, sb);\r
+ uint32_t bg_used_dirs =\r
+ ext4_bg_get_used_dirs_count(bg_ref.block_group, sb);\r
bg_used_dirs--;\r
- ext4_bg_set_used_dirs_count(bg_ref.block_group, sb,\r
- bg_used_dirs);\r
+ ext4_bg_set_used_dirs_count(bg_ref.block_group, sb, bg_used_dirs);\r
}\r
\r
/* Update block group free inodes count */\r
- uint32_t free_inodes = ext4_bg_get_free_inodes_count(\r
- bg_ref.block_group, sb);\r
+ uint32_t free_inodes =\r
+ ext4_bg_get_free_inodes_count(bg_ref.block_group, sb);\r
free_inodes++;\r
- ext4_bg_set_free_inodes_count(bg_ref.block_group, sb,\r
- free_inodes);\r
+ ext4_bg_set_free_inodes_count(bg_ref.block_group, sb, free_inodes);\r
\r
bg_ref.dirty = true;\r
\r
uint32_t bgid = fs->last_inode_bg_id;\r
uint32_t bg_count = ext4_block_group_cnt(sb);\r
uint32_t sb_free_inodes = ext4_get32(sb, free_inodes_count);\r
- bool rewind = false;\r
+ bool rewind = false;\r
\r
/* Try to find free i-node in all block groups */\r
while (bgid <= bg_count) {\r
\r
- if(bgid == bg_count){\r
- if(rewind)\r
+ if (bgid == bg_count) {\r
+ if (rewind)\r
break;\r
bg_count = fs->last_inode_bg_id;\r
bgid = 0;\r
/* Check if this block group is good candidate for allocation */\r
if (free_inodes > 0) {\r
/* Load block with bitmap */\r
- uint32_t bitmap_block_addr = ext4_bg_get_inode_bitmap(\r
- bg_ref.block_group, sb);\r
+ uint32_t bitmap_block_addr =\r
+ ext4_bg_get_inode_bitmap(bg_ref.block_group, sb);\r
\r
struct ext4_block bitmap_block;\r
rc = ext4_block_get(fs->bdev, &bitmap_block, bitmap_block_addr);\r
- if (rc != EOK){\r
+ if (rc != EOK) {\r
ext4_fs_put_block_group_ref(&bg_ref);\r
return rc;\r
}\r
uint32_t index_in_group;\r
\r
rc = ext4_bmap_bit_find_clr(bitmap_block.data, 0, inodes_in_group,\r
- &index_in_group);\r
+ &index_in_group);\r
/* Block group has not any free i-node */\r
if (rc == ENOSPC) {\r
rc = ext4_block_set(fs->bdev, &bitmap_block);\r
- if(rc != EOK){\r
+ if (rc != EOK) {\r
ext4_fs_put_block_group_ref(&bg_ref);\r
return rc;\r
}\r
bitmap_block.dirty = true;\r
\r
ext4_block_set(fs->bdev, &bitmap_block);\r
- if (rc != EOK){\r
+ if (rc != EOK) {\r
ext4_fs_put_block_group_ref(&bg_ref);\r
return rc;\r
}\r
}\r
\r
/* Decrease unused inodes count */\r
- if (ext4_bg_has_flag(bg,\r
- EXT4_BLOCK_GROUP_ITABLE_ZEROED)) {\r
- uint32_t unused =\r
- ext4_bg_get_itable_unused(bg, sb);\r
+ if (ext4_bg_has_flag(bg, EXT4_BLOCK_GROUP_ITABLE_ZEROED)) {\r
+ uint32_t unused = ext4_bg_get_itable_unused(bg, sb);\r
\r
- uint32_t inodes_in_group =\r
- ext4_inodes_in_group_cnt(sb, bgid);\r
+ uint32_t inodes_in_group = ext4_inodes_in_group_cnt(sb, bgid);\r
\r
uint32_t free = inodes_in_group - unused;\r
\r
sb_free_inodes--;\r
ext4_set32(sb, free_inodes_count, sb_free_inodes);\r
\r
-\r
/* Compute the absolute i-nodex number */\r
- *index = ext4_ialloc_index_in_group2inode(sb,\r
- index_in_group, bgid);\r
+ *index = ext4_ialloc_index_in_group2inode(sb, index_in_group, bgid);\r
\r
fs->last_inode_bg_id = bgid;\r
\r
/**\r
* @}\r
*/\r
-\r
{\r
uint32_t v = to_le16(inode->mode);\r
\r
- if(ext4_get32(sb, creator_os) == EXT4_SUPERBLOCK_OS_HURD){\r
- v |= ((uint32_t) to_le16(inode->osd2.hurd2.mode_high)) << 16;\r
+ if (ext4_get32(sb, creator_os) == EXT4_SUPERBLOCK_OS_HURD) {\r
+ v |= ((uint32_t)to_le16(inode->osd2.hurd2.mode_high)) << 16;\r
}\r
\r
return v;\r
}\r
\r
void ext4_inode_set_mode(struct ext4_sblock *sb, struct ext4_inode *inode,\r
- uint32_t mode)\r
+ uint32_t mode)\r
{\r
inode->mode = to_le16((mode << 16) >> 16);\r
\r
- if(ext4_get32(sb, creator_os) == EXT4_SUPERBLOCK_OS_HURD)\r
+ if (ext4_get32(sb, creator_os) == EXT4_SUPERBLOCK_OS_HURD)\r
inode->osd2.hurd2.mode_high = to_le16(mode >> 16);\r
}\r
\r
{\r
uint64_t v = to_le32(inode->size_lo);\r
\r
- if ((ext4_get32(sb, rev_level) > 0) && (ext4_inode_is_type(sb, inode,\r
- EXT4_INODE_MODE_FILE)))\r
+ if ((ext4_get32(sb, rev_level) > 0) &&\r
+ (ext4_inode_is_type(sb, inode, EXT4_INODE_MODE_FILE)))\r
v |= ((uint64_t)to_le32(inode->size_hi)) << 32;\r
\r
return v;\r
inode->access_time = to_le32(time);\r
}\r
\r
-\r
uint32_t ext4_inode_get_change_inode_time(struct ext4_inode *inode)\r
{\r
return to_le32(inode->change_inode_time);\r
}\r
-void ext4_inode_set_change_inode_time(struct ext4_inode *inode,\r
- uint32_t time)\r
+void ext4_inode_set_change_inode_time(struct ext4_inode *inode, uint32_t time)\r
{\r
inode->change_inode_time = to_le32(time);\r
}\r
\r
-\r
uint32_t ext4_inode_get_modification_time(struct ext4_inode *inode)\r
{\r
return to_le32(inode->modification_time);\r
}\r
\r
-void ext4_inode_set_modification_time(struct ext4_inode *inode,\r
- uint32_t time)\r
+void ext4_inode_set_modification_time(struct ext4_inode *inode, uint32_t time)\r
{\r
inode->modification_time = to_le32(time);\r
}\r
\r
-\r
uint32_t ext4_inode_get_deletion_time(struct ext4_inode *inode)\r
{\r
return to_le32(inode->deletion_time);\r
}\r
\r
uint64_t ext4_inode_get_blocks_count(struct ext4_sblock *sb,\r
- struct ext4_inode *inode)\r
+ struct ext4_inode *inode)\r
{\r
uint64_t count = to_le32(inode->blocks_count_lo);\r
\r
- if (ext4_sb_has_feature_read_only(sb,\r
- EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {\r
+ if (ext4_sb_has_feature_read_only(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {\r
\r
/* 48-bit field */\r
- count |= ((uint64_t) to_le16(inode->osd2.linux2.blocks_high)) << 32;\r
+ count |= ((uint64_t)to_le16(inode->osd2.linux2.blocks_high)) << 32;\r
\r
if (ext4_inode_has_flag(inode, EXT4_INODE_FLAG_HUGE_FILE)) {\r
\r
uint32_t block_bits =\r
- ext4_inode_block_bits_count(ext4_sb_get_block_size(sb));\r
+ ext4_inode_block_bits_count(ext4_sb_get_block_size(sb));\r
return count << (block_bits - 9);\r
}\r
}\r
}\r
\r
int ext4_inode_set_blocks_count(struct ext4_sblock *sb,\r
- struct ext4_inode *inode, uint64_t count)\r
+ struct ext4_inode *inode, uint64_t count)\r
{\r
/* 32-bit maximum */\r
uint64_t max = 0;\r
}\r
\r
/* Check if there can be used huge files (many blocks) */\r
- if (!ext4_sb_has_feature_read_only(sb,\r
- EXT4_FEATURE_RO_COMPAT_HUGE_FILE))\r
+ if (!ext4_sb_has_feature_read_only(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE))\r
return EINVAL;\r
\r
/* 48-bit maximum */\r
inode->osd2.linux2.blocks_high = to_le16(count >> 32);\r
ext4_inode_clear_flag(inode, EXT4_INODE_FLAG_HUGE_FILE);\r
} else {\r
- uint32_t block_bits = ext4_inode_block_bits_count(ext4_sb_get_block_size(sb));\r
+ uint32_t block_bits =\r
+ ext4_inode_block_bits_count(ext4_sb_get_block_size(sb));\r
\r
ext4_inode_set_flag(inode, EXT4_INODE_FLAG_HUGE_FILE);\r
count = count >> (block_bits - 9);\r
}\r
\r
uint64_t ext4_inode_get_file_acl(struct ext4_inode *inode,\r
- struct ext4_sblock *sb)\r
+ struct ext4_sblock *sb)\r
{\r
/*TODO: Verify it*/\r
uint64_t v = to_le32(inode->file_acl_lo);\r
\r
if (ext4_get32(sb, creator_os) == EXT4_SUPERBLOCK_OS_LINUX)\r
- v |= ((uint32_t) to_le16(inode->osd2.linux2.file_acl_high)) << 16;\r
-\r
+ v |= ((uint32_t)to_le16(inode->osd2.linux2.file_acl_high)) << 16;\r
\r
return v;\r
}\r
\r
void ext4_inode_set_file_acl(struct ext4_inode *inode, struct ext4_sblock *sb,\r
- uint64_t acl)\r
+ uint64_t acl)\r
{\r
/*TODO: Verify it*/\r
inode->file_acl_lo = to_le32((acl << 32) >> 32);\r
return to_le32(inode->blocks[idx]);\r
}\r
void ext4_inode_set_direct_block(struct ext4_inode *inode, uint32_t idx,\r
- uint32_t block)\r
+ uint32_t block)\r
{\r
inode->blocks[idx] = to_le32(block);\r
}\r
}\r
\r
void ext4_inode_set_indirect_block(struct ext4_inode *inode, uint32_t idx,\r
- uint32_t block)\r
+ uint32_t block)\r
{\r
inode->blocks[idx + EXT4_INODE_INDIRECT_BLOCK] = to_le32(block);\r
}\r
\r
bool ext4_inode_is_type(struct ext4_sblock *sb, struct ext4_inode *inode,\r
- uint32_t type)\r
+ uint32_t type)\r
{\r
- return (ext4_inode_get_mode(sb, inode) &\r
- EXT4_INODE_MODE_TYPE_MASK) == type;\r
+ return (ext4_inode_get_mode(sb, inode) & EXT4_INODE_MODE_TYPE_MASK) == type;\r
}\r
\r
bool ext4_inode_has_flag(struct ext4_inode *inode, uint32_t f)\r
ext4_inode_set_flags(inode, flags);\r
}\r
\r
-bool ext4_inode_can_truncate(struct ext4_sblock *sb,\r
- struct ext4_inode *inode)\r
+bool ext4_inode_can_truncate(struct ext4_sblock *sb, struct ext4_inode *inode)\r
{\r
if ((ext4_inode_has_flag(inode, EXT4_INODE_FLAG_APPEND)) ||\r
- (ext4_inode_has_flag(inode, EXT4_INODE_FLAG_IMMUTABLE)))\r
+ (ext4_inode_has_flag(inode, EXT4_INODE_FLAG_IMMUTABLE)))\r
return false;\r
\r
if ((ext4_inode_is_type(sb, inode, EXT4_INODE_MODE_FILE)) ||\r
- (ext4_inode_is_type(sb, inode, EXT4_INODE_MODE_DIRECTORY)))\r
+ (ext4_inode_is_type(sb, inode, EXT4_INODE_MODE_DIRECTORY)))\r
return true;\r
\r
return false;\r
}\r
\r
-struct ext4_extent_header * ext4_inode_get_extent_header(\r
- struct ext4_inode *inode)\r
+struct ext4_extent_header *\r
+ext4_inode_get_extent_header(struct ext4_inode *inode)\r
{\r
- return (struct ext4_extent_header *) inode->blocks;\r
+ return (struct ext4_extent_header *)inode->blocks;\r
}\r
\r
/**\r
* @param mode Mode to set to i-node\r
*/\r
void ext4_inode_set_mode(struct ext4_sblock *sb, struct ext4_inode *inode,\r
- uint32_t mode);\r
+ uint32_t mode);\r
\r
/**@brief Get ID of the i-node owner (user id).\r
* @param inode I-node to load uid from\r
* @param inode I-node\r
* @param time Time of the last change (POSIX)\r
*/\r
-void ext4_inode_set_change_inode_time(struct ext4_inode *inode,\r
- uint32_t time);\r
+void ext4_inode_set_change_inode_time(struct ext4_inode *inode, uint32_t time);\r
\r
/**@brief Get time, when i-node content was last modified.\r
* @param inode I-node\r
* @return Number of 512-bytes blocks\r
*/\r
uint64_t ext4_inode_get_blocks_count(struct ext4_sblock *sb,\r
- struct ext4_inode *inode);\r
+ struct ext4_inode *inode);\r
\r
/**@brief Set number of 512-bytes blocks used for i-node.\r
* @param sb Superblock\r
* @return Error code\r
*/\r
int ext4_inode_set_blocks_count(struct ext4_sblock *sb,\r
- struct ext4_inode *inode, uint64_t cnt);\r
+ struct ext4_inode *inode, uint64_t cnt);\r
\r
/**@brief Get flags (features) of i-node.\r
* @param inode I-node to get flags from\r
* @return Block address\r
*/\r
uint64_t ext4_inode_get_file_acl(struct ext4_inode *inode,\r
- struct ext4_sblock *sb);\r
+ struct ext4_sblock *sb);\r
\r
/**@brief Set address of block, where are extended attributes located.\r
* @param inode I-node\r
* @param sb Superblock\r
* @param file_acl Block address\r
*/\r
-void ext4_inode_set_file_acl(struct ext4_inode *inode,\r
- struct ext4_sblock *sb, uint64_t acl);\r
+void ext4_inode_set_file_acl(struct ext4_inode *inode, struct ext4_sblock *sb,\r
+ uint64_t acl);\r
\r
/**@brief Get block address of specified direct block.\r
* @param inode I-node to load block from\r
* @param fblock Physical block address\r
*/\r
void ext4_inode_set_direct_block(struct ext4_inode *inode, uint32_t idx,\r
- uint32_t block);\r
+ uint32_t block);\r
\r
/**@brief Get block address of specified indirect block.\r
* @param inode I-node to get block address from\r
* @param fblock Physical block address\r
*/\r
void ext4_inode_set_indirect_block(struct ext4_inode *inode, uint32_t idx,\r
- uint32_t block);\r
+ uint32_t block);\r
\r
/**@brief Check if i-node has specified type.\r
* @param sb Superblock\r
* @return Result of check operation\r
*/\r
bool ext4_inode_is_type(struct ext4_sblock *sb, struct ext4_inode *inode,\r
- uint32_t type);\r
+ uint32_t type);\r
\r
/**@brief Check if i-node has specified flag.\r
* @param inode I-node to check flags of\r
* @param inode I-node to get extent header from\r
* @return Pointer to extent header of the root node\r
*/\r
-struct ext4_extent_header * ext4_inode_get_extent_header(struct ext4_inode *inode);\r
+struct ext4_extent_header *\r
+ext4_inode_get_extent_header(struct ext4_inode *inode);\r
\r
#endif /* EXT4_INODE_H_ */\r
\r
/**\r
* @}\r
*/\r
-\r
#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);
if (bgid < block_group_count - 1)
return blocks_per_group;
-
return (total_blocks - ((block_group_count - 1) * blocks_per_group));
}
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;
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)
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;
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 db_count = (ext4_block_group_cnt(s) + dsc_per_block - 1) /
- dsc_per_block;
+ 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;
if (ext4_sb_has_feature_incompatible(s, EXT4_FEATURE_INCOMPAT_META_BG))
return ext4_sb_first_meta_bg(s);
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);
#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.
* @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.
* @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);
{
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*********************************/
* @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;
}
* @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);
}
* @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_ */
/**
* @}
*/
-
#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_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_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_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*/
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];
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) */
-
- 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_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 */
+};
+
+struct ext4_block_group_ref
+{
struct ext4_block block;
struct ext4_bgroup *block_group;
struct ext4_fs *fs;
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;
uint16_t gid_high;
uint32_t reserved2;
} linux2;
- struct {
+ struct
+ {
uint16_t reserved1;
uint16_t mode_high;
uint16_t uid_high;
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)) ;
-
-#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
+ 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
/*
* 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_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
-
-struct ext4_inode_ref {
- struct ext4_block block;
+#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_ROOT_INDEX 2
+
+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;
};
/* 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;
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
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_FIRST(header) \
- ((struct ext4_extent *) (((char *) (header)) + sizeof(struct ext4_extent_header)))
+#define EXT4_EXTENT_MAGIC 0xF30A
-#define EXT4_EXTENT_FIRST_INDEX(header) \
- ((struct ext4_extent_index *) (((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)))
/* 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_EOF 0x7FFFFFFFUL
+#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
-struct ext4_hash_info {
+struct ext4_hash_info
+{
uint32_t hash;
uint32_t minor_hash;
uint32_t hash_version;
/*****************************************************************************/
-
#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
/****************************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_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_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)
#endif /* EXT4_TYPES_H_ */