ChainingBlockDevice example to show how to format a FATFileSystem on two blocks of storage

Fork of MBRBlockDevice_ex_1 by mbed_example

Revision:
1:8ad9777787ba
Parent:
0:daa62d7aa9f9
--- a/main.cpp	Fri Oct 13 16:56:09 2017 +0000
+++ b/main.cpp	Wed Oct 18 20:03:25 2017 +0000
@@ -1,18 +1,23 @@
 #include "mbed.h"
 #include "HeapBlockDevice.h"
-#include "MBRBlockDevice.h"
+#include "ChainingBlockDevice.h"
+#include "FATFileSystem.h"
     
 int main(void) {
-    // Create a block device with 64 blocks of size 512
-    HeapBlockDevice mem(64*512, 512);
-    
-    // Partition into two partitions with ~half the blocks
-    MBRBlockDevice::partition(&mem, 1, 0x83, 0*512, 32*512);
-    MBRBlockDevice::partition(&mem, 2, 0x83, 32*512);
+    // Create two smaller block devices with
+    // 64 and 32 blocks of size 512 bytes
+    HeapBlockDevice mem1(64*512, 512);
+    HeapBlockDevice mem2(32*512, 512);
     
-    // Create a block device that maps to the first 32 blocks (excluding MBR block)
-    MBRBlockDevice part1(&mem, 1);
+    // Create a block device backed by mem1 and mem2
+    // contains 96 blocks of size 512 bytes
+    BlockDevice *bds[] = {&mem1, &mem2};
+    ChainingBlockDevice chainmem(bds);
     
-    // Create a block device that maps to the last 32 blocks
-    MBRBlockDevice part2(&mem, 2);
+    // Format the new chained block device with a FAT filesystem
+    FATFileSystem::format(&chainmem);
+    
+    // Create the FAT filesystem instance, files can now be written to
+    // the FAT filesystem as if to a single 96 x 512 byte storage device
+    FATFileSystem fat("fat", &chainmem);
 }
\ No newline at end of file