PO2013 - Last sector allocated
Hi, It has sounded here earlier, it might be sometimes useful, to know last sector used by OBERON.FS. Could this hint where the sector lies? PROCEDURE LastSec(name: FileDir.FileName; sec : INTEGER; VAR cont: BOOLEAN); BEGIN IF sec > lsec THEN lsec := sec END ; cont := TRUE END LastSec; PROCEDURE Last*; BEGIN lsec := 0; FileDir.Enumerate("", LastSec); Texts.WriteInt(W, lsec, 6); Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf) END Last; -- Tomas Kral <thomas.kral@email.cz>
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
Hello Paul, Hello Tomas, Am 26.06.2020 um 10:06 schrieb Paul Reed:
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).
I think you can optimize this and stop as soon as you found Kernel.Nofsectors sectors that are already allocated. Regards, Michael PS: I decided to export the last used sector from Kernel.Mod instead, but that obviously does not work if you do not want to change the kernel.
On Fri, 26 Jun 2020 11:31:49 +0200 Michael Schierl <schierlm@gmx.de> wrote:
I decided to export the last used sector from Kernel.Mod instead, but that obviously does not work if you do not want to change the kernel.
Hey, isn't this simple while not much simpler? -- Tomas Kral <thomas.kral@email.cz>
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@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@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Hi Joerg,
Paul‘s method is the only „official“ method to do so. A dirty and a very dirty alternative...
Well if we're doing dirty... :) Perhaps a reasonable general assumption under maintenance of Kernel's code might be to ensure the map is always the last variable in Kernel, and search down from one bit before the value of the code member of Kernel's module descriptor. (This is assuming you want to keep the symbol files the same as the reference system, I prefer to. Otherwise you can do better obviously, as Michael says.) Dirty: i := 10C1FH; WHILE ~SYSTEM.BIT(i DIV 32 * 4, i) DO DEC(i) END; Texts.WriteString(W, "used = "); Texts.WriteInt(W, i-0C20H, 1); Texts.Write(W, "K"); EndLine; a bit better (no pun intended) M := Modules.root; WHILE M.next # NIL DO M := M.next END; i := M.code*8-1; WHILE ...; Texts.WriteInt(W, i-(M.code*8-65536), 1); ... Or something. Anyway, moving on... :) Cheers, Paul
participants (4)
-
Joerg -
Michael Schierl -
Paul Reed -
Tomas Kral