From 83309a924989d3c40c8d4931da668cbf5ba55ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maja=20K=C4=85dzio=C5=82ka?= Date: Mon, 19 Sep 2022 21:28:02 +0200 Subject: [PATCH] Simple filesystem --- bootstrap.fth | 92 +++++++++++--------- editor.fth | 10 +-- filesystem.fth | 224 +++++++++++++++++++++++++++++++++++++++++++++++++ mkdisk.py | 11 ++- splitdisk.py | 6 +- 5 files changed, 295 insertions(+), 48 deletions(-) create mode 100644 filesystem.fth diff --git a/bootstrap.fth b/bootstrap.fth index 7070a21..2d48615 100644 --- a/bootstrap.fth +++ b/bootstrap.fth @@ -231,7 +231,7 @@ variable srcpos bx push, [di] bx movw+mr, next, ; 0 rpick: r@ 1 rpick: rover 2 rpick: 2rpick --> ( double-cell values, stored little endian - ANS be damned ) -: s>d dup 0< ; : d>s drop ; +: s>d dup 0< ; : d>s drop ; : d0<> or 0<> ; : 2@ dup @ swap cell+ @ ; : 2! swap over cell+ ! ! ; : 2literal swap lit, lit, ; immediate : 2variable create 2 cells allot ; @@ -245,7 +245,7 @@ variable srcpos :code d+ ax pop, dx pop, cx pop, cx ax addw-rr, dx bx adcw-rr, ax push, next, : ud*u ( ud u -- ud ) tuck u* >r um* r> + ; -: dnegate invert swap invert swap 1 0 d+ ; --> +: dnegate invert swap invert swap 1 0 d+ ; : d- dnegate d+ ; --> ( strings ) : exit 'exit , ; immediate : compiling? st c@ 0= ; : mem= ( a1 a2 len -- t|f ) begin dup while >r @@ -294,6 +294,22 @@ variable srcpos --> +( :noname recurse ) +: link, ( list -- ) here swap dup @ , ! ; +: header, ( name len -- ) latest link, dup c, n, ; +: rel@ ( a -- v ) dup @ + cell+ ; +: rel! ( v a -- ) dup >r - 1 cells - r> ! ; +: rel, ( v -- ) here rel! 1 cells allot ; +latest @ >xt 1+ rel@ constant 'docol +: call, E8 c, rel, ; +: hide latest @ cell+ dup >r c@ 40 or r> c! ; +: unhide latest @ cell+ dup >r c@ 40 invert and r> c! ; +: :noname ( -- xt ) s" " header, here 'docol call, hide ] ; +: recurse latest @ >xt , ; immediate --> + + + + ( exception handling ) :code sp! bx sp movw-rr, bx pop, next, @@ -314,34 +330,18 @@ else drop then ; --> : exception ( -- dict-pos ) latest @ ; : print-uint @ u. ; : uint ['] print-uint , variable ; : print-str 2@ type ; : str ['] print-str , 2variable ; +: var #bl token 2dup must-find dup 1 cells - @ , + >r header, 'docol call, r> >xt , postpone ; ; : print-name, ( nt -- ) >name postpone{ 2literal type } ; -: print-field, ( nt -- ) - dup print-name, postpone space - dup >xt , - 1 cells - @ , - postpone cr ; +: print-field, ( nt -- ) dup print-name, postpone space + dup >xt , 1 cells - @ , postpone cr ; : end-exception ( dict-pos -- ) latest @ : latest @ print-name, postpone cr begin ( end-pos cur-pos ) 2dup <> while dup print-field, @ repeat 2drop postpone ; ; --> -( :noname recurse ) -: link, ( list -- ) here swap dup @ , ! ; -: header, ( name len -- ) latest link, dup c, n, ; -: rel@ ( a -- v ) dup @ + cell+ ; -: rel! ( v a -- ) dup >r - 1 cells - r> ! ; -: rel, ( v -- ) here rel! 1 cells allot ; -latest @ >xt 1+ rel@ constant 'docol -: call, E8 c, rel, ; -: hide latest @ cell+ dup >r c@ 40 or r> c! ; -: unhide latest @ cell+ dup >r c@ 40 invert and r> c! ; -: :noname ( -- xt ) s" " header, here 'docol call, hide ] ; -: recurse latest @ >xt , ; immediate - - - --> ( defer ) exception str defer-vector: end-exception unset-defer : bad-defer ( nt -- ) >name defer-vector: 2! @@ -409,19 +409,19 @@ exception str word: end-exception unknown-word ( >number, continued ) : sc@ ( str len -- str len c|0 ) dup if over c@ else 0 then ; : ?dup ( x -- x x | 0 ) dup if dup then ; -: >number ( str -- d t | f ) is-dnum off base @ >r +create all-dnums false , +: >number ( str -- d t | f ) all-dnums @ is-dnum ! base @ >r sc@ basechar ?dup if base ! 1 /string then sc@ [char] - = dup >r if 1 /string then dup 0= if rdrop 2drop false else >digits r> if dnegate then 2swap nip 0<> if 2drop false else true then - then r> base ! ; + then r> base ! ; --> - --> ( block utilities ) exception uint block: uint error: end-exception i/o-error : movb-rr, 8A c, rm-r, ; : movb-rm, 88 c, r-m, ; @@ -457,19 +457,19 @@ exception uint block: uint error: end-exception i/o-error ( quit ) : ." postpone s" compiling? if postpone type else type then ; immediate -: refill-kbd 0 500 dup >in ! 100 accept + c! space ; -: refill ; +create no--> false , : --> no--> @ invert if --> then ; +: refill-kbd no--> off 0 500 dup >in ! 100 accept + c! space ; +: refill ( don't stop processing this block at "quit" below ) ; : prompt compiling? if ." compiled" else ." ok" then cr ; : repl begin refill interpret prompt again ; :noname 1 st c! ; is [ :noname 0 st c! ; is ] rp@ constant r0 -: quit begin postpone [ r0 rp! +: quit begin postpone [ r0 rp! 10 base ! ['] repl catch cr execute again ; :noname ; is skip-space : list cr list ; -quit ' refill-kbd is refill +quit ' refill-kbd is refill --> - --> ( division ) : divw-r, F7 c, 6 rm-r, ; :code (um/mod) dx pop, ax pop, bx divw-r, @@ -484,13 +484,14 @@ exception end-exception division-overflow tuck u/mod >r ( lo div hi R: hi-res ) swap um/mod r> ; : u/ ( u u -- quot ) u/mod nip ; - +: umod ( u u -- mod ) u/mod drop ; --> ( <# #> ) create holdbuf $100 allot here constant endhold variable holdptr : <# ( -- ) endhold holdptr ! ; -: #> ( xd -- str ) 2drop holdptr @ endhold over - ; +: nhold ( -- u ) endhold holdptr @ - ; +: #> ( xd -- str ) 2drop holdptr @ nhold ; exception end-exception hold-area-exhausted : hold ( c -- ) -1 holdptr +! holdptr @ dup holdbuf < ['] hold-area-exhausted and throw c! ; @@ -499,9 +500,8 @@ exception end-exception hold-area-exhausted [char] 0 + then ; : # ( ud -- ud ) base @ ud/mod 2>r >digit hold 2r> ; : d= ( xd xd -- t|f ) >r swap r> = >r = r> and ; -: #s ( ud -- 0. ) begin # 2dup 0. d= until ; +: #s ( ud -- 0. ) begin # 2dup 0. d= until ; --> - --> ( numeric output ) : decimal #10 base ! ; : hex #16 base ! ; : ud. ( ud -- ) <# #s #> type space ; @@ -680,7 +680,7 @@ latest @ ' Forth >body ! definitions --> ( search-order support for find ) :noname ( name len -- nt|0 ) search-order stk.iter< do - 2dup i @ search-in dup if >r 2drop r> unloop exit then + 2dup i @ @ search-in dup if >r 2drop r> unloop exit then drop body ] literal move-to ; : vocab. cell+ @ >name type ; @@ -689,18 +689,34 @@ Root definitions Root then ; : order search-order stk.iter> ?do i @ vocab. space >next space current @ vocab. ; -previous definitions +: only begin search-order stk.depth 1 > while previous repeat ; +: words search-order peek @ words-in ; +previous definitions --> - - --> ( random words not defined earlier ) +: callot ( u -- ) here over allot swap 0 fill ; : max ( a b -- m ) 2dup < if nip else drop then ; : min ( a b -- m ) 2dup > if nip else drop then ; +: umax ( a b -- m ) 2dup u< if nip else drop then ; +: umin ( a b -- m ) 2dup u> if nip else drop then ; : shlw-cl, D3 c, 4 rm-r, ; :code lshift bx cx movw-rr, bx pop, bx shlw-cl, next, : ud> ( da db -- da>db ) >r swap r> 2dup <> if 2swap then 2drop u> ; +: ud< 2swap ud> ; +: ud>= ud< invert ; +#25 #80 u* 2* constant #vga +: clrscr #vga 0 ?do #bl i vga! 7 i 1+ vga! 2 +loop 0 curpos! ; +$1B constant #esc +: 2over ( a. b. -- a. b. a. ) 2>r 2dup 2r> 2swap ; --> +( far cmove ) +: push-es, 06 c, ; : pop-es, 07 c, ; +: push-fs, 0F c, A0 c, ; : pop-fs, 0F c, A1 c, ; +:code fs-cmove bx cx movw-rr, si ax movw-rr, di dx movw-rr, + di pop, si pop, push-es, push-fs, pop-es, + fs> rep, movsb, pop-es, ax si movw-rr, dx di movw-rr, + bx pop, next, diff --git a/editor.fth b/editor.fth index dbc8828..646a343 100644 --- a/editor.fth +++ b/editor.fth @@ -15,8 +15,6 @@ variable dirty dirty off value curblk : read ( blk -- ) dup blk! buf read-block ; : mark ( -- ) dirty on ; --> ( editor: rendering ) -#25 #80 u* 2* constant #vga -: clrscr #vga 0 ?do #bl i vga! 7 i 1+ vga! 2 +loop 0 curpos! ; : mojibake 4 curpos@ attr! $A8 emit ; ( $A8 printable? -> 0 ) create column-colors line-length allot column-colors line-length 7 fill @@ -30,6 +28,8 @@ $47 $3f colclr! : (show-line) line-length 0 ?do dup show-char 1+ loop ; : show-line ( addr -- addr ) dup .lineno (show-line) cr ; --> + + ( editor: rendering - cont. ) defer modeline : modeline-normal ." Editing block $" curblk . @@ -47,7 +47,6 @@ variable need-redraw ( editor: keymaps ) -: callot here over allot swap 0 fill ; value keypress : unbound status ." Unbound key " keypress dup u. emit ; : keymap create ['] unbound , $100 cells callot does> @@ -62,6 +61,7 @@ defer current-keymap keymap normal dup if status red execute else drop then ; : edit-loop normal-mode need-redraw on begin render need-redraw on handle-key again ; --> + ( editor: basic movement ) : quit-editor status quit ; >> char Q bind normal : move-left col @ 1- 0 max col ! ; >> char h bind normal @@ -90,7 +90,7 @@ exception end-exception won't-fit-in-buffer : insert-char cur>buf insert-at move-right ; keymap insert :noname keypress lobyte printable? if keypress insert-char else unbound then ; to insert -$1B constant #esc ' normal-mode #esc bind insert +' normal-mode #esc bind insert :noname ." -- INSERT --" ; : insert-mode literal is modeline ['] insert is current-keymap ; ' insert-mode char i bind normal --> @@ -115,7 +115,7 @@ Forth definitions : ed edit-loop ; : edit read ed ; : save save ; -: run save curblk load ; +: run save no--> on curblk load ; : bnew status ." Erase this block? (y/n)" key lobyte [char] y = if buf 400 clear mark move-top then ed ; previous definitions diff --git a/filesystem.fth b/filesystem.fth new file mode 100644 index 0000000..8c81e1d --- /dev/null +++ b/filesystem.fth @@ -0,0 +1,224 @@ +( more flexible disk I/O ) +: dpacket ( dLBA count buf -- ) + packet pos ! + 10 pos, ( magic ) + swap pos, ( count ) + pos, 0 pos, ( buffer ) + swap pos, pos, 0 pos, 0 pos, ( LBA ) ; +:code do-int13 ( disk ax -- err? ) + dx pop, si push, packet si movw-ir, + bx ax movw-rr, $13 int, + ax bx movw-rr, si pop, next, +: dread ( disk dLBA count buf -- ) dpacket 4200 do-int13 err? ; +: dwrite ( as above ) dpacket 4300 do-int13 err? ; + --> + + +( install to other disk ) +value target +$2000 constant buffer $4000 #512 u/ constant bufsize +: read-orig target 0. 1 buffer dread ; +: read-ours disk# 0. 1 buffer $200 + dread ; +: copy-code buffer $200 + buffer #446 cmove ; +: write-back target 0. 1 buffer dwrite ; +: copy-mbr read-orig read-ours copy-code write-back ; +: copy-small ( lo count -- ) 2dup 2>r 2>r + disk# 2r> 0 swap buffer dread + target 2r> 0 swap buffer dwrite ; +: copy-rest ( lo count -- ) begin dup while + 2dup bufsize min copy-small dup bufsize min tuck - >r + r> + repeat ; +: install-to ( sectors disk -- ) to target copy-mbr + 1- 1 swap copy-rest ; --> +( partition table and chainloading ) +: load-ptable 0 $1e00 read-block ; +: ptable $1e00 #446 + ; +: part ( u -- ptr ) $10 u* ptable + ; +: part-start ( n -- dLBA ) part 8 + 2@ ; +: part-size ( n -- d ) part c + 2@ ; +: ret, $C3 c, ; +: chainload ( n -- ) >r load-ptable + disk# r> part-start 1 buffer dread + buffer $1FE + @ $AA55 = if + $600 dp ! $6000 sp movw-ir, + buffer si movw-ir, $7C00 di movw-ir, $200 cx movw-ir, + rep, movsb, disk# dl movb-ir, $7C00 bx movw-ir, bx push, + ret, + $600 execute + else ." Invalid signature" cr then ; --> +( filesystem -- 4k blocks, free/used bitmap ) +vocabulary Files Files definitions +2variable lba0 load-ptable 0 part-start lba0 2! +: >lba ( blk -- dLBA ) 0 8 ud*u lba0 2@ d+ ; +: bread ( blk buf -- ) >r >r disk# r> >lba 8 r> dread ; +: bwrite ( blk buf -- ) >r >r disk# r> >lba 8 r> dwrite ; +$2000 constant freebits 0 freebits bread +: >bit ( #bit -- val addr ) 8 u/mod >r 1 swap lshift r> + freebits + ; +: is-free ( blk -- ? ) >bit c@ and 0= ; +: save-bits ( -- ) 0 freebits bwrite ; +: (mark-free) ( blk -- ) >bit dup >r c@ swap invert and r> c! ; +: (mark-used) ( blk -- ) >bit dup >r c@ or r> c! ; + + + --> +( filesystem -- freebits manipulation ) +: mark-free ( -- ) (mark-free) save-bits ; +: mark-used ( -- ) (mark-used) save-bits ; +: format-freebits ( -- ) load-ptable + freebits $1000 0 fill 0 (mark-used) + 0 part-size 8 ud/mod d>s nip + $8000 swap ?do i (mark-used) loop save-bits ; +exception end-exception out-of-space +: alloc-any ( -- blk ) $8000 0 ?do + i is-free if i unloop exit then loop ['] out-of-space throw ; +: alloc-sparse ( -- blk ) freebits dup $1000 + swap ?do + i @ 0= if i freebits - 8 u* unloop exit then 2 +loop + alloc-any ; +: alloc-after ( blk -- blk ) 1+ dup is-free invert + if drop alloc-sparse then ; + --> +( filesystem -- blocklist: blk blk blk ... 0 0 0 ... fsize ) +exception end-exception no-file-open create cur-fid 0 , +: fid? ( -- ) cur-fid @ 0= ['] no-file-open and throw ; +$3000 constant blks $3FFC constant fsize +: save-blks ( -- ) fid? cur-fid @ blks bwrite ; +: open-fid ( fid -- ) dup cur-fid ! blks bread ; +: clear-fid ( -- ) blks $1000 0 fill save-blks ; +: new-fid ( -- ) alloc-any dup cur-fid ! mark-used clear-fid ; +: shrink ( n--) fid? cells blks + begin dup fsize < over @ 0<> + and while dup @ (mark-free) 0 over ! cell+ repeat drop ; +exception end-exception file-too-large +: enlarge ( nblk -- ) fid? cells blks + + dup fsize > ['] file-too-large and throw >r 0 blks r> + begin ( prevblk pcur pmax ) 2dup < while >r + dup @ 0= if over alloc-after dup (mark-used) over ! then + nip dup @ swap cell+ r> repeat 2drop drop ; --> +( filesystem -- fsize! fblk ) +: nblk! ( nblk -- ) dup enlarge shrink save-bits ; +: #blks ( bytes. -- blks ) $fff. d+ $1000 ud/mod d>s nip ; +: fsize! ( ud -- ) 2dup fsize 2! #blks nblk! save-blks ; +: fbread ( fb buf -- ) fid? >r cells blks + @ r> bread ; +: fbwrite ( fb buf -- ) fid? >r cells blks + @ r> bwrite ; +$4000 constant fblk create fb -1 , +create fblk-dirty 0 , 2variable fpos +: undirty ( -- ) fblk-dirty @ if fb @ fblk fbwrite + fblk-dirty off then ; +: fb! ( fb -- ) dup fb @ <> if undirty dup fb ! fblk fbread + else drop then ; +: fb-reset ( -- ) undirty -1 fb ! 0. fpos 2! ; +: open-fid ( fid -- ) fb-reset open-fid ; +: new-fid ( -- ) fb-reset new-fid ; --> + +( filesystem -- fread feof? ) +: >blk ( pos. -- off blk ) $1000 ud/mod d>s ; +: blk-use ( blk -- sz ) >r fsize 2@ >blk r> <> + if drop $1000 then ; +: blk-part ( -- bp sz ) fpos 2@ >blk dup >r fb! dup fblk + swap + r> blk-use swap - ; +: next-fpos ( sz -- fpos. ) 0 fpos 2@ d+ ; +: advance ( off -- ) next-fpos fpos 2! ; +exception end-exception file-overread +: can-read ( sz -- ) next-fpos fsize 2@ ud> + ['] file-overread and throw ; +: fread ( buf sz -- ) fid? dup can-read begin dup 0<> while >r + blk-part r@ min ( buf bp n ) >r over r@ cmove r@ advance + r@ + r> r> swap - repeat 2drop ; +: feof? ( -- ? ) fid? fpos 2@ fsize 2@ ud>= ; +: fneof? feof? invert ; --> +( filesystem -- fwrite pread pwrite fshift< ) +: ensure ( sz -- ) next-fpos 2dup fsize 2@ ud> + if fsize! else 2drop then ; +: fwrite ( buf sz -- ) fid? dup ensure begin dup 0<> while >r + blk-part r@ min ( buf bp n ) >r 2dup r@ cmove fblk-dirty on + r@ advance drop r@ + r> r> swap - repeat 2drop ; +: pread ( pos. buf sz -- ) fpos 2@ 2>r 2swap fpos 2! fread + 2r> fpos 2! ; +: pwrite ( pos. buf sz -- ) fpos 2@ 2>r 2swap fpos 2! fwrite + 2r> fpos 2! ; +$5000 constant fsbuf +: bmax ( sz. -- u ) if drop $1000 else $1000 min then ; +: fshift< ( src. dst. sz. -- ) begin 2dup d0<> while 2dup 2>r + bmax >r 2over fsbuf r@ pread 2dup fsbuf r@ pwrite + r@ 0 d+ 2swap r@ 0 d+ 2swap r> 2r> rot 0 d- repeat + 2drop 2drop 2drop ; --> +( filesystem -- directories ) +: format-filesystem ( -- ) format-freebits new-fid ; + ( assume new-fid chose blk 1 ) +20 stack cwds 1 cwds push : cwd ( -- fid ) cwds peek ; +: dirent-blk ( -- blk# ) fsbuf @ ; +: dirent-dir? ( -- t|f ) fsbuf 2 + c@ $80 and 0<> ; +: dirent-name ( -- s u ) fsbuf 2 + count $7f and ; +: next-dirent ( -- ) fsbuf 3 fread dirent-name fread ; +: write-dirent ( -- ) fsbuf 3 fwrite dirent-name fwrite ; +: find-dirent ( name len -- t|f ) cwd open-fid + begin fneof? while + next-dirent 2dup dirent-name s= + if 2drop true exit then + repeat 2drop false ; --> + + +( filesystem -- fopen fcreate ) +exception str filename: end-exception fopen-dir +: fopen? ( name len -- ) 2dup filename: 2! find-dirent dup if + dirent-dir? ['] fopen-dir and throw + dirent-blk open-fid then ; +exception var filename: end-exception no-such-file +: fopen ( name len -- ) 2dup filename: 2! fopen? + invert ['] no-such-file and throw ; +: append ( -- ) fsize 2@ fpos 2! ; +: dirent-blk! ( blk# -- ) fsbuf ! ; +: dirent-name! ( name len -- ) fsbuf 2 + c! dirent-name cmove ; +: dirent-dir! ( -- ) fsbuf 2 + dup c@ $80 or swap c! ; +: append-dirent ( -- ) cwd open-fid append write-dirent ; +: fcreate ( name len -- ) 2dup fopen? if 2drop 0. fsize! else + new-fid cur-fid @ dup >r dirent-blk! dirent-name! + append-dirent r> open-fid then ; --> +( filesystem -- mkdir chdir ls ) +exception var filename: end-exception mkdir-file +: mkdir ( name len -- ) 2dup find-dirent if + filename: 2! dirent-dir? invert ['] mkdir-file and throw else + new-fid cur-fid @ dirent-blk! dirent-name! dirent-dir! + append-dirent then ; +: name. ( -- ) dirent-name type cr ; +: dirent. ( -- ) dirent-dir? if lblue then name. noclr ; +: ls ( -- ) cr cwd open-fid begin fneof? while + next-dirent dirent. repeat ; +: .. ( -- ) cwds stk.depth 1 <> if cwds pop drop then ; +exception var filename: end-exception no-such-dir +: chdir ( name len -- ) 2dup filename: 2! find-dirent + invert ['] no-such-dir and throw + dirent-dir? invert ['] no-such-dir and throw + dirent-blk cwds push ; --> +( filesystem -- delete ) +exception var filename: end-exception cannot-rm-directory +: bytes-left ( -- ud ) fid? fsize 2@ fpos 2@ d- ; +: fbackspace ( sz. -- ) 2>r fpos 2@ fpos 2@ 2r@ d- + bytes-left fshift< fsize 2@ 2r> d- fsize! ; +: delete-dirent ( -- ) dirent-name nip 3 + 0 fbackspace ; +: delete-fid ( fid -- ) dup open-fid 0. fsize! mark-free ; +: (delete) delete-dirent dirent-blk delete-fid ; +: rm ( name len -- ) 2dup filename: 2! find-dirent + invert ['] no-such-file and throw + dirent-dir? ['] cannot-rm-directory and throw (delete) ; +exception var filename: end-exception not-empty +: rmdir ( name len -- ) 2dup filename: 2! find-dirent + invert ['] no-such-dir and throw + dirent-blk open-fid fsize 2@ d0<> ['] not-empty and throw + filename: 2@ find-dirent (delete) ; --> +( filesystem -- readline exec ) +: readline ( b u -- b' ) begin dup 0<> fneof? and while + over 1 fread over c@ #lf = if drop exit then + 1 /string repeat drop ; +variable src-fid 2variable src-fpos +: ensure-fid ( fid -- ) dup cur-fid @ <> if open-fid + else drop then ; +: ensure-src ( -- ) src-fid @ ensure-fid src-fpos 2@ fpos 2! ; +: refill-file ( -- ) + 500 ff readline 0 swap c! 500 >in ! fpos 2@ src-fpos 2! ; +: (exec) ( offset. fname. -- ) src-fid @ >r src-fpos 2@ 2>r + fopen cur-fid @ src-fid ! src-fpos 2! + begin ensure-src fneof? while refill-file interpret repeat + 2r> src-fpos 2! r> src-fid ! ; +: exec ( fname. -- ) 0. 2swap (exec) ; + diff --git a/mkdisk.py b/mkdisk.py index 190172e..dc15121 100644 --- a/mkdisk.py +++ b/mkdisk.py @@ -1,6 +1,12 @@ from itertools import count import sys +FILE_MAP = [ + (0x01, 'bootstrap.fth'), + (0x30, 'editor.fth'), + (0x50, 'filesystem.fth'), +] + # Most blocks (which we'll call *formatted*) are stored in the repository # as 16 lines of length 64 or less, and we can preserve that formatting within # the disk. @@ -20,6 +26,7 @@ def format_block(bnum, block): block = block.strip().replace(b'\n', b' ') if len(block) > 1024: print('Block', bnum, 'is too large - ', len(block), 'bytes') + print(block[:64]) sys.exit(1) block += b' ' * (1024 - len(block)) return block @@ -51,8 +58,8 @@ def blocks_at(begin, fname): blocks = {} blocks[0] = uefix + boot - blocks_at(0x01, 'bootstrap.fth') - blocks_at(0x30, 'editor.fth') + for bnum, fname in FILE_MAP: + blocks_at(bnum, fname) num_blocks = max(blocks.keys()) + 1 diff --git a/splitdisk.py b/splitdisk.py index 1fc7fbf..119f6fe 100644 --- a/splitdisk.py +++ b/splitdisk.py @@ -7,7 +7,7 @@ from difflib import SequenceMatcher from itertools import zip_longest, count -from mkdisk import read_block +from mkdisk import read_block, FILE_MAP import re import sys @@ -74,5 +74,5 @@ def blocks_as_file(start, fname): _, img = sys.argv with open(img, 'rb') as img_file: - blocks_as_file(0x01, 'bootstrap.fth') - blocks_as_file(0x30, 'editor.fth') + for bnum, fname in FILE_MAP: + blocks_as_file(bnum, fname)