aboutsummaryrefslogtreecommitdiffstats
path: root/include/gbos.inc
diff options
context:
space:
mode:
authoruser <user@clank>2026-07-16 12:20:57 +0200
committeruser <user@clank>2026-07-16 12:20:57 +0200
commit4f2d40ca35e0e39886dc881d06256fc25ba27a77 (patch)
tree368474d3d24a2480b45c0efd8ffe0b7ee018b879 /include/gbos.inc
parentfs rewrite stage 1: persistent block device (bounce buffer, cart SRAM) (diff)
downloadgbos-4f2d40ca35e0e39886dc881d06256fc25ba27a77.tar.gz
gbos-4f2d40ca35e0e39886dc881d06256fc25ba27a77.tar.xz
gbos-4f2d40ca35e0e39886dc881d06256fc25ba27a77.zip
fs rewrite stage 2: inodes + root directory (block-based, persistent)
- fs.asm: a real block filesystem on the persistent block device - superblock, block/inode bitmaps, a 32-entry inode table (type, size, 8 direct block pointers -> files up to 2 KiB), and a root directory of 16-byte entries. Metadata cached in WRAMX; one-block data cache streams file/dir blocks. - same syscall interface (open/getb/putb/list/remove) -> tools unchanged; ls now enumerates until flist() runs out (16 files, was hardcoded 8). - old 8-slot WRAM FS removed; cart RAM partitioned: process banks 0-7, disk 8-11. - two register-clobber bugs fixed: alloc_block/alloc_inode returned the bitmap-block number (write_bitmap clobbers C); db_use loaded the wrong block on a transition (db_flush->write_block clobbers C) -> multi-block files broke. - verified: 10+ files, multi-block (300-byte) files, delete, and persistence across reboots. Debug 'blk' disk tool retained (fill/peek). - README: document the block filesystem.
Diffstat (limited to '')
-rw-r--r--include/gbos.inc52
1 files changed, 41 insertions, 11 deletions
diff --git a/include/gbos.inc b/include/gbos.inc
index 3b96f56..770bd55 100644
--- a/include/gbos.inc
+++ b/include/gbos.inc
@@ -124,21 +124,51 @@ DEF SYS_MAX EQU 25
; (SYS_OPEN=4 / SYS_CLOSE=5 are now implemented by the filesystem)
; -----------------------------------------------------------------------------
-; RAM filesystem (lives in WRAMX $D000-$DFFF, 4 KiB; fixed in DMG mode).
-; 8 files x 512 bytes: name[8] (first byte 0 = free) + len[2] + data[502].
+; Block-based filesystem (on the persistent block device; see fs.asm).
+; block 0 superblock (magic + version)
+; block 1 bitmaps: block bitmap @0 (16 B), inode bitmap @16 (4 B)
+; blocks 2-3 inode table (32 inodes x 16 B)
+; blocks 4.. data blocks
+; Metadata (bitmaps + inode table) is cached in WRAMX; data/dir blocks stream
+; through fs_datbuf / fs_dirbuf.
; -----------------------------------------------------------------------------
-DEF FS_BASE EQU $D000
-DEF FS_MAX_FILES EQU 8
-DEF FS_FILE_SIZE EQU 512
-DEF FS_NAME EQU 0
-DEF FS_LEN EQU 8
-DEF FS_DATA EQU 10
-DEF FS_MAX_DATA EQU 502
+DEF BLK_SUPER EQU 0
+DEF BLK_BITMAP EQU 1
+DEF BLK_INODE0 EQU 2 ; inode table = blocks 2,3
+DEF BLK_DATA0 EQU 4 ; first data block
+DEF FS_VERSION EQU 2
+DEF NINODES EQU 32
+DEF ROOT_INO EQU 1
+DEF NDIRECT EQU 8 ; direct block pointers per inode -> files <= 2 KiB
+DEF DIRENTS EQU 16 ; directory entries per block (256/16)
-; open-file table (kernel WRAM0): inuse, slot, mode, pos(2)
+; inode fields (16 bytes)
+DEF I_TYPE EQU 0 ; 0=free 1=file 2=dir
+DEF I_NLINK EQU 1
+DEF I_SIZE EQU 2 ; 16-bit
+DEF I_BLOCKS EQU 4 ; 8 direct block pointers (1 byte each; 0=none)
+DEF IT_FREE EQU 0
+DEF IT_FILE EQU 1
+DEF IT_DIR EQU 2
+
+; directory entry (16 bytes): inode(1, 0=free) + name(15, NUL-term)
+DEF DE_INO EQU 0
+DEF DE_NAME EQU 1
+
+; bitmap offsets within block 1
+DEF BM_BLOCKS EQU 0
+DEF BM_INODES EQU 16
+
+; WRAMX working buffers (freed by removing the old 8-slot FS)
+DEF fs_bmbuf EQU $D000 ; 256 B: bitmap block cache (block 1)
+DEF fs_inobuf EQU $D100 ; 512 B: inode table cache (blocks 2-3)
+DEF fs_dirbuf EQU $D300 ; 256 B: directory block scratch
+DEF fs_datbuf EQU $D400 ; 256 B: data block cache
+
+; open-file table (kernel WRAM0): inuse, inode, mode, pos(2)
DEF OF_MAX EQU 4
DEF OF_INUSE EQU 0
-DEF OF_SLOT EQU 1
+DEF OF_INODE EQU 1
DEF OF_MODE EQU 2
DEF OF_POS EQU 3
DEF OF_SIZE EQU 5