Changes in tools/mkfat.py [cc1a727:042fbe0] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/mkfat.py

    rcc1a727 r042fbe0  
    3737import xstruct
    3838import array
    39 from imgutil import *
     39
     40exclude_names = set(['.svn', '.bzr'])
     41
     42def align_up(size, alignment):
     43        "Return size aligned up to alignment"
     44       
     45        if (size % alignment == 0):
     46                return size
     47       
     48        return ((size // alignment) + 1) * alignment
    4049
    4150def subtree_size(root, cluster_size, dirent_size):
     
    4554        files = 2
    4655       
    47         for item in listdir_items(root):
    48                 if item.is_file:
    49                         size += align_up(item.size, cluster_size)
     56        for name in os.listdir(root):
     57                canon = os.path.join(root, name)
     58               
     59                if (os.path.isfile(canon) and (not name in exclude_names)):
     60                        size += align_up(os.path.getsize(canon), cluster_size)
    5061                        files += 1
    51                 elif item.is_dir:
    52                         size += subtree_size(item.path, cluster_size, dirent_size)
     62               
     63                if (os.path.isdir(canon) and (not name in exclude_names)):
     64                        size += subtree_size(canon, cluster_size, dirent_size)
    5365                        files += 1
    5466       
     
    6072        return len(os.listdir(root))
    6173
    62 def write_file(item, outf, cluster_size, data_start, fat, reserved_clusters):
     74def write_file(path, outf, cluster_size, data_start, fat, reserved_clusters):
    6375        "Store the contents of a file"
    6476       
     77        size = os.path.getsize(path)
    6578        prev = -1
    6679        first = 0
    6780       
    68         for data in chunks(item, cluster_size):
     81        inf = open(path, "rb")
     82        rd = 0;
     83        while (rd < size):
    6984                empty_cluster = fat.index(0)
    7085                fat[empty_cluster] = 0xffff
     
    7792                prev = empty_cluster
    7893               
     94                data = bytes(inf.read(cluster_size));
    7995                outf.seek(data_start + (empty_cluster - reserved_clusters) * cluster_size)
    8096                outf.write(data)
    81        
    82         return first, item.size
     97                rd += len(data)
     98        inf.close()
     99       
     100        return first, size
    83101
    84102def write_directory(directory, outf, cluster_size, data_start, fat, reserved_clusters, dirent_size, empty_cluster):
     
    285303                empty_cluster = 0
    286304       
    287         for item in listdir_items(root):               
    288                 if item.is_file:
    289                         rv = write_file(item, outf, cluster_size, data_start, fat, reserved_clusters)
    290                         directory.append(create_dirent(item.name, False, rv[0], rv[1]))
    291                 elif item.is_dir:
    292                         rv = recursion(False, item.path, outf, cluster_size, root_start, data_start, fat, reserved_clusters, dirent_size, empty_cluster)
    293                         directory.append(create_dirent(item.name, True, rv[0], rv[1]))
     305        for name in os.listdir(root):
     306                canon = os.path.join(root, name)
     307               
     308                if (os.path.isfile(canon) and (not name in exclude_names)):
     309                        rv = write_file(canon, outf, cluster_size, data_start, fat, reserved_clusters)
     310                        directory.append(create_dirent(name, False, rv[0], rv[1]))
     311               
     312                if (os.path.isdir(canon) and (not name in exclude_names)):
     313                        rv = recursion(False, canon, outf, cluster_size, root_start, data_start, fat, reserved_clusters, dirent_size, empty_cluster)
     314                        directory.append(create_dirent(name, True, rv[0], rv[1]))
    294315       
    295316        if (head):
Note: See TracChangeset for help on using the changeset viewer.