MeterLogger
Typedefs | Functions
espfs.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct EspFsFile EspFsFile
 

Functions

EspFsFileespFsOpen (char *fileName)
 
int espFsRead (EspFsFile *fh, char *buff, int len)
 
void espFsClose (EspFsFile *fh)
 

Typedef Documentation

◆ EspFsFile

typedef struct EspFsFile EspFsFile

Definition at line 6 of file espfs.h.

Function Documentation

◆ espFsClose()

void espFsClose ( EspFsFile fh)

Definition at line 214 of file espfs.c.

References EspFsFile::decompData, EspFsFile::decompressor, heatshrink_decoder_free(), NULL, and os_free.

Referenced by cgiEspFsHook(), and cgiEspFsTemplate().

214  {
215  if (fh==NULL) return;
216 #ifdef EFS_HEATSHRINK
217  if (fh->decompressor==COMPRESS_HEATSHRINK) {
220 // INFO("Freed %p\n", dec);
221  }
222 #endif
223 // INFO("Freed %p\n", fh);
224  os_free(fh);
225 }
void * decompData
Definition: espfs.c:57
#define NULL
Definition: def.h:47
void heatshrink_decoder_free(heatshrink_decoder *hsd)
char decompressor
Definition: espfs.c:53
#define os_free(s)
Definition: mem.h:40
Here is the call graph for this function:
Here is the caller graph for this function:

◆ espFsOpen()

EspFsFile* espFsOpen ( char *  fileName)

Definition at line 97 of file espfs.c.

References EspFsFile::decompData, EspFsFile::decompressor, ESPFS_POS, EspFsFile::header, heatshrink_decoder_alloc(), INFO, memcpyAligned(), NULL, os_malloc, os_memcpy, os_strcmp, EspFsFile::posComp, EspFsFile::posDecomp, and EspFsFile::posStart.

Referenced by cgiEspFsHook(), and cgiEspFsTemplate().

97  {
98 #ifdef __ets__
99  char *p=(char *)(ESPFS_POS+0x40200000);
100 #else
101  char *p=espFsData;
102 #endif
103  char *hpos;
104  char namebuf[256];
105  EspFsHeader h;
106  EspFsFile *r;
107  //Strip initial slashes
108  while(fileName[0]=='/') fileName++;
109  //Go find that file!
110  while(1) {
111  hpos=p;
112  //Grab the next file header.
113  os_memcpy(&h, p, sizeof(EspFsHeader));
114  if (h.magic!=0x73665345) {
115  INFO("Magic mismatch. EspFS image broken.\n");
116  return NULL;
117  }
118  if (h.flags&FLAG_LASTFILE) {
119  INFO("End of image.\n");
120  return NULL;
121  }
122  //Grab the name of the file.
123  p+=sizeof(EspFsHeader);
124  os_memcpy(namebuf, p, sizeof(namebuf));
125 // INFO("Found file '%s'. Namelen=%x fileLenComp=%x, compr=%d flags=%d\n",
126 // namebuf, (unsigned int)h.nameLen, (unsigned int)h.fileLenComp, h.compression, h.flags);
127  if (os_strcmp(namebuf, fileName)==0) {
128  //Yay, this is the file we need!
129  p+=h.nameLen; //Skip to content.
130  r=(EspFsFile *)os_malloc(sizeof(EspFsFile)); //Alloc file desc mem
131 // INFO("Alloc %p\n", r);
132  if (r==NULL) return NULL;
133  r->header=(EspFsHeader *)hpos;
134  r->decompressor=h.compression;
135  r->posComp=p;
136  r->posStart=p;
137  r->posDecomp=0;
138  if (h.compression==COMPRESS_NONE) {
139  r->decompData=NULL;
140 #ifdef EFS_HEATSHRINK
141  } else if (h.compression==COMPRESS_HEATSHRINK) {
142  //File is compressed with Heatshrink.
143  char parm;
144  heatshrink_decoder *dec;
145  //Decoder params are stored in 1st byte.
146  memcpyAligned(&parm, r->posComp, 1);
147  r->posComp++;
148  INFO("Heatshrink compressed file; decode parms = %x\n", parm);
149  dec=heatshrink_decoder_alloc(16, (parm>>4)&0xf, parm&0xf);
150  r->decompData=dec;
151 #endif
152  } else {
153  INFO("Invalid compression: %d\n", h.compression);
154  return NULL;
155  }
156  return r;
157  }
158  //We don't need this file. Skip name and file
159  p+=h.nameLen+h.fileLenComp;
160  if ((int)p&3) p+=4-((int)p&3); //align to next 32bit val
161  }
162 }
char * posStart
Definition: espfs.c:55
void * decompData
Definition: espfs.c:57
int32_t posDecomp
Definition: espfs.c:54
#define NULL
Definition: def.h:47
heatshrink_decoder * heatshrink_decoder_alloc(uint16_t input_buffer_size, uint8_t window_sz2, uint8_t lookahead_sz2)
void ICACHE_FLASH_ATTR memcpyAligned(char *dst, char *src, int len)
Definition: espfs.c:81
#define os_memcpy
Definition: osapi.h:36
#define os_strcmp
Definition: osapi.h:41
#define os_malloc(s)
Definition: mem.h:41
EspFsHeader * header
Definition: espfs.c:52
char decompressor
Definition: espfs.c:53
#define ESPFS_POS
Definition: httpdconfig.h:6
char * posComp
Definition: espfs.c:56
#define INFO(...)
Definition: debug.h:17
Here is the call graph for this function:
Here is the caller graph for this function:

◆ espFsRead()

int espFsRead ( EspFsFile fh,
char *  buff,
int  len 
)

Definition at line 165 of file espfs.c.

References EspFsFile::decompData, EspFsFile::decompressor, EspFsFile::header, heatshrink_decoder_finish(), heatshrink_decoder_poll(), heatshrink_decoder_sink(), memcpyAligned(), NULL, EspFsFile::posComp, EspFsFile::posDecomp, and EspFsFile::posStart.

Referenced by cgiEspFsHook(), and cgiEspFsTemplate().

165  {
166  int flen;
167  if (fh==NULL) return 0;
168  //Cache file length.
169  memcpyAligned((char*)&flen, (char*)&fh->header->fileLenComp, 4);
170  //Do stuff depending on the way the file is compressed.
171  if (fh->decompressor==COMPRESS_NONE) {
172  int toRead;
173  toRead=flen-(fh->posComp-fh->posStart);
174  if (len>toRead) len=toRead;
175 // INFO("Reading %d bytes from %x\n", len, (unsigned int)fh->posComp);
176  memcpyAligned(buff, fh->posComp, len);
177  fh->posDecomp+=len;
178  fh->posComp+=len;
179 // INFO("Done reading %d bytes, pos=%x\n", len, fh->posComp);
180  return len;
181 #ifdef EFS_HEATSHRINK
182  } else if (fh->decompressor==COMPRESS_HEATSHRINK) {
183  int decoded=0;
184  unsigned int elen, rlen;
185  char ebuff[16];
187 // INFO("Alloc %p\n", dec);
188  while(decoded<len) {
189  //Feed data into the decompressor
190  //ToDo: Check ret val of heatshrink fns for errors
191  elen=flen-(fh->posComp - fh->posStart);
192  if (elen==0) return decoded; //file is read
193  if (elen>0) {
194  memcpyAligned(ebuff, fh->posComp, 16);
195  heatshrink_decoder_sink(dec, (uint8_t *)ebuff, (elen>16)?16:elen, &rlen);
196  fh->posComp+=rlen;
197  if (rlen==elen) {
199  }
200  }
201  //Grab decompressed data and put into buff
202  heatshrink_decoder_poll(dec, (uint8_t *)buff, len-decoded, &rlen);
203  fh->posDecomp+=rlen;
204  buff+=rlen;
205  decoded+=rlen;
206  }
207  return len;
208 #endif
209  }
210  return 0;
211 }
HSD_poll_res heatshrink_decoder_poll(heatshrink_decoder *hsd, uint8_t *out_buf, size_t out_buf_size, size_t *output_size)
char * posStart
Definition: espfs.c:55
void * decompData
Definition: espfs.c:57
int32_t posDecomp
Definition: espfs.c:54
#define NULL
Definition: def.h:47
void ICACHE_FLASH_ATTR memcpyAligned(char *dst, char *src, int len)
Definition: espfs.c:81
HSD_finish_res heatshrink_decoder_finish(heatshrink_decoder *hsd)
EspFsHeader * header
Definition: espfs.c:52
char decompressor
Definition: espfs.c:53
HSD_sink_res heatshrink_decoder_sink(heatshrink_decoder *hsd, uint8_t *in_buf, size_t size, size_t *input_size)
char * posComp
Definition: espfs.c:56
Here is the call graph for this function:
Here is the caller graph for this function: