Changeset 28f4adb in mainline for tools/mkfat.py


Ignore:
Timestamp:
2010-11-02T11:13:36Z (14 years ago)
Author:
Martin Decky <martin@…>
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)
Message:

update scripts for compatibility with Python 3 (thx Vojtech Horky and Martin Sucha)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/mkfat.py

    r458619f7 r28f4adb  
    4646                return size
    4747       
    48         return (((size / alignment) + 1) * alignment)
     48        return ((size // alignment) + 1) * alignment
    4949
    5050def subtree_size(root, cluster_size, dirent_size):
     
    7979        first = 0
    8080       
    81         inf = file(path, "r")
     81        inf = open(path, "rb")
    8282        rd = 0;
    8383        while (rd < size):
     
    9292                prev = empty_cluster
    9393               
    94                 data = inf.read(cluster_size);
     94                data = bytes(inf.read(cluster_size));
    9595                outf.seek(data_start + (empty_cluster - reserved_clusters) * cluster_size)
    9696                outf.write(data)
     
    120120                prev = empty_cluster
    121121               
    122                 data = ''
     122                data = bytes()
    123123                data_len = 0
    124124                while ((i < length) and (data_len < cluster_size)):
     
    343343def usage(prname):
    344344        "Print usage syntax"
    345         print prname + " <EXTRA_BYTES> <PATH> <IMAGE>"
     345        print(prname + " <EXTRA_BYTES> <PATH> <IMAGE>")
    346346
    347347def main():
     
    351351       
    352352        if (not sys.argv[1].isdigit()):
    353                 print "<EXTRA_BYTES> must be a number"
     353                print("<EXTRA_BYTES> must be a number")
    354354                return
    355355       
     
    358358        path = os.path.abspath(sys.argv[2])
    359359        if (not os.path.isdir(path)):
    360                 print "<PATH> must be a directory"
     360                print("<PATH> must be a directory")
    361361                return
    362362       
     
    372372        # Make sure the filesystem is large enought for FAT16
    373373        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):
    375375                if (cluster_size > sector_size):
    376                         cluster_size /= 2
     376                        cluster_size = cluster_size // 2
    377377                        size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size + extra_bytes
    378378                else:
     
    381381        root_size = align_up(root_entries(path) * dirent_size, cluster_size)
    382382       
    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_size
     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_size
    386386        root_start = cluster_size + fat_count * fat_size
    387387        data_start = root_start + root_size
    388388       
    389         outf = file(sys.argv[3], "w")
     389        outf = open(sys.argv[3], "wb")
    390390       
    391391        boot_sector = xstruct.create(BOOT_SECTOR)
    392392        boot_sector.jmp = [0xEB, 0x3C, 0x90]
    393         boot_sector.oem = "MSDOS5.0"
     393        boot_sector.oem = b'MSDOS5.0'
    394394        boot_sector.sector = sector_size
    395         boot_sector.cluster = cluster_size / sector_size
    396         boot_sector.reserved = cluster_size / sector_size
     395        boot_sector.cluster = cluster_size // sector_size
     396        boot_sector.reserved = cluster_size // sector_size
    397397        boot_sector.fats = fat_count
    398         boot_sector.rootdir = root_size / dirent_size
     398        boot_sector.rootdir = root_size // dirent_size
    399399        if (sectors <= 65535):
    400400                boot_sector.sectors = sectors
     
    402402                boot_sector.sectors = 0
    403403        boot_sector.descriptor = 0xF8
    404         boot_sector.fat_sectors = fat_size / sector_size
     404        boot_sector.fat_sectors = fat_size // sector_size
    405405        boot_sector.track_sectors = 63
    406406        boot_sector.heads = 6
     
    414414        boot_sector.extboot_signature = 0x29
    415415        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   '
    418418        boot_sector.boot_signature = [0x55, 0xAA]
    419419       
     
    423423       
    424424        # Reserved sectors
    425         for i in range(1, cluster_size / sector_size):
     425        for i in range(1, cluster_size // sector_size):
    426426                outf.write(empty_sector.pack())
    427427       
    428428        # FAT tables
    429429        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):
    431431                        outf.write(empty_sector.pack())
    432432       
    433433        # Root directory
    434         for i in range(0, root_size / sector_size):
     434        for i in range(0, root_size // sector_size):
    435435                outf.write(empty_sector.pack())
    436436       
    437437        # Data
    438         for i in range(0, size / sector_size):
     438        for i in range(0, size // sector_size):
    439439                outf.write(empty_sector.pack())
    440440       
    441         fat = array.array('L', [0] * (fat_size / fatent_size))
     441        fat = array.array('L', [0] * (fat_size // fatent_size))
    442442        fat[0] = 0xfff8
    443443        fat[1] = 0xffff
     
    449449        for i in range(0, fat_count):
    450450                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):
    452452                        fat_entry.next = fat[j]
    453453                        outf.write(fat_entry.pack())
Note: See TracChangeset for help on using the changeset viewer.