From 1af3e134bf5a6005c7860832d3d6b559cabd78e7 Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 14 Oct 2024 23:08:44 +0200 Subject: [PATCH] Mon 14 Oct 23:06:38 CEST 2024 --- kernel/diskfs.h | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 kernel/diskfs.h diff --git a/kernel/diskfs.h b/kernel/diskfs.h new file mode 100644 index 0000000..ee63efb --- /dev/null +++ b/kernel/diskfs.h @@ -0,0 +1,65 @@ +/* +Copyright (C) 2016-2019 The University of Notre Dame +This software is distributed under the GNU General Public License. +See the file LICENSE for details. +*/ + +#ifndef DISKFS_H +#define DISKFS_H + +#include "kernel/types.h" + +#define DISKFS_MAGIC 0xabcd4321 +#define DISKFS_BLOCK_SIZE 4096 +#define DISKFS_DIRECT_POINTERS 6 +#define DISKFS_INODES_PER_BLOCK (DISKFS_BLOCK_SIZE/sizeof(struct diskfs_inode)) +#define DISKFS_ITEMS_PER_BLOCK (DISKFS_BLOCK_SIZE/sizeof(struct diskfs_item)) +#define DISKFS_POINTERS_PER_BLOCK (DISKFS_BLOCK_SIZE/sizeof(uint32_t)) + +struct diskfs_superblock { + uint32_t magic; + uint32_t block_size; + uint32_t inode_start; + uint32_t inode_blocks; + uint32_t bitmap_start; + uint32_t bitmap_blocks; + uint32_t data_start; + uint32_t data_blocks; +}; + +struct diskfs_inode { + uint32_t inuse; // reserve for broader use. + uint32_t size; + uint32_t direct[DISKFS_DIRECT_POINTERS]; + uint32_t indirect; +}; + +#define DISKFS_ITEM_BLANK 0 +#define DISKFS_ITEM_FILE 1 +#define DISKFS_ITEM_DIR 2 + +/* Maximum name length chosen so that diskfs_item is 32 bytes. */ +#define DISKFS_NAME_MAX 26 + +#pragma pack(1) +struct diskfs_item { + uint32_t inumber; + uint8_t type; + uint8_t name_length; + char name[DISKFS_NAME_MAX]; +}; +#pragma pack() + +struct diskfs_block { + union { + struct diskfs_superblock superblock; + struct diskfs_inode inodes[DISKFS_INODES_PER_BLOCK]; + struct diskfs_item items[DISKFS_ITEMS_PER_BLOCK]; + uint32_t pointers[DISKFS_POINTERS_PER_BLOCK]; + char data[DISKFS_BLOCK_SIZE]; + }; +}; + +int diskfs_init(void); + +#endif