Now we can generate a fairly basic FS.

Added some test material
This commit is contained in:
Godzil
2022-05-26 12:02:47 +01:00
parent d9b7996c8e
commit 8fd7ab33fc
11 changed files with 296 additions and 40 deletions

View File

@@ -11,14 +11,6 @@
#include <stdint.h>
#if BUILD_TARGET == MEMORY
#include <miniffs/platform/memory.h>
#elif BUILD_TARGET == FILE
#include <miniffs/platform/file.h>
#else
#error Unknown build target
#endif
/*
* The pack(1) may not be needed, but better be safe than sorry to
* have a consistent binary representation across architectures
@@ -38,21 +30,29 @@ typedef struct miniffs_header_t
uint32_t entry_count;
fileentry_t fent[];
} miniffs_header_t;
#pragma pack()
typedef struct miniffs_t miniffs_t;
#if BUILD_PLATFORM_MEMORY
#include <platform/memory.h>
#elif BUILD_PLATFORM_FILE
#include <platform/file.h>
#else
#error Unknown build target.
#endif
/* Somewhat similar structure to the plain C FILE structure */
typedef struct file_t
{
void *private;
fileentry_t fent; /***< file linked to this structure */
fileentry_t *fent; /***< file linked to this structure */
uint32_t offset; /***< current position in the file */
} file_t;
#define MAKE4(_a, _b, _c, _d) ((_a & 0xFF) << 21) | ((_b & 0xFF) << 16) | ((_c & 0xFF) << 8) | (_d & 0xFF)
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define MAKE4(_a, _b, _c, _d) (((_a) & 0xFF) << 24) | (((_b) & 0xFF) << 16) | (((_c) & 0xFF) << 8) | ((_d) & 0xFF)
#else
#define MAKE4(_d, _c, _b, _a) (((_a) & 0xFF) << 24) | (((_b) & 0xFF) << 16) | (((_c) & 0xFF) << 8) | ((_d) & 0xFF)
#endif
#define MINIFFS_MAGIC MAKE4('M', 'F', 'F', 'S')
enum {
@@ -65,8 +65,8 @@ enum {
* Public functions used reading the filesystem
* This implementation is system dependant as it relly on how the memory is architectured and where the MiniFFS is stored.
*/
miniffs_t *miniffs_openfs(void *address); /***< Open a MiniFFS filesystem */
/* miniffs_openfs is backend specific and will be found in the backend header file */
file_t *miniffs_open(miniffs_t *fs, char *filename); /***< Open a file */
int miniffs_close(file_t *file); /***< Close a file */
void *miniffs_map(file_t *file); /***< Map a file to memory */
@@ -84,7 +84,7 @@ typedef enum miniffs_error_t
miniffs_error_t miniffs_geterror(); /***< Return last error */
#ifdef BUILDING_HOST_TOOLS
#ifdef BUILD_HOST_TOOLS
/*
* Functions used for offline creation of the filesystem
*/
@@ -93,6 +93,15 @@ int miniffs_addfile(miniffs_t *fs, char *name, char *ext, char *host_path);
int miniffs_delfile(miniffs_t *fs, char *name, char *ext, char *host_path);
int miniffs_writeimage(miniffs_t *fs, char *host_path);
int miniffs_closefs(miniffs_t *fs);
#endif /* BUILDING_HOST_TOOLS */
#endif /* BUILD_HOST_TOOLS */
#ifdef __miniffs_internal
/*
* Function that are private to the library
*/
int miniffs_checkfs(miniffs_t *fs);
fileentry_t *miniffs_findfile(miniffs_t *fs, char *filename);
#endif /* __miniffs_internal */
#endif /* MINIFFS_H */

View File

@@ -1,8 +1,43 @@
//
// Created by Manoel.Trapier on 25/05/2022.
//
/******************************************************************************
* MiniFFS : Mini Flat File System
* platform/file.h: Specific functions for the File backend
*
* Copyright (c) 2008-2022 986-Studio. All rights reserved.
*
******************************************************************************/
#ifndef MINIFFS_FILE_H
#define MINIFFS_FILE_H
#ifndef MINIFFS_PLATFORM_FILE_H
#define MINIFFS_PLATFORM_FILE_H
#endif //MINIFFS_FILE_H
#include <stdint.h>
#include <stdbool.h>
#ifdef BUILD_HOST_TOOLS
typedef struct fs_fent_t
{
char name[8];
char ext[3];
bool deleted;
bool mapped;
uint32_t size;
char *file_pointer;
} fs_fent_t;
#endif
typedef struct miniffs_t
{
miniffs_header_t *header;
#ifdef BUILD_HOST_TOOLS
uint32_t file_count; /***< Number of valid files in the list */
uint32_t file_list_count; /***< Number of items in the list */
uint32_t file_list_size; /***< Size of the list */
fs_fent_t *files; /***< File entry list */
#endif
} miniffs_t;
size_t host_map_file(char *filename, char **dest);
void host_unmap_file(char **dest, size_t length);
miniffs_t *miniffs_openfs(char *host_file); /***< Open a MiniFFS filesystem */
#endif /* MINIFFS_PLATFORM_FILE_H */

View File

@@ -1,8 +1,18 @@
//
// Created by Manoel.Trapier on 25/05/2022.
//
/******************************************************************************
* MiniFFS : Mini Flat File System
* platform/memory.h: Specific functions for the Memory backend
*
* Copyright (c) 2008-2022 986-Studio. All rights reserved.
*
******************************************************************************/
#ifndef MINIFFS_PLATFORM_MEMORY_H
#define MINIFFS_PLATFORM_MEMORY_H
typedef struct miniffs_t
{
miniffs_header_t *header;
void *memoryOffset;
} miniffs_t;
#endif /* MINIFFS_PLATFORM_MEMORY_H */