Download code

Jump to: navigation, search

Back to FAT12_floppy_image_(Python)

Download for Windows: single file, zip

Download for UNIX: single file, zip, tar.gz, tar.bz2

build.log

1 SyntaxError: ('invalid syntax', ('/tmp/litprog199799/mkfat12.py', 48, 48, '\t  [(int(param(\'-s\',"2880"))-1,[pack(\'512x\')])]@ text\n'))
2 


mkfat12.py

 1 # The authors of this work have released all rights to it and placed it
 2 # in the public domain under the Creative Commons CC0 1.0 waiver
 3 # (http://creativecommons.org/publicdomain/zero/1.0/).
 4 # 
 5 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 # 
13 # Retrieved from: http://en.literateprograms.org/FAT12_floppy_image_(Python)?oldid=16591
14 
15 from struct import pack
16 from os.path import basename
17 
18 dosfn	=lambda f: "%-8.8s%-3.3s" % tuple((f.upper()+'.').split('.'))[:2]
19 dirent  =lambda f,o,l: pack('<11s15xHI',dosfn(basename(f)),o,l)
20 blocks	=lambda n,b: n/b + (n%b>0)
21 accum   =lambda vs,v0: reduce(lambda l,r: l + [r+l[-1]],vs,[v0])
22 nybbles =lambda vs: sum(((v&0xf,(v>>4)&0xf,(v>>8)&0xf) for v in vs),())
23 n2bytes =lambda ns: [pack('B',o*0x10+e) for e,o in zip(ns[0::2],ns[1::2])]
24 def mkimg(filename,blobs):
25     f = open(filename, "w")
26     for off, data in blobs:
27         f.seek(512*off)
28         f.write(''.join(data))
29     f.close()
30 
31 def mkfat12(opts,files):
32     if '-h' in opts:
33         print "Usage: [-b MBR] [-o output] [-s sector count] files..."
34         return
35 
36     param   = opts.get
37     contents= [file(f).read() for f in files]
38     lens    = [len(c) for c in contents]
39     offs    = accum((blocks(l,512) for l in lens),2)
40     fat     = n2bytes(nybbles((b in offs) and 0xfff or b
41     				for b in range(1,offs[-1]+1)))
42     mkimg(param('-o',"a.raw"),
43           [( 0,[open(param('-b',"mbr.raw")).read()]),
44 	   ( 1,fat),
45 	   (10,fat),
46 	   (19,[dirent(*e) for e in zip(files,offs,lens)])] +
47 	  [(31+o,[c]) for o,c in zip(offs,contents)] +
48 	  [(int(param('-s',"2880"))-1,[pack('512x')])]@ text
49 )
50 
51 if __name__ == '__main__':
52     import sys, getopt
53 
54     os,files = getopt.getopt(sys.argv[1:],"b:o:s:h")
55     mkfat12(dict(os),files)


hijacker
hijacker
hijacker
hijacker