Work on adding partition support
This commit is contained in:
parent
e8d8f6390e
commit
16c8742bef
2
Makefile
2
Makefile
@ -7,7 +7,7 @@ LIBC_OBJ = $(LIBC_SOURCES:.c=.o)
|
||||
CC = $(shell cat psinfo/$(PLAT)/cc.txt)
|
||||
GDB = $(shell cat psinfo/$(PLAT)/gdb.txt)
|
||||
CFLAGS = -Isysroot/usr/include -Wextra -Wall -Wno-unused-parameter -g -ffreestanding
|
||||
QFLAGS = -hda ext2.img -m 2G -boot d -cdrom os.iso -serial stdio #-chardev socket,id=s1,port=3000,host=localhost -serial chardev:s1
|
||||
QFLAGS = -hda image.vdi -m 2G -boot d -cdrom os.iso -serial stdio #-chardev socket,id=s1,port=3000,host=localhost -serial chardev:s1
|
||||
|
||||
.PHONY: sysroot
|
||||
|
||||
|
3
image.vdi
Normal file
3
image.vdi
Normal file
@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:ed1f00fd7b78afe8199f18b4726df1ae29d13b1fe32d51d483254cb27d7423ab
|
||||
size 196083712
|
@ -21,7 +21,6 @@
|
||||
static long initrd_sz;
|
||||
static char* initrd;
|
||||
static multiboot_info_t* mbd;
|
||||
|
||||
typedef int (*func_ptr)();
|
||||
|
||||
static int console_dev_drv(char* filename,int c,long pos,char wr) {
|
||||
@ -95,7 +94,7 @@ static void init() {
|
||||
// pci_init();
|
||||
}
|
||||
// Detect and initailize serial ports
|
||||
//serial_init();
|
||||
serial_init();
|
||||
FILE* file=fopen("/initrd/prog.elf","r");
|
||||
elf_header header;
|
||||
fread(&header,sizeof(elf_header),1,file);
|
||||
@ -115,13 +114,15 @@ static void init() {
|
||||
klog("INFO","RAN PROG:%d",val);
|
||||
}
|
||||
ide_init();
|
||||
load_parts("/dev/hda");
|
||||
init_ext2();
|
||||
mount("/","/dev/hda","ext2");
|
||||
fopen("/mydir/mybadfile","w");
|
||||
// char str[256];
|
||||
// fgets(str,256,f);
|
||||
// str[strlen(str)-1]='\0';
|
||||
// klog("INFO","Got string %s",str);
|
||||
mount("/","/dev/hda1","ext2");
|
||||
klog("INFO","MOUNT");
|
||||
FILE* f=fopen("/file","r");
|
||||
char str[256];
|
||||
fgets(str,256,f);
|
||||
str[strlen(str)-1]='\0';
|
||||
klog("INFO","Got string %s",str);
|
||||
for(;;) {
|
||||
yield();
|
||||
}
|
||||
|
100
kernel/parts.c
Normal file
100
kernel/parts.c
Normal file
@ -0,0 +1,100 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../fs/devfs.h"
|
||||
|
||||
typedef struct {
|
||||
char bootable;
|
||||
char chs_start[3];
|
||||
char fs_id;
|
||||
char chs_end[3];
|
||||
uint32_t start_lba;
|
||||
uint32_t length;
|
||||
} partition;
|
||||
|
||||
static char** part_devs=NULL;
|
||||
static partition** parts=NULL;
|
||||
static uint32_t num_part_devs=0;
|
||||
static uint32_t max_part_devs=0;
|
||||
|
||||
int drv(char* filename,int c,long pos,char wr) {
|
||||
int part_no;
|
||||
switch (filename[strlen(filename)-1]) {
|
||||
case '1':
|
||||
part_no=0;
|
||||
break;
|
||||
case '2':
|
||||
part_no=1;
|
||||
break;
|
||||
case '3':
|
||||
part_no=2;
|
||||
break;
|
||||
case '4':
|
||||
part_no=3;
|
||||
break;
|
||||
}
|
||||
char* str=malloc(sizeof(char)*(strlen(filename)+1));
|
||||
strcpy(str,filename);
|
||||
str[strlen(str)-1]='\0';
|
||||
int i;
|
||||
for (i=0;i<num_part_devs;i++) {
|
||||
if (strcmp(part_devs[i]+5,str)==0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(str);
|
||||
uint32_t lba=pos/512;
|
||||
int offset=pos%512;
|
||||
if (lba>parts[i][part_no].length) {
|
||||
klog("INFO","Outside partition boundary");
|
||||
for(;;);
|
||||
return 0;
|
||||
}
|
||||
lba+=parts[i][part_no].start_lba;
|
||||
pos=lba*512;
|
||||
pos+=offset;
|
||||
if (wr) {
|
||||
FILE* f=fopen(part_devs[i],"w");
|
||||
fseek(f,pos,SEEK_SET);
|
||||
fputc(c,f);
|
||||
fclose(f);
|
||||
return 1;
|
||||
} else {
|
||||
FILE* f=fopen(part_devs[i],"r");
|
||||
fseek(f,pos,SEEK_SET);
|
||||
char* c=fgetc(f);
|
||||
fclose(f);
|
||||
return c;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void load_parts(const char* path) {
|
||||
if (num_part_devs==max_part_devs) {
|
||||
max_part_devs+=32;
|
||||
part_devs=realloc(part_devs,sizeof(char*)*max_part_devs);
|
||||
parts=realloc(parts,sizeof(partition*)*num_part_devs);
|
||||
}
|
||||
FILE* f=fopen(path,"r");
|
||||
part_devs[num_part_devs]=path;
|
||||
path+=5;
|
||||
parts[num_part_devs]=malloc(sizeof(partition)*4);
|
||||
fseek(f,0x1BE,SEEK_SET);
|
||||
fread(parts[num_part_devs],sizeof(partition),4,f);
|
||||
for (int i=0;i<4;i++) {
|
||||
if (parts[num_part_devs][i].fs_id!=0) {
|
||||
klog("INFO","Found partition %d of type %x on sectors %d-%d ",i,(uint8_t)parts[num_part_devs][i].fs_id,parts[num_part_devs][i].start_lba,parts[num_part_devs][i].start_lba+parts[num_part_devs][i].length);
|
||||
char str[2];
|
||||
int_to_ascii(i+1,str);
|
||||
char* part_path=malloc(sizeof(char)*strlen(path)+2);
|
||||
memcpy(part_path,path,strlen(path));
|
||||
memcpy(part_path+strlen(path),str,2);
|
||||
klog("INFO","Path:%s",part_path);
|
||||
devfs_add(drv,part_path);
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
num_part_devs++;
|
||||
}
|
6
kernel/parts.h
Normal file
6
kernel/parts.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef PARTS_H
|
||||
#define PARTS_H
|
||||
|
||||
void load_parts(const char* path);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user