41void Writefile(
const char *filename,
const char *ext,
const char *data,
44 u32 entries_per_sector =
fat16.bytes_per_sector / 32;
45 u32 root_dir_sectors =
46 ((
fat16.root_entry_count * 32) + (
fat16.bytes_per_sector - 1)) /
47 fat16.bytes_per_sector;
51 for (
u32 i = 0; i < root_dir_sectors; i++) {
54 for (
u32 j = 0; j < entries_per_sector; j++) {
59 Padname(filename, name_pad, 8);
60 Padname(ext, ext_pad, 3);
62 if (entry[0] != 0x00 && entry[0] != 0xE5 &&
63 Kmemcmp(entry + 0x00, name_pad, 8) == 0 &&
64 Kmemcmp(entry + 0x08, ext_pad, 3) == 0) {
65 u16 clust = entry[0x1A] | (entry[0x1B] << 8);
72 u32 data_sector =
fat16.data_start_lba +
73 ((clust - 2) *
fat16.sectors_per_cluster);
75 u8 writebuf[512] = {0};
82 entry[0x1C] = size & 0xFF;
83 entry[0x1D] = (size >> 8) & 0xFF;
84 entry[0x1E] = (size >> 16) & 0xFF;
85 entry[0x1F] = (size >> 24) & 0xFF;
void AtaWriteSector(u32 lba, const u8 *buffer)
Write a single 512-byte sector to the ATA device using LBA addressing.
void AtaReadSector(u32 lba, u8 *buffer)
Read a single 512-byte sector from the ATA device using LBA addressing.
u8 sector[SECTOR_SIZE]
Buffer for reading sectors.
struct FaT16Info fat16
Holds FAT16 filesystem info and a sector buffer.
Definitions and declarations for FAT16 filesystem and ATA I/O.
void Kprintf(const char *fmt,...)
Formatted output to the screen.
int Kmemcmp(const void *a, const void *b, size_t n)
Compare memory.
void * Kmemcpy(void *dest, const void *src, unsigned int count)
Copy memory.
unsigned int u32
32-Bit Unsigned Int
unsigned short u16
16-Bit Unsigned Int
unsigned char u8
8-Bit Unsigned Int
void Writefile(const char *filename, const char *ext, const char *data, u32 size)
Write data to an existing file in the FAT16 filesystem.