mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
f0bd96b690
This implements basic features with the VFS interface
237 lines
8.3 KiB
Diff
237 lines
8.3 KiB
Diff
From 3c753304a7366514c86abfba436103b2f37edf15 Mon Sep 17 00:00:00 2001
|
|
From: Vincent Dupont <vincent@otakeys.com>
|
|
Date: Thu, 8 Sep 2016 14:38:18 +0200
|
|
Subject: [PATCH 2/2] Use const pointer through all write functions
|
|
|
|
HAL API has been updated to use const pointer when writing
|
|
---
|
|
src/spiffs.h | 4 ++--
|
|
src/spiffs_cache.c | 2 +-
|
|
src/spiffs_hydrogen.c | 18 ++++++++++--------
|
|
src/spiffs_nucleus.c | 12 ++++++------
|
|
src/spiffs_nucleus.h | 8 ++++----
|
|
5 files changed, 23 insertions(+), 21 deletions(-)
|
|
|
|
diff --git a/src/spiffs.h b/src/spiffs.h
|
|
index dfe967d..8a42868 100644
|
|
--- a/src/spiffs.h
|
|
+++ b/src/spiffs.h
|
|
@@ -81,7 +81,7 @@ struct spiffs_t;
|
|
/* spi read call function type */
|
|
typedef s32_t (*spiffs_read)(struct spiffs_t *fs, u32_t addr, u32_t size, u8_t *dst);
|
|
/* spi write call function type */
|
|
-typedef s32_t (*spiffs_write)(struct spiffs_t *fs, u32_t addr, u32_t size, u8_t *src);
|
|
+typedef s32_t (*spiffs_write)(struct spiffs_t *fs, u32_t addr, u32_t size, const u8_t *src);
|
|
/* spi erase call function type */
|
|
typedef s32_t (*spiffs_erase)(struct spiffs_t *fs, u32_t addr, u32_t size);
|
|
|
|
@@ -90,7 +90,7 @@ typedef s32_t (*spiffs_erase)(struct spiffs_t *fs, u32_t addr, u32_t size);
|
|
/* spi read call function type */
|
|
typedef s32_t (*spiffs_read)(u32_t addr, u32_t size, u8_t *dst);
|
|
/* spi write call function type */
|
|
-typedef s32_t (*spiffs_write)(u32_t addr, u32_t size, u8_t *src);
|
|
+typedef s32_t (*spiffs_write)(u32_t addr, u32_t size, const u8_t *src);
|
|
/* spi erase call function type */
|
|
typedef s32_t (*spiffs_erase)(u32_t addr, u32_t size);
|
|
#endif // SPIFFS_HAL_CALLBACK_EXTRA
|
|
diff --git a/src/spiffs_cache.c b/src/spiffs_cache.c
|
|
index b508ad5..65f8cd2 100644
|
|
--- a/src/spiffs_cache.c
|
|
+++ b/src/spiffs_cache.c
|
|
@@ -183,7 +183,7 @@ s32_t spiffs_phys_wr(
|
|
spiffs_file fh,
|
|
u32_t addr,
|
|
u32_t len,
|
|
- u8_t *src) {
|
|
+ const u8_t *src) {
|
|
(void)fh;
|
|
spiffs_page_ix pix = SPIFFS_PADDR_TO_PAGE(fs, addr);
|
|
spiffs_cache *cache = spiffs_get_cache(fs);
|
|
diff --git a/src/spiffs_hydrogen.c b/src/spiffs_hydrogen.c
|
|
index 8eb3919..b2c3d92 100644
|
|
--- a/src/spiffs_hydrogen.c
|
|
+++ b/src/spiffs_hydrogen.c
|
|
@@ -417,7 +417,7 @@ static s32_t spiffs_hydro_write(spiffs *fs, spiffs_fd *fd, const void *buf, u32_
|
|
s32_t remaining = len;
|
|
if (fd->size != SPIFFS_UNDEFINED_LEN && offset < fd->size) {
|
|
s32_t m_len = MIN((s32_t)(fd->size - offset), len);
|
|
- res = spiffs_object_modify(fd, offset, (u8_t *)buf, m_len);
|
|
+ res = spiffs_object_modify(fd, offset, buf, m_len);
|
|
SPIFFS_CHECK_RES(res);
|
|
remaining -= m_len;
|
|
u8_t *buf_8 = (u8_t *)buf;
|
|
@@ -426,7 +426,7 @@ static s32_t spiffs_hydro_write(spiffs *fs, spiffs_fd *fd, const void *buf, u32_
|
|
offset += m_len;
|
|
}
|
|
if (remaining > 0) {
|
|
- res = spiffs_object_append(fd, offset, (u8_t *)buf, remaining);
|
|
+ res = spiffs_object_append(fd, offset, buf, remaining);
|
|
SPIFFS_CHECK_RES(res);
|
|
}
|
|
return len;
|
|
@@ -499,7 +499,7 @@ s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, const void *buf, s32_t len) {
|
|
spiffs_get_cache_page(fs, spiffs_get_cache(fs), fd->cache_page->ix),
|
|
fd->cache_page->offset, fd->cache_page->size);
|
|
spiffs_cache_fd_release(fs, fd->cache_page);
|
|
- SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
|
+ SPIFFS_API_CHECK_RES(fs, res);
|
|
} else {
|
|
// writing within cache
|
|
alloc_cpage = 0;
|
|
@@ -530,7 +530,7 @@ s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, const void *buf, s32_t len) {
|
|
return len;
|
|
} else {
|
|
res = spiffs_hydro_write(fs, fd, buf, offset, len);
|
|
- SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
|
+ SPIFFS_API_CHECK_RES(fs, res);
|
|
fd->fdoffset += len;
|
|
SPIFFS_UNLOCK(fs);
|
|
return res;
|
|
@@ -553,7 +553,7 @@ s32_t SPIFFS_write(spiffs *fs, spiffs_file fh, const void *buf, s32_t len) {
|
|
#endif
|
|
|
|
res = spiffs_hydro_write(fs, fd, buf, offset, len);
|
|
- SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
|
+ SPIFFS_API_CHECK_RES(fs, res);
|
|
fd->fdoffset += len;
|
|
|
|
SPIFFS_UNLOCK(fs);
|
|
@@ -571,7 +571,7 @@ s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence) {
|
|
s32_t res;
|
|
fh = SPIFFS_FH_UNOFFS(fs, fh);
|
|
res = spiffs_fd_get(fs, fh, &fd);
|
|
- SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
|
+ SPIFFS_API_CHECK_RES(fs, res);
|
|
|
|
#if SPIFFS_CACHE_WR
|
|
spiffs_fflush_cache(fs, fh);
|
|
@@ -917,7 +917,7 @@ static s32_t spiffs_read_dir_v(
|
|
if (res != SPIFFS_OK) return res;
|
|
if ((obj_id & SPIFFS_OBJ_ID_IX_FLAG) &&
|
|
objix_hdr.p_hdr.span_ix == 0 &&
|
|
- (objix_hdr.p_hdr.flags & (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_IXDELE)) ==
|
|
+ (objix_hdr.p_hdr.flags& (SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_IXDELE)) ==
|
|
(SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_IXDELE)) {
|
|
struct spiffs_dirent *e = (struct spiffs_dirent*)user_var_p;
|
|
e->obj_id = obj_id;
|
|
@@ -927,6 +927,7 @@ static s32_t spiffs_read_dir_v(
|
|
e->pix = pix;
|
|
return SPIFFS_OK;
|
|
}
|
|
+
|
|
return SPIFFS_VIS_COUNTINUE;
|
|
}
|
|
|
|
@@ -1305,10 +1306,11 @@ s32_t SPIFFS_vis(spiffs *fs) {
|
|
spiffs_printf("free_blocks: %i\n", fs->free_blocks);
|
|
spiffs_printf("page_alloc: %i\n", fs->stats_p_allocated);
|
|
spiffs_printf("page_delet: %i\n", fs->stats_p_deleted);
|
|
- SPIFFS_UNLOCK(fs);
|
|
u32_t total, used;
|
|
SPIFFS_info(fs, &total, &used);
|
|
spiffs_printf("used: %i of %i\n", used, total);
|
|
+
|
|
+ SPIFFS_UNLOCK(fs);
|
|
return res;
|
|
}
|
|
#endif
|
|
diff --git a/src/spiffs_nucleus.c b/src/spiffs_nucleus.c
|
|
index 35fe0d4..625d036 100644
|
|
--- a/src/spiffs_nucleus.c
|
|
+++ b/src/spiffs_nucleus.c
|
|
@@ -73,7 +73,7 @@ s32_t spiffs_phys_wr(
|
|
spiffs *fs,
|
|
u32_t addr,
|
|
u32_t len,
|
|
- u8_t *src) {
|
|
+ const u8_t *src) {
|
|
return SPIFFS_HAL_WRITE(fs, addr, len, src);
|
|
}
|
|
|
|
@@ -142,7 +142,7 @@ s32_t spiffs_obj_lu_find_entry_visitor(
|
|
int entries_per_page = (SPIFFS_CFG_LOG_PAGE_SZ(fs) / sizeof(spiffs_obj_id));
|
|
|
|
// wrap initial
|
|
- if (cur_entry > (int)SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs) - 1) {
|
|
+ if (cur_entry >= (int)SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs) - 1) {
|
|
cur_entry = 0;
|
|
cur_block++;
|
|
cur_block_addr = cur_block * SPIFFS_CFG_LOG_BLOCK_SZ(fs);
|
|
@@ -467,7 +467,7 @@ s32_t spiffs_obj_lu_find_free(
|
|
SPIFFS_OBJ_ID_FREE, block_ix, lu_entry);
|
|
if (res == SPIFFS_OK) {
|
|
fs->free_cursor_block_ix = *block_ix;
|
|
- fs->free_cursor_obj_lu_entry = (*lu_entry) + 1;
|
|
+ fs->free_cursor_obj_lu_entry = *lu_entry;
|
|
if (*lu_entry == 0) {
|
|
fs->free_blocks--;
|
|
}
|
|
@@ -754,7 +754,7 @@ s32_t spiffs_page_allocate_data(
|
|
spiffs *fs,
|
|
spiffs_obj_id obj_id,
|
|
spiffs_page_header *ph,
|
|
- u8_t *data,
|
|
+ const u8_t *data,
|
|
u32_t len,
|
|
u32_t page_offs,
|
|
u8_t finalize,
|
|
@@ -1155,7 +1155,7 @@ s32_t spiffs_object_open_by_page(
|
|
#if !SPIFFS_READ_ONLY
|
|
// Append to object
|
|
// keep current object index (header) page in fs->work buffer
|
|
-s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|
+s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, const u8_t *data, u32_t len) {
|
|
spiffs *fs = fd->fs;
|
|
s32_t res = SPIFFS_OK;
|
|
u32_t written = 0;
|
|
@@ -1402,7 +1402,7 @@ s32_t spiffs_object_append(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|
#if !SPIFFS_READ_ONLY
|
|
// Modify object
|
|
// keep current object index (header) page in fs->work buffer
|
|
-s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, u8_t *data, u32_t len) {
|
|
+s32_t spiffs_object_modify(spiffs_fd *fd, u32_t offset, const u8_t *data, u32_t len) {
|
|
spiffs *fs = fd->fs;
|
|
s32_t res = SPIFFS_OK;
|
|
u32_t written = 0;
|
|
diff --git a/src/spiffs_nucleus.h b/src/spiffs_nucleus.h
|
|
index 0fa1cb3..2e6afa1 100644
|
|
--- a/src/spiffs_nucleus.h
|
|
+++ b/src/spiffs_nucleus.h
|
|
@@ -532,7 +532,7 @@ s32_t spiffs_phys_wr(
|
|
#endif
|
|
u32_t addr,
|
|
u32_t len,
|
|
- u8_t *src);
|
|
+ const u8_t *src);
|
|
|
|
s32_t spiffs_phys_cpy(
|
|
spiffs *fs,
|
|
@@ -610,7 +610,7 @@ s32_t spiffs_page_allocate_data(
|
|
spiffs *fs,
|
|
spiffs_obj_id obj_id,
|
|
spiffs_page_header *ph,
|
|
- u8_t *data,
|
|
+ const u8_t *data,
|
|
u32_t len,
|
|
u32_t page_offs,
|
|
u8_t finalize,
|
|
@@ -684,13 +684,13 @@ s32_t spiffs_object_open_by_page(
|
|
s32_t spiffs_object_append(
|
|
spiffs_fd *fd,
|
|
u32_t offset,
|
|
- u8_t *data,
|
|
+ const u8_t *data,
|
|
u32_t len);
|
|
|
|
s32_t spiffs_object_modify(
|
|
spiffs_fd *fd,
|
|
u32_t offset,
|
|
- u8_t *data,
|
|
+ const u8_t *data,
|
|
u32_t len);
|
|
|
|
s32_t spiffs_object_read(
|
|
--
|
|
2.9.3
|
|
|