Import backup from 2004-12-20
This commit is contained in:
1 parent
3c531f3b7b
commit
2445034e43
15 files changed
+409
-75
No files matched your search
+9
-2
@@ -7,10 +7,17 @@
|
||||
#include "fs/devfs.h"
|
||||
#include "fs/devices.h"
|
||||
#include "fs/vfs.h"
|
||||
#include "block/ramdisk.h"
|
||||
|
||||
void devfs_init(minor_t rd_minor)
|
||||
int devfs_init()
|
||||
{
|
||||
// vfs_mount(MAJORB_RAMDISK, rd_minor, FS_EXT2, "/dev");
|
||||
minor_t devfs_minor = ramdisk_new(DEVFS_SIZE);
|
||||
if (devfs_minor < 0)
|
||||
return -1;
|
||||
// ext2_mkfs(MAJORB_RAMDISK, devfs_minor);
|
||||
// vfs_mount(MAJORB_RAMDISK, rd_minor, FS_EXT2, "/dev");
|
||||
// mknod(MAJORB_RAMDISK, initrd_minor, 0600, "/dev/rd0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -9,7 +9,9 @@
|
||||
#include "hos_defines.h"
|
||||
#include "fs/devices.h"
|
||||
|
||||
void devfs_init(minor_t rd_minor);
|
||||
#define DEVFS_SIZE 102400
|
||||
|
||||
int devfs_init();
|
||||
|
||||
#endif
|
||||
|
||||
+2
-1
@@ -8,6 +8,7 @@
|
||||
#include "kernel.h"
|
||||
#include "char/parallel.h"
|
||||
#include "char/vconsole.h"
|
||||
#include "block/ramdisk.h"
|
||||
|
||||
dev_driver_t *drivers[2][256];
|
||||
|
||||
@@ -17,7 +18,7 @@ void devices_init()
|
||||
{
|
||||
parallel_init(MAJORC_PARALLEL);
|
||||
vconsole_init(MAJORC_VCONSOLE);
|
||||
// ramdisk_init(MAJORB_RAMDISK);
|
||||
ramdisk_init(MAJORB_RAMDISK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
typedef short major_t;
|
||||
typedef short minor_t;
|
||||
typedef unsigned int device_t;
|
||||
|
||||
typedef struct {
|
||||
int (*block_read)(minor_t minor, u32_t blockStart, u32_t blocks, void *buffer);
|
||||
|
||||
+34
-4
@@ -6,11 +6,41 @@
|
||||
#include "hos_defines.h"
|
||||
#include "fs/devices.h"
|
||||
#include "kout.h"
|
||||
#include "ext2.h"
|
||||
#include "mm/vmm.h"
|
||||
#include "fs/vfs.h"
|
||||
|
||||
void ext2_read_super(major_t major, minor_t minor);
|
||||
|
||||
int ext2_init(int fsID)
|
||||
{
|
||||
ext2_super_block_t *super = kmalloc(1024);
|
||||
block_read(major, minor, 2, 2, super);
|
||||
kprintf("Magic: 0x%x\n", super->s_magic);
|
||||
vfs_fs_t *fs;
|
||||
if (( fs = New(vfs_fs_t) ))
|
||||
{
|
||||
fs->mount_super = ext2_mount_super;
|
||||
fs->mkfs = ext2_mkfs;
|
||||
vfs_register_fs(fsID, fs);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int ext2_mkfs(major_t major, minor_t minor)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// read the superblock of the filesystem and return a pointer to it
|
||||
void *ext2_mount_super(major_t major, minor_t minor)
|
||||
{
|
||||
ext2_super_block_t *super = kmalloc(1024);
|
||||
block_read(major, minor, 2, 2, super);
|
||||
if (super->s_magic != EXT2_MAGIC)
|
||||
{
|
||||
kfree(super);
|
||||
return NULL;
|
||||
}
|
||||
return super;
|
||||
}
|
||||
|
||||
+6
-2
@@ -9,6 +9,8 @@
|
||||
#include "hos_defines.h"
|
||||
#include "fs/devices.h"
|
||||
|
||||
#define EXT2_MAGIC 0xEF53
|
||||
|
||||
typedef struct {
|
||||
u32_t s_inodes_count; /* Inodes count */
|
||||
u32_t s_blocks_count; /* Blocks count */
|
||||
@@ -53,7 +55,7 @@ typedef struct {
|
||||
/*
|
||||
* Performance hints...
|
||||
*/
|
||||
u8_t s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
|
||||
u8_t s_prealloc_blocks; /* Nr of blocks to try to preallocate */
|
||||
u8_t s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
|
||||
u16_t s_padding1;
|
||||
|
||||
@@ -75,7 +77,9 @@ typedef struct {
|
||||
} ext2_super_block_t;
|
||||
|
||||
|
||||
void ext2_read_super(major_t major, minor_t minor);
|
||||
int ext2_init(int fsID);
|
||||
void *ext2_mount_super(major_t major, minor_t minor);
|
||||
int ext2_mkfs(major_t major, minor_t minor);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+178
-2
@@ -1,10 +1,186 @@
|
||||
// vfs.c
|
||||
// Author: Josh Holtrop
|
||||
// Date: 08/22/04
|
||||
// Modified: 08/22/04
|
||||
// Modified: 12/20/04
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "kout.h"
|
||||
#include "fs/vfs.h"
|
||||
#include "fs/ext2.h"
|
||||
#include "kernel.h"
|
||||
#include "mm/vmm.h"
|
||||
|
||||
vfs_mount_t *firstMount;
|
||||
vfs_fs_t *fses[VFS_MAX_FS];
|
||||
vfs_node_t *vfsMountTree;
|
||||
|
||||
int vfs_init()
|
||||
{
|
||||
k_check(ext2_init(FS_EXT2), "ext2_init() failed!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vfs_register_fs(int fsn, vfs_fs_t *fs)
|
||||
{
|
||||
if (fsn < 0 || fsn >= VFS_MAX_FS || fses[fsn])
|
||||
{
|
||||
kprintf("Invalid filesystem register: %d\n", fsn);
|
||||
return -1;
|
||||
}
|
||||
fses[fsn] = fs;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vfs_mount(major_t maj, minor_t min, int fsType, char *mountPoint)
|
||||
{
|
||||
if (mountPoint[0] != '/')
|
||||
return -1; // mount point must be absolute
|
||||
if (fsType < 0 || fsType >= VFS_MAX_FS || !fses[fsType])
|
||||
return -2; // invalid filesystem type
|
||||
if (vfs_find_mount(mountPoint))
|
||||
{
|
||||
return -5; // mount point already mounted
|
||||
}
|
||||
void *super = fses[fsType]->mount_super(maj, min);
|
||||
if (!super)
|
||||
return -6; // filesystem superblock not correctly identified
|
||||
vfs_mount_t *mnt = New(vfs_mount_t);
|
||||
if (!mnt)
|
||||
return -3; // could not allocate memory
|
||||
mnt->refs = 0;
|
||||
mnt->major = maj;
|
||||
mnt->minor = min;
|
||||
mnt->super = super;
|
||||
if (vfs_add_mount(mnt, mountPoint))
|
||||
{
|
||||
kfree(mnt);
|
||||
return -4; // could not add mount
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vfs_add_mount(vfs_mount_t *mnt, char *mountPoint)
|
||||
{
|
||||
vfs_node_t *node = vfsMountTree;
|
||||
char *mp = mountPoint;
|
||||
if (!vfsMountTree)
|
||||
{
|
||||
vfsMountTree = New(vfs_node_t);
|
||||
node = vfsMountTree;
|
||||
node->chr = *mp;
|
||||
node->up = NULL;
|
||||
node->next = NULL;
|
||||
node->down = NULL;
|
||||
node->mount = NULL;
|
||||
}
|
||||
for (;;)
|
||||
{
|
||||
if (node->chr == *mp) // got a match
|
||||
{
|
||||
mp++;
|
||||
if (*mp == 0)
|
||||
{
|
||||
if (node->mount)
|
||||
return -1; // mount point already taken
|
||||
node->mount = mnt;
|
||||
return 0;
|
||||
}
|
||||
if (node->down)
|
||||
node = node->down;
|
||||
else
|
||||
{
|
||||
node->down = New(vfs_node_t);
|
||||
node->down->up = node;
|
||||
node = node->down;
|
||||
node->next = NULL;
|
||||
node->down = NULL;
|
||||
node->mount = NULL;
|
||||
node->chr = *mp;
|
||||
}
|
||||
}
|
||||
else if (node->next)
|
||||
{
|
||||
node = node->next;
|
||||
}
|
||||
else // add a node for this character
|
||||
{
|
||||
node->next = New(vfs_node_t);
|
||||
node->next->up = node->up;
|
||||
node = node->next;
|
||||
node->next = NULL;
|
||||
node->down = NULL;
|
||||
node->mount = NULL;
|
||||
node->chr = *mp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vfs_mount_match_t vfs_get_rel_path(char *path)
|
||||
{
|
||||
vfs_mount_match_t matched;
|
||||
char *pp = path;
|
||||
int length = 0;
|
||||
vfs_node_t *node = vfsMountTree;
|
||||
while (*pp)
|
||||
{
|
||||
if (!node)
|
||||
break;
|
||||
if (node->chr == *pp) // got a character match
|
||||
{
|
||||
if (node->mount) // and there is something mounted here
|
||||
{
|
||||
matched.major = node->mount->major;
|
||||
matched.minor = node->mount->minor;
|
||||
matched.length = length;
|
||||
}
|
||||
pp++;
|
||||
length++;
|
||||
node = node->down;
|
||||
}
|
||||
else
|
||||
node = node->next;
|
||||
}
|
||||
return matched;
|
||||
}
|
||||
|
||||
vfs_mount_t *vfs_find_mount(char *mountPoint)
|
||||
{
|
||||
char *mp = mountPoint;
|
||||
vfs_node_t *node = vfsMountTree;
|
||||
while (node)
|
||||
{
|
||||
if (node->chr == *mp)
|
||||
{
|
||||
mp++;
|
||||
if (*mp == 0) // we matched the whole mount point string
|
||||
return node->mount;
|
||||
node = node->down;
|
||||
}
|
||||
else
|
||||
node = node->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*void vfs_dump_tree()
|
||||
{
|
||||
vfs_dump_node(vfsMountTree, 0);
|
||||
}
|
||||
|
||||
void vfs_dump_node(vfs_node_t *node, int level)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < level; i++)
|
||||
{
|
||||
putc(' ');
|
||||
}
|
||||
kprintf("%c (0x%x) mount: 0x%x, up: 0x%x, next:0x%x, down:0x%x\n", node->chr, node, node->mount, node->up, node->next, node->down);
|
||||
node = node->down;
|
||||
if (!node)
|
||||
return;
|
||||
while (node)
|
||||
{
|
||||
vfs_dump_node(node, level + 1);
|
||||
node = node->next;
|
||||
}
|
||||
}*/
|
||||
|
||||
+44
-7
@@ -1,7 +1,7 @@
|
||||
// vfs.h
|
||||
// Author: Josh Holtrop
|
||||
// Date: 08/22/04
|
||||
// Modified: 08/22/04
|
||||
// Modified: 12/20/04
|
||||
|
||||
#ifndef __HOS_VFS_H__
|
||||
#define __HOS_VFS_H__ __HOS_VFS_H__
|
||||
@@ -10,14 +10,51 @@
|
||||
#include "fs/devices.h"
|
||||
|
||||
#define FS_EXT2 1
|
||||
#define VFS_MAX_FS 10
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
void *super;
|
||||
void *next;
|
||||
major_t major;
|
||||
minor_t minor;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int refs;
|
||||
void *super;
|
||||
major_t major;
|
||||
minor_t minor;
|
||||
} vfs_mount_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *(*mount_super)(major_t major, minor_t minor);
|
||||
int (*mkfs)(major_t major, minor_t minor);
|
||||
} vfs_fs_t;
|
||||
|
||||
struct vfs_node_s
|
||||
{
|
||||
char chr;
|
||||
vfs_mount_t *mount;
|
||||
struct vfs_node_s *up;
|
||||
struct vfs_node_s *next;
|
||||
struct vfs_node_s *down;
|
||||
};
|
||||
|
||||
typedef struct vfs_node_s vfs_node_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
major_t major;
|
||||
minor_t minor;
|
||||
int length;
|
||||
} vfs_mount_match_t;
|
||||
|
||||
|
||||
int vfs_init();
|
||||
int vfs_mount(major_t maj, minor_t min, int fsType, char *mountPoint);
|
||||
int vfs_register_fs(int fsn, vfs_fs_t *fs);
|
||||
int vfs_add_mount(vfs_mount_t *mnt, char *mountPoint);
|
||||
vfs_mount_t *vfs_find_mount(char *mountPoint);
|
||||
vfs_mount_match_t vfs_get_rel_path(char *path);
|
||||
/*void vfs_dump_tree();
|
||||
void vfs_dump_node(vfs_node_t *node, int level);*/
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user