aboutsummaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/def.h65
-rw-r--r--inc/spec.h58
2 files changed, 123 insertions, 0 deletions
diff --git a/inc/def.h b/inc/def.h
new file mode 100644
index 0000000..e73d6e9
--- /dev/null
+++ b/inc/def.h
@@ -0,0 +1,65 @@
+/**
+ * Copyright (c) 2021, Marvin Borner <melvix@marvinborner.de>
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef MARFS_DEF_H
+#define MARFS_DEF_H
+
+/**
+ * Types
+ */
+
+typedef signed char s8;
+typedef unsigned char u8;
+
+typedef signed short s16;
+typedef unsigned short u16;
+
+typedef signed int s32;
+typedef unsigned int u32;
+
+typedef signed long s64;
+typedef unsigned long u64;
+
+typedef float f32;
+typedef double f64;
+typedef long double f80;
+
+/**
+ * Useful macros
+ */
+
+#define UNUSED(a) ((void)(a))
+
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+#define COUNT(a) (sizeof(a) / sizeof 0 [a])
+
+#define BIT_GET(num, n) (((num) & (1UL << (n))) >> (n))
+#define BIT_SET(num, n) ((num) | (1UL << (n)))
+#define BIT_CLEAR(num, n) ((num) & ~(1UL << (n)))
+#define BIT_TOGGLE(num, n) ((num) ^ (1UL << (n)))
+
+/**
+ * Compiler attribute wrappers
+ */
+
+#define ATTR __attribute__
+#define NORETURN ATTR((noreturn))
+#define INLINE ATTR((gnu_inline)) inline
+#define NOINLINE ATTR((noinline))
+#define DEPRECATED ATTR((deprecated))
+#define NONNULL ATTR((nonnull))
+#define PACKED ATTR((packed))
+#define HOT ATTR((hot))
+#define OPTIMIZE(level) ATTR((optimize(level)))
+#define ALIGNED(align) ATTR((aligned(align)))
+
+/**
+ * General macro constants
+ */
+
+#define NULL ((void *)0)
+
+#endif
diff --git a/inc/spec.h b/inc/spec.h
new file mode 100644
index 0000000..7991866
--- /dev/null
+++ b/inc/spec.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2021, Marvin Borner <melvix@marvinborner.de>
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef MARFS_SPEC
+#define MARFS_SPEC
+
+#include <def.h>
+
+#define MARFS_POINT(head, tail) ((struct marfs_pointer){ (head), (tail) })
+#define MARFS_MAGIC "MarFS"
+#define MARFS_SPEC_VERSION 1
+
+#define MARFS_END 0xffffffff
+#define MARFS_NAME_LENGTH 32
+#define MARFS_ENTRY_SIZE 1024
+
+#define MARFS_DIR_ENTRY 1
+#define MARFS_FILE_ENTRY 2;
+
+#define MARFS_DIR_ENTRY_COUNT (MARFS_ENTRY_SIZE / sizeof(struct marfs_dir_entry_data))
+
+struct marfs_pointer {
+ u32 head, tail;
+} PACKED;
+
+struct marfs_header {
+ char magic[6];
+ u32 version;
+ u32 entry_size;
+ struct marfs_pointer main;
+ u8 padding[MARFS_ENTRY_SIZE - 22];
+} PACKED;
+
+struct marfs_entry_header {
+ u32 type;
+ u32 prev, next; // MARFS_END if end
+} PACKED;
+
+struct marfs_dir_entry_data {
+ char name[MARFS_NAME_LENGTH];
+ struct marfs_pointer pointer;
+} PACKED;
+
+struct marfs_dir_entry {
+ struct marfs_entry_header header;
+ struct marfs_dir_entry_data entries[MARFS_DIR_ENTRY_COUNT];
+ u8 padding[MARFS_ENTRY_SIZE - sizeof(struct marfs_entry_header) -
+ (MARFS_DIR_ENTRY_COUNT * sizeof(struct marfs_dir_entry_data))];
+} PACKED;
+
+struct marfs_file_entry {
+ struct marfs_entry_header header;
+ u8 data[MARFS_ENTRY_SIZE - sizeof(struct marfs_entry_header)];
+} PACKED;
+
+#endif