new fs node device pointer

This commit is contained in:
Kevin Lange 2013-03-25 21:48:16 -07:00
parent bac4d54bed
commit a55a652e0e
6 changed files with 62 additions and 52 deletions

View File

@ -13,13 +13,6 @@ uint32_t PTRS_PER_BLOCK = 256;
#define SECTORSIZE 512 #define SECTORSIZE 512
#define DISK_PORT 0x1F0 #define DISK_PORT 0x1F0
typedef struct {
uint32_t block_no;
uint32_t last_use;
uint8_t dirty;
uint8_t *block;
} ext2_disk_cache_entry_t;
ext2_disk_cache_entry_t *ext2_disk_cache = NULL; // LSU block cache ext2_disk_cache_entry_t *ext2_disk_cache = NULL; // LSU block cache
ext2_superblock_t *ext2_disk_superblock = NULL; ext2_superblock_t *ext2_disk_superblock = NULL;
ext2_bgdescriptor_t *ext2_disk_root_block = NULL; ext2_bgdescriptor_t *ext2_disk_root_block = NULL;

View File

@ -26,7 +26,7 @@ static inline size_t pipe_unread(pipe_device_t * pipe) {
} }
int pipe_size(fs_node_t * node) { int pipe_size(fs_node_t * node) {
pipe_device_t * pipe = (pipe_device_t *)node->inode; pipe_device_t * pipe = (pipe_device_t *)node->device;
return pipe_unread(pipe); return pipe_unread(pipe);
} }
@ -61,14 +61,14 @@ static inline void pipe_increment_write_by(pipe_device_t * pipe, size_t amount)
} }
uint32_t read_pipe(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) { uint32_t read_pipe(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
assert(node->inode != 0 && "Attempted to read from a fully-closed pipe."); assert(node->device != 0 && "Attempted to read from a fully-closed pipe.");
/* Retreive the pipe object associated with this file node */ /* Retreive the pipe object associated with this file node */
pipe_device_t * pipe = (pipe_device_t *)node->inode; pipe_device_t * pipe = (pipe_device_t *)node->device;
#if DEBUG_PIPES #if DEBUG_PIPES
if (pipe->size > 300) { /* Ignore small pipes (ie, keyboard) */ if (pipe->size > 300) { /* Ignore small pipes (ie, keyboard) */
kprintf("[debug] Call to read from pipe 0x%x\n", node->inode); kprintf("[debug] Call to read from pipe 0x%x\n", node->device);
kprintf(" Unread bytes: %d\n", pipe_unread(pipe)); kprintf(" Unread bytes: %d\n", pipe_unread(pipe));
kprintf(" Total size: %d\n", pipe->size); kprintf(" Total size: %d\n", pipe->size);
kprintf(" Request size: %d\n", size); kprintf(" Request size: %d\n", size);
@ -99,14 +99,14 @@ uint32_t read_pipe(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buf
} }
uint32_t write_pipe(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) { uint32_t write_pipe(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
assert(node->inode != 0 && "Attempted to write to a fully-closed pipe."); assert(node->device != 0 && "Attempted to write to a fully-closed pipe.");
/* Retreive the pipe object associated with this file node */ /* Retreive the pipe object associated with this file node */
pipe_device_t * pipe = (pipe_device_t *)node->inode; pipe_device_t * pipe = (pipe_device_t *)node->device;
#if DEBUG_PIPES #if DEBUG_PIPES
if (pipe->size > 300) { /* Ignore small pipes (ie, keyboard) */ if (pipe->size > 300) { /* Ignore small pipes (ie, keyboard) */
kprintf("[debug] Call to write to pipe 0x%x\n", node->inode); kprintf("[debug] Call to write to pipe 0x%x\n", node->device);
kprintf(" Available space: %d\n", pipe_available(pipe)); kprintf(" Available space: %d\n", pipe_available(pipe));
kprintf(" Total size: %d\n", pipe->size); kprintf(" Total size: %d\n", pipe->size);
kprintf(" Request size: %d\n", size); kprintf(" Request size: %d\n", size);
@ -153,10 +153,10 @@ uint32_t write_pipe(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *bu
} }
void open_pipe(fs_node_t * node, uint8_t read, uint8_t write) { void open_pipe(fs_node_t * node, uint8_t read, uint8_t write) {
assert(node->inode != 0 && "Attempted to open a fully-closed pipe."); assert(node->device != 0 && "Attempted to open a fully-closed pipe.");
/* Retreive the pipe object associated with this file node */ /* Retreive the pipe object associated with this file node */
pipe_device_t * pipe = (pipe_device_t *)node->inode; pipe_device_t * pipe = (pipe_device_t *)node->device;
/* Add a reference */ /* Add a reference */
pipe->refcount++; pipe->refcount++;
@ -165,10 +165,10 @@ void open_pipe(fs_node_t * node, uint8_t read, uint8_t write) {
} }
void close_pipe(fs_node_t * node) { void close_pipe(fs_node_t * node) {
assert(node->inode != 0 && "Attempted to close an already fully-closed pipe."); assert(node->device != 0 && "Attempted to close an already fully-closed pipe.");
/* Retreive the pipe object associated with this file node */ /* Retreive the pipe object associated with this file node */
pipe_device_t * pipe = (pipe_device_t *)node->inode; pipe_device_t * pipe = (pipe_device_t *)node->device;
/* Drop one reference */ /* Drop one reference */
pipe->refcount--; pipe->refcount--;
@ -182,7 +182,7 @@ void close_pipe(fs_node_t * node) {
free(pipe->wait_queue); free(pipe->wait_queue);
free(pipe); free(pipe);
/* And let the creator know there are no more references */ /* And let the creator know there are no more references */
node->inode = 0; node->device = 0;
#endif #endif
} }
@ -193,7 +193,7 @@ fs_node_t * make_pipe(size_t size) {
fs_node_t * fnode = malloc(sizeof(fs_node_t)); fs_node_t * fnode = malloc(sizeof(fs_node_t));
pipe_device_t * pipe = malloc(sizeof(pipe_device_t)); pipe_device_t * pipe = malloc(sizeof(pipe_device_t));
fnode->inode = 0; fnode->device = 0;
fnode->name[0] = '\0'; fnode->name[0] = '\0';
sprintf(fnode->name, "[pipe]"); sprintf(fnode->name, "[pipe]");
fnode->uid = 0; fnode->uid = 0;
@ -212,7 +212,7 @@ fs_node_t * make_pipe(size_t size) {
fnode->mtime = fnode->atime; fnode->mtime = fnode->atime;
fnode->ctime = fnode->atime; fnode->ctime = fnode->atime;
fnode->inode = (uintptr_t)pipe; fnode->device = pipe;
pipe->buffer = malloc(size); pipe->buffer = malloc(size);
pipe->write_ptr = 0; pipe->write_ptr = 0;

View File

@ -20,11 +20,11 @@ uint32_t read_serial(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *b
memset(buffer, 0x00, 1); memset(buffer, 0x00, 1);
uint32_t collected = 0; uint32_t collected = 0;
while (collected < size) { while (collected < size) {
while (!serial_rcvd(node->inode)) { while (!serial_rcvd((int)node->device)) {
switch_task(1); switch_task(1);
} }
debug_print(NOTICE, "Data received from TTY"); debug_print(NOTICE, "Data received from TTY");
buffer[collected] = serial_recv(node->inode); buffer[collected] = serial_recv((int)node->device);
collected++; collected++;
} }
return collected; return collected;
@ -33,7 +33,7 @@ uint32_t read_serial(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *b
uint32_t write_serial(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) { uint32_t write_serial(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
uint32_t sent = 0; uint32_t sent = 0;
while (sent < size) { while (sent < size) {
serial_send(node->inode, buffer[sent]); serial_send((int)node->device, buffer[sent]);
sent++; sent++;
} }
return size; return size;
@ -50,7 +50,7 @@ void close_serial(fs_node_t * node) {
fs_node_t * serial_device_create(int device) { fs_node_t * serial_device_create(int device) {
fs_node_t * fnode = malloc(sizeof(fs_node_t)); fs_node_t * fnode = malloc(sizeof(fs_node_t));
memset(fnode, 0x00, sizeof(fs_node_t)); memset(fnode, 0x00, sizeof(fs_node_t));
fnode->inode = device; fnode->device= (void *)device;
strcpy(fnode->name, "serial"); strcpy(fnode->name, "serial");
fnode->uid = 0; fnode->uid = 0;
fnode->gid = 0; fnode->gid = 0;

View File

@ -77,7 +77,7 @@ static inline size_t ring_buffer_unread(ring_buffer_t * ring_buffer) {
} }
size_t ring_buffer_size(fs_node_t * node) { size_t ring_buffer_size(fs_node_t * node) {
ring_buffer_t * ring_buffer = (ring_buffer_t *)node->inode; ring_buffer_t * ring_buffer = (ring_buffer_t *)node->device;
return ring_buffer_unread(ring_buffer); return ring_buffer_unread(ring_buffer);
} }
@ -109,7 +109,7 @@ static inline void ring_buffer_increment_write(ring_buffer_t * ring_buffer) {
uint32_t read_pty_master(fs_node_t * node, uint32_t offset, uint32_t size, uint8_t *buffer) { uint32_t read_pty_master(fs_node_t * node, uint32_t offset, uint32_t size, uint8_t *buffer) {
pty_t * pty = (pty_t *)node->inode; pty_t * pty = (pty_t *)node->device;
/* Standard pipe read */ /* Standard pipe read */
size_t collected = 0; size_t collected = 0;
@ -130,7 +130,7 @@ uint32_t read_pty_master(fs_node_t * node, uint32_t offset, uint32_t size, uint
return collected; return collected;
} }
uint32_t write_pty_master(fs_node_t * node, uint32_t offset, uint32_t size, uint8_t *buffer) { uint32_t write_pty_master(fs_node_t * node, uint32_t offset, uint32_t size, uint8_t *buffer) {
pty_t * pty = (pty_t *)node->inode; pty_t * pty = (pty_t *)node->device;
size_t written = 0; size_t written = 0;
while (written < size) { while (written < size) {
@ -163,7 +163,7 @@ void close_pty_master(fs_node_t * node) {
} }
uint32_t read_pty_slave(fs_node_t * node, uint32_t offset, uint32_t size, uint8_t *buffer) { uint32_t read_pty_slave(fs_node_t * node, uint32_t offset, uint32_t size, uint8_t *buffer) {
pty_t * pty = (pty_t *)node->inode; pty_t * pty = (pty_t *)node->device;
debug_print(INFO, "tty read at offset=%d, size=%d", offset, size); debug_print(INFO, "tty read at offset=%d, size=%d", offset, size);
@ -188,7 +188,7 @@ uint32_t read_pty_slave(fs_node_t * node, uint32_t offset, uint32_t size, uint8
return collected; return collected;
} }
uint32_t write_pty_slave(fs_node_t * node, uint32_t offset, uint32_t size, uint8_t *buffer) { uint32_t write_pty_slave(fs_node_t * node, uint32_t offset, uint32_t size, uint8_t *buffer) {
pty_t * pty = (pty_t *)node->inode; pty_t * pty = (pty_t *)node->device;
size_t written = 0; size_t written = 0;
while (written < size) { while (written < size) {
@ -221,22 +221,22 @@ void close_pty_slave(fs_node_t * node) {
* things differently in the slave or master. * things differently in the slave or master.
*/ */
int ioctl_pty_master(fs_node_t * node, int request, void * argp) { int ioctl_pty_master(fs_node_t * node, int request, void * argp) {
pty_t * pty = (pty_t *)node->inode; pty_t * pty = (pty_t *)node->device;
return pty_ioctl(pty, request, argp); return pty_ioctl(pty, request, argp);
} }
int ioctl_pty_slave(fs_node_t * node, int request, void * argp) { int ioctl_pty_slave(fs_node_t * node, int request, void * argp) {
pty_t * pty = (pty_t *)node->inode; pty_t * pty = (pty_t *)node->device;
return pty_ioctl(pty, request, argp); return pty_ioctl(pty, request, argp);
} }
int pty_available_input(fs_node_t * node) { int pty_available_input(fs_node_t * node) {
pty_t * pty = (pty_t *)node->inode; pty_t * pty = (pty_t *)node->device;
return ring_buffer_unread(&pty->in); return ring_buffer_unread(&pty->in);
} }
int pty_available_output(fs_node_t * node) { int pty_available_output(fs_node_t * node) {
pty_t * pty = (pty_t *)node->inode; pty_t * pty = (pty_t *)node->device;
return ring_buffer_unread(&pty->out); return ring_buffer_unread(&pty->out);
} }
@ -258,7 +258,7 @@ fs_node_t * pty_master_create(pty_t * pty) {
fnode->ioctl = ioctl_pty_master; fnode->ioctl = ioctl_pty_master;
fnode->get_size = pty_available_output; fnode->get_size = pty_available_output;
fnode->inode = (uintptr_t)pty; fnode->device = pty;
return fnode; return fnode;
} }
@ -281,7 +281,7 @@ fs_node_t * pty_slave_create(pty_t * pty) {
fnode->ioctl = ioctl_pty_slave; fnode->ioctl = ioctl_pty_slave;
fnode->get_size = pty_available_input; fnode->get_size = pty_available_input;
fnode->inode = (uintptr_t)pty; fnode->device = pty;
return fnode; return fnode;
} }

View File

@ -15,6 +15,8 @@
#define EXT2_SUPER_MAGIC 0xEF53 #define EXT2_SUPER_MAGIC 0xEF53
#define EXT2_DIRECT_BLOCKS 12
/* Super block struct. */ /* Super block struct. */
struct ext2_superblock { struct ext2_superblock {
uint32_t inodes_count; uint32_t inodes_count;
@ -162,7 +164,16 @@ struct ext2_dir {
typedef struct ext2_dir ext2_dir_t; typedef struct ext2_dir ext2_dir_t;
typedef struct {
uint32_t block_no;
uint32_t last_use;
uint8_t dirty;
uint8_t *block;
} ext2_disk_cache_entry_t;
void ext2_ramdisk_mount(uint32_t offset); void ext2_ramdisk_mount(uint32_t offset);
typedef int (*ext2_block_io_t) (void *, uint32_t, uint8_t *);
#endif #endif

View File

@ -39,14 +39,22 @@ typedef int (*ioctl_type_t) (struct fs_node *, int request, void * argp);
typedef int (*get_size_type_t) (struct fs_node *); typedef int (*get_size_type_t) (struct fs_node *);
typedef struct fs_node { typedef struct fs_node {
char name[256]; // The filename. char name[256]; // The filename.
uint32_t mask; // The permissions mask. void * device; // Device object (optional)
uint32_t uid; // The owning user. uint32_t mask; // The permissions mask.
uint32_t gid; // The owning group. uint32_t uid; // The owning user.
uint32_t flags; // Flags (node type, etc). uint32_t gid; // The owning group.
uint32_t inode; // Inode number. uint32_t flags; // Flags (node type, etc).
uint32_t length; // Size of the file, in byte. uint32_t inode; // Inode number.
uint32_t impl; // Used to keep track which fs it belongs to. uint32_t length; // Size of the file, in byte.
uint32_t impl; // Used to keep track which fs it belongs to.
/* times */
uint32_t atime; // Accessed
uint32_t mtime; // Modified
uint32_t ctime; // Created
/* File operations */
read_type_t read; read_type_t read;
write_type_t write; write_type_t write;
open_type_t open; open_type_t open;
@ -57,17 +65,15 @@ typedef struct fs_node {
mkdir_type_t mkdir; mkdir_type_t mkdir;
ioctl_type_t ioctl; ioctl_type_t ioctl;
get_size_type_t get_size; get_size_type_t get_size;
struct fs_node *ptr; // Used by mountpoints and symlinks.
uint32_t offset; struct fs_node *ptr; // Alias pointer, for symlinks.
int32_t shared_with; uint32_t offset; // Offset for read operations XXX move this to new "file descriptor" entry
uint32_t atime; int32_t shared_with; // File descriptor sharing XXX
uint32_t mtime;
uint32_t ctime;
} fs_node_t; } fs_node_t;
struct dirent { struct dirent {
uint32_t ino; // Inode number. uint32_t ino; // Inode number.
char name[256]; // The filename. char name[256]; // The filename.
}; };
struct stat { struct stat {