From bce989eb57cf23b6f72bcc28afe82b5854fffff8 Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Mon, 23 Mar 2015 22:21:24 +0100 Subject: [PATCH] Struct alignment needed for some targets, define in spiffs_config #10 Added config define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES, default disabled --- src/default/spiffs_config.h | 7 ++++++- src/spiffs_nucleus.h | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/default/spiffs_config.h b/src/default/spiffs_config.h index 33a712e..169a88f 100644 --- a/src/default/spiffs_config.h +++ b/src/default/spiffs_config.h @@ -151,7 +151,12 @@ #endif #endif -// Set SPFIFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function +// Enable this if your target needs aligned data for index tables +#ifndef SPIFFS_ALIGNED_OBJECT_INDEX_TABLES +#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 0 +#endif + +// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function // in the api. This function will visualize all filesystem using given printf // function. #ifndef SPIFFS_TEST_VISUALISATION diff --git a/src/spiffs_nucleus.h b/src/spiffs_nucleus.h index 01a1f05..a8e30b7 100644 --- a/src/spiffs_nucleus.h +++ b/src/spiffs_nucleus.h @@ -381,6 +381,8 @@ typedef struct { // object structs // page header, part of each page except object lookup pages +// NB: this is always aligned when the data page is an object index, +// as in this case struct spiffs_page_object_ix is used typedef struct __attribute(( packed )) { // object id spiffs_obj_id obj_id; @@ -391,7 +393,11 @@ typedef struct __attribute(( packed )) { } spiffs_page_header; // object index header page header -typedef struct __attribute(( packed )) { +typedef struct __attribute(( packed )) +#if SPIFFS_ALIGNED_OBJECT_INDEX_TABLES + __attribute(( aligned(sizeof(spiffs_page_ix)) )) +#endif +{ // common page header spiffs_page_header p_hdr; // alignment