Olli Vanhoja
/
mFS_sample
Examples for mFS.
Revision 3:fa4e0fea475b, committed 2011-02-24
- Comitter:
- HBP
- Date:
- Thu Feb 24 00:02:58 2011 +0000
- Parent:
- 2:a608de004dcf
- Commit message:
- -16bit block number version
Changed in this revision
mFS.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r a608de004dcf -r fa4e0fea475b mFS.lib --- a/mFS.lib Tue Feb 22 21:40:00 2011 +0000 +++ b/mFS.lib Thu Feb 24 00:02:58 2011 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/HBP/code/mFS/#6c4fcb9d6193 +http://mbed.org/users/HBP/code/mFS/#928346513c87
diff -r a608de004dcf -r fa4e0fea475b main.cpp --- a/main.cpp Tue Feb 22 21:40:00 2011 +0000 +++ b/main.cpp Thu Feb 24 00:02:58 2011 +0000 @@ -13,7 +13,7 @@ pc.printf("\n\r\n\r[mFS] Formatting... %u bad block headers.\n\r", fs.mkfs(true)); // Quick format EEPROM // Mark block 2 as bad - fs.write((char[]){'\x00','\x00','\x00'}, 2, 0, 3); + fs.write((char[]){'\x00','\x00','\x00', '\x00', '\x00'}, 2, 0, 3); pc.printf("Block 2 marked as a bad block.\n\r"); fs.read(data, 0, 0, 1); @@ -26,32 +26,32 @@ pc.printf("Create file new.txt: "); printStatus(fs.createFile("new.txt")); // Try to write multi block file new.txt - file *fp3 = new file(&fs, "new.txt", 1); - pc.printf("Trying to write multi block file new.txt...\n\r"); - for (n=0; n < (BS-4)-20-1; n++) - fp3->write("b", 1); + file *fp3 = new file(&fs, "new.txt", AWRITE); + pc.printf("Trying to write multi-block file new.txt...\n\r"); + for (n=0; n < BS; n++) + fp3->write("F", 1); pc.printf("Create file testi.txt: "); printStatus(fs.createFile("testi.txt")); - file *fp = new file(&fs, "testi.txt", 1); + file *fp = new file(&fs, "testi.txt", AWRITE); pc.printf("File new.txt opened successfully\n\r"); fp->write("The quick brown fox jumps over the lazy dog", 44); pc.printf("File write OK\n\r"); fp->flush(); pc.printf("Continue to write new.txt..."); - for (n=0; n < 40; n++) - fp3->write("u", 1); + for (n=0; n < 400; n++) + fp3->write("S", 1); pc.printf(" End\n\r"); fp3->rewind(); - fp3->read(buf, 1); + fp3->read(buf, 20); pc.printf("Rewind test (new.txt): %s\n\r", buf); - fp3->forward(BS-20); - fp3->read(buf, 1); + pc.printf("Forwarding new.txt: "); printStatus(fp3->forward(BS-25-22)); + fp3->read(buf, 43); pc.printf("Forward test (new.txt): %s\n\r", buf); delete fp3; - pc.printf("Create file ykaa.txt: "); printStatus(fs.createFile("yykaa.txt")); + pc.printf("Create file yykaa.txt: "); printStatus(fs.createFile("yykaa.txt")); fp->rewind(); fp->read(buf, 44); @@ -59,7 +59,7 @@ delete fp; // Open read-only file - file *fp2 = new file(&fs, "koe.txt", 0); /* Keep in mind that error will * + file *fp2 = new file(&fs, "koe.txt", RO); /* Keep in mind that error will * * be thrown if RO file is * * opened in RW mode. So it's * * better to check flags before * @@ -76,6 +76,15 @@ ls(&fs); listReservedBlocks(&fs); + + fs.setFileFlags(0, "new.txt"); + file *fp4 = new file(&fs, "new.txt", DWRITE); + pc.printf("Trying destructive write with new.txt... "); + for (n=0; n < 3*(BS-25); n++) + fp3->write("*", 1); + pc.printf("End\n\r"); + listReservedBlocks(&fs); + } /** Lists files stored in file system @@ -103,9 +112,9 @@ pc.printf(" "); pc.printf("%X\t%X\n\r", n, flags[0]); } else break; // Reach end of fs + fileCount++; next: n++; - fileCount++; } // Get number of free blocks @@ -113,7 +122,7 @@ // Calculate amount of space used unsigned int iSpaceUsed = VOL_SIZE - (iFreeBlocks*BS); // Summary - pc.printf("%u files total\n\r%u/%u kB space used, %u blocks free\n\r\n\r", fileCount-1, iSpaceUsed/1024, VOL_SIZE/1024, iFreeBlocks); + pc.printf("%u files total\n\r%u/%u kB space used, %u blocks free\n\r\n\r", fileCount, iSpaceUsed/1024, VOL_SIZE/1024, iFreeBlocks); } /** Lists blocks marked as used @@ -122,14 +131,14 @@ */ void listReservedBlocks(mfs *fs) { - char data[3]; + char data[5]; - pc.printf("\n\rReserved blocks:\n\r"); + pc.printf("\n\rReserved blocks and list of related links:\n\r"); for (unsigned int n=0; n < BC; n++) { - fs->read(data, n, 0, 3); + fs->read(data, n, 0, 5); if (data[0] != 4) - pc.printf("b%XB0: %X, %X, %X\n\r", n, data[0], data[1], data[2]); + pc.printf("b%XB0: %X, %X, %X\n\r", n, data[0], data[1]<<8|data[2], data[3]<<8|data[4]); } }