HANDLE BP_OpenPartition(
DWORD dwStartSector,
DWORD dwNumSectors,
DWORD dwPartType,
BOOL fActive,
DWORD dwCreationFlags
);
Parameters
dwStartSector
[in] Logical sector to the start of the partition. This value should be set to NEXT_FREE_LOC if no sector is specified. This parameter is ignored if an existing partition is opened.
dwNumSectors
[in] Number of logical sectors of the partition. This value can be set to USE_REMAINING_SPACE to indicate that the remaining space on the flash for the partition should be used. The USE_REMAINING_SPACE value should only be used when creating an extended partition. This parameter is ignored if an existing partition is opened.
dwPartType
[in] Type of partition to open or create. The following table shows the possible values for dwPartType. Value Description
PART_BOOTSECTION Creates a boot section that can be used to store boot arguments. All flash blocks in the partition are marked as read-only.
PART_BINFS Creates a BinFS partition. All flash blocks in the partition are marked as read-only.
PART_EXTENDED Creates an extended partition that can be used to store one or more data partitions, such as FATFS. If dwStartSector is not on a block boundary then it is incremented to start at the next block boundary.
fActive
[in] Set to TRUE to indicate that the partition is active. Set to FALSE for inactive.
dwCreationFlags
[in] Value that stores information for opening or creating a partition. The following table shows the possible values for dwCreationFlags. Value Description
PART_CREATE_NEW Creates a partition. Fails if a partition already exists.
PART_OPEN_EXISTING Opens an existing partition. Fails if the partition does not exist.
PART_OPEN_ALWAYS Creates a partition if it does not exist or opens a partition if it does exist.
Return Values
Returns a handle to the partition on success. Returns INVALID_HANDLE_VALUE on an error.
Requirements
OS Versions: Windows CE .NET 4.2 and later.
Header: Bootpart.h
Link Library: Bootpart.lib
Windows CE Features > File Systems and Data Store > File Systems and Data Store OS Design Development > File Systems > Binary Rom Image File System (BinFS)
The boot loader uses the Bootpart library to create a partition that enables BinFS and another file system, such as FAT, to be located on the same flash memory. The boot loader can use Bootpart to create the BinFS partition as well as a second partition. The second partition can either be a specific partition such as TFAT, or an extended partition. The second partition must be an extended partition if multiple data partitions are to be used. An extended partition also provides the flexibility to create one or more data partitions through the operating system (OS) using OS utilities.
Bootpart can also create a boot partition to store boot arguments. The flash blocks that contain the master boot record section, BinFS region, and the boot arguments partition are read-only and you cannot modify them. In addition, the BinFS and Boot partitions are marked as read-only so that you cannot format or delete the partitions themselves.
In order for MSPART to recognize the BinFS partition, you must add the following registry keys to the partition table.
[HKEY_LOCAL_MACHINE\System\StorageManager\PartitionTable]
"20"="BOOT"
"21"="BINFS"See Also
Binary Rom Image File System (BinFS)
Windows CE Features > File Systems and Data Store > File Systems and Data Store OS Design Development > File Systems
The binary ROM Image File System (BinFS) is a file system that reads the binary image (.bin) file format generated by Romimage.exe. The .bin file format organizes data into specific sections. Each section contains a section header that specifies the starting address, length, and checksum values for that section. Romimage.exe writes data organized by logical sections, such as an application's text or .data region, to the .bin file.
To load BinFS on top of a block driver, you must enter the appropriate registry keys in the storage profile of your block driver. For Windows CE 5.0 and later, the following code example shows the registry keys you can add to the storage profile of your block driver to specify that BinFS is the default file system.
[HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\MSFlash]
"DefaultFileSystem"="BINFS"
"PartitionDriver"="mspart.dll"
"MountHidden"=dword:1
"MountAsROM"=dword:1
"Folder"="NAND Flash"
"Name"= "FLASH Disk Block Device"
[HKEY_LOCAL_MACHINE\System\StorageManager\BinFS]
"FriendlyName"="BIN Filesystem"
"Dll"="binfs.dll"
"Paging"=dword:1
For versions of Windows CE earlier than 5.0, replace the entries for MountHidden and MountAsROM with the following single value for MountFlags:
"MountFlags"=dword:11
For more information about replacements for the MountFlags registry value, see XXXX.
In addition to the registry settings shown, you must add a registry key to the FAT file system settings within the storage profile. The default setting for FATFS is for the mount point to be visible to the user. In order to hide the mount point from the user you must add a registry key to prevent the FAT file system from shadowing the Windows directory. The following registry key prevents the FAT file system from attempting to shadow the Windows directory.
[HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\MSFlash\FATFS]
"MountFlags"=dword:0
C:\WINCE500\PUBLIC\COMMON\OAK\DRIVERS\ETHDBG\BOOTPART\bootpart.cpp(113):static BOOL CreateMBR()
//------------------------------------------------------------------------------
static BOOL CreateMBR()
{
// This, plus a valid partition table, is all the CE partition manager needs to recognize
// the MBR as valid. It does not contain boot code.
if (!WriteBlock (dwMBRBlockNum, g_pbBlock, g_pSectorInfoBuf)) {
RETAILMSG (1, (TEXT("CreatePartition: could not write to block 0x%x\r\n"), dwMBRBlockNum));
return FALSE;
}
/*****************************************************************************
* WriteMBR - adds a partition entry to the master boot record. The partition
* table is traversed to find the placement for this partition. Entries within
* the MBR are sorted by the start sector.
*
* Input: state - structure for this store
* snSectorNum - start sector number for this partition
* snNumSectors - number of sectors in this partition
* fileSysType - partition type
* bCreateMBR - TRUE to generate a new MBR, FALSE to add to the
* existing MBR *
* Output: none
*
* Return: TRUE if successfully written, FALSE for failures, ERROR_DISK_FULL
* will be set if no room in the MBR
*
*****************************************************************************/
BOOL WriteMBR(DriverState *state, SECTORNUM snSectorNum, SECTORNUM snNumSectors, BYTE fileSysType, BOOL bCreateMBR)
{
PBYTE buffer = NULL;
PPARTENTRY tmpbuffer, tmpbuffer1;
BOOL bResult;
int i, partIndex, partNum = -1;
// don't create the MBR, it already exists so use it
if (!bCreateMBR)
{
bResult = ReadSectors (state, 0, 1, &buffer);
if (!bResult)
return FALSE;
for (i = 0, partIndex = 0, tmpbuffer = (PPARTENTRY)(buffer + PARTTABLE_OFFSET); i < 4; i++, tmpbuffer++)
{
if (tmpbuffer->Part_TotalSectors == 0)
{
partNum = i;
break;
}
// find the index of the partition located just before this one
if (snSectorNum > tmpbuffer->Part_StartSector)
partIndex = i + 1;
}
if (partNum == -1)
{
// we return this error code so the caller can tell that there's no room in the MBR
LocalFree(buffer);
SetLastError(ERROR_DISK_FULL);
return FALSE;
}
// these indexes would be equal if we are adding to the end of the table
if (partIndex != partNum)
{
// this partition needs to be added in the order that it appears on the disk - so this may involve
// shifting some of the existing partition entries to open up the partition entry where this belongs
tmpbuffer = (PPARTENTRY)(buffer + PARTTABLE_OFFSET + (partNum * sizeof(PARTENTRY)));
tmpbuffer1 = (PPARTENTRY)(buffer + PARTTABLE_OFFSET + ((partNum -1) * sizeof(PARTENTRY)));
C:\WINCE500\PRIVATE\WINCEOS\COREOS\STORAGE\DOSPART\helper.cpp(747):BOOL WriteMBR(DriverState *state, SECTORNUM snSectorNum, SECTORNUM snNumSectors, BYTE fileSysType, BOOL bCreateMBR)
/*****************************************************************************
* WriteMBR - adds a partition entry to the master boot record. The partition
* table is traversed to find the placement for this partition. Entries within
* the MBR are sorted by the start sector.
*
* Input: state - structure for this store
* snSectorNum - start sector number for this partition
* snNumSectors - number of sectors in this partition
* fileSysType - partition type
* bCreateMBR - TRUE to generate a new MBR, FALSE to add to the
* existing MBR
*
* Output: none
*
* Return: TRUE if successfully written, FALSE for failures, ERROR_DISK_FULL
* will be set if no room in the MBR
*
*****************************************************************************/
BOOL WriteMBR(DriverState *state, SECTORNUM snSectorNum, SECTORNUM snNumSectors, BYTE fileSysType, BOOL bCreateMBR)
{
PBYTE buffer = NULL;
PPARTENTRY tmpbuffer, tmpbuffer1;
BOOL bResult;
int i, partIndex, partNum = -1;
// don't create the MBR, it already exists so use it
if (!bCreateMBR)
{
bResult = ReadSectors (state, 0, 1, &buffer);
if (!bResult)
return FALSE;
for (i = 0, partIndex = 0, tmpbuffer = (PPARTENTRY)(buffer + PARTTABLE_OFFSET); i < 4; i++, tmpbuffer++)
{
if (tmpbuffer->Part_TotalSectors == 0)
{
partNum = i;
break;
}
// find the index of the partition located just before this one
if (snSectorNum > tmpbuffer->Part_StartSector)
partIndex = i + 1;
}
if (partNum == -1)
{
// we return this error code so the caller can tell that there's no room in the MBR
LocalFree(buffer);
SetLastError(ERROR_DISK_FULL);
return FALSE;
}
// these indexes would be equal if we are adding to the end of the table
if (partIndex != partNum)
{
// this partition needs to be added in the order that it appears on the disk - so this may involve
// shifting some of the existing partition entries to open up the partition entry where this belongs
tmpbuffer = (PPARTENTRY)(buffer + PARTTABLE_OFFSET + (partNum * sizeof(PARTENTRY)));
tmpbuffer1 = (PPARTENTRY)(buffer + PARTTABLE_OFFSET + ((partNum -1) * sizeof(PARTENTRY)));