[Oberon] PO2013 - Last sector allocated

Joerg joerg.straube at iaeth.ch
Fri Jun 26 11:37:32 CEST 2020


Tomas

Paul‘s method is the only „official“ method to do so. A dirty and a very dirty alternative are:

IMPORT SYSTEM, Kernel;

PROCEDURE LastSectorDirty(): INTEGER;
 CONST nbrOfWord = 10000H DIV 32;
 TYPE
   SecMap = RECORD
     map: ARRAY nbrOfWord OF SET
   END;
   P = POINTER TO SecMap;
 VAR p: P; i, j: INTEGER; s: SET;
 BEGIN
   p := SYSTEM.VAL(P,
     SYSTEM.ADR(Kernel.MemLim)+28);
   i := nbrOfWord;
   REPEAT DEC(i); s := p.map[i] UNTIL s # {};
   j := 32;
   REPEAT DEC(j) UNTIL j IN s
 RETURN (i*32 + j) * 29
 END LastSectorDirty;

PROCEDURE LastSectorVeryDirty(): INTEGER;
 CONST nbrOfByte = 10000H DIV 8;
 VAR map, p, j: INTEGER; s: SET;
 BEGIN
   map := SYSTEM.ADR(Kernel.MemLim)+28);
   p := map + nbrOfByte;
   REPEAT
     DEC(p, 4); SYSTEM.GET(p, s)
   UNTIL s # {};
   j := 32;
   REPEAT DEC(j) UNTIL j IN s
 RETURN ((p-map)*8 + j) * 29
 END LastSectorVeryDirty;

br
Jörg

> Am 26.06.2020 um 11:09 schrieb Paul Reed <paulreed at paddedcell.com>:
> 
> Hi Tomas,
> 
>> Could this hint where the sector lies?
> ...     FileDir.Enumerate("", LastSec); Texts.WriteInt(W, lsec, 6);
> 
> No.
> 
> This will only tell you where the first sector of each file is.
> 
> Please study FileDir.Mod, in particular FileDir.Init to see how the system builds a list of allocated sectors at startup, if you really want to do it this way.
> 
> I have already suggested an easier way is to use the hint in Kernel.AllocSector: allocate the next free sector after the hint, then free it, and keep incrementing the hint until the sector allocated is before the hint (ie it's wrapped).  See Kernel.AllocSector and Kernel.FreeSector.  This has the advantage of being purely in memory, it doesn't hit the disk at all.
> 
> Cheers,
> Paul
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon



More information about the Oberon mailing list