mFS

This note is related to my previously published mFS file system.

Specifications:

  • Filename length: 20 characters (NULL and EOF characters are reserved for internal use. Filename ends with NULL.)
  • Flat filesystem, No directory support atm at least
  • Cached write (buffer length can be changed)
  • Possibility use tickers to sync individual files
  • One file system per device atm
  • Maximum number of blocks: 65536 (Could be made variable in future releases.)
  • Maximum number of files: 65536 (limited by number of blocks used)
  • Block size: 32/256 B to 4 GB (minimum depends on used volume size)
  • Maximum volume size: 256 TB (Limited to 64 kB by I2C EEPROM library)

/media/uploads/HBP/mfs.png

Picture above shows how blocks and files are constructed in mFS. Byte numbers are not up-to-date

List of flags:

7:FBOF    First block of file
6:LBOF    Last block of file (FBOF & LBOF are both set if the block is only block of the file)
5:RO      Read only file (set only with FBOF)
4:HIDDEN  Hidden file
3:INUSE   Block is reserved for use
2:NBAD    Block is consider as bad block if this is 0
1:VOL     Volume label. This will be used to mark blocks used to store directory hierarchy.
0:LOCK    Not specified. Could be used for soft file lock implementation.

Short example of usage:

char buf[13];
mfs fs(0xA0); // Initialize mFS

pc.printf("\n\r\n\r[mFS] Formatting... %u bad block headers.\n\r", fs.mkfs(true));
// Sure you don't have to format on every boot :)

fs.createFile("datalog.txt");
file *fp = new file(&fs, "datalog.txt", AWRITE); /* Open the file in rw mode
                                              (there is no maximum limit for file handles
                                              but 65536 is kinda practical limit)

// Write 1000 Hello worlds
for (n=0; n < 1000; n++)
        fp->write("Hello world!", 1);
rewind(); // Rewind back to begining of the file (will automatically flush what has not been yet saved)

// Read some bytes
fp->read(buf, 13);
pc.printf("%s\n\r", buf);

delete fp; // Delete file handle (will flush if necessary)
fs.removeFile("datalog.txt"); // Remove the file created

For examples of usage see: http://mbed.org/users/HBP/programs/mFS_sample/


Please log in to post comments.