1
0
mirror of https://github.com/CovidBraceletPrj/CovidBracelet.git synced 2024-11-12 22:48:52 +01:00

Store CRC and 'not-deleted' flag in last byte of each entry

This commit is contained in:
H1ghBre4k3r 2021-04-13 01:22:12 +02:00 committed by Patrick Rathje
parent c4f035246b
commit bf9ad9cbec
2 changed files with 18 additions and 4 deletions

View File

@ -1,8 +1,11 @@
#include <drivers/flash.h>
#include <storage/flash_map.h>
#include <sys/crc.h>
#include "ens_fs.h"
#define SEED 42
int ens_fs_init(ens_fs_t* fs, uint8_t id, uint64_t entry_size) {
int rc = flash_area_open(id, &fs->area);
if (rc) {
@ -36,9 +39,11 @@ end:
int ens_fs_write(ens_fs_t* fs, uint64_t id, void* data) {
uint64_t offset = id * fs->entry_size;
// Set CRC and not-deleted-flag
uint8_t* obj = data;
obj[fs->entry_size - 1] = crc7_be(SEED, obj, fs->entry_size - 1) | 1;
// TODO lome: set CRC
uint64_t offset = id * fs->entry_size;
int rc = flash_area_write(fs->area, offset, data, fs->entry_size);
if(rc) {
goto end;
@ -49,7 +54,15 @@ end:
}
int ens_fs_delete(ens_fs_t* fs, uint64_t id) {
// TODO lome: Overwrite deleted flag.
// TODO lome: Maybe overwrite last 4 bytes? Or make it file system dependend?
// uint8_t data = 0;
// uint64_t offset = (id + 1) * fs->entry_size - 1;
// int rc = flash_area_write(fs->area, offset, &data, 0);
// if(rc) {
// goto end;
// }
return 0;
}

View File

@ -14,7 +14,8 @@ typedef struct ens_fs {
*/
const struct flash_area* area;
/**
* Size of each individual entry.
* Size of each individual entry. The last byte will be used by
* ens_fs to store metadata about each individual entry.
*/
size_t entry_size;
/**