Changeset 0516fd7 in mainline for tools/mktmpfs.py
- Timestamp:
- 2008-08-09T23:46:00Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8f2a852
- Parents:
- 838e14e2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified tools/mktmpfs.py ¶
r838e14e2 r0516fd7 33 33 import sys 34 34 import os 35 import struct36 35 import xstruct 37 36 38 HEADER = xstruct.convert("little: "39 "char[5] /* 'TMPFS' */ "40 ) 37 HEADER = """little: 38 char[5] tag /* 'TMPFS' */ 39 """ 41 40 42 DENTRY = xstruct.convert("little: "43 "uint8_t /* NONE, FILE or DIRECTORY */ "44 "uint32_t /* filename length */ "45 ) 41 DENTRY_NONE = """little: 42 uint8_t kind /* NONE */ 43 uint32_t fname_len /* 0 */ 44 """ 46 45 47 SIZE = xstruct.convert("little: " 48 "uint32_t /* file size */ " 49 ) 46 DENTRY_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 """ 50 52 51 DENTRY_NONE = 0 52 DENTRY_FILE = 1 53 DENTRY_DIRECTORY = 2 53 DENTRY_DIRECTORY = """little: 54 uint8_t kind /* DIRECTORY */ 55 uint32_t fname_len /* filename length */ 56 char[%d] fname /* filename */ 57 """ 58 59 TMPFS_NONE = 0 60 TMPFS_FILE = 1 61 TMPFS_DIRECTORY = 2 54 62 55 63 def usage(prname): … … 64 72 65 73 if (os.path.isfile(canon)): 66 outf.write(struct.pack(DENTRY, DENTRY_FILE, len(name)))67 outf.write(xstruct.little_string(name))68 74 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()) 71 83 72 84 inf = file(canon, "r") 85 rd = 0; 73 86 while (rd < size): 74 87 data = inf.read(4096); … … 78 91 79 92 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 82 100 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()) 84 107 85 108 def main(): … … 95 118 outf = file(sys.argv[2], "w") 96 119 97 outf.write(struct.pack(HEADER, "TMPFS")) 120 header = xstruct.create(HEADER) 121 header.tag = "TMPFS" 122 123 outf.write(header.pack()) 124 98 125 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 101 133 outf.close() 102 134 103 135 if __name__ == '__main__': 104 136 main()
Note:
See TracChangeset
for help on using the changeset viewer.