Import backup from 2005-08-17

This commit is contained in:
josh committed 2017-07-25 22:23:50 -04:00
1 parent 2cefd9441c
commit e1682a2fe7
10 files changed
+141 -84

No files matched your search

+1 -2
View File
@@ -7,7 +7,7 @@
#include "FileSystem.h"
#include "hos_defines.h"
FileSystem::FileSystem() {myError = -10278;}
FileSystem::FileSystem() {}
FileSystem::~FileSystem() {}
u32_t FileSystem::totalBlocks(){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::freeInodes(){return 0;};
u32_t FileSystem::getRootInodeNumber(){return 0;};
int FileSystem::check(){return myError;};
-6
View File
@@ -12,12 +12,8 @@
class FileSystem
{
protected:
int myError;
device_t myDevice;
public:
FileSystem();
FileSystem(device_t dev);
virtual ~FileSystem();
virtual u32_t totalBlocks(); /* 512 byte blocks */
@@ -29,8 +25,6 @@ public:
virtual u32_t freeInodes();
virtual u32_t getRootInodeNumber();
virtual int check();
};
#endif
+32 -13
View File
@@ -8,26 +8,45 @@
extern "C" {
#include "display/kout.h"
#include "mm/vmm.h"
#include "lang/lang.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;
if (block_read(DEV_MAJOR(dev), DEV_MINOR(dev), 2, 2, &mySuper) < 1024)
{
myError = -1;
return;
}
if (mySuper.s_magic != EXT2_MAGIC)
{
myError = -2;
return;
}
myError = 0;
memcpy(&mySuper, super, sizeof(ext2_super_block_t));
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()
+17 -11
View File
@@ -41,6 +41,7 @@
#define EXT2_I_FLAGS_APPEND 0x20
#define EXT2_I_FLAGS_NODUMP 0x40
/* ext2 standard inode numbers */
#define EXT2_INODE_BAD_BLOCKS 1
#define EXT2_INODE_ROOT 2
#define EXT2_INODE_ACL_INDEX 3
@@ -49,15 +50,16 @@
#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
/* The directory entry file type field values */
#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
#include "fs/vfs.h"
@@ -140,13 +142,17 @@ typedef struct
#ifdef _HOS_CPP_
int ext2_init();
FileSystem *ext2__mount_func(device_t dev);
class Ext2fs : public FileSystem
{
protected:
device_t myDevice;
int mySuperDirty;
ext2_super_block_t mySuper;
int mySuperDirty;
public:
Ext2fs(device_t dev);
Ext2fs(ext2_super_block_t *super, device_t dev);
~Ext2fs();
};
+32 -17
View File
@@ -21,16 +21,32 @@ extern "C" {
inode_num_t rootInode;
vector<VFSMount> *mountPoints;
vector<FSHandle> *fses;
int vfs_init()
{
mountPoints = new vector<VFSMount>;
fses = new vector<FSHandle>;
ext2_init();
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 fsName(fsType);
if (!vfs_get_mount_func(fsName))
return -501;
if (mountPt == "/")
{
if (mountPoints->size())
@@ -47,27 +63,26 @@ int vfs_mount(device_t device, int fsType, char *mountPoint)
}
else
{
// TODO: mount a second filesystem
}
return 500;
}
FileSystem *vfs_attempt_mount(device_t device, int fsType)
FileSystem *vfs_attempt_mount(device_t device, char *fsType)
{
FileSystem *fs;
switch (fsType)
{
case FS_EXT2:
fs = new Ext2fs(device);
break;
default:
mount_func_t mount_func;
if (( mount_func = vfs_get_mount_func(string(fsType)) ))
return mount_func(device);
else
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;
}
+14 -7
View File
@@ -7,9 +7,6 @@
#ifndef __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_FILE 1
#define VFS_FT_DIR 2
@@ -37,14 +34,14 @@
#include "hos_defines.h"
#include "devices.h"
typedef u64_t inode_num_t;
#ifdef _HOS_CPP_
extern "C" {
#endif
typedef u64_t inode_num_t;
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_
}
@@ -53,7 +50,17 @@ int vfs_mount(device_t device, int fsType, char *mountPoint);
#include "fs/FileSystem.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
+11 -12
View File
@@ -39,21 +39,20 @@
typedef u64_t vfs_inode_t;
/* Structure to hold information about a mount point */
struct vfs_mount_s
typedef 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;
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;
} vfs_mount_t;
typedef struct
{