* @brief More complex filesystem functions.
*/
-#include "ext4_config.h"
-#include "ext4_types.h"
-#include "ext4_misc.h"
-#include "ext4_errno.h"
-#include "ext4_debug.h"
-
-#include "ext4_trans.h"
-#include "ext4_fs.h"
-#include "ext4_blockdev.h"
-#include "ext4_super.h"
-#include "ext4_crc32.h"
-#include "ext4_block_group.h"
-#include "ext4_balloc.h"
-#include "ext4_bitmap.h"
-#include "ext4_inode.h"
-#include "ext4_ialloc.h"
-#include "ext4_extent.h"
+#include <ext4_config.h>
+#include <ext4_types.h>
+#include <ext4_misc.h>
+#include <ext4_errno.h>
+#include <ext4_debug.h>
+
+#include <ext4_trans.h>
+#include <ext4_fs.h>
+#include <ext4_blockdev.h>
+#include <ext4_super.h>
+#include <ext4_crc32.h>
+#include <ext4_block_group.h>
+#include <ext4_balloc.h>
+#include <ext4_bitmap.h>
+#include <ext4_inode.h>
+#include <ext4_ialloc.h>
+#include <ext4_extent.h>
#include <string.h>
struct ext4_sblock *sb = &bg_ref->fs->sb;
struct ext4_bgroup *bg = bg_ref->block_group;
- uint32_t inode_size = ext4_get32(sb, inode_size);
+ uint32_t inode_size = ext4_get16(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);
memset(b.data, 0, block_size);
ext4_trans_set_block_dirty(b.buf);
- ext4_block_set(bg_ref->fs->bdev, &b);
+ rc = ext4_block_set(bg_ref->fs->bdev, &b);
if (rc != EOK)
return rc;
}
void ext4_fs_inode_blocks_init(struct ext4_fs *fs,
struct ext4_inode_ref *inode_ref)
{
- int i;
struct ext4_inode *inode = inode_ref->inode;
- for (i = 0; i < EXT4_INODE_BLOCKS; i++)
- inode->blocks[i] = 0;
+ /* Reset blocks array. For inode which is not directory or file, just
+ * fill in blocks with 0 */
+ switch (ext4_inode_type(&fs->sb, inode_ref->inode)) {
+ case EXT4_INODE_MODE_FILE:
+ case EXT4_INODE_MODE_DIRECTORY:
+ break;
+ default:
+ return;
+ }
- (void)fs;
#if CONFIG_EXTENT_ENABLE
/* Initialize extents if needed */
if (ext4_sb_feature_incom(&fs->sb, EXT4_FINCOM_EXTENTS)) {
/* Initialize extent root header */
ext4_extent_tree_init(inode_ref);
}
+
+ inode_ref->dirty = true;
#endif
}
{
/* Check if newly allocated i-node will be a directory */
bool is_dir;
- uint32_t type;
uint16_t inode_size = ext4_get16(&fs->sb, inode_size);
is_dir = (filetype == EXT4_DE_DIR);
ext4_inode_set_flags(inode, 0);
ext4_inode_set_generation(inode, 0);
if (inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
- uint16_t off = offsetof(struct ext4_inode, extra_isize);
- uint16_t size = sizeof(struct ext4_inode) - off;
+ uint16_t size = ext4_get16(&fs->sb, want_extra_isize);
ext4_inode_set_extra_isize(&fs->sb, inode, size);
}
- /* Reset blocks array. For inode which is not directory or file, just
- * fill in blocks with 0 */
- type = ext4_inode_type(&fs->sb, inode_ref->inode);
- if (type == EXT4_INODE_MODE_CHARDEV ||
- type == EXT4_INODE_MODE_BLOCKDEV ||
- type == EXT4_INODE_MODE_SOCKET ||
- type == EXT4_INODE_MODE_SOFTLINK) {
- for (int i = 0; i < EXT4_INODE_BLOCKS; i++)
- inode->blocks[i] = 0;
-
- } else {
- ext4_fs_inode_blocks_init(fs, inode_ref);
- }
-
+ memset(inode->blocks, 0, sizeof(inode->blocks));
inode_ref->dirty = true;
return EOK;