Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: sfs.h
- * Author: Marcus Hund (@marcus at community.spark.io)
- * Created on May 30, 2014, 2:21 PM
- * SFS: Simple|Silly File System
- * This class creates a files system that can hold 16 files, each with a max size of 64kB. It's silly, in the sense that it
- * uses 1 4k block for the directory entry and 16 4K blocks per file. These parameters can be tailored to your need off course.
- * But keep in mind that the flash memory is divided in sectors of 4kB.
- * It's working flawlessly in a webserver I created.
- *
- */
- #include "stdint.h"
- #include "string.h"
- #include "spark_wiring_string.h"
- #include "stm32_it.h"
- #include "spark_wiring_usartserial.h"
- #include "spark_wiring_tcpclient.h"
- #ifndef SFS_H
- #define SFS_H
- #define MAX_FILES 16
- #define FLASH_USER_SPACE 0x80000
- #define FILE_NONE 0
- #define FILE_WRITE 1
- #define FILE_READ 2
- #define DIR_ENTRY 0x1000
- #define MAX_NAME_LEN 32
- #define FILE_LEN_OFFSET MAX_NAME_LEN + 2
- #define MAX_FILESIZE_LEN 8
- #define MAX_FILE_BLOCKS 16
- #define FILE_NOT_FOUND -1;
- class sfs {
- public:
- sfs();
- int dir(char * entry);
- int dir(char * entry, int * ndx);
- bool open(char* name);
- bool create(char* name);
- void append(char * str);
- void append(char* array, int len);
- int read(char *buffer, int len);
- void close();
- int get_handle(char *name);
- int rename(char*oldname, char* newname);
- void dump();
- void dump(int handle, int len);
- void dump_loc(uint32_t p, int len);
- void erase_file(char* name);
- void erase_all_files();
- int size();
- private:
- unsigned long filepointer;
- uint8_t bb;
- int filesize;
- int read();
- int read_user_flash(unsigned long loc, uint8_t* array, unsigned long length);
- unsigned long calc_file_offset(int where);
- bool handle_is_ok();
- void write_filename(char*name);
- void write_file_size();
- void read_flash(uint8_t* array, uint32_t start, uint32_t len);
- void write_flash(uint8_t* array, uint32_t start, uint32_t len);
- void pad(uint8_t * buf, char* str);
- unsigned long calc_dir_entry();
- void get_free_handle(char *name);
- void erase_handle();
- void erase_file_data();
- void erase_file(int h);
- int erase_sector(uint32_t start);
- int write_to_user_flash(uint8_t *buf, uint32_t start, uint32_t len);
- void pad(uint8_t* buf, char* name, int len);
- int file_mode;
- bool pad_flag;
- char pad_char;
- int len;
- int wlen;
- char wbuf[256];
- uint8_t wndx;
- void flush();
- int handle;
- void add_to_buf(char str);
- void add_to_buf(char* str);
- void add_to_buf_minus_one(char* str);
- int get_dir_entry(char * entry, int * ndx);
- int dir_index;
- };
- #endif /* SFS_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement