aboutsummaryrefslogtreecommitdiffstats
path: root/src/fs
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2018-11-29 20:43:06 -0500
committerClyne Sullivan <tullivan99@gmail.com>2018-11-29 20:43:06 -0500
commit563c92e6d08c305cb9f7693818ecbe2a2dec527b (patch)
tree5b8a6dcdad1daa64dc3a73e3dc9385b85b2c9200 /src/fs
parent22615096dee294f63c6940c17f2a448da51d9197 (diff)
hello world from initrd
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/Makefile22
-rw-r--r--src/fs/initrd.c67
-rw-r--r--src/fs/initrd.h23
-rw-r--r--src/fs/stdio.c37
-rw-r--r--src/fs/stdio.h23
5 files changed, 143 insertions, 29 deletions
diff --git a/src/fs/Makefile b/src/fs/Makefile
index d22fbf3..ce23a89 100644
--- a/src/fs/Makefile
+++ b/src/fs/Makefile
@@ -1,9 +1,29 @@
+##
+# @file Makefile
+# Script to build folder of source files
+#
+# Copyright (C) 2018 Clyne Sullivan
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+
CFILES = $(wildcard *.c)
AFILES = $(wildcard *.s)
OFILES = $(patsubst %.c, %.o, $(CFILES)) \
$(patsubst %.s, %.asm.o, $(AFILES))
-CFLAGS += -I.. -I../arch/cmsis
+CFLAGS += -ffreestanding -nostdlib -I.. -I../arch/cmsis
all: $(OFILES)
diff --git a/src/fs/initrd.c b/src/fs/initrd.c
index 44e5493..de00a4a 100644
--- a/src/fs/initrd.c
+++ b/src/fs/initrd.c
@@ -1,3 +1,23 @@
+/**
+ * @file initrd.c
+ * Filesystem module for handling the initrd
+ *
+ * Copyright (C) 2018 Clyne Sullivan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
#include <stdint.h>
#include <kernel/heap.h>
@@ -5,7 +25,6 @@
typedef struct {
char *address;
- uint32_t pos;
uint32_t size;
} initrd_info;
@@ -16,8 +35,9 @@ static const uint8_t *initrd_start = (uint8_t *)_binary_initrd_img_start;
static const uint32_t initrd_size = (uint32_t)_binary_initrd_img_size;
void *initrd_open(const char *file);
-uint32_t initrd_read(void *info, uint32_t count, uint8_t *buffer);
-int initrd_close(void *info);
+uint32_t initrd_read(vfs_file_info *info, uint32_t count, uint8_t *buffer);
+int initrd_close(vfs_file_info *info);
+int initrd_seek(vfs_file_info *info, uint32_t offset, int whence);
char *initrd_getfile(uint32_t offset);
@@ -26,7 +46,8 @@ static const vfs_volume_funcs initrd_funcs = {
initrd_close,
initrd_read,
0, // write
- 0 // readdir
+ 0, // readdir
+ initrd_seek
};
int initrd_strncmp(const char *a, const char *b, unsigned int n)
@@ -53,7 +74,6 @@ void *initrd_open(const char *file)
initrd_info *file = (initrd_info *)malloc(
sizeof(initrd_info));
file->address = ptr + len + 8;
- file->pos = 0;
file->size = *(uint32_t *)(ptr + len + 4);
return file;
}
@@ -62,41 +82,48 @@ void *initrd_open(const char *file)
return 0;
}
-int initrd_close(void *info)
+int initrd_close(vfs_file_info *info)
{
// Nothing to do
- free(info);
+ free(info->fsinfo);
return 0;
}
-uint32_t initrd_read(void *info, uint32_t count, uint8_t *buffer)
+uint32_t initrd_read(vfs_file_info *info, uint32_t count, uint8_t *buffer)
{
- initrd_info *iinfo = (initrd_info *)info;
+ initrd_info *iinfo = (initrd_info *)info->fsinfo;
if (iinfo == 0 || iinfo->address == 0)
return 0;
uint32_t i;
for (i = 0; i < count; i++) {
- if (iinfo->pos >= iinfo->size)
+ if (info->pos >= iinfo->size)
break;
- buffer[iinfo->pos] = iinfo->address[iinfo->pos];
- iinfo->pos++;
+ buffer[info->pos] = iinfo->address[info->pos];
+ info->pos++;
}
return i;
}
-/*char *readfile(const char *name)
+int initrd_seek(vfs_file_info *info, uint32_t offset, int whence)
{
- char *ptr;
- for (uint32_t i = 0; ptr = getfile(i), ptr != 0; i++) {
- uint32_t len = *((uint32_t *)ptr);
- if (!strncmp(name, ptr + 4, len))
- return ptr + len + 8;
- }
+ initrd_info *iinfo = (initrd_info *)info->fsinfo;
+ if (iinfo == 0 || iinfo->address == 0)
+ return 0;
+
+ if (whence == SEEK_SET)
+ info->pos = offset;
+ else if (whence == SEEK_CUR)
+ info->pos += offset;
+ else if (whence == SEEK_END)
+ info->pos = iinfo->size + offset;
+ else
+ return -1;
+
return 0;
-}*/
+}
char *initrd_getfile(uint32_t offset)
{
diff --git a/src/fs/initrd.h b/src/fs/initrd.h
index dbc0079..045b2b9 100644
--- a/src/fs/initrd.h
+++ b/src/fs/initrd.h
@@ -1,6 +1,29 @@
+/**
+ * @file initrd.h
+ * Filesystem module for handling the initrd
+ *
+ * Copyright (C) 2018 Clyne Sullivan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
#ifndef INTIRD_H_
#define INITRD_H_
+/**
+ * Mounts the initrd (initrd is built into kernel).
+ */
void initrd_init(void);
#endif // INITRD_H_
diff --git a/src/fs/stdio.c b/src/fs/stdio.c
index 6cea2a3..e15003d 100644
--- a/src/fs/stdio.c
+++ b/src/fs/stdio.c
@@ -1,12 +1,32 @@
+/**
+ * @file stdio.c
+ * Filesystem module for handling stdio (stdout, stdin, stderr)
+ *
+ * Copyright (C) 2018 Clyne Sullivan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
#include "stdio.h"
#include <kernel/heap.h>
#include <kernel/serial.h>
void *stdio_open(const char *path);
-int stdio_close(void *info);
-uint32_t stdio_read(void *info, uint32_t count, uint8_t *buffer);
-uint32_t stdio_write(void *info, uint32_t count, const uint8_t *buffer);
+int stdio_close(vfs_file_info *info);
+uint32_t stdio_read(vfs_file_info *info, uint32_t count, uint8_t *buffer);
+uint32_t stdio_write(vfs_file_info *info, uint32_t count, const uint8_t *buffer);
const vfs_volume_funcs stdio_funcs = {
stdio_open,
@@ -14,6 +34,7 @@ const vfs_volume_funcs stdio_funcs = {
stdio_read,
stdio_write,
0, // readdir
+ 0 // seek
};
void *stdio_open(const char *path)
@@ -30,14 +51,14 @@ void *stdio_open(const char *path)
return id;
}
-int stdio_close(void *info)
+int stdio_close(vfs_file_info *info)
{
// Nothing to do
- free(info);
+ free(info->fsinfo);
return 0;
}
-uint32_t stdio_read(void *info, uint32_t count, uint8_t *buffer)
+uint32_t stdio_read(vfs_file_info *info, uint32_t count, uint8_t *buffer)
{
(void)info;
(void)count;
@@ -45,11 +66,11 @@ uint32_t stdio_read(void *info, uint32_t count, uint8_t *buffer)
return 0;
}
-uint32_t stdio_write(void *info, uint32_t count, const uint8_t *buffer)
+uint32_t stdio_write(vfs_file_info *info, uint32_t count, const uint8_t *buffer)
{
(void)info;
for (uint32_t i = 0; i < count; i++)
- serial_put(buffer[count]);
+ serial_put(buffer[i]);
return count;
}
diff --git a/src/fs/stdio.h b/src/fs/stdio.h
index 90d0f68..bf52fa8 100644
--- a/src/fs/stdio.h
+++ b/src/fs/stdio.h
@@ -1,8 +1,31 @@
+/**
+ * @file stdio.h
+ * Filesystem module for handling stdio (stdout, stdin, stderr)
+ *
+ * Copyright (C) 2018 Clyne Sullivan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
#ifndef INTIRD_H_
#define INITRD_H_
#include <kernel/vfs.h>
+/**
+ * Structure of function calls for stdio filesystem operations.
+ */
extern const vfs_volume_funcs stdio_funcs;
#endif // INITRD_H_