duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit f0629e30ac421f73b877b8877c2469c4de21831f
parent b35dd5a2235d21f81d3d513ad164fd00864b9a7c
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Thu, 18 Aug 2022 20:26:45 -0400

sys/file: move File :copy to Path :copyfile

Diffstat:
Mfs/fs/fatlo.fs | 15++++++++-------
Mfs/sys/file.fs | 21++++++++++-----------
Mfs/tests/fs/fat.fs | 12++++++------
Mfs/xcomp/boothi.fs | 6+++---
Mfs/xcomp/bootlo.fs | 2+-
5 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/fs/fs/fatlo.fs b/fs/fs/fatlo.fs @@ -158,7 +158,7 @@ r@ :buf( r> Filesystem :drv :sec@ ; ]struct \ File cursor -extends FileLo struct[ FATFile +extends File struct[ FATFile sfield fat \ all zeroes = free cursor \ b0 = used @@ -176,10 +176,11 @@ extends FileLo struct[ FATFile : :)buf ( self -- a ) dup :buf( swap _clustersize + ; : :free? ( self -- f ) flags not ; : :dirty? ( self -- f ) flags 2 and ; - : :bufpos ( self -- a ) dup FileLo pos over _clustersize mod swap :buf( + ; + : :bufpos ( self -- a ) dup File pos over _clustersize mod swap :buf( + ; : :dirent ( self -- dirent ) dup entryoff swap :fat :getdirentry ; : :cluster0 ( self -- cl ) :dirent DirEntry cluster ; + \ TODO _dst :seek is broken for FAT when file is empty. fix. 0 value self \ set self to pos. If new pos crosses cluster boundaries compared to current \ pos, flush current buffer and read a new sector from disk. @@ -193,17 +194,17 @@ extends FileLo struct[ FATFile swap ?dup if >r begin ( pos cl ) self :fat :FAT@ next then ( pos cl ) dup self :buf( self :fat :readcluster ( pos cl ) self to cluster ( pos ) - then ( pos ) self to FileLo pos ; + then ( pos ) self to File pos ; : :fatreadbuf ( n self -- a? n ) dup :free? if 2drop 0 exit then ( n self ) - dup >r FileLo size r@ FileLo pos - ( n maxn ) + dup >r File size r@ File pos - ( n maxn ) dup 1- 0< if ( EOF ) 2drop rdrop 0 exit then min ( n ) \ make sure that n doesn't go over size - r@ FileLo pos r@ :fatseek ( n ) + r@ File pos r@ :fatseek ( n ) r@ :bufpos r@ :)buf over - ( n a nmax ) rot min ( a n ) - dup r> to+ FileLo pos ( a n ) ; + dup r> to+ File pos ( a n ) ; : :fatclose ( self -- ) dup IO :flush 0 swap to flags ; @@ -214,7 +215,7 @@ extends FileLo struct[ FATFile create _EmptyCursor \ IO ' :fatreadbuf , ' abort , ' drop , - \ FileLo + \ File 0 ( pos ) , 0 ( size ) , ' :fatseek , ' :fatclose , \ FAT fields 0 ( fat ) , 0 ( flags ) , 0 ( cluster ) , -1 ( clusteridx ) , diff --git a/fs/sys/file.fs b/fs/sys/file.fs @@ -12,17 +12,6 @@ struct[ FSInfo create filesystems MAXFSCNT CELLSZ * allot0 bootfs filesystems ! \ record our boot FS in the list -extends FileLo struct[ File - \ TODO implement truncating for when dstfile is larger than self. - 0 structbind FileLo _dst - 0 structbind FileLo _self - : :copy ( dstfile self -- ) ['] _self rebind ['] _dst rebind - \ TODO _dst :seek is broken for FAT when file is empty. fix. - 0 _self :seek begin ( ) - _self size _self :readbuf ?dup while ( a n ) _dst :self IO :write repeat - _dst :flush ; -]struct - struct[ Path sfield fs sfield id @@ -42,6 +31,8 @@ struct[ Path : :child ( name self -- path-or-0 ) >r r@ id swap r@ fs Filesystem :child ( id ) dup if r> fs swap :new else rdrop then ; + : :newfile ( name self -- path ) >r + r@ id swap r@ fs Filesystem :newfile ( id ) r> fs swap :new ; : :root ( self -- path ) fs 0 :new ; @@ -74,6 +65,14 @@ struct[ Path : :chdir ( self -- ) dup id _curpath CELLSZ + ! fs _curpath ! ; : :fload ( self -- ) dup fs swap id fload ; + + \ TODO implement truncating for when dstfile is larger than self. + 0 structbind File _dst + 0 structbind File _src + : :copyfile ( dst self -- ) + :open ['] _src rebind :open ['] _dst rebind begin ( ) + _src size _src :readbuf ?dup while ( a n ) _dst :self IO :write repeat + _dst :close _src :close ; ]struct Path _curpath structbind Path curpath diff --git a/fs/tests/fs/fat.fs b/fs/tests/fs/fat.fs @@ -8,17 +8,17 @@ testbegin mydrv 16 1 1 TOTSEC 17 - FAT newFAT12 mydrv FAT :mountvolume value myfat myfat 0 Path :new structbind Path myroot -0 S" foo.fs" myfat Filesystem :newfile # +S" foo.fs" myroot :newfile # S" /foo.fs" myroot :find# ( path ) \ found! dup Path :info ( path info ) FSInfo name S" FOO.FS" #s= ( path ) Path :open value myfile myfile FATFile :cluster0 0 #eq \ no cluster allocated yet -S" 42" c@+ myfile File :write myfile File :flush +S" 42" c@+ myfile File :write myfile File :close S" /foo.fs" myroot :find# Path :fload 42 #eq \ let's copy that file -0 S" bar.fs" myfat Filesystem :newfile myfat Filesystem :open value mydst -mydst myfile File :copy mydst File :close -S" /bar.fs" myroot :find# Path :fload 42 #eq -myfile File :close +S" foo.fs" myroot :find# value mysrc +S" bar.fs" myroot :newfile value mydst +mydst mysrc Path :copyfile +mydst Path :fload 42 #eq testend diff --git a/fs/xcomp/boothi.fs b/fs/xcomp/boothi.fs @@ -1,15 +1,15 @@ 0 value curhdl \ handle of the file currently being read 0 value fecho -: \s curhdl ?dup if FileLo :close then ; +: \s curhdl ?dup if File :close then ; : f< ( -- c ) - 1 curhdl FileLo :readbuf if c@ else -1 ( EOF ) then + 1 curhdl File :readbuf if c@ else -1 ( EOF ) then fecho if dup emit then ; : fload ( fs id -- ) dup floaded, curhdl >r swap Filesystem :open to curhdl to' in< @ >r ['] f< to in< begin maybeword ?dup if runword 0 else 1 then until - r> to in< curhdl FileLo :close r> to curhdl ; + r> to in< curhdl File :close r> to curhdl ; 0 S" sys" bootfs Filesystem :child S" file.fs" bootfs Filesystem :child bootfs swap fload 0 S" init.fs" bootfs Filesystem :child bootfs swap fload diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs @@ -250,7 +250,7 @@ struct[ Filesystem \ bootfs holds a reference to boot FS. This is used until the full sys/file \ subsystem takes over with Path mechanics. 0 value bootfs \ has to be set before first use -extends IO struct[ FileLo +extends IO struct[ File sfield pos \ offset from beginning of file sfield size smethod :seek