2 * Copyright (c) 2015 Grzegorz Kostka (kostka.grzegorz@gmail.com)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /** @addtogroup lwext4
37 #include "ext4_config.h"
38 #include "ext4_types.h"
39 #include "ext4_misc.h"
40 #include "ext4_errno.h"
41 #include "ext4_debug.h"
43 #include "ext4_super.h"
44 #include "ext4_block_group.h"
46 #include "ext4_dir_idx.h"
48 #include "ext4_inode.h"
49 #include "ext4_ialloc.h"
50 #include "ext4_mkfs.h"
57 struct ext4_sblock *sb;
58 struct ext4_bgroup *bg_desc;
59 struct xattr_list_element *xattrs;
60 uint32_t first_data_block;
62 uint32_t inode_table_blocks;
64 uint32_t bg_desc_blocks;
65 uint32_t default_i_flags;
66 uint32_t blocks_per_ind;
67 uint32_t blocks_per_dind;
68 uint32_t blocks_per_tind;
71 static inline int log_2(int j)
75 for (i = 0; j > 0; i++)
81 static int sb2info(struct ext4_sblock *sb, struct ext4_mkfs_info *info)
83 if (to_le16(sb->magic) != EXT4_SUPERBLOCK_MAGIC)
86 info->block_size = 1024 << to_le32(sb->log_block_size);
87 info->blocks_per_group = to_le32(sb->blocks_per_group);
88 info->inodes_per_group = to_le32(sb->inodes_per_group);
89 info->inode_size = to_le16(sb->inode_size);
90 info->inodes = to_le32(sb->inodes_count);
91 info->feat_ro_compat = to_le32(sb->features_read_only);
92 info->feat_compat = to_le32(sb->features_compatible);
93 info->feat_incompat = to_le32(sb->features_incompatible);
94 info->bg_desc_reserve_blocks = to_le16(sb->s_reserved_gdt_blocks);
95 info->label = sb->volume_name;
96 info->len = (uint64_t)info->block_size * ext4_sb_get_blocks_cnt(sb);
97 info->dsc_size = to_le16(sb->desc_size);
102 static uint32_t compute_blocks_per_group(struct ext4_mkfs_info *info)
104 return info->block_size * 8;
107 static uint32_t compute_inodes(struct ext4_mkfs_info *info)
109 return (uint32_t)EXT4_DIV_ROUND_UP(info->len, info->block_size) / 4;
112 static uint32_t compute_inodes_per_group(struct ext4_mkfs_info *info)
114 uint32_t blocks = (uint32_t)EXT4_DIV_ROUND_UP(info->len, info->block_size);
115 uint32_t block_groups = EXT4_DIV_ROUND_UP(blocks, info->blocks_per_group);
116 uint32_t inodes = EXT4_DIV_ROUND_UP(info->inodes, block_groups);
117 inodes = EXT4_ALIGN(inodes, (info->block_size / info->inode_size));
119 /* After properly rounding up the number of inodes/group,
120 * make sure to update the total inodes field in the info struct.
122 info->inodes = inodes * block_groups;
128 static uint32_t compute_journal_blocks(struct ext4_mkfs_info *info)
130 uint32_t journal_blocks = (uint32_t)EXT4_DIV_ROUND_UP(info->len,
131 info->block_size) / 64;
132 if (journal_blocks < 1024)
133 journal_blocks = 1024;
134 if (journal_blocks > 32768)
135 journal_blocks = 32768;
136 return journal_blocks;
139 static bool has_superblock(struct ext4_mkfs_info *info, uint32_t bgid)
141 if (!(info->feat_ro_compat & EXT4_FRO_COM_SPARSE_SUPER))
144 return ext4_sb_sparse(bgid);
147 static int create_fs_aux_info(struct fs_aux_info *aux_info,
148 struct ext4_mkfs_info *info)
150 aux_info->first_data_block = (info->block_size > 1024) ? 0 : 1;
151 aux_info->len_blocks = info->len / info->block_size;
152 aux_info->inode_table_blocks = EXT4_DIV_ROUND_UP(info->inodes_per_group *
153 info->inode_size, info->block_size);
154 aux_info->groups = (uint32_t)EXT4_DIV_ROUND_UP(aux_info->len_blocks -
155 aux_info->first_data_block, info->blocks_per_group);
156 aux_info->blocks_per_ind = info->block_size / sizeof(uint32_t);
157 aux_info->blocks_per_dind =
158 aux_info->blocks_per_ind * aux_info->blocks_per_ind;
159 aux_info->blocks_per_tind =
160 aux_info->blocks_per_dind * aux_info->blocks_per_dind;
162 aux_info->bg_desc_blocks =
163 EXT4_DIV_ROUND_UP(aux_info->groups * info->dsc_size,
166 aux_info->default_i_flags = EXT4_INODE_FLAG_NOATIME;
168 uint32_t last_group_size = aux_info->len_blocks % info->blocks_per_group;
169 uint32_t last_header_size = 2 + aux_info->inode_table_blocks;
170 if (has_superblock(info, aux_info->groups - 1))
171 last_header_size += 1 + aux_info->bg_desc_blocks +
172 info->bg_desc_reserve_blocks;
174 if (last_group_size > 0 && last_group_size < last_header_size) {
176 aux_info->len_blocks -= last_group_size;
179 aux_info->sb = calloc(1, EXT4_SUPERBLOCK_SIZE);
183 aux_info->bg_desc = calloc(aux_info->groups, sizeof(struct ext4_bgroup));
184 if (!aux_info->bg_desc)
187 aux_info->xattrs = NULL;
190 ext4_dbg(DEBUG_MKFS, DBG_INFO "create_fs_aux_info\n");
191 ext4_dbg(DEBUG_MKFS, DBG_NONE "first_data_block: %"PRIu32"\n",
192 aux_info->first_data_block);
193 ext4_dbg(DEBUG_MKFS, DBG_NONE "len_blocks: %"PRIu64"\n",
194 aux_info->len_blocks);
195 ext4_dbg(DEBUG_MKFS, DBG_NONE "inode_table_blocks: %"PRIu32"\n",
196 aux_info->inode_table_blocks);
197 ext4_dbg(DEBUG_MKFS, DBG_NONE "groups: %"PRIu32"\n",
199 ext4_dbg(DEBUG_MKFS, DBG_NONE "bg_desc_blocks: %"PRIu32"\n",
200 aux_info->bg_desc_blocks);
201 ext4_dbg(DEBUG_MKFS, DBG_NONE "default_i_flags: %"PRIu32"\n",
202 aux_info->default_i_flags);
203 ext4_dbg(DEBUG_MKFS, DBG_NONE "blocks_per_ind: %"PRIu32"\n",
204 aux_info->blocks_per_ind);
205 ext4_dbg(DEBUG_MKFS, DBG_NONE "blocks_per_dind: %"PRIu32"\n",
206 aux_info->blocks_per_dind);
207 ext4_dbg(DEBUG_MKFS, DBG_NONE "blocks_per_tind: %"PRIu32"\n",
208 aux_info->blocks_per_tind);
213 static void release_fs_aux_info(struct fs_aux_info *aux_info)
217 if (aux_info->bg_desc)
218 free(aux_info->bg_desc);
222 /* Fill in the superblock memory buffer based on the filesystem parameters */
223 static void fill_in_sb(struct fs_aux_info *aux_info, struct ext4_mkfs_info *info)
225 struct ext4_sblock *sb = aux_info->sb;
227 sb->inodes_count = to_le32(info->inodes_per_group * aux_info->groups);
229 ext4_sb_set_blocks_cnt(sb, aux_info->len_blocks);
230 ext4_sb_set_free_blocks_cnt(sb, aux_info->len_blocks);
231 sb->free_inodes_count = to_le32(info->inodes_per_group * aux_info->groups);
233 sb->reserved_blocks_count_lo = to_le32(0);
234 sb->first_data_block = to_le32(aux_info->first_data_block);
235 sb->log_block_size = to_le32(log_2(info->block_size / 1024));
236 sb->log_cluster_size = to_le32(log_2(info->block_size / 1024));
237 sb->blocks_per_group = to_le32(info->blocks_per_group);
238 sb->frags_per_group = to_le32(info->blocks_per_group);
239 sb->inodes_per_group = to_le32(info->inodes_per_group);
240 sb->mount_time = to_le32(0);
241 sb->write_time = to_le32(0);
242 sb->mount_count = to_le16(0);
243 sb->max_mount_count = to_le16(0xFFFF);
244 sb->magic = to_le16(EXT4_SUPERBLOCK_MAGIC);
245 sb->state = to_le16(EXT4_SUPERBLOCK_STATE_VALID_FS);
246 sb->errors = to_le16(EXT4_SUPERBLOCK_ERRORS_RO);
247 sb->minor_rev_level = to_le16(0);
248 sb->last_check_time = to_le32(0);
249 sb->check_interval = to_le32(0);
250 sb->creator_os = to_le32(EXT4_SUPERBLOCK_OS_LINUX);
251 sb->rev_level = to_le32(1);
252 sb->def_resuid = to_le16(0);
253 sb->def_resgid = to_le16(0);
255 sb->first_inode = to_le32(EXT4_GOOD_OLD_FIRST_INO);
256 sb->inode_size = to_le16(info->inode_size);
257 sb->block_group_index = to_le16(0);
259 sb->features_compatible = to_le32(info->feat_compat);
260 sb->features_incompatible = to_le32(info->feat_incompat);
261 sb->features_read_only = to_le32(info->feat_ro_compat);
263 memset(sb->uuid, 0, sizeof(sb->uuid));
265 memset(sb->volume_name, 0, sizeof(sb->volume_name));
266 strncpy(sb->volume_name, info->label, sizeof(sb->volume_name));
267 memset(sb->last_mounted, 0, sizeof(sb->last_mounted));
269 sb->algorithm_usage_bitmap = to_le32(0);
270 sb->s_prealloc_blocks = 0;
271 sb->s_prealloc_dir_blocks = 0;
272 sb->s_reserved_gdt_blocks = to_le16(info->bg_desc_reserve_blocks);
274 if (info->feat_compat & EXT4_FCOM_HAS_JOURNAL)
275 sb->journal_inode_number = to_le32(EXT4_JOURNAL_INO);
276 sb->journal_dev = to_le32(0);
277 sb->last_orphan = to_le32(0);
278 sb->hash_seed[0] = to_le32(0x11111111);
279 sb->hash_seed[1] = to_le32(0x22222222);
280 sb->hash_seed[2] = to_le32(0x33333333);
281 sb->hash_seed[3] = to_le32(0x44444444);
282 sb->default_hash_version = EXT2_HTREE_HALF_MD4;
283 sb->checksum_type = 1;
284 sb->desc_size = to_le16(info->dsc_size);
285 sb->default_mount_opts = to_le32(0);
286 sb->first_meta_bg = to_le32(0);
287 sb->mkfs_time = to_le32(0);
289 sb->reserved_blocks_count_hi = to_le32(0);
290 sb->min_extra_isize = to_le32(sizeof(struct ext4_inode) -
291 EXT4_GOOD_OLD_INODE_SIZE);
292 sb->want_extra_isize = to_le32(sizeof(struct ext4_inode) -
293 EXT4_GOOD_OLD_INODE_SIZE);
294 sb->flags = to_le32(EXT4_SUPERBLOCK_FLAGS_SIGNED_HASH);
297 static void fill_bgroups(struct fs_aux_info *aux_info,
298 struct ext4_mkfs_info *info)
302 uint32_t bg_free_blk = 0;
303 uint64_t sb_free_blk = 0;
305 for (i = 0; i < aux_info->groups; i++) {
307 uint64_t bg_start_block = aux_info->first_data_block +
308 aux_info->first_data_block + i * info->blocks_per_group;
309 uint32_t blk_off = 0;
311 bg_free_blk = info->blocks_per_group -
312 aux_info->inode_table_blocks;
315 blk_off += aux_info->bg_desc_blocks;
317 if (i == (aux_info->groups - 1))
318 bg_free_blk -= aux_info->first_data_block;
320 if (has_superblock(info, i)) {
322 blk_off += info->bg_desc_reserve_blocks;
323 bg_free_blk -= info->bg_desc_reserve_blocks + 1;
324 bg_free_blk -= aux_info->bg_desc_blocks;
327 ext4_bg_set_block_bitmap(&aux_info->bg_desc[i], aux_info->sb,
328 bg_start_block + blk_off + 1);
330 ext4_bg_set_inode_bitmap(&aux_info->bg_desc[i], aux_info->sb,
331 bg_start_block + blk_off + 2);
333 ext4_bg_set_inode_table_first_block(&aux_info->bg_desc[i],
335 bg_start_block + blk_off + 3);
337 ext4_bg_set_free_blocks_count(&aux_info->bg_desc[i],
338 aux_info->sb, bg_free_blk);
340 ext4_bg_set_free_inodes_count(&aux_info->bg_desc[i],
341 aux_info->sb, aux_info->sb->inodes_per_group);
343 ext4_bg_set_used_dirs_count(&aux_info->bg_desc[i], aux_info->sb,
346 ext4_bg_set_flag(&aux_info->bg_desc[i],
347 EXT4_BLOCK_GROUP_BLOCK_UNINIT |
348 EXT4_BLOCK_GROUP_INODE_UNINIT);
350 sb_free_blk += bg_free_blk;
353 ext4_sb_set_free_blocks_cnt(aux_info->sb, sb_free_blk);
357 static int write_bgroups(struct ext4_blockdev *bd, struct fs_aux_info *aux_info,
358 struct ext4_mkfs_info *info)
363 for (i = 0; i < aux_info->groups; i++) {
364 uint64_t bg_start_block = aux_info->first_data_block +
365 + i * info->blocks_per_group;
366 uint32_t blk_off = 0;
368 blk_off += aux_info->bg_desc_blocks;
369 if (has_superblock(info, i)) {
371 blk_off += info->bg_desc_reserve_blocks;
374 uint32_t block_size = ext4_sb_get_block_size(aux_info->sb);
375 uint32_t dsc_pos = 0;
377 uint32_t dsc_size = ext4_sb_get_desc_size(aux_info->sb);
378 uint32_t dsc_blk_cnt = aux_info->bg_desc_blocks;
379 uint64_t dsc_blk = bg_start_block;
381 while (dsc_blk_cnt--) {
382 r = ext4_block_get(bd, &b, dsc_blk++);
387 while (dsc_pos + dsc_size <= block_size) {
388 memcpy(b.data + dsc_pos,
389 &aux_info->bg_desc[dsc_id],
395 if (dsc_id == aux_info->groups)
399 ext4_bcache_set_dirty(b.buf);
400 r = ext4_block_set(bd, &b);
404 if (dsc_id == aux_info->groups)
408 r = ext4_block_get_noread(bd, &b, bg_start_block + blk_off + 1);
411 memset(b.data, 0, block_size);
412 ext4_bcache_set_dirty(b.buf);
413 r = ext4_block_set(bd, &b);
416 r = ext4_block_get_noread(bd, &b, bg_start_block + blk_off + 2);
419 memset(b.data, 0, block_size);
420 ext4_bcache_set_dirty(b.buf);
421 r = ext4_block_set(bd, &b);
430 static int write_sblocks(struct ext4_blockdev *bd, struct fs_aux_info *aux_info,
431 struct ext4_mkfs_info *info)
437 /* write out the backup superblocks */
438 for (i = 1; i < aux_info->groups; i++) {
439 if (has_superblock(info, i)) {
440 offset = info->block_size * (aux_info->first_data_block
441 + i * info->blocks_per_group);
443 aux_info->sb->block_group_index = to_le16(i);
444 r = ext4_block_writebytes(bd, offset, aux_info->sb,
445 EXT4_SUPERBLOCK_SIZE);
451 /* write out the primary superblock */
452 aux_info->sb->block_group_index = to_le16(0);
453 return ext4_block_writebytes(bd, 1024, aux_info->sb,
454 EXT4_SUPERBLOCK_SIZE);
458 int ext4_mkfs_read_info(struct ext4_blockdev *bd, struct ext4_mkfs_info *info)
461 struct ext4_sblock *sb = NULL;
462 r = ext4_block_init(bd);
466 sb = malloc(EXT4_SUPERBLOCK_SIZE);
471 r = ext4_sb_read(bd, sb);
475 r = sb2info(sb, info);
484 static int mkfs_initial(struct ext4_blockdev *bd, struct ext4_mkfs_info *info)
487 struct fs_aux_info aux_info;
488 memset(&aux_info, 0, sizeof(struct fs_aux_info));
490 r = create_fs_aux_info(&aux_info, info);
494 fill_in_sb(&aux_info, info);
495 fill_bgroups(&aux_info, info);
498 r = write_bgroups(bd, &aux_info, info);
502 r = write_sblocks(bd, &aux_info, info);
507 release_fs_aux_info(&aux_info);
511 static int init_bgs(struct ext4_fs *fs)
514 struct ext4_block_group_ref ref;
516 uint32_t bg_count = ext4_block_group_cnt(&fs->sb);
517 for (i = 0; i < bg_count; ++i) {
518 r = ext4_fs_get_block_group_ref(fs, i, &ref);
522 r = ext4_fs_put_block_group_ref(&ref);
529 static int alloc_inodes(struct ext4_fs *fs)
533 struct ext4_inode_ref inode_ref;
534 for (i = 1; i < 12; ++i) {
535 int filetype = EXT4_DE_REG_FILE;
539 case EXT4_GOOD_OLD_FIRST_INO:
540 filetype = EXT4_DE_DIR;
544 r = ext4_fs_alloc_inode(fs, &inode_ref, filetype);
548 ext4_inode_set_mode(&fs->sb, inode_ref.inode, 0);
549 ext4_fs_put_inode_ref(&inode_ref);
555 static int create_dirs(struct ext4_fs *fs)
558 struct ext4_inode_ref root;
559 struct ext4_inode_ref child;
561 r = ext4_fs_get_inode_ref(fs, EXT4_ROOT_INO, &root);
565 r = ext4_fs_get_inode_ref(fs, EXT4_GOOD_OLD_FIRST_INO, &child);
569 ext4_inode_set_mode(&fs->sb, child.inode,
570 EXT4_INODE_MODE_DIRECTORY | 0777);
572 ext4_inode_set_mode(&fs->sb, root.inode,
573 EXT4_INODE_MODE_DIRECTORY | 0777);
575 #if CONFIG_DIR_INDEX_ENABLE
576 /* Initialize directory index if supported */
577 if (ext4_sb_feature_com(&fs->sb, EXT4_FCOM_DIR_INDEX)) {
578 r = ext4_dir_dx_init(&root, &root);
582 r = ext4_dir_dx_init(&child, &root);
586 ext4_inode_set_flag(root.inode, EXT4_INODE_FLAG_INDEX);
587 ext4_inode_set_flag(child.inode, EXT4_INODE_FLAG_INDEX);
591 r = ext4_dir_add_entry(&root, ".", strlen("."), &root);
595 r = ext4_dir_add_entry(&root, "..", strlen(".."), &root);
599 r = ext4_dir_add_entry(&child, ".", strlen("."), &child);
603 r = ext4_dir_add_entry(&child, "..", strlen(".."), &root);
608 r = ext4_dir_add_entry(&root, "lost+found", strlen("lost+found"), &child);
612 ext4_inode_set_links_cnt(root.inode, 3);
613 ext4_inode_set_links_cnt(child.inode, 2);
617 ext4_fs_put_inode_ref(&child);
618 ext4_fs_put_inode_ref(&root);
622 int ext4_mkfs(struct ext4_fs *fs, struct ext4_blockdev *bd,
623 struct ext4_mkfs_info *info, int fs_type)
627 r = ext4_block_init(bd);
634 info->len = bd->bdif->ph_bcnt * bd->bdif->ph_bsize;
636 if (info->block_size == 0)
637 info->block_size = 4096; /*Set block size to default value*/
639 /* Round down the filesystem length to be a multiple of the block size */
640 info->len &= ~((uint64_t)info->block_size - 1);
642 if (info->journal_blocks == 0)
643 info->journal_blocks = compute_journal_blocks(info);
645 if (info->blocks_per_group == 0)
646 info->blocks_per_group = compute_blocks_per_group(info);
648 if (info->inodes == 0)
649 info->inodes = compute_inodes(info);
651 if (info->inode_size == 0)
652 info->inode_size = 256;
654 if (info->label == NULL)
657 info->inodes_per_group = compute_inodes_per_group(info);
661 info->feat_compat = EXT2_SUPPORTED_FCOM;
662 info->feat_ro_compat = EXT2_SUPPORTED_FRO_COM;
663 info->feat_incompat = EXT2_SUPPORTED_FINCOM;
666 info->feat_compat = EXT3_SUPPORTED_FCOM;
667 info->feat_ro_compat = EXT3_SUPPORTED_FRO_COM;
668 info->feat_incompat = EXT3_SUPPORTED_FINCOM;
671 info->feat_compat = EXT4_SUPPORTED_FCOM;
672 info->feat_ro_compat = EXT4_SUPPORTED_FRO_COM;
673 info->feat_incompat = EXT4_SUPPORTED_FINCOM;
677 /*TODO: handle this features*/
678 info->feat_incompat &= ~EXT4_FINCOM_META_BG;
679 info->feat_incompat &= ~EXT4_FINCOM_FLEX_BG;
680 info->feat_ro_compat &= ~EXT4_FRO_COM_METADATA_CSUM;
682 /*TODO: handle journal feature & inode*/
683 if (info->journal == 0)
684 info->feat_compat |= 0;
686 if (info->dsc_size == 0) {
688 if (info->feat_incompat & EXT4_FINCOM_64BIT)
689 info->dsc_size = EXT4_MAX_BLOCK_GROUP_DESCRIPTOR_SIZE;
691 info->dsc_size = EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE;
694 info->bg_desc_reserve_blocks = 0;
696 ext4_dbg(DEBUG_MKFS, DBG_INFO "Creating filesystem with parameters:\n");
697 ext4_dbg(DEBUG_MKFS, DBG_NONE "Size: %"PRIu64"\n", info->len);
698 ext4_dbg(DEBUG_MKFS, DBG_NONE "Block size: %"PRIu32"\n",
700 ext4_dbg(DEBUG_MKFS, DBG_NONE "Blocks per group: %"PRIu32"\n",
701 info->blocks_per_group);
702 ext4_dbg(DEBUG_MKFS, DBG_NONE "Inodes per group: %"PRIu32"\n",
703 info->inodes_per_group);
704 ext4_dbg(DEBUG_MKFS, DBG_NONE "Inode size: %"PRIu32"\n",
706 ext4_dbg(DEBUG_MKFS, DBG_NONE "Inodes: %"PRIu32"\n", info->inodes);
707 ext4_dbg(DEBUG_MKFS, DBG_NONE "Journal blocks: %"PRIu32"\n",
708 info->journal_blocks);
709 ext4_dbg(DEBUG_MKFS, DBG_NONE "Features ro_compat: 0x%x\n",
710 info->feat_ro_compat);
711 ext4_dbg(DEBUG_MKFS, DBG_NONE "Features compat: 0x%x\n",
713 ext4_dbg(DEBUG_MKFS, DBG_NONE "Features incompat: 0x%x\n",
714 info->feat_incompat);
715 ext4_dbg(DEBUG_MKFS, DBG_NONE "BG desc reserve: %"PRIu32"\n",
716 info->bg_desc_reserve_blocks);
717 ext4_dbg(DEBUG_MKFS, DBG_NONE "Descriptor size: %"PRIu16"\n",
719 ext4_dbg(DEBUG_MKFS, DBG_NONE "journal: %s\n",
720 info->journal ? "yes" : "no");
721 ext4_dbg(DEBUG_MKFS, DBG_NONE "Label: %s\n", info->label);
723 struct ext4_bcache bc;
724 memset(&bc, 0, sizeof(struct ext4_bcache));
725 ext4_block_set_lb_size(bd, info->block_size);
726 r = ext4_bcache_init_dynamic(&bc, CONFIG_BLOCK_DEV_CACHE_SIZE,
731 /*Bind block cache to block device*/
732 r = ext4_block_bind_bcache(bd, &bc);
736 r = ext4_block_cache_write_back(bd, 1);
740 r = mkfs_initial(bd, info);
744 r = ext4_fs_init(fs, bd, false);
752 r = alloc_inodes(fs);
764 ext4_block_cache_write_back(bd, 0);
765 ext4_bcache_fini_dynamic(&bc);