Changes in / [3c8b0a8:b6d5e31] in mainline
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mkext4/mkext4.c
r3c8b0a8 rb6d5e31 56 56 aoff64_t nblocks; 57 57 const char *label = ""; 58 unsigned int bsize = 1024;59 58 60 59 cfg.version = ext4_def_fs_version; … … 80 79 81 80 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);103 81 if (*endptr != '\0') { 104 82 printf(NAME ": Error, invalid argument.\n"); … … 181 159 182 160 cfg.volume_name = label; 183 cfg.bsize = bsize;184 161 (void) nblocks; 185 162 … … 201 178 "\t--size <sectors> Filesystem size, overrides device size\n" 202 179 "\t--label <label> Volume label\n" 203 "\t--type <fstype> Filesystem type (ext2, ext2old)\n" 204 "\t--bsize <bytes> Filesystem block size in bytes (default = 1024)\n"); 180 "\t--type <fstype> Filesystem type (ext2, ext2old)\n"); 205 181 } 206 182 -
uspace/lib/ext4/include/ext4/cfg.h
r3c8b0a8 rb6d5e31 53 53 /** Volume name encoded as UTF-8 string */ 54 54 const char *volume_name; 55 /** Filesystem block size */56 size_t bsize;57 55 } ext4_cfg_t; 58 56 -
uspace/lib/ext4/include/ext4/superblock.h
r3c8b0a8 rb6d5e31 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);150 149 151 150 /* More complex superblock functions */ -
uspace/lib/ext4/src/balloc.c
r3c8b0a8 rb6d5e31 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 271 263 r = itable + itable_sz; 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; 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; 287 291 } 288 292 -
uspace/lib/ext4/src/filesystem.c
r3c8b0a8 rb6d5e31 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? */ 716 718 717 719 ext4_block_group_set_free_blocks_count(bg_ref->block_group, -
uspace/lib/ext4/src/ialloc.c
r3c8b0a8 rb6d5e31 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;179 178 ext4_superblock_t *sb = fs->superblock; 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; 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; 190 184 191 185 /* Try to find free i-node in all block groups */ … … 216 210 * blocks. 217 211 */ 218 if (((free_inodes >= avg_free_inodes) || 219 ( bgid == bg_count - 1) || pick_first_free) && (free_blocks > 0)) {212 if (((free_inodes >= avg_free_inodes) || (bgid == bg_count - 1)) && 213 (free_blocks > 0)) { 220 214 /* Load block with bitmap */ 221 215 uint32_t bitmap_block_addr = ext4_block_group_get_inode_bitmap( … … 313 307 } 314 308 315 /* Try again with less strict conditions */316 if (pick_first_free == 0) {317 pick_first_free = 1;318 goto retry;319 }320 321 309 return ENOSPC; 322 310 } -
uspace/lib/ext4/src/superblock.c
r3c8b0a8 rb6d5e31 1315 1315 ext4_superblock_get_blocks_per_group(sb); 1316 1316 uint64_t total_blocks = 1317 ext4_superblock_get_blocks_count(sb); 1318 uint32_t first_block = 1319 ext4_superblock_get_first_data_block(sb); 1317 ext4_superblock_get_blocks_count(sb) - 1; 1320 1318 1321 1319 if (bgid < block_group_count - 1) 1322 1320 return blocks_per_group; 1323 1321 else 1324 return (total_blocks - ((block_group_count - 1) * blocks_per_group)) - first_block;1322 return (total_blocks - ((block_group_count - 1) * blocks_per_group)); 1325 1323 } 1326 1324 … … 1394 1392 { 1395 1393 sb->reserved_gdt_blocks = host2uint32_t_le(n); 1396 }1397 1398 /** Get the size of the flex groups1399 *1400 * @param sb Pointer to the superblock1401 *1402 * @return Size of the flex groups1403 */1404 uint32_t ext4_superblock_get_flex_group_size(ext4_superblock_t *sb)1405 {1406 return 2 << sb->log_groups_per_flex;1407 1394 } 1408 1395 … … 1478 1465 */ 1479 1466 1467 if (idx == 0 && block_size == 1024) { 1468 /* 1469 * Special case for first group were the boot block 1470 * resides 1471 */ 1472 r++; 1473 } 1474 1480 1475 /* This accounts for the superblock */ 1481 1476 r++; … … 1510 1505 uuid_t uuid; 1511 1506 uint32_t cur_ts; 1512 uint64_t first_block = 0;1507 uint64_t first_block; 1513 1508 uint64_t fs_blocks; 1514 1509 uint32_t blocks_count; … … 1523 1518 uint32_t idx; 1524 1519 size_t fs_bsize; 1525 size_t fs_bsize_log;1526 1520 errno_t rc; 1527 1521 struct timespec ts; … … 1539 1533 cur_ts = ts.tv_sec; 1540 1534 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 } 1535 fs_bsize = 1024; 1536 first_block = 1; /* 1 for 1k block size, 0 otherwise */ 1559 1537 1560 1538 if (fs_bsize % dev_bsize == 0) { … … 1565 1543 fs_blocks = dev_bcnt * (dev_bsize / fs_bsize); 1566 1544 } 1545 1546 /* FS blocks per group */ 1547 blocks_group = 8 * fs_bsize; 1567 1548 1568 1549 /* Inodes per group */ … … 1600 1581 ext4_superblock_set_free_inodes_count(sb, inodes_count); 1601 1582 ext4_superblock_set_first_data_block(sb, first_block); 1602 ext4_superblock_set_log_block_size(sb, fs_bsize_log); 1583 /* Block size will be 1024 bytes */ 1584 ext4_superblock_set_log_block_size(sb, 0); 1603 1585 /* Fragment size should be equal to block size */ 1604 ext4_superblock_set_log_frag_size(sb, fs_bsize_log);1586 ext4_superblock_set_log_frag_size(sb, 0); 1605 1587 ext4_superblock_set_blocks_per_group(sb, blocks_group); 1606 1588 /* Should be the same as blocks per group. */ … … 1652 1634 /* Compute free blocks */ 1653 1635 free_blocks = blocks_count; 1636 ++free_blocks; // XXX Why? 1654 1637 for (idx = 0; idx < ngroups; idx++) { 1655 1638 free_blocks -= ext4_superblock_get_group_backup_blocks(sb, idx);
Note:
See TracChangeset
for help on using the changeset viewer.