Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified drivers/Ide.c
Binary file not shown.
10 changes: 6 additions & 4 deletions drivers/Ide.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define IDE_CMD_WRITE_SECTORS 0x30
#define IDE_CMD_IDENTIFY 0xEC
#define IDE_CMD_PACKET 0xA0
#define IDE_CMD_IDENTIFY_PACKET 0xA1
#define ATAPI_CMD_READ_10 0x28


Expand All @@ -42,10 +43,10 @@

// Error Codes
#define IDE_OK 0
#define IDE_ERROR_TIMEOUT -1
#define IDE_ERROR_NOT_READY -2
#define IDE_ERROR_NO_DRIVE -3
#define IDE_ERROR_IO -4
#define IDE_ERROR_TIMEOUT (-1)
#define IDE_ERROR_NOT_READY (-2)
#define IDE_ERROR_NO_DRIVE (-3)
#define IDE_ERROR_IO (-4)

typedef struct {
uint16_t base_port;
Expand All @@ -57,6 +58,7 @@ typedef struct {

// Core Functions
int IdeInit(void);
int IdeIsInitialized(void);
int IdeReadSector(uint8_t drive, uint32_t lba, void* buffer);
int IdeWriteSector(uint8_t drive, uint32_t lba, const uint8_t* buffer);
int IdeGetDriveInfo(uint8_t drive, char* model_out);
Expand Down
43 changes: 32 additions & 11 deletions fs/Iso9660.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@

static uint8_t cdrom_drive = 0xFF;

static inline char toupper_iso(char c) {
if (c >= 'a' && c <= 'z') return (char)(c - 'a' + 'A');
return c;
}

// Compare ISO names case-insensitively and ignore version suffix ";n"
static int IsoNameEquals(const char* a, const char* b) {
// Skip leading spaces in ISO entries if any
while (*a == ' ') a++;
while (*b == ' ') b++;

for (;;) {
char ca = *a;
char cb = *b;
if (ca == ';') ca = '\0';
if (cb == ';') cb = '\0';
ca = toupper_iso(ca);
cb = toupper_iso(cb);
if (ca != cb) return 0;
if (ca == '\0') return 1;
a++; b++;
}
}

static int ReadSector(uint32_t lba, void* buffer) {
if (cdrom_drive == 0xFF) {
PrintKernel("[ISO] Auto-detecting CD-ROM drive...\n");
Expand Down Expand Up @@ -78,7 +102,7 @@ static Iso9660DirEntry* FindFileInDir(uint32_t dir_lba, uint32_t dir_size, const
*semicolon = 0;
}

if (FastStrCmp(entry_filename, filename) == 0) {
if (IsoNameEquals(entry_filename, filename)) {
// Found it! We need to copy the entry to a new buffer, as the sector_buffer will be freed.
Iso9660DirEntry* result = KernelMemoryAlloc(entry->length);
if (result) {
Expand Down Expand Up @@ -241,15 +265,14 @@ int Iso9660Read(const char* path, void* buffer, uint32_t max_size) {
const uint32_t to_read = (file_size < max_size) ? file_size : max_size;
uint8_t* read_buffer = (uint8_t*)buffer;
uint32_t bytes_read = 0;
uint8_t* temp_sector = KernelMemoryAlloc(ISO9660_SECTOR_SIZE);
if (!temp_sector) {
if (current_entry != root_entry) KernelFree(current_entry);
KernelFree(pvd);
return -1;
}
while (bytes_read < to_read) {
uint32_t sector_to_read = file_lba + (bytes_read / ISO9660_SECTOR_SIZE);
uint8_t* temp_sector = KernelMemoryAlloc(ISO9660_SECTOR_SIZE);
if (!temp_sector) {
if (current_entry != root_entry) KernelFree(current_entry);
KernelFree(pvd);
return -1;
}

if (ReadSector(sector_to_read, temp_sector) != 0) {
KernelFree(temp_sector);
if (current_entry != root_entry) KernelFree(current_entry);
Expand All @@ -264,8 +287,8 @@ int Iso9660Read(const char* path, void* buffer, uint32_t max_size) {

FastMemcpy(read_buffer + bytes_read, temp_sector + offset_in_sector, chunk_size);
bytes_read += chunk_size;
KernelFree(temp_sector);
}
KernelFree(temp_sector);

if (current_entry != root_entry) {
KernelFree(current_entry);
Expand Down Expand Up @@ -447,8 +470,6 @@ int Iso9660CopyFile(const char* iso_path, const char* vfs_path) {
return 0; // Success
}



int Iso9660Copy(const char* iso_path, const char* vfs_path) {
Iso9660DirEntry** entries = Iso9660ListDir(iso_path);
if (!entries) {
Expand Down
2 changes: 1 addition & 1 deletion fs/VFRFS.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ int FsListDir(const char* path) {

FsNode* child = dir_node->children;
if (!child) {
PrintKernel("(empty directory)\n");
PrintKernel("\n");
return 0;
}

Expand Down
21 changes: 1 addition & 20 deletions kernel/etc/POST.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool MemoryTest() {
if (!ptr) return false;
KernelFree(ptr);
}
//

for (int i = 0; i < N; i++) ptrs[i] = KernelMemoryAlloc(128);

// free every other block
Expand All @@ -38,25 +38,6 @@ bool MemoryTest() {
ptrs[i] = KernelMemoryAlloc((i % 2) ? 64 : 256);
}

for (int iter = 0; iter < 100000; iter++) {
int idx = rnd() % N;
if (ptrs[idx]) {
KernelFree(ptrs[idx]);
ptrs[idx] = NULL;
} else {
size_t sz = (rnd() % 8192) + 1; // 1–8K
ptrs[idx] = KernelMemoryAlloc(sz);
if (!ptrs[idx]) PANIC("OOM during fuzz");
}
}

for (uintptr_t addr = 0x400000; addr < 0x800000; addr += 0x1000) {
void* frame = AllocPage();
VMemMap(addr, (uint64_t)frame, PAGE_PRESENT | PAGE_WRITABLE);
VMemUnmap(addr, PAGE_SIZE);
FreePage(frame);
}

for (int i = 0; i < 1000; i++) {
size_t sz = (i % 500) + 1;
uint8_t *p = (uint8_t*)KernelMemoryAlloc(sz);
Expand Down
4 changes: 2 additions & 2 deletions kernel/etc/Shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -1220,11 +1220,11 @@ void ExecuteCommand(const char* cmd) {
};
const uint32_t pid = LoadExecutable(full, &opts);
if (pid != 0) {
PrintKernelSuccess("ELF Executable loaded (PID: ");
PrintKernelSuccess("Executable loaded (PID: ");
PrintKernelInt(pid);
PrintKernel(")\n");
} else {
PrintKernelError("Failed to load ELF executable\n");
PrintKernelError("Failed to load executable\n");
}
KernelFree(cmd_name);
return; // avoid also running a built-in with the same name
Expand Down
Loading