Changeset 3c8b0a8 in mainline
- Timestamp:
- 2018-12-15T15:48:59Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4bb4cf88
- Parents:
- b6d5e31 (diff), 6ea5e7a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Maurizio Lombardi <m.lombardi85@…> (2018-12-15 15:48:59)
- git-committer:
- GitHub <noreply@…> (2018-12-15 15:48:59)
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mkext4/mkext4.c
rb6d5e31 r3c8b0a8 56 56 aoff64_t nblocks; 57 57 const char *label = ""; 58 unsigned int bsize = 1024; 58 59 59 60 cfg.version = ext4_def_fs_version; … … 79 80 80 81 nblocks = strtol(*argv, &endptr, 10); 82 if (*endptr != '\0') { 83 printf(NAME ": Error, invalid argument.\n"); 84 syntax_print(); 85 return 1; 86 } 87 88 --argc; 89 ++argv; 90 continue; 91 } 92 93 if (str_cmp(*argv, "--bsize") == 0) { 94 --argc; 95 ++argv; 96 if (*argv == NULL) { 97 printf(NAME ": Error, argument missing.\n"); 98 syntax_print(); 99 return 1; 100 } 101 102 bsize = strtol(*argv, &endptr, 10); 81 103 if (*endptr != '\0') { 82 104 printf(NAME ": Error, invalid argument.\n"); … … 159 181 160 182 cfg.volume_name = label; 183 cfg.bsize = bsize; 161 184 (void) nblocks; 162 185 … … 178 201 "\t--size <sectors> Filesystem size, overrides device size\n" 179 202 "\t--label <label> Volume label\n" 180 "\t--type <fstype> Filesystem type (ext2, ext2old)\n"); 203 "\t--type <fstype> Filesystem type (ext2, ext2old)\n" 204 "\t--bsize <bytes> Filesystem block size in bytes (default = 1024)\n"); 181 205 } 182 206 -
uspace/lib/ext4/include/ext4/cfg.h
rb6d5e31 r3c8b0a8 53 53 /** Volume name encoded as UTF-8 string */ 54 54 const char *volume_name; 55 /** Filesystem block size */ 56 size_t bsize; 55 57 } ext4_cfg_t; 56 58 -
uspace/lib/ext4/include/ext4/superblock.h
rb6d5e31 r3c8b0a8 147 147 extern void ext4_superblock_set_reserved_gdt_blocks(ext4_superblock_t *sb, 148 148 uint32_t n); 149 extern uint32_t ext4_superblock_get_flex_group_size(ext4_superblock_t *sb); 149 150 150 151 /* More complex superblock functions */ -
uspace/lib/ext4/src/balloc.c
rb6d5e31 r3c8b0a8 261 261 * is always after the inode table. 262 262 */ 263 return itable + itable_sz; 264 } 265 266 uint32_t flex_group_size = ext4_superblock_get_flex_group_size(sb); 267 if ((bg_ref->index % flex_group_size) == 0) { 268 /* This is the base group */ 269 uint32_t i; 270 263 271 r = itable + itable_sz; 264 return ext4_filesystem_blockaddr2_index_in_group(sb, r); 265 } 266 267 uint64_t bbmap = ext4_block_group_get_block_bitmap(bg_ref->block_group, 268 sb); 269 uint64_t ibmap = ext4_block_group_get_inode_bitmap(bg_ref->block_group, 270 sb); 271 272 r = ext4_filesystem_index_in_group2blockaddr(sb, 0, bg_ref->index); 273 r += ext4_filesystem_bg_get_backup_blocks(bg_ref); 274 275 if (ext4_filesystem_blockaddr2group(sb, bbmap) != bg_ref->index) 276 bbmap = -1; /* Invalid */ 277 278 if (ext4_filesystem_blockaddr2group(sb, ibmap) != bg_ref->index) 279 ibmap = -1; 280 281 while (true) { 282 if (r == bbmap || r == ibmap) 283 r++; 284 else if (r >= itable && r < (itable + itable_sz)) 285 r = itable + itable_sz; 286 else 287 break; 288 } 289 290 return r; 272 273 uint32_t total_groups = ext4_superblock_get_block_group_count(sb); 274 for (i = bg_ref->index + 1; 275 i < min(total_groups, bg_ref->index + flex_group_size); ++i) { 276 r += ext4_filesystem_bg_get_itable_size(sb, i); 277 } 278 279 return r; 280 } 281 282 uint64_t base_addr = ext4_filesystem_index_in_group2blockaddr(sb, 0, 283 bg_ref->index); 284 uint32_t reserved = ext4_filesystem_bg_get_backup_blocks(bg_ref); 285 286 return base_addr + reserved; 291 287 } 292 288 -
uspace/lib/ext4/src/filesystem.c
rb6d5e31 r3c8b0a8 714 714 /* One for block bitmap one for inode bitmap */ 715 715 free_blocks = free_blocks - reserved - 2 - inode_table_blocks; 716 if (bg_index == 0)717 ++free_blocks; /* XXX Why? */718 716 719 717 ext4_block_group_set_free_blocks_count(bg_ref->block_group, -
uspace/lib/ext4/src/ialloc.c
rb6d5e31 r3c8b0a8 176 176 errno_t ext4_ialloc_alloc_inode(ext4_filesystem_t *fs, uint32_t *index, bool is_dir) 177 177 { 178 int pick_first_free = 0; 178 179 ext4_superblock_t *sb = fs->superblock; 179 180 uint32_t bgid = 0; 181 uint32_t bg_count = ext4_superblock_get_block_group_count(sb); 182 uint32_t sb_free_inodes = ext4_superblock_get_free_inodes_count(sb); 183 uint32_t avg_free_inodes = sb_free_inodes / bg_count; 180 uint32_t bgid; 181 uint32_t sb_free_inodes; 182 uint32_t avg_free_inodes; 183 uint32_t const bg_count = ext4_superblock_get_block_group_count(sb); 184 185 retry: 186 187 bgid = 0; 188 sb_free_inodes = ext4_superblock_get_free_inodes_count(sb); 189 avg_free_inodes = sb_free_inodes / bg_count; 184 190 185 191 /* Try to find free i-node in all block groups */ … … 210 216 * blocks. 211 217 */ 212 if (((free_inodes >= avg_free_inodes) || (bgid == bg_count - 1)) &&213 ( free_blocks > 0)) {218 if (((free_inodes >= avg_free_inodes) || 219 (bgid == bg_count - 1) || pick_first_free) && (free_blocks > 0)) { 214 220 /* Load block with bitmap */ 215 221 uint32_t bitmap_block_addr = ext4_block_group_get_inode_bitmap( … … 307 313 } 308 314 315 /* Try again with less strict conditions */ 316 if (pick_first_free == 0) { 317 pick_first_free = 1; 318 goto retry; 319 } 320 309 321 return ENOSPC; 310 322 } -
uspace/lib/ext4/src/superblock.c
rb6d5e31 r3c8b0a8 1315 1315 ext4_superblock_get_blocks_per_group(sb); 1316 1316 uint64_t total_blocks = 1317 ext4_superblock_get_blocks_count(sb) - 1; 1317 ext4_superblock_get_blocks_count(sb); 1318 uint32_t first_block = 1319 ext4_superblock_get_first_data_block(sb); 1318 1320 1319 1321 if (bgid < block_group_count - 1) 1320 1322 return blocks_per_group; 1321 1323 else 1322 return (total_blocks - ((block_group_count - 1) * blocks_per_group)) ;1324 return (total_blocks - ((block_group_count - 1) * blocks_per_group)) - first_block; 1323 1325 } 1324 1326 … … 1392 1394 { 1393 1395 sb->reserved_gdt_blocks = host2uint32_t_le(n); 1396 } 1397 1398 /** Get the size of the flex groups 1399 * 1400 * @param sb Pointer to the superblock 1401 * 1402 * @return Size of the flex groups 1403 */ 1404 uint32_t ext4_superblock_get_flex_group_size(ext4_superblock_t *sb) 1405 { 1406 return 2 << sb->log_groups_per_flex; 1394 1407 } 1395 1408 … … 1465 1478 */ 1466 1479 1467 if (idx == 0 && block_size == 1024) {1468 /*1469 * Special case for first group were the boot block1470 * resides1471 */1472 r++;1473 }1474 1475 1480 /* This accounts for the superblock */ 1476 1481 r++; … … 1505 1510 uuid_t uuid; 1506 1511 uint32_t cur_ts; 1507 uint64_t first_block ;1512 uint64_t first_block = 0; 1508 1513 uint64_t fs_blocks; 1509 1514 uint32_t blocks_count; … … 1518 1523 uint32_t idx; 1519 1524 size_t fs_bsize; 1525 size_t fs_bsize_log; 1520 1526 errno_t rc; 1521 1527 struct timespec ts; … … 1533 1539 cur_ts = ts.tv_sec; 1534 1540 1535 fs_bsize = 1024; 1536 first_block = 1; /* 1 for 1k block size, 0 otherwise */ 1541 fs_bsize = cfg->bsize; 1542 switch (fs_bsize) { 1543 case 1024: 1544 first_block = 1; 1545 fs_bsize_log = 0; 1546 blocks_group = 8192; 1547 break; 1548 case 2048: 1549 fs_bsize_log = 1; 1550 blocks_group = 8192 * 2; 1551 break; 1552 case 4096: 1553 fs_bsize_log = 2; 1554 blocks_group = 8192 * 4; 1555 break; 1556 default: 1557 return ENOTSUP; 1558 } 1537 1559 1538 1560 if (fs_bsize % dev_bsize == 0) { … … 1543 1565 fs_blocks = dev_bcnt * (dev_bsize / fs_bsize); 1544 1566 } 1545 1546 /* FS blocks per group */1547 blocks_group = 8 * fs_bsize;1548 1567 1549 1568 /* Inodes per group */ … … 1581 1600 ext4_superblock_set_free_inodes_count(sb, inodes_count); 1582 1601 ext4_superblock_set_first_data_block(sb, first_block); 1583 /* Block size will be 1024 bytes */ 1584 ext4_superblock_set_log_block_size(sb, 0); 1602 ext4_superblock_set_log_block_size(sb, fs_bsize_log); 1585 1603 /* Fragment size should be equal to block size */ 1586 ext4_superblock_set_log_frag_size(sb, 0);1604 ext4_superblock_set_log_frag_size(sb, fs_bsize_log); 1587 1605 ext4_superblock_set_blocks_per_group(sb, blocks_group); 1588 1606 /* Should be the same as blocks per group. */ … … 1634 1652 /* Compute free blocks */ 1635 1653 free_blocks = blocks_count; 1636 ++free_blocks; // XXX Why?1637 1654 for (idx = 0; idx < ngroups; idx++) { 1638 1655 free_blocks -= ext4_superblock_get_group_backup_blocks(sb, idx);
Note:
See TracChangeset
for help on using the changeset viewer.