Import backup from 2005-08-17
This commit is contained in:
parent
2cefd9441c
commit
e1682a2fe7
@ -1,2 +1,2 @@
|
|||||||
To build the HOS kernel, just run 'make'
|
To build the HOS kernel, just run 'make'
|
||||||
To build a HOS floppy image for bochs, run 'make initrd' and 'make install_img' as root (root permissions needed to mount floppy image)
|
To build a HOS floppy image for bochs, run 'make initrd' and 'make install_img'. You will need root permissions to mount the ext2 image. This can be accomplished my setting the MOUNT variable to "sudo mount" in the Makefile or by running the last two mount commands as root.
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "hos_defines.h"
|
#include "hos_defines.h"
|
||||||
|
|
||||||
FileSystem::FileSystem() {myError = -10278;}
|
FileSystem::FileSystem() {}
|
||||||
FileSystem::~FileSystem() {}
|
FileSystem::~FileSystem() {}
|
||||||
u32_t FileSystem::totalBlocks(){return 0;}
|
u32_t FileSystem::totalBlocks(){return 0;}
|
||||||
u32_t FileSystem::usedBlocks(){return 0;};
|
u32_t FileSystem::usedBlocks(){return 0;};
|
||||||
@ -16,4 +16,3 @@ u32_t FileSystem::totalInodes(){return 0;};
|
|||||||
u32_t FileSystem::usedInodes(){return 0;};
|
u32_t FileSystem::usedInodes(){return 0;};
|
||||||
u32_t FileSystem::freeInodes(){return 0;};
|
u32_t FileSystem::freeInodes(){return 0;};
|
||||||
u32_t FileSystem::getRootInodeNumber(){return 0;};
|
u32_t FileSystem::getRootInodeNumber(){return 0;};
|
||||||
int FileSystem::check(){return myError;};
|
|
||||||
|
@ -12,12 +12,8 @@
|
|||||||
|
|
||||||
class FileSystem
|
class FileSystem
|
||||||
{
|
{
|
||||||
protected:
|
|
||||||
int myError;
|
|
||||||
device_t myDevice;
|
|
||||||
public:
|
public:
|
||||||
FileSystem();
|
FileSystem();
|
||||||
FileSystem(device_t dev);
|
|
||||||
virtual ~FileSystem();
|
virtual ~FileSystem();
|
||||||
|
|
||||||
virtual u32_t totalBlocks(); /* 512 byte blocks */
|
virtual u32_t totalBlocks(); /* 512 byte blocks */
|
||||||
@ -29,8 +25,6 @@ public:
|
|||||||
virtual u32_t freeInodes();
|
virtual u32_t freeInodes();
|
||||||
|
|
||||||
virtual u32_t getRootInodeNumber();
|
virtual u32_t getRootInodeNumber();
|
||||||
|
|
||||||
virtual int check();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,26 +8,45 @@
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "display/kout.h"
|
#include "display/kout.h"
|
||||||
|
#include "mm/vmm.h"
|
||||||
|
#include "lang/lang.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "ext2.h"
|
#include "ext2.h"
|
||||||
|
|
||||||
Ext2fs::Ext2fs(device_t dev)
|
int ext2_init()
|
||||||
|
{
|
||||||
|
vfs_register("ext2", ext2__mount_func);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileSystem *ext2__mount_func(device_t dev)
|
||||||
|
{
|
||||||
|
ext2_super_block_t *super =
|
||||||
|
(ext2_super_block_t *) New(ext2_super_block_t);
|
||||||
|
if ( (block_read(DEV_MAJOR(dev), DEV_MINOR(dev), 2, 2, super) < 1024)
|
||||||
|
|| (super->s_magic != EXT2_MAGIC) )
|
||||||
|
{
|
||||||
|
kfree(super);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
Ext2fs *fs = new Ext2fs(super, dev);
|
||||||
|
kfree(super);
|
||||||
|
return fs;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ext2fs::Ext2fs(ext2_super_block_t *super, device_t dev)
|
||||||
{
|
{
|
||||||
myDevice = dev;
|
myDevice = dev;
|
||||||
if (block_read(DEV_MAJOR(dev), DEV_MINOR(dev), 2, 2, &mySuper) < 1024)
|
memcpy(&mySuper, super, sizeof(ext2_super_block_t));
|
||||||
{
|
|
||||||
myError = -1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (mySuper.s_magic != EXT2_MAGIC)
|
|
||||||
{
|
|
||||||
myError = -2;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
myError = 0;
|
|
||||||
mySuperDirty = 0;
|
mySuperDirty = 0;
|
||||||
kprintf("Device: %d\n", myDevice);
|
kprintf("Blocks: %d (%d free), Inodes: %d (%d free) Creator OS:\n",
|
||||||
|
mySuper.s_blocks_count,
|
||||||
|
mySuper.s_free_blocks_count,
|
||||||
|
mySuper.s_inodes_count,
|
||||||
|
mySuper.s_free_inodes_count,
|
||||||
|
mySuper.s_creator_os);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ext2fs::~Ext2fs()
|
Ext2fs::~Ext2fs()
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#define EXT2_I_FLAGS_APPEND 0x20
|
#define EXT2_I_FLAGS_APPEND 0x20
|
||||||
#define EXT2_I_FLAGS_NODUMP 0x40
|
#define EXT2_I_FLAGS_NODUMP 0x40
|
||||||
|
|
||||||
|
/* ext2 standard inode numbers */
|
||||||
#define EXT2_INODE_BAD_BLOCKS 1
|
#define EXT2_INODE_BAD_BLOCKS 1
|
||||||
#define EXT2_INODE_ROOT 2
|
#define EXT2_INODE_ROOT 2
|
||||||
#define EXT2_INODE_ACL_INDEX 3
|
#define EXT2_INODE_ACL_INDEX 3
|
||||||
@ -49,6 +50,7 @@
|
|||||||
#define EXT2_INODE_UNDELETE_DIR 6
|
#define EXT2_INODE_UNDELETE_DIR 6
|
||||||
#define EXT2_INODE_AVAIL 11
|
#define EXT2_INODE_AVAIL 11
|
||||||
|
|
||||||
|
/* The directory entry file type field values */
|
||||||
#define EXT2_FT_UNKNOWN 0
|
#define EXT2_FT_UNKNOWN 0
|
||||||
#define EXT2_FT_FILE 1
|
#define EXT2_FT_FILE 1
|
||||||
#define EXT2_FT_DIR 2
|
#define EXT2_FT_DIR 2
|
||||||
@ -140,13 +142,17 @@ typedef struct
|
|||||||
|
|
||||||
#ifdef _HOS_CPP_
|
#ifdef _HOS_CPP_
|
||||||
|
|
||||||
|
int ext2_init();
|
||||||
|
FileSystem *ext2__mount_func(device_t dev);
|
||||||
|
|
||||||
class Ext2fs : public FileSystem
|
class Ext2fs : public FileSystem
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
ext2_super_block_t mySuper;
|
device_t myDevice;
|
||||||
int mySuperDirty;
|
int mySuperDirty;
|
||||||
|
ext2_super_block_t mySuper;
|
||||||
public:
|
public:
|
||||||
Ext2fs(device_t dev);
|
Ext2fs(ext2_super_block_t *super, device_t dev);
|
||||||
~Ext2fs();
|
~Ext2fs();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,16 +21,32 @@ extern "C" {
|
|||||||
|
|
||||||
inode_num_t rootInode;
|
inode_num_t rootInode;
|
||||||
vector<VFSMount> *mountPoints;
|
vector<VFSMount> *mountPoints;
|
||||||
|
vector<FSHandle> *fses;
|
||||||
|
|
||||||
int vfs_init()
|
int vfs_init()
|
||||||
{
|
{
|
||||||
mountPoints = new vector<VFSMount>;
|
mountPoints = new vector<VFSMount>;
|
||||||
|
fses = new vector<FSHandle>;
|
||||||
|
ext2_init();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vfs_mount(device_t device, int fsType, char *mountPoint)
|
int vfs_register(char *fs, FileSystem *(*mount_func)(device_t))
|
||||||
|
{
|
||||||
|
string fsName(fs);
|
||||||
|
if (vfs_get_mount_func(fsName))
|
||||||
|
return -1;
|
||||||
|
FSHandle fsh = {fsName, mount_func};
|
||||||
|
fses->add(fsh);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int vfs_mount(device_t device, char *fsType, char *mountPoint)
|
||||||
{
|
{
|
||||||
string mountPt(mountPoint);
|
string mountPt(mountPoint);
|
||||||
|
string fsName(fsType);
|
||||||
|
if (!vfs_get_mount_func(fsName))
|
||||||
|
return -501;
|
||||||
if (mountPt == "/")
|
if (mountPt == "/")
|
||||||
{
|
{
|
||||||
if (mountPoints->size())
|
if (mountPoints->size())
|
||||||
@ -47,27 +63,26 @@ int vfs_mount(device_t device, int fsType, char *mountPoint)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// TODO: mount a second filesystem
|
||||||
}
|
}
|
||||||
return 500;
|
return 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSystem *vfs_attempt_mount(device_t device, int fsType)
|
FileSystem *vfs_attempt_mount(device_t device, char *fsType)
|
||||||
{
|
{
|
||||||
FileSystem *fs;
|
mount_func_t mount_func;
|
||||||
switch (fsType)
|
if (( mount_func = vfs_get_mount_func(string(fsType)) ))
|
||||||
{
|
return mount_func(device);
|
||||||
case FS_EXT2:
|
else
|
||||||
fs = new Ext2fs(device);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (fs->check())
|
|
||||||
{
|
|
||||||
delete fs;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return fs;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
mount_func_t vfs_get_mount_func(const string & fsName)
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < fses->size(); i++)
|
||||||
|
{
|
||||||
|
if (fsName == (*fses)[i].name)
|
||||||
|
return (*fses)[i].mount_func;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
@ -7,9 +7,6 @@
|
|||||||
#ifndef __HOS_VFS_H__
|
#ifndef __HOS_VFS_H__
|
||||||
#define __HOS_VFS_H__ __HOS_VFS_H__
|
#define __HOS_VFS_H__ __HOS_VFS_H__
|
||||||
|
|
||||||
#define FS_EXT2 1
|
|
||||||
#define FS_MAX 5
|
|
||||||
|
|
||||||
#define VFS_FT_UNKNOWN 0
|
#define VFS_FT_UNKNOWN 0
|
||||||
#define VFS_FT_FILE 1
|
#define VFS_FT_FILE 1
|
||||||
#define VFS_FT_DIR 2
|
#define VFS_FT_DIR 2
|
||||||
@ -37,14 +34,14 @@
|
|||||||
#include "hos_defines.h"
|
#include "hos_defines.h"
|
||||||
#include "devices.h"
|
#include "devices.h"
|
||||||
|
|
||||||
|
typedef u64_t inode_num_t;
|
||||||
|
|
||||||
#ifdef _HOS_CPP_
|
#ifdef _HOS_CPP_
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef u64_t inode_num_t;
|
|
||||||
|
|
||||||
int vfs_init();
|
int vfs_init();
|
||||||
int vfs_mount(device_t device, int fsType, char *mountPoint);
|
int vfs_mount(device_t device, char *fsType, char *mountPoint);
|
||||||
|
|
||||||
#ifdef _HOS_CPP_
|
#ifdef _HOS_CPP_
|
||||||
}
|
}
|
||||||
@ -53,7 +50,17 @@ int vfs_mount(device_t device, int fsType, char *mountPoint);
|
|||||||
#include "fs/FileSystem.h"
|
#include "fs/FileSystem.h"
|
||||||
#include "fs/VFSMount.h"
|
#include "fs/VFSMount.h"
|
||||||
|
|
||||||
FileSystem *vfs_attempt_mount(device_t device, int fsType);
|
typedef FileSystem *(*mount_func_t)(device_t);
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
string name;
|
||||||
|
mount_func_t mount_func;
|
||||||
|
} FSHandle;
|
||||||
|
|
||||||
|
FileSystem *vfs_attempt_mount(device_t device, char *fsType);
|
||||||
|
int vfs_register(char *fs, FileSystem *(*mount_func)(device_t));
|
||||||
|
mount_func_t vfs_get_mount_func(const string & fsName);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
typedef u64_t vfs_inode_t;
|
typedef u64_t vfs_inode_t;
|
||||||
|
|
||||||
/* Structure to hold information about a mount point */
|
/* Structure to hold information about a mount point */
|
||||||
struct vfs_mount_s
|
typedef struct vfs_mount_s
|
||||||
{
|
{
|
||||||
int refs;
|
int refs;
|
||||||
void *super;
|
void *super;
|
||||||
@ -52,8 +52,7 @@ struct vfs_mount_s
|
|||||||
vfs_inode_t vfs_root_inode;
|
vfs_inode_t vfs_root_inode;
|
||||||
struct vfs_mount_s *next;
|
struct vfs_mount_s *next;
|
||||||
struct vfs_mount_s *prev;
|
struct vfs_mount_s *prev;
|
||||||
};
|
} vfs_mount_t;
|
||||||
typedef struct vfs_mount_s vfs_mount_t;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
@ -141,7 +141,7 @@ void k_init()
|
|||||||
// we found an initrd
|
// we found an initrd
|
||||||
minor_t initrd_minor = ramdisk_register((void *)mb_modules[i].mod_start, mb_modules[i].mod_end - mb_modules[i].mod_start);
|
minor_t initrd_minor = ramdisk_register((void *)mb_modules[i].mod_start, mb_modules[i].mod_end - mb_modules[i].mod_start);
|
||||||
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(DEV(MAJOR_RAMDISK, initrd_minor), FS_EXT2, "/"), "Could not mount initrd to /!");
|
k_check(vfs_mount(DEV(MAJOR_RAMDISK, initrd_minor), "ext2", "/"), "Kernel panic: Could not mount initrd to /!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +184,6 @@ void k_init()
|
|||||||
else
|
else
|
||||||
kprintf("Error: Could not open directory\n");
|
kprintf("Error: Could not open directory\n");
|
||||||
*/
|
*/
|
||||||
|
|
||||||
criticalCounter--;
|
criticalCounter--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Author: Josh Holtrop
|
// Author: Josh Holtrop
|
||||||
// Date: 09/30/03
|
// Date: 09/30/03
|
||||||
// Rewritten from scratch: 12/23/03
|
// Rewritten from scratch: 12/23/03
|
||||||
// Modified: 07/30/04
|
// Modified: 08/17/05
|
||||||
|
|
||||||
#include "hos_defines.h"
|
#include "hos_defines.h"
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
@ -18,6 +18,7 @@ int vmm_coalesceEntry(u32_t queue, HeapEntry_t *newHE);
|
|||||||
void vmm_heb_init(HeapEntryBlock_t *heb);
|
void vmm_heb_init(HeapEntryBlock_t *heb);
|
||||||
void vmm_addToQueue(u32_t queue, HeapEntry_t *preceeding, HeapEntry_t *he);
|
void vmm_addToQueue(u32_t queue, HeapEntry_t *preceeding, HeapEntry_t *he);
|
||||||
int vmm_countHeapEntries(HeapEntry_t *he);
|
int vmm_countHeapEntries(HeapEntry_t *he);
|
||||||
|
int vmm_unmapp(void *addr);
|
||||||
HeapEntry_t *vmm_followChain(HeapEntry_t *he);
|
HeapEntry_t *vmm_followChain(HeapEntry_t *he);
|
||||||
HeapEntry_t *vmm_getUnusedEntry();
|
HeapEntry_t *vmm_getUnusedEntry();
|
||||||
HeapEntry_t *vmm_stripUnusedEntry();
|
HeapEntry_t *vmm_stripUnusedEntry();
|
||||||
@ -101,10 +102,13 @@ int vmm_mapn(u32_t virt, u32_t physical, u32_t n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// This function removes the virtual address's entry in the page directory / page table
|
// This function removes the virtual address's entry in the
|
||||||
|
// page directory / page table
|
||||||
void vmm_unmap1(u32_t virt)
|
void vmm_unmap1(u32_t virt)
|
||||||
{
|
{
|
||||||
*(u32_t *)(0xFFC00000 | ((virt & 0xFFC00000) >> 10) | ((virt & 0x003FF000) >> 10)) = 0;
|
*(u32_t *)(0xFFC00000 |
|
||||||
|
((virt & 0xFFC00000) >> 10) |
|
||||||
|
((virt & 0x003FF000) >> 10)) = 0;
|
||||||
invlpg_(virt);
|
invlpg_(virt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +147,8 @@ void *kmalloc(u32_t size)
|
|||||||
{
|
{
|
||||||
k_enter_critical();
|
k_enter_critical();
|
||||||
if (size % VMM_MALLOC_GRANULARITY)
|
if (size % VMM_MALLOC_GRANULARITY)
|
||||||
size = size + VMM_MALLOC_GRANULARITY - (size % VMM_MALLOC_GRANULARITY);
|
size = size + VMM_MALLOC_GRANULARITY -
|
||||||
|
(size % VMM_MALLOC_GRANULARITY);
|
||||||
void *attempt = vmm_getFreeChunk(size);
|
void *attempt = vmm_getFreeChunk(size);
|
||||||
if (attempt)
|
if (attempt)
|
||||||
{
|
{
|
||||||
@ -196,7 +201,8 @@ void *vmm_palloc()
|
|||||||
{
|
{
|
||||||
vmm_removeHeapEntry(VMM_HE_HOLE, he);
|
vmm_removeHeapEntry(VMM_HE_HOLE, he);
|
||||||
vmm_addToQueue(VMM_HE_USED, &heapEntryHeadNodes[VMM_HE_USED], he);
|
vmm_addToQueue(VMM_HE_USED, &heapEntryHeadNodes[VMM_HE_USED], he);
|
||||||
vmm_map(he->base);
|
if (vmm_map(he->base))
|
||||||
|
he->base = NULL;
|
||||||
k_leave_critical();
|
k_leave_critical();
|
||||||
return he->base;
|
return he->base;
|
||||||
}
|
}
|
||||||
@ -214,7 +220,8 @@ void *vmm_palloc()
|
|||||||
he->base = wilderness->base + wilderness->length;
|
he->base = wilderness->base + wilderness->length;
|
||||||
he->length = 4096;
|
he->length = 4096;
|
||||||
vmm_addToQueue(VMM_HE_USED, &heapEntryHeadNodes[VMM_HE_USED], he);
|
vmm_addToQueue(VMM_HE_USED, &heapEntryHeadNodes[VMM_HE_USED], he);
|
||||||
vmm_map(he->base);
|
if (vmm_map(he->base))
|
||||||
|
he->base = NULL;
|
||||||
k_leave_critical();
|
k_leave_critical();
|
||||||
return he->base;
|
return he->base;
|
||||||
}
|
}
|
||||||
@ -223,6 +230,18 @@ void *vmm_palloc()
|
|||||||
// This function frees a previously-allocated virtual page
|
// This function frees a previously-allocated virtual page
|
||||||
int vmm_pfree(void *addr)
|
int vmm_pfree(void *addr)
|
||||||
{
|
{
|
||||||
|
u32_t pbase = *(u32_t *)(0xFFC00000 |
|
||||||
|
(((u32_t)addr & 0xFFC00000) >> 10) |
|
||||||
|
(((u32_t)addr & 0x003FF000) >> 10));
|
||||||
|
if (vmm_unmapp(addr))
|
||||||
|
return -1;
|
||||||
|
mm_pfree(pbase);
|
||||||
|
}
|
||||||
|
|
||||||
|
int vmm_unmapp(void *addr)
|
||||||
|
{
|
||||||
|
if (!addr)
|
||||||
|
return -2;
|
||||||
k_enter_critical();
|
k_enter_critical();
|
||||||
HeapEntry_t *he = heapEntryQueues[VMM_HE_USED].head->next;
|
HeapEntry_t *he = heapEntryQueues[VMM_HE_USED].head->next;
|
||||||
while (he->next)
|
while (he->next)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user