实现文件路径焦点的进程间隔离
This commit is contained in:
parent
80570dcdbf
commit
a6b044fe1c
|
@ -1,10 +1,10 @@
|
||||||
default: Makefile
|
default: Makefile
|
||||||
make -r -C libs
|
make -r -C libs
|
||||||
make -r -C init
|
make -r -C init
|
||||||
make -r -C base_service
|
make -r -C shell
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm ../isodir/apps/*
|
rm ../isodir/apps/*
|
||||||
make -r -C libs clean
|
make -r -C libs clean
|
||||||
make -r -C init clean
|
make -r -C init clean
|
||||||
make -r -C base_service clean
|
make -r -C shell clean
|
|
@ -1,6 +0,0 @@
|
||||||
#include "../include/stdio.h"
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
while (1);
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -7,6 +7,7 @@
|
||||||
#define SYSCALL_MALLOC 4
|
#define SYSCALL_MALLOC 4
|
||||||
#define SYSCALL_FREE 5
|
#define SYSCALL_FREE 5
|
||||||
#define SYSCALL_EXIT 6
|
#define SYSCALL_EXIT 6
|
||||||
|
#define SYSCALL_G_CLEAN 7
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
@ -17,5 +18,6 @@ char syscall_getc();
|
||||||
void* syscall_malloc(size_t size);
|
void* syscall_malloc(size_t size);
|
||||||
void syscall_free(void *ptr);
|
void syscall_free(void *ptr);
|
||||||
void syscall_exit(int code);
|
void syscall_exit(int code);
|
||||||
|
void syscall_g_clean();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
#include "../include/stdio.h"
|
#include "../include/stdio.h"
|
||||||
|
|
||||||
void hlt(){
|
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
printf("User application %d\n",12);
|
printf("User application %d\n",12);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -39,6 +39,10 @@ void syscall_exit(int code){
|
||||||
uint32_t rets;
|
uint32_t rets;
|
||||||
uint32_t __arg1 = (uint32_t)(code);
|
uint32_t __arg1 = (uint32_t)(code);
|
||||||
register uint32_t ebx asm("ebx") = __arg1;
|
register uint32_t ebx asm("ebx") = __arg1;
|
||||||
asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_EXIT), "r"(ebx) : "memory", "cc");
|
asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_EXIT), "r"(ebx) : "memory", "cc");\
|
||||||
return rets;
|
}
|
||||||
|
|
||||||
|
void syscall_g_clean(){
|
||||||
|
uint32_t rets;
|
||||||
|
asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_G_CLEAN) : "memory", "cc");
|
||||||
}
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
OBJS_PACK = out/service.obj
|
OBJS_PACK = out/shell.obj
|
||||||
include ../def.mk
|
include ../def.mk
|
||||||
|
|
||||||
default: $(OBJS_PACK)
|
default: $(OBJS_PACK)
|
||||||
$(LINK) $(OBJS_PACK) $(BASIC_LIB_C) -o ../../isodir/apps/service.bin
|
$(LINK) $(OBJS_PACK) $(BASIC_LIB_C) -o ../../isodir/apps/shell.bin
|
||||||
out/%.obj : %.c Makefile
|
out/%.obj : %.c Makefile
|
||||||
$(C) -c $*.c -o out/$*.obj
|
$(C) -c $*.c -o out/$*.obj
|
||||||
out/%.obj : %.cpp Makefile
|
out/%.obj : %.cpp Makefile
|
|
@ -0,0 +1,11 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "../include/syscall.h"
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
syscall_g_clean();
|
||||||
|
printf("CoolPotOS UserShell v0.0.1\n");
|
||||||
|
while (1){
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -25,6 +25,7 @@ static inline int get_fat_time(unsigned short hour, unsigned short minute) {
|
||||||
time |= (minute & 0x3f) << 5;
|
time |= (minute & 0x3f) << 5;
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_fat(unsigned char *img, int *fat, unsigned char *ff, int max,
|
void read_fat(unsigned char *img, int *fat, unsigned char *ff, int max,
|
||||||
int type) {
|
int type) {
|
||||||
if (type == 12) {
|
if (type == 12) {
|
||||||
|
|
50
src/fs/vfs.c
50
src/fs/vfs.c
|
@ -9,9 +9,9 @@
|
||||||
#include "../include/fat.h"
|
#include "../include/fat.h"
|
||||||
#include "../include/iso9660.h"
|
#include "../include/iso9660.h"
|
||||||
|
|
||||||
|
char root_disk = 'A';
|
||||||
vfs_t vfsstl[26];
|
vfs_t vfsstl[26];
|
||||||
vfs_t vfsMount_Stl[26];
|
vfs_t vfsMount_Stl[26];
|
||||||
vfs_t *vfs_now;
|
|
||||||
bool hasFS;
|
bool hasFS;
|
||||||
|
|
||||||
static vfs_t *drive2fs(uint8_t drive) {
|
static vfs_t *drive2fs(uint8_t drive) {
|
||||||
|
@ -24,7 +24,7 @@ static vfs_t *drive2fs(uint8_t drive) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static vfs_t *ParsePath(char *result) {
|
static vfs_t *ParsePath(char *result) {
|
||||||
vfs_t *vfs_result = vfs_now;
|
vfs_t *vfs_result = get_current()->vfs_now;
|
||||||
if (result[1] == ':') {
|
if (result[1] == ':') {
|
||||||
if (!(vfs_result = drive2fs(result[0]))) {
|
if (!(vfs_result = drive2fs(result[0]))) {
|
||||||
printf("Mount Drive is not found!\n");
|
printf("Mount Drive is not found!\n");
|
||||||
|
@ -154,7 +154,7 @@ uint32_t vfs_filesize(char *filename) {
|
||||||
|
|
||||||
List *vfs_listfile(char *dictpath) { // dictpath == "" 则表示当前路径
|
List *vfs_listfile(char *dictpath) { // dictpath == "" 则表示当前路径
|
||||||
if (strcmp(dictpath, "") == 0) {
|
if (strcmp(dictpath, "") == 0) {
|
||||||
return vfs_now->ListFile(vfs_now, dictpath);
|
return get_current()->vfs_now->ListFile(get_current()->vfs_now, dictpath);
|
||||||
} else {
|
} else {
|
||||||
char *new_path = kmalloc(strlen(dictpath) + 1);
|
char *new_path = kmalloc(strlen(dictpath) + 1);
|
||||||
strcpy(new_path, dictpath);
|
strcpy(new_path, dictpath);
|
||||||
|
@ -188,7 +188,7 @@ bool vfs_change_path(char *dictName) {
|
||||||
memcpy(buf, dictName, strlen(dictName) + 1);
|
memcpy(buf, dictName, strlen(dictName) + 1);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
if (buf[i] == '/' || buf[i] == '\\') {
|
if (buf[i] == '/' || buf[i] == '\\') {
|
||||||
if (!vfs_now->cd(vfs_now, "/")) {
|
if (!get_current()->vfs_now->cd(get_current()->vfs_now, "/")) {
|
||||||
kfree(r);
|
kfree(r);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -199,14 +199,14 @@ bool vfs_change_path(char *dictName) {
|
||||||
for (;; i++) {
|
for (;; i++) {
|
||||||
if (buf[i] == '/' || buf[i] == '\\') {
|
if (buf[i] == '/' || buf[i] == '\\') {
|
||||||
buf[i] = 0;
|
buf[i] = 0;
|
||||||
if (!vfs_now->cd(vfs_now, buf)) {
|
if (!get_current()->vfs_now->cd(get_current()->vfs_now, buf)) {
|
||||||
kfree(r);
|
kfree(r);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
buf += strlen(buf) + 1;
|
buf += strlen(buf) + 1;
|
||||||
}
|
}
|
||||||
if (buf[i] == 0) {
|
if (buf[i] == 0) {
|
||||||
if (!vfs_now->cd(vfs_now, buf)) {
|
if (!get_current()->vfs_now->cd(get_current()->vfs_now, buf)) {
|
||||||
kfree(r);
|
kfree(r);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -329,15 +329,15 @@ vfs_file *get_cur_file(char* filename){
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool vfs_change_disk(uint8_t drive) {
|
bool vfs_change_disk(struct task_struct *task,uint8_t drive) {
|
||||||
if (vfs_now != NULL) {
|
if (task->vfs_now != NULL) {
|
||||||
while (FindForCount(1, vfs_now->path) != NULL) {
|
while (FindForCount(1, task->vfs_now->path) != NULL) {
|
||||||
kfree(FindForCount(vfs_now->path->ctl->all, vfs_now->path)->val);
|
kfree(FindForCount(task->vfs_now->path->ctl->all, task->vfs_now->path)->val);
|
||||||
DeleteVal(vfs_now->path->ctl->all, vfs_now->path);
|
DeleteVal(task->vfs_now->path->ctl->all, task->vfs_now->path);
|
||||||
}
|
}
|
||||||
kfree(vfs_now->cache);
|
kfree(task->vfs_now->cache);
|
||||||
DeleteList(vfs_now->path);
|
DeleteList(task->vfs_now->path);
|
||||||
kfree(vfs_now);
|
kfree(task->vfs_now);
|
||||||
}
|
}
|
||||||
|
|
||||||
vfs_t *f;
|
vfs_t *f;
|
||||||
|
@ -345,11 +345,11 @@ bool vfs_change_disk(uint8_t drive) {
|
||||||
return false; // 没有mount
|
return false; // 没有mount
|
||||||
}
|
}
|
||||||
|
|
||||||
vfs_now = kmalloc(sizeof(vfs_t));
|
task->vfs_now = kmalloc(sizeof(vfs_t));
|
||||||
memcpy(vfs_now, f, sizeof(vfs_t));
|
memcpy(task->vfs_now, f, sizeof(vfs_t));
|
||||||
f->CopyCache(vfs_now, f);
|
f->CopyCache(task->vfs_now, f);
|
||||||
vfs_now->path = NewList();
|
task->vfs_now->path = NewList();
|
||||||
vfs_now->cd(vfs_now, "/");
|
task->vfs_now->cd(task->vfs_now, "/");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,12 +357,12 @@ void vfs_getPath(char *buffer) {
|
||||||
char *path;
|
char *path;
|
||||||
List *l;
|
List *l;
|
||||||
buffer[0] = 0;
|
buffer[0] = 0;
|
||||||
insert_char(buffer, 0, vfs_now->drive);
|
insert_char(buffer, 0, get_current()->vfs_now->drive);
|
||||||
insert_char(buffer, 1, ':');
|
insert_char(buffer, 1, ':');
|
||||||
insert_char(buffer, 2, '\\');
|
insert_char(buffer, 2, '\\');
|
||||||
int pos = strlen(buffer);
|
int pos = strlen(buffer);
|
||||||
for (int i = 1; FindForCount(i, vfs_now->path) != NULL; i++) {
|
for (int i = 1; FindForCount(i, get_current()->vfs_now->path) != NULL; i++) {
|
||||||
l = FindForCount(i, vfs_now->path);
|
l = FindForCount(i, get_current()->vfs_now->path);
|
||||||
path = (char *)l->val;
|
path = (char *)l->val;
|
||||||
insert_str(buffer, path, pos);
|
insert_str(buffer, path, pos);
|
||||||
pos += strlen(path);
|
pos += strlen(path);
|
||||||
|
@ -378,8 +378,8 @@ void vfs_getPath_no_drive(char *buffer) {
|
||||||
buffer[0] = 0;
|
buffer[0] = 0;
|
||||||
int pos = strlen(buffer);
|
int pos = strlen(buffer);
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; FindForCount(i, vfs_now->path) != NULL; i++) {
|
for (i = 1; FindForCount(i, get_current()->vfs_now->path) != NULL; i++) {
|
||||||
l = FindForCount(i, vfs_now->path);
|
l = FindForCount(i, get_current()->vfs_now->path);
|
||||||
path = (char *)l->val;
|
path = (char *)l->val;
|
||||||
insert_char(buffer, pos, '/');
|
insert_char(buffer, pos, '/');
|
||||||
pos++;
|
pos++;
|
||||||
|
@ -401,7 +401,7 @@ void init_vfs() {
|
||||||
vfsMount_Stl[i].drive = 0;
|
vfsMount_Stl[i].drive = 0;
|
||||||
// PDEBUG("Set vfsstl[%d] & vfsMount_Stl[%d] OK.", i, i);
|
// PDEBUG("Set vfsstl[%d] & vfsMount_Stl[%d] OK.", i, i);
|
||||||
}
|
}
|
||||||
vfs_now = NULL;
|
get_current()->vfs_now = NULL;
|
||||||
klogf(true,"Virtual File System initialize.\n");
|
klogf(true,"Virtual File System initialize.\n");
|
||||||
Register_fat_fileSys();
|
Register_fat_fileSys();
|
||||||
init_iso9660();
|
init_iso9660();
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define CRASHPOWEROS_COMMON_H
|
#define CRASHPOWEROS_COMMON_H
|
||||||
|
|
||||||
#define OS_NAME "CoolPotOS"
|
#define OS_NAME "CoolPotOS"
|
||||||
#define OS_VERSION "v0.2.9"
|
#define OS_VERSION "v0.3.0"
|
||||||
|
|
||||||
// b 0x211972
|
// b 0x211972
|
||||||
// b 0x20d0a6
|
// b 0x20d0a6
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#define SYSCALL_MALLOC 4
|
#define SYSCALL_MALLOC 4
|
||||||
#define SYSCALL_FREE 5
|
#define SYSCALL_FREE 5
|
||||||
#define SYSCALL_EXIT 6
|
#define SYSCALL_EXIT 6
|
||||||
|
#define SYSCALL_G_CLEAN 7
|
||||||
|
|
||||||
void syscall_install();
|
void syscall_install();
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ struct task_struct {
|
||||||
void *stack; // 进程的内核栈地址
|
void *stack; // 进程的内核栈地址
|
||||||
header_t *head; // 进程堆
|
header_t *head; // 进程堆
|
||||||
header_t *tail;
|
header_t *tail;
|
||||||
|
vfs_t *vfs_now; // 文件路径焦点
|
||||||
bool isUser; // 是否是用户进程
|
bool isUser; // 是否是用户进程
|
||||||
uint32_t program_break; // 进程堆基址
|
uint32_t program_break; // 进程堆基址
|
||||||
uint32_t program_break_end; // 进程堆尾
|
uint32_t program_break_end; // 进程堆尾
|
||||||
|
|
|
@ -67,7 +67,10 @@ bool vfs_renamefile(char *filename, char *filename_of_new);
|
||||||
bool vfs_attrib(char *filename, ftype type);
|
bool vfs_attrib(char *filename, ftype type);
|
||||||
bool vfs_format(uint8_t disk_number, char *FSName);
|
bool vfs_format(uint8_t disk_number, char *FSName);
|
||||||
vfs_file *vfs_fileinfo(char *filename);
|
vfs_file *vfs_fileinfo(char *filename);
|
||||||
bool vfs_change_disk(uint8_t drive);
|
|
||||||
|
#include "task.h"
|
||||||
|
|
||||||
|
bool vfs_change_disk(struct task_struct *task,uint8_t drive);
|
||||||
bool vfs_register_fs(vfs_t vfs);
|
bool vfs_register_fs(vfs_t vfs);
|
||||||
void init_vfs();
|
void init_vfs();
|
||||||
vfs_file *get_cur_file(char* filename);
|
vfs_file *get_cur_file(char* filename);
|
||||||
|
|
|
@ -116,7 +116,9 @@ void kernel_main(multiboot_t *multiboot) {
|
||||||
}
|
}
|
||||||
hasFS = false;
|
hasFS = false;
|
||||||
if(disk_id != '0'){
|
if(disk_id != '0'){
|
||||||
if(vfs_change_disk(disk_id)){
|
if(vfs_change_disk(get_current(),disk_id)){
|
||||||
|
extern char root_disk;
|
||||||
|
root_disk = disk_id;
|
||||||
klogf(true,"Chang default mounted disk.\n");
|
klogf(true,"Chang default mounted disk.\n");
|
||||||
hasFS = true;
|
hasFS = true;
|
||||||
}
|
}
|
||||||
|
@ -135,13 +137,13 @@ void kernel_main(multiboot_t *multiboot) {
|
||||||
|
|
||||||
clock_sleep(25);
|
clock_sleep(25);
|
||||||
|
|
||||||
vfs_change_path("apps");
|
//vfs_change_path("apps");
|
||||||
//klogf(user_process("service.bin","Service") != -1,"Service base process init.\n");
|
//klogf(user_process("shell.bin","Shell") != -1,"Shell process init.\n");
|
||||||
klogf(user_process("init.bin","Init") != -1,"Init base process init.\n");
|
//klogf(user_process("init.bin","Init") != -1,"Init base process init.\n");
|
||||||
|
|
||||||
//int pid = kernel_thread(setup_shell,NULL,"CPOS-Shell");
|
int pid = kernel_thread(setup_shell,NULL,"CPOS-Shell");
|
||||||
//klogf(pid != -1,"Launch kernel shell.\n");
|
klogf(pid != -1,"Launch kernel shell.\n");
|
||||||
//kernel_thread(check_task,&pid,"CPOS-CK");
|
kernel_thread(check_task,&pid,"CPOS-CK");
|
||||||
|
|
||||||
//panic_pane("System out of memory error!",OUT_OF_MEMORY);
|
//panic_pane("System out of memory error!",OUT_OF_MEMORY);
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,10 @@ static void syscall_free(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uin
|
||||||
use_free(get_current(),ebx);
|
use_free(get_current(),ebx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void syscall_g_clean(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uint32_t edi){
|
||||||
|
screen_clear();
|
||||||
|
}
|
||||||
|
|
||||||
void *sycall_handlers[MAX_SYSCALLS] = {
|
void *sycall_handlers[MAX_SYSCALLS] = {
|
||||||
[SYSCALL_PUTC] = syscall_puchar,
|
[SYSCALL_PUTC] = syscall_puchar,
|
||||||
[SYSCALL_PRINT] = syscall_print,
|
[SYSCALL_PRINT] = syscall_print,
|
||||||
|
@ -44,6 +48,7 @@ void *sycall_handlers[MAX_SYSCALLS] = {
|
||||||
[SYSCALL_MALLOC] = syscall_malloc,
|
[SYSCALL_MALLOC] = syscall_malloc,
|
||||||
[SYSCALL_FREE] = syscall_free,
|
[SYSCALL_FREE] = syscall_free,
|
||||||
[SYSCALL_EXIT] = syscall_exit,
|
[SYSCALL_EXIT] = syscall_exit,
|
||||||
|
[SYSCALL_G_CLEAN] = syscall_g_clean,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef size_t (*syscall_t)(size_t, size_t, size_t, size_t, size_t);
|
typedef size_t (*syscall_t)(size_t, size_t, size_t, size_t, size_t);
|
||||||
|
|
|
@ -216,6 +216,9 @@ int32_t user_process(char *path, char *name){ // 用户进程创建
|
||||||
new_task->name = name;
|
new_task->name = name;
|
||||||
new_task->isUser = 1;
|
new_task->isUser = 1;
|
||||||
|
|
||||||
|
extern char root_disk;
|
||||||
|
vfs_change_disk(new_task,root_disk);
|
||||||
|
|
||||||
io_sti();
|
io_sti();
|
||||||
|
|
||||||
page_switch(page);
|
page_switch(page);
|
||||||
|
|
|
@ -303,7 +303,7 @@ void cmd_disk(int argc, char **argv) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(have_vdisk(argv[2][0])){
|
if(have_vdisk(argv[2][0])){
|
||||||
vfs_change_disk(argv[2][0]);
|
vfs_change_disk(get_current(),argv[2][0]);
|
||||||
} else printf("[DISK]: Cannot found disk.\n");
|
} else printf("[DISK]: Cannot found disk.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -386,6 +386,9 @@ void setup_shell() {
|
||||||
int argc = -1;
|
int argc = -1;
|
||||||
char *buffer[255];
|
char *buffer[255];
|
||||||
|
|
||||||
|
extern char root_disk;
|
||||||
|
vfs_change_disk(get_current(),root_disk);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if(hasFS) vfs_getPath(buffer);
|
if(hasFS) vfs_getPath(buffer);
|
||||||
else{
|
else{
|
||||||
|
|
Loading…
Reference in New Issue