52 #define PRINTF(...) printf(__VA_ARGS__) 59 #include "cfs-coffee-arch.h" 64 #ifndef COFFEE_MICRO_LOGS 65 #define COFFEE_MICRO_LOGS 1 70 #ifndef COFFEE_APPEND_ONLY 71 #define COFFEE_APPEND_ONLY 0 74 #if COFFEE_MICRO_LOGS && COFFEE_APPEND_ONLY 75 #error "Cannot have COFFEE_APPEND_ONLY set when COFFEE_MICRO_LOGS is set." 83 #ifndef COFFEE_EXTENDED_WEAR_LEVELLING 84 #define COFFEE_EXTENDED_WEAR_LEVELLING 1 87 #if COFFEE_START & (COFFEE_SECTOR_SIZE - 1) 88 #error COFFEE_START must point to the first byte in a sector. 92 #define COFFEE_FD_FREE 0x0 93 #define COFFEE_FD_READ 0x1 94 #define COFFEE_FD_WRITE 0x2 95 #define COFFEE_FD_APPEND 0x4 98 #define COFFEE_FILE_MODIFIED 0x1 101 #define INVALID_PAGE ((coffee_page_t)-1) 102 #define UNKNOWN_OFFSET ((cfs_offset_t)-1) 113 #define GC_RELUCTANT 1 116 #define FD_VALID(fd) ((fd) >= 0 && (fd) < COFFEE_FD_SET_SIZE && \ 117 coffee_fd_set[(fd)].flags != COFFEE_FD_FREE) 118 #define FD_READABLE(fd) (coffee_fd_set[(fd)].flags & CFS_READ) 119 #define FD_WRITABLE(fd) (coffee_fd_set[(fd)].flags & CFS_WRITE) 120 #define FD_APPENDABLE(fd) (coffee_fd_set[(fd)].flags & CFS_APPEND) 123 #define FILE_MODIFIED(file) ((file)->flags & COFFEE_FILE_MODIFIED) 124 #define FILE_FREE(file) ((file)->max_pages == 0) 125 #define FILE_UNREFERENCED(file) ((file)->references == 0) 128 #define HDR_FLAG_VALID 0x01 129 #define HDR_FLAG_ALLOCATED 0x02 130 #define HDR_FLAG_OBSOLETE 0x04 131 #define HDR_FLAG_MODIFIED 0x08 132 #define HDR_FLAG_LOG 0x10 133 #define HDR_FLAG_ISOLATED 0x20 136 #define CHECK_FLAG(hdr, flag) ((hdr).flags & (flag)) 137 #define HDR_VALID(hdr) CHECK_FLAG(hdr, HDR_FLAG_VALID) 138 #define HDR_ALLOCATED(hdr) CHECK_FLAG(hdr, HDR_FLAG_ALLOCATED) 139 #define HDR_FREE(hdr) !HDR_ALLOCATED(hdr) 140 #define HDR_LOG(hdr) CHECK_FLAG(hdr, HDR_FLAG_LOG) 141 #define HDR_MODIFIED(hdr) CHECK_FLAG(hdr, HDR_FLAG_MODIFIED) 142 #define HDR_ISOLATED(hdr) CHECK_FLAG(hdr, HDR_FLAG_ISOLATED) 143 #define HDR_OBSOLETE(hdr) CHECK_FLAG(hdr, HDR_FLAG_OBSOLETE) 144 #define HDR_ACTIVE(hdr) (HDR_ALLOCATED(hdr) && \ 145 !HDR_OBSOLETE(hdr) && \ 149 #define COFFEE_SECTOR_COUNT \ 150 (coffee_page_t)(COFFEE_SIZE / COFFEE_SECTOR_SIZE) 151 #define COFFEE_PAGE_COUNT \ 152 ((coffee_page_t)(COFFEE_SIZE / COFFEE_PAGE_SIZE)) 153 #define COFFEE_PAGES_PER_SECTOR \ 154 ((coffee_page_t)(COFFEE_SECTOR_SIZE / COFFEE_PAGE_SIZE)) 157 struct sector_status {
168 int16_t record_count;
185 uint16_t log_records;
186 uint16_t log_record_size;
188 uint8_t deprecated_eof_hint;
213 hdr->flags |= HDR_FLAG_VALID;
221 if(DEBUG && HDR_ACTIVE(*hdr) && !HDR_VALID(*hdr)) {
222 PRINTF(
"Coffee: Invalid header at page %u!\n", (
unsigned)page);
233 get_sector_status(
coffee_page_t sector,
struct sector_status *stats)
236 static char last_pages_are_active;
237 struct file_header hdr;
242 memset(stats, 0,
sizeof(*stats));
243 active = obsolete = free = 0;
252 last_pages_are_active = 0;
255 sector_start = sector * COFFEE_PAGES_PER_SECTOR;
256 sector_end = sector_start + COFFEE_PAGES_PER_SECTOR;
263 if(last_pages_are_active) {
264 if(skip_pages >= COFFEE_PAGES_PER_SECTOR) {
265 stats->active = COFFEE_PAGES_PER_SECTOR;
266 skip_pages -= COFFEE_PAGES_PER_SECTOR;
271 if(skip_pages >= COFFEE_PAGES_PER_SECTOR) {
272 stats->obsolete = COFFEE_PAGES_PER_SECTOR;
273 skip_pages -= COFFEE_PAGES_PER_SECTOR;
274 return skip_pages >= COFFEE_PAGES_PER_SECTOR ? 0 : skip_pages;
276 obsolete = skip_pages;
281 for(page = sector_start + skip_pages; page < sector_end;) {
282 read_header(&hdr, page);
283 last_pages_are_active = 0;
284 if(HDR_ACTIVE(hdr)) {
285 last_pages_are_active = 1;
286 page += hdr.max_pages;
287 active += hdr.max_pages;
288 }
else if(HDR_ISOLATED(hdr)) {
291 }
else if(HDR_OBSOLETE(hdr)) {
292 page += hdr.max_pages;
293 obsolete += hdr.max_pages;
295 free = sector_end - page;
308 skip_pages = active + obsolete + free - COFFEE_PAGES_PER_SECTOR;
310 if(last_pages_are_active) {
311 active = COFFEE_PAGES_PER_SECTOR - obsolete;
313 obsolete = COFFEE_PAGES_PER_SECTOR - active;
317 stats->active = active;
318 stats->obsolete = obsolete;
328 return (last_pages_are_active || (skip_pages >= COFFEE_PAGES_PER_SECTOR)) ?
335 struct file_header hdr;
340 memset(&hdr, 0,
sizeof(hdr));
341 hdr.flags = HDR_FLAG_ALLOCATED | HDR_FLAG_ISOLATED;
344 for(page = 0; page < skip_pages; page++) {
345 write_header(&hdr, start + page);
347 PRINTF(
"Coffee: Isolated %u pages starting in sector %d\n",
348 (
unsigned)skip_pages, (
int)start / COFFEE_PAGES_PER_SECTOR);
352 collect_garbage(
int mode)
355 struct sector_status stats;
358 PRINTF(
"Coffee: Running the garbage collector in %s mode\n",
359 mode == GC_RELUCTANT ?
"reluctant" :
"greedy");
364 for(sector = 0; sector < COFFEE_SECTOR_COUNT; sector++) {
365 isolation_count = get_sector_status(sector, &stats);
366 PRINTF(
"Coffee: Sector %u has %u active, %u obsolete, and %u free pages.\n",
367 (
unsigned)sector, (
unsigned)stats.active,
368 (
unsigned)stats.obsolete, (
unsigned)stats.free);
370 if(stats.active > 0) {
374 if((mode == GC_RELUCTANT && stats.free == 0) ||
375 (mode == GC_GREEDY && stats.obsolete > 0)) {
376 first_page = sector * COFFEE_PAGES_PER_SECTOR;
377 if(first_page < next_free) {
378 next_free = first_page;
381 if(isolation_count > 0) {
382 isolate_pages(first_page + COFFEE_PAGES_PER_SECTOR, isolation_count);
386 PRINTF(
"Coffee: Erased sector %d!\n", sector);
388 if(mode == GC_RELUCTANT && isolation_count > 0) {
409 return (page + COFFEE_PAGES_PER_SECTOR) & ~(COFFEE_PAGES_PER_SECTOR - 1);
410 }
else if(HDR_ISOLATED(*hdr)) {
413 return page + hdr->max_pages;
419 int i, unreferenced, free;
428 if(FILE_FREE(&coffee_files[i])) {
431 }
else if(FILE_UNREFERENCED(&coffee_files[i])) {
437 if(unreferenced != -1) {
444 file = &coffee_files[i];
446 file->end = UNKNOWN_OFFSET;
447 file->max_pages = hdr->max_pages;
448 file->flags = HDR_MODIFIED(*hdr) ? COFFEE_FILE_MODIFIED : 0;
450 file->record_count = -1;
456 find_file(
const char *name)
459 struct file_header hdr;
464 if(FILE_FREE(&coffee_files[i])) {
468 read_header(&hdr, coffee_files[i].page);
469 if(HDR_ACTIVE(hdr) && !HDR_LOG(hdr) && strcmp(name, hdr.name) == 0) {
470 return &coffee_files[i];
475 for(page = 0; page < COFFEE_PAGE_COUNT; page = next_file(page, &hdr)) {
476 read_header(&hdr, page);
477 if(HDR_ACTIVE(hdr) && !HDR_LOG(hdr) && strcmp(name, hdr.name) == 0) {
478 return load_file(page, &hdr);
488 struct file_header hdr;
493 read_header(&hdr, start);
503 for(page = hdr.max_pages - 1; page >= 0; page--) {
507 if(page == 0 && i <
sizeof(hdr)) {
523 struct file_header hdr;
525 start = INVALID_PAGE;
526 for(page = next_free; page < COFFEE_PAGE_COUNT;) {
527 read_header(&hdr, page);
529 if(start == INVALID_PAGE) {
531 if(start + amount >= COFFEE_PAGE_COUNT) {
539 page = next_file(page, &hdr);
541 if(start + amount <= page) {
542 if(start == next_free) {
543 next_free = start + amount;
548 start = INVALID_PAGE;
549 page = next_file(page, &hdr);
557 int close_fds,
int gc_allowed)
559 struct file_header hdr;
562 read_header(&hdr, page);
563 if(!HDR_ACTIVE(hdr)) {
567 if(remove_log && HDR_MODIFIED(hdr)) {
568 if(remove_by_page(hdr.log_page, !REMOVE_LOG, !CLOSE_FDS, !ALLOW_GC) < 0) {
573 hdr.flags |= HDR_FLAG_OBSOLETE;
574 write_header(&hdr, page);
581 if(coffee_fd_set[i].file != NULL && coffee_fd_set[i].file->page == page) {
582 coffee_fd_set[i].flags = COFFEE_FD_FREE;
588 if(coffee_files[i].page == page) {
589 coffee_files[i].page = INVALID_PAGE;
590 coffee_files[i].references = 0;
591 coffee_files[i].max_pages = 0;
595 if(!COFFEE_EXTENDED_WEAR_LEVELLING && gc_allowed) {
596 collect_garbage(GC_RELUCTANT);
603 page_count(cfs_offset_t size)
611 int allow_duplicates,
unsigned flags)
613 struct file_header hdr;
617 if(!allow_duplicates && find_file(name) != NULL) {
621 page = find_contiguous_pages(pages);
622 if(page == INVALID_PAGE) {
626 collect_garbage(GC_GREEDY);
627 page = find_contiguous_pages(pages);
628 if(page == INVALID_PAGE) {
634 memset(&hdr, 0,
sizeof(hdr));
635 strncpy(hdr.name, name,
sizeof(hdr.name) - 1);
636 hdr.max_pages = pages;
637 hdr.flags = HDR_FLAG_ALLOCATED | flags;
638 write_header(&hdr, page);
640 PRINTF(
"Coffee: Reserved %u pages starting from %u for file %s\n",
641 (
unsigned)pages, (
unsigned)page, name);
643 file = load_file(page, &hdr);
651 #if COFFEE_MICRO_LOGS 653 adjust_log_config(
struct file_header *hdr,
654 uint16_t *log_record_size, uint16_t *log_records)
656 *log_record_size = hdr->log_record_size == 0 ?
658 *log_records = hdr->log_records == 0 ?
663 #if COFFEE_MICRO_LOGS 665 modify_log_buffer(uint16_t log_record_size,
666 cfs_offset_t *offset, uint16_t *size)
670 region = *offset / log_record_size;
671 *offset %= log_record_size;
673 if(*size > log_record_size - *offset) {
674 *size = log_record_size - *offset;
681 #if COFFEE_MICRO_LOGS 683 get_record_index(
coffee_page_t log_page, uint16_t search_records,
689 int16_t match_index, i;
691 base = absolute_offset(log_page,
sizeof(uint16_t) * search_records);
698 uint16_t indices[batch_size];
700 while(processed < search_records && match_index < 0) {
701 if(batch_size + processed > search_records) {
702 batch_size = search_records - processed;
705 base -= batch_size *
sizeof(indices[0]);
706 COFFEE_READ(&indices,
sizeof(indices[0]) * batch_size, base);
708 for(i = batch_size - 1; i >= 0; i--) {
709 if(indices[i] - 1 == region) {
710 match_index = search_records - processed - (batch_size - i);
715 processed += batch_size;
723 #if COFFEE_MICRO_LOGS 725 read_log_page(
struct file_header *hdr, int16_t record_count,
726 struct log_param *lp)
730 uint16_t log_record_size;
731 uint16_t log_records;
733 uint16_t search_records;
735 adjust_log_config(hdr, &log_record_size, &log_records);
736 region = modify_log_buffer(log_record_size, &lp->offset, &lp->size);
738 search_records = record_count < 0 ? log_records : record_count;
739 match_index = get_record_index(hdr->log_page, search_records, region);
740 if(match_index < 0) {
744 base = absolute_offset(hdr->log_page, log_records *
sizeof(region));
745 base += (cfs_offset_t)match_index * log_record_size;
753 #if COFFEE_MICRO_LOGS 755 create_log(
struct file *file,
struct file_header *hdr)
757 uint16_t log_record_size, log_records;
759 struct file *log_file;
761 adjust_log_config(hdr, &log_record_size, &log_records);
764 size = log_records * (
sizeof(uint16_t) + log_record_size);
766 log_file = reserve(hdr->name, page_count(size), 1, HDR_FLAG_LOG);
767 if(log_file == NULL) {
771 hdr->flags |= HDR_FLAG_MODIFIED;
772 hdr->log_page = log_file->page;
773 write_header(hdr, file->page);
775 file->flags |= COFFEE_FILE_MODIFIED;
776 return log_file->page;
783 struct file_header hdr, hdr2;
787 struct file *new_file;
790 read_header(&hdr, file_page);
801 max_pages = hdr.max_pages << extend;
802 new_file = reserve(hdr.name, max_pages, 1, 0);
803 if(new_file == NULL) {
810 char buf[hdr.log_record_size == 0 ?
COFFEE_PAGE_SIZE : hdr.log_record_size];
813 remove_by_page(new_file->page, !REMOVE_LOG, !CLOSE_FDS, ALLOW_GC);
817 COFFEE_WRITE(buf, n, absolute_offset(new_file->page, offset));
823 if(coffee_fd_set[i].flags != COFFEE_FD_FREE &&
824 coffee_fd_set[i].file->page == file_page) {
825 coffee_fd_set[i].file = new_file;
826 new_file->references++;
830 if(remove_by_page(file_page, REMOVE_LOG, !CLOSE_FDS, !ALLOW_GC) < 0) {
831 remove_by_page(new_file->page, !REMOVE_LOG, !CLOSE_FDS, !ALLOW_GC);
837 read_header(&hdr2, new_file->page);
838 hdr2.log_record_size = hdr.log_record_size;
839 hdr2.log_records = hdr.log_records;
840 write_header(&hdr2, new_file->page);
842 new_file->flags &= ~COFFEE_FILE_MODIFIED;
843 new_file->end = offset;
850 #if COFFEE_MICRO_LOGS 855 int log_record, preferred_batch_size;
857 if(file->record_count >= 0) {
858 return file->record_count;
865 uint16_t indices[preferred_batch_size];
869 log_record = log_records;
870 for(processed = 0; processed < log_records; processed += batch_size) {
871 batch_size = log_records - processed >= preferred_batch_size ?
872 preferred_batch_size : log_records - processed;
874 COFFEE_READ(&indices, batch_size *
sizeof(indices[0]),
875 absolute_offset(log_page, processed *
sizeof(indices[0])));
876 for(log_record = 0; log_record < batch_size; log_record++) {
877 if(indices[log_record] == 0) {
878 log_record += processed;
889 #if COFFEE_MICRO_LOGS 891 write_log_page(
struct file *file,
struct log_param *lp)
893 struct file_header hdr;
897 uint16_t log_record_size;
898 uint16_t log_records;
900 struct log_param lp_out;
902 read_header(&hdr, file->page);
904 adjust_log_config(&hdr, &log_record_size, &log_records);
905 region = modify_log_buffer(log_record_size, &lp->offset, &lp->size);
908 if(HDR_MODIFIED(hdr)) {
910 log_page = hdr.log_page;
911 log_record = find_next_record(file, log_page, log_records);
912 if(log_record >= log_records) {
914 PRINTF(
"Coffee: Merging the file %s with its log\n", hdr.name);
915 return merge_log(file->page, 0);
919 log_page = create_log(file, &hdr);
920 if(log_page == INVALID_PAGE) {
923 PRINTF(
"Coffee: Created a log structure for file %s at page %u\n",
924 hdr.name, (
unsigned)log_page);
925 hdr.log_page = log_page;
930 char copy_buf[log_record_size];
932 lp_out.offset = offset = region * log_record_size;
933 lp_out.buf = copy_buf;
934 lp_out.size = log_record_size;
936 if((lp->offset > 0 || lp->size != log_record_size) &&
937 read_log_page(&hdr, log_record, &lp_out) < 0) {
939 absolute_offset(file->page, offset));
942 memcpy(©_buf[lp->offset], lp->buf, lp->size);
948 offset = absolute_offset(log_page, 0);
951 offset + log_record *
sizeof(region));
953 offset += log_records *
sizeof(region);
955 offset + log_record * log_record_size);
956 file->record_count = log_record + 1;
964 get_available_fd(
void)
969 if(coffee_fd_set[i].flags == COFFEE_FD_FREE) {
980 struct file_desc *fdp;
982 fd = get_available_fd();
984 PRINTF(
"Coffee: Failed to allocate a new file descriptor!\n");
988 fdp = &coffee_fd_set[fd];
992 fdp->file = find_file(name);
993 if(fdp->file == NULL) {
998 if(fdp->file == NULL) {
1002 }
else if(fdp->file->end == UNKNOWN_OFFSET) {
1003 fdp->file->end = file_end(fdp->file->page);
1006 fdp->flags |= flags;
1007 fdp->offset = flags &
CFS_APPEND ? fdp->file->end : 0;
1008 fdp->file->references++;
1017 coffee_fd_set[fd].flags = COFFEE_FD_FREE;
1018 coffee_fd_set[fd].file->references--;
1019 coffee_fd_set[fd].file = NULL;
1026 struct file_desc *fdp;
1027 cfs_offset_t new_offset;
1032 fdp = &coffee_fd_set[fd];
1035 new_offset = offset;
1037 new_offset = fdp->file->end + offset;
1039 new_offset = fdp->offset + offset;
1041 return (cfs_offset_t)-1;
1044 if(new_offset < 0 || new_offset > fdp->file->max_pages *
COFFEE_PAGE_SIZE) {
1048 if(fdp->file->end < new_offset) {
1049 if(FD_WRITABLE(fd)) {
1050 fdp->file->end = new_offset;
1053 return (cfs_offset_t)-1;
1057 return fdp->offset = new_offset;
1071 file = find_file(name);
1076 return remove_by_page(file->page, REMOVE_LOG, CLOSE_FDS, ALLOW_GC);
1080 cfs_read(
int fd,
void *buf,
unsigned size)
1082 struct file_desc *fdp;
1084 #if COFFEE_MICRO_LOGS 1085 struct file_header hdr;
1086 struct log_param lp;
1087 unsigned bytes_left;
1091 if(!(FD_VALID(fd) && FD_READABLE(fd))) {
1095 fdp = &coffee_fd_set[fd];
1099 while(fdp->offset + size > file->end) {
1100 ((
char *)buf)[--size] =
'\0';
1102 }
else if(fdp->offset + size > file->end) {
1103 size = file->end - fdp->offset;
1107 if(!FILE_MODIFIED(file)) {
1108 COFFEE_READ(buf, size, absolute_offset(file->page, fdp->offset));
1109 fdp->offset += size;
1113 #if COFFEE_MICRO_LOGS 1114 read_header(&hdr, file->page);
1121 for(bytes_left = size; bytes_left > 0; bytes_left -= r) {
1122 lp.offset = fdp->offset;
1124 lp.size = bytes_left;
1125 r = read_log_page(&hdr, file->record_count, &lp);
1129 COFFEE_READ(buf, lp.size, absolute_offset(file->page, fdp->offset));
1133 buf = (
char *)buf + r;
1141 cfs_write(
int fd,
const void *buf,
unsigned size)
1143 struct file_desc *fdp;
1145 #if COFFEE_MICRO_LOGS 1147 struct log_param lp;
1148 cfs_offset_t bytes_left;
1149 int8_t need_dummy_write;
1150 const char dummy[1] = { 0xff };
1153 if(!(FD_VALID(fd) && FD_WRITABLE(fd))) {
1157 fdp = &coffee_fd_set[fd];
1162 while(size + fdp->offset +
sizeof(
struct file_header) >
1164 if(merge_log(file->page, 1) < 0) {
1168 PRINTF(
"Extended the file at page %u\n", (
unsigned)file->page);
1172 #if COFFEE_MICRO_LOGS 1174 (FILE_MODIFIED(file) || fdp->offset < file->end)) {
1175 need_dummy_write = 0;
1176 for(bytes_left = size; bytes_left > 0;) {
1177 lp.offset = fdp->offset;
1178 lp.buf = (
void *)buf;
1179 lp.size = bytes_left;
1180 i = write_log_page(file, &lp);
1183 if(size == bytes_left) {
1194 buf = (
char *)buf + i;
1198 if(fdp->offset > file->end) {
1199 file->end = fdp->offset;
1200 need_dummy_write = 1;
1205 if(need_dummy_write) {
1212 COFFEE_WRITE(dummy, 1, absolute_offset(file->page, fdp->offset - 1));
1220 COFFEE_WRITE(buf, size, absolute_offset(file->page, fdp->offset));
1221 fdp->offset += size;
1222 #if COFFEE_MICRO_LOGS 1226 if(fdp->offset > file->end) {
1227 file->end = fdp->offset;
1247 struct file_header hdr;
1253 while(page < COFFEE_PAGE_COUNT) {
1254 read_header(&hdr, page);
1255 if(HDR_ACTIVE(hdr) && !HDR_LOG(hdr)) {
1256 memcpy(record->name, hdr.name,
sizeof(record->name));
1257 record->name[
sizeof(record->name) - 1] =
'\0';
1258 record->size = file_end(page);
1260 next_page = next_file(page, &hdr);
1264 page = next_file(page, &hdr);
1279 return reserve(name, page_count(size), 0, 0) == NULL ? -1 : 0;
1284 unsigned log_record_size)
1287 struct file_header hdr;
1290 log_size < log_record_size) {
1294 file = find_file(filename);
1299 read_header(&hdr, file->page);
1300 if(HDR_MODIFIED(hdr)) {
1305 hdr.log_records = log_size / log_record_size;
1306 hdr.log_record_size = log_record_size;
1307 write_header(&hdr, file->page);
1319 coffee_fd_set[fd].io_flags |= flags;
1329 PRINTF(
"Coffee: Formatting %u sectors", (
unsigned)COFFEE_SECTOR_COUNT);
1331 for(i = 0; i < COFFEE_SECTOR_COUNT; i++) {
1337 memset(&coffee_files, 0,
sizeof(coffee_files));
1338 memset(&coffee_fd_set, 0,
sizeof(coffee_fd_set));
static bool start(void)
Start measurement.
Header for the Coffee file system.
#define COFFEE_FD_SET_SIZE
Number of file descriptor entries.
#define COFFEE_READ(buf, size, offset)
Read.
int cfs_open(const char *name, int flags)
Open a file.
int cfs_coffee_set_io_semantics(int fd, unsigned flags)
Set the I/O semantics for accessing a file.
#define COFFEE_MAX_OPEN_FILES
Number of file cache entries.
int cfs_coffee_configure_log(const char *filename, unsigned log_size, unsigned log_record_size)
Configure the on-demand log file.
#define COFFEE_LOG_SIZE
Default micro-log size.
#define COFFEE_APPEND_ONLY
Whether files are expected to be appended to only.
int cfs_remove(const char *name)
Remove a file.
cfs_offset_t cfs_seek(int fd, cfs_offset_t offset, int whence)
Seek to a specified position in an open file.
int16_t coffee_page_t
Page.
#define CFS_APPEND
Specify that cfs_open() should append written data to the file rather than overwriting it...
int cfs_write(int fd, const void *buf, unsigned int len)
Write data to an open file.
#define COFFEE_WRITE(buf, size, offset)
Write.
#define COFFEE_DYN_SIZE
Default reserved file size.
#define CFS_COFFEE_IO_FLASH_AWARE
Instruct Coffee that the access pattern to this file is adapted to flash I/O semantics by design...
int cfs_opendir(struct cfs_dir *dir, const char *name)
Open a directory for reading directory entries.
void cfs_close(int fd)
Close an open file.
#define CFS_COFFEE_IO_FIRM_SIZE
Instruct Coffee not to attempt to extend the file upon a request to write past the reserved file size...
int cfs_readdir(struct cfs_dir *dir, struct cfs_dirent *record)
Read a directory entry.
#define CFS_SEEK_END
Specify that cfs_seek() should compute the offset from the end of the file.
int cfs_read(int fd, void *buf, unsigned int len)
Read data from an open file.
#define CFS_READ
Specify that cfs_open() should open a file for reading.
int cfs_coffee_reserve(const char *name, cfs_offset_t size)
Reserve space for a file.
#define CFS_SEEK_CUR
Specify that cfs_seek() should compute the offset from the current position of the file pointer...
#define CFS_SEEK_SET
Specify that cfs_seek() should compute the offset from the beginning of the file. ...
void cfs_closedir(struct cfs_dir *dir)
Close a directory opened with cfs_opendir().
#define CFS_WRITE
Specify that cfs_open() should open a file for writing.
int cfs_coffee_format(void)
Format the storage area assigned to Coffee.
#define COFFEE_NAME_LENGTH
Maximal filename length.
#define COFFEE_ERASE(sector)
Erase.
#define COFFEE_LOG_TABLE_LIMIT
Maximal amount of log table entries read in one batch.
#define CFS_COFFEE_IO_ENSURE_READ_LENGTH
Instruct Coffee to set unused bytes in the destination buffer to zero.
#define COFFEE_PAGE_SIZE
Logical page size.