Partitions
A device can be partitioned into two or more regions, and a file system created on one or more of these, each of which could be mounted as a volume. µC/FS can handle and make DOS-style partitions, which is a common partitioning system.
The first sector on a device with DOS-style partitions is the Master Boot Record (MBR), with a partition table with four entries, each describing a partition. An MBR entry contains the start address of a partition, the number of sectors it contains and its type. The structure of a MBR entry and the MBR sector is shown in Figure - Partition entry format and Figure - Master boot record.
An application can write an MBR to a device and create an initial partition with FSDev_PartitionInit()
. For example, if you wanted to create an initial 256-MB partition on a 1-GB device “ide:0:
”:
FSDev_PartitionInit((CPU_CHAR *)"ide:0:", /* <-- (a) device name */ (FS_SEC_QTY )(512 * 1024), /* <-- (b) size of partition */ (FS_ERR *)&err); /* <-- (c) return error */
The parameters are the device name (a) and the size of the partition, in sectors (b). If (b) is 0, then the partition will take up the entire device. After this call, the device will be divided as shown in Figure - Device after partition initialization. This new partition is called a primary partition because its entry is in the MBR. The four circles in the MBR represent the four partition entries; the one that is now used ‘points to’ Primary Partition 1.
More partitions can now be created on the device. Since the MBR has four partition entries, three more can be made without using extended partitions (as discussed below). The function FSDev_PartitionAdd() should be called three times:
FSDev_PartitionAdd((CPU_CHAR *)"ide:0:", /* <-- (a) device name */ (FS_SEC_QTY )(512 * 1024), /* <-- (b) size of partition */ (FS_ERR *)&err); /* <-- (c) return error */
Again, the parameters are the device name (a) and the size of the partition, in sectors (b). After this has been done, the device is divided as shown in Figure - Device after four partitions have been created.
When first instituted, DOS partitioning was a simple scheme allowing up to four partitions, each with an entry in the MBR. It was later extended for larger devices requiring more with extended partitions, partitions that contains other partitions. The primary extended partition is the extended partition with its entry in the MBR; it should be the last occupied entry.
An extended partition begins with a partition table that has up to two entries (typically). The first defines a secondary partition which may contain a file system. The second may define another extended partition; in this case, a secondary extended partition, which can contain yet another secondary partition and secondary extended partition. Basically, the primary extended partition heads a linked list of partitions.
Reading secondary partitions in existing preformatted devices is supported in µC/FS. For the moment, the creation of extended and secondary partitions is not supported in µC/FS.