|
@@ -10,6 +10,15 @@
|
|
#define MINIFFS_H
|
|
#define MINIFFS_H
|
|
|
|
|
|
#include <stdint.h>
|
|
#include <stdint.h>
|
|
|
|
+#include <stdbool.h>
|
|
|
|
+
|
|
|
|
+#define MINIFFS_VERSION_MAJOR (1)
|
|
|
|
+#define MINIFFS_VERSION_MINOR (0)
|
|
|
|
+#define MINIFFS_FILENAME_LENGTH (8)
|
|
|
|
+#define MINIFFS_EXTENSION_LENGTH (3)
|
|
|
|
+
|
|
|
|
+/* the full name is FILENAME + '.' + EXTENSION */
|
|
|
|
+#define MINIFFS_FULLNAME_LENGTH (MINIFFS_FILENAME_LENGTH + MINIFFS_EXTENSION_LENGTH + 1)
|
|
|
|
|
|
/*
|
|
/*
|
|
* The pack(1) may not be needed, but better be safe than sorry to
|
|
* The pack(1) may not be needed, but better be safe than sorry to
|
|
@@ -18,8 +27,8 @@
|
|
#pragma pack(1)
|
|
#pragma pack(1)
|
|
typedef struct fileentry_t
|
|
typedef struct fileentry_t
|
|
{
|
|
{
|
|
- char name[8];
|
|
|
|
- char ext[3];
|
|
|
|
|
|
+ char name[MINIFFS_FILENAME_LENGTH];
|
|
|
|
+ char ext[MINIFFS_EXTENSION_LENGTH];
|
|
uint32_t size;
|
|
uint32_t size;
|
|
uint32_t offset;
|
|
uint32_t offset;
|
|
} fileentry_t;
|
|
} fileentry_t;
|
|
@@ -27,6 +36,10 @@ typedef struct fileentry_t
|
|
typedef struct miniffs_header_t
|
|
typedef struct miniffs_header_t
|
|
{
|
|
{
|
|
uint32_t magic;
|
|
uint32_t magic;
|
|
|
|
+ uint8_t fs_version_major;
|
|
|
|
+ uint8_t fs_version_minor;
|
|
|
|
+ uint8_t fs_filename_len;
|
|
|
|
+ uint8_t fs_extention_len;
|
|
uint32_t entry_count;
|
|
uint32_t entry_count;
|
|
fileentry_t fent[];
|
|
fileentry_t fent[];
|
|
} miniffs_header_t;
|
|
} miniffs_header_t;
|
|
@@ -49,9 +62,9 @@ typedef struct file_t
|
|
} file_t;
|
|
} file_t;
|
|
|
|
|
|
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
|
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
|
-#define MAKE4(_a, _b, _c, _d) (((_a) & 0xFF) << 24) | (((_b) & 0xFF) << 16) | (((_c) & 0xFF) << 8) | ((_d) & 0xFF)
|
|
|
|
|
|
+#define MAKE4(_a, _b, _c, _d) ((((_a) & 0xFF) << 24) | (((_b) & 0xFF) << 16) | (((_c) & 0xFF) << 8) | ((_d) & 0xFF))
|
|
#else
|
|
#else
|
|
-#define MAKE4(_d, _c, _b, _a) (((_a) & 0xFF) << 24) | (((_b) & 0xFF) << 16) | (((_c) & 0xFF) << 8) | ((_d) & 0xFF)
|
|
|
|
|
|
+#define MAKE4(_d, _c, _b, _a) ((((_a) & 0xFF) << 24) | (((_b) & 0xFF) << 16) | (((_c) & 0xFF) << 8) | ((_d) & 0xFF))
|
|
#endif
|
|
#endif
|
|
#define MINIFFS_MAGIC MAKE4('M', 'F', 'F', 'S')
|
|
#define MINIFFS_MAGIC MAKE4('M', 'F', 'F', 'S')
|
|
|
|
|
|
@@ -67,18 +80,23 @@ enum {
|
|
*/
|
|
*/
|
|
|
|
|
|
/* miniffs_openfs is backend specific and will be found in the backend header file */
|
|
/* 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 */
|
|
|
|
-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*/
|
|
|
|
|
|
+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_blocks(void *ptr, size_t size, size_t nmemb, file_t *file); /***< Read blocks of bytes from a file */
|
|
|
|
+uint8_t miniffs_read(file_t *file); /***< Read a single byte 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
|
|
typedef enum miniffs_error_t
|
|
{
|
|
{
|
|
MINIFFS_NOERROR = 0,
|
|
MINIFFS_NOERROR = 0,
|
|
MINIFFS_INVALID_FS,
|
|
MINIFFS_INVALID_FS,
|
|
|
|
+ MINIFFS_INVALID_NAME,
|
|
|
|
+ MINIFFS_INVALID_PARAMS,
|
|
MINIFFS_FILE_NOT_FOUND,
|
|
MINIFFS_FILE_NOT_FOUND,
|
|
|
|
+ MINIFFS_ALLOCATION_ERROR,
|
|
|
|
+ MINIFFS_END_OF_FILE,
|
|
//MINIFFS_,
|
|
//MINIFFS_,
|
|
} miniffs_error_t;
|
|
} miniffs_error_t;
|
|
|
|
|
|
@@ -99,9 +117,10 @@ int miniffs_closefs(miniffs_t *fs);
|
|
/*
|
|
/*
|
|
* Function that are private to the library
|
|
* Function that are private to the library
|
|
*/
|
|
*/
|
|
-int miniffs_checkfs(miniffs_t *fs);
|
|
|
|
|
|
+bool miniffs_isvalidfs(miniffs_t *fs);
|
|
fileentry_t *miniffs_findfile(miniffs_t *fs, char *filename);
|
|
fileentry_t *miniffs_findfile(miniffs_t *fs, char *filename);
|
|
-
|
|
|
|
|
|
+void miniffs_seterror(miniffs_error_t err);
|
|
|
|
+void *miniffs_getfileaddr(miniffs_t *fs, fileentry_t *fent);
|
|
#endif /* __miniffs_internal */
|
|
#endif /* __miniffs_internal */
|
|
|
|
|
|
#endif /* MINIFFS_H */
|
|
#endif /* MINIFFS_H */
|