Changeset 9b70394 in mainline
- Timestamp:
- 2008-06-03T00:19:14Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 66a65d7
- Parents:
- 0e6461d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/mktmpfs.py
r0e6461d r9b70394 43 43 print prname + " <ALIGNMENT> <PATH> <IMAGE>" 44 44 45 def recursion(root, outf): 46 "Recursive directory walk" 47 48 payload_size = 0 49 50 for name in os.listdir(root): 51 canon = os.path.join(root, name) 52 53 if (os.path.isfile(canon)): 54 outf.write(struct.pack("<BL" + ("%d" % len(name)) + "s", 1, len(name), name)) 55 payload_size += 5 + len(name) 56 size = os.path.getsize(canon) 57 rd = 0; 58 outf.write(struct.pack("<L", size)) 59 payload_size += 4 60 61 inf = file(canon, "r") 62 while (rd < size): 63 data = inf.read(4096); 64 outf.write(data) 65 payload_size += len(data) 66 rd += len(data) 67 inf.close() 68 69 if (os.path.isdir(canon)): 70 outf.write(struct.pack("<BL" + ("%d" % len(name)) + "s", 2, len(name), name)) 71 payload_size += 5 + len(name) 72 payload_size += recursion(canon, outf) 73 outf.write(struct.pack("<BL", 0, 0)) 74 payload_size += 5 75 76 return payload_size 77 45 78 def main(): 46 79 if (len(sys.argv) < 4): … … 59 92 60 93 header_size = align_up(18, align) 61 payload_size = 062 94 outf = file(sys.argv[3], "w") 63 95 outf.write(struct.pack("<" + ("%d" % header_size) + "x")) 64 96 65 for root, dirs, files in os.walk(path): 66 relpath = root[len(path):len(root)] 67 for name in files: 68 canon = os.path.join(relpath, name) 69 outf.write(struct.pack("<BL" + ("%d" % len(canon)) + "s", 1, len(canon), canon)) 70 payload_size += 5 + len(canon) 71 72 fn = os.path.join(root, name) 73 size = os.path.getsize(fn) 74 rd = 0; 75 outf.write(struct.pack("<L", size)) 76 payload_size += 4 77 78 inf = file(fn, "r") 79 while (rd < size): 80 data = inf.read(4096); 81 outf.write(data) 82 payload_size += len(data) 83 rd += len(data) 84 inf.close() 97 outf.write(struct.pack("<5s", "TMPFS")) 98 payload_size = 5 99 100 payload_size += recursion(path, outf) 85 101 86 for name in dirs: 87 canon = os.path.join(relpath, name) 88 outf.write(struct.pack("<BL" + ("%d" % len(canon)) + "s", 2, len(canon), canon)) 89 payload_size += 5 + len(canon) 102 outf.write(struct.pack("<BL", 0, 0)) 103 payload_size += 5 90 104 91 105 aligned_size = align_up(payload_size, align) … … 93 107 if (aligned_size - payload_size > 0): 94 108 outf.write(struct.pack("<" + ("%d" % (aligned_size - payload_size)) + "x")) 95 109 96 110 outf.seek(0) 97 111 outf.write(struct.pack("<4sBBLQ", "HORD", 1, 1, header_size, aligned_size))
Note:
See TracChangeset
for help on using the changeset viewer.