Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 187 lines (171 sloc) 7.381 kb
c7e5df2 - utility for building a tape for use with cold-boot
tim.newsham authored
1 #!/usr/bin/env python
2 """
3 Make a tape for 1st ed cold boot.
4
5 A sequence of files where each file is started with a metadata block
6 and followed by data blocks. A file with a length of zero indicates
7 the end.
8
9 metadata:
10 length : word
11 mode : byte
12 uid : byte
13 name : variable length
14 """
15
474ff8c - apparently perms on s2 bits werent preserved so mktape is now
tim.newsham authored
16 import os, re, sys
c7e5df2 - utility for building a tape for use with cold-boot
tim.newsham authored
17 from struct import pack
18
474ff8c - apparently perms on s2 bits werent preserved so mktape is now
tim.newsham authored
19 # unfortunately the permission bits and uids weren't preserved
20 # so we have to restore them based on this table...
21 rawperms = """
22 -rwrw 0 16448 538 Jan 1 00:33 /core 121912
23 -rwrw 10 54 529 Jan 1 00:52 /usr/x 188944
24 -rwrw 10 84 474 Jan 1 00:58 /usr/jack/x.f 209544
25 -rwrw 0 312 490 Jan 1 00:58 /usr/jack/x.o 210381
26 xrwrw 0 7514 475 Jan 1 00:58 /usr/jack/a.out 210836
27 -r-r- 1 1664 533 Jan 1 01:31 /tmp/etma 328795
28 -rwrw 1 670 530 Jan 1 01:33 /usr/ken/maki.s 336810
29 -rwr- 0 142 532 Jan 1 01:33 /tmp/utmp 337991
30 -rwrw 0 512 259 Jan 1 01:33 /etc/std0 338378
31 xrwrw 0 698 229 Jan 1 01:35 /bin/maki 344095
32 -rwrw 0 26 537 Jan 1 01:35 /tmp/ttmp 344821
33 -rwrw 0 16448 260 Jan 1 01:36 /usr/sys/core 347684
34 -rwr- 1 1928 298 Jan 1 01:36 /usr/sys/maki.s 348923
35 xrwrw 0 2192 293 Jan 1 01:37 /usr/sys/a.out 349375
36 xrwr- 3 1912 135 Jan 4 17:05 /bin/form 19243860
37 urwr- 0 3940 142 Jan 5 19:26 /bin/mail 24936840
38 xrwr- 1 2662 241 Jan 6 18:01 /etc/glob 29812654
39 xrwr- 1 186 240 Jan 6 18:01 /etc/msh 29812724
40 urwr- 0 784 50 Jan 17 17:46 /bin/mv 86785042
41 xrwr- 3 134 114 Jan 17 17:53 /bin/cat 86808907
42 xrwr- 3 82 25 Jan 17 17:53 /bin/chmod 86808926
43 xrwr- 3 420 93 Jan 17 17:53 /bin/cmp 86808947
44 xrwr- 3 160 48 Jan 17 17:53 /bin/cp 86808966
45 xrwr- 3 464 79 Jan 17 17:53 /bin/du 86809052
46 xrwr- 3 104 49 Jan 17 17:53 /bin/ln 86809162
47 xrwr- 3 2010 42 Jan 17 17:53 /bin/ls 86809182
48 xrwr- 3 154 126 Jan 17 17:53 /bin/mesg 86809205
49 xrwr- 3 70 121 Jan 17 17:53 /bin/rew 86809297
50 xrwr- 3 93 52 Jan 17 17:53 /bin/rm 86809316
51 xrwr- 3 1026 54 Jan 17 17:53 /bin/stat 86809356
52 xrwr- 3 80 125 Jan 17 17:53 /bin/tty 86809419
53 xrwr- 3 524 57 Jan 17 17:53 /bin/write 86809532
54 xrwr- 3 560 77 Jan 17 17:54 /bin/who 86813788
55 xrwr- 3 644 139 Jan 17 17:54 /bin/wc 86813793
56 xrwr- 3 750 164 Jan 17 17:54 /bin/skip 86813802
57 xrwr- 3 1166 115 Jan 17 17:54 /bin/pr 86813803
58 xrwr- 3 300 141 Jan 17 17:54 /bin/od 86813807
59 xrwr- 3 1844 159 Jan 17 17:56 /bin/if 86819396
60 xrwr- 3 1154 156 Jan 17 17:56 /bin/goto 86819398
61 xrwr- 3 276 163 Jan 17 17:56 /bin/exit 86819403
62 xrwr- 3 1054 153 Jan 17 17:56 /bin/echo 86819406
63 xrwr- 3 244 60 Jan 17 17:56 /bin/dsw 86819407
64 xrwr- 3 5922 80 Jan 17 17:56 /bin/bas 86819408
65 xrwr- 3 16 152 Jan 17 17:56 /bin/: 86819410
66 xrwr- 1 954 32 Jan 19 17:20 /bin/sh 97059255
67 xrwr- 3 2310 103 Jan 26 17:20 /bin/ar 133346922
68 xrwr- 3 1048 166 Jan 31 18:14 /bin/stty 159458885
69 xrwrw 6 2860 169 Mar 7 12:23 /bin/cal 339637168
70 -rwr- 3 2082 233 Mar 28 16:42 /etc/suftab 449432781
71 urwr- 0 1290 28 Mar 29 15:19 /bin/login 454317684
72 xrwr- 3 4066 95 Mar 29 16:42 /bin/db 454616955
73 xrwrw 3 76 94 Apr 6 19:42 /bin/chball 496735250
74 xrwrw 3 446 232 Apr 7 16:40 /etc/getty 501264829
75 xrwr- 3 6846 176 Apr 14 20:50 /bin/dc 538454712
76 urwr- 0 794 26 Apr 20 23:45 /bin/date 570186721
77 urwr- 0 746 190 May 3 22:54 /bin/su 637395674
78 xrwr- 3 3998 127 May 10 15:23 /bin/ed 672059949
79 xrwr- 3 330 213 May 27 00:21 /bin/find 756940137
80 xrwr- 3 480 59 May 27 00:21 /bin/strip 756940428
81 urwr- 1 872 211 May 27 00:26 /bin/ds 756957948
82 xrwr- 10 2730 192 May 27 23:37 /bin/fc 761966733
83 xrwrw 3 17092 346 Jun 6 21:26 /usr/lib/c1 813333853
84 -rwrw 0 3498 339 Jun 9 17:10 /usr/lib/bilib.a 827964344
85 -rwrw 0 6626 326 Jun 20 10:47 /usr/lib/libb.a 883611316
86 xrwr- 3 7582 214 Jun 30 17:45 /bin/as 936955268
87 xrwrw 3 5778 247 Jun 30 17:47 /etc/as2 936962166
88 xrwr- 3 238 118 Jun 30 18:37 /bin/un 937143109
89 -rwrw 0 12158 302 Jun 30 18:40 /usr/lib/liba.a 937154143
90 xrwr- 3 2942 108 Jun 30 19:26 /bin/ld 937319472
91 xrwr- 3 518 75 Jun 30 20:09 /bin/nm 937472871
92 xrwr- 3 1446 208 Jun 30 20:15 /bin/size 937496145
93 -rwrw 28 304 448 Jun 30 20:31 /usr/lib/fr0.o 937553564
94 -rwrw 28 12222 449 Jun 30 20:37 /usr/lib/filib.a 937573356
95 -rwrw 28 9158 419 Jun 30 20:46 /usr/lib/libf.a 937606048
96 -rwrw 0 108 473 Jun 30 21:11 /usr/lib/crt0.o 937696858
97 -rwrw 0 5242 437 Jun 30 21:20 /usr/lib/libc.a 937728015
98 xrwrw 3 19948 380 Jun 30 21:21 /usr/lib/c0 937734428
99 xrwrw 3 4672 198 Jun 30 21:53 /bin/cc 937848855
100 xrwr- 28 3462 491 Jul 1 16:35 /usr/fort/fc1 941888104
101 xrwr- 28 3238 498 Jul 1 16:35 /usr/fort/fc2 941888184
102 xrwr- 28 6840 505 Jul 1 16:35 /usr/fort/fc3 941888472
103 xrwr- 28 4918 519 Jul 1 16:35 /usr/fort/fc4 941888613
104 xrwrw 3 214 175 Jul 15 01:21 /bin/sum 1011175062
105 xrwr- 4 7154 61 Jul 21 12:42 /bin/roff 1044729738
106 urwr- 0 282 53 Sep 28 21:37 /bin/rmdir 1404349922
107 urwr- 0 232 31 Nov 6 21:42 /bin/mkdir 1606544287
108 urwr- 1 192 92 Nov 22 19:35 /bin/df 1689030995
109 urwr- 1 1084 122 Nov 22 19:35 /bin/check 1689030997
110 xrwr- 3 718 46 Nov 22 22:51 /bin/chown 1689737545
111 xrwr- 3 604 150 Nov 22 22:51 /bin/sort 1689737557
112 urwr- 1 790 119 Nov 26 14:24 /bin/tm 1708647263
113 urwr- 0 3678 34 Dec 31 04:08 /bin/tap 1887871165
114 -rw-- 1 221 239 Feb 6 14:35 /etc/passwd 2081934621
115 -rwr- 1 70 238 Feb 6 14:38 /etc/uids 2081948231
116 xrwr- 1 424 231 Feb 6 14:50 /etc/init 2081988977
117 """
118
119
120 def uMode(s) :
121 m = 0
122 if s[0] == 'u' : m |= 040 | 020
123 if s[0] == 'x' : m |= 020
124 if s[1] == 'r' : m |= 010
125 if s[2] == 'w' : m |= 004
126 if s[3] == 'r' : m |= 002
127 if s[4] == '2' : m |= 001
128 return m
129
130 # preprocess the perms table to form perm :: path -> (mode, uid)
131 ps = re.sub("[ \t]+", " ", rawperms)
132 ps = filter(None, ps.split("\n"))
133 ps = [p.split(' ') for p in ps]
134 perms = dict((p[7], (uMode(p[0]), int(p[1]))) for p in ps)
135
c7e5df2 - utility for building a tape for use with cold-boot
tim.newsham authored
136 def pad(d) :
137 "pad to 512-byte boundary"
138 l = len(d)
139 m = ((l + 511) & ~511) - l
140 return d + ("\0" * m)
141
142 def sMode(m) :
143 return (
144 ("-","s")[(m & 040) != 0] +
145 ("-","x")[(m & 020) != 0] +
146 ("-","r")[(m & 010) != 0] +
147 ("-","w")[(m & 004) != 0] +
148 ("-","r")[(m & 002) != 0] +
149 ("-","w")[(m & 001) != 0] )
150
151 def wrFile(out, fn, d, mode, uid) :
152 "write out file."
153 print sMode(mode), uid, fn
107d3d1 - oops, forgot to be explicit about the endian.
tim.newsham authored
154 meta = pack("<HBB", len(d), mode, uid) + fn
c7e5df2 - utility for building a tape for use with cold-boot
tim.newsham authored
155 out.write(pad(meta))
156 out.write(pad(d))
157
158 def wrEof(out) :
159 wrFile(out, "", "", 0, 0)
160
161 def copyFile(out, fn) :
162 "copy file from local filesystem to tape."
163 f = file(fn, 'rb')
164 d = f.read()
165 f.close()
166 s = os.stat(fn)
167 if fn[:len(root)] == root :
168 fn = fn[len(root):]
474ff8c - apparently perms on s2 bits werent preserved so mktape is now
tim.newsham authored
169 # get the perm from the table, if not present, just make it
170 # uid=1 mode = 37.
171 mode,uid = perms.get(fn, (037, 1))
172 if not fn in perms : print "making up mode"
c7e5df2 - utility for building a tape for use with cold-boot
tim.newsham authored
173 wrFile(out, fn, d, mode, uid)
174
474ff8c - apparently perms on s2 bits werent preserved so mktape is now
tim.newsham authored
175 root = "/tmp/s2"
c7e5df2 - utility for building a tape for use with cold-boot
tim.newsham authored
176 def main() :
177 f = file("tape", "wb")
d44f2a2 - oops, need to start output at block #65
tim.newsham authored
178 f.write("\0" * (512 * 65)) # start at block 65
c7e5df2 - utility for building a tape for use with cold-boot
tim.newsham authored
179 for fn in sys.argv[1:] :
180 copyFile(f, fn)
181 wrEof(f)
182 f.close()
183
184 if __name__ == "__main__" :
185 main()
186
Something went wrong with that request. Please try again.