mirror of
https://github.com/pellepl/spiffs.git
synced 2026-09-15 21:50:05 +00:00
Merge pull request #53 from raburton/master
make api string params const
This commit is contained in:
+6
-8
@@ -5,8 +5,6 @@
|
||||
* Author: petera
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef SPIFFS_H_
|
||||
#define SPIFFS_H_
|
||||
#if defined(__cplusplus)
|
||||
@@ -315,7 +313,7 @@ void SPIFFS_unmount(spiffs *fs);
|
||||
* @param path the path of the new file
|
||||
* @param mode ignored, for posix compliance
|
||||
*/
|
||||
s32_t SPIFFS_creat(spiffs *fs, char *path, spiffs_mode mode);
|
||||
s32_t SPIFFS_creat(spiffs *fs, const char *path, spiffs_mode mode);
|
||||
|
||||
/**
|
||||
* Opens/creates a file.
|
||||
@@ -326,7 +324,7 @@ s32_t SPIFFS_creat(spiffs *fs, char *path, spiffs_mode mode);
|
||||
* SPIFFS_WR_ONLY, SPIFFS_RDWR, SPIFFS_DIRECT
|
||||
* @param mode ignored, for posix compliance
|
||||
*/
|
||||
spiffs_file SPIFFS_open(spiffs *fs, char *path, spiffs_flags flags, spiffs_mode mode);
|
||||
spiffs_file SPIFFS_open(spiffs *fs, const char *path, spiffs_flags flags, spiffs_mode mode);
|
||||
|
||||
|
||||
/**
|
||||
@@ -381,7 +379,7 @@ s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence);
|
||||
* @param fs the file system struct
|
||||
* @param path the path of the file to remove
|
||||
*/
|
||||
s32_t SPIFFS_remove(spiffs *fs, char *path);
|
||||
s32_t SPIFFS_remove(spiffs *fs, const char *path);
|
||||
|
||||
/**
|
||||
* Removes a file by filehandle
|
||||
@@ -396,7 +394,7 @@ s32_t SPIFFS_fremove(spiffs *fs, spiffs_file fh);
|
||||
* @param path the path of the file to stat
|
||||
* @param s the stat struct to populate
|
||||
*/
|
||||
s32_t SPIFFS_stat(spiffs *fs, char *path, spiffs_stat *s);
|
||||
s32_t SPIFFS_stat(spiffs *fs, const char *path, spiffs_stat *s);
|
||||
|
||||
/**
|
||||
* Gets file status by filehandle
|
||||
@@ -426,7 +424,7 @@ s32_t SPIFFS_close(spiffs *fs, spiffs_file fh);
|
||||
* @param old path of file to rename
|
||||
* @param newPath new path of file
|
||||
*/
|
||||
s32_t SPIFFS_rename(spiffs *fs, char *old, char *newPath);
|
||||
s32_t SPIFFS_rename(spiffs *fs, const char *old, const char *newPath);
|
||||
|
||||
/**
|
||||
* Returns last error of last file operation.
|
||||
@@ -449,7 +447,7 @@ void SPIFFS_clearerr(spiffs *fs);
|
||||
* @param name the name of the directory
|
||||
* @param d pointer the directory stream to be populated
|
||||
*/
|
||||
spiffs_DIR *SPIFFS_opendir(spiffs *fs, char *name, spiffs_DIR *d);
|
||||
spiffs_DIR *SPIFFS_opendir(spiffs *fs, const char *name, spiffs_DIR *d);
|
||||
|
||||
/**
|
||||
* Closes a directory stream
|
||||
|
||||
+8
-8
@@ -440,9 +440,9 @@ static s32_t spiffs_lookup_check_validate(spiffs *fs, spiffs_obj_id lu_obj_id, s
|
||||
}
|
||||
|
||||
static s32_t spiffs_lookup_check_v(spiffs *fs, spiffs_obj_id obj_id, spiffs_block_ix cur_block, int cur_entry,
|
||||
u32_t user_data, void *user_p) {
|
||||
(void)user_data;
|
||||
(void)user_p;
|
||||
const void *user_const_p, void *user_var_p) {
|
||||
(void)user_const_p;
|
||||
(void)user_var_p;
|
||||
s32_t res = SPIFFS_OK;
|
||||
spiffs_page_header p_hdr;
|
||||
spiffs_page_ix cur_pix = SPIFFS_OBJ_LOOKUP_ENTRY_TO_PIX(fs, cur_block, cur_entry);
|
||||
@@ -873,11 +873,11 @@ static int spiffs_object_index_search(spiffs *fs, spiffs_obj_id obj_id) {
|
||||
}
|
||||
|
||||
static s32_t spiffs_object_index_consistency_check_v(spiffs *fs, spiffs_obj_id obj_id, spiffs_block_ix cur_block,
|
||||
int cur_entry, u32_t user_data, void *user_p) {
|
||||
(void)user_data;
|
||||
int cur_entry, const void *user_const_p, void *user_var_p) {
|
||||
(void)user_const_p;
|
||||
s32_t res_c = SPIFFS_VIS_COUNTINUE;
|
||||
s32_t res = SPIFFS_OK;
|
||||
u32_t *log_ix = (u32_t *)user_p;
|
||||
u32_t *log_ix = (u32_t*)user_var_p;
|
||||
spiffs_obj_id *obj_table = (spiffs_obj_id *)fs->work;
|
||||
|
||||
CHECK_CB(fs, SPIFFS_CHECK_INDEX, SPIFFS_CHECK_PROGRESS,
|
||||
@@ -977,8 +977,8 @@ s32_t spiffs_object_index_consistency_check(spiffs *fs) {
|
||||
memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
u32_t obj_id_log_ix = 0;
|
||||
CHECK_CB(fs, SPIFFS_CHECK_INDEX, SPIFFS_CHECK_PROGRESS, 0, 0);
|
||||
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_object_index_consistency_check_v, 0, &obj_id_log_ix,
|
||||
0, 0);
|
||||
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_object_index_consistency_check_v, &obj_id_log_ix,
|
||||
0, 0, 0);
|
||||
if (res == SPIFFS_VIS_END) {
|
||||
res = SPIFFS_OK;
|
||||
}
|
||||
|
||||
+19
-19
@@ -166,7 +166,7 @@ void SPIFFS_clearerr(spiffs *fs) {
|
||||
fs->err_code = SPIFFS_OK;
|
||||
}
|
||||
|
||||
s32_t SPIFFS_creat(spiffs *fs, char *path, spiffs_mode mode) {
|
||||
s32_t SPIFFS_creat(spiffs *fs, const char *path, spiffs_mode mode) {
|
||||
(void)mode;
|
||||
SPIFFS_API_CHECK_CFG(fs);
|
||||
SPIFFS_API_CHECK_MOUNT(fs);
|
||||
@@ -174,15 +174,15 @@ s32_t SPIFFS_creat(spiffs *fs, char *path, spiffs_mode mode) {
|
||||
spiffs_obj_id obj_id;
|
||||
s32_t res;
|
||||
|
||||
res = spiffs_obj_lu_find_free_obj_id(fs, &obj_id, (u8_t *)path);
|
||||
res = spiffs_obj_lu_find_free_obj_id(fs, &obj_id, (const u8_t*)path);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
res = spiffs_object_create(fs, obj_id, (u8_t *)path, SPIFFS_TYPE_FILE, 0);
|
||||
res = spiffs_object_create(fs, obj_id, (const u8_t*)path, SPIFFS_TYPE_FILE, 0);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
SPIFFS_UNLOCK(fs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
spiffs_file SPIFFS_open(spiffs *fs, char *path, spiffs_flags flags, spiffs_mode mode) {
|
||||
spiffs_file SPIFFS_open(spiffs *fs, const char *path, spiffs_flags flags, spiffs_mode mode) {
|
||||
(void)mode;
|
||||
SPIFFS_API_CHECK_CFG(fs);
|
||||
SPIFFS_API_CHECK_MOUNT(fs);
|
||||
@@ -194,7 +194,7 @@ spiffs_file SPIFFS_open(spiffs *fs, char *path, spiffs_flags flags, spiffs_mode
|
||||
s32_t res = spiffs_fd_find_new(fs, &fd);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (u8_t*)path, &pix);
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t*)path, &pix);
|
||||
if ((flags & SPIFFS_CREAT) == 0) {
|
||||
if (res < SPIFFS_OK) {
|
||||
spiffs_fd_return(fs, fd->file_nbr);
|
||||
@@ -218,7 +218,7 @@ spiffs_file SPIFFS_open(spiffs *fs, char *path, spiffs_flags flags, spiffs_mode
|
||||
spiffs_fd_return(fs, fd->file_nbr);
|
||||
}
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
res = spiffs_object_create(fs, obj_id, (u8_t*)path, SPIFFS_TYPE_FILE, &pix);
|
||||
res = spiffs_object_create(fs, obj_id, (const u8_t*)path, SPIFFS_TYPE_FILE, &pix);
|
||||
if (res < SPIFFS_OK) {
|
||||
spiffs_fd_return(fs, fd->file_nbr);
|
||||
}
|
||||
@@ -522,7 +522,7 @@ s32_t SPIFFS_lseek(spiffs *fs, spiffs_file fh, s32_t offs, int whence) {
|
||||
return offs;
|
||||
}
|
||||
|
||||
s32_t SPIFFS_remove(spiffs *fs, char *path) {
|
||||
s32_t SPIFFS_remove(spiffs *fs, const char *path) {
|
||||
SPIFFS_API_CHECK_CFG(fs);
|
||||
SPIFFS_API_CHECK_MOUNT(fs);
|
||||
SPIFFS_LOCK(fs);
|
||||
@@ -534,7 +534,7 @@ s32_t SPIFFS_remove(spiffs *fs, char *path) {
|
||||
res = spiffs_fd_find_new(fs, &fd);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (u8_t *)path, &pix);
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t*)path, &pix);
|
||||
if (res != SPIFFS_OK) {
|
||||
spiffs_fd_return(fs, fd->file_nbr);
|
||||
}
|
||||
@@ -607,7 +607,7 @@ static s32_t spiffs_stat_pix(spiffs *fs, spiffs_page_ix pix, spiffs_file fh, spi
|
||||
return res;
|
||||
}
|
||||
|
||||
s32_t SPIFFS_stat(spiffs *fs, char *path, spiffs_stat *s) {
|
||||
s32_t SPIFFS_stat(spiffs *fs, const char *path, spiffs_stat *s) {
|
||||
SPIFFS_API_CHECK_CFG(fs);
|
||||
SPIFFS_API_CHECK_MOUNT(fs);
|
||||
SPIFFS_LOCK(fs);
|
||||
@@ -615,7 +615,7 @@ s32_t SPIFFS_stat(spiffs *fs, char *path, spiffs_stat *s) {
|
||||
s32_t res;
|
||||
spiffs_page_ix pix;
|
||||
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (u8_t*)path, &pix);
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t*)path, &pix);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
|
||||
res = spiffs_stat_pix(fs, pix, 0, s);
|
||||
@@ -720,7 +720,7 @@ s32_t SPIFFS_close(spiffs *fs, spiffs_file fh) {
|
||||
return res;
|
||||
}
|
||||
|
||||
s32_t SPIFFS_rename(spiffs *fs, char *old, char *new) {
|
||||
s32_t SPIFFS_rename(spiffs *fs, const char *old, const char *new) {
|
||||
SPIFFS_API_CHECK_CFG(fs);
|
||||
SPIFFS_API_CHECK_MOUNT(fs);
|
||||
SPIFFS_LOCK(fs);
|
||||
@@ -728,10 +728,10 @@ s32_t SPIFFS_rename(spiffs *fs, char *old, char *new) {
|
||||
spiffs_page_ix pix_old, pix_dummy;
|
||||
spiffs_fd *fd;
|
||||
|
||||
s32_t res = spiffs_object_find_object_index_header_by_name(fs, (u8_t*)old, &pix_old);
|
||||
s32_t res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t*)old, &pix_old);
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (u8_t*)new, &pix_dummy);
|
||||
res = spiffs_object_find_object_index_header_by_name(fs, (const u8_t*)new, &pix_dummy);
|
||||
if (res == SPIFFS_ERR_NOT_FOUND) {
|
||||
res = SPIFFS_OK;
|
||||
} else if (res == SPIFFS_OK) {
|
||||
@@ -748,7 +748,7 @@ s32_t SPIFFS_rename(spiffs *fs, char *old, char *new) {
|
||||
}
|
||||
SPIFFS_API_CHECK_RES_UNLOCK(fs, res);
|
||||
|
||||
res = spiffs_object_update_index_hdr(fs, fd, fd->obj_id, fd->objix_hdr_pix, 0, (u8_t*)new,
|
||||
res = spiffs_object_update_index_hdr(fs, fd, fd->obj_id, fd->objix_hdr_pix, 0, (const u8_t*)new,
|
||||
0, &pix_dummy);
|
||||
|
||||
spiffs_fd_return(fs, fd->file_nbr);
|
||||
@@ -760,7 +760,7 @@ s32_t SPIFFS_rename(spiffs *fs, char *old, char *new) {
|
||||
return res;
|
||||
}
|
||||
|
||||
spiffs_DIR *SPIFFS_opendir(spiffs *fs, char *name, spiffs_DIR *d) {
|
||||
spiffs_DIR *SPIFFS_opendir(spiffs *fs, const char *name, spiffs_DIR *d) {
|
||||
(void)name;
|
||||
|
||||
if (!SPIFFS_CHECK_CFG((fs))) {
|
||||
@@ -784,9 +784,9 @@ static s32_t spiffs_read_dir_v(
|
||||
spiffs_obj_id obj_id,
|
||||
spiffs_block_ix bix,
|
||||
int ix_entry,
|
||||
u32_t user_data,
|
||||
void *user_p) {
|
||||
(void)user_data;
|
||||
const void *user_const_p,
|
||||
void *user_var_p) {
|
||||
(void)user_const_p;
|
||||
s32_t res;
|
||||
spiffs_page_object_ix_header objix_hdr;
|
||||
if (obj_id == SPIFFS_OBJ_ID_FREE || obj_id == SPIFFS_OBJ_ID_DELETED ||
|
||||
@@ -802,7 +802,7 @@ static s32_t spiffs_read_dir_v(
|
||||
objix_hdr.p_hdr.span_ix == 0 &&
|
||||
(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_p;
|
||||
struct spiffs_dirent *e = (struct spiffs_dirent*)user_var_p;
|
||||
e->obj_id = obj_id;
|
||||
strcpy((char *)e->name, (char *)objix_hdr.name);
|
||||
e->type = objix_hdr.type;
|
||||
|
||||
+38
-38
@@ -101,7 +101,7 @@ s32_t spiffs_phys_cpy(
|
||||
|
||||
// Find object lookup entry containing given id with visitor.
|
||||
// Iterate over object lookup pages in each block until a given object id entry is found.
|
||||
// When found, the visitor function is called with block index, entry index and user_data.
|
||||
// When found, the visitor function is called with block index, entry index and user data.
|
||||
// If visitor returns SPIFFS_VIS_CONTINUE, the search goes on. Otherwise, the search will be
|
||||
// ended and visitor's return code is returned to caller.
|
||||
// If no visitor is given (0) the search returns on first entry with matching object id.
|
||||
@@ -113,8 +113,8 @@ s32_t spiffs_phys_cpy(
|
||||
// SPIFFS_VIS_NO_WRAP
|
||||
// @param obj_id argument object id
|
||||
// @param v visitor callback function
|
||||
// @param user_data any data, passed to the callback visitor function
|
||||
// @param user_p any pointer, passed to the callback visitor function
|
||||
// @param user_const_p any const pointer, passed to the callback visitor function
|
||||
// @param user_var_p any pointer, passed to the callback visitor function
|
||||
// @param block_ix reported block index where match was found
|
||||
// @param lu_entry reported look up index where match was found
|
||||
s32_t spiffs_obj_lu_find_entry_visitor(
|
||||
@@ -124,8 +124,8 @@ s32_t spiffs_obj_lu_find_entry_visitor(
|
||||
u8_t flags,
|
||||
spiffs_obj_id obj_id,
|
||||
spiffs_visitor_f v,
|
||||
u32_t user_data,
|
||||
void *user_p,
|
||||
const void *user_const_p,
|
||||
void *user_var_p,
|
||||
spiffs_block_ix *block_ix,
|
||||
int *lu_entry) {
|
||||
s32_t res = SPIFFS_OK;
|
||||
@@ -175,8 +175,8 @@ s32_t spiffs_obj_lu_find_entry_visitor(
|
||||
(flags & SPIFFS_VIS_CHECK_PH) ? obj_id : obj_lu_buf[cur_entry-entry_offset],
|
||||
cur_block,
|
||||
cur_entry,
|
||||
user_data,
|
||||
user_p);
|
||||
user_const_p,
|
||||
user_var_p);
|
||||
if (res == SPIFFS_VIS_COUNTINUE || res == SPIFFS_VIS_COUNTINUE_RELOAD) {
|
||||
if (res == SPIFFS_VIS_COUNTINUE_RELOAD) {
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
||||
@@ -264,11 +264,11 @@ static s32_t spiffs_obj_lu_scan_v(
|
||||
spiffs_obj_id obj_id,
|
||||
spiffs_block_ix bix,
|
||||
int ix_entry,
|
||||
u32_t user_data,
|
||||
void *user_p) {
|
||||
const void *user_const_p,
|
||||
void *user_var_p) {
|
||||
(void)bix;
|
||||
(void)user_data;
|
||||
(void)user_p;
|
||||
(void)user_const_p;
|
||||
(void)user_var_p;
|
||||
if (obj_id == SPIFFS_OBJ_ID_FREE) {
|
||||
if (ix_entry == 0) {
|
||||
fs->free_blocks++;
|
||||
@@ -439,8 +439,8 @@ static s32_t spiffs_obj_lu_find_id_and_span_v(
|
||||
spiffs_obj_id obj_id,
|
||||
spiffs_block_ix bix,
|
||||
int ix_entry,
|
||||
u32_t user_data,
|
||||
void *user_p) {
|
||||
const void *user_const_p,
|
||||
void *user_var_p) {
|
||||
s32_t res;
|
||||
spiffs_page_header ph;
|
||||
spiffs_page_ix pix = SPIFFS_OBJ_LOOKUP_ENTRY_TO_PIX(fs, bix, ix_entry);
|
||||
@@ -448,10 +448,10 @@ static s32_t spiffs_obj_lu_find_id_and_span_v(
|
||||
SPIFFS_PAGE_TO_PADDR(fs, pix), sizeof(spiffs_page_header), (u8_t *)&ph);
|
||||
SPIFFS_CHECK_RES(res);
|
||||
if (ph.obj_id == obj_id &&
|
||||
ph.span_ix == (spiffs_span_ix)user_data &&
|
||||
ph.span_ix == *((spiffs_span_ix*)user_var_p) &&
|
||||
(ph.flags & (SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_DELET | SPIFFS_PH_FLAG_USED)) == SPIFFS_PH_FLAG_DELET &&
|
||||
!((obj_id & SPIFFS_OBJ_ID_IX_FLAG) && (ph.flags & SPIFFS_PH_FLAG_IXDELE) == 0 && ph.span_ix == 0) &&
|
||||
(user_p == 0 || *((spiffs_page_ix *)user_p) != pix)) {
|
||||
(user_const_p == 0 || *((const spiffs_page_ix*)user_const_p) != pix)) {
|
||||
return SPIFFS_OK;
|
||||
} else {
|
||||
return SPIFFS_VIS_COUNTINUE;
|
||||
@@ -476,8 +476,8 @@ s32_t spiffs_obj_lu_find_id_and_span(
|
||||
SPIFFS_VIS_CHECK_ID,
|
||||
obj_id,
|
||||
spiffs_obj_lu_find_id_and_span_v,
|
||||
(u32_t)spix,
|
||||
exclusion_pix ? &exclusion_pix : 0,
|
||||
&spix,
|
||||
&bix,
|
||||
&entry);
|
||||
|
||||
@@ -515,8 +515,8 @@ s32_t spiffs_obj_lu_find_id_and_span_by_phdr(
|
||||
SPIFFS_VIS_CHECK_PH,
|
||||
obj_id,
|
||||
spiffs_obj_lu_find_id_and_span_v,
|
||||
(u32_t)spix,
|
||||
exclusion_pix ? &exclusion_pix : 0,
|
||||
&spix,
|
||||
&bix,
|
||||
&entry);
|
||||
|
||||
@@ -690,7 +690,7 @@ s32_t spiffs_page_delete(
|
||||
s32_t spiffs_object_create(
|
||||
spiffs *fs,
|
||||
spiffs_obj_id obj_id,
|
||||
u8_t name[SPIFFS_OBJ_NAME_LEN],
|
||||
const u8_t name[SPIFFS_OBJ_NAME_LEN],
|
||||
spiffs_obj_type type,
|
||||
spiffs_page_ix *objix_hdr_pix) {
|
||||
s32_t res = SPIFFS_OK;
|
||||
@@ -721,7 +721,7 @@ s32_t spiffs_object_create(
|
||||
oix_hdr.p_hdr.flags = 0xff & ~(SPIFFS_PH_FLAG_FINAL | SPIFFS_PH_FLAG_INDEX | SPIFFS_PH_FLAG_USED);
|
||||
oix_hdr.type = type;
|
||||
oix_hdr.size = SPIFFS_UNDEFINED_LEN; // keep ones so we can update later without wasting this page
|
||||
strncpy((char *)&oix_hdr.name, (char *)name, SPIFFS_OBJ_NAME_LEN);
|
||||
strncpy((char*)&oix_hdr.name, (const char*)name, SPIFFS_OBJ_NAME_LEN);
|
||||
|
||||
|
||||
// update page
|
||||
@@ -748,7 +748,7 @@ s32_t spiffs_object_update_index_hdr(
|
||||
spiffs_obj_id obj_id,
|
||||
spiffs_page_ix objix_hdr_pix,
|
||||
u8_t *new_objix_hdr_data,
|
||||
u8_t name[SPIFFS_OBJ_NAME_LEN],
|
||||
const u8_t name[SPIFFS_OBJ_NAME_LEN],
|
||||
u32_t size,
|
||||
spiffs_page_ix *new_pix) {
|
||||
s32_t res = SPIFFS_OK;
|
||||
@@ -772,7 +772,7 @@ s32_t spiffs_object_update_index_hdr(
|
||||
|
||||
// change name
|
||||
if (name) {
|
||||
strncpy((char *)objix_hdr->name, (char *)name, SPIFFS_OBJ_NAME_LEN);
|
||||
strncpy((char*)objix_hdr->name, (const char*)name, SPIFFS_OBJ_NAME_LEN);
|
||||
}
|
||||
if (size) {
|
||||
objix_hdr->size = size;
|
||||
@@ -1335,9 +1335,9 @@ static s32_t spiffs_object_find_object_index_header_by_name_v(
|
||||
spiffs_obj_id obj_id,
|
||||
spiffs_block_ix bix,
|
||||
int ix_entry,
|
||||
u32_t user_data,
|
||||
void *user_p) {
|
||||
(void)user_data;
|
||||
const void *user_const_p,
|
||||
void *user_var_p) {
|
||||
(void)user_var_p;
|
||||
s32_t res;
|
||||
spiffs_page_object_ix_header objix_hdr;
|
||||
spiffs_page_ix pix = SPIFFS_OBJ_LOOKUP_ENTRY_TO_PIX(fs, bix, ix_entry);
|
||||
@@ -1351,7 +1351,7 @@ static s32_t spiffs_object_find_object_index_header_by_name_v(
|
||||
if (objix_hdr.p_hdr.span_ix == 0 &&
|
||||
(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)) {
|
||||
if (strcmp((char *)user_p, (char *)objix_hdr.name) == 0) {
|
||||
if (strcmp((const char*)user_const_p, (char*)objix_hdr.name) == 0) {
|
||||
return SPIFFS_OK;
|
||||
}
|
||||
}
|
||||
@@ -1362,7 +1362,7 @@ static s32_t spiffs_object_find_object_index_header_by_name_v(
|
||||
// Finds object index header page by name
|
||||
s32_t spiffs_object_find_object_index_header_by_name(
|
||||
spiffs *fs,
|
||||
u8_t name[SPIFFS_OBJ_NAME_LEN],
|
||||
const u8_t name[SPIFFS_OBJ_NAME_LEN],
|
||||
spiffs_page_ix *pix) {
|
||||
s32_t res;
|
||||
spiffs_block_ix bix;
|
||||
@@ -1374,8 +1374,8 @@ s32_t spiffs_object_find_object_index_header_by_name(
|
||||
0,
|
||||
0,
|
||||
spiffs_object_find_object_index_header_by_name_v,
|
||||
0,
|
||||
name,
|
||||
0,
|
||||
&bix,
|
||||
&entry);
|
||||
|
||||
@@ -1702,10 +1702,10 @@ typedef struct {
|
||||
} spiffs_free_obj_id_state;
|
||||
|
||||
static s32_t spiffs_obj_lu_find_free_obj_id_bitmap_v(spiffs *fs, spiffs_obj_id id, spiffs_block_ix bix, int ix_entry,
|
||||
u32_t user_data, void *user_p) {
|
||||
const void *user_const_p, void *user_var_p) {
|
||||
if (id != SPIFFS_OBJ_ID_FREE && id != SPIFFS_OBJ_ID_DELETED) {
|
||||
spiffs_obj_id min_obj_id = user_data;
|
||||
u8_t *conflicting_name = (u8_t *)user_p;
|
||||
spiffs_obj_id min_obj_id = *((spiffs_obj_id*)user_var_p);
|
||||
const u8_t *conflicting_name = (const u8_t*)user_const_p;
|
||||
|
||||
// if conflicting name parameter is given, also check if this name is found in object index hdrs
|
||||
if (conflicting_name && (id & SPIFFS_OBJ_ID_IX_FLAG)) {
|
||||
@@ -1718,7 +1718,7 @@ static s32_t spiffs_obj_lu_find_free_obj_id_bitmap_v(spiffs *fs, spiffs_obj_id i
|
||||
if (objix_hdr.p_hdr.span_ix == 0 &&
|
||||
(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)) {
|
||||
if (strcmp((char *)user_p, (char *)objix_hdr.name) == 0) {
|
||||
if (strcmp((const char*)user_const_p, (char*)objix_hdr.name) == 0) {
|
||||
return SPIFFS_ERR_CONFLICTING_NAME;
|
||||
}
|
||||
}
|
||||
@@ -1735,11 +1735,11 @@ static s32_t spiffs_obj_lu_find_free_obj_id_bitmap_v(spiffs *fs, spiffs_obj_id i
|
||||
}
|
||||
|
||||
static s32_t spiffs_obj_lu_find_free_obj_id_compact_v(spiffs *fs, spiffs_obj_id id, spiffs_block_ix bix, int ix_entry,
|
||||
u32_t user_data, void *user_p) {
|
||||
(void)user_data;
|
||||
const void *user_const_p, void *user_var_p) {
|
||||
(void)user_var_p;
|
||||
if (id != SPIFFS_OBJ_ID_FREE && id != SPIFFS_OBJ_ID_DELETED && (id & SPIFFS_OBJ_ID_IX_FLAG)) {
|
||||
s32_t res;
|
||||
spiffs_free_obj_id_state *state = (spiffs_free_obj_id_state *)user_p;
|
||||
const spiffs_free_obj_id_state *state = (const spiffs_free_obj_id_state*)user_const_p;
|
||||
spiffs_page_object_ix_header objix_hdr;
|
||||
|
||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU2 | SPIFFS_OP_C_READ,
|
||||
@@ -1768,7 +1768,7 @@ static s32_t spiffs_obj_lu_find_free_obj_id_compact_v(spiffs *fs, spiffs_obj_id
|
||||
// object ids cannot fit into a work buffer, these are grouped. When a group containing free
|
||||
// object ids is found, the object lu is again scanned for object ids within group and bitmasked.
|
||||
// Finally, the bitmask is searched for a free id
|
||||
s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *conflicting_name) {
|
||||
s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, const u8_t *conflicting_name) {
|
||||
s32_t res = SPIFFS_OK;
|
||||
u32_t max_objects = (fs->block_count * SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs)) / 2;
|
||||
spiffs_free_obj_id_state state;
|
||||
@@ -1787,8 +1787,8 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *co
|
||||
SPIFFS_DBG("free_obj_id: BITM min:%04x max:%04x\n", state.min_obj_id, state.max_obj_id);
|
||||
|
||||
memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_obj_lu_find_free_obj_id_bitmap_v, state.min_obj_id,
|
||||
conflicting_name, 0, 0);
|
||||
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_obj_lu_find_free_obj_id_bitmap_v,
|
||||
conflicting_name, &state.min_obj_id, 0, 0);
|
||||
if (res == SPIFFS_VIS_END) res = SPIFFS_OK;
|
||||
SPIFFS_CHECK_RES(res);
|
||||
// traverse bitmask until found free obj_id
|
||||
@@ -1852,7 +1852,7 @@ s32_t spiffs_obj_lu_find_free_obj_id(spiffs *fs, spiffs_obj_id *obj_id, u8_t *co
|
||||
SPIFFS_DBG("free_obj_id: COMP min:%04x max:%04x compact:%i\n", state.min_obj_id, state.max_obj_id, state.compaction);
|
||||
|
||||
memset(fs->work, 0, SPIFFS_CFG_LOG_PAGE_SZ(fs));
|
||||
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_obj_lu_find_free_obj_id_compact_v, 0, &state, 0, 0);
|
||||
res = spiffs_obj_lu_find_entry_visitor(fs, 0, 0, 0, 0, spiffs_obj_lu_find_free_obj_id_compact_v, &state, 0, 0, 0);
|
||||
if (res == SPIFFS_VIS_END) res = SPIFFS_OK;
|
||||
SPIFFS_CHECK_RES(res);
|
||||
state.conflicting_name = 0; // searched for conflicting name once, no need to do it again
|
||||
|
||||
@@ -460,7 +460,7 @@ typedef struct __attribute(( packed )) {
|
||||
|
||||
// callback func for object lookup visitor
|
||||
typedef s32_t (*spiffs_visitor_f)(spiffs *fs, spiffs_obj_id id, spiffs_block_ix bix, int ix_entry,
|
||||
u32_t user_data, void *user_p);
|
||||
const void *user_const_p, void *user_var_p);
|
||||
|
||||
|
||||
#if SPIFFS_CACHE
|
||||
@@ -521,8 +521,8 @@ s32_t spiffs_obj_lu_find_entry_visitor(
|
||||
u8_t flags,
|
||||
spiffs_obj_id obj_id,
|
||||
spiffs_visitor_f v,
|
||||
u32_t user_data,
|
||||
void *user_p,
|
||||
const void *user_const_p,
|
||||
void *user_var_p,
|
||||
spiffs_block_ix *block_ix,
|
||||
int *lu_entry);
|
||||
|
||||
@@ -538,7 +538,7 @@ s32_t spiffs_obj_lu_scan(
|
||||
s32_t spiffs_obj_lu_find_free_obj_id(
|
||||
spiffs *fs,
|
||||
spiffs_obj_id *obj_id,
|
||||
u8_t *conflicting_name);
|
||||
const u8_t *conflicting_name);
|
||||
|
||||
s32_t spiffs_obj_lu_find_free(
|
||||
spiffs *fs,
|
||||
@@ -599,7 +599,7 @@ s32_t spiffs_page_delete(
|
||||
s32_t spiffs_object_create(
|
||||
spiffs *fs,
|
||||
spiffs_obj_id obj_id,
|
||||
u8_t name[SPIFFS_OBJ_NAME_LEN],
|
||||
const u8_t name[SPIFFS_OBJ_NAME_LEN],
|
||||
spiffs_obj_type type,
|
||||
spiffs_page_ix *objix_hdr_pix);
|
||||
|
||||
@@ -609,7 +609,7 @@ s32_t spiffs_object_update_index_hdr(
|
||||
spiffs_obj_id obj_id,
|
||||
spiffs_page_ix objix_hdr_pix,
|
||||
u8_t *new_objix_hdr_data,
|
||||
u8_t name[SPIFFS_OBJ_NAME_LEN],
|
||||
const u8_t name[SPIFFS_OBJ_NAME_LEN],
|
||||
u32_t size,
|
||||
spiffs_page_ix *new_pix);
|
||||
|
||||
@@ -661,7 +661,7 @@ s32_t spiffs_object_truncate(
|
||||
|
||||
s32_t spiffs_object_find_object_index_header_by_name(
|
||||
spiffs *fs,
|
||||
u8_t name[SPIFFS_OBJ_NAME_LEN],
|
||||
const u8_t name[SPIFFS_OBJ_NAME_LEN],
|
||||
spiffs_page_ix *pix);
|
||||
|
||||
// ---------------
|
||||
|
||||
Reference in New Issue
Block a user