Hello to all,
I am working in winCE 5.0. The BSP is SMDK2440. I want to create partition
at run time By the API CreatePartition() function.Can any body tell me that
what will be the entry point to call the CreatePartation() function, if there
is no already partition exists.
Thanx

--
Message posted via PocketPCJunkies.com
http://www.pocketpcjunkies.com/Uwe/Forums.aspx/wince-pb/200805/1

Re: Create partition at Run Time by Michel

Michel
Mon May 05 01:47:44 PDT 2008

What exactly do you mean with "the entry point to call"?

Here's an example on how to create a partition on a disk:

#include <storemgr.h>
#include <fatutil.h>


HINSTANCE hLib = LoadLibrary(L"fatutil.dll");
if( !hLib )
{
wprintf(L"ERR: Can't find fatutil.dll!\r\n");
return 0;
}
PFN_FORMATVOLUME pFormatVolume =
(PFN_FORMATVOLUME)GetProcAddress(hLib, L"FormatVolume");
if( !pFormatVolume )
{
wprintf(L"ERR: Can't find function FormatVolume in
fatutil.dll!\r\n");
FreeLibrary(hLib);
return 0;
}

STOREINFO StoreInfo;
StoreInfo.cbSize = sizeof StoreInfo;
HANDLE hSearch = FindFirstStore(&StoreInfo);

if( INVALID_HANDLE_VALUE == hSearch )
{
wprintf(L"ERR: Could not find any disk!\r\n");
return 0;
}
FindCloseStore(hSearch);

HANDLE hStore = OpenStore( StoreInfo.szDeviceName );
if( INVALID_HANDLE_VALUE == hStore )
{
wprintf(L"ERR: Can't open disk \"%s\"!\r\n",
StoreInfo.szDeviceName);
return 0;
}

DismountStore(hStore);

FormatStore(hStore);

if( !GetStoreInfo(hStore, &StoreInfo) )
{
wprintf(L"ERR: Could not get information for disk \"%s\".\r\n",
StoreInfo.szDeviceName);
return 0;
}

// Calculate nr of sectors for 40MB partition
SECTORNUM Sectors = 40*1024*1024 / StoreInfo.dwBytesPerSector;
if( (Sectors > StoreInfo.snNumSectors )
{
wprintf(L"ERR: Disk \"%s\" is too small!\r\n",
StoreInfo.szDeviceName);
return 0;
}

wprintf(L"Creating partition (%.2fMB) \"Part00\" on disk
\"%s\".\r\n", (Sectors * StoreInfo.dwBytesPerSector) / (1024 * 1024.0),
StoreInfo.szDeviceName);
// Create the partition
if( !CreatePartitionEx(hStore, L"Part00", PART_DOS4_FAT, DataSectors) )
{
wprintf(L"ERR: Could not create partition on disk \"%s\", err
%d.\r\n", StoreInfo.szDeviceName, GetLastError());
return 0;
}

HANDLE hPart = OpenPartition(hStore, L"Part00");
if( INVALID_HANDLE_VALUE != hPart )
{
DismountPartition(hPart);

wprintf(L"Formatting partition: ");
DWORD dwErr = pFormatVolume(hPart, NULL, NULL, FormatPgs,
FormatMsg);
BOOL bRet = (ERROR_SUCCESS == dwErr);
if( bRet )
{
wprintf(L": SUCCESS!\r\n");
wprintf(L"Mounting partition: ");
bRet = MountPartition(hPart);
if( bRet )
wprintf(L"SUCCESS!\r\n");
else
wprintf(L"FAILED! (Err %d)\r\n", dwErr);
}
else
{
wprintf(L": FAILED! (Err %d)\r\n", GetLastError());
}
CloseHandle(hPart);
}

CloseHandle(hStore);


// Functions for the pFormatVolume callbacks:

BOOL FormatMsg(LPTSTR szMessage, LPTSTR szCaption, BOOL fYesNo)
{
wprintf(L"\r\n%s: %s", szCaption, szMessage);
if( fYesNo )
{
wprintf(L" (Y)es or (N)o? ");
WCHAR c = getwchar();
if( (L'Y' == c) || (L'y' == c) )
return TRUE;
else
return FALSE;
}
wprintf(L"\r\n");
return TRUE;
}

VOID FormatPgs(DWORD dwPercent)
{
static DWORD dwOldPerc = 0;

if( dwOldPerc != dwPercent )
{
dwOldPerc = dwPercent;
wprintf(L" %d%%", dwPercent);
}
}




Good luck,

Michel Verhagen, eMVP
Check out my blog: http://GuruCE.com/blog

GuruCE Ltd.
Microsoft Embedded Partner
http://GuruCE.com
Consultancy, training and development services.

shinewine via PocketPCJunkies.com wrote:
> Hello to all,
> I am working in winCE 5.0. The BSP is SMDK2440. I want to create partition
> at run time By the API CreatePartition() function.Can any body tell me that
> what will be the entry point to call the CreatePartation() function, if there
> is no already partition exists.
> Thanx
>

RE: Create partition at Run Time by Rob

Rob
Mon May 05 04:02:00 PDT 2008

See storage manager functions.
Try FindFirstStore etc....

ms-help://MS.VSCC.v80/MS.VSIPCC.v80/MS.WindowsCE.v60.en/CE_OS_FileSys/html/d23f827c-8809-42de-b5f6-326c21ec2f53.htm

Greetings,
Rob.




"shinewine via PocketPCJunkies.com" wrote:

> Hello to all,
> I am working in winCE 5.0. The BSP is SMDK2440. I want to create partition
> at run time By the API CreatePartition() function.Can any body tell me that
> what will be the entry point to call the CreatePartation() function, if there
> is no already partition exists.
> Thanx
>
> --
> Message posted via PocketPCJunkies.com
> http://www.pocketpcjunkies.com/Uwe/Forums.aspx/wince-pb/200805/1
>
>