123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- #ifndef RINGFS_H
- #define RINGFS_H
- #include <stdint.h>
- #if defined ( __GNUC__ )
- #include <unistd.h>
- #endif
- #ifdef PRINTF_STDLIB
- #include <stdio.h>
- #endif
- #ifdef PRINTF_CUSTOM
- #include "tinystdio.h"
- #endif
- #if defined ( __ICCARM__ )
- typedef int ssize_t;
- #include <stdlib.h>
- #endif
-
- struct ringfs_flash_partition
- {
- int sector_size;
- int sector_offset;
- int sector_count;
-
- int (*sector_erase)(struct ringfs_flash_partition *flash, int address);
-
- ssize_t (*program)(struct ringfs_flash_partition *flash, int address, const void *data, size_t size);
-
- ssize_t (*read)(struct ringfs_flash_partition *flash, int address, void *data, size_t size);
- };
- struct ringfs_loc {
- int sector;
- int slot;
- };
- struct ringfs {
-
- struct ringfs_flash_partition *flash;
- uint32_t version;
- int object_size;
-
- int slots_per_sector;
-
- struct ringfs_loc read;
- struct ringfs_loc write;
- struct ringfs_loc cursor;
- int cursor_position;
- };
- int ringfs_init(struct ringfs *fs, struct ringfs_flash_partition *flash, uint32_t version, int object_size);
- int ringfs_format(struct ringfs *fs);
- int ringfs_scan(struct ringfs *fs);
- int ringfs_capacity(struct ringfs *fs);
- int ringfs_count_estimate(struct ringfs *fs);
- int ringfs_count_exact(struct ringfs *fs);
- int ringfs_cursor_position(struct ringfs *fs);
- int ringfs_append(struct ringfs *fs, const void *object);
- int ringfs_fetch(struct ringfs *fs, void *object);
- int ringfs_discard(struct ringfs *fs);
- int ringfs_rewind(struct ringfs *fs);
- #endif
|