存储发展促使WinCE需要一种管理不同文件系统的方法。管理这些文件系统的存储管理器,提供了一系列方法使应用程序可以管理文件系统和文件系统卷。
1.对象存储
2.使用文件API访问卷
CeGetVolumeInfo()获得卷的信息。
WINBASEAPI BOOL CeGetVolumeInfo( LPCSTR pszRootPath, CE_VOLUME_INFO_LEVEL InfoLevel, LPCE_VOLUME_INFO lpVolumeInfo );
Parameters
-
pszRootPath
- [in] Pointer to a string that contains the root directory of the volume to be described. InfoLevel
- [in] Type of information requested. Currently, this value can only be CeVolumeInfoLevelStandard. lpVolumeInfo
- [out] Pointer to a CE_VOLUME_INFO structure that retrieves information about the volume.
Return Values
Returns TRUE if successful, otherwise FALSE.
typedef struct _CE_VOLUME_INFO{ DWORD cbSize; DWORD dwAttributes; DWORD dwFlags; DWORD dwBlockSize; TCHAR szStoreName[STORENAMESIZE]; TCHAR szPartitionName[PARTITIONNAMESIZE]; } CE_VOLUME_INFO, *PCE_VOLUME_INFO, *LPCE_VOLUME_INFO;
Members
-
cbSize
- Set to sizeof(CE_VOLUME_INFO). dwAttributes
-
Specifies attributes of a volume.
The following table shows the possible values.
Value
DesriptionCE_VOLUME_ATTRIBUTE_READONLY
Volume is read only.CE_VOLUME_ATTRIBUTE_HIDDEN
Volume is hidden.CE_VOLUME_ATTRIBUTE_REMOVABLE
Volume is removable.CE_VOLUME_ATTRIBUTE_SYSTEM
Volume is marked as a system volume.CE_VOLUME_ATTRIBUTE_BOOT
Volume is the boot volume and contains the hive-based registry.
dwFlags
-
Specifies additional properties of a volume.
The following table shows the possible values.
Value
DescriptionCE_VOLUME_TRANSACTION_SAFE
Performs transaction-safe operations.CE_VOLUME_FLAG_TRANSACT_WRITE
Transacts WriteFile operation.CE_VOLUME_FLAG_WFSC_SUPPORTED
Supports WriteFileScatterGather and ReadFileScatterGather operations.CE_VOLUME_FLAG_LOCKFILE_SUPPORTED
Supports file locking.CE_VOLUME_FLAG_NETWORK
Specifies that the volume is a network volume.CE_VOLUME_FLAG_STORE
Specifies that the volume has a back-up store.
dwBlockSize
- Size of the block, in bytes. szStoreName
- Name of the store. Maximum length is 32. szPartitionName
- Name of the partition. Maximum length is 32.
3.存储管理器
存储管理器为应用程序提供了一个使用存储设备以及其分区的方法。可以打开并查询设备与分区,来获得大小、属性、和其他有用信息。
存储管理器也提供了重分区设备以及格式化设备、分区的功能。在格式化一个设备,或是在格式化分区,或是在设定分区类型时,格式化操作将会清除分区表。实际上在一个分区上放置一个文件系统的操作是由特定文件系统驱动来完成的。
1)打开、查询存储设备;要使用一个设备必须先打开它。OpenStore();一旦打开了,就可以使用GetStoreInfo()来查询设备信息。在调用之前,必须先设置好STOREINFO结构体中的cbSize字段。
BOOL WINAPI GetStoreInfo( HANDLE hStore, PSTOREINFO pStoreInfo );
Parameters
-
hStore
- [in] Handle to the store returned from OpenStore. pStoreInfo
-
[in, out] Pointer to a
STOREINFO (Storage Manager) structure.
This structure contains information about a store.
typedef struct { DWORD cbSize; TCHAR szDeviceName[DEVICENAMESIZE]; TCHAR szStoreName[STORENAMESIZE]; DWORD dwDeviceClass; DWORD dwDeviceType; STORAGEDEVICEINFO sdi; DWORD dwDeviceFlags; SECTORNUM snNumSectors; DWORD dwBytesPerSector; SECTORNUM snFreeSectors; SECTORNUM snBiggestPartCreatable; FILETIME ftCreated; FILETIME ftLastModified; DWORD dwAttributes; DWORD dwPartitionCount; DWORD dwMountCount; } STOREINFO, *PSTOREINFO;
Members
-
cbSize
- Set to sizeof(STOREINFO). szDeviceName
- Name of the device. Maximum length is 8. szStoreName
- Name of the store. Maximum length is 32. dwDeviceClass
-
Specifies the device class in the device descriptor.
These are the possible values.
- STORAGE_DEVICE_CLASS_BLOCK
- STORAGE_DEVICE_CLASS_MULTIMEDIA
dwDeviceType
-
Specifies the device type in the device descriptor.
These are the possible values:
- STORAGE_DEVICE_TYPE_PCIIDE
- STORAGE_DEVICE_TYPE_FLASH
- STORAGE_DEVICE_TYPE_ATA
- STORAGE_DEVICE_TYPE_ATAPI
- STORAGE_DEVICE_TYPE_PCCARD
- STORAGE_DEVICE_TYPE_CFCARD
- STORAGE_DEVICE_TYPE_SRAM
- STORAGE_DEVICE_TYPE_DVD
- STORAGE_DEVICE_TYPE_CDROM
- STORAGE_DEVICE_TYPE_USB
- STORAGE_DEVICE_TYPE_1394
- STORAGE_DEVICE_TYPE_DOC
- STORAGE_DEVICE_TYPE_UNKNOWN
- STORAGE_DEVICE_TYPE_REMOVABLE_DRIVE
- STORAGE_DEVICE_TYPE_REMOVABLE_MEDIA
sdi
- Specifies the device identifier in the device descriptor. dwDeviceFlags
-
Specifies additional properties of a store.
These are the possible values:
- STORAGE_DEVICE_FLAG_READWRITE
- STORAGE_DEVICE_FLAG_READONLY
- STORAGE_DEVICE_FLAG_TRANSACTED
- STORAGE_DEVICE_FLAG_MEDIASENSE
snNumSectors
- Number of sectors on the store. dwBytesPerSector
- Number of bytes per sector. snFreeSectors
- Number of unallocated sectors. snBiggestPartCreatable
- Biggest partition currently creatable. ftCreated
- Last time store was formatted. ftLastModified
- Last time partition table was modified. dwAttributes
-
Specifies attributes of a volume.
These are the store attributes:
- STORE_ATTRIBUTE_READONLY
- STORE_ATTRIBUTE_REMOVABLE
- STORE_ATTRIBUTE_UNFORMATTED
- STORE_ATTRIBUTE_AUTOFORMAT
- STORE_ATTRIBUTE_AUTOPART
- STORE_ATTRIBUTE_AUTOMOUNT
dwPartitionCount
- Number of Partitions. dwMountCount
- Number of partitions that have been mounted.
Requirements
OS Versions: Windows CE .NET 4.0 and later.
Header: Storemgr.h.2)枚举存储设备。要对一个存储设备使用GetStoreInfo函数,你必须首先打开这个设备;要打开它,必须先知道他的名字。了解系统中的存储设备的一个方法是使用下面的函数来枚举:
-
HANDLE FindFirstStore(PSTOREINFO pStoreInfo);在调用之前,必须先设置好STOREINFO结构体中的cbSize字段。如果该函数不是返回INVALID_HANDLE_VALUE,那么这个STOREINFO结构体就将包含找到的第一个存储设备的信息。要查找其他的存储设备,可以重复的调用下面这个函数:BOOL FindNextStore();最后要调用FindCloseStore()关闭句柄。
-
3)枚举分区;一般比较大的存储设备都会被分为几个区,每个分区以一个独立卷的形式挂载进系统。只要你知道分区名,就可以像打开设备一样的打开一个分区。然而在一个特殊的设备上使用下面函数来枚举分区往往更简单:
-
HANDLE FindFirstPartition(HANDLE hStore,PPARTINFO pPartInfo);
-
HANDLE WINAPI FindFirstPartition( HANDLE hStore, PPARTINFO pPartInfo );
Parameters
-
hStore
- [in] Handle to the store returned from OpenStore. 已经打开的句柄 pPartInfo
- [in, out] Pointer to a PARTINFO structure. 在调用前,必须将PARTINFO结构体中的cbSize字段设置成该结构体的大小。
Return Values
Returns a search handle if successful, otherwise returns INVALID_HANDLE_VALUE.
For extended error information, call GetLastError.
-
要枚举其他分区,只要重复的调用下面这个函数:
BOOL WINAPI FindNextPartition( HANDLE hSearch, PPARTINFO pPartInfo );
Parameters
-
hSearch
- [in] Search handle returned from FindFirstPartition. When the search handle is no longer needed, close it by using the FindClosePartition function. pPartInfo
- [in, out] Pointer to a PARTINFO structure.
Return Values
Returns TRUE if successful, otherwise FALSE.
-
This structure contains information about a partition.
typedef struct { DWORD cbSize; TCHAR szPartitionName[PARTITIONNAMESIZE]; TCHAR szFileSys[FILESYSNAMESIZE]; TCHAR szVolumeName[VOLUMENAMESIZE]; SECTORNUM snNumSectors; FILETIME ftCreated; FILETIME ftLastModified; DWORD dwAttributes; BYTE bPartType; } PARTINFO, *PPARTINFO;
Members
-
cbSize
- Set to sizeof(PARTINFO). szPartitionName
- Name of the partition. Maximum length is 32. szFileSys
- Name of the file system. Maximum length is 32. szVolumeName
- Name of the volume. This is the name that the partition has when mounted. You can use the volume name to correlate the mount points with partitions and stores. Mount points are subdirectories located under "/". snNumSectors
- Number of sectors in the partition. ftCreated
- Creation time of the partition. ftLastModified
- Last time the partition was modified. dwAttributes
-
Partition attributes.
These are the possible values:.
- PARTITION_ATTRIBUTE_EXPENDABLE
- PARTITION_ATTRIBUTE_READONLY
- PARTITION_ATTRIBUTE_BOOT
- PARTITION_ATTRIBUTE_AUTOFORMAT
- PARTITION_ATTRIBUTE_MOUNTED
bPartType
-
[in] The partition type or identifier. The byte limitation indicates that a specified partition format can only support 256 partition types. There are fewer file systems supported than partition types because a single file system can map to multiple partition types. Also, some partition types might have not have an associated file system.
Partition type
DescriptionPART_UNKNOWN
Unknown partition type.PART_DOS2_FAT
Legitimate DOS partition.PART_DOS3_FAT
Legitimate DOS partition.PART_DOS4_FAT
Legitimate DOS partition.PART_DOS32
Legitimate DOS partition (FAT32).PART_DOS32X13
Same as 0x0B only "use LBA".PART_DOSX13
Same as 0x06 only "use LBA".PART_DOSX13X
Same as 0x05 only "use LBA".INVALID
Invalid or unused partition type.
Requirements
OS Versions: Windows CE .NET 4.0 and later.
4)使用分区 -
使用CreatePartitionEx()创建分区。
This function creates the store.
BOOL WINAPI CreatePartitionEx( HANDLE hStore, LPCTSTR szPartitionName, BYTE bPartType, SECTORNUM snNumSectors );
Parameters
-
hStore
- [in] Handle to the store returned from OpenStore. 一个已经打开的句柄 szPartitionName
- [in] Name of the partition. bPartType
- [in] Type of partition. snNumSectors
- [in] 64-bit number indicating the size of the partition.
Return Values
Returns TRUE if successful, otherwise FALSE.
-
/////////////////////////////////////////////////////////////////////////////////////
-
删除分区用DeletePartition();在一个正在运行的系统上,一个带有FAT分区ID的分区会在启动或是插入存储设备时被自动挂载。要格式化一个分区或是删除一系列分区从而使得设备可以以不同于之前的大小重新分区,就必须首先将分区卸载。挂载/卸载分区可以使用下面的函数:
-
BOOL MountPartition(HANDLE hPartition);
-
BOOL DismountPartition(HANDLE hPartition);
-
两个参数都是由OpenPartition返回的句柄。
-
5)格式化卷;虽然有个FormatPartition函数,但它所做的只是清除分区的第一个扇区的数据。真正格式化一个分区,从而使分区可以存储数据,这是文件系统驱动程序的任务。
-
This function formats a volume according to the options specified.
DWORD FormatVolume( HANDLE hVolume, PDISK_INFO pdi, PFORMAT_OPTIONS pfo, PFN_PROGRESS pfnProgress, PFN_PROGRESS pfnMessage );
Parameters
-
hVolume
- [in] Handle to disk or partition. Call CreateFile to obtain a handle to the volume. pdi
- [in] Not used. /////////////////////////////////////////////////////////////////////// pfo
-
[in] Pointer to a
FORMAT_OPTIONS structure. The following fields can be specified.
Member
Description -
dwClusSize
Desired cluster size in bytes, which must be power of 2.dwRootEntries
Desired number of root directory entries.dwFatVersion
FAT Version, either 12, 16, or 32.dwNumFats
Number of FATs to create.fFullFormat
TRUE if full format requested.//////////////////////////////////////////////////////////////////
pfnProgress
- [in] Callback function indicating progress. pfnMessage
- [in] Callback function used to display a message to user. 该回调函数将在格式化期间出错时被调用
Return Values
If the function succeeds, the return value is ERROR_SUCCESS. If it fails, the return valid is ERROR_GEN_FAILURE.
Remarks
For best results, use the correct type of handle. For example, if the store to be scanned is partitioned, use a handle to the partition. If the store is not partitioned, use a disk handle.
-
This structure contains options specified by clients of format disk.
-
//////////////////////////////////////////
typedef struct _FORMAT_OPTIONS { DWORD dwClusSize; DWORD dwRootEntries; DWORD dwFatVersion; DWORD dwNumFats; DWORD dwFlags; } FORMAT_OPTIONS;
Members
-
dwClusSize
- Desired cluster size in bytes, must be power of 2. dwRootEntries
- Desired number of root directory entries dwFatVersion
- FAT Version. Either 12, 16, or 32. dwNumFats
- Number of FATs to create.
- ////////////////////////////////////////////// dwFlags
-
This member may be set to one or a combination of possible values. The following table shows the possible values for
dwFlags.
Value
DescriptionFATUTIL_FULL_FORMAT
Performs a full format on a volume.FATUTIL_FORMAT_TFAT
Formats a volume as TFAT.FATUTIL_DISABLE_MOUNT_CHK
Disables checking to see if a volume is mounted prior to performing an operation. -
//////////////////////////////////////////////////////
Technorati 标签: 存储管理器
Requirements
OS Versions: Windows CE .NET 4.0 and later.
Header: Formatdisk.h.
这个函数会向用户展示一个对话框,通过对话框用户可以选择格式化参数。
This function formats a volume according to the options specified. It contains a dialog box user interface that can be displayed standalone or invoked from another place such as a control panel window.
VOID FormatVolumeUI( HANDLE hVolume, HWND hWnd );
Parameters
-
hVolume
- [in] Handle to disk or partition. Call CreateFile to obtain a handle to the volume. hWnd
- [in] Handle to parent window. Can be NULL if there is no parent.