1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /******************************************************************************
- * MiniFFS : Mini Flat File System
- * miniffs.h: MiniFFS main header
- *
- * Copyright (c) 2008-2022 986-Studio. All rights reserved.
- *
- ******************************************************************************/
- #ifndef MINIFFS_H
- #define MINIFFS_H
- #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
- */
- #pragma pack(1)
- typedef struct fileentry_t
- {
- char name[8];
- char ext[3];
- uint32_t size;
- uint32_t offset;
- } fileentry_t;
- typedef struct miniffs_header_t
- {
- uint32_t magic;
- uint32_t entry_count;
- fileentry_t fent[];
- } miniffs_header_t;
- #pragma pack()
- typedef struct miniffs_t miniffs_t;
- /* Somewhat similar structure to the plain C FILE structure */
- typedef struct file_t
- {
- void *private;
- 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)
- #define MINIFFS_MAGIC MAKE4('M', 'F', 'F', 'S')
- enum {
- MFFS_SEEK_SET, /***< Seek from beginning of file */
- MFFS_SEEK_CUR, /***< Seek from current position */
- MFFS_SEEK_END /***< Seek from end of file */
- };
- /*
- * 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 */
- 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 */
- int miniffs_read(void *ptr, size_t size, size_t nmemb, file_t *file); /***< Read bytes from a file */
- int miniffs_seek(file_t *file, size_t offset, int whence); /***< Set position in a file */
- size_t miniffs_tell(file_t *file); /***< Get current position in a file*/
- typedef enum miniffs_error_t
- {
- MINIFFS_NOERROR = 0,
- MINIFFS_INVALID_FS,
- MINIFFS_FILE_NOT_FOUND,
- //MINIFFS_,
- } miniffs_error_t;
- miniffs_error_t miniffs_geterror(); /***< Return last error */
- #ifdef BUILDING_HOST_TOOLS
- /*
- * Functions used for offline creation of the filesystem
- */
- miniffs_t *miniffs_createfs();
- 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 /* MINIFFS_H */
|