// disk_io.c

#include "disk_io.h"
#include "print.h"  // Assuming you have a function for kernel printing

#define SECTOR_SIZE 512

// Function to read sectors from disk
int disk_read(uint32_t lba, void *buffer, uint32_t size) {
    // lba: logical block address
    // buffer: where to store the read data
    // size: number of bytes to read

    if (size % SECTOR_SIZE != 0) {
        printf("Read size must be a multiple of 512 bytes\n");
        return -1;
    }

    for (uint32_t i = 0; i < size / SECTOR_SIZE; i++) {
        // Placeholder for actual disk sector read. Replace with proper implementation
        if (!bios_read_sector(lba + i, buffer + (i * SECTOR_SIZE))) {
            printf("Error reading sector from disk\n");
            return -1;
        }
    }

    return 0;
}

// Placeholder function to simulate reading sectors from the disk
// Replace this with actual disk reading logic depending on the platform
int bios_read_sector(uint32_t lba, void *buffer) {
    // Simulate disk sector read
    // In an actual kernel, you'd use interrupts or other mechanisms to read from disk

    // For now, just zero out the buffer to simulate
    for (int i = 0; i < SECTOR_SIZE; i++) {
        ((uint8_t*)buffer)[i] = 0;  // Fill buffer with zeros
    }

    return 1;  // Success
}

