Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: mfs.h
- Revision:
- 9:52c01cb100ac
- Parent:
- 8:e67733ad4427
- Child:
- 10:211cb54339a0
diff -r e67733ad4427 -r 52c01cb100ac mfs.h
--- a/mfs.h Mon Feb 21 22:41:13 2011 +0000
+++ b/mfs.h Tue Feb 22 18:57:37 2011 +0000
@@ -44,10 +44,13 @@
* *Added possibility change I2C speed
* *I2C autoreset on failure
* 0.4 2011-02-22 Olli Vanhoja *mfs::renameFile(char [20], char [20] function added
+ * *Incresed fault tolerance by first allocating new
+ * block and then linking to it from previous block
*
* TODO :
- * Directory support (VOL labeled blocks)
- *
+ * *Directory support (VOL labeled blocks)
+ * *Change 16bit integers to 32bit where it's possible
+ *Support for >256 blocks
*H*/
#ifndef MFS_H
@@ -61,8 +64,6 @@
const char mEOF='\x01'; // End Of File/Section marked
const unsigned int BUF=400; /**< File buffer length */
-typedef unsigned short int uint16;
-
/** mFS File System class
*
* This class is used as a handle for the fs in use.
@@ -85,7 +86,7 @@
* @param n Bytes to be read.
* @returns Error code. 0 = OK, 1 = Incorrect input
*/
- char read(char *data, char block, unsigned int byte, unsigned int n);
+ char read(char *data, char block, uint32_t byte, uint32_t n);
/** Writes data to specified fs block
*
@@ -95,7 +96,7 @@
* @param n Bytes to be read.
* @returns Error code. 0 = OK, 1 = Incorrect input
*/
- char write(char *data, char block, unsigned int byte, unsigned int n);
+ char write(char *data, char block, uint32_t byte, uint32_t n);
/** Locate next free block
*
@@ -110,14 +111,14 @@
* @param *filenameOut Return name of the file found.
* @returns Block number of the file found or 0xFFFF to indicate empty file system.
*/
- unsigned int findNextFile(unsigned int block, char *filenameOut);
+ uint32_t findNextFile(char block, char *filenameOut);
/** Get number of the first block of the given file. (FBOF flag)
*
* @param filename[20] Filename input.
* @returns Block number of the file or 0xFFFF to indicate that file not found.
*/
- uint16 getFirstBlockOfFile(char filename[20]);
+ uint32_t getFirstBlockOfFile(char filename[20]);
/** Create a new empty file
*
@@ -168,7 +169,7 @@
*
* @returns Number of free blocks.
*/
- uint16 free();
+ char free();
/** Format new file system
*
@@ -188,21 +189,32 @@
mfs *fs; // Reference to the file system in use
char attr; // RW = 1; RO = 0
char buffer[BUF]; // Write buffer
- unsigned int bufPos; // "Cursor" position in buffer
+ uint32_t bufPos; // "Cursor" position in buffer
char firstBlock; // First block of the file
char currBlock; // Current block in use
- unsigned int blockPos; // "head" position on the current block
- void needsFlush(); // check if flush is needed before read operation
+ uint32_t blockPos; // "head" position on the current block
public:
/** Open new file handle
*
- * File must be created before it can be opened!
+ * \warning {File must be created before it can be opened!
+ * Opening non-existing file will trip the system to error();}
*
* @param filename[20] Filename input.
* @param operation 0 = read only, 1 = read and write. If read only file is opened in rw mode system will trip to error().
*/
file(mfs *fs_ref, char filename[20], char operation);
+ /** Open new file handle with timed flush
+ *
+ * \warning {File must be created before it can be opened!
+ * Opening non-existing file will trip the system to error();}
+ *
+ * @param filename[20] Filename input.
+ * @param operation 0 = read only, 1 = read and write. If read only file is opened in rw mode system will trip to error().
+ * @param autoFlushInterval Interval between flushes in seconds.
+ */
+ file(mfs *fs_ref, char filename[20], char operation, float autoFlushInterval);
+
/** Close file handle
*
* Flushes the file and closes the handle.
@@ -219,7 +231,7 @@
* @param n Number of blocks to be rewinded.
* @returns Error code. 0 = OK, 1 = First block of file.
*/
- char rewind(uint16 n);
+ char rewind(uint32_t n);
/** Forward one byte
*
@@ -232,7 +244,7 @@
* @param n Number of blocks.
* @returns Error code. 0 = OK, 1 = End of file.
*/
- char forward(uint16 n);
+ char forward(uint32_t n);
/** Reads a string of bytes
*
@@ -242,7 +254,7 @@
* @param n Number of bytes to be read.
* @returns Error code. 0 = OK, 1 = Last block of the file
*/
- void read(char *data, unsigned int n);
+ void read(char *data, uint32_t n);
/** Reads a binary array of bytes
*
* Doesn't add '\0' at the end of data array and doesn't respect mEOF byte.
@@ -251,7 +263,7 @@
* @param n Number of bytes to be read.
*/
- void readBin(char *data, unsigned int n);
+ void readBin(char *data, uint32_t n);
/** Write byte array to a file (buffer)
*
* @param data Input data.
@@ -259,7 +271,7 @@
* @returns Error code. 0 = OK, 1 = Flush failed.
*/
- char write(char *data, unsigned int n);
+ char write(char *data, uint32_t n);
/** Flush file buffer
* Writes buffer to the EEPROM chip in use.