Skip to content

Commit

Permalink
修复IDE设备无法挂载问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyi1212 committed Dec 8, 2024
1 parent d4f0aae commit 745464b
Show file tree
Hide file tree
Showing 13 changed files with 926 additions and 626 deletions.
21 changes: 14 additions & 7 deletions src/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ _Noreturn void reboot(){
}

static void play_music(){
printk("Playing..\n");
wav_player("/music_box.mp3");
printk("PlayEnd\n");
}

/*
Expand Down Expand Up @@ -122,20 +124,25 @@ _Noreturn void kernel_main(multiboot_t *multiboot, uint32_t kernel_stack) {
// 挂载最后一个块设备(通常为引导设备)
vfs_node_t dev = vfs_open("/dev");
vfs_node_t c = NULL;
bool win = false;
list_foreach(dev->child, i) {
c = (vfs_node_t) i->data;
char buf[20];
sprintf(buf,"/dev/%s",c->name);
if(vfs_mount(buf, vfs_open("/")) != -1){
win = true;
break;
}
}
if(c == NULL) {
if(c == NULL || !win) {
klogf(false,"Cannot mount a drive device.\n");
goto jmp;
}else{
klogf(true,"Block device mount success!\n");
}
char buf[20];
sprintf(buf,"/dev/%s",c->name);
vfs_mount(buf, vfs_open("/"));
jmp:


klogf(true,"Kernel load done!\n");
//beep();
beep();
clock_sleep(100);
enable_scheduler();
io_sti(); //内核加载完毕, 打开中断以启动进程调度器, 开始运行
Expand Down
1 change: 0 additions & 1 deletion src/core/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ int vfs_mount(const char* src, vfs_node_t node) {
if (node->type != file_dir) return -1;
void *handle = NULL;
for (int i = 1; i < fs_nextid; i++) {
// printf("trying %d", i);
if (fs_callbacks[i]->mount(src, node) == 0) {
node->fsid = i;
node->root = node;
Expand Down
4 changes: 3 additions & 1 deletion src/core/vsound.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "vsound.h"
#include "rbtree-strptr.h"
#include "krlibc.h"
#include "klog.h"
#include "vfs.h"

#define ALL_IMPLEMENTATION
#include "rbtree-strptr.h"

#define DR_MP3_IMPLEMENTATION
#define DR_MP3_NO_STDIO
#include "dr_mp3.h"
Expand Down
4 changes: 3 additions & 1 deletion src/driver/pci/hda.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ void hda_init_codec(uint32_t codec) {
}

void hda_interrupt_handler(registers_t *reg){
printk("HDA IRQ\n");
if(hda_stopping){
hda_stop();
} else{
Expand Down Expand Up @@ -486,7 +487,8 @@ void hda_init(){
hda_output_base = hda_base + 0x80 + (0x20 * input_stream_count);
hda_output_buffer = kmalloc(4096);

register_interrupt_handler(0x20 + 0xb,hda_interrupt_handler);
int irq = pci_get_drive_irq(device->bus,device->slot,device->func);
register_interrupt_handler(0x20 + irq,hda_interrupt_handler);
mem_set32(hda_base + 0x20, ((uint32_t )1 << 31) | ((uint32_t )1 << input_stream_count));

mem_set32(hda_base + 0x70, 0);
Expand Down
1 change: 1 addition & 0 deletions src/driver/pci/ide.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ void ide_initialize(uint32_t BAR0, uint32_t BAR1, uint32_t BAR2, uint32_t BAR3,
vd.Write = Write;
vd.size = ide_devices[i].Size;
vd.sector_size = vd.flag == 2 ? 2048 : 512;

int c = register_vdisk(vd);
drive_mapping[c] = i;
}
Expand Down
17 changes: 14 additions & 3 deletions src/fs/devfs.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#include "devfs.h"
#include "vdisk.h"
#include "klog.h"
#include "rbtree-strptr.h"
#include "krlibc.h"
#include "kmalloc.h"
#include "page.h"
#include "scheduler.h"

#define ALL_IMPLEMENTATION
#define SLIST_SP_IMPLEMENTATION
#include "rbtree-strptr.h"

int devfs_id = 0;
extern vdisk vdisk_ctl[26]; // core/vdisk.c
rbtree_sp_t dev_rbtree;
Expand Down Expand Up @@ -39,7 +42,7 @@ int devfs_mount(const char* src, vfs_node_t node) {

static int devfs_read(void *file, void *addr, size_t offset, size_t size) {
int dev_id = (int)file;
int sector_size;
int sector_size = 0;
if (vdisk_ctl[dev_id].flag == 0) return -1;
sector_size = vdisk_ctl[dev_id].sector_size;
int padding_up_to_sector_size = PADDING_UP(size, sector_size);
Expand All @@ -58,6 +61,14 @@ static int devfs_read(void *file, void *addr, size_t offset, size_t size) {
return 0;
}

static int devfs_stat(void *handle, vfs_node_t node) {
if (node->type == file_dir) return 0;
node->handle = rbtree_sp_get(dev_rbtree, node->name);
node->type = file_block;
node->size = disk_Size((int)node->handle);
return 0;
}

static int devfs_write(void *file, const void *addr, size_t offset, size_t size) {
int dev_id = (int)file;
int sector_size;
Expand Down Expand Up @@ -94,7 +105,7 @@ static struct vfs_callback callbacks = {
.mkfile = (void *)dummy,
.open = devfs_open,
.close = (void *)dummy,
.stat = (void *)dummy,
.stat = devfs_stat,
.read = devfs_read,
.write = devfs_write,
};
Expand Down
2 changes: 2 additions & 0 deletions src/fs/iso9660.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ l9660_status l9660_openfs(l9660_fs *fs,
uint32_t idx = 0x10;
for (;;) {
// Read next sector

if (!read_sector(fs, pvd, idx)) return L9660_EIO;

// Validate magic
if (memcmp(pvd->hdr.magic, "CD001", 5) != 0) return L9660_EBADFS;

Expand Down
Loading

0 comments on commit 745464b

Please sign in to comment.