Not logged inTalkContributionsCreate accountLog in

Filesystem

From nexOS Wiki
ATA/IDE PIO and FAT32 — the old “no filesystem” note no longer applies

New in Phase 2. nexOS now reads a real disk via ATA PIO and parses FAT32. LS and CAT in the terminal and the File Manager list real directory entries. Former fake files (README.TXT / NOTES.TXT placeholders) are superseded.

Contents

[hide]

ATA driver (ata.c / ata.h)

Primary master, LBA28 PIO, polled (IRQ14 defined but not used). 33 lines of C plus inline helpers in the header.

PortUse
0x1F0Data (insw/outsw 256 words)
0x1F1–0x1F6Error, count, LBA lo/mid/hi, device (0xE0 | LBA>>24)
0x1F7Status/command (0x20 read, 0x30 write, 0xEC identify)
ata_read_sector(lba, buf):
  wait_ready(); outb(count=1, lba lo/mid/hi, device);
  outb(cmd=0x20); wait DRQ; insw(0x1F0, buf, 256);
ata_write_sector: same with 0x30 + outsw.
ata_probe(): select 0xA0 + IDENTIFY; returns 1 if status 0x00 (no disk).

FAT32 driver (fat32.c / fat32.h)

129 lines. BPB parsing with strict validation (fixes triple-fault/ATA hang bugs from early Phase 2):

fat32_init(fs, buf, lba_start):
  ata_read_sector_data(lba_start, buf);
  spc must be 1/2/4/8/16/32/64/128; nfats 1 or 2; sectors_per_fat != 0
  else zero the superblock (marks "NO DISK IMAGE").
  fat_start = reserved_count
  root_start = reserved + nfats * sectors_per_fat
  data_start = root_start + ... ; total_clusters = ...
FunctionPurpose
fat32_cluster_to_sectordata_start + (cluster-2)*spc
fat32_get_fat_entryRead 4-byte FAT entry via ATA
fat32_read_clusterRead spc sectors into buffer
fat32_list_dirIterate 256 entries, skip 0x00/0xE5, build 8.3 names, callback
fat32_read_fileFollow cluster chain to 0x0FFFFFF8, copy to buffer
fat32_get_clusterRoot-dir (cluster 2) lookup by name

Globals: g_fs, g_disk_buf[1 MiB], g_disk_init. Directory entries use packed fat32_dir_entry_t (8+3 name, attrib, cluster hi/lo, size).

Terminal integration

LS          -> fat32_list_dir(&g_fs, 2, term_ls_cb)  // "(EMPTY DIR)" or "READ ERR"
CAT FILE    -> fat32_read_file(&g_fs, name, file_buf, 4095); term_show_file()
            -> "NO DISK IMAGE" if superblock invalid; "NOT FOUND" if cluster 0

File Manager draws the same listing in a window (NAME/TYPE columns).

Limits and validation

  • Only root directory cluster 2 listing is used for LS; subdirectories report is_dir but are not traversed by CAT.
  • Long file names not supported (8.3 only).
  • Writes go through ata_write_sector but FAT32 allocator does not create files.
  • Bad BPB safely disables the FS instead of triple-faulting (regression fix).