~vdupras/duskos

e9562086c7eb0ca8f25ede1c7d089d8309b0dbcf — Virgil Dupras 14 days ago 39864c9
Remove bufptr and bufsz from base File struct

It is far from being commonly used now.
5 files changed, 13 insertions(+), 22 deletions(-)

M fs/comp/c/lib.fs
M fs/fs/fatlo.fs
M fs/lib/file.fs
M fs/xcomp/bootlo.fs
M posix/vm.c
M fs/comp/c/lib.fs => fs/comp/c/lib.fs +1 -2
@@ 141,9 141,8 @@ calias 0-9? int isdigit(char c);
    void *_close;
    uint pos;
    uint size;
    uchar *bufptr;
    uint bufsz;
    void *_seek;
    void *_truncate;
};

\ Quick sort implementation using Hoare's partitioning

M fs/fs/fatlo.fs => fs/fs/fatlo.fs +1 -3
@@ 157,7 157,6 @@ extends File struct[ FATFile
  alias drop flush
  alias abort truncate

  : seek to pos ;
  : _clpos ( self -- subpos clidx ) bi pos | :fat :ClusterSize /mod ;
  \ Can't be called with pos >= size
  : _place ( self -- )


@@ 184,8 183,7 @@ extends File struct[ FATFile
    File :new >r S[ :[methods] ]S c@+ -move, \ V1=hdl
    S[ IO :[methods] ]S c@+ r@ IO :methods( swap move
    swap ( fat ) , ( secwin ) , 0 ( flags ) , 0 ( cluster ) ,
    -1 ( clusteridx ) , 0 ( entryoff ) ,
    r@ :secwin :buf( r@ to bufptr r@ :fat :drv secsz r@ to bufsz r> ;
    -1 ( clusteridx ) , 0 ( entryoff ) , r> ;
]struct

struct+[ FAT

M fs/lib/file.fs => fs/lib/file.fs +7 -8
@@ 1,6 1,10 @@
?f<< /lib/drive.fs

extends File struct[ MemFile
  sfield bufsz
  SZ &+ :buf(
  : :)buf bi :buf( | bufsz + ;
  : :ptr bi+ pos | bufsz mod swap :buf( + ;
  : _maxn ( n hdl -- real-n ) >r V1 pos + V1 size min r> pos - ;
  : readbuf ( n hdl -- a? read-n )
    >r V1 _maxn ( read-n ) dup if V1 :ptr swap dup V1 to+ pos then rdrop ;


@@ 8,12 12,10 @@ extends File struct[ MemFile
    >r V1 _maxn ( a write-n ) dup if ( a write-n )
      tuck V1 :ptr swap ( write-n a dst n ) move ( write-n ) dup V1 to+ pos
      else nip then rdrop ;
  : seek ( pos hdl -- ) to pos ;
  alias drop truncate
  : :new ( sz -- hdl )
    File :new >r S[ :[methods] ]S c@+ -move, ( sz ) \ V1=hdl
    File :new >r S[ :[methods] ]S c@+ -move, \ V1=hdl
    S[ IO :[methods] ]S c@+ r@ IO :methods( swap move
    dup to r@ size dup to r@ bufsz here to r@ bufptr allot r> ;
    dup ( bufsz ) , dup to r@ size allot r> ;
]struct

extends File struct[ DriveFile


@@ 21,7 23,6 @@ extends File struct[ DriveFile
  : :secwin [compile] secwin [compile] SectorWindow ; immediate
  : :move dup :secwin :move 0 :seek ;
  : flush :secwin :flush ;
  : seek ( pos self -- ) to pos ;
  : readbuf ( n self -- a? read-n )
    over if
      swap >r bi+ pos | :secwin :seek ( self a? n ) r> min


@@ 30,10 31,8 @@ extends File struct[ DriveFile
  : writebuf ( a n self -- written-n )
    r! readbuf ( src dst? n ) dup if
      r! move r> r> :secwin :dirty! else nip rdrop then ;
  alias drop truncate
  : :new ( drv -- hdl )
    SectorWindow :new File :new >r S[ :[methods] ]S c@+ -move, ( secwin ) ,
    S[ IO :[methods] ]S c@+ r@ IO :methods( swap move
    -1 to r@ size r@ :secwin :buf( to r@ bufptr
    r@ :secwin :drv secsz to r@ bufsz 0 -1 r@ :secwin :move r> ;
    -1 to r@ size 0 -1 r@ :secwin :move r> ;
]struct

M fs/xcomp/bootlo.fs => fs/xcomp/bootlo.fs +3 -6
@@ 453,15 453,12 @@ struct[ Filesystem
extends IO struct[ File
  sfield pos
  sfield size
  sfield bufptr
  sfield bufsz
  smethod :seek     ( n hdl -- )
  smethod :truncate ( hdl -- )
  : :buf( bufptr ;
  : :)buf bi :buf( | bufsz + ;
  : :ptr bi+ pos | bufsz mod swap :buf( + ;
  : :new ( -- hdl )
    IO :new 0 ( pos ) , 0 ( size ) , 0 ( bufptr ) , 0 ( bufsz ) , 2 nabort, ;
    IO :new 0 ( pos ) , 0 ( size ) , 2 nabort, ;
  : seek ( pos hdl -- ) to pos ;
  alias drop truncate
  : :[methods] '" seek" , '" truncate" , ;
]struct


M posix/vm.c => posix/vm.c +1 -3
@@ 626,7 626,7 @@ reads into.
#define MAXPATHSZ 0x100
#define FSIDCNT 0x200
#define FILEPOSOFF 20
#define FILEDESCOFF 44
#define FILEDESCOFF 36
static char fsids[FSIDCNT][MAXPATHSZ] = {0};

static dword findpath(char *path) {


@@ 733,8 733,6 @@ static void FOPEN () {
	dwrite(find("_fclose")); // close
	dwrite(0); // pos
	dwrite(filesize);
	dwrite(0); // bufptr, not used
	dwrite(0); // bufsz, not used
	dwrite(find("_fseek")); // seek
	dwrite(find("abort")); // truncate
	dwrite(fd);