Changeset 28f4adb in mainline for tools/mkfat.py
- Timestamp:
- 2010-11-02T11:13:36Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4687a26c, e06ef614
- Parents:
- 458619f7
- git-author:
- Vojtech Horky <> (2010-11-02 11:13:36)
- git-committer:
- Martin Decky <martin@…> (2010-11-02 11:13:36)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/mkfat.py
r458619f7 r28f4adb 46 46 return size 47 47 48 return (( (size / alignment) + 1) * alignment)48 return ((size // alignment) + 1) * alignment 49 49 50 50 def subtree_size(root, cluster_size, dirent_size): … … 79 79 first = 0 80 80 81 inf = file(path, "r")81 inf = open(path, "rb") 82 82 rd = 0; 83 83 while (rd < size): … … 92 92 prev = empty_cluster 93 93 94 data = inf.read(cluster_size);94 data = bytes(inf.read(cluster_size)); 95 95 outf.seek(data_start + (empty_cluster - reserved_clusters) * cluster_size) 96 96 outf.write(data) … … 120 120 prev = empty_cluster 121 121 122 data = ''122 data = bytes() 123 123 data_len = 0 124 124 while ((i < length) and (data_len < cluster_size)): … … 343 343 def usage(prname): 344 344 "Print usage syntax" 345 print prname + " <EXTRA_BYTES> <PATH> <IMAGE>"345 print(prname + " <EXTRA_BYTES> <PATH> <IMAGE>") 346 346 347 347 def main(): … … 351 351 352 352 if (not sys.argv[1].isdigit()): 353 print "<EXTRA_BYTES> must be a number"353 print("<EXTRA_BYTES> must be a number") 354 354 return 355 355 … … 358 358 path = os.path.abspath(sys.argv[2]) 359 359 if (not os.path.isdir(path)): 360 print "<PATH> must be a directory"360 print("<PATH> must be a directory") 361 361 return 362 362 … … 372 372 # Make sure the filesystem is large enought for FAT16 373 373 size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size + extra_bytes 374 while (size / cluster_size < fat16_clusters):374 while (size // cluster_size < fat16_clusters): 375 375 if (cluster_size > sector_size): 376 cluster_size /=2376 cluster_size = cluster_size // 2 377 377 size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size + extra_bytes 378 378 else: … … 381 381 root_size = align_up(root_entries(path) * dirent_size, cluster_size) 382 382 383 fat_size = align_up(align_up(size, cluster_size) / cluster_size * fatent_size, sector_size)384 385 sectors = (cluster_size + fat_count * fat_size + root_size + size) / sector_size383 fat_size = align_up(align_up(size, cluster_size) // cluster_size * fatent_size, sector_size) 384 385 sectors = (cluster_size + fat_count * fat_size + root_size + size) // sector_size 386 386 root_start = cluster_size + fat_count * fat_size 387 387 data_start = root_start + root_size 388 388 389 outf = file(sys.argv[3], "w")389 outf = open(sys.argv[3], "wb") 390 390 391 391 boot_sector = xstruct.create(BOOT_SECTOR) 392 392 boot_sector.jmp = [0xEB, 0x3C, 0x90] 393 boot_sector.oem = "MSDOS5.0"393 boot_sector.oem = b'MSDOS5.0' 394 394 boot_sector.sector = sector_size 395 boot_sector.cluster = cluster_size / sector_size396 boot_sector.reserved = cluster_size / sector_size395 boot_sector.cluster = cluster_size // sector_size 396 boot_sector.reserved = cluster_size // sector_size 397 397 boot_sector.fats = fat_count 398 boot_sector.rootdir = root_size / dirent_size398 boot_sector.rootdir = root_size // dirent_size 399 399 if (sectors <= 65535): 400 400 boot_sector.sectors = sectors … … 402 402 boot_sector.sectors = 0 403 403 boot_sector.descriptor = 0xF8 404 boot_sector.fat_sectors = fat_size / sector_size404 boot_sector.fat_sectors = fat_size // sector_size 405 405 boot_sector.track_sectors = 63 406 406 boot_sector.heads = 6 … … 414 414 boot_sector.extboot_signature = 0x29 415 415 boot_sector.serial = random.randint(0, 0x7fffffff) 416 boot_sector.label = "HELENOS"417 boot_sector.fstype = "FAT16 "416 boot_sector.label = b'HELENOS' 417 boot_sector.fstype = b'FAT16 ' 418 418 boot_sector.boot_signature = [0x55, 0xAA] 419 419 … … 423 423 424 424 # Reserved sectors 425 for i in range(1, cluster_size / sector_size):425 for i in range(1, cluster_size // sector_size): 426 426 outf.write(empty_sector.pack()) 427 427 428 428 # FAT tables 429 429 for i in range(0, fat_count): 430 for j in range(0, fat_size / sector_size):430 for j in range(0, fat_size // sector_size): 431 431 outf.write(empty_sector.pack()) 432 432 433 433 # Root directory 434 for i in range(0, root_size / sector_size):434 for i in range(0, root_size // sector_size): 435 435 outf.write(empty_sector.pack()) 436 436 437 437 # Data 438 for i in range(0, size / sector_size):438 for i in range(0, size // sector_size): 439 439 outf.write(empty_sector.pack()) 440 440 441 fat = array.array('L', [0] * (fat_size / fatent_size))441 fat = array.array('L', [0] * (fat_size // fatent_size)) 442 442 fat[0] = 0xfff8 443 443 fat[1] = 0xffff … … 449 449 for i in range(0, fat_count): 450 450 outf.seek(cluster_size + i * fat_size) 451 for j in range(0, fat_size / fatent_size):451 for j in range(0, fat_size // fatent_size): 452 452 fat_entry.next = fat[j] 453 453 outf.write(fat_entry.pack())
Note:
See TracChangeset
for help on using the changeset viewer.