Import backup from 2005-05-12
This commit is contained in:
parent
14792ef954
commit
b0132c866e
9
Makefile
9
Makefile
@ -7,12 +7,15 @@ FLOPPY_MOUNT=./mnt_flp
|
|||||||
FLOPPY_IMAGE=hos.flp
|
FLOPPY_IMAGE=hos.flp
|
||||||
GRUB_IMAGE=grub.flp
|
GRUB_IMAGE=grub.flp
|
||||||
INITRD=hos_initrd
|
INITRD=hos_initrd
|
||||||
|
INITRD_DIR=initrd
|
||||||
INITRD_MOUNT=./mnt_initrd
|
INITRD_MOUNT=./mnt_initrd
|
||||||
INITRD_SIZE=100 #initrd size in kb
|
INITRD_SIZE=100 #initrd size in kb
|
||||||
|
|
||||||
# Do not print "Entering directory ..."
|
# Do not print "Entering directory ..."
|
||||||
MAKEFLAGS += --no-print-directory
|
MAKEFLAGS += --no-print-directory
|
||||||
|
|
||||||
|
.PHONY: initrd
|
||||||
|
|
||||||
all:
|
all:
|
||||||
make -C kernel
|
make -C kernel
|
||||||
make -C rmmod
|
make -C rmmod
|
||||||
@ -64,9 +67,7 @@ initrd:
|
|||||||
mke2fs -Fv -m0 -r0 -i1024 $(INITRD)
|
mke2fs -Fv -m0 -r0 -i1024 $(INITRD)
|
||||||
-mkdir $(INITRD_MOUNT)
|
-mkdir $(INITRD_MOUNT)
|
||||||
mount -t ext2 -o loop $(INITRD) $(INITRD_MOUNT)
|
mount -t ext2 -o loop $(INITRD) $(INITRD_MOUNT)
|
||||||
mkdir $(INITRD_MOUNT)/bin
|
cp -Pr $(INITRD_DIR)/* $(INITRD_MOUNT)
|
||||||
cp apps/hash/hash $(INITRD_MOUNT)/bin
|
|
||||||
ln -s /bin/hash $(INITRD_MOUNT)/bin/init
|
|
||||||
umount $(INITRD_MOUNT)
|
umount $(INITRD_MOUNT)
|
||||||
rm -rf $(INITRD_MOUNT)
|
rm -rf $(INITRD_MOUNT)
|
||||||
|
|
||||||
|
@ -9,40 +9,67 @@ NASM_FLAGS=-f aout
|
|||||||
|
|
||||||
# C Information:
|
# C Information:
|
||||||
CC=gcc
|
CC=gcc
|
||||||
|
CPP=g++
|
||||||
CC_FLAGS=-fleading-underscore -fno-builtin -nostdlib -nostartfiles -nodefaultlibs -I. -Wall
|
CC_FLAGS=-fleading-underscore -fno-builtin -nostdlib -nostartfiles -nodefaultlibs -I. -Wall
|
||||||
|
CPP_FLAGS=$(CC_FLAGS) -fno-rtti -fno-exceptions
|
||||||
|
|
||||||
# Linker Information:
|
# Linker Information:
|
||||||
LD=ld
|
LD=ld
|
||||||
LD_FLAGS=-nodefaultlibs -nostdlib --no-demangle -T link.ld
|
LD_FLAGS=-nodefaultlibs -nostdlib --no-demangle -T link.ld
|
||||||
|
|
||||||
all: Asm_Kernel C_Kernel
|
all: Asm_Kernel C_Kernel
|
||||||
$(LD) $(LD_FLAGS) -Map kernel.map \
|
@echo ' LD kernel.bin'
|
||||||
boot.o kernel.o lang_a.o mm.o vmm.o parallel.o conv.o kout.o \
|
@$(LD) $(LD_FLAGS) -Map kernel.map \
|
||||||
vconsole.o display.o devices.o pic.o keyboard.o ramdisk.o vfs.o \
|
boot.o kernel.o lang_a.o mm.o vmm.o conv.o kout.o \
|
||||||
devfs.o ext2.o lang_c.o vesafb.o -o kernel.bin
|
vconsole.o display.o devices.o pic.o keyboard.o \
|
||||||
|
ramdisk.o vfs.o lang_c.o vesafb.o \
|
||||||
|
string.o new.o ext2.o misc_char.o -o kernel.bin
|
||||||
|
@echo ' Kernel built: ' `ls -sk kernel.bin | cut -d' ' -f1`kb
|
||||||
|
|
||||||
Asm_Kernel:
|
Asm_Kernel:
|
||||||
$(NASM) $(NASM_FLAGS) -l boot.lst boot.asm -o boot.o
|
@echo ' NASM boot.o'
|
||||||
$(NASM) $(NASM_FLAGS) -l lang.lst lang/lang.asm -o lang_a.o
|
@$(NASM) $(NASM_FLAGS) -l boot.lst boot.asm -o boot.o
|
||||||
|
@echo ' NASM lang_a.o'
|
||||||
|
@$(NASM) $(NASM_FLAGS) -l lang.lst lang/lang.asm -o lang_a.o
|
||||||
|
|
||||||
C_Kernel:
|
C_Kernel:
|
||||||
$(CC) $(CC_FLAGS) -c kernel.c -o kernel.o
|
@echo ' CC kernel.o'
|
||||||
$(CC) $(CC_FLAGS) -c mm/mm.c -o mm.o
|
@$(CC) $(CC_FLAGS) -c kernel.c -o kernel.o
|
||||||
$(CC) $(CC_FLAGS) -c mm/vmm.c -o vmm.o
|
@echo ' CC mm.o'
|
||||||
$(CC) $(CC_FLAGS) -c char/parallel.c -o parallel.o
|
@$(CC) $(CC_FLAGS) -c mm/mm.c -o mm.o
|
||||||
$(CC) $(CC_FLAGS) -c lang/conv.c -o conv.o
|
@echo ' CC vmm.o'
|
||||||
$(CC) $(CC_FLAGS) -c display/kout.c -o kout.o
|
@$(CC) $(CC_FLAGS) -c mm/vmm.c -o vmm.o
|
||||||
$(CC) $(CC_FLAGS) -c char/vconsole.c -o vconsole.o
|
@echo ' CC conv.o'
|
||||||
$(CC) $(CC_FLAGS) -c fs/devices.c -o devices.o
|
@$(CC) $(CC_FLAGS) -c lang/conv.c -o conv.o
|
||||||
$(CC) $(CC_FLAGS) -c display/display.c -o display.o
|
@echo ' CC kout.o'
|
||||||
$(CC) $(CC_FLAGS) -c sys/pic.c -o pic.o
|
@$(CC) $(CC_FLAGS) -c display/kout.c -o kout.o
|
||||||
$(CC) $(CC_FLAGS) -c char/keyboard.c -o keyboard.o
|
@echo ' CC display.o'
|
||||||
$(CC) $(CC_FLAGS) -c block/ramdisk.c -o ramdisk.o
|
@$(CC) $(CC_FLAGS) -c display/display.c -o display.o
|
||||||
$(CC) $(CC_FLAGS) -c fs/devfs.c -o devfs.o
|
@echo ' CC pic.o'
|
||||||
$(CC) $(CC_FLAGS) -c fs/vfs.c -o vfs.o
|
@$(CC) $(CC_FLAGS) -c sys/pic.c -o pic.o
|
||||||
$(CC) $(CC_FLAGS) -c fs/ext2.c -o ext2.o
|
@echo ' CC keyboard.o'
|
||||||
$(CC) $(CC_FLAGS) -c lang/lang.c -o lang_c.o
|
@$(CC) $(CC_FLAGS) -c char/keyboard.c -o keyboard.o
|
||||||
$(CC) $(CC_FLAGS) -c display/vesafb.c -o vesafb.o
|
@echo ' CC lang_c.o'
|
||||||
|
@$(CC) $(CC_FLAGS) -c lang/lang.c -o lang_c.o
|
||||||
|
@echo ' CC vesafb.o'
|
||||||
|
@$(CC) $(CC_FLAGS) -c display/vesafb.c -o vesafb.o
|
||||||
|
|
||||||
|
@echo ' CPP string.o'
|
||||||
|
@$(CPP) $(CPP_FLAGS) -c lang/string.cpp -o string.o
|
||||||
|
@echo ' CPP new.o'
|
||||||
|
@$(CPP) $(CPP_FLAGS) -c lang/new.cpp -o new.o
|
||||||
|
@echo ' CPP vfs.o'
|
||||||
|
@$(CPP) $(CPP_FLAGS) -c fs/vfs.cpp -o vfs.o
|
||||||
|
@echo ' CPP ext2.o'
|
||||||
|
@$(CPP) $(CPP_FLAGS) -c fs/ext2.cpp -o ext2.o
|
||||||
|
@echo ' CPP misc_char.o'
|
||||||
|
@$(CPP) $(CPP_FLAGS) -c char/misc_char.cpp -o misc_char.o
|
||||||
|
@echo ' CPP ramdisk.o'
|
||||||
|
@$(CPP) $(CPP_FLAGS) -c block/ramdisk.cpp -o ramdisk.o
|
||||||
|
@echo ' CPP vconsole.o'
|
||||||
|
@$(CPP) $(CPP_FLAGS) -c char/vconsole.cpp -o vconsole.o
|
||||||
|
@echo ' CPP devices.o'
|
||||||
|
@$(CPP) $(CPP_FLAGS) -c devices.cpp -o devices.o
|
||||||
|
|
||||||
#################################################
|
#################################################
|
||||||
# Clean up the source directory of any binaries #
|
# Clean up the source directory of any binaries #
|
||||||
|
93
kernel/block/ramdisk.cpp
Normal file
93
kernel/block/ramdisk.cpp
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
// ramdisk.cpp
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Date: 08/20/04
|
||||||
|
// Modified: 05/11/05
|
||||||
|
|
||||||
|
#define _HOS_CPP_ _HOS_CPP_
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include "functions.h"
|
||||||
|
#include "mm/vmm.h"
|
||||||
|
#include "lang/lang.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "block/ramdisk.h"
|
||||||
|
#include "devices.h"
|
||||||
|
|
||||||
|
ramdisk_t *ramdisks[256];
|
||||||
|
|
||||||
|
minor_t ramdisk_new(u32_t size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
if (!ramdisks[i])
|
||||||
|
{
|
||||||
|
void *start;
|
||||||
|
if (( start = kmalloc(size) ))
|
||||||
|
{
|
||||||
|
ramdisks[i] = (ramdisk_t *)New(ramdisk_t);
|
||||||
|
ramdisks[i]->start = start;
|
||||||
|
ramdisks[i]->size = size;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
minor_t ramdisk_register(void *ramdisk, u32_t size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
if (!ramdisks[i])
|
||||||
|
{
|
||||||
|
ramdisks[i] = (ramdisk_t *)New(ramdisk_t);
|
||||||
|
ramdisks[i]->start = ramdisk;
|
||||||
|
ramdisks[i]->size = size;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ramdisk_remove(minor_t minor)
|
||||||
|
{
|
||||||
|
if (ramdisks[minor])
|
||||||
|
{
|
||||||
|
kfree(ramdisks[minor]->start);
|
||||||
|
kfree(ramdisks[minor]);
|
||||||
|
ramdisks[minor] = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Ramdisk::block_read(minor_t minor, u32_t blockStart, u32_t blocks, void *buffer)
|
||||||
|
{
|
||||||
|
if (!ramdisks[minor])
|
||||||
|
return -1;
|
||||||
|
if ((blockStart << BLOCK_SIZE_LOG) >= ramdisks[minor]->size)
|
||||||
|
return -2;
|
||||||
|
void *rdAddr = (void *)((u32_t)ramdisks[minor]->start + (blockStart << BLOCK_SIZE_LOG));
|
||||||
|
u32_t copyLen = min(blocks << BLOCK_SIZE_LOG, ramdisks[minor]->size + (u32_t)ramdisks[minor]->start - (u32_t)rdAddr);
|
||||||
|
memcpyd(buffer, rdAddr, copyLen >> 2);
|
||||||
|
return copyLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Ramdisk::block_write(minor_t minor, u32_t blockStart, u32_t blocks, void *buffer)
|
||||||
|
{
|
||||||
|
if (!ramdisks[minor])
|
||||||
|
return -1;
|
||||||
|
if ((blockStart << BLOCK_SIZE_LOG) >= ramdisks[minor]->size)
|
||||||
|
return -2;
|
||||||
|
void *rdAddr = (void *)((u32_t)ramdisks[minor]->start + (blockStart << BLOCK_SIZE_LOG));
|
||||||
|
u32_t copyLen = min(blocks << BLOCK_SIZE_LOG, ramdisks[minor]->size + (u32_t)ramdisks[minor]->start - (u32_t)rdAddr);
|
||||||
|
memcpyd(rdAddr, buffer, copyLen >> 2);
|
||||||
|
return copyLen;
|
||||||
|
}
|
||||||
|
|
@ -6,20 +6,33 @@
|
|||||||
#ifndef __HOS_RD_H__
|
#ifndef __HOS_RD_H__
|
||||||
#define __HOS_RD_H__ __HOS_RD_H__
|
#define __HOS_RD_H__ __HOS_RD_H__
|
||||||
|
|
||||||
|
#ifdef _HOS_CPP_
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "hos_defines.h"
|
#include "hos_defines.h"
|
||||||
#include "fs/devices.h"
|
#include "devices.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void *start;
|
void *start;
|
||||||
u32_t size;
|
u32_t size;
|
||||||
} ramdisk_t;
|
} ramdisk_t;
|
||||||
|
|
||||||
int ramdisk_init(major_t major);
|
|
||||||
minor_t ramdisk_new(u32_t size);
|
minor_t ramdisk_new(u32_t size);
|
||||||
minor_t ramdisk_register(void *ramdisk, u32_t size);
|
minor_t ramdisk_register(void *ramdisk, u32_t size);
|
||||||
int ramdisk_remove(minor_t minor);
|
int ramdisk_remove(minor_t minor);
|
||||||
int ramdisk_block_read(minor_t minor, u32_t blockNum, u32_t count, void *buffer);
|
|
||||||
int ramdisk_block_write(minor_t minor, u32_t blockNum, u32_t count, void *buffer);
|
#ifdef _HOS_CPP_
|
||||||
|
}
|
||||||
|
|
||||||
|
class Ramdisk : public DeviceDriver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int block_read(minor_t minor, u32_t blockStart, u32_t blocks, void *buffer);
|
||||||
|
int block_write(minor_t minor, u32_t blockStart, u32_t blocks, void *buffer);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
25
kernel/block/ramdisk_old.h
Normal file
25
kernel/block/ramdisk_old.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// ramdisk.h
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Date: 08/20/04
|
||||||
|
// Modified: 08/22/04
|
||||||
|
|
||||||
|
#ifndef __HOS_RD_H__
|
||||||
|
#define __HOS_RD_H__ __HOS_RD_H__
|
||||||
|
|
||||||
|
#include "hos_defines.h"
|
||||||
|
#include "fs/devices.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void *start;
|
||||||
|
u32_t size;
|
||||||
|
} ramdisk_t;
|
||||||
|
|
||||||
|
int ramdisk_init(major_t major);
|
||||||
|
minor_t ramdisk_new(u32_t size);
|
||||||
|
minor_t ramdisk_register(void *ramdisk, u32_t size);
|
||||||
|
int ramdisk_remove(minor_t minor);
|
||||||
|
int ramdisk_block_read(minor_t minor, u32_t blockNum, u32_t count, void *buffer);
|
||||||
|
int ramdisk_block_write(minor_t minor, u32_t blockNum, u32_t count, void *buffer);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
46
kernel/char/misc_char.cpp
Normal file
46
kernel/char/misc_char.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// misc_char.cpp
|
||||||
|
// Miscellaneous character devices
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Date: 05/11/05
|
||||||
|
// Modified: 05/11/05
|
||||||
|
|
||||||
|
#define _HOS_CPP_ _HOS_CPP_
|
||||||
|
|
||||||
|
#include "hos_defines.h"
|
||||||
|
#include "devices.h"
|
||||||
|
#include "misc_char.h"
|
||||||
|
#include "sys/io.h"
|
||||||
|
|
||||||
|
int MiscChar::char_read(minor_t minor)
|
||||||
|
{
|
||||||
|
switch (minor)
|
||||||
|
{
|
||||||
|
case MISC_CHAR_NULL:
|
||||||
|
return DEV_EOF;
|
||||||
|
case MISC_CHAR_ZERO:
|
||||||
|
return 0;
|
||||||
|
case MISC_CHAR_LP0:
|
||||||
|
return DEV_INVALID_ACCESS;
|
||||||
|
default:
|
||||||
|
return DEV_INVALID_ACCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int MiscChar::char_write(minor_t minor, int c)
|
||||||
|
{
|
||||||
|
switch (minor)
|
||||||
|
{
|
||||||
|
case MISC_CHAR_NULL:
|
||||||
|
return 0;
|
||||||
|
case MISC_CHAR_ZERO:
|
||||||
|
return 0;
|
||||||
|
case MISC_CHAR_LP0:
|
||||||
|
outportb(0x37a, 0xc);
|
||||||
|
outportb(0x378, c);
|
||||||
|
outportb(0x37a, 0x1);
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
return DEV_INVALID_ACCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
31
kernel/char/misc_char.h
Normal file
31
kernel/char/misc_char.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// misc_char.h
|
||||||
|
// Miscellaneous character devices
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Date: 05/11/05
|
||||||
|
// Modified: 05/11/05
|
||||||
|
|
||||||
|
#ifndef __HOS_MISC_CHAR__
|
||||||
|
#define __HOS_MISC_CHAR__ __HOS_MISC_CHAR__
|
||||||
|
|
||||||
|
#define MISC_CHAR_NULL 3
|
||||||
|
#define MISC_CHAR_ZERO 5
|
||||||
|
#define MISC_CHAR_LP0 10
|
||||||
|
|
||||||
|
#include "hos_defines.h"
|
||||||
|
#include "devices.h"
|
||||||
|
#include "misc_char.h"
|
||||||
|
|
||||||
|
#ifdef _HOS_CPP_
|
||||||
|
|
||||||
|
class MiscChar : public DeviceDriver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int char_read(minor_t minor);
|
||||||
|
int char_write(minor_t minor, int c);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -1,36 +0,0 @@
|
|||||||
// parallel.c
|
|
||||||
// Author: Josh Holtrop
|
|
||||||
// Date: 08/02/04
|
|
||||||
// Modified: 08/16/04
|
|
||||||
|
|
||||||
#include "hos_defines.h"
|
|
||||||
#include "functions.h"
|
|
||||||
#include "char/parallel.h"
|
|
||||||
#include "fs/devices.h"
|
|
||||||
#include "mm/vmm.h"
|
|
||||||
|
|
||||||
// initialization routine for vconsoles module
|
|
||||||
int parallel_init(major_t major)
|
|
||||||
{
|
|
||||||
dev_driver_t *parallel_driver;
|
|
||||||
if (( parallel_driver = New(dev_driver_t) ))
|
|
||||||
{
|
|
||||||
parallel_driver->char_write = parallel_char_write;
|
|
||||||
devices_register_major('c', major, parallel_driver);
|
|
||||||
// register parallel devices as /dev/lp0, etc...
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int parallel_char_write(minor_t minor, int c)
|
|
||||||
{
|
|
||||||
if (minor == 0)
|
|
||||||
{
|
|
||||||
outportb(0x37a, 0xc);
|
|
||||||
outportb(0x378, c);
|
|
||||||
outportb(0x37a, 0x1);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
|||||||
// parallel.h
|
|
||||||
// Author: Josh Holtrop
|
|
||||||
// Date: 08/02/04
|
|
||||||
|
|
||||||
#ifndef __HOS_PARALLEL__
|
|
||||||
#define __HOS_PARALLEL__ __HOS_PARALLEL__
|
|
||||||
|
|
||||||
#include "hos_defines.h"
|
|
||||||
#include "fs/devices.h"
|
|
||||||
|
|
||||||
int parallel_init(major_t major);
|
|
||||||
int parallel_char_write(minor_t minor, int c);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,302 +0,0 @@
|
|||||||
// vconsole.c
|
|
||||||
// Author: Josh Holtrop
|
|
||||||
// Date: 08/02/04
|
|
||||||
// Modified: 08/16/04
|
|
||||||
|
|
||||||
#include "char/vconsole.h"
|
|
||||||
#include "hos_defines.h"
|
|
||||||
#include "fs/devices.h"
|
|
||||||
#include "mm/vmm.h"
|
|
||||||
#include "lang/lang.h"
|
|
||||||
#include "display/display.h"
|
|
||||||
#include "functions.h"
|
|
||||||
|
|
||||||
vconsole_t *vconsoles[VCONSOLE_MAX]; // pointer to virtual console structs
|
|
||||||
extern int display_activeConsole; // display subsystem active virtual console number
|
|
||||||
char ansi2vgaAttr[8] = {0, 4, 2, 6, 1, 5, 3, 7};
|
|
||||||
|
|
||||||
void vconsole_put_char(minor_t id, int c);
|
|
||||||
void vconsole_update_cursor(minor_t id, u16_t position);
|
|
||||||
void vconsole_update_attribute(minor_t id);
|
|
||||||
void vconsole_refresh(minor_t id);
|
|
||||||
|
|
||||||
// initialization routine for vconsoles module
|
|
||||||
int vconsole_init(major_t major)
|
|
||||||
{
|
|
||||||
dev_driver_t *vconsole_driver;
|
|
||||||
if (( vconsole_driver = New(dev_driver_t) ))
|
|
||||||
{
|
|
||||||
vconsole_driver->char_write = vconsole_char_write;
|
|
||||||
devices_register_major('c', major, vconsole_driver);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// routine to create a new virtual console object
|
|
||||||
minor_t vconsole_new(int width, int height)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = 1; i < VCONSOLE_MAX; i++)
|
|
||||||
{
|
|
||||||
if ( (!vconsoles[i]) && ( vconsoles[i] = New(vconsole_t) ) )
|
|
||||||
{
|
|
||||||
if (( vconsoles[i]->buffer = kmalloc(width * height * 2) ))
|
|
||||||
{
|
|
||||||
vconsoles[i]->width = width;
|
|
||||||
vconsoles[i]->height = height;
|
|
||||||
vconsoles[i]->attribute = vconsoles[i]->foreground = 0x07;
|
|
||||||
memsetw(vconsoles[i]->buffer, 0x0720, width * height);
|
|
||||||
// TODO: register the device as /dev/console%d
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
kfree(vconsoles[i]);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// called by display subsystem to draw a virtual console to the screen
|
|
||||||
int vconsole_draw(minor_t id)
|
|
||||||
{
|
|
||||||
if (vconsoles[id])
|
|
||||||
return display_console_draw(id, vconsoles[id]->cursorPosition,
|
|
||||||
vconsoles[id]->buffer, vconsoles[id]->width * vconsoles[id]->height);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// called by character device interface when a character is written to device w/ minor #id
|
|
||||||
int vconsole_char_write(minor_t id, int c)
|
|
||||||
{
|
|
||||||
if (!vconsoles[id])
|
|
||||||
return -1;
|
|
||||||
int cursorY = vconsoles[id]->cursorPosition / vconsoles[id]->width;
|
|
||||||
int cursorX = vconsoles[id]->cursorPosition % vconsoles[id]->width;
|
|
||||||
int evalEscapePosition = 0;
|
|
||||||
switch (vconsoles[id]->escapeLevel)
|
|
||||||
{
|
|
||||||
case 2:
|
|
||||||
if (c >= '0' && c <= '9') // c is part of an escape value
|
|
||||||
{
|
|
||||||
vconsoles[id]->escapeValue[vconsoles[id]->escapePosition] *= 10;
|
|
||||||
vconsoles[id]->escapeValue[vconsoles[id]->escapePosition] += c - '0';
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if (c == ';')
|
|
||||||
{
|
|
||||||
if (vconsoles[id]->escapePosition < 7)
|
|
||||||
vconsoles[id]->escapePosition++;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case 'A': // move cursor up n rows
|
|
||||||
cursorY -= vconsoles[id]->escapeValue[0];
|
|
||||||
if (cursorY < 0)
|
|
||||||
cursorY = 0;
|
|
||||||
vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX);
|
|
||||||
break;
|
|
||||||
case 'B': // move cursor down n rows
|
|
||||||
cursorY += vconsoles[id]->escapeValue[0];
|
|
||||||
if (cursorY >= vconsoles[id]->height)
|
|
||||||
cursorY = vconsoles[id]->height - 1;
|
|
||||||
vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX);
|
|
||||||
break;
|
|
||||||
case 'C': // move cursor left n columns
|
|
||||||
cursorX -= vconsoles[id]->escapeValue[0];
|
|
||||||
if (cursorX < 0)
|
|
||||||
cursorX = 0;
|
|
||||||
vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX);
|
|
||||||
break;
|
|
||||||
case 'D': // move cursor right n columns
|
|
||||||
cursorX += vconsoles[id]->escapeValue[0];
|
|
||||||
if (cursorX >= vconsoles[id]->width)
|
|
||||||
cursorX = vconsoles[id]->width - 1;
|
|
||||||
vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX);
|
|
||||||
break;
|
|
||||||
case 'H':
|
|
||||||
case 'f': // move cursor to position (x,y) upper left is (1,1)
|
|
||||||
cursorX = vconsoles[id]->escapeValue[0] - 1;
|
|
||||||
cursorY = vconsoles[id]->escapeValue[1] - 1;
|
|
||||||
if (cursorY < 0)
|
|
||||||
cursorY = 0;
|
|
||||||
if (cursorY >= vconsoles[id]->height)
|
|
||||||
cursorY = vconsoles[id]->height - 1;
|
|
||||||
if (cursorX < 0)
|
|
||||||
cursorX = 0;
|
|
||||||
if (cursorX >= vconsoles[id]->width)
|
|
||||||
cursorX = vconsoles[id]->width - 1;
|
|
||||||
vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX);
|
|
||||||
break;
|
|
||||||
case 'J': // clear screen, home cursor
|
|
||||||
memsetw(vconsoles[id]->buffer, 0x0720, vconsoles[id]->width * vconsoles[id]->height);
|
|
||||||
vconsole_draw(id);
|
|
||||||
vconsole_update_cursor(id, 0);
|
|
||||||
break;
|
|
||||||
case 'K': // erase line from cursor position (including char. under cursor) to end of line
|
|
||||||
memsetw(vconsoles[id]->buffer + vconsoles[id]->cursorPosition, 0x0720, vconsoles[id]->width - cursorX);
|
|
||||||
vconsole_draw(id);
|
|
||||||
break;
|
|
||||||
case 's': // push cursor position on an internal stack
|
|
||||||
if (vconsoles[id]->cursorStackPosition < 16)
|
|
||||||
vconsoles[id]->cursorStack[vconsoles[id]->cursorStackPosition++] = vconsoles[id]->cursorPosition;
|
|
||||||
break;
|
|
||||||
case 'u': // pop cursor position from stack
|
|
||||||
if (vconsoles[id]->cursorStackPosition > 0)
|
|
||||||
vconsole_update_cursor(id, vconsoles[id]->cursorStack[--vconsoles[id]->cursorStackPosition]);
|
|
||||||
break;
|
|
||||||
case 'm': // set text attributes
|
|
||||||
for (evalEscapePosition = 0; evalEscapePosition <= vconsoles[id]->escapePosition; evalEscapePosition++)
|
|
||||||
{
|
|
||||||
switch (vconsoles[id]->escapeValue[evalEscapePosition])
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
vconsoles[id]->foreground = 0x07;
|
|
||||||
vconsoles[id]->background = 0x00;
|
|
||||||
vconsoles[id]->concealed = 0;
|
|
||||||
vconsoles[id]->reverse = 0;
|
|
||||||
vconsoles[id]->blink = 0;
|
|
||||||
vconsoles[id]->bold = 0;
|
|
||||||
vconsole_update_attribute(id);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
vconsoles[id]->bold = 1;
|
|
||||||
vconsole_update_attribute(id);
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
vconsoles[id]->blink = 1;
|
|
||||||
vconsole_update_attribute(id);
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
vconsoles[id]->reverse = 1;
|
|
||||||
vconsole_update_attribute(id);
|
|
||||||
break;
|
|
||||||
case 30:
|
|
||||||
case 31:
|
|
||||||
case 32:
|
|
||||||
case 33:
|
|
||||||
case 34:
|
|
||||||
case 35:
|
|
||||||
case 36:
|
|
||||||
case 37:
|
|
||||||
vconsoles[id]->foreground = ansi2vgaAttr[vconsoles[id]->escapeValue[evalEscapePosition] - 30];
|
|
||||||
vconsole_update_attribute(id);
|
|
||||||
break;
|
|
||||||
case 40:
|
|
||||||
case 41:
|
|
||||||
case 42:
|
|
||||||
case 43:
|
|
||||||
case 44:
|
|
||||||
case 45:
|
|
||||||
case 46:
|
|
||||||
case 47:
|
|
||||||
vconsoles[id]->background = ansi2vgaAttr[vconsoles[id]->escapeValue[evalEscapePosition] - 40];
|
|
||||||
vconsole_update_attribute(id);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vconsoles[id]->escapePosition = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
memsetd(vconsoles[id]->escapeValue, 0, 8);
|
|
||||||
vconsoles[id]->escapePosition = 0;
|
|
||||||
vconsoles[id]->escapeLevel = 0;
|
|
||||||
return 0;
|
|
||||||
case 1:
|
|
||||||
if (c == '[')
|
|
||||||
vconsoles[id]->escapeLevel = 2;
|
|
||||||
break;
|
|
||||||
vconsoles[id]->escapeLevel = 0;
|
|
||||||
return 0; // invalid escape sequence
|
|
||||||
default:
|
|
||||||
if (c == '\e')
|
|
||||||
{
|
|
||||||
vconsoles[id]->escapeLevel = 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
vconsole_put_char(id, c);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// write the character to the virtual console
|
|
||||||
void vconsole_put_char(minor_t id, int c)
|
|
||||||
{
|
|
||||||
if (!vconsoles[id]->concealed)
|
|
||||||
{
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case '\t':
|
|
||||||
if (vconsoles[id]->cursorPosition % 8)
|
|
||||||
vconsole_update_cursor(id, vconsoles[id]->cursorPosition + (8 - (vconsoles[id]->cursorPosition % 8)));
|
|
||||||
else
|
|
||||||
vconsole_update_cursor(id, vconsoles[id]->cursorPosition + 8);
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
if (vconsoles[id]->cursorPosition % (vconsoles[id]->width))
|
|
||||||
vconsole_update_cursor(id, vconsoles[id]->cursorPosition + (vconsoles[id]->width - (vconsoles[id]->cursorPosition % vconsoles[id]->width)));
|
|
||||||
else
|
|
||||||
vconsole_update_cursor(id, vconsoles[id]->cursorPosition + vconsoles[id]->width);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
vconsoles[id]->buffer[vconsoles[id]->cursorPosition] = c | (vconsoles[id]->attribute << 8);
|
|
||||||
if (id == display_activeConsole)
|
|
||||||
display_console_put_char(id, c | (vconsoles[id]->attribute << 8), vconsoles[id]->cursorPosition);
|
|
||||||
vconsole_update_cursor(id, vconsoles[id]->cursorPosition + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void vconsole_update_cursor(minor_t id, u16_t position)
|
|
||||||
{
|
|
||||||
vconsoles[id]->cursorPosition = position;
|
|
||||||
if (position >= (vconsoles[id]->width * vconsoles[id]->height)) // time to scroll console
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < vconsoles[id]->cursorStackPosition; i++)
|
|
||||||
{
|
|
||||||
vconsoles[id]->cursorStack[i] -= vconsoles[id]->width;
|
|
||||||
if (vconsoles[id]->cursorStack[i] < 0)
|
|
||||||
vconsoles[id]->cursorStack[i] = 0;
|
|
||||||
}
|
|
||||||
vconsoles[id]->cursorPosition -= vconsoles[id]->width;
|
|
||||||
memcpyw(vconsoles[id]->buffer, vconsoles[id]->buffer + vconsoles[id]->width, vconsoles[id]->width * (vconsoles[id]->height - 1));
|
|
||||||
memsetw(vconsoles[id]->buffer + (vconsoles[id]->width * (vconsoles[id]->height - 1)), 0x0720, vconsoles[id]->width);
|
|
||||||
if (display_activeConsole == id)
|
|
||||||
{
|
|
||||||
vconsole_draw(id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (display_activeConsole == id)
|
|
||||||
display_console_update_cursor(id, position);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vconsole_update_attribute(minor_t id)
|
|
||||||
{
|
|
||||||
if (vconsoles[id]->reverse)
|
|
||||||
{
|
|
||||||
vconsoles[id]->attribute =
|
|
||||||
vconsoles[id]->blink << 7 |
|
|
||||||
vconsoles[id]->foreground << 4 |
|
|
||||||
vconsoles[id]->bold << 3 |
|
|
||||||
vconsoles[id]->background;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vconsoles[id]->attribute =
|
|
||||||
vconsoles[id]->blink << 7 |
|
|
||||||
vconsoles[id]->background << 4 |
|
|
||||||
vconsoles[id]->bold << 3 |
|
|
||||||
vconsoles[id]->foreground;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
258
kernel/char/vconsole.cpp
Normal file
258
kernel/char/vconsole.cpp
Normal file
@ -0,0 +1,258 @@
|
|||||||
|
// vconsole.cpp
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Date: 08/02/04
|
||||||
|
// Modified: 05/11/05
|
||||||
|
|
||||||
|
#define _HOS_CPP_ _HOS_CPP_
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include "hos_defines.h"
|
||||||
|
#include "mm/vmm.h"
|
||||||
|
#include "lang/lang.h"
|
||||||
|
#include "display/display.h"
|
||||||
|
#include "functions.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "devices.h"
|
||||||
|
#include "char/vconsole.h"
|
||||||
|
|
||||||
|
VConsole *vconsoles[VCONSOLE_MAX]; // pointer to virtual console structs
|
||||||
|
extern int display_activeConsole; // display subsystem active virtual console number
|
||||||
|
char ansi2vgaAttr[8] = {0, 4, 2, 6, 1, 5, 3, 7};
|
||||||
|
|
||||||
|
void vconsole_setup(int width, int height)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < VCONSOLE_MAX; i++)
|
||||||
|
vconsoles[i] = new VConsole(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
VConsoleDriver::~VConsoleDriver()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < VCONSOLE_MAX; i++)
|
||||||
|
if (vconsoles[i])
|
||||||
|
delete vconsoles[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
int VConsoleDriver::char_write(minor_t minor, int c)
|
||||||
|
{
|
||||||
|
if (minor < 0 || minor >= VCONSOLE_MAX)
|
||||||
|
return -1;
|
||||||
|
if (!vconsoles[minor])
|
||||||
|
return -2;
|
||||||
|
return vconsoles[minor]->char_write(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
VConsole::VConsole(int width, int height)
|
||||||
|
{
|
||||||
|
myBuffer = new u16_t[width * height];
|
||||||
|
myWidth = width;
|
||||||
|
myHeight = height;
|
||||||
|
myAttribute = myForeground = 0x07;
|
||||||
|
memsetw(myBuffer, 0x0720, width * height);
|
||||||
|
myCursorPosition = 0;
|
||||||
|
myCursorStackPosition = myEscapeLevel = myEscapePosition = myBackground =
|
||||||
|
myBold = myReverse = myBlink = myConcealed = myActive = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
VConsole::~VConsole()
|
||||||
|
{
|
||||||
|
delete[] myBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VConsole::activate()
|
||||||
|
{
|
||||||
|
myActive = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VConsole::deactivate()
|
||||||
|
{
|
||||||
|
myActive = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int VConsole::char_write(int c)
|
||||||
|
{
|
||||||
|
int cursorY = myCursorPosition / myWidth;
|
||||||
|
int cursorX = myCursorPosition % myWidth;
|
||||||
|
switch (myEscapeLevel)
|
||||||
|
{
|
||||||
|
case 2:
|
||||||
|
if (c >= '0' && c <= '9') // c is part of an escape value
|
||||||
|
{
|
||||||
|
myEscapeValue[myEscapePosition] *= 10;
|
||||||
|
myEscapeValue[myEscapePosition] += c - '0';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (c == ';')
|
||||||
|
{
|
||||||
|
if (myEscapePosition < 7)
|
||||||
|
myEscapePosition++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case 'A': // move cursor up n rows
|
||||||
|
update_cursor_coord(cursorY - myEscapeValue[0], cursorX);
|
||||||
|
break;
|
||||||
|
case 'B': // move cursor down n rows
|
||||||
|
update_cursor_coord(cursorY + myEscapeValue[0], cursorX);
|
||||||
|
break;
|
||||||
|
case 'C': // move cursor left n columns
|
||||||
|
update_cursor_coord(cursorY, cursorX - myEscapeValue[0]);
|
||||||
|
break;
|
||||||
|
case 'D': // move cursor right n columns
|
||||||
|
update_cursor_coord(cursorY, cursorX + myEscapeValue[0]);
|
||||||
|
break;
|
||||||
|
case 'H':
|
||||||
|
case 'f': // move cursor to position (x,y) upper left is (1,1)
|
||||||
|
update_cursor_coord(myEscapeValue[1] - 1, myEscapeValue[0] - 1);
|
||||||
|
break;
|
||||||
|
case 'J': // clear screen, home cursor
|
||||||
|
memsetw(myBuffer, 0x0720, myWidth * myHeight);
|
||||||
|
// vconsole_draw(id);
|
||||||
|
update_cursor_coord(0, 0);
|
||||||
|
break;
|
||||||
|
case 'K': // erase line from cursor position (including char. under cursor) to end of line
|
||||||
|
memsetw(myBuffer + myCursorPosition, 0x0720, myWidth - cursorX);
|
||||||
|
// vconsole_draw(id);
|
||||||
|
break;
|
||||||
|
case 's': // push cursor position on an internal stack
|
||||||
|
if (myCursorStackPosition < 16)
|
||||||
|
myCursorStack[myCursorStackPosition++] = myCursorPosition;
|
||||||
|
break;
|
||||||
|
case 'u': // pop cursor position from stack
|
||||||
|
if (myCursorStackPosition > 0)
|
||||||
|
update_cursor(myCursorStack[--myCursorStackPosition]);
|
||||||
|
break;
|
||||||
|
case 'm': // set text attributes
|
||||||
|
for (int evalEscapePosition = 0; evalEscapePosition <= myEscapePosition; evalEscapePosition++)
|
||||||
|
{
|
||||||
|
switch (myEscapeValue[evalEscapePosition])
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
myForeground = 0x07;
|
||||||
|
myBackground = myConcealed = myReverse = myBlink = myBold = 0;
|
||||||
|
update_attribute();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
myBold = 1;
|
||||||
|
update_attribute();
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
myBlink = 1;
|
||||||
|
update_attribute();
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
myReverse = 1;
|
||||||
|
update_attribute();
|
||||||
|
break;
|
||||||
|
case 30: case 31: case 32: case 33: case 34: case 35: case 36: case 37:
|
||||||
|
myForeground = ansi2vgaAttr[myEscapeValue[evalEscapePosition] - 30];
|
||||||
|
update_attribute();
|
||||||
|
break;
|
||||||
|
case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47:
|
||||||
|
myBackground = ansi2vgaAttr[myEscapeValue[evalEscapePosition] - 40];
|
||||||
|
update_attribute();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
myEscapePosition = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
memsetd(myEscapeValue, 0, 8);
|
||||||
|
myEscapePosition = 0;
|
||||||
|
myEscapeLevel = 0;
|
||||||
|
return 0;
|
||||||
|
case 1:
|
||||||
|
if (c == '[')
|
||||||
|
myEscapeLevel = 2;
|
||||||
|
break;
|
||||||
|
myEscapeLevel = 0;
|
||||||
|
return 0; // invalid escape sequence
|
||||||
|
default:
|
||||||
|
if (c == '\e')
|
||||||
|
{
|
||||||
|
myEscapeLevel = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
put_char(c);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void VConsole::put_char(int c)
|
||||||
|
{
|
||||||
|
if (!myConcealed)
|
||||||
|
{
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '\t':
|
||||||
|
if (myCursorPosition % 8)
|
||||||
|
update_cursor(myCursorPosition + (8 - (myCursorPosition % 8)));
|
||||||
|
else
|
||||||
|
update_cursor(myCursorPosition + 8);
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
if (myCursorPosition % myWidth)
|
||||||
|
update_cursor(myCursorPosition + (myWidth - (myCursorPosition % myWidth)));
|
||||||
|
else
|
||||||
|
update_cursor(myCursorPosition + myWidth);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
myBuffer[myCursorPosition] = c | (myAttribute << 8);
|
||||||
|
// if (myActive)
|
||||||
|
// display_console_put_char(c | (myAttribute << 8), myCursorPosition);
|
||||||
|
update_cursor(myCursorPosition + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VConsole::update_cursor_coord(int y, int x)
|
||||||
|
{
|
||||||
|
if (y < 0)
|
||||||
|
y = 0;
|
||||||
|
else if (y >= myHeight)
|
||||||
|
y = myHeight - 1;
|
||||||
|
if (x < 0)
|
||||||
|
x = 0;
|
||||||
|
else if (x >= myWidth)
|
||||||
|
x = myWidth - 1;
|
||||||
|
update_cursor(myWidth * y + x);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VConsole::update_cursor(u16_t position)
|
||||||
|
{
|
||||||
|
myCursorPosition = position;
|
||||||
|
if (position >= (myWidth * myHeight)) // time to scroll console
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < myCursorStackPosition; i++)
|
||||||
|
{
|
||||||
|
myCursorStack[i] -= myWidth;
|
||||||
|
if (myCursorStack[i] < 0)
|
||||||
|
myCursorStack[i] = 0;
|
||||||
|
}
|
||||||
|
myCursorPosition -= myWidth;
|
||||||
|
memcpyw(myBuffer, myBuffer + myWidth, myWidth * (myHeight - 1));
|
||||||
|
memsetw(myBuffer + (myWidth * (myHeight - 1)), 0x0720, myWidth);
|
||||||
|
// if (myActive)
|
||||||
|
// {
|
||||||
|
// vconsole_draw(id);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
// if (myActive)
|
||||||
|
// display_console_update_cursor(id, position);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VConsole::update_attribute()
|
||||||
|
{
|
||||||
|
if (myReverse)
|
||||||
|
myAttribute = myBlink << 7 | myForeground << 4 | myBold << 3 | myBackground;
|
||||||
|
else
|
||||||
|
myAttribute = myBlink << 7 | myBackground << 4 | myBold << 3 | myForeground;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,42 +1,72 @@
|
|||||||
// vconsole.h
|
// vconsole.h
|
||||||
// Author: Josh Holtrop
|
// Author: Josh Holtrop
|
||||||
// Date: 08/02/04
|
// Date: 08/02/04
|
||||||
// Modified: 08/07/04
|
// Modified: 05/11/05
|
||||||
|
|
||||||
#ifndef __HOS_VCONSOLE__
|
#ifndef __HOS_VCONSOLE__
|
||||||
#define __HOS_VCONSOLE__ __HOS_VCONSOLE__
|
#define __HOS_VCONSOLE__ __HOS_VCONSOLE__
|
||||||
|
|
||||||
|
#define VCONSOLE_MAX 7
|
||||||
|
|
||||||
|
#ifdef _HOS_CPP_
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "hos_defines.h"
|
#include "hos_defines.h"
|
||||||
#include "fs/devices.h"
|
|
||||||
|
|
||||||
#define VCONSOLE_MAX 16
|
void vconsole_setup(int width, int height);
|
||||||
|
|
||||||
typedef struct
|
#ifdef _HOS_CPP_
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "devices.h"
|
||||||
|
|
||||||
|
class VConsoleDriver : public DeviceDriver
|
||||||
{
|
{
|
||||||
u16_t *buffer;
|
public:
|
||||||
u32_t escapeValue[8];
|
~VConsoleDriver();
|
||||||
u16_t cursorPosition;
|
int char_write(minor_t minor, int c);
|
||||||
u16_t width;
|
};
|
||||||
u16_t height;
|
|
||||||
short cursorStack[16];
|
|
||||||
|
|
||||||
u8_t attribute;
|
class VConsole
|
||||||
u8_t foreground;
|
{
|
||||||
u8_t background;
|
protected:
|
||||||
u8_t bold;
|
u16_t *myBuffer;
|
||||||
u8_t reverse;
|
u16_t myWidth;
|
||||||
u8_t blink;
|
u16_t myHeight;
|
||||||
u8_t concealed;
|
u16_t myCursorPosition;
|
||||||
|
|
||||||
u8_t cursorStackPosition;
|
short myCursorStack[16];
|
||||||
u8_t escapeLevel;
|
u8_t myCursorStackPosition;
|
||||||
u8_t escapePosition;
|
|
||||||
} vconsole_t;
|
|
||||||
|
|
||||||
int vconsole_init(major_t major);
|
u32_t myEscapeValue[8];
|
||||||
minor_t vconsole_new(int width, int height);
|
u8_t myEscapeLevel;
|
||||||
int vconsole_draw(minor_t id);
|
u8_t myEscapePosition;
|
||||||
int vconsole_char_write(minor_t id, int c);
|
|
||||||
|
u8_t myAttribute;
|
||||||
|
u8_t myForeground;
|
||||||
|
u8_t myBackground;
|
||||||
|
u8_t myBold;
|
||||||
|
u8_t myReverse;
|
||||||
|
u8_t myBlink;
|
||||||
|
u8_t myConcealed;
|
||||||
|
|
||||||
|
u8_t myActive;
|
||||||
|
|
||||||
|
public:
|
||||||
|
VConsole(int width, int height);
|
||||||
|
~VConsole();
|
||||||
|
int char_read();
|
||||||
|
int char_write(int c);
|
||||||
|
void put_char(int c);
|
||||||
|
void update_cursor(u16_t position);
|
||||||
|
void update_cursor_coord(int y, int x);
|
||||||
|
void update_attribute();
|
||||||
|
void activate();
|
||||||
|
void deactivate();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
65
kernel/devices.cpp
Normal file
65
kernel/devices.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
// devices.cpp
|
||||||
|
// Device subsystem for HOS
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Date: 05/11/05
|
||||||
|
// Modified: 05/11/05
|
||||||
|
|
||||||
|
#define _HOS_CPP_ _HOS_CPP_
|
||||||
|
|
||||||
|
#include "hos_defines.h"
|
||||||
|
#include "devices.h"
|
||||||
|
#include "char/misc_char.h"
|
||||||
|
#include "char/vconsole.h"
|
||||||
|
|
||||||
|
DeviceDriver *drivers[256];
|
||||||
|
|
||||||
|
int devices_init()
|
||||||
|
{
|
||||||
|
drivers[MAJOR_MISC_CHAR] = new MiscChar();
|
||||||
|
drivers[MAJOR_VCONSOLE] = new VConsoleDriver();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int block_read(major_t major, minor_t minor, u32_t blockStart, u32_t blocks, void *buffer)
|
||||||
|
{
|
||||||
|
if (drivers[major & 0xFF])
|
||||||
|
return drivers[major & 0xFF]->block_read(minor, blockStart, blocks, buffer);
|
||||||
|
return DEV_INVALID_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int block_write(major_t major, minor_t minor, u32_t blockStart, u32_t blocks, void *buffer)
|
||||||
|
{
|
||||||
|
if (drivers[major & 0xFF])
|
||||||
|
return drivers[major & 0xFF]->block_write(minor, blockStart, blocks, buffer);
|
||||||
|
return DEV_INVALID_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int char_read(major_t major, minor_t minor)
|
||||||
|
{
|
||||||
|
if (drivers[major & 0xFF])
|
||||||
|
return drivers[major & 0xFF]->char_read(minor);
|
||||||
|
return DEV_INVALID_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int char_write(major_t major, minor_t minor, int c)
|
||||||
|
{
|
||||||
|
if (drivers[major & 0xFF])
|
||||||
|
return drivers[major & 0xFF]->char_write(minor, c);
|
||||||
|
return DEV_INVALID_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceDriver::DeviceDriver() {}
|
||||||
|
DeviceDriver::~DeviceDriver() {}
|
||||||
|
|
||||||
|
int DeviceDriver::char_read(minor_t minor)
|
||||||
|
{ return DEV_INVALID_ACCESS; }
|
||||||
|
|
||||||
|
int DeviceDriver::char_write(minor_t minor, int c)
|
||||||
|
{ return DEV_INVALID_ACCESS; }
|
||||||
|
|
||||||
|
int DeviceDriver::block_read(minor_t minor, u32_t blockStart, u32_t blocks, void *buffer)
|
||||||
|
{ return DEV_INVALID_ACCESS; }
|
||||||
|
|
||||||
|
int DeviceDriver::block_write(minor_t minor, u32_t blockStart, u32_t blocks, void *buffer)
|
||||||
|
{ return DEV_INVALID_ACCESS; }
|
||||||
|
|
54
kernel/devices.h
Normal file
54
kernel/devices.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// devices.h
|
||||||
|
// Device subsystem for HOS
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Date: 05/11/05
|
||||||
|
// Modified: 05/11/05
|
||||||
|
|
||||||
|
#ifndef __HOS_DEVICES_H__
|
||||||
|
#define __HOS_DEVICES_H__ __HOS_DEVICES_H__
|
||||||
|
|
||||||
|
#include "hos_defines.h"
|
||||||
|
|
||||||
|
#define DEV_INVALID_ACCESS -256
|
||||||
|
#define DEV_INVALID_DEVICE -257
|
||||||
|
#define DEV_EOF -1
|
||||||
|
|
||||||
|
#define MAJOR_MISC_CHAR 1
|
||||||
|
#define MAJOR_RAMDISK 2
|
||||||
|
#define MAJOR_VCONSOLE 4
|
||||||
|
|
||||||
|
#define BLOCK_SIZE 512
|
||||||
|
#define BLOCK_SIZE_LOG 9
|
||||||
|
|
||||||
|
typedef short major_t;
|
||||||
|
typedef short minor_t;
|
||||||
|
typedef u32_t device_t;
|
||||||
|
|
||||||
|
#ifdef _HOS_CPP_
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int devices_init();
|
||||||
|
int block_read(major_t major, minor_t minor, u32_t blockStart, u32_t blocks, void *buffer);
|
||||||
|
int block_write(major_t major, minor_t minor, u32_t blockStart, u32_t blocks, void *buffer);
|
||||||
|
int char_read(major_t major, minor_t minor);
|
||||||
|
int char_write(major_t major, minor_t minor, int c);
|
||||||
|
|
||||||
|
#ifdef _HOS_CPP_
|
||||||
|
}
|
||||||
|
|
||||||
|
class DeviceDriver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DeviceDriver();
|
||||||
|
virtual ~DeviceDriver();
|
||||||
|
virtual int char_read(minor_t minor);
|
||||||
|
virtual int char_write(minor_t minor, int c);
|
||||||
|
virtual int block_read(minor_t minor, u32_t blockStart, u32_t blocks, void *buffer);
|
||||||
|
virtual int block_write(minor_t minor, u32_t blockStart, u32_t blocks, void *buffer);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -3,7 +3,7 @@
|
|||||||
// Date: 08/07/04
|
// Date: 08/07/04
|
||||||
// Modified: 03/19/05
|
// Modified: 03/19/05
|
||||||
|
|
||||||
#include "fs/devices.h"
|
#include "devices.h"
|
||||||
#include "char/vconsole.h"
|
#include "char/vconsole.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "lang/lang.h"
|
#include "lang/lang.h"
|
||||||
@ -17,7 +17,6 @@ display_t myDisplays[12]; // f1-f12 change displays
|
|||||||
// initialization routine for display subsystem
|
// initialization routine for display subsystem
|
||||||
int display_init()
|
int display_init()
|
||||||
{
|
{
|
||||||
minor_t vc;
|
|
||||||
int width = 80;
|
int width = 80;
|
||||||
int height = 25;
|
int height = 25;
|
||||||
int displayType = DISPLAY_CONSOLE;
|
int displayType = DISPLAY_CONSOLE;
|
||||||
@ -28,25 +27,9 @@ int display_init()
|
|||||||
height = vesafb_getHeight();
|
height = vesafb_getHeight();
|
||||||
displayType = DISPLAY_FB;
|
displayType = DISPLAY_FB;
|
||||||
}
|
}
|
||||||
if (( vc = vconsole_new(width, height) ))
|
vconsole_setup(width, height);
|
||||||
{
|
// vconsole_activate(0);
|
||||||
myDisplays[11].type = displayType;
|
|
||||||
myDisplays[11].id = vc;
|
|
||||||
display_activeConsole = vc;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < 6; i++)
|
|
||||||
{
|
|
||||||
if ((vc = vconsole_new(width, height)))
|
|
||||||
{
|
|
||||||
myDisplays[i].type = displayType;
|
|
||||||
myDisplays[i].id = vc;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return -2 - i;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +44,7 @@ int display_activate(u32_t id)
|
|||||||
case DISPLAY_CONSOLE:
|
case DISPLAY_CONSOLE:
|
||||||
case DISPLAY_FB:
|
case DISPLAY_FB:
|
||||||
display_activeConsole = myDisplays[id].id;
|
display_activeConsole = myDisplays[id].id;
|
||||||
return vconsole_draw(display_activeConsole);
|
// return vconsole_draw(display_activeConsole);
|
||||||
case DISPLAY_GRAPHICAL:
|
case DISPLAY_GRAPHICAL:
|
||||||
default:
|
default:
|
||||||
return -2;
|
return -2;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#define __HOS_CONSOLE__ __HOS_CONSOLE__
|
#define __HOS_CONSOLE__ __HOS_CONSOLE__
|
||||||
|
|
||||||
#include "hos_defines.h"
|
#include "hos_defines.h"
|
||||||
#include "fs/devices.h"
|
#include "devices.h"
|
||||||
|
|
||||||
#define DISPLAY_NULL 0
|
#define DISPLAY_NULL 0
|
||||||
#define DISPLAY_CONSOLE 1
|
#define DISPLAY_CONSOLE 1
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
#include "hos_defines.h"
|
#include "hos_defines.h"
|
||||||
#include "kout.h"
|
#include "kout.h"
|
||||||
#include "lang/conv.h"
|
#include "lang/conv.h"
|
||||||
#include "fs/devices.h"
|
#include "devices.h"
|
||||||
|
#include "char/misc_char.h"
|
||||||
|
|
||||||
char buffer[64]; // for hex/oct/dec/ascii conversion
|
char buffer[64]; // for hex/oct/dec/ascii conversion
|
||||||
|
|
||||||
@ -14,9 +15,9 @@ char buffer[64]; // for hex/oct/dec/ascii conversion
|
|||||||
void putc(int c)
|
void putc(int c)
|
||||||
{
|
{
|
||||||
#ifdef PARALLEL_DEBUG
|
#ifdef PARALLEL_DEBUG
|
||||||
char_write(MAJORC_PARALLEL, 0, c);
|
char_write(MAJOR_MISC_CHAR, MISC_CHAR_LP0, c);
|
||||||
#endif
|
#endif
|
||||||
char_write(MAJORC_VCONSOLE, 1, c); // write to vconsole with minor 1, first allocated
|
char_write(MAJOR_VCONSOLE, 1, c); // write to vconsole with minor 1, first allocated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
// devfs.c
|
|
||||||
// Author: Josh Holtrop
|
|
||||||
// Date: 08/22/04
|
|
||||||
// Modified: 08/22/04
|
|
||||||
|
|
||||||
#include "hos_defines.h"
|
|
||||||
#include "fs/devfs.h"
|
|
||||||
#include "fs/devices.h"
|
|
||||||
#include "fs/vfs.h"
|
|
||||||
#include "block/ramdisk.h"
|
|
||||||
|
|
||||||
int devfs_init()
|
|
||||||
{
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
|||||||
// devfs.h
|
|
||||||
// Author: Josh Holtrop
|
|
||||||
// Date: 08/22/04
|
|
||||||
// Modified: 08/22/04
|
|
||||||
|
|
||||||
#ifndef __HOS_DEVFS_H__
|
|
||||||
#define __HOS_DEVFS_H__ __HOS_DEVFS_H__
|
|
||||||
|
|
||||||
#include "hos_defines.h"
|
|
||||||
#include "fs/devices.h"
|
|
||||||
|
|
||||||
int devfs_init();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
6
kernel/fs/ext2.cpp
Normal file
6
kernel/fs/ext2.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
// ext2.cpp
|
||||||
|
// ext2 filesystem driver for HOS
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Date: 05/10/05
|
||||||
|
// Modified: 05/10/05
|
||||||
|
|
238
kernel/fs/ext2.h
238
kernel/fs/ext2.h
@ -1,241 +1,21 @@
|
|||||||
// ext2.h
|
// ext2.h
|
||||||
|
// ext2 filesystem driver for HOS
|
||||||
// Author: Josh Holtrop
|
// Author: Josh Holtrop
|
||||||
// Date: 08/22/04
|
// Date: 05/10/05
|
||||||
// Modified: 12/24/04
|
// Modified: 05/10/05
|
||||||
|
|
||||||
#ifndef __HOS_EXT2_H__
|
#ifndef __HOS_EXT2_H__
|
||||||
#define __HOS_EXT2_H__ __HOS_EXT2_H__
|
#define __HOS_EXT2_H__ __HOS_EXT2_H__
|
||||||
|
|
||||||
#include "hos_defines.h"
|
#include "vfs.h"
|
||||||
#include "fs/devices.h"
|
|
||||||
#include "fs/vfs.h"
|
|
||||||
|
|
||||||
#define EXT2_MAGIC 0xEF53
|
#ifdef _HOS_CPP_
|
||||||
#define EXT2_NAME_LEN 255
|
|
||||||
|
|
||||||
#define EXT2_I_MODE_ATTR_MASK 0x0FFF
|
class Ext2 : public FileSystem
|
||||||
#define EXT2_I_MODE_OX 0x0001
|
|
||||||
#define EXT2_I_MODE_OW 0x0002
|
|
||||||
#define EXT2_I_MODE_OR 0x0004
|
|
||||||
#define EXT2_I_MODE_GX 0x0008
|
|
||||||
#define EXT2_I_MODE_GW 0x0010
|
|
||||||
#define EXT2_I_MODE_GR 0x0020
|
|
||||||
#define EXT2_I_MODE_UX 0x0040
|
|
||||||
#define EXT2_I_MODE_UW 0x0080
|
|
||||||
#define EXT2_I_MODE_UR 0x0100
|
|
||||||
#define EXT2_I_MODE_STICKY 0x0200
|
|
||||||
#define EXT2_I_MODE_SGID 0x0400
|
|
||||||
#define EXT2_I_MODE_SUID 0x0800
|
|
||||||
|
|
||||||
#define EXT2_I_MODE_TYPE_MASK 0xF000
|
|
||||||
#define EXT2_I_MODE_FIFO 0x1000
|
|
||||||
#define EXT2_I_MODE_CHAR 0x2000
|
|
||||||
#define EXT2_I_MODE_DIR 0x4000
|
|
||||||
#define EXT2_I_MODE_BLOCK 0x6000
|
|
||||||
#define EXT2_I_MODE_FILE 0x8000
|
|
||||||
#define EXT2_I_MODE_SYM 0xA000
|
|
||||||
#define EXT2_I_MODE_SOCK 0xC000
|
|
||||||
|
|
||||||
#define EXT2_I_FLAGS_SEC_DEL 0x01
|
|
||||||
#define EXT2_I_FLAGS_UNDELETE 0x02
|
|
||||||
#define EXT2_I_FLAGS_COMPRESS 0x04
|
|
||||||
#define EXT2_I_FLAGS_SYNC 0x08
|
|
||||||
#define EXT2_I_FLAGS_IMMUTABLE 0x10
|
|
||||||
#define EXT2_I_FLAGS_APPEND 0x20
|
|
||||||
#define EXT2_I_FLAGS_NODUMP 0x40
|
|
||||||
|
|
||||||
#define EXT2_INODE_BAD_BLOCKS 1
|
|
||||||
#define EXT2_INODE_ROOT 2
|
|
||||||
#define EXT2_INODE_ACL_INDEX 3
|
|
||||||
#define EXT2_INODE_ACL_DATA 4
|
|
||||||
#define EXT2_INODE_BOOT_LOADER 5
|
|
||||||
#define EXT2_INODE_UNDELETE_DIR 6
|
|
||||||
#define EXT2_INODE_AVAIL 11
|
|
||||||
|
|
||||||
#define EXT2_FT_UNKNOWN 0
|
|
||||||
#define EXT2_FT_FILE 1
|
|
||||||
#define EXT2_FT_DIR 2
|
|
||||||
#define EXT2_FT_CHAR 3
|
|
||||||
#define EXT2_FT_BLOCK 4
|
|
||||||
#define EXT2_FT_FIFO 5
|
|
||||||
#define EXT2_FT_SOCK 6
|
|
||||||
#define EXT2_FT_SYMLINK 7
|
|
||||||
#define EXT2_FT_MAX 8
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
{
|
||||||
u32_t s_inodes_count; /* Inodes count */
|
};
|
||||||
u32_t s_blocks_count; /* Blocks count */
|
|
||||||
u32_t s_r_blocks_count; /* Reserved blocks count */
|
#endif
|
||||||
u32_t s_free_blocks_count; /* Free blocks count */
|
|
||||||
u32_t s_free_inodes_count; /* Free inodes count */
|
|
||||||
u32_t s_first_data_block; /* First Data Block */
|
|
||||||
u32_t s_log_block_size; /* Block size: 0->1024, 1->2048, 2->4096 */
|
|
||||||
int s_log_frag_size; /* Fragment size */
|
|
||||||
u32_t s_blocks_per_group; /* # Blocks per group */
|
|
||||||
u32_t s_frags_per_group; /* # Fragments per group */
|
|
||||||
u32_t s_inodes_per_group; /* # Inodes per group */
|
|
||||||
u32_t s_mtime; /* Mount time */
|
|
||||||
u32_t s_wtime; /* Write time */
|
|
||||||
u16_t s_mnt_count; /* Mount count */
|
|
||||||
short s_max_mnt_count; /* Maximal mount count */
|
|
||||||
u16_t s_magic; /* Magic signature */
|
|
||||||
u16_t s_state; /* File system state */
|
|
||||||
u16_t s_errors; /* Behaviour when detecting errors */
|
|
||||||
u16_t s_minor_rev_level; /* minor revision level */
|
|
||||||
u32_t s_lastcheck; /* time of last check */
|
|
||||||
u32_t s_checkinterval; /* max. time between checks */
|
|
||||||
u32_t s_creator_os; /* OS */
|
|
||||||
u32_t s_rev_level; /* Revision level */
|
|
||||||
u16_t s_def_resuid; /* Default uid for reserved blocks */
|
|
||||||
u16_t s_def_resgid; /* Default gid for reserved blocks */
|
|
||||||
|
|
||||||
u32_t s_reserved[235];
|
|
||||||
} ext2_super_block_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
u32_t bg_block_bitmap; // Blocks bitmap block
|
|
||||||
u32_t bg_inode_bitmap; // Inode bitmap block
|
|
||||||
u32_t bg_inode_table; // Inode table block
|
|
||||||
u16_t bg_free_blocks_count; // Free blocks count
|
|
||||||
u16_t bg_free_inodes_count; // Free Inodes count
|
|
||||||
u16_t bg_used_dirs_count; // Directories count
|
|
||||||
u16_t bg_pad1;
|
|
||||||
u32_t bg_reserved[3];
|
|
||||||
} ext2_group_desc_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
u16_t i_mode; // File mode
|
|
||||||
u16_t i_uid; // Owner UID
|
|
||||||
u32_t i_size; // Size in bytes
|
|
||||||
u32_t i_atime; // Access time
|
|
||||||
u32_t i_ctime; // Creation time
|
|
||||||
u32_t i_mtime; // Modification time
|
|
||||||
u32_t i_dtime; // Deletion time
|
|
||||||
u16_t i_gid; // Group ID
|
|
||||||
u16_t i_links_count; // Links count
|
|
||||||
u32_t i_blocks; // Blocks count
|
|
||||||
u32_t i_flags; // File flags
|
|
||||||
u32_t i_reserved1;
|
|
||||||
u32_t i_block[15]; // Pointers to blocks (12 direct, single, double, triple indirect)
|
|
||||||
u32_t i_version; // File version (for NFS)
|
|
||||||
u32_t i_file_acl; // File ACL
|
|
||||||
u32_t i_dir_acl; // Directory ACL
|
|
||||||
u32_t i_faddr; // Fragment address
|
|
||||||
u8_t i_frag; // Fragment number
|
|
||||||
u8_t i_fsize; // Fragment size
|
|
||||||
u16_t i_pad1;
|
|
||||||
u32_t i_reserved2[2];
|
|
||||||
} ext2_inode_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
u32_t inode; // inode number
|
|
||||||
u16_t length; // directory entry length
|
|
||||||
u8_t name_length; // name length
|
|
||||||
u8_t file_type; // File type
|
|
||||||
char name[EXT2_NAME_LEN];
|
|
||||||
} ext2_dir_entry_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
ext2_inode_t inode;
|
|
||||||
u32_t block;
|
|
||||||
u32_t *block_pointers;
|
|
||||||
u32_t block_pointers_start;
|
|
||||||
} ext2_open_inode_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
ext2_open_inode_t *open_inode;
|
|
||||||
u32_t position;
|
|
||||||
} ext2_open_dir_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
ext2_open_inode_t *open_inode;
|
|
||||||
u32_t position;
|
|
||||||
u32_t buffer_start;
|
|
||||||
u32_t buffer_bytes;
|
|
||||||
u8_t *buffer;
|
|
||||||
} ext2__open_file_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
ext2_open_inode_t *open_inode;
|
|
||||||
u32_t block;
|
|
||||||
} ext2__open_block_file_t;
|
|
||||||
|
|
||||||
static inline u32_t ext2_diskToFSBlock(u32_t block, ext2_super_block_t *super)
|
|
||||||
{
|
|
||||||
// convert # of disk blocks to # of filesystem blocks
|
|
||||||
return block >> (super->s_log_block_size + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline u32_t ext2_FSToDiskBlock(u32_t block, ext2_super_block_t *super)
|
|
||||||
{
|
|
||||||
// convert # of filesystem blocks to # of disk blocks
|
|
||||||
return block << (super->s_log_block_size + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int ext2_init(int fsID);
|
|
||||||
int ext2_read_inode(vfs_mount_t *mount, u32_t inode, ext2_inode_t *dat);
|
|
||||||
int ext2_write_inode(vfs_mount_t *mount, u32_t inode, ext2_inode_t *dat);
|
|
||||||
ext2_group_desc_t ext2_get_group_desc(vfs_mount_t *mount, u32_t group);
|
|
||||||
void ext2_write_group_desc(vfs_mount_t *mount, u32_t group_num, ext2_group_desc_t *gd);
|
|
||||||
ext2_open_inode_t *ext2_open_inode(vfs_mount_t *mount, u32_t inode_number);
|
|
||||||
int ext2_close_inode(vfs_mount_t *mount, ext2_open_inode_t *open_inode);
|
|
||||||
int ext2_read_inode_block(vfs_mount_t *mount, ext2_open_inode_t *open_inode, void *block);
|
|
||||||
u32_t ext2_block_number(vfs_mount_t *mount, ext2_open_inode_t *open_inode);
|
|
||||||
int ext2_inode_seek(vfs_mount_t *mount, ext2_open_inode_t *open_inode, u32_t block_number);
|
|
||||||
|
|
||||||
int ext2_inode_status(vfs_mount_t *mount, u32_t inode_number);
|
|
||||||
int ext2_block_status(vfs_mount_t *mount, u32_t block_number);
|
|
||||||
|
|
||||||
u32_t ext2_alloc_inode(vfs_mount_t *mount);
|
|
||||||
int ext2_free_inode(vfs_mount_t *mount, u32_t inode_number);
|
|
||||||
u32_t ext2_alloc_block(vfs_mount_t *mount);
|
|
||||||
int ext2_free_block(vfs_mount_t *mount, u32_t block_number);
|
|
||||||
|
|
||||||
u32_t ext2_reserve_node(vfs_mount_t *mount, u32_t bitmap_block_num, u32_t bitmap_size);
|
|
||||||
int ext2_free_node(vfs_mount_t *mount, u32_t bitmap_block_num, u32_t node_number);
|
|
||||||
int ext2_num_block_groups(ext2_super_block_t *super);
|
|
||||||
void ext2_write_super(vfs_mount_t *mount);
|
|
||||||
|
|
||||||
int ext2_resize_inode(vfs_mount_t *mount, u32_t inode_number, u32_t new_size);
|
|
||||||
|
|
||||||
ext2_open_dir_t *ext2_open_dir(vfs_mount_t *mount, u32_t inode_number);
|
|
||||||
int ext2_dir_read_entry(vfs_mount_t *mount, ext2_open_dir_t *open_dir, ext2_dir_entry_t *dentry);
|
|
||||||
int ext2_close_dir(vfs_mount_t *mount, ext2_open_dir_t *open_dir);
|
|
||||||
int ext2_dir_lookup(vfs_mount_t *mount, u32_t dir_inode, char *fileName, ext2_dir_entry_t *direntry);
|
|
||||||
|
|
||||||
|
|
||||||
void *ext2_mount_super(major_t major, minor_t minor);
|
|
||||||
int ext2_umount_super(vfs_mount_t *mount);
|
|
||||||
int ext2_stat(vfs_mount_t *mount, u32_t inode_number, vfs_stat_t *stat);
|
|
||||||
u32_t ext2__get_root_dir_inode(vfs_mount_t *mount);
|
|
||||||
int ext2__link_deref(vfs_mount_t *mount, u32_t link_inode, char *link);
|
|
||||||
int ext2__free_inodes(vfs_mount_t *mount);
|
|
||||||
int ext2__total_inodes(vfs_mount_t *mount);
|
|
||||||
int ext2__free_blocks(vfs_mount_t *mount);
|
|
||||||
int ext2__total_blocks(vfs_mount_t *mount);
|
|
||||||
|
|
||||||
|
|
||||||
int ext2__open_dir(vfs_mount_t *mount, u32_t inode_number, vfs_open_file_t *dir);
|
|
||||||
int ext2__read_dir(vfs_mount_t *mount, vfs_open_file_t *dir, vfs_dir_entry_t *dentry);
|
|
||||||
int ext2__close_dir(vfs_mount_t *mount, vfs_open_file_t *dir);
|
|
||||||
|
|
||||||
int ext2__open_file(vfs_mount_t *mount, u32_t inode_number, vfs_open_file_t *open_file);
|
|
||||||
int ext2__read_file(vfs_mount_t *mount, vfs_open_file_t *open_file);
|
|
||||||
int ext2__close_file(vfs_mount_t *mount, vfs_open_file_t *open_file);
|
|
||||||
|
|
||||||
int ext2__open_block_file(vfs_mount_t *mount, u32_t inode_number, vfs_open_file_t *open_file);
|
|
||||||
int ext2__read_block_file(vfs_mount_t *mount, vfs_open_file_t *open_file, void *buffer);
|
|
||||||
int ext2__block_file_seek(vfs_mount_t *mount, vfs_open_file_t *open_file, u32_t block_number);
|
|
||||||
int ext2__close_block_file(vfs_mount_t *mount, vfs_open_file_t *open_file);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
241
kernel/fs/ext2_old.h
Normal file
241
kernel/fs/ext2_old.h
Normal file
@ -0,0 +1,241 @@
|
|||||||
|
// ext2.h
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Date: 08/22/04
|
||||||
|
// Modified: 12/24/04
|
||||||
|
|
||||||
|
#ifndef __HOS_EXT2_H__
|
||||||
|
#define __HOS_EXT2_H__ __HOS_EXT2_H__
|
||||||
|
|
||||||
|
#include "hos_defines.h"
|
||||||
|
#include "fs/devices.h"
|
||||||
|
#include "fs/vfs.h"
|
||||||
|
|
||||||
|
#define EXT2_MAGIC 0xEF53
|
||||||
|
#define EXT2_NAME_LEN 255
|
||||||
|
|
||||||
|
#define EXT2_I_MODE_ATTR_MASK 0x0FFF
|
||||||
|
#define EXT2_I_MODE_OX 0x0001
|
||||||
|
#define EXT2_I_MODE_OW 0x0002
|
||||||
|
#define EXT2_I_MODE_OR 0x0004
|
||||||
|
#define EXT2_I_MODE_GX 0x0008
|
||||||
|
#define EXT2_I_MODE_GW 0x0010
|
||||||
|
#define EXT2_I_MODE_GR 0x0020
|
||||||
|
#define EXT2_I_MODE_UX 0x0040
|
||||||
|
#define EXT2_I_MODE_UW 0x0080
|
||||||
|
#define EXT2_I_MODE_UR 0x0100
|
||||||
|
#define EXT2_I_MODE_STICKY 0x0200
|
||||||
|
#define EXT2_I_MODE_SGID 0x0400
|
||||||
|
#define EXT2_I_MODE_SUID 0x0800
|
||||||
|
|
||||||
|
#define EXT2_I_MODE_TYPE_MASK 0xF000
|
||||||
|
#define EXT2_I_MODE_FIFO 0x1000
|
||||||
|
#define EXT2_I_MODE_CHAR 0x2000
|
||||||
|
#define EXT2_I_MODE_DIR 0x4000
|
||||||
|
#define EXT2_I_MODE_BLOCK 0x6000
|
||||||
|
#define EXT2_I_MODE_FILE 0x8000
|
||||||
|
#define EXT2_I_MODE_SYM 0xA000
|
||||||
|
#define EXT2_I_MODE_SOCK 0xC000
|
||||||
|
|
||||||
|
#define EXT2_I_FLAGS_SEC_DEL 0x01
|
||||||
|
#define EXT2_I_FLAGS_UNDELETE 0x02
|
||||||
|
#define EXT2_I_FLAGS_COMPRESS 0x04
|
||||||
|
#define EXT2_I_FLAGS_SYNC 0x08
|
||||||
|
#define EXT2_I_FLAGS_IMMUTABLE 0x10
|
||||||
|
#define EXT2_I_FLAGS_APPEND 0x20
|
||||||
|
#define EXT2_I_FLAGS_NODUMP 0x40
|
||||||
|
|
||||||
|
#define EXT2_INODE_BAD_BLOCKS 1
|
||||||
|
#define EXT2_INODE_ROOT 2
|
||||||
|
#define EXT2_INODE_ACL_INDEX 3
|
||||||
|
#define EXT2_INODE_ACL_DATA 4
|
||||||
|
#define EXT2_INODE_BOOT_LOADER 5
|
||||||
|
#define EXT2_INODE_UNDELETE_DIR 6
|
||||||
|
#define EXT2_INODE_AVAIL 11
|
||||||
|
|
||||||
|
#define EXT2_FT_UNKNOWN 0
|
||||||
|
#define EXT2_FT_FILE 1
|
||||||
|
#define EXT2_FT_DIR 2
|
||||||
|
#define EXT2_FT_CHAR 3
|
||||||
|
#define EXT2_FT_BLOCK 4
|
||||||
|
#define EXT2_FT_FIFO 5
|
||||||
|
#define EXT2_FT_SOCK 6
|
||||||
|
#define EXT2_FT_SYMLINK 7
|
||||||
|
#define EXT2_FT_MAX 8
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u32_t s_inodes_count; /* Inodes count */
|
||||||
|
u32_t s_blocks_count; /* Blocks count */
|
||||||
|
u32_t s_r_blocks_count; /* Reserved blocks count */
|
||||||
|
u32_t s_free_blocks_count; /* Free blocks count */
|
||||||
|
u32_t s_free_inodes_count; /* Free inodes count */
|
||||||
|
u32_t s_first_data_block; /* First Data Block */
|
||||||
|
u32_t s_log_block_size; /* Block size: 0->1024, 1->2048, 2->4096 */
|
||||||
|
int s_log_frag_size; /* Fragment size */
|
||||||
|
u32_t s_blocks_per_group; /* # Blocks per group */
|
||||||
|
u32_t s_frags_per_group; /* # Fragments per group */
|
||||||
|
u32_t s_inodes_per_group; /* # Inodes per group */
|
||||||
|
u32_t s_mtime; /* Mount time */
|
||||||
|
u32_t s_wtime; /* Write time */
|
||||||
|
u16_t s_mnt_count; /* Mount count */
|
||||||
|
short s_max_mnt_count; /* Maximal mount count */
|
||||||
|
u16_t s_magic; /* Magic signature */
|
||||||
|
u16_t s_state; /* File system state */
|
||||||
|
u16_t s_errors; /* Behaviour when detecting errors */
|
||||||
|
u16_t s_minor_rev_level; /* minor revision level */
|
||||||
|
u32_t s_lastcheck; /* time of last check */
|
||||||
|
u32_t s_checkinterval; /* max. time between checks */
|
||||||
|
u32_t s_creator_os; /* OS */
|
||||||
|
u32_t s_rev_level; /* Revision level */
|
||||||
|
u16_t s_def_resuid; /* Default uid for reserved blocks */
|
||||||
|
u16_t s_def_resgid; /* Default gid for reserved blocks */
|
||||||
|
|
||||||
|
u32_t s_reserved[235];
|
||||||
|
} ext2_super_block_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u32_t bg_block_bitmap; // Blocks bitmap block
|
||||||
|
u32_t bg_inode_bitmap; // Inode bitmap block
|
||||||
|
u32_t bg_inode_table; // Inode table block
|
||||||
|
u16_t bg_free_blocks_count; // Free blocks count
|
||||||
|
u16_t bg_free_inodes_count; // Free Inodes count
|
||||||
|
u16_t bg_used_dirs_count; // Directories count
|
||||||
|
u16_t bg_pad1;
|
||||||
|
u32_t bg_reserved[3];
|
||||||
|
} ext2_group_desc_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u16_t i_mode; // File mode
|
||||||
|
u16_t i_uid; // Owner UID
|
||||||
|
u32_t i_size; // Size in bytes
|
||||||
|
u32_t i_atime; // Access time
|
||||||
|
u32_t i_ctime; // Creation time
|
||||||
|
u32_t i_mtime; // Modification time
|
||||||
|
u32_t i_dtime; // Deletion time
|
||||||
|
u16_t i_gid; // Group ID
|
||||||
|
u16_t i_links_count; // Links count
|
||||||
|
u32_t i_blocks; // Blocks count
|
||||||
|
u32_t i_flags; // File flags
|
||||||
|
u32_t i_reserved1;
|
||||||
|
u32_t i_block[15]; // Pointers to blocks (12 direct, single, double, triple indirect)
|
||||||
|
u32_t i_version; // File version (for NFS)
|
||||||
|
u32_t i_file_acl; // File ACL
|
||||||
|
u32_t i_dir_acl; // Directory ACL
|
||||||
|
u32_t i_faddr; // Fragment address
|
||||||
|
u8_t i_frag; // Fragment number
|
||||||
|
u8_t i_fsize; // Fragment size
|
||||||
|
u16_t i_pad1;
|
||||||
|
u32_t i_reserved2[2];
|
||||||
|
} ext2_inode_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u32_t inode; // inode number
|
||||||
|
u16_t length; // directory entry length
|
||||||
|
u8_t name_length; // name length
|
||||||
|
u8_t file_type; // File type
|
||||||
|
char name[EXT2_NAME_LEN];
|
||||||
|
} ext2_dir_entry_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ext2_inode_t inode;
|
||||||
|
u32_t block;
|
||||||
|
u32_t *block_pointers;
|
||||||
|
u32_t block_pointers_start;
|
||||||
|
} ext2_open_inode_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ext2_open_inode_t *open_inode;
|
||||||
|
u32_t position;
|
||||||
|
} ext2_open_dir_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ext2_open_inode_t *open_inode;
|
||||||
|
u32_t position;
|
||||||
|
u32_t buffer_start;
|
||||||
|
u32_t buffer_bytes;
|
||||||
|
u8_t *buffer;
|
||||||
|
} ext2__open_file_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
ext2_open_inode_t *open_inode;
|
||||||
|
u32_t block;
|
||||||
|
} ext2__open_block_file_t;
|
||||||
|
|
||||||
|
static inline u32_t ext2_diskToFSBlock(u32_t block, ext2_super_block_t *super)
|
||||||
|
{
|
||||||
|
// convert # of disk blocks to # of filesystem blocks
|
||||||
|
return block >> (super->s_log_block_size + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline u32_t ext2_FSToDiskBlock(u32_t block, ext2_super_block_t *super)
|
||||||
|
{
|
||||||
|
// convert # of filesystem blocks to # of disk blocks
|
||||||
|
return block << (super->s_log_block_size + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ext2_init(int fsID);
|
||||||
|
int ext2_read_inode(vfs_mount_t *mount, u32_t inode, ext2_inode_t *dat);
|
||||||
|
int ext2_write_inode(vfs_mount_t *mount, u32_t inode, ext2_inode_t *dat);
|
||||||
|
ext2_group_desc_t ext2_get_group_desc(vfs_mount_t *mount, u32_t group);
|
||||||
|
void ext2_write_group_desc(vfs_mount_t *mount, u32_t group_num, ext2_group_desc_t *gd);
|
||||||
|
ext2_open_inode_t *ext2_open_inode(vfs_mount_t *mount, u32_t inode_number);
|
||||||
|
int ext2_close_inode(vfs_mount_t *mount, ext2_open_inode_t *open_inode);
|
||||||
|
int ext2_read_inode_block(vfs_mount_t *mount, ext2_open_inode_t *open_inode, void *block);
|
||||||
|
u32_t ext2_block_number(vfs_mount_t *mount, ext2_open_inode_t *open_inode);
|
||||||
|
int ext2_inode_seek(vfs_mount_t *mount, ext2_open_inode_t *open_inode, u32_t block_number);
|
||||||
|
|
||||||
|
int ext2_inode_status(vfs_mount_t *mount, u32_t inode_number);
|
||||||
|
int ext2_block_status(vfs_mount_t *mount, u32_t block_number);
|
||||||
|
|
||||||
|
u32_t ext2_alloc_inode(vfs_mount_t *mount);
|
||||||
|
int ext2_free_inode(vfs_mount_t *mount, u32_t inode_number);
|
||||||
|
u32_t ext2_alloc_block(vfs_mount_t *mount);
|
||||||
|
int ext2_free_block(vfs_mount_t *mount, u32_t block_number);
|
||||||
|
|
||||||
|
u32_t ext2_reserve_node(vfs_mount_t *mount, u32_t bitmap_block_num, u32_t bitmap_size);
|
||||||
|
int ext2_free_node(vfs_mount_t *mount, u32_t bitmap_block_num, u32_t node_number);
|
||||||
|
int ext2_num_block_groups(ext2_super_block_t *super);
|
||||||
|
void ext2_write_super(vfs_mount_t *mount);
|
||||||
|
|
||||||
|
int ext2_resize_inode(vfs_mount_t *mount, u32_t inode_number, u32_t new_size);
|
||||||
|
|
||||||
|
ext2_open_dir_t *ext2_open_dir(vfs_mount_t *mount, u32_t inode_number);
|
||||||
|
int ext2_dir_read_entry(vfs_mount_t *mount, ext2_open_dir_t *open_dir, ext2_dir_entry_t *dentry);
|
||||||
|
int ext2_close_dir(vfs_mount_t *mount, ext2_open_dir_t *open_dir);
|
||||||
|
int ext2_dir_lookup(vfs_mount_t *mount, u32_t dir_inode, char *fileName, ext2_dir_entry_t *direntry);
|
||||||
|
|
||||||
|
|
||||||
|
void *ext2_mount_super(major_t major, minor_t minor);
|
||||||
|
int ext2_umount_super(vfs_mount_t *mount);
|
||||||
|
int ext2_stat(vfs_mount_t *mount, u32_t inode_number, vfs_stat_t *stat);
|
||||||
|
u32_t ext2__get_root_dir_inode(vfs_mount_t *mount);
|
||||||
|
int ext2__link_deref(vfs_mount_t *mount, u32_t link_inode, char *link);
|
||||||
|
int ext2__free_inodes(vfs_mount_t *mount);
|
||||||
|
int ext2__total_inodes(vfs_mount_t *mount);
|
||||||
|
int ext2__free_blocks(vfs_mount_t *mount);
|
||||||
|
int ext2__total_blocks(vfs_mount_t *mount);
|
||||||
|
|
||||||
|
|
||||||
|
int ext2__open_dir(vfs_mount_t *mount, u32_t inode_number, vfs_open_file_t *dir);
|
||||||
|
int ext2__read_dir(vfs_mount_t *mount, vfs_open_file_t *dir, vfs_dir_entry_t *dentry);
|
||||||
|
int ext2__close_dir(vfs_mount_t *mount, vfs_open_file_t *dir);
|
||||||
|
|
||||||
|
int ext2__open_file(vfs_mount_t *mount, u32_t inode_number, vfs_open_file_t *open_file);
|
||||||
|
int ext2__read_file(vfs_mount_t *mount, vfs_open_file_t *open_file);
|
||||||
|
int ext2__close_file(vfs_mount_t *mount, vfs_open_file_t *open_file);
|
||||||
|
|
||||||
|
int ext2__open_block_file(vfs_mount_t *mount, u32_t inode_number, vfs_open_file_t *open_file);
|
||||||
|
int ext2__read_block_file(vfs_mount_t *mount, vfs_open_file_t *open_file, void *buffer);
|
||||||
|
int ext2__block_file_seek(vfs_mount_t *mount, vfs_open_file_t *open_file, u32_t block_number);
|
||||||
|
int ext2__close_block_file(vfs_mount_t *mount, vfs_open_file_t *open_file);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
16
kernel/fs/vfs.cpp
Normal file
16
kernel/fs/vfs.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// vfs.cpp
|
||||||
|
// Virtual file system subsystem for HOS
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Date: 05/10/05
|
||||||
|
// Modified: 05/10/05
|
||||||
|
|
||||||
|
#define _HOS_CPP_ _HOS_CPP_
|
||||||
|
|
||||||
|
#include "hos_defines.h"
|
||||||
|
#include "vfs.h"
|
||||||
|
|
||||||
|
int vfs_init()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
171
kernel/fs/vfs.h
171
kernel/fs/vfs.h
@ -1,168 +1,29 @@
|
|||||||
// vfs.h
|
// vfs.h
|
||||||
|
// Virtual file system subsystem for HOS
|
||||||
// Author: Josh Holtrop
|
// Author: Josh Holtrop
|
||||||
// Date: 08/22/04
|
// Date: 05/10/05
|
||||||
// Modified: 12/21/04
|
// Modified: 05/10/05
|
||||||
|
|
||||||
#ifndef __HOS_VFS_H__
|
#ifndef __HOS_VFS_H__
|
||||||
#define __HOS_VFS_H__ __HOS_VFS_H__
|
#define __HOS_VFS_H__ __HOS_VFS_H__
|
||||||
|
|
||||||
#include "hos_defines.h"
|
#ifdef _HOS_CPP_
|
||||||
#include "fs/devices.h"
|
extern "C" {
|
||||||
|
#endif
|
||||||
#define FS_EXT2 1
|
|
||||||
#define VFS_MAX_FS 10
|
|
||||||
|
|
||||||
#define VFS_FT_UNKNOWN 0
|
|
||||||
#define VFS_FT_FILE 1
|
|
||||||
#define VFS_FT_DIR 2
|
|
||||||
#define VFS_FT_CHAR 3
|
|
||||||
#define VFS_FT_BLOCK 4
|
|
||||||
#define VFS_FT_FIFO 5
|
|
||||||
#define VFS_FT_SOCK 6
|
|
||||||
#define VFS_FT_SYMLINK 7
|
|
||||||
|
|
||||||
#define VFS_PERMS_OX 0x0001
|
|
||||||
#define VFS_PERMS_OW 0x0002
|
|
||||||
#define VFS_PERMS_OR 0x0004
|
|
||||||
#define VFS_PERMS_GX 0x0008
|
|
||||||
#define VFS_PERMS_GW 0x0010
|
|
||||||
#define VFS_PERMS_GR 0x0020
|
|
||||||
#define VFS_PERMS_UX 0x0040
|
|
||||||
#define VFS_PERMS_UW 0x0080
|
|
||||||
#define VFS_PERMS_UR 0x0100
|
|
||||||
#define VFS_PERMS_STICKY 0x0200
|
|
||||||
#define VFS_PERMS_SGID 0x0400
|
|
||||||
#define VFS_PERMS_SUID 0x0800
|
|
||||||
|
|
||||||
#define EOF 1000000
|
|
||||||
|
|
||||||
typedef u64_t vfs_inode_t;
|
|
||||||
|
|
||||||
/* Structure to hold information about a mount point */
|
|
||||||
struct vfs_mount_s
|
|
||||||
{
|
|
||||||
int refs;
|
|
||||||
void *super;
|
|
||||||
int fs;
|
|
||||||
major_t major;
|
|
||||||
minor_t minor;
|
|
||||||
char *mountPoint;
|
|
||||||
vfs_inode_t vfs_mount_inode;
|
|
||||||
vfs_inode_t vfs_up_inode;
|
|
||||||
vfs_inode_t vfs_root_inode;
|
|
||||||
struct vfs_mount_s *next;
|
|
||||||
struct vfs_mount_s *prev;
|
|
||||||
};
|
|
||||||
typedef struct vfs_mount_s vfs_mount_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
u16_t type; // file type, of VFS_FILE_TYPE_*
|
|
||||||
u32_t size;
|
|
||||||
u32_t inode;
|
|
||||||
u16_t permissions;
|
|
||||||
u16_t uid;
|
|
||||||
u16_t gid;
|
|
||||||
u32_t atime;
|
|
||||||
u32_t mtime;
|
|
||||||
u32_t ctime;
|
|
||||||
u16_t links;
|
|
||||||
u32_t dev;
|
|
||||||
} vfs_stat_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
vfs_mount_t *mount;
|
|
||||||
void *fs_data;
|
|
||||||
} vfs_open_file_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
char name[257];
|
|
||||||
u32_t inode_number; // relative inode number returned from fs
|
|
||||||
} vfs_dir_entry_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
vfs_mount_t *mount;
|
|
||||||
u32_t inode;
|
|
||||||
} vfs_file_addr_t;
|
|
||||||
|
|
||||||
/* Every filesystem must provide pointers to its respective functions in a structure like this */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
void *(*mount_super)(major_t major, minor_t minor);
|
|
||||||
int (*umount_super)(vfs_mount_t *mount);
|
|
||||||
int (*stat)(vfs_mount_t *mount, u32_t inode_number, vfs_stat_t *stat);
|
|
||||||
u32_t (*get_root_inode)(vfs_mount_t *mount);
|
|
||||||
int (*link_deref)(vfs_mount_t *mount, u32_t inode_number, char *link);
|
|
||||||
int (*free_inodes)(vfs_mount_t *mount);
|
|
||||||
int (*total_inodes)(vfs_mount_t *mount);
|
|
||||||
int (*free_blocks)(vfs_mount_t *mount);
|
|
||||||
int (*total_blocks)(vfs_mount_t *mount);
|
|
||||||
|
|
||||||
u32_t (*alloc_inode)(vfs_mount_t *mount);
|
|
||||||
int (*free_inode)(vfs_mount_t *mount, u32_t inode_number);
|
|
||||||
u32_t (*alloc_block)(vfs_mount_t *mount);
|
|
||||||
int (*free_block)(vfs_mount_t *mount, u32_t block_number);
|
|
||||||
|
|
||||||
int (*open_dir)(vfs_mount_t *mount, u32_t inode_number, vfs_open_file_t *dir);
|
|
||||||
int (*read_dir)(vfs_mount_t *mount, vfs_open_file_t *dir, vfs_dir_entry_t *dentry);
|
|
||||||
int (*close_dir)(vfs_mount_t *mount, vfs_open_file_t *dir);
|
|
||||||
|
|
||||||
int (*open_file)(vfs_mount_t *mount, u32_t inode_number, vfs_open_file_t *open_file);
|
|
||||||
int (*read_file)(vfs_mount_t *mount, vfs_open_file_t *open_file);
|
|
||||||
int (*close_file)(vfs_mount_t *mount, vfs_open_file_t *open_file);
|
|
||||||
|
|
||||||
int (*open_block_file)(vfs_mount_t *mount, u32_t inode_number, vfs_open_file_t *open_file);
|
|
||||||
int (*read_block_file)(vfs_mount_t *mount, vfs_open_file_t *open_file, void *buffer);
|
|
||||||
int (*block_file_seek)(vfs_mount_t *mount, vfs_open_file_t *open_file, u32_t block_number);
|
|
||||||
int (*close_block_file)(vfs_mount_t *mount, vfs_open_file_t *open_file);
|
|
||||||
|
|
||||||
} vfs_fs_t;
|
|
||||||
|
|
||||||
|
|
||||||
int vfs_init();
|
int vfs_init();
|
||||||
int vfs_mount(major_t maj, minor_t min, int fsType, char *mountPoint);
|
|
||||||
int vfs_umount(char *mountPoint);
|
|
||||||
int vfs_register_fs(int fsn, vfs_fs_t *fs);
|
|
||||||
int vfs_umount(char *mountPoint);
|
|
||||||
vfs_inode_t vfs_get_inode_number(char *path);
|
|
||||||
vfs_inode_t vfs_get_inode_number_rel(vfs_inode_t dir_inode, char *path);
|
|
||||||
vfs_inode_t vfs_real_inode(vfs_inode_t vfs_inode);
|
|
||||||
vfs_file_addr_t vfs_get_file_addr(vfs_inode_t vfs_inode);
|
|
||||||
vfs_inode_t vfs_entry_lookup(vfs_inode_t dir_inode, char *entry);
|
|
||||||
|
|
||||||
int vfs_mount_count();
|
#ifdef _HOS_CPP_
|
||||||
vfs_mount_t *vfs_get_mount(int index);
|
}
|
||||||
int vfs_free_inodes(vfs_mount_t *mount);
|
|
||||||
int vfs_total_inodes(vfs_mount_t *mount);
|
|
||||||
int vfs_free_blocks(vfs_mount_t *mount);
|
|
||||||
int vfs_total_blocks(vfs_mount_t *mount);
|
|
||||||
|
|
||||||
/* Temporary for debugging */
|
|
||||||
vfs_inode_t vfs_alloc_inode(vfs_mount_t *mount);
|
|
||||||
int vfs_free_inode(vfs_mount_t *mount, u32_t inode_number);
|
|
||||||
u32_t vfs_alloc_block(vfs_mount_t *mount);
|
|
||||||
int vfs_free_block(vfs_mount_t *mount, u32_t block_number);
|
|
||||||
|
|
||||||
|
|
||||||
int vfs_link_deref(vfs_inode_t vfs_inode, char *link);
|
|
||||||
|
|
||||||
int vfs_stat(char *file, vfs_stat_t *stat);
|
|
||||||
int vfs_stat_inode(vfs_inode_t vfs_inode, vfs_stat_t *stat);
|
|
||||||
|
|
||||||
vfs_open_file_t *vfs_open_dir(char *path);
|
|
||||||
vfs_open_file_t *vfs_open_dir_inode(vfs_inode_t inode);
|
|
||||||
int vfs_read_dir(vfs_open_file_t *open_dir, vfs_dir_entry_t *dentry);
|
|
||||||
int vfs_close_dir(vfs_open_file_t *open_dir);
|
|
||||||
|
|
||||||
vfs_open_file_t *vfs_open_block_file(char *file);
|
|
||||||
vfs_open_file_t *vfs_open_block_file_inode(vfs_inode_t vfs_inode);
|
|
||||||
int vfs_read_block_file(vfs_open_file_t *open_file, void *buffer);
|
|
||||||
int vfs_block_file_seek(vfs_open_file_t *open_file, u32_t block_number);
|
|
||||||
int vfs_close_block_file(vfs_open_file_t *open_file);
|
|
||||||
|
|
||||||
|
class FileSystem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FileSystem();
|
||||||
|
~FileSystem();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
// vfs.c
|
// vfs.cpp
|
||||||
// Author: Josh Holtrop
|
// Author: Josh Holtrop
|
||||||
// Date: 08/22/04
|
// Date: 08/22/04
|
||||||
// Modified: 12/21/04
|
// Modified: 12/21/04
|
||||||
|
|
||||||
|
#define _HOS_CPP_ _HOS_CPP_
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
#include "hos_defines.h"
|
#include "hos_defines.h"
|
||||||
#include "display/kout.h"
|
#include "display/kout.h"
|
||||||
#include "fs/vfs.h"
|
#include "fs/vfs.h"
|
||||||
@ -10,6 +14,8 @@
|
|||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
#include "mm/vmm.h"
|
#include "mm/vmm.h"
|
||||||
#include "lang/lang.h"
|
#include "lang/lang.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
vfs_fs_t *fses[VFS_MAX_FS]; // a vfs_fs structure for every filesystem we support
|
vfs_fs_t *fses[VFS_MAX_FS]; // a vfs_fs structure for every filesystem we support
|
||||||
vfs_mount_t *mounts;
|
vfs_mount_t *mounts;
|
||||||
@ -18,9 +24,16 @@ vfs_mount_t *mounts;
|
|||||||
int vfs_init()
|
int vfs_init()
|
||||||
{
|
{
|
||||||
k_check(ext2_init(FS_EXT2), "ext2_init() failed!");
|
k_check(ext2_init(FS_EXT2), "ext2_init() failed!");
|
||||||
|
FileSystem fs;
|
||||||
|
FileSystem *ext2 = new Ext2();
|
||||||
|
FileSystem *jfs = new JoshsFS();
|
||||||
|
fs.out();
|
||||||
|
ext2->out();
|
||||||
|
jfs->out();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// called by a filesystem driver to let us know that it is ready to handle fs requests
|
// called by a filesystem driver to let us know that it is ready to handle fs requests
|
||||||
int vfs_register_fs(int fsn, vfs_fs_t *fs)
|
int vfs_register_fs(int fsn, vfs_fs_t *fs)
|
||||||
{
|
{
|
||||||
@ -45,7 +58,7 @@ int vfs_mount(major_t maj, minor_t min, int fsType, char *mountPoint)
|
|||||||
void *super = fses[fsType]->mount_super(maj, min);
|
void *super = fses[fsType]->mount_super(maj, min);
|
||||||
if (!super)
|
if (!super)
|
||||||
return -3; // didn't mount superblock
|
return -3; // didn't mount superblock
|
||||||
vfs_mount_t *mnt = New(vfs_mount_t);
|
vfs_mount_t *mnt = (vfs_mount_t *) New(vfs_mount_t);
|
||||||
mnt->refs = 0;
|
mnt->refs = 0;
|
||||||
mnt->fs = fsType;
|
mnt->fs = fsType;
|
||||||
mnt->major = maj;
|
mnt->major = maj;
|
||||||
@ -53,7 +66,7 @@ int vfs_mount(major_t maj, minor_t min, int fsType, char *mountPoint)
|
|||||||
mnt->super = super;
|
mnt->super = super;
|
||||||
mnt->next = NULL;
|
mnt->next = NULL;
|
||||||
mnt->prev = NULL;
|
mnt->prev = NULL;
|
||||||
mnt->mountPoint = kmalloc(2);
|
mnt->mountPoint = (char *) kmalloc(2);
|
||||||
strcpy(mnt->mountPoint, mountPoint);
|
strcpy(mnt->mountPoint, mountPoint);
|
||||||
mnt->vfs_mount_inode = 0; // root not mounted on another fs
|
mnt->vfs_mount_inode = 0; // root not mounted on another fs
|
||||||
mnt->vfs_root_inode = ((vfs_inode_t)maj << 40) | ((vfs_inode_t)min << 32) | fses[fsType]->get_root_inode(mnt);
|
mnt->vfs_root_inode = ((vfs_inode_t)maj << 40) | ((vfs_inode_t)min << 32) | fses[fsType]->get_root_inode(mnt);
|
||||||
@ -77,13 +90,13 @@ int vfs_mount(major_t maj, minor_t min, int fsType, char *mountPoint)
|
|||||||
void *super = fses[fsType]->mount_super(maj, min);
|
void *super = fses[fsType]->mount_super(maj, min);
|
||||||
if (!super)
|
if (!super)
|
||||||
return -3; // didn't mount superblock
|
return -3; // didn't mount superblock
|
||||||
vfs_mount_t *mnt = New(vfs_mount_t);
|
vfs_mount_t *mnt = (vfs_mount_t *) New(vfs_mount_t);
|
||||||
mnt->refs = 0;
|
mnt->refs = 0;
|
||||||
mnt->super = super;
|
mnt->super = super;
|
||||||
mnt->fs = fsType;
|
mnt->fs = fsType;
|
||||||
mnt->major = maj;
|
mnt->major = maj;
|
||||||
mnt->minor = min;
|
mnt->minor = min;
|
||||||
mnt->mountPoint = kmalloc(strlen(mountPoint) + 1);
|
mnt->mountPoint = (char *) kmalloc(strlen(mountPoint) + 1);
|
||||||
strcpy(mnt->mountPoint, mountPoint);
|
strcpy(mnt->mountPoint, mountPoint);
|
||||||
mnt->vfs_mount_inode = vfs_inode;
|
mnt->vfs_mount_inode = vfs_inode;
|
||||||
mnt->vfs_up_inode = updir;
|
mnt->vfs_up_inode = updir;
|
||||||
@ -135,7 +148,7 @@ vfs_inode_t vfs_get_inode_number(char *path)
|
|||||||
|
|
||||||
vfs_inode_t vfs_get_inode_number_rel(vfs_inode_t dir_inode, char *path)
|
vfs_inode_t vfs_get_inode_number_rel(vfs_inode_t dir_inode, char *path)
|
||||||
{
|
{
|
||||||
char *path_copy = kmalloc(strlen(path) + 1);
|
char *path_copy = (char *) kmalloc(strlen(path) + 1);
|
||||||
strcpy(path_copy, path);
|
strcpy(path_copy, path);
|
||||||
int stanzas = str_split(path_copy, '/');
|
int stanzas = str_split(path_copy, '/');
|
||||||
char *lookup = path_copy;
|
char *lookup = path_copy;
|
||||||
@ -149,7 +162,7 @@ vfs_inode_t vfs_get_inode_number_rel(vfs_inode_t dir_inode, char *path)
|
|||||||
return 0x8000000000000002ULL;
|
return 0x8000000000000002ULL;
|
||||||
if (stat.type == VFS_FT_SYMLINK)
|
if (stat.type == VFS_FT_SYMLINK)
|
||||||
{
|
{
|
||||||
char *link = kmalloc(4096);
|
char *link = (char *) kmalloc(4096);
|
||||||
vfs_link_deref(vfs_inode, link);
|
vfs_link_deref(vfs_inode, link);
|
||||||
if (link[0] == '/')
|
if (link[0] == '/')
|
||||||
vfs_inode = vfs_get_inode_number(link);
|
vfs_inode = vfs_get_inode_number(link);
|
||||||
@ -348,7 +361,7 @@ vfs_open_file_t *vfs_open_dir(char *path)
|
|||||||
vfs_open_file_t *vfs_open_dir_inode(vfs_inode_t vfs_inode)
|
vfs_open_file_t *vfs_open_dir_inode(vfs_inode_t vfs_inode)
|
||||||
{
|
{
|
||||||
vfs_file_addr_t addr = vfs_get_file_addr(vfs_inode);
|
vfs_file_addr_t addr = vfs_get_file_addr(vfs_inode);
|
||||||
vfs_open_file_t *open_dir = New(vfs_open_file_t);
|
vfs_open_file_t *open_dir = (vfs_open_file_t *) New(vfs_open_file_t);
|
||||||
if (fses[addr.mount->fs]->open_dir && !(fses[addr.mount->fs]->open_dir(addr.mount, addr.inode, open_dir)))
|
if (fses[addr.mount->fs]->open_dir && !(fses[addr.mount->fs]->open_dir(addr.mount, addr.inode, open_dir)))
|
||||||
{
|
{
|
||||||
open_dir->mount = addr.mount;
|
open_dir->mount = addr.mount;
|
||||||
@ -384,7 +397,7 @@ vfs_open_file_t *vfs_open_block_file(char *path)
|
|||||||
vfs_open_file_t *vfs_open_block_file_inode(vfs_inode_t vfs_inode)
|
vfs_open_file_t *vfs_open_block_file_inode(vfs_inode_t vfs_inode)
|
||||||
{
|
{
|
||||||
vfs_file_addr_t addr = vfs_get_file_addr(vfs_inode);
|
vfs_file_addr_t addr = vfs_get_file_addr(vfs_inode);
|
||||||
vfs_open_file_t *open_file = New(vfs_open_file_t);
|
vfs_open_file_t *open_file = (vfs_open_file_t *) New(vfs_open_file_t);
|
||||||
if (fses[addr.mount->fs]->open_block_file && !(fses[addr.mount->fs]->open_block_file(addr.mount, addr.inode, open_file)))
|
if (fses[addr.mount->fs]->open_block_file && !(fses[addr.mount->fs]->open_block_file(addr.mount, addr.inode, open_file)))
|
||||||
{
|
{
|
||||||
open_file->mount = addr.mount;
|
open_file->mount = addr.mount;
|
218
kernel/fs/vfs_old.h
Normal file
218
kernel/fs/vfs_old.h
Normal file
@ -0,0 +1,218 @@
|
|||||||
|
// vfs.h
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Date: 08/22/04
|
||||||
|
// Modified: 12/21/04
|
||||||
|
|
||||||
|
#ifndef __HOS_VFS_H__
|
||||||
|
#define __HOS_VFS_H__ __HOS_VFS_H__
|
||||||
|
|
||||||
|
#include "hos_defines.h"
|
||||||
|
#include "fs/devices.h"
|
||||||
|
|
||||||
|
#define FS_EXT2 1
|
||||||
|
#define VFS_MAX_FS 10
|
||||||
|
|
||||||
|
#define VFS_FT_UNKNOWN 0
|
||||||
|
#define VFS_FT_FILE 1
|
||||||
|
#define VFS_FT_DIR 2
|
||||||
|
#define VFS_FT_CHAR 3
|
||||||
|
#define VFS_FT_BLOCK 4
|
||||||
|
#define VFS_FT_FIFO 5
|
||||||
|
#define VFS_FT_SOCK 6
|
||||||
|
#define VFS_FT_SYMLINK 7
|
||||||
|
|
||||||
|
#define VFS_PERMS_OX 0x0001
|
||||||
|
#define VFS_PERMS_OW 0x0002
|
||||||
|
#define VFS_PERMS_OR 0x0004
|
||||||
|
#define VFS_PERMS_GX 0x0008
|
||||||
|
#define VFS_PERMS_GW 0x0010
|
||||||
|
#define VFS_PERMS_GR 0x0020
|
||||||
|
#define VFS_PERMS_UX 0x0040
|
||||||
|
#define VFS_PERMS_UW 0x0080
|
||||||
|
#define VFS_PERMS_UR 0x0100
|
||||||
|
#define VFS_PERMS_STICKY 0x0200
|
||||||
|
#define VFS_PERMS_SGID 0x0400
|
||||||
|
#define VFS_PERMS_SUID 0x0800
|
||||||
|
|
||||||
|
#define EOF 1000000
|
||||||
|
|
||||||
|
typedef u64_t vfs_inode_t;
|
||||||
|
|
||||||
|
/* Structure to hold information about a mount point */
|
||||||
|
struct vfs_mount_s
|
||||||
|
{
|
||||||
|
int refs;
|
||||||
|
void *super;
|
||||||
|
int fs;
|
||||||
|
major_t major;
|
||||||
|
minor_t minor;
|
||||||
|
char *mountPoint;
|
||||||
|
vfs_inode_t vfs_mount_inode;
|
||||||
|
vfs_inode_t vfs_up_inode;
|
||||||
|
vfs_inode_t vfs_root_inode;
|
||||||
|
struct vfs_mount_s *next;
|
||||||
|
struct vfs_mount_s *prev;
|
||||||
|
};
|
||||||
|
typedef struct vfs_mount_s vfs_mount_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
u16_t type; // file type, of VFS_FILE_TYPE_*
|
||||||
|
u32_t size;
|
||||||
|
u32_t inode;
|
||||||
|
u16_t permissions;
|
||||||
|
u16_t uid;
|
||||||
|
u16_t gid;
|
||||||
|
u32_t atime;
|
||||||
|
u32_t mtime;
|
||||||
|
u32_t ctime;
|
||||||
|
u16_t links;
|
||||||
|
u32_t dev;
|
||||||
|
} vfs_stat_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
vfs_mount_t *mount;
|
||||||
|
void *fs_data;
|
||||||
|
} vfs_open_file_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
char name[257];
|
||||||
|
u32_t inode_number; // relative inode number returned from fs
|
||||||
|
} vfs_dir_entry_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
vfs_mount_t *mount;
|
||||||
|
u32_t inode;
|
||||||
|
} vfs_file_addr_t;
|
||||||
|
|
||||||
|
/* Every filesystem must provide pointers to its respective functions in a structure like this */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
void *(*mount_super)(major_t major, minor_t minor);
|
||||||
|
int (*umount_super)(vfs_mount_t *mount);
|
||||||
|
int (*stat)(vfs_mount_t *mount, u32_t inode_number, vfs_stat_t *stat);
|
||||||
|
u32_t (*get_root_inode)(vfs_mount_t *mount);
|
||||||
|
int (*link_deref)(vfs_mount_t *mount, u32_t inode_number, char *link);
|
||||||
|
int (*free_inodes)(vfs_mount_t *mount);
|
||||||
|
int (*total_inodes)(vfs_mount_t *mount);
|
||||||
|
int (*free_blocks)(vfs_mount_t *mount);
|
||||||
|
int (*total_blocks)(vfs_mount_t *mount);
|
||||||
|
|
||||||
|
u32_t (*alloc_inode)(vfs_mount_t *mount);
|
||||||
|
int (*free_inode)(vfs_mount_t *mount, u32_t inode_number);
|
||||||
|
u32_t (*alloc_block)(vfs_mount_t *mount);
|
||||||
|
int (*free_block)(vfs_mount_t *mount, u32_t block_number);
|
||||||
|
|
||||||
|
int (*open_dir)(vfs_mount_t *mount, u32_t inode_number, vfs_open_file_t *dir);
|
||||||
|
int (*read_dir)(vfs_mount_t *mount, vfs_open_file_t *dir, vfs_dir_entry_t *dentry);
|
||||||
|
int (*close_dir)(vfs_mount_t *mount, vfs_open_file_t *dir);
|
||||||
|
|
||||||
|
int (*open_file)(vfs_mount_t *mount, u32_t inode_number, vfs_open_file_t *open_file);
|
||||||
|
int (*read_file)(vfs_mount_t *mount, vfs_open_file_t *open_file);
|
||||||
|
int (*close_file)(vfs_mount_t *mount, vfs_open_file_t *open_file);
|
||||||
|
|
||||||
|
int (*open_block_file)(vfs_mount_t *mount, u32_t inode_number, vfs_open_file_t *open_file);
|
||||||
|
int (*read_block_file)(vfs_mount_t *mount, vfs_open_file_t *open_file, void *buffer);
|
||||||
|
int (*block_file_seek)(vfs_mount_t *mount, vfs_open_file_t *open_file, u32_t block_number);
|
||||||
|
int (*close_block_file)(vfs_mount_t *mount, vfs_open_file_t *open_file);
|
||||||
|
|
||||||
|
} vfs_fs_t;
|
||||||
|
|
||||||
|
|
||||||
|
int vfs_init();
|
||||||
|
int vfs_mount(major_t maj, minor_t min, int fsType, char *mountPoint);
|
||||||
|
int vfs_umount(char *mountPoint);
|
||||||
|
int vfs_register_fs(int fsn, vfs_fs_t *fs);
|
||||||
|
int vfs_umount(char *mountPoint);
|
||||||
|
vfs_inode_t vfs_get_inode_number(char *path);
|
||||||
|
vfs_inode_t vfs_get_inode_number_rel(vfs_inode_t dir_inode, char *path);
|
||||||
|
vfs_inode_t vfs_real_inode(vfs_inode_t vfs_inode);
|
||||||
|
vfs_file_addr_t vfs_get_file_addr(vfs_inode_t vfs_inode);
|
||||||
|
vfs_inode_t vfs_entry_lookup(vfs_inode_t dir_inode, char *entry);
|
||||||
|
|
||||||
|
int vfs_mount_count();
|
||||||
|
vfs_mount_t *vfs_get_mount(int index);
|
||||||
|
int vfs_free_inodes(vfs_mount_t *mount);
|
||||||
|
int vfs_total_inodes(vfs_mount_t *mount);
|
||||||
|
int vfs_free_blocks(vfs_mount_t *mount);
|
||||||
|
int vfs_total_blocks(vfs_mount_t *mount);
|
||||||
|
|
||||||
|
vfs_inode_t vfs_alloc_inode(vfs_mount_t *mount);
|
||||||
|
int vfs_free_inode(vfs_mount_t *mount, u32_t inode_number);
|
||||||
|
u32_t vfs_alloc_block(vfs_mount_t *mount);
|
||||||
|
int vfs_free_block(vfs_mount_t *mount, u32_t block_number);
|
||||||
|
|
||||||
|
|
||||||
|
int vfs_link_deref(vfs_inode_t vfs_inode, char *link);
|
||||||
|
|
||||||
|
int vfs_stat(char *file, vfs_stat_t *stat);
|
||||||
|
int vfs_stat_inode(vfs_inode_t vfs_inode, vfs_stat_t *stat);
|
||||||
|
|
||||||
|
vfs_open_file_t *vfs_open_dir(char *path);
|
||||||
|
vfs_open_file_t *vfs_open_dir_inode(vfs_inode_t inode);
|
||||||
|
int vfs_read_dir(vfs_open_file_t *open_dir, vfs_dir_entry_t *dentry);
|
||||||
|
int vfs_close_dir(vfs_open_file_t *open_dir);
|
||||||
|
|
||||||
|
vfs_open_file_t *vfs_open_block_file(char *file);
|
||||||
|
vfs_open_file_t *vfs_open_block_file_inode(vfs_inode_t vfs_inode);
|
||||||
|
int vfs_read_block_file(vfs_open_file_t *open_file, void *buffer);
|
||||||
|
int vfs_block_file_seek(vfs_open_file_t *open_file, u32_t block_number);
|
||||||
|
int vfs_close_block_file(vfs_open_file_t *open_file);
|
||||||
|
|
||||||
|
#ifdef _HOS_CPP_
|
||||||
|
|
||||||
|
class FileSystem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FileSystem();
|
||||||
|
virtual void out();
|
||||||
|
};
|
||||||
|
|
||||||
|
FileSystem::FileSystem()
|
||||||
|
{
|
||||||
|
kprintf("FileSystem()\n");
|
||||||
|
}
|
||||||
|
void FileSystem::out()
|
||||||
|
{
|
||||||
|
kprintf("I am a FileSystem object.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
class Ext2 : public FileSystem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Ext2();
|
||||||
|
void out();
|
||||||
|
};
|
||||||
|
|
||||||
|
Ext2::Ext2()
|
||||||
|
{
|
||||||
|
kprintf("Ext2()\n");
|
||||||
|
}
|
||||||
|
void Ext2::out()
|
||||||
|
{
|
||||||
|
kprintf("I am an Ext2 object.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
class JoshsFS : public FileSystem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
JoshsFS();
|
||||||
|
void out();
|
||||||
|
};
|
||||||
|
|
||||||
|
JoshsFS::JoshsFS()
|
||||||
|
{
|
||||||
|
kprintf("JoshsFS()\n");
|
||||||
|
}
|
||||||
|
void JoshsFS::out()
|
||||||
|
{
|
||||||
|
kprintf("I am an JoshsFS object.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -11,16 +11,14 @@
|
|||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
#include "mm/mm.h"
|
#include "mm/mm.h"
|
||||||
#include "mm/vmm.h"
|
#include "mm/vmm.h"
|
||||||
#include "char/parallel.h"
|
|
||||||
#include "lang/conv.h"
|
#include "lang/conv.h"
|
||||||
#include "char/vconsole.h"
|
//#include "char/vconsole.h"
|
||||||
#include "fs/devices.h"
|
#include "devices.h"
|
||||||
#include "display/display.h"
|
#include "display/display.h"
|
||||||
#include "display/kout.h"
|
#include "display/kout.h"
|
||||||
#include "sys/io.h"
|
#include "sys/io.h"
|
||||||
#include "sys/pic.h"
|
#include "sys/pic.h"
|
||||||
#include "char/keyboard.h"
|
#include "char/keyboard.h"
|
||||||
#include "fs/devfs.h"
|
|
||||||
#include "block/ramdisk.h"
|
#include "block/ramdisk.h"
|
||||||
#include "fs/vfs.h"
|
#include "fs/vfs.h"
|
||||||
#include "fs/ext2.h"
|
#include "fs/ext2.h"
|
||||||
@ -122,23 +120,23 @@ void k_init()
|
|||||||
case 32:
|
case 32:
|
||||||
vid_mem <<= 2; break;
|
vid_mem <<= 2; break;
|
||||||
}
|
}
|
||||||
|
// map in video memory so we can access the video card's LFB
|
||||||
vmm_mapn(0xF0000000, (u32_t)rm_params.vid_addr, (vid_mem >> 12) + 1);
|
vmm_mapn(0xF0000000, (u32_t)rm_params.vid_addr, (vid_mem >> 12) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
display_init(); // get us some virtual consoles to look at
|
display_init(); // initialize display subsystem
|
||||||
display_activate(11); // activate kernel dump vconsole
|
display_activate(11); // activate kernel dump vconsole
|
||||||
kprintf("HOS v0.16 initializing...\n");
|
kprintf("HOS v0.16 initializing...\n");
|
||||||
kprintf("Kernel load size: %d (0x%x) bytes (%d kb)\n", kernel_size(), kernel_size(), kernel_size() >> 10);
|
kprintf("Kernel load size: %d (0x%x) bytes (%d kb)\n", kernel_size(), kernel_size(), kernel_size() >> 10);
|
||||||
kprintf("Kernel memory size: %d (0x%x) bytes (%d kb)\n", kernel_size_used(), kernel_size_used(), kernel_size_used() >> 10);
|
kprintf("Kernel memory size: %d (0x%x) bytes (%d kb)\n", kernel_size_used(), kernel_size_used(), kernel_size_used() >> 10);
|
||||||
|
|
||||||
k_check(vfs_init(), "vfs_init() failed!");
|
k_check(vfs_init(), "vfs_init() failed!");
|
||||||
k_check(devfs_init(), "devfs_init() failed!");
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < mb_info_block.mods_count; i++)
|
for (i = 0; i < mb_info_block.mods_count; i++)
|
||||||
{
|
{
|
||||||
kprintf("Loaded kernel module %d: 0x%x - 0x%x (%d bytes)\n", i, mb_modules[i].mod_start, mb_modules[i].mod_end, mb_modules[i].mod_end - mb_modules[i].mod_start);
|
kprintf("Loaded kernel module %d: 0x%x - 0x%x (%d bytes)\n", i, mb_modules[i].mod_start, mb_modules[i].mod_end, mb_modules[i].mod_end - mb_modules[i].mod_start);
|
||||||
if (((mb_modules[i].mod_end - mb_modules[i].mod_start) > 1024) &&
|
/* if (((mb_modules[i].mod_end - mb_modules[i].mod_start) > 1024) &&
|
||||||
((ext2_super_block_t *)(mb_modules[i].mod_start + 1024))->s_magic == EXT2_MAGIC)
|
((ext2_super_block_t *)(mb_modules[i].mod_start + 1024))->s_magic == EXT2_MAGIC)
|
||||||
{
|
{
|
||||||
// we found an initrd
|
// we found an initrd
|
||||||
@ -146,9 +144,9 @@ void k_init()
|
|||||||
kprintf("initrd (%dkb) loaded\n", (mb_modules[i].mod_end - mb_modules[i].mod_start) >> 10);
|
kprintf("initrd (%dkb) loaded\n", (mb_modules[i].mod_end - mb_modules[i].mod_start) >> 10);
|
||||||
k_check(vfs_mount(MAJORB_RAMDISK, initrd_minor, FS_EXT2, "/"), "Could not mount initrd to /!");
|
k_check(vfs_mount(MAJORB_RAMDISK, initrd_minor, FS_EXT2, "/"), "Could not mount initrd to /!");
|
||||||
}
|
}
|
||||||
}
|
*/ }
|
||||||
|
|
||||||
vfs_open_file_t *root = vfs_open_dir("////");
|
/* vfs_open_file_t *root = vfs_open_dir("////");
|
||||||
if (root)
|
if (root)
|
||||||
{
|
{
|
||||||
vfs_dir_entry_t dentry;
|
vfs_dir_entry_t dentry;
|
||||||
@ -186,7 +184,7 @@ void k_init()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
kprintf("Error: Could not open directory\n");
|
kprintf("Error: Could not open directory\n");
|
||||||
|
*/
|
||||||
criticalCounter--;
|
criticalCounter--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
kernel/lang/new.cpp
Normal file
25
kernel/lang/new.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Author: Josh Holtrop
|
||||||
|
// Date: 05/10/05
|
||||||
|
// Adds C++ support for new, delete functions
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include "hos_defines.h"
|
||||||
|
#include "mm/vmm.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
//overload the operator "new"
|
||||||
|
void * operator new (u32_t size)
|
||||||
|
{ return kmalloc(size); }
|
||||||
|
|
||||||
|
//overload the operator "new[]"
|
||||||
|
void * operator new[] (u32_t size)
|
||||||
|
{ return kmalloc(size); }
|
||||||
|
|
||||||
|
//overload the operator "delete"
|
||||||
|
void operator delete (void *p)
|
||||||
|
{ kfree(p); }
|
||||||
|
|
||||||
|
//overload the operator "delete[]"
|
||||||
|
void operator delete[] (void *p)
|
||||||
|
{ kfree(p); }
|
258
kernel/lang/string.cpp
Normal file
258
kernel/lang/string.cpp
Normal file
@ -0,0 +1,258 @@
|
|||||||
|
|
||||||
|
// string.cpp
|
||||||
|
// implements c++ string object for HOS
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Date: 06/01/04
|
||||||
|
// Modified: 05/10/05
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include "string.h" //string class declaration
|
||||||
|
#include "lang/lang.h" //memcpy(void *dest, void *src, int n), strlen(char *str)
|
||||||
|
}
|
||||||
|
|
||||||
|
string::string()
|
||||||
|
{
|
||||||
|
myLength = 0;
|
||||||
|
myChars = new char; //myChars must be a valid pointer at all times
|
||||||
|
*myChars = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
string::~string()
|
||||||
|
{
|
||||||
|
delete[] myChars;
|
||||||
|
}
|
||||||
|
|
||||||
|
string::string(const string & orig)
|
||||||
|
{
|
||||||
|
myLength = orig.myLength;
|
||||||
|
myChars = new char[myLength + 1];
|
||||||
|
memcpy(myChars, orig.myChars, myLength + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
string::string(const char *cstring)
|
||||||
|
{
|
||||||
|
myLength = strlen(cstring);
|
||||||
|
myChars = new char[myLength + 1];
|
||||||
|
memcpy(myChars, cstring, myLength + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
string & string::operator=(const string & orig)
|
||||||
|
{
|
||||||
|
if (this != &orig)
|
||||||
|
{
|
||||||
|
delete[] myChars;
|
||||||
|
myLength = orig.myLength;
|
||||||
|
myChars = new char[myLength + 1];
|
||||||
|
memcpy(myChars, orig.myChars, myLength + 1);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
string & string::operator=(const char *cstring)
|
||||||
|
{
|
||||||
|
if (myChars != cstring)
|
||||||
|
{
|
||||||
|
delete[] myChars;
|
||||||
|
myLength = strlen(cstring);
|
||||||
|
myChars = new char[myLength + 1];
|
||||||
|
memcpy(myChars, cstring, myLength + 1);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
char * string::data() const { return myChars; }
|
||||||
|
|
||||||
|
int string::size() const { return myLength; }
|
||||||
|
|
||||||
|
string & string::operator+=(const string & str)
|
||||||
|
{
|
||||||
|
char *newStr = new char[myLength + str.myLength + 1];
|
||||||
|
memcpy(newStr, myChars, myLength);
|
||||||
|
memcpy(newStr + myLength, str.myChars, str.myLength + 1);
|
||||||
|
delete[] myChars;
|
||||||
|
myChars = newStr;
|
||||||
|
myLength += str.myLength;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
string & string::operator+=(const char *cstring)
|
||||||
|
{
|
||||||
|
char *newStr = new char[myLength + strlen(cstring) + 1];
|
||||||
|
memcpy(newStr, myChars, myLength);
|
||||||
|
memcpy(newStr + myLength, cstring, strlen(cstring) + 1);
|
||||||
|
delete[] myChars;
|
||||||
|
myChars = newStr;
|
||||||
|
myLength += strlen(cstring);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
string & string::operator+=(char chr)
|
||||||
|
{
|
||||||
|
myLength++;
|
||||||
|
char *newStr = new char[myLength + 1];
|
||||||
|
memcpy(newStr, myChars, myLength);
|
||||||
|
newStr[myLength - 1] = chr;
|
||||||
|
newStr[myLength] = 0;
|
||||||
|
delete[] myChars;
|
||||||
|
myChars = newStr;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string string::operator+(const string & str)
|
||||||
|
{ return string(*this, str); }
|
||||||
|
|
||||||
|
string string::operator+(const char *cstring)
|
||||||
|
{ return string(*this, cstring); }
|
||||||
|
|
||||||
|
string string::operator+(char chr)
|
||||||
|
{ return string(*this, chr); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
string::string(const string & str1, const string & str2)
|
||||||
|
{
|
||||||
|
myLength = str1.myLength + str2.myLength;
|
||||||
|
myChars = new char[myLength + 1];
|
||||||
|
memcpy(myChars, str1.myChars, str1.myLength);
|
||||||
|
memcpy(myChars + str1.myLength, str2.myChars, str2.myLength + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
string::string(const string & str1, const char *cstring)
|
||||||
|
{
|
||||||
|
myLength = str1.myLength + strlen(cstring);
|
||||||
|
myChars = new char[myLength + 1];
|
||||||
|
memcpy(myChars, str1.myChars, str1.myLength);
|
||||||
|
memcpy(myChars + str1.myLength, cstring, strlen(cstring) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
string::string(const char *cstring, const string & str)
|
||||||
|
{
|
||||||
|
myLength = str.myLength + strlen(cstring);
|
||||||
|
myChars = new char[myLength + 1];
|
||||||
|
memcpy(myChars, cstring, strlen(cstring));
|
||||||
|
memcpy(myChars + strlen(cstring), str.myChars, str.myLength + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
string::string(const string & str1, char chr)
|
||||||
|
{
|
||||||
|
myLength = str1.myLength + 1;
|
||||||
|
myChars = new char[myLength + 1];
|
||||||
|
memcpy(myChars, str1.myChars, myLength);
|
||||||
|
myChars[myLength - 1] = chr;
|
||||||
|
myChars[myLength] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
string::string(char chr, const string & str1)
|
||||||
|
{
|
||||||
|
myLength = str1.myLength + 1;
|
||||||
|
myChars = new char[myLength + 1];
|
||||||
|
memcpy(myChars + 1, str1.myChars, myLength + 1);
|
||||||
|
*myChars = chr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char & string::operator[](unsigned int index) const
|
||||||
|
{
|
||||||
|
if (index < myLength)
|
||||||
|
return myChars[index];
|
||||||
|
return *myChars; //if index is invalid, return a pointer to the trailing 0
|
||||||
|
}
|
||||||
|
|
||||||
|
char & string::operator[](unsigned int index)
|
||||||
|
{
|
||||||
|
if (index < myLength)
|
||||||
|
return myChars[index];
|
||||||
|
return *myChars; //if index is invalid, return a pointer to the trailing 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool string::operator==(const string & second) const
|
||||||
|
{
|
||||||
|
if (myLength != second.myLength)
|
||||||
|
return false;
|
||||||
|
for (unsigned int i = 0; i < myLength; i++)
|
||||||
|
{
|
||||||
|
if (myChars[i] != second.myChars[i])
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool string::operator==(const char *cstring) const
|
||||||
|
{
|
||||||
|
if (myLength != strlen(cstring))
|
||||||
|
return false;
|
||||||
|
for (unsigned int i = 0; i < myLength; i++)
|
||||||
|
{
|
||||||
|
if (myChars[i] != cstring[i])
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool string::operator!=(const string & second) const
|
||||||
|
{ return !operator==(second); }
|
||||||
|
|
||||||
|
bool string::operator!=(const char *cstring) const
|
||||||
|
{ return !operator==(cstring); }
|
||||||
|
|
||||||
|
bool string::operator<(const string & second) const
|
||||||
|
{
|
||||||
|
char *c1 = myChars, *c2 = second.myChars;
|
||||||
|
while (*c1 == *c2 && *c1)
|
||||||
|
{
|
||||||
|
c1++;
|
||||||
|
c2++;
|
||||||
|
}
|
||||||
|
return *c1 < *c2;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool string::operator>(const string & second) const
|
||||||
|
{
|
||||||
|
char *c1 = myChars, *c2 = second.myChars;
|
||||||
|
while (*c1 == *c2 && *c1)
|
||||||
|
{
|
||||||
|
c1++;
|
||||||
|
c2++;
|
||||||
|
}
|
||||||
|
return *c1 > *c2;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool string::operator<(const char *cstring) const
|
||||||
|
{
|
||||||
|
char *c1 = myChars;
|
||||||
|
while (*c1 == *cstring && *c1)
|
||||||
|
{
|
||||||
|
c1++;
|
||||||
|
cstring++;
|
||||||
|
}
|
||||||
|
return *c1 < *cstring;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool string::operator>(const char *cstring) const
|
||||||
|
{
|
||||||
|
char *c1 = myChars;
|
||||||
|
while (*c1 == *cstring && *c1)
|
||||||
|
{
|
||||||
|
c1++;
|
||||||
|
cstring++;
|
||||||
|
}
|
||||||
|
return *c1 > *cstring;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool string::operator<=(const string & second) const
|
||||||
|
{ return !operator>(second); }
|
||||||
|
|
||||||
|
bool string::operator>=(const string & second) const
|
||||||
|
{ return !operator<(second); }
|
||||||
|
|
||||||
|
bool string::operator<=(const char *cstring) const
|
||||||
|
{ return operator<(cstring) || operator==(cstring); }
|
||||||
|
|
||||||
|
bool string::operator>=(const char *cstring) const
|
||||||
|
{ return operator>(cstring) || operator==(cstring); }
|
||||||
|
|
||||||
|
|
||||||
|
|
107
kernel/lang/string.h
Normal file
107
kernel/lang/string.h
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
|
||||||
|
// string.h
|
||||||
|
// implements c++ string object for HOS
|
||||||
|
// Author: Josh Holtrop
|
||||||
|
// Date: 06/01/04
|
||||||
|
// Modified: 05/10/05
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __HOS_STRING__
|
||||||
|
#define __HOS_STRING__ __HOS_STRING__
|
||||||
|
|
||||||
|
class string
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
/* myChars is a pointer to a character array
|
||||||
|
* It will always be a valid pointer, not null.
|
||||||
|
* The constructor is responsible for initializing
|
||||||
|
* it to point to a 1-char array with myChars[0] == 0 */
|
||||||
|
char * myChars;
|
||||||
|
|
||||||
|
/* myLength holds how many characters are in the
|
||||||
|
* string, not including the trailing null value
|
||||||
|
* (ASCII 0 character) */
|
||||||
|
unsigned int myLength;
|
||||||
|
public:
|
||||||
|
/* Basic constructors */
|
||||||
|
string();
|
||||||
|
~string();
|
||||||
|
|
||||||
|
/* Copy constructor */
|
||||||
|
string(const string & orig);
|
||||||
|
|
||||||
|
/* Construct strings from c-style strings:
|
||||||
|
* Allows declarations like string s = "data"; */
|
||||||
|
string(const char *cstring);
|
||||||
|
|
||||||
|
/* Assignment operators */
|
||||||
|
string & operator=(const string & orig);
|
||||||
|
string & operator=(const char *cstring);
|
||||||
|
|
||||||
|
/* Boolean comparison operators */
|
||||||
|
bool operator==(const string & second) const;
|
||||||
|
bool operator==(const char *cstring) const;
|
||||||
|
bool operator!=(const string & second) const;
|
||||||
|
bool operator!=(const char *cstring) const;
|
||||||
|
bool operator<(const string & second) const;
|
||||||
|
bool operator>(const string & second) const;
|
||||||
|
bool operator<(const char *cstring) const;
|
||||||
|
bool operator>(const char *cstring) const;
|
||||||
|
bool operator<=(const string & second) const;
|
||||||
|
bool operator>=(const string & second) const;
|
||||||
|
bool operator<=(const char *cstring) const;
|
||||||
|
bool operator>=(const char *cstring) const;
|
||||||
|
|
||||||
|
/* Construct strings made up of combinations of other
|
||||||
|
* strings, c-style strings, and characters */
|
||||||
|
string(const string & str1, const string & str2);
|
||||||
|
string(const string & str1, const char *cstring);
|
||||||
|
string(const char *cstring, const string & str);
|
||||||
|
string(const string & str1, char chr);
|
||||||
|
string(char chr, const string & str1);
|
||||||
|
|
||||||
|
/* Append operators */
|
||||||
|
string & operator+=(const string & str);
|
||||||
|
string & operator+=(const char *cstring);
|
||||||
|
string & operator+=(char chr);
|
||||||
|
|
||||||
|
string operator+(const string & str);
|
||||||
|
string operator+(const char *cstring);
|
||||||
|
string operator+(char chr);
|
||||||
|
|
||||||
|
/* Direct character-access operators */
|
||||||
|
const char & operator[](unsigned int index) const;
|
||||||
|
char & operator[](unsigned int index);
|
||||||
|
|
||||||
|
/* Returns handle to actual character-array for programs
|
||||||
|
* that need raw data instead of a string object */
|
||||||
|
char * data() const;
|
||||||
|
|
||||||
|
/* Returns the size of the string. This is myLength
|
||||||
|
* and is the number of characters in the string
|
||||||
|
* not counting the trailing null (ASCII 0) character */
|
||||||
|
int size() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static inline bool operator==(char *cstring, const string & str)
|
||||||
|
{ return str == cstring; }
|
||||||
|
|
||||||
|
static inline bool operator!=(char *cstring, const string & str)
|
||||||
|
{ return str != cstring; }
|
||||||
|
|
||||||
|
static inline bool operator<(const char *cstring, const string & str)
|
||||||
|
{ return str > cstring; }
|
||||||
|
|
||||||
|
static inline bool operator>(const char *cstring, const string & str)
|
||||||
|
{ return str < cstring; }
|
||||||
|
|
||||||
|
static inline bool operator<=(const char *cstring, const string & str)
|
||||||
|
{ return str >= cstring; }
|
||||||
|
|
||||||
|
static inline bool operator>=(const char *cstring, const string & str)
|
||||||
|
{ return str <= cstring; }
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -1,7 +1,8 @@
|
|||||||
NASM=nasm
|
NASM=nasm
|
||||||
|
|
||||||
all:
|
all:
|
||||||
$(NASM) -f bin rmmod.asm -l rmmod.lst -o rmmod.bin
|
@echo ' $$(NASM) rmmod.bin'
|
||||||
|
@$(NASM) -f bin rmmod.asm -l rmmod.lst -o rmmod.bin
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -f *~ *.o *.bin *.lst
|
-rm -f *~ *.o *.bin *.lst
|
||||||
|
Loading…
x
Reference in New Issue
Block a user