Changeset 0516fd7 in mainline for tools/mktmpfs.py


Ignore:
Timestamp:
2008-08-09T23:46:00Z (17 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8f2a852
Parents:
838e14e2
Message:

structure objects: variable names, comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified tools/mktmpfs.py

    r838e14e2 r0516fd7  
    3333import sys
    3434import os
    35 import struct
    3635import xstruct
    3736
    38 HEADER = xstruct.convert("little: "
    39         "char[5]  /* 'TMPFS' */ "
    40 )
     37HEADER = """little:
     38        char[5] tag  /* 'TMPFS' */
     39"""
    4140
    42 DENTRY = xstruct.convert("little: "
    43         "uint8_t   /* NONE, FILE or DIRECTORY */ "
    44         "uint32_t  /* filename length */ "
    45 )
     41DENTRY_NONE = """little:
     42        uint8_t kind        /* NONE */
     43        uint32_t fname_len  /* 0 */
     44"""
    4645
    47 SIZE = xstruct.convert("little: "
    48         "uint32_t  /* file size */ "
    49 )
     46DENTRY_FILE = """little:
     47        uint8_t kind        /* FILE */
     48        uint32_t fname_len  /* filename length */
     49        char[%d] fname      /* filename */
     50        uint32_t flen       /* file length */
     51"""
    5052
    51 DENTRY_NONE = 0
    52 DENTRY_FILE = 1
    53 DENTRY_DIRECTORY = 2
     53DENTRY_DIRECTORY = """little:
     54        uint8_t kind        /* DIRECTORY */
     55        uint32_t fname_len  /* filename length */
     56        char[%d] fname      /* filename */
     57"""
     58
     59TMPFS_NONE = 0
     60TMPFS_FILE = 1
     61TMPFS_DIRECTORY = 2
    5462
    5563def usage(prname):
     
    6472               
    6573                if (os.path.isfile(canon)):
    66                         outf.write(struct.pack(DENTRY, DENTRY_FILE, len(name)))
    67                         outf.write(xstruct.little_string(name))
    6874                        size = os.path.getsize(canon)
    69                         rd = 0;
    70                         outf.write(struct.pack(SIZE, size))
     75                       
     76                        dentry = xstruct.create(DENTRY_FILE % len(name))
     77                        dentry.kind = TMPFS_FILE
     78                        dentry.fname_len = len(name)
     79                        dentry.fname = name
     80                        dentry.flen = size
     81                       
     82                        outf.write(dentry.pack())
    7183                       
    7284                        inf = file(canon, "r")
     85                        rd = 0;
    7386                        while (rd < size):
    7487                                data = inf.read(4096);
     
    7891               
    7992                if (os.path.isdir(canon)):
    80                         outf.write(struct.pack(DENTRY, DENTRY_DIRECTORY, len(name)))
    81                         outf.write(xstruct.little_string(name))
     93                        dentry = xstruct.create(DENTRY_DIRECTORY % len(name))
     94                        dentry.kind = TMPFS_DIRECTORY
     95                        dentry.fname_len = len(name)
     96                        dentry.fname = name
     97                       
     98                        outf.write(dentry.pack())
     99                       
    82100                        recursion(canon, outf)
    83                         outf.write(struct.pack(DENTRY, DENTRY_NONE, 0))
     101                       
     102                        dentry = xstruct.create(DENTRY_NONE)
     103                        dentry.kind = TMPFS_NONE
     104                        dentry.fname_len = 0
     105                       
     106                        outf.write(dentry.pack())
    84107
    85108def main():
     
    95118        outf = file(sys.argv[2], "w")
    96119       
    97         outf.write(struct.pack(HEADER, "TMPFS"))
     120        header = xstruct.create(HEADER)
     121        header.tag = "TMPFS"
     122       
     123        outf.write(header.pack())
     124       
    98125        recursion(path, outf)
    99         outf.write(struct.pack(DENTRY, DENTRY_NONE, 0))
    100 
     126       
     127        dentry = xstruct.create(DENTRY_NONE)
     128        dentry.kind = TMPFS_NONE
     129        dentry.fname_len = 0
     130       
     131        outf.write(dentry.pack())
     132       
    101133        outf.close()
    102                
     134       
    103135if __name__ == '__main__':
    104136        main()
Note: See TracChangeset for help on using the changeset viewer.