continue working on implementing lib9660 into the kernel
This commit is contained in:
@@ -4,7 +4,7 @@ OBJS = bin/boot.o bin/kernel.o bin/idt.o bin/isr.o bin/screen.o \
|
|||||||
bin/keyboard.o bin/paging.o bin/page_alloc.o bin/page_tables.o \
|
bin/keyboard.o bin/paging.o bin/page_alloc.o bin/page_tables.o \
|
||||||
bin/fat.o bin/task.o bin/switch.o bin/sys_exit.o bin/gdt.o bin/isr-asm.o \
|
bin/fat.o bin/task.o bin/switch.o bin/sys_exit.o bin/gdt.o bin/isr-asm.o \
|
||||||
bin/kheap.o bin/liballoc.o bin/exec_from_file.o bin/syscalls.o bin/atapi.o \
|
bin/kheap.o bin/liballoc.o bin/exec_from_file.o bin/syscalls.o bin/atapi.o \
|
||||||
bin/lib9660.o
|
bin/lib9660.o bin/vfs.o
|
||||||
|
|
||||||
# Define the compiler and assembler
|
# Define the compiler and assembler
|
||||||
#CC = i686-elf-gcc -D__is_katauos
|
#CC = i686-elf-gcc -D__is_katauos
|
||||||
@@ -118,7 +118,7 @@ bin/page_alloc.o: src/mm/page_alloc.c
|
|||||||
bin/page_tables.o: src/mm/page_tables.c
|
bin/page_tables.o: src/mm/page_tables.c
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
bin/fat.o: src/drivers/fat.c
|
bin/fat.o: src/fs/fat.c
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
bin/switch.o: src/tasking/switch.asm
|
bin/switch.o: src/tasking/switch.asm
|
||||||
@@ -151,7 +151,10 @@ bin/syscalls.o: src/tasking/syscalls.c
|
|||||||
bin/atapi.o: src/drivers/atapi.c
|
bin/atapi.o: src/drivers/atapi.c
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
bin/lib9660.o: src/drivers/lib9660.c
|
bin/lib9660.o: src/fs/lib9660.c
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
bin/vfs.o: src/fs/vfs.c
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ typedef struct {
|
|||||||
} disk_info;
|
} disk_info;
|
||||||
|
|
||||||
void get_disk_info(disk_info *info);
|
void get_disk_info(disk_info *info);
|
||||||
int ide_check_disk_present();
|
|
||||||
bool ata_read(uint8_t *buffer, uint32_t lba);
|
bool ata_read(uint8_t *buffer, uint32_t lba);
|
||||||
bool ata_write(const uint8_t *buffer, uint32_t lba);
|
bool ata_write(const uint8_t *buffer, uint32_t lba);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "../include/fat.h"
|
|
||||||
#include "../include/elf.h"
|
#include "../include/elf.h"
|
||||||
#include "../include/stdio.h"
|
#include "../include/stdio.h"
|
||||||
|
#include "../include/vfs.h"
|
||||||
|
#include "../include/lib9660.h"
|
||||||
|
|
||||||
void exec_from_file(const char* filename, const char* dirname);
|
void exec_from_file(const char* filename, const char* dirname);
|
||||||
+3
-3
@@ -2,7 +2,7 @@
|
|||||||
#define TASK_H
|
#define TASK_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "../include/fat.h"
|
#include "../include/lib9660.h"
|
||||||
|
|
||||||
// Сегменты для ядра и пользователя
|
// Сегменты для ядра и пользователя
|
||||||
#define SEG_KCODE 0x08 // Сегмент кода ядра
|
#define SEG_KCODE 0x08 // Сегмент кода ядра
|
||||||
@@ -64,8 +64,8 @@ typedef struct Process
|
|||||||
uint32_t ring; // Уровень привилегий (0 или 3)
|
uint32_t ring; // Уровень привилегий (0 или 3)
|
||||||
struct Process* next; // Следующий процесс
|
struct Process* next; // Следующий процесс
|
||||||
|
|
||||||
file_t* file_descriptors[MAX_OPEN_FILES];
|
l9660_file* file_descriptors[MAX_OPEN_FILES];
|
||||||
dir_t* cwd;
|
l9660_dir* cwd;
|
||||||
|
|
||||||
void* brk;
|
void* brk;
|
||||||
} Process;
|
} Process;
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef VFS_H
|
||||||
|
#define VFS_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "../include/atapi.h"
|
||||||
|
#include "../include/lib9660.h"
|
||||||
|
|
||||||
|
extern l9660_fs global_fs;
|
||||||
|
|
||||||
|
bool read_sector_callback(l9660_fs *fs, void *buf, uint32_t sector);
|
||||||
|
void mount_fs();
|
||||||
|
void list_files(l9660_dir *dir);
|
||||||
|
|
||||||
|
size_t vfs_read_file(l9660_file *file, uint8_t* buffer);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
#include "../include/vfs.h"
|
||||||
|
#include "../include/stdio.h"
|
||||||
|
#include "../include/string.h"
|
||||||
|
|
||||||
|
l9660_fs global_fs;
|
||||||
|
|
||||||
|
bool read_sector_callback(l9660_fs *fs, void *buf, uint32_t sector) {
|
||||||
|
// The 'fs' parameter is not needed for our simple case, so we can ignore it.
|
||||||
|
(void)fs;
|
||||||
|
|
||||||
|
// Call your existing CD-ROM read function to read 1 sector.
|
||||||
|
// We assume the CD-ROM is the secondary master (0x170).
|
||||||
|
int result = read_cdrom(0x170, false, sector, 1, (uint16_t*)buf);
|
||||||
|
|
||||||
|
// lib9660 expects 'true' for success and 'false' for failure.
|
||||||
|
// Your read_cdrom returns 0 for success.
|
||||||
|
return (result == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mount_fs()
|
||||||
|
{
|
||||||
|
l9660_status status = l9660_openfs(&global_fs, read_sector_callback);
|
||||||
|
|
||||||
|
if (status != L9660_OK) {
|
||||||
|
printf("Error opening ISO9660 filesystem!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printf("FS mounted\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void list_files(l9660_dir *dir)
|
||||||
|
{
|
||||||
|
debug_log("----------CONTENTS----------");
|
||||||
|
l9660_status status;
|
||||||
|
for (;;) {
|
||||||
|
l9660_dirent *dent;
|
||||||
|
status = l9660_readdir(dir, &dent);
|
||||||
|
|
||||||
|
if (dent == NULL || status != L9660_OK) {
|
||||||
|
break; // End of directory or error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print the filename. It's not null-terminated, so use the length field.
|
||||||
|
for (int i = 0; i < dent->name_len; ++i) {
|
||||||
|
printf("%c", dent->name[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
size_t vfs_read_file(l9660_file *file, uint8_t* buffer)
|
||||||
|
{
|
||||||
|
size_t total_read = 0;
|
||||||
|
for(;;) {
|
||||||
|
char buf[128];
|
||||||
|
size_t read;
|
||||||
|
l9660_read(file, buf, 128, &read);
|
||||||
|
|
||||||
|
//check for EOF
|
||||||
|
if (read == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
memcpy(buffer, buf, 128);
|
||||||
|
buffer += 128;
|
||||||
|
total_read += read;
|
||||||
|
}
|
||||||
|
|
||||||
|
//reset the current position to the original position
|
||||||
|
buffer -= total_read;
|
||||||
|
return total_read;
|
||||||
|
}
|
||||||
+17
-28
@@ -15,6 +15,7 @@
|
|||||||
#include "../include/exec_from_file.h"
|
#include "../include/exec_from_file.h"
|
||||||
#include "../include/atapi.h"
|
#include "../include/atapi.h"
|
||||||
#include "../include/lib9660.h"
|
#include "../include/lib9660.h"
|
||||||
|
#include "../include/vfs.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@@ -25,34 +26,14 @@ void apply_pic_masks()
|
|||||||
outb(0xa1,0xff);
|
outb(0xa1,0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static l9660_fs g_iso_fs;
|
|
||||||
static l9660_dir g_root_dir;
|
|
||||||
static l9660_file g_test_file;
|
|
||||||
|
|
||||||
bool read_sector_callback(l9660_fs *fs, void *buf, uint32_t sector) {
|
|
||||||
// The 'fs' parameter is not needed for our simple case, so we can ignore it.
|
|
||||||
(void)fs;
|
|
||||||
|
|
||||||
// Call your existing CD-ROM read function to read 1 sector.
|
|
||||||
// We assume the CD-ROM is the secondary master (0x170).
|
|
||||||
int result = read_cdrom(0x170, false, sector, 1, (uint16_t*)buf);
|
|
||||||
|
|
||||||
// lib9660 expects 'true' for success and 'false' for failure.
|
|
||||||
// Your read_cdrom returns 0 for success.
|
|
||||||
return (result == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_iso9660()
|
void test_iso9660()
|
||||||
{
|
{
|
||||||
l9660_status status = l9660_openfs(&g_iso_fs, read_sector_callback);
|
l9660_dir g_root_dir;
|
||||||
|
l9660_file g_test_file;
|
||||||
if (status != L9660_OK) {
|
|
||||||
printf("Error opening ISO9660 filesystem!\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
l9660_status status;
|
||||||
// 2. Open the root directory
|
// 2. Open the root directory
|
||||||
status = l9660_fs_open_root(&g_root_dir, &g_iso_fs);
|
status = l9660_fs_open_root(&g_root_dir, &global_fs);
|
||||||
if (status != L9660_OK) {
|
if (status != L9660_OK) {
|
||||||
printf("Error opening root directory!\n");
|
printf("Error opening root directory!\n");
|
||||||
return;
|
return;
|
||||||
@@ -77,10 +58,16 @@ void test_iso9660()
|
|||||||
printf("\nReading content of /TEST.TXT:\n");
|
printf("\nReading content of /TEST.TXT:\n");
|
||||||
|
|
||||||
// Re-open the root directory to reset its position before searching
|
// Re-open the root directory to reset its position before searching
|
||||||
l9660_fs_open_root(&g_root_dir, &g_iso_fs);
|
l9660_fs_open_root(&g_root_dir, &global_fs);
|
||||||
|
|
||||||
// Note: ISO9660 filenames are often uppercase.
|
l9660_dir boot_dir;
|
||||||
status = l9660_openat(&g_test_file, &g_root_dir, "test.txt;1");
|
l9660_dir grub_dir;
|
||||||
|
status = l9660_opendirat(&boot_dir, &g_root_dir, "boot");
|
||||||
|
printf("STATUS %X\n", status);
|
||||||
|
status = l9660_opendirat(&grub_dir, &boot_dir, "grub");
|
||||||
|
printf("STATUS %X\n", status);
|
||||||
|
|
||||||
|
status = l9660_openat(&g_test_file, &grub_dir, "grub.cfg");
|
||||||
|
|
||||||
if (status != L9660_OK) {
|
if (status != L9660_OK) {
|
||||||
printf("Error opening TEST.TXT;1. Error code: ");
|
printf("Error opening TEST.TXT;1. Error code: ");
|
||||||
@@ -197,9 +184,11 @@ void kmain(unsigned int magic, unsigned int info)
|
|||||||
printf("huy1 points to: 0x%X huy2 points to:0x%X\n", huy, huy2);
|
printf("huy1 points to: 0x%X huy2 points to:0x%X\n", huy, huy2);
|
||||||
printf("huy1: %s\nhuy2: %s", huy, huy2);
|
printf("huy1: %s\nhuy2: %s", huy, huy2);
|
||||||
|
|
||||||
|
mount_fs();
|
||||||
|
|
||||||
test_iso9660();
|
test_iso9660();
|
||||||
|
|
||||||
//exec_from_file("/ebalo/main", "/ebalo/");
|
exec_from_file("main.", ".");
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,46 +12,64 @@
|
|||||||
#define USER_STACK_SIZE 0x4000 // 16KB stack (4 pages)
|
#define USER_STACK_SIZE 0x4000 // 16KB stack (4 pages)
|
||||||
#define USER_STACK_BOTTOM (USER_STACK_TOP - USER_STACK_SIZE)
|
#define USER_STACK_BOTTOM (USER_STACK_TOP - USER_STACK_SIZE)
|
||||||
|
|
||||||
disk_ops_t ops1 =
|
int read_file(const char* path, uint8_t** buffer, l9660_dir* dir)
|
||||||
{
|
{
|
||||||
.read = ata_read,
|
//file_t file;
|
||||||
.write = ata_write,
|
l9660_file file;
|
||||||
};
|
|
||||||
|
|
||||||
static fat_t g_fat;
|
l9660_status err;
|
||||||
|
|
||||||
int read_file(const char* path, uint8_t** buffer, dir_t* dir)
|
err = l9660_openat(&file, dir, path);//fat_fopen(&file, path, "r");
|
||||||
{
|
if (err != L9660_OK)
|
||||||
file_t file;
|
{
|
||||||
int err = fat_fopen(&file, path, "r");
|
debug_log("read_file: err: 0x%X\n", err);
|
||||||
if (err)
|
|
||||||
return err;
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t file_size = fat_fsize(&file);
|
l9660_seek(&file, L9660_SEEK_END, 0);
|
||||||
|
uint32_t file_size = l9660_tell(&file);//fat_fsize(&file);
|
||||||
debug_log("file_size: %X\n", file_size);
|
debug_log("file_size: %X\n", file_size);
|
||||||
|
l9660_seek(&file, L9660_SEEK_SET, 0);
|
||||||
|
|
||||||
uint8_t buf[512];
|
uint8_t buf[512];
|
||||||
debug_log("heh\n");
|
debug_log("heh\n");
|
||||||
|
|
||||||
*buffer = (uint8_t*)malloc(file_size);
|
*buffer = (uint8_t*)malloc(file_size+1);
|
||||||
uint8_t* current = *buffer;
|
uint8_t* current = *buffer;
|
||||||
debug_log("eeee\n");
|
debug_log("eeee\n");
|
||||||
|
|
||||||
int cnt = fat_fread(&file, *buffer, file_size);
|
size_t read;
|
||||||
|
|
||||||
*dir = file.dir;
|
debug_log("info: buffer: %X, *buffer: %X, &buffer: %X\n", buffer, *buffer, &buffer);
|
||||||
|
|
||||||
return fat_fclose(&file);
|
//err = l9660_read(&file, *buffer, file_size, &read);//fat_fread(&file, *buffer, file_size);
|
||||||
|
read = vfs_read_file(&file, *buffer);
|
||||||
|
debug_log("bytes read: 0x%X\n", read);
|
||||||
|
|
||||||
|
while(1){}
|
||||||
|
|
||||||
|
return 0;//fat_fclose(&file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void exec_from_file(const char* filename, const char* dirname)
|
void exec_from_file(const char* filename, const char* dirname)
|
||||||
{
|
{
|
||||||
asm volatile("cli");
|
asm volatile("cli");
|
||||||
int err, cnt;
|
int err, cnt;
|
||||||
err = fat_mount(&ops1, 0, &g_fat, "ebalo");
|
//err = fat_mount(&ops1, 0, &g_fat, "ebalo");
|
||||||
|
|
||||||
uint8_t* file;
|
uint8_t* file;
|
||||||
dir_t dir;
|
//dir_t dir;
|
||||||
|
l9660_dir dir;
|
||||||
|
l9660_dir root_dir;
|
||||||
|
l9660_status status;
|
||||||
|
|
||||||
|
status = l9660_fs_open_root(&root_dir, &global_fs);
|
||||||
|
debug_log("l9660_fs_open_root status: 0x%X\n", status);
|
||||||
|
|
||||||
|
status = l9660_opendirat(&dir, &root_dir, dirname);
|
||||||
|
debug_log("l9660_opendirat status: 0x%X\n", status);
|
||||||
|
|
||||||
|
list_files(&dir);
|
||||||
|
|
||||||
uint32_t bss_start, bss_end;
|
uint32_t bss_start, bss_end;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user