WKern
|
Definitions and declarations for FAT16 filesystem and ATA I/O. More...
Go to the source code of this file.
Data Structures | |
struct | FaT16Bpb |
FAT16 BIOS Parameter Block (BPB) structure — describes volume layout. More... | |
struct | FaT16Info |
Parsed FAT16 filesystem layout and parameters. More... |
Macros | |
#define | ATA_IO_BASE 0x1F0 |
ATA IO Base port for primary IDE channel. | |
#define | ATA_CTRL 0x3F6 |
ATA Control port. | |
#define | ATA_STATUS (ATA_IO_BASE + 7) |
ATA Status port (read) | |
#define | ATA_COMMAND (ATA_IO_BASE + 7) |
ATA Command port (write) | |
#define | ATA_DRIVE (ATA_IO_BASE + 6) |
ATA Drive/head select port. | |
#define | ATA_ERROR (ATA_IO_BASE + 1) |
ATA Error register port (read) | |
#define | ATA_SECCNT (ATA_IO_BASE + 2) |
ATA Sector count register port. | |
#define | ATA_LBA_LOW (ATA_IO_BASE + 3) |
ATA LBA low byte port. | |
#define | ATA_LBA_MID (ATA_IO_BASE + 4) |
ATA LBA mid byte port. | |
#define | ATA_LBA_HI (ATA_IO_BASE + 5) |
ATA LBA high byte port. | |
#define | ATA_DATA (ATA_IO_BASE + 0) |
ATA Data port (read/write 16-bit) | |
#define | ATA_CMD_READ_SECTORS 0x20 |
ATA command to read sectors. | |
#define | ATA_SR_BSY 0x80 |
ATA status register BSY (busy) bit. | |
#define | ATA_SR_DRQ 0x08 |
ATA status register DRQ (data request) bit. | |
#define | ATA_SR_ERR 0x01 |
ATA status register ERR (error) bit. | |
#define | ATA_WRITE_CMD 0x30 |
ATA command to write sectors. |
Functions | |
void | AtaReadSector (u32 lba, u8 *buffer) |
Reads a 512-byte sector from ATA disk into buffer. | |
void | AtaWriteSector (u32 lba, const u8 *buffer) |
Writes a 512-byte sector to ATA disk from buffer. | |
u32 | FindFat16Partition (void) |
Finds the FAT16 partition on disk. | |
void | Writefile (const char *filename, const char *ext, const char *data, u32 size) |
Writes data to a FAT16 file, replacing its contents. | |
void | Fat16Ls (void) |
Lists files in the FAT16 root directory. | |
u32 | Fat16Mount (u32 partition_lba) |
Mounts FAT16 partition and reads filesystem info. | |
void | Fileconts (const char *filename, const char *ext) |
Prints contents of a FAT16 file. | |
void | Mkfile (const char *filename, const char *ext) |
Creates a new empty file in the FAT16 root directory. | |
void | Fat16RemoveFile (const char *filename, const char *ext) |
Removes a file from the FAT16 root directory and frees clusters. |
Variables | |
struct FaT16Info | fat16 |
Global FAT16 filesystem info struct. | |
volatile u8 | irq14stat |
IRQ status flags for IRQ14 and IRQ15 (primary and secondary IDE interrupts) | |
volatile u8 | irq15stat |
Definitions and declarations for FAT16 filesystem and ATA I/O.
Definition in file fileio.h.
#define ATA_CMD_READ_SECTORS 0x20 |
#define ATA_COMMAND (ATA_IO_BASE + 7) |
#define ATA_DATA (ATA_IO_BASE + 0) |
#define ATA_DRIVE (ATA_IO_BASE + 6) |
#define ATA_ERROR (ATA_IO_BASE + 1) |
#define ATA_IO_BASE 0x1F0 |
#define ATA_LBA_HI (ATA_IO_BASE + 5) |
#define ATA_LBA_LOW (ATA_IO_BASE + 3) |
#define ATA_LBA_MID (ATA_IO_BASE + 4) |
#define ATA_SECCNT (ATA_IO_BASE + 2) |
#define ATA_SR_DRQ 0x08 |
#define ATA_SR_ERR 0x01 |
#define ATA_STATUS (ATA_IO_BASE + 7) |
Reads a 512-byte sector from ATA disk into buffer.
lba | Logical block address of sector. |
buffer | Pointer to buffer to store sector data (must be >= 512 bytes). |
Reads a 512-byte sector from ATA disk into buffer.
Sends commands to the ATA device to read one sector specified by the logical block address (LBA). The read sector data is stored in the provided buffer.
lba | The logical block address of the sector to read. |
buffer | Pointer to a 512-byte buffer where the read data will be stored. |
Writes a 512-byte sector to ATA disk from buffer.
lba | Logical block address of sector. |
buffer | Pointer to buffer containing data to write (must be >= 512 bytes). |
Writes a 512-byte sector to ATA disk from buffer.
Sends commands to the ATA device to write one sector specified by the logical block address (LBA). The data to write is taken from the provided buffer.
lba | The logical block address of the sector to write. |
buffer | Pointer to a 512-byte buffer containing the data to write. |
void Fat16Ls | ( | void | ) |
Lists files in the FAT16 root directory.
Lists files in the FAT16 root directory.
Reads the root directory sectors of the FAT16 filesystem and prints the file names, their starting cluster numbers, and file sizes.
It handles:
Output format per file: File: [filename].[ext] | Cluster: [cluster] | Size: [size in bytes]
Mounts FAT16 partition and reads filesystem info.
partition_lba | LBA address of FAT16 partition start. |
Mounts FAT16 partition and reads filesystem info.
Reads the boot sector, validates the FAT16 signature, and initializes the FAT16 info struct with important filesystem layout details.
partition_lba | Logical block address of the FAT16 partition. |
Prints mount status and key filesystem layout info via Kprintf.
Definition at line 67 of file fat16_mnt.c.
void Fat16RemoveFile | ( | const char * | filename, |
const char * | ext ) |
Removes a file from the FAT16 root directory and frees clusters.
filename | File name (8 chars). |
ext | File extension (3 chars). |
Removes a file from the FAT16 root directory and frees clusters.
This function searches the FAT16 root directory for a file matching the specified filename and extension. If found, it marks the directory entry as deleted and frees all associated FAT clusters by clearing their entries in the FAT table.
filename | The 8-character filename (without extension). |
ext | The 3-character file extension. |
void Fileconts | ( | const char * | filename, |
const char * | ext ) |
Prints contents of a FAT16 file.
filename | Name of the file (8 chars). |
ext | File extension (3 chars). |
Prints contents of a FAT16 file.
This function searches the FAT16 root directory for a file matching the specified filename and extension. If found, it reads the first data cluster of the file and prints its contents as ASCII characters to the console. Non-printable characters are displayed as dots ('.'). The reading stops either at the end of the cluster or when a FAT16 EOF marker (0x1A) is found.
filename | The 8-character filename (without extension). |
ext | The 3-character file extension. |
Definition at line 40 of file printconts.c.
u32 FindFat16Partition | ( | void | ) |
Finds the FAT16 partition on disk.
Finds the FAT16 partition on disk.
Reads the MBR sector, verifies the signature, then scans all partitions for a FAT16 type (0x04 or 0x06).
Prints debug info about partitions to kernel log.
< Invalid MBR signature
< Return FAT16 partition start LBA
< No FAT16 partition found
void Mkfile | ( | const char * | filename, |
const char * | ext ) |
Creates a new empty file in the FAT16 root directory.
filename | File name (8 chars). |
ext | File extension (3 chars). |
Creates a new empty file in the FAT16 root directory.
This function searches for a free root directory entry and a free cluster, then creates a new directory entry for the specified filename and extension. It initializes the directory entry with default attributes and zero file size.
filename | The 8-character filename (without extension). |
ext | The 3-character file extension. |
void Writefile | ( | const char * | filename, |
const char * | ext, | ||
const char * | data, | ||
u32 | size ) |
Writes data to a FAT16 file, replacing its contents.
filename | 8.3 filename (name only). |
ext | File extension (3 chars). |
data | Pointer to data buffer to write. |
size | Size of data to write in bytes. |
Writes data to a FAT16 file, replacing its contents.
Searches for the file specified by filename and extension in the FAT16 root directory. If found, writes up to 512 bytes of data to the file's first cluster sector and updates the file size in the directory entry.
filename | The 8-character filename (without extension). |
ext | The 3-character file extension. |
data | Pointer to the data buffer to write. |
size | Number of bytes to write from the data buffer (max 512 bytes). |
|
extern |
Global FAT16 filesystem info struct.
Global FAT16 filesystem info struct.
Definition at line 25 of file fat16_mnt.c.
|
extern |
IRQ status flags for IRQ14 and IRQ15 (primary and secondary IDE interrupts)
Definition at line 22 of file irqflags.c.
|
extern |
Definition at line 23 of file irqflags.c.