Compare commits
No commits in common. "99f290634fdc98ef5a299bdc42219d0d0cb7a420" and "9f41ddd2424320e35d5544dfad2a8741841c3140" have entirely different histories.
99f290634f
...
9f41ddd242
@ -38,9 +38,7 @@ OBJS = \
|
||||
pic/pic.o \
|
||||
pic/keyboard.o \
|
||||
pic/pit.o \
|
||||
utils/ring_buffer.o \
|
||||
iso.o \
|
||||
fd.o
|
||||
utils/ring_buffer.o
|
||||
|
||||
|
||||
DEPS = $(OBJS:.o=.d)
|
||||
|
@ -17,8 +17,7 @@ static void busy_wait(uint16_t drive)
|
||||
|
||||
static void wait_device_selection(uint16_t drive)
|
||||
{
|
||||
for (int i = 0; i < 4000; ++i)
|
||||
//printf("wait\r\n");
|
||||
for (int i = 0; i < 400; ++i)
|
||||
inb(drive);
|
||||
}
|
||||
|
||||
|
37
k/fd.c
37
k/fd.c
@ -1,37 +0,0 @@
|
||||
#include "fd.h"
|
||||
|
||||
static struct file_entry fd_table[MAX_FD] = { 0 };
|
||||
|
||||
static int find_next_fd(void)
|
||||
{
|
||||
for (int fd = 0; fd < MAX_FD; ++fd)
|
||||
{
|
||||
if (!fd_table[fd].open)
|
||||
return fd;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int register_fd(u32 lba)
|
||||
{
|
||||
int free_fd = find_next_fd();
|
||||
if (free_fd < 0)
|
||||
return -1;
|
||||
|
||||
struct file_entry f = { .open = 1, .lba = lba, .file_offset = 0 };
|
||||
fd_table[free_fd] = f;
|
||||
return free_fd;
|
||||
}
|
||||
|
||||
int destroy_fd(int fd)
|
||||
{
|
||||
if (fd > MAX_FD || !fd_table[fd].open)
|
||||
return -1;
|
||||
|
||||
fd_table[fd].open = 0;
|
||||
fd_table[fd].lba = 0;
|
||||
fd_table[fd].file_offset = 0;
|
||||
|
||||
return 0;
|
||||
}
|
18
k/fd.h
18
k/fd.h
@ -1,18 +0,0 @@
|
||||
#ifndef FD_H
|
||||
#define FD_H
|
||||
|
||||
#include <k/types.h>
|
||||
|
||||
#define MAX_FD 65535
|
||||
|
||||
struct file_entry
|
||||
{
|
||||
u8 open;
|
||||
u32 lba;
|
||||
u64 file_offset;
|
||||
};
|
||||
|
||||
int register_fd(u32 lba);
|
||||
int destroy_fd(int fd);
|
||||
|
||||
#endif /* !FD_H */
|
73
k/iso.c
73
k/iso.c
@ -1,73 +0,0 @@
|
||||
#include <k/iso9660.h>
|
||||
|
||||
#include <k/types.h>
|
||||
|
||||
#include "atapi.h"
|
||||
#include "fd.h"
|
||||
#include "iso.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
static u32 get_filename_length(const char *path, u32 *index)
|
||||
{
|
||||
u32 len = 0;
|
||||
for (; path[*index]; ++(*index))
|
||||
{
|
||||
if (path[*index] != '/')
|
||||
++len;
|
||||
else {
|
||||
while (path[*index] == '/')
|
||||
++(*index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int open(const char *pathname, int flags)
|
||||
{
|
||||
if (flags != O_RDONLY)
|
||||
return -1;
|
||||
|
||||
struct iso_prim_voldesc *iso_prim_block = read_block(ISO_PRIM_VOLDESC_BLOCK);
|
||||
if (strncmp(iso_prim_block->std_identifier, "CD001", 5))
|
||||
return -1;
|
||||
|
||||
struct iso_dir *root = &iso_prim_block->root_dir;
|
||||
struct iso_dir *curr = read_block(root->data_blk.le);
|
||||
|
||||
u32 index = 0;
|
||||
while (pathname[index] == '/')
|
||||
++index;
|
||||
|
||||
for (int depth = 0; depth < MAX_DIR_DEPTH; ++depth)
|
||||
{
|
||||
char found = 0;
|
||||
u32 start = index;
|
||||
u32 length = get_filename_length(pathname, &index);
|
||||
|
||||
// we found the file
|
||||
if (!length)
|
||||
return register_fd(curr->data_blk.le);
|
||||
|
||||
// iteration for one directory
|
||||
while (curr->dir_size != 0)
|
||||
{
|
||||
if (length == curr->idf_len &&
|
||||
!strncmp(pathname + start, curr->idf, length))
|
||||
{
|
||||
curr = read_block(curr->data_blk.le);
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
curr = (void *)curr + curr->dir_size;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
10
k/iso.h
10
k/iso.h
@ -1,10 +0,0 @@
|
||||
#ifndef ISO_H
|
||||
#define ISO_H
|
||||
|
||||
#include <k/types.h>
|
||||
|
||||
#define O_RDONLY 0
|
||||
|
||||
int open(const char *path, int flags);
|
||||
|
||||
#endif /* !ISO_H */
|
5
k/k.c
5
k/k.c
@ -31,7 +31,6 @@
|
||||
#include "serial.h"
|
||||
#include "stdio.h"
|
||||
#include "iso.h"
|
||||
#include "atapi.h"
|
||||
|
||||
static void k_init(void)
|
||||
{
|
||||
@ -53,6 +52,10 @@ void k_main(unsigned long magic, multiboot_info_t *info)
|
||||
|
||||
k_init();
|
||||
|
||||
//printf("bonjour\r\n");
|
||||
|
||||
poggers();
|
||||
|
||||
for (unsigned i = 0; ; ) {
|
||||
*fb = star[i++ % 4];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user