duskos

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

drivelo.fs (1004B) - raw


      1 struct[ SectorWindow
      2   sfield drv
      3   sfield fsec
      4   sfield cnt
      5   sfield sec
      6   sfield dirty
      7   SZ &+ :buf(
      8   : :drv [compile] drv [compile] Drive ; immediate
      9   : :)buf bi :buf( | drv Drive secsz + ;
     10   : :dirty! 1 swap to dirty ;
     11   : :flush ( self -- )
     12     0 over to@! dirty if tri sec | :buf( | :drv :sec! else drop then ;
     13   : :load ( sec self -- )
     14     2dup sec <> if
     15       2dup tuck fsec - swap cnt >= if abort" secwin oor" then ( sec self )
     16       dup :flush 2dup to sec tuck :buf( rot :drv :sec@ else 2drop then ;
     17   : :move ( fsec cnt self -- ) swap 1 max over to cnt to fsec ;
     18   : :fulldrv ( self -- ) 0 over :drv seccnt rot :move ;
     19   : :seek ( pos self -- a? n-or-0 )
     20     r! :drv secsz /mod ( off relsec ) \ V1=self
     21     dup r@ cnt < if ( off relsec )
     22       r@ fsec + r@ :load ( off )
     23       bi r@ :buf( + | r> :drv secsz -^ ( a n )
     24     else rdrop 2drop 0 then ;
     25   : :next bi+ sec 1+ | :drv secsz * swap :seek ;
     26   : :new ( drv -- secwin )
     27     here# >r dup , 0 , 1 , -1 , 0 , Drive secsz allot r> ;
     28 ]struct