SpriteHTTPD - embedded HTTP server with read-only filesystem and templating, originally developed for ESP8266, now stand-alone and POSIX compatible.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
spritehttpd/spritehttpd/lib/espfs/espfs.h

88 lines
1.8 KiB

#pragma once
#include <stdbool.h>
#include <stddef.h>
#include "espfsformat.h"
#include "heatshrink_decoder.h"
typedef enum {
ESPFS_INIT_RESULT_OK,
ESPFS_INIT_RESULT_NO_IMAGE,
ESPFS_INIT_RESULT_BAD_ALIGN,
} EspFsInitResult;
typedef struct EspFsFile EspFsFile;
struct EspFsWalk {
uint32_t hpos;
};
typedef struct EspFsWalk EspFsWalk;
/**
* Read a file header
*
* @param[in] file - file to read
* @param[out] header - header is read here
* @return 0 = success
*/
int espFsFileReadHeader(const EspFsFile *file, EspFsHeader *header);
/** Init filesystem walk */
void espFsWalkInit(EspFsWalk *walk);
/**
* Advance in the filesystem walk
*
* header - the next file's header is read here
* namebuf - the name is read here
* filepos - the file header's pos is copied here, if not NULL
*/
bool espFsWalkNext(EspFsWalk *walk, EspFsHeader *header, char *namebuf, size_t namebuf_cap, uint32_t *filepos);
/** Open a file with header starting at the given position */
EspFsFile *espFsOpenAt(uint32_t hpos);
/**
* Open a file using an already read header and it's offset.
* This is the same function as espFsOpenAt, but avoids reading the header again if already read.
*/
EspFsFile *espFsOpenFromHeader(EspFsHeader *h, uint32_t hpos);
/**
* Init the filesystem global state
*
* @return
*/
EspFsInitResult espFsInit();
/**
* Open a file
*
* @param fileName
* @return File handle or null
*/
EspFsFile *espFsOpen(const char *fileName);
/**
* Read file flags
*
* @param fh - file handle
* @return flags
*/
int espFsFlags(EspFsFile *fh);
/**
* Read from an open file
*
* @param fh - file handle
* @param[out] buff - output buffer
* @param len - read len
* @return real length of read bytes
*/
size_t espFsRead(EspFsFile *fh, uint8_t *buff, size_t len);
/**
* Close a file
*
* @param fh - file handle
*/
void espFsClose(EspFsFile *fh);