Data Structures | Macros | Typedefs | Enumerations | Functions
spiffs.h File Reference
#include "spiffs_config.h"

Go to the source code of this file.

Data Structures

struct  spiffs_config
 
struct  spiffs_t
 
struct  spiffs_stat
 
struct  spiffs_dirent
 
struct  spiffs_DIR
 
struct  spiffs_ix_map
 

Macros

#define SPIFFS_OK   0
 
#define SPIFFS_ERR_NOT_MOUNTED   -10000
 
#define SPIFFS_ERR_FULL   -10001
 
#define SPIFFS_ERR_NOT_FOUND   -10002
 
#define SPIFFS_ERR_END_OF_OBJECT   -10003
 
#define SPIFFS_ERR_DELETED   -10004
 
#define SPIFFS_ERR_NOT_FINALIZED   -10005
 
#define SPIFFS_ERR_NOT_INDEX   -10006
 
#define SPIFFS_ERR_OUT_OF_FILE_DESCS   -10007
 
#define SPIFFS_ERR_FILE_CLOSED   -10008
 
#define SPIFFS_ERR_FILE_DELETED   -10009
 
#define SPIFFS_ERR_BAD_DESCRIPTOR   -10010
 
#define SPIFFS_ERR_IS_INDEX   -10011
 
#define SPIFFS_ERR_IS_FREE   -10012
 
#define SPIFFS_ERR_INDEX_SPAN_MISMATCH   -10013
 
#define SPIFFS_ERR_DATA_SPAN_MISMATCH   -10014
 
#define SPIFFS_ERR_INDEX_REF_FREE   -10015
 
#define SPIFFS_ERR_INDEX_REF_LU   -10016
 
#define SPIFFS_ERR_INDEX_REF_INVALID   -10017
 
#define SPIFFS_ERR_INDEX_FREE   -10018
 
#define SPIFFS_ERR_INDEX_LU   -10019
 
#define SPIFFS_ERR_INDEX_INVALID   -10020
 
#define SPIFFS_ERR_NOT_WRITABLE   -10021
 
#define SPIFFS_ERR_NOT_READABLE   -10022
 
#define SPIFFS_ERR_CONFLICTING_NAME   -10023
 
#define SPIFFS_ERR_NOT_CONFIGURED   -10024
 
#define SPIFFS_ERR_NOT_A_FS   -10025
 
#define SPIFFS_ERR_MOUNTED   -10026
 
#define SPIFFS_ERR_ERASE_FAIL   -10027
 
#define SPIFFS_ERR_MAGIC_NOT_POSSIBLE   -10028
 
#define SPIFFS_ERR_NO_DELETED_BLOCKS   -10029
 
#define SPIFFS_ERR_FILE_EXISTS   -10030
 
#define SPIFFS_ERR_NOT_A_FILE   -10031
 
#define SPIFFS_ERR_RO_NOT_IMPL   -10032
 
#define SPIFFS_ERR_RO_ABORTED_OPERATION   -10033
 
#define SPIFFS_ERR_PROBE_TOO_FEW_BLOCKS   -10034
 
#define SPIFFS_ERR_PROBE_NOT_A_FS   -10035
 
#define SPIFFS_ERR_NAME_TOO_LONG   -10036
 
#define SPIFFS_ERR_IX_MAP_UNMAPPED   -10037
 
#define SPIFFS_ERR_IX_MAP_MAPPED   -10038
 
#define SPIFFS_ERR_IX_MAP_BAD_RANGE   -10039
 
#define SPIFFS_ERR_SEEK_BOUNDS   -10040
 
#define SPIFFS_ERR_INTERNAL   -10050
 
#define SPIFFS_ERR_TEST   -10100
 
#define SPIFFS_APPEND   (1<<0)
 
#define SPIFFS_O_APPEND   SPIFFS_APPEND
 
#define SPIFFS_TRUNC   (1<<1)
 
#define SPIFFS_O_TRUNC   SPIFFS_TRUNC
 
#define SPIFFS_CREAT   (1<<2)
 
#define SPIFFS_O_CREAT   SPIFFS_CREAT
 
#define SPIFFS_RDONLY   (1<<3)
 
#define SPIFFS_O_RDONLY   SPIFFS_RDONLY
 
#define SPIFFS_WRONLY   (1<<4)
 
#define SPIFFS_O_WRONLY   SPIFFS_WRONLY
 
#define SPIFFS_RDWR   (SPIFFS_RDONLY | SPIFFS_WRONLY)
 
#define SPIFFS_O_RDWR   SPIFFS_RDWR
 
#define SPIFFS_DIRECT   (1<<5)
 
#define SPIFFS_O_DIRECT   SPIFFS_DIRECT
 
#define SPIFFS_EXCL   (1<<6)
 
#define SPIFFS_O_EXCL   SPIFFS_EXCL
 
#define SPIFFS_SEEK_SET   (0)
 
#define SPIFFS_SEEK_CUR   (1)
 
#define SPIFFS_SEEK_END   (2)
 
#define SPIFFS_TYPE_FILE   (1)
 
#define SPIFFS_TYPE_DIR   (2)
 
#define SPIFFS_TYPE_HARD_LINK   (3)
 
#define SPIFFS_TYPE_SOFT_LINK   (4)
 

Typedefs

typedef s16_t spiffs_file
 
typedef u16_t spiffs_flags
 
typedef u16_t spiffs_mode
 
typedef u8_t spiffs_obj_type
 
typedef s32_t(* spiffs_read) (struct spiffs_t *fs, u32_t addr, u32_t size, u8_t *dst)
 
typedef s32_t(* spiffs_write) (struct spiffs_t *fs, u32_t addr, u32_t size, u8_t *src)
 
typedef s32_t(* spiffs_erase) (struct spiffs_t *fs, u32_t addr, u32_t size)
 
typedef void(* spiffs_check_callback) (struct spiffs_t *fs, spiffs_check_type type, spiffs_check_report report, u32_t arg1, u32_t arg2)
 
typedef void(* spiffs_file_callback) (struct spiffs_t *fs, spiffs_fileop_type op, spiffs_obj_id obj_id, spiffs_page_ix pix)
 
typedef struct spiffs_t spiffs
 

Enumerations

enum  spiffs_check_type { SPIFFS_CHECK_LOOKUP = 0, SPIFFS_CHECK_INDEX, SPIFFS_CHECK_PAGE }
 
enum  spiffs_check_report {
  SPIFFS_CHECK_PROGRESS = 0, SPIFFS_CHECK_ERROR, SPIFFS_CHECK_FIX_INDEX, SPIFFS_CHECK_FIX_LOOKUP,
  SPIFFS_CHECK_DELETE_ORPHANED_INDEX, SPIFFS_CHECK_DELETE_PAGE, SPIFFS_CHECK_DELETE_BAD_FILE
}
 
enum  spiffs_fileop_type { SPIFFS_CB_CREATED = 0, SPIFFS_CB_UPDATED, SPIFFS_CB_DELETED }
 

Functions

s32_t SPIFFS_probe_fs (spiffs_config *config)
 
s32_t SPIFFS_mount (spiffs *fs, spiffs_config *config, u8_t *work, u8_t *fd_space, u32_t fd_space_size, void *cache, u32_t cache_size, spiffs_check_callback check_cb_f)
 
void SPIFFS_unmount (spiffs *fs)
 
s32_t SPIFFS_creat (spiffs *fs, const char *path, spiffs_mode mode)
 
spiffs_file SPIFFS_open (spiffs *fs, const char *path, spiffs_flags flags, spiffs_mode mode)
 
spiffs_file SPIFFS_open_by_dirent (spiffs *fs, struct spiffs_dirent *e, spiffs_flags flags, spiffs_mode mode)
 
spiffs_file SPIFFS_open_by_page (spiffs *fs, spiffs_page_ix page_ix, spiffs_flags flags, spiffs_mode mode)
 
s32_t SPIFFS_read (spiffs *fs, spiffs_file fh, void *buf, s32_t len)
 
s32_t SPIFFS_write (spiffs *fs, spiffs_file fh, void *buf, s32_t len)
 
s32_t SPIFFS_lseek (spiffs *fs, spiffs_file fh, s32_t offs, int whence)
 
s32_t SPIFFS_remove (spiffs *fs, const char *path)
 
s32_t SPIFFS_fremove (spiffs *fs, spiffs_file fh)
 
s32_t SPIFFS_stat (spiffs *fs, const char *path, spiffs_stat *s)
 
s32_t SPIFFS_fstat (spiffs *fs, spiffs_file fh, spiffs_stat *s)
 
s32_t SPIFFS_fflush (spiffs *fs, spiffs_file fh)
 
s32_t SPIFFS_close (spiffs *fs, spiffs_file fh)
 
s32_t SPIFFS_rename (spiffs *fs, const char *old, const char *newPath)
 
s32_t SPIFFS_errno (spiffs *fs)
 
void SPIFFS_clearerr (spiffs *fs)
 
spiffs_DIRSPIFFS_opendir (spiffs *fs, const char *name, spiffs_DIR *d)
 
s32_t SPIFFS_closedir (spiffs_DIR *d)
 
struct spiffs_direntSPIFFS_readdir (spiffs_DIR *d, struct spiffs_dirent *e)
 
s32_t SPIFFS_check (spiffs *fs)
 
s32_t SPIFFS_info (spiffs *fs, u32_t *total, u32_t *used)
 
s32_t SPIFFS_format (spiffs *fs)
 
u8_t SPIFFS_mounted (spiffs *fs)
 
s32_t SPIFFS_gc_quick (spiffs *fs, u16_t max_free_pages)
 
s32_t SPIFFS_gc (spiffs *fs, u32_t size)
 
s32_t SPIFFS_eof (spiffs *fs, spiffs_file fh)
 
s32_t SPIFFS_tell (spiffs *fs, spiffs_file fh)
 
s32_t SPIFFS_set_file_callback_func (spiffs *fs, spiffs_file_callback cb_func)
 
s32_t SPIFFS_ix_map (spiffs *fs, spiffs_file fh, spiffs_ix_map *map, u32_t offset, u32_t len, spiffs_page_ix *map_buf)
 
s32_t SPIFFS_ix_unmap (spiffs *fs, spiffs_file fh)
 
s32_t SPIFFS_ix_remap (spiffs *fs, spiffs_file fh, u32_t offs)
 
s32_t SPIFFS_bytes_to_ix_map_entries (spiffs *fs, u32_t bytes)
 
s32_t SPIFFS_ix_map_entries_to_bytes (spiffs *fs, u32_t map_page_ix_entries)
 
u32_t SPIFFS_buffer_bytes_for_filedescs (spiffs *fs, u32_t num_descs)
 
u32_t SPIFFS_buffer_bytes_for_cache (spiffs *fs, u32_t num_pages)
 

Macro Definition Documentation

§ SPIFFS_OK

#define SPIFFS_OK   0

§ SPIFFS_ERR_NOT_MOUNTED

#define SPIFFS_ERR_NOT_MOUNTED   -10000

§ SPIFFS_ERR_FULL

#define SPIFFS_ERR_FULL   -10001

§ SPIFFS_ERR_NOT_FOUND

#define SPIFFS_ERR_NOT_FOUND   -10002

§ SPIFFS_ERR_END_OF_OBJECT

#define SPIFFS_ERR_END_OF_OBJECT   -10003

§ SPIFFS_ERR_DELETED

#define SPIFFS_ERR_DELETED   -10004

§ SPIFFS_ERR_NOT_FINALIZED

#define SPIFFS_ERR_NOT_FINALIZED   -10005

§ SPIFFS_ERR_NOT_INDEX

#define SPIFFS_ERR_NOT_INDEX   -10006

§ SPIFFS_ERR_OUT_OF_FILE_DESCS

#define SPIFFS_ERR_OUT_OF_FILE_DESCS   -10007

§ SPIFFS_ERR_FILE_CLOSED

#define SPIFFS_ERR_FILE_CLOSED   -10008

§ SPIFFS_ERR_FILE_DELETED

#define SPIFFS_ERR_FILE_DELETED   -10009

§ SPIFFS_ERR_BAD_DESCRIPTOR

#define SPIFFS_ERR_BAD_DESCRIPTOR   -10010

§ SPIFFS_ERR_IS_INDEX

#define SPIFFS_ERR_IS_INDEX   -10011

§ SPIFFS_ERR_IS_FREE

#define SPIFFS_ERR_IS_FREE   -10012

§ SPIFFS_ERR_INDEX_SPAN_MISMATCH

#define SPIFFS_ERR_INDEX_SPAN_MISMATCH   -10013

§ SPIFFS_ERR_DATA_SPAN_MISMATCH

#define SPIFFS_ERR_DATA_SPAN_MISMATCH   -10014

§ SPIFFS_ERR_INDEX_REF_FREE

#define SPIFFS_ERR_INDEX_REF_FREE   -10015

§ SPIFFS_ERR_INDEX_REF_LU

#define SPIFFS_ERR_INDEX_REF_LU   -10016

§ SPIFFS_ERR_INDEX_REF_INVALID

#define SPIFFS_ERR_INDEX_REF_INVALID   -10017

§ SPIFFS_ERR_INDEX_FREE

#define SPIFFS_ERR_INDEX_FREE   -10018

§ SPIFFS_ERR_INDEX_LU

#define SPIFFS_ERR_INDEX_LU   -10019

§ SPIFFS_ERR_INDEX_INVALID

#define SPIFFS_ERR_INDEX_INVALID   -10020

§ SPIFFS_ERR_NOT_WRITABLE

#define SPIFFS_ERR_NOT_WRITABLE   -10021

§ SPIFFS_ERR_NOT_READABLE

#define SPIFFS_ERR_NOT_READABLE   -10022

§ SPIFFS_ERR_CONFLICTING_NAME

#define SPIFFS_ERR_CONFLICTING_NAME   -10023

§ SPIFFS_ERR_NOT_CONFIGURED

#define SPIFFS_ERR_NOT_CONFIGURED   -10024

§ SPIFFS_ERR_NOT_A_FS

#define SPIFFS_ERR_NOT_A_FS   -10025

§ SPIFFS_ERR_MOUNTED

#define SPIFFS_ERR_MOUNTED   -10026

§ SPIFFS_ERR_ERASE_FAIL

#define SPIFFS_ERR_ERASE_FAIL   -10027

§ SPIFFS_ERR_MAGIC_NOT_POSSIBLE

#define SPIFFS_ERR_MAGIC_NOT_POSSIBLE   -10028

§ SPIFFS_ERR_NO_DELETED_BLOCKS

#define SPIFFS_ERR_NO_DELETED_BLOCKS   -10029

§ SPIFFS_ERR_FILE_EXISTS

#define SPIFFS_ERR_FILE_EXISTS   -10030

§ SPIFFS_ERR_NOT_A_FILE

#define SPIFFS_ERR_NOT_A_FILE   -10031

§ SPIFFS_ERR_RO_NOT_IMPL

#define SPIFFS_ERR_RO_NOT_IMPL   -10032

§ SPIFFS_ERR_RO_ABORTED_OPERATION

#define SPIFFS_ERR_RO_ABORTED_OPERATION   -10033

§ SPIFFS_ERR_PROBE_TOO_FEW_BLOCKS

#define SPIFFS_ERR_PROBE_TOO_FEW_BLOCKS   -10034

§ SPIFFS_ERR_PROBE_NOT_A_FS

#define SPIFFS_ERR_PROBE_NOT_A_FS   -10035

§ SPIFFS_ERR_NAME_TOO_LONG

#define SPIFFS_ERR_NAME_TOO_LONG   -10036

§ SPIFFS_ERR_IX_MAP_UNMAPPED

#define SPIFFS_ERR_IX_MAP_UNMAPPED   -10037

§ SPIFFS_ERR_IX_MAP_MAPPED

#define SPIFFS_ERR_IX_MAP_MAPPED   -10038

§ SPIFFS_ERR_IX_MAP_BAD_RANGE

#define SPIFFS_ERR_IX_MAP_BAD_RANGE   -10039

§ SPIFFS_ERR_SEEK_BOUNDS

#define SPIFFS_ERR_SEEK_BOUNDS   -10040

§ SPIFFS_ERR_INTERNAL

#define SPIFFS_ERR_INTERNAL   -10050

§ SPIFFS_ERR_TEST

#define SPIFFS_ERR_TEST   -10100

§ SPIFFS_APPEND

#define SPIFFS_APPEND   (1<<0)

§ SPIFFS_O_APPEND

#define SPIFFS_O_APPEND   SPIFFS_APPEND

§ SPIFFS_TRUNC

#define SPIFFS_TRUNC   (1<<1)

§ SPIFFS_O_TRUNC

#define SPIFFS_O_TRUNC   SPIFFS_TRUNC

§ SPIFFS_CREAT

#define SPIFFS_CREAT   (1<<2)

§ SPIFFS_O_CREAT

#define SPIFFS_O_CREAT   SPIFFS_CREAT

§ SPIFFS_RDONLY

#define SPIFFS_RDONLY   (1<<3)

§ SPIFFS_O_RDONLY

#define SPIFFS_O_RDONLY   SPIFFS_RDONLY

§ SPIFFS_WRONLY

#define SPIFFS_WRONLY   (1<<4)

§ SPIFFS_O_WRONLY

#define SPIFFS_O_WRONLY   SPIFFS_WRONLY

§ SPIFFS_RDWR

#define SPIFFS_RDWR   (SPIFFS_RDONLY | SPIFFS_WRONLY)

§ SPIFFS_O_RDWR

#define SPIFFS_O_RDWR   SPIFFS_RDWR

§ SPIFFS_DIRECT

#define SPIFFS_DIRECT   (1<<5)

§ SPIFFS_O_DIRECT

#define SPIFFS_O_DIRECT   SPIFFS_DIRECT

§ SPIFFS_EXCL

#define SPIFFS_EXCL   (1<<6)

§ SPIFFS_O_EXCL

#define SPIFFS_O_EXCL   SPIFFS_EXCL

§ SPIFFS_SEEK_SET

#define SPIFFS_SEEK_SET   (0)

§ SPIFFS_SEEK_CUR

#define SPIFFS_SEEK_CUR   (1)

§ SPIFFS_SEEK_END

#define SPIFFS_SEEK_END   (2)

§ SPIFFS_TYPE_FILE

#define SPIFFS_TYPE_FILE   (1)

§ SPIFFS_TYPE_DIR

#define SPIFFS_TYPE_DIR   (2)

§ SPIFFS_TYPE_HARD_LINK

#define SPIFFS_TYPE_HARD_LINK   (3)

§ SPIFFS_TYPE_SOFT_LINK

#define SPIFFS_TYPE_SOFT_LINK   (4)

Typedef Documentation

§ spiffs_file

typedef s16_t spiffs_file

§ spiffs_flags

§ spiffs_mode

typedef u16_t spiffs_mode

§ spiffs_obj_type

§ spiffs_read

typedef s32_t(* spiffs_read) (struct spiffs_t *fs, u32_t addr, u32_t size, u8_t *dst)

§ spiffs_write

typedef s32_t(* spiffs_write) (struct spiffs_t *fs, u32_t addr, u32_t size, u8_t *src)

§ spiffs_erase

typedef s32_t(* spiffs_erase) (struct spiffs_t *fs, u32_t addr, u32_t size)

§ spiffs_check_callback

typedef void(* spiffs_check_callback) (struct spiffs_t *fs, spiffs_check_type type, spiffs_check_report report, u32_t arg1, u32_t arg2)

§ spiffs_file_callback

typedef void(* spiffs_file_callback) (struct spiffs_t *fs, spiffs_fileop_type op, spiffs_obj_id obj_id, spiffs_page_ix pix)

§ spiffs

typedef struct spiffs_t spiffs

Enumeration Type Documentation

§ spiffs_check_type

Enumerator
SPIFFS_CHECK_LOOKUP 
SPIFFS_CHECK_INDEX 
SPIFFS_CHECK_PAGE 

§ spiffs_check_report

Enumerator
SPIFFS_CHECK_PROGRESS 
SPIFFS_CHECK_ERROR 
SPIFFS_CHECK_FIX_INDEX 
SPIFFS_CHECK_FIX_LOOKUP 
SPIFFS_CHECK_DELETE_ORPHANED_INDEX 
SPIFFS_CHECK_DELETE_PAGE 
SPIFFS_CHECK_DELETE_BAD_FILE 

§ spiffs_fileop_type

Enumerator
SPIFFS_CB_CREATED 
SPIFFS_CB_UPDATED 
SPIFFS_CB_DELETED 

Function Documentation

§ SPIFFS_probe_fs()

s32_t SPIFFS_probe_fs ( spiffs_config config)

Special function. This takes a spiffs config struct and returns the number of blocks this file system was formatted with. This function relies on that following info is set correctly in given config struct:

phys_addr, log_page_size, and log_block_size.

Also, hal_read_f must be set in the config struct.

One must be sure of the correct page size and that the physical address is correct in the probed file system when calling this function. It is not checked if the phys_addr actually points to the start of the file system, so one might get a false positive if entering a phys_addr somewhere in the middle of the file system at block boundary. In addition, it is not checked if the page size is actually correct. If it is not, weird file system sizes will be returned.

If this function detects a file system it returns the assumed file system size, which can be used to set the phys_size.

Otherwise, it returns an error indicating why it is not regarded as a file system.

Note: this function is not protected with SPIFFS_LOCK and SPIFFS_UNLOCK macros. It returns the error code directly, instead of as read by SPIFFS_errno.

Parameters
configessential parts of the physical and logical configuration of the file system.

§ SPIFFS_mount()

s32_t SPIFFS_mount ( spiffs fs,
spiffs_config config,
u8_t work,
u8_t fd_space,
u32_t  fd_space_size,
void *  cache,
u32_t  cache_size,
spiffs_check_callback  check_cb_f 
)

Initializes the file system dynamic parameters and mounts the filesystem. If SPIFFS_USE_MAGIC is enabled the mounting may fail with SPIFFS_ERR_NOT_A_FS if the flash does not contain a recognizable file system. In this case, SPIFFS_format must be called prior to remounting.

Parameters
fsthe file system struct
configthe physical and logical configuration of the file system
worka memory work buffer comprising 2*config->log_page_size bytes used throughout all file system operations
fd_spacememory for file descriptors
fd_space_sizememory size of file descriptors
cachememory for cache, may be null
cache_sizememory size of cache
check_cb_fcallback function for reporting during consistency checks

§ SPIFFS_unmount()

void SPIFFS_unmount ( spiffs fs)

Unmounts the file system. All file handles will be flushed of any cached writes and closed.

Parameters
fsthe file system struct

§ SPIFFS_creat()

s32_t SPIFFS_creat ( spiffs fs,
const char *  path,
spiffs_mode  mode 
)

Creates a new file.

Parameters
fsthe file system struct
paththe path of the new file
modeignored, for posix compliance

§ SPIFFS_open()

spiffs_file SPIFFS_open ( spiffs fs,
const char *  path,
spiffs_flags  flags,
spiffs_mode  mode 
)

Opens/creates a file.

Parameters
fsthe file system struct
paththe path of the new file
flagsthe flags for the open command, can be combinations of SPIFFS_O_APPEND, SPIFFS_O_TRUNC, SPIFFS_O_CREAT, SPIFFS_O_RDONLY, SPIFFS_O_WRONLY, SPIFFS_O_RDWR, SPIFFS_O_DIRECT, SPIFFS_O_EXCL
modeignored, for posix compliance

§ SPIFFS_open_by_dirent()

spiffs_file SPIFFS_open_by_dirent ( spiffs fs,
struct spiffs_dirent e,
spiffs_flags  flags,
spiffs_mode  mode 
)

Opens a file by given dir entry. Optimization purposes, when traversing a file system with SPIFFS_readdir a normal SPIFFS_open would need to traverse the filesystem again to find the file, whilst SPIFFS_open_by_dirent already knows where the file resides.

Parameters
fsthe file system struct
ethe dir entry to the file
flagsthe flags for the open command, can be combinations of SPIFFS_APPEND, SPIFFS_TRUNC, SPIFFS_CREAT, SPIFFS_RD_ONLY, SPIFFS_WR_ONLY, SPIFFS_RDWR, SPIFFS_DIRECT. SPIFFS_CREAT will have no effect in this case.
modeignored, for posix compliance

§ SPIFFS_open_by_page()

spiffs_file SPIFFS_open_by_page ( spiffs fs,
spiffs_page_ix  page_ix,
spiffs_flags  flags,
spiffs_mode  mode 
)

Opens a file by given page index. Optimization purposes, opens a file by directly pointing to the page index in the spi flash. If the page index does not point to a file header SPIFFS_ERR_NOT_A_FILE is returned.

Parameters
fsthe file system struct
page_ixthe page index
flagsthe flags for the open command, can be combinations of SPIFFS_APPEND, SPIFFS_TRUNC, SPIFFS_CREAT, SPIFFS_RD_ONLY, SPIFFS_WR_ONLY, SPIFFS_RDWR, SPIFFS_DIRECT. SPIFFS_CREAT will have no effect in this case.
modeignored, for posix compliance

§ SPIFFS_read()

s32_t SPIFFS_read ( spiffs fs,
spiffs_file  fh,
void *  buf,
s32_t  len 
)

Reads from given filehandle.

Parameters
fsthe file system struct
fhthe filehandle
bufwhere to put read data
lenhow much to read
Returns
number of bytes read, or -1 if error

§ SPIFFS_write()

s32_t SPIFFS_write ( spiffs fs,
spiffs_file  fh,
void *  buf,
s32_t  len 
)

Writes to given filehandle.

Parameters
fsthe file system struct
fhthe filehandle
bufthe data to write
lenhow much to write
Returns
number of bytes written, or -1 if error

§ SPIFFS_lseek()

s32_t SPIFFS_lseek ( spiffs fs,
spiffs_file  fh,
s32_t  offs,
int  whence 
)

Moves the read/write file offset. Resulting offset is returned or negative if error. lseek(fs, fd, 0, SPIFFS_SEEK_CUR) will thus return current offset.

Parameters
fsthe file system struct
fhthe filehandle
offshow much/where to move the offset
whenceif SPIFFS_SEEK_SET, the file offset shall be set to offset bytes if SPIFFS_SEEK_CUR, the file offset shall be set to its current location plus offset if SPIFFS_SEEK_END, the file offset shall be set to the size of the file plus offse, which should be negative

§ SPIFFS_remove()

s32_t SPIFFS_remove ( spiffs fs,
const char *  path 
)

Removes a file by path

Parameters
fsthe file system struct
paththe path of the file to remove

§ SPIFFS_fremove()

s32_t SPIFFS_fremove ( spiffs fs,
spiffs_file  fh 
)

Removes a file by filehandle

Parameters
fsthe file system struct
fhthe filehandle of the file to remove

§ SPIFFS_stat()

s32_t SPIFFS_stat ( spiffs fs,
const char *  path,
spiffs_stat s 
)

Gets file status by path

Parameters
fsthe file system struct
paththe path of the file to stat
sthe stat struct to populate

§ SPIFFS_fstat()

s32_t SPIFFS_fstat ( spiffs fs,
spiffs_file  fh,
spiffs_stat s 
)

Gets file status by filehandle

Parameters
fsthe file system struct
fhthe filehandle of the file to stat
sthe stat struct to populate

§ SPIFFS_fflush()

s32_t SPIFFS_fflush ( spiffs fs,
spiffs_file  fh 
)

Flushes all pending write operations from cache for given file

Parameters
fsthe file system struct
fhthe filehandle of the file to flush

§ SPIFFS_close()

s32_t SPIFFS_close ( spiffs fs,
spiffs_file  fh 
)

Closes a filehandle. If there are pending write operations, these are finalized before closing.

Parameters
fsthe file system struct
fhthe filehandle of the file to close

§ SPIFFS_rename()

s32_t SPIFFS_rename ( spiffs fs,
const char *  old,
const char *  newPath 
)

Renames a file

Parameters
fsthe file system struct
oldpath of file to rename
newPathnew path of file

§ SPIFFS_errno()

s32_t SPIFFS_errno ( spiffs fs)

Returns last error of last file operation.

Parameters
fsthe file system struct

§ SPIFFS_clearerr()

void SPIFFS_clearerr ( spiffs fs)

Clears last error.

Parameters
fsthe file system struct

§ SPIFFS_opendir()

spiffs_DIR* SPIFFS_opendir ( spiffs fs,
const char *  name,
spiffs_DIR d 
)

Opens a directory stream corresponding to the given name. The stream is positioned at the first entry in the directory. On hydrogen builds the name argument is ignored as hydrogen builds always correspond to a flat file structure - no directories.

Parameters
fsthe file system struct
namethe name of the directory
dpointer the directory stream to be populated

§ SPIFFS_closedir()

s32_t SPIFFS_closedir ( spiffs_DIR d)

Closes a directory stream

Parameters
dthe directory stream to close

§ SPIFFS_readdir()

struct spiffs_dirent* SPIFFS_readdir ( spiffs_DIR d,
struct spiffs_dirent e 
)

Reads a directory into given spifs_dirent struct.

Parameters
dpointer to the directory stream
ethe dirent struct to be populated
Returns
null if error or end of stream, else given dirent is returned

§ SPIFFS_check()

s32_t SPIFFS_check ( spiffs fs)

Runs a consistency check on given filesystem.

Parameters
fsthe file system struct

§ SPIFFS_info()

s32_t SPIFFS_info ( spiffs fs,
u32_t total,
u32_t used 
)

Returns number of total bytes available and number of used bytes. This is an estimation, and depends on if there a many files with little data or few files with much data. NB: If used number of bytes exceeds total bytes, a SPIFFS_check should run. This indicates a power loss in midst of things. In worst case (repeated powerlosses in mending or gc) you might have to delete some files.

Parameters
fsthe file system struct
totaltotal number of bytes in filesystem
usedused number of bytes in filesystem

§ SPIFFS_format()

s32_t SPIFFS_format ( spiffs fs)

Formats the entire file system. All data will be lost. The filesystem must not be mounted when calling this.

NB: formatting is awkward. Due to backwards compatibility, SPIFFS_mount MUST be called prior to formatting in order to configure the filesystem. If SPIFFS_mount succeeds, SPIFFS_unmount must be called before calling SPIFFS_format. If SPIFFS_mount fails, SPIFFS_format can be called directly without calling SPIFFS_unmount first.

Parameters
fsthe file system struct

§ SPIFFS_mounted()

u8_t SPIFFS_mounted ( spiffs fs)

Returns nonzero if spiffs is mounted, or zero if unmounted.

Parameters
fsthe file system struct

§ SPIFFS_gc_quick()

s32_t SPIFFS_gc_quick ( spiffs fs,
u16_t  max_free_pages 
)

Tries to find a block where most or all pages are deleted, and erase that block if found. Does not care for wear levelling. Will not move pages around. If parameter max_free_pages are set to 0, only blocks with only deleted pages will be selected.

NB: the garbage collector is automatically called when spiffs needs free pages. The reason for this function is to give possibility to do background tidying when user knows the system is idle.

Use with care.

Setting max_free_pages to anything larger than zero will eventually wear flash more as a block containing free pages can be erased.

Will set err_no to SPIFFS_OK if a block was found and erased, SPIFFS_ERR_NO_DELETED_BLOCK if no matching block was found, or other error.

Parameters
fsthe file system struct
max_free_pagesmaximum number allowed free pages in block

§ SPIFFS_gc()

s32_t SPIFFS_gc ( spiffs fs,
u32_t  size 
)

Will try to make room for given amount of bytes in the filesystem by moving pages and erasing blocks. If it is physically impossible, err_no will be set to SPIFFS_ERR_FULL. If there already is this amount (or more) of free space, SPIFFS_gc will silently return. It is recommended to call SPIFFS_info before invoking this method in order to determine what amount of bytes to give.

NB: the garbage collector is automatically called when spiffs needs free pages. The reason for this function is to give possibility to do background tidying when user knows the system is idle.

Use with care.

Parameters
fsthe file system struct
sizeamount of bytes that should be freed

§ SPIFFS_eof()

s32_t SPIFFS_eof ( spiffs fs,
spiffs_file  fh 
)

Check if EOF reached.

Parameters
fsthe file system struct
fhthe filehandle of the file to check

§ SPIFFS_tell()

s32_t SPIFFS_tell ( spiffs fs,
spiffs_file  fh 
)

Get position in file.

Parameters
fsthe file system struct
fhthe filehandle of the file to check

§ SPIFFS_set_file_callback_func()

s32_t SPIFFS_set_file_callback_func ( spiffs fs,
spiffs_file_callback  cb_func 
)

Registers a callback function that keeps track on operations on file headers. Do note, that this callback is called from within internal spiffs mechanisms. Any operations on the actual file system being callbacked from in this callback will mess things up for sure - do not do this. This can be used to track where files are and move around during garbage collection, which in turn can be used to build location tables in ram. Used in conjuction with SPIFFS_open_by_page this may improve performance when opening a lot of files. Must be invoked after mount.

Parameters
fsthe file system struct
cb_functhe callback on file operations

§ SPIFFS_ix_map()

s32_t SPIFFS_ix_map ( spiffs fs,
spiffs_file  fh,
spiffs_ix_map map,
u32_t  offset,
u32_t  len,
spiffs_page_ix map_buf 
)

Maps the first level index lookup to a given memory map. This will make reading big files faster, as the memory map will be used for looking up data pages instead of searching for the indices on the physical medium. When mapping, all affected indicies are found and the information is copied to the array. Whole file or only parts of it may be mapped. The index map will cover file contents from argument offset until and including arguments (offset+len). It is valid to map a longer range than the current file size. The map will then be populated when the file grows. On garbage collections and file data page movements, the map array will be automatically updated. Do not tamper with the map array, as this contains the references to the data pages. Modifying it from outside will corrupt any future readings using this file descriptor. The map will no longer be used when the file descriptor closed or the file is unmapped. This can be useful to get faster and more deterministic timing when reading large files, or when seeking and reading a lot within a file.

Parameters
fsthe file system struct
fhthe file handle of the file to map
mapa spiffs_ix_map struct, describing the index map
offsetabsolute file offset where to start the index map
lenlength of the mapping in actual file bytes
map_bufthe array buffer for the look up data - number of required elements in the array can be derived from function SPIFFS_bytes_to_ix_map_entries given the length

§ SPIFFS_ix_unmap()

s32_t SPIFFS_ix_unmap ( spiffs fs,
spiffs_file  fh 
)

Unmaps the index lookup from this filehandle. All future readings will proceed as normal, requiring reading of the first level indices from physical media. The map and map buffer given in function SPIFFS_ix_map will no longer be referenced by spiffs. It is not strictly necessary to unmap a file before closing it, as closing a file will automatically unmap it.

Parameters
fsthe file system struct
fhthe file handle of the file to unmap

§ SPIFFS_ix_remap()

s32_t SPIFFS_ix_remap ( spiffs fs,
spiffs_file  fh,
u32_t  offs 
)

Moves the offset for the index map given in function SPIFFS_ix_map. Parts or all of the map buffer will repopulated.

Parameters
fsthe file system struct
fhthe mapped file handle of the file to remap
offsnew absolute file offset where to start the index map

§ SPIFFS_bytes_to_ix_map_entries()

s32_t SPIFFS_bytes_to_ix_map_entries ( spiffs fs,
u32_t  bytes 
)

Utility function to get number of spiffs_page_ix entries a map buffer must contain on order to map given amount of file data in bytes. See function SPIFFS_ix_map and SPIFFS_ix_map_entries_to_bytes.

Parameters
fsthe file system struct
bytesnumber of file data bytes to map
Returns
needed number of elements in a spiffs_page_ix array needed to map given amount of bytes in a file

§ SPIFFS_ix_map_entries_to_bytes()

s32_t SPIFFS_ix_map_entries_to_bytes ( spiffs fs,
u32_t  map_page_ix_entries 
)

Utility function to amount of file data bytes that can be mapped when mapping a file with buffer having given number of spiffs_page_ix entries. See function SPIFFS_ix_map and SPIFFS_bytes_to_ix_map_entries.

Parameters
fsthe file system struct
map_page_ix_entriesnumber of entries in a spiffs_page_ix array
Returns
amount of file data in bytes that can be mapped given a map buffer having given amount of spiffs_page_ix entries

§ SPIFFS_buffer_bytes_for_filedescs()

u32_t SPIFFS_buffer_bytes_for_filedescs ( spiffs fs,
u32_t  num_descs 
)

Returns number of bytes needed for the filedescriptor buffer given amount of file descriptors.

§ SPIFFS_buffer_bytes_for_cache()

u32_t SPIFFS_buffer_bytes_for_cache ( spiffs fs,
u32_t  num_pages 
)

Returns number of bytes needed for the cache buffer given amount of cache pages.

Copyright 2018, Texas Instruments Incorporated