File Write Testing

Testing persistent storage and file operations

Overview

guideXOS includes full file writing capabilities through its FAT filesystem implementation and IDE/SATA disk drivers. This guide covers testing file write operations to persistent storage devices.

? File Writing Works!

guideXOS already has complete file writing support for IDE/SATA disks with FAT12/16/32 filesystems. No TAR write support (TAR is read-only by design), but FAT volumes fully support read/write operations.


Current Capabilities

? Working Features

Component Status Notes
FAT12/16/32 ? Full Support Read, write, create, delete files
IDE/SATA Drivers ? Full Support Read and write operations
Long Filenames ? Full Support LFN (Long File Name) support
Sector Caching ? Full Support Performance optimization
USB Mass Storage ?? Read-Only Write support not yet enabled
TAR Archives ? Read-Only By design (archive format)
Low-Level Format ? Not Yet Use external tools to format

Quick Start Guide

Follow these steps to test file writing in 5 minutes:

Step 1: Create Test Disk

On Linux or macOS:

# Create 100MB disk image
dd if=/dev/zero of=test.img bs=1M count=100

# Format as FAT32
mkfs.vfat -F 32 test.img

On Windows (PowerShell as Admin):

# Use VirtualBox or VMware to create virtual disk
# Then format from Windows Explorer as FAT32

Step 2: Attach to VM

  • VMware: Add as IDE hard disk
  • VirtualBox: Add as SATA controller
  • QEMU: Use -hda test.img

Step 3: Boot & Test

  1. Boot guideXOS
  2. Open File Write Test from Start Menu ? All Programs
  3. Select your disk (e.g., IDE0)
  4. Click "FAT Filesystem" button
  5. Watch for green [OK] messages

Expected Output

[TEST] FAT Filesystem Test on IDE0 (100MB)
--------------------------------------
Initializing FAT filesystem...
  [OK] FAT filesystem initialized

Testing file write operations...
  Writing test file: /guidexos_test.txt
  [OK] File written successfully
  Reading back test file...
  [OK] File read successfully
  Verifying file content...
  [OK] Content verification successful!

Listing root directory...
  Found 1 entries:
    [FILE] guidexos_test.txt

Deleting test file...
  [OK] Test file deleted

[RESULT] FAT filesystem test PASSED

Detailed VM Setup

VirtualBox Configuration

  1. Open VM Settings ? Storage
  2. Add SATA or IDE controller if not present
  3. Click "Add Hard Disk" ? Create new VDI
  4. Set size to 100MB (sufficient for testing)
  5. Boot a live Linux CD or use Windows to format as FAT32
  6. Attach formatted disk and boot guideXOS

QEMU Command Line

qemu-system-x86_64 \
  -cdrom guidexos.iso \
  -hda test.img \
  -m 2G \
  -vga std

VMware Configuration

  1. VM Settings ? Add ? Hard Disk
  2. Choose IDE or SATA
  3. Create new virtual disk
  4. Set size to 100MB
  5. Use Windows or Linux to format as FAT32
  6. Boot guideXOS
?? Important:

Always use dedicated test disks! File write operations modify disk contents. Backup important data before testing on real hardware.


File Write Test Application

The built-in File Write Test application provides comprehensive testing capabilities:

Features

  • Automatic Disk Detection - Finds all IDE/SATA disks
  • Raw Sector Testing - Low-level read/write verification
  • FAT Filesystem Testing - File creation, read, verify, delete
  • Safe Testing - Restores original data after tests
  • Color-Coded Logs - Easy to spot issues
  • Format Information - Shows formatting options

Test Modes

1. Raw Sector R/W Test

Tests low-level disk I/O operations:

  • Reads sector 2048 (safe area after boot sectors)
  • Writes test pattern
  • Verifies data matches
  • Restores original data
2. FAT Filesystem Test

Tests complete file operations:

  • Initializes FAT filesystem
  • Creates test file /guidexos_test.txt
  • Writes "Hello from guideXOS!" content
  • Reads back and verifies
  • Lists directory contents
  • Deletes test file
3. Format Options

Displays information about formatting disks:

  • FAT12 - For disks < 16MB
  • FAT16 - For disks 16MB - 2GB
  • FAT32 - For disks > 2GB

Troubleshooting

No Disks Found

Problem: Application shows "No disks found"

Solutions:

  • Check VM settings - disk must be attached as IDE or SATA
  • Use primary IDE controller (not secondary)
  • Check console output at boot for IDE detection messages
  • Try different VM software (QEMU vs VMware vs VirtualBox)

FAT Initialization Failed

Problem: "Could not initialize FAT filesystem"

Solutions:

  • Disk must be pre-formatted as FAT12/16/32
  • Use mkfs.vfat -F 32 disk.img on Linux
  • Use Windows Format tool (select FAT32)
  • Check disk isn't corrupted
  • Verify boot sector is valid

Write Failed

Problem: "Could not write sector" or "Could not write file"

Solutions:

  • Check disk isn't write-protected
  • Verify disk has free space
  • Try raw sector test first to isolate issue
  • Check for disk errors in VM logs
  • Increase VM disk size if needed

USB Drive Read-Only

Problem: USB drives show as read-only

Solutions:

  • This is expected - USB write support not yet implemented
  • Use IDE/SATA disks for write testing
  • USB write support planned for future release

Advanced Topics

Manual File Operations

You can also test file writing using the console:

# Switch filesystem to IDE disk
gx> mount /dev/ide0

# Create a test file
gx> echo "Hello World" > /test.txt

# Read it back
gx> cat /test.txt

# List files
gx> ls -l /

# Delete file
gx> rm /test.txt

Programmatic File Writing

Example C# code for file operations:

// Switch to IDE disk
Disk.Instance = IDE.Ports[0];

// Initialize FAT filesystem
var fat = new FAT();
File.Instance = fat;

// Write a file
string content = "Hello from guideXOS!";
byte[] data = new byte[content.Length];
for (int i = 0; i < content.Length; i++) {
    data[i] = (byte)content[i];
}
fat.WriteAllBytes("/myfile.txt", data);

// Read back
byte[] readData = fat.ReadAllBytes("/myfile.txt");

// Verify
bool ok = true;
for (int i = 0; i < data.Length; i++) {
    if (readData[i] != data[i]) {
        ok = false;
        break;
    }
}

Console.WriteLine(ok ? "Success!" : "Failed!");

Raw Sector Writing

Low-level disk access example:

// Get IDE disk
var disk = IDE.Ports[0];

// Prepare 512-byte sector
byte[] buffer = new byte[512];
for (int i = 0; i < 512; i++) {
    buffer[i] = (byte)(i % 256);
}

// Write to sector 2048 (safe area)
ulong sector = 2048;
unsafe {
    fixed (byte* p = buffer) {
        bool success = disk.Write(sector, 1, p);
        Console.WriteLine(success ? "Write OK" : "Write Failed");
    }
}

Testing on Real Hardware

Requirements:

  • x86/x64 PC with legacy BIOS or CSM mode enabled
  • IDE or SATA hard drive (dedicated test disk recommended)
  • At least 512MB RAM (2GB recommended)

Steps:

  1. Burn guideXOS.iso to CD/DVD or create bootable USB
  2. Attach test disk with FAT partition
  3. Boot from CD/USB
  4. Use File Write Test application as normal
?? WARNING:

File write operations modify disk contents. Always use dedicated test hardware! Never test on disks containing important data without complete backups.

Future Enhancements

Planned features:

  • USB Write Support - Enable writing to USB mass storage devices
  • Low-Level Formatting - Implement FAT.Format() method
  • Partition Management - Create/delete partitions programmatically
  • NTFS Support - Read and write NTFS filesystems
  • ext2/3/4 Support - Linux filesystem compatibility
  • Journaling - Crash recovery for interrupted writes
  • Write Caching - Performance optimization

Related Topics