wince 快速挂载SD卡及U盘

1、起初我的wince bsp 在插入8G u盘时需要等待大概40秒左右才出现盘符,这个速度简直无法忍受。
 
2、经过分析,发现比较耗时的是位于文件 C:\WINCE500\PUBLIC\COMMON\OAK\DRIVERS\FSD\FATUTIL\MAIN\scandisk.cpp内的 ScanVolumeInternal 函数
,这个函数是用来扫描文件系统的,如果能够去掉插入sd卡或U盘时不自动扫描则可以大大缩短出现盘符的时间。
 
3、经过分析发现这个是有FATFS相关注册表进行控制的
 

[HKEY_LOCAL_MACHINE\System\StorageManager\FATFS]

"MountFlags"=dword:0 ;

"Flags"=dword:14 ;


具体的控制是Flags项,这个分支定义的是整个FATFS的参数,如果想进行分类进行不同的定义,则需要修改相关注册表分支,例如,想定义flash自动扫描则添加定义如下

[HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\FlashDrv\FATFS]

"MountFlags"=dword:2

"Flags"=dword:10

;在Profiles\FlashDrv添加FATFS分支定义falsh上FATFS文件系统的相关参数,其他的sd卡,U盘等也可分别进行定义


以上两个分支可同时存在,进行详细的的定义。

关于FATFS相关参赛的定义如下:(http://msdn.microsoft.com/en-us/library/ms885403.aspx

Platform Builder for Microsoft Windows CE 5.0
FAT File System Registry Settings

The file allocation table (FAT) file system retrieves driver specific settings from the registry.

The following table shows the registry settings for the FAT file system stored in HKEY_LOCAL_MACHINE\System\StorageManager\FATFS.

Registry value: TypeDescription
BufferSize: REG_DWORDSpecifies the number of sector-sized buffers to use for streams.

The default value is 64 for TFAT and 32 for FAT.

CacheSize: REG_DWORDIndicates the size of the disk cache, in number of sectors. This value must be a power of 2 and at least 16 sectors. If set to zero, FATFS will determine the best cache size to use.

For more information, see CacheSize registry subkey.

CodePage: REG_DWORDOverrides CP_OEMCP in all character conversions.
Dll: REG_SZSpecifies the name of the file system DLL.
EnableCache: REG_DWORDControls caching.
  • 0 - Disables caching
  • 1 - Enables caching
EnableCacheWarm: REG_DWORDEnables pre-warming of the cache.
Flags: REG_DWORDIndicates FAT file system registry flags.

For more information, see Flags registry subkey.

FormatTfat: REG_DWORDFormats the volume as TFAT on auto-format or through IOCTL_DISK_FORMAT_VOLUME.
FriendlyName: REG_SZSpecifies a friendly name for the file system.
MountLabel: REG_DWORDPulls the volume label and uses it as a mount point.
Paging: REG_DWORDControls paging.
  • 0 - Disables paging
  • 1 - Enables paging
Util: REG_SZSpecifies the DLL name of utility to do format and scan.

Flags registry subkey

The following table shows the available values you can set for the Flags registry subkey; set Flags to a combination of these values.

FlagValueDescription
FATFS_UPDATE_ACCESS0x00000001Updates access times.
FATFS_DISABLE_LOG0x00000002Disables event logging.
FATFS_DISABLE_AUTOSCAN0x00000004Disables automatic calls to ScanVolume.
FATFS_VERIFY_WRITES0x00000008Verifies all writes.
FATFS_ENABLE_BACKUP_FAT0x00000010Adds a backup FAT to all formats.
FATFS_FORCE_WRITETHROUGH0x00000020Sets all files to WRITE_THROUGH, regardless of the parameters to CreateFile.
FATFS_DISABLE_AUTOFORMAT0x00000040Disables automatic formatting of unformatted volumes.
FATFS_WFWS_NOWRITETHRU0x00010000Disables write through on the WriteFileWithSeek function. Improves memory-mapped file performance.
FATFS_DISABLE_FORMAT0x00020000Disables format.
FATFS_TRANS_DATA0x00040000Transacts data on a write operation.
FATFS_TFAT_USECLUS10x00080000Uses the cluster 1 entry in the FAT table for a TFAT transaction. TFAT uses the NOF field of the boot sector by default.
FATFS_DISABLE_TFAT_REDIR0x00100000Disables the redirect of the root directory to another hidden directory for FAT12 or 16.
FATFS_TFAT_ALWAYS0x00200000Marks transaction status, even if only one sector in FAT is changed.
FATFS_FORCE_TFAT0x00400000Forces TFAT transactions even if the volume is not formatted as TFAT.

CacheSize registry subkey

The CacheSize registry subkey is a hexadecimal number of sectors to cache. This has to be a power of two. The following table shows valid numbers for theCacheSize registry subkey.

Registry entryNumber of sectorsCache in kilobytes (KB)
221
442
884
10168
201632
406432
8012864
100256128
200512256
4001024512
80020481024
10004096

2048

Example

The following registry key example shows the location of the Flags and CacheSize registry subkey values.

Copy Code
[HKEY_LOCAL_MACHINE\System\StorageManager\FATFS]
    "Flags": dword:00000024
    "CacheSize" = dword:400

If CacheSize is set to zero, the cache size will be set automatically.

 

http://www.vckbase.com/document/viewdoc/?id=1267

对”Flags”值的描述如下(C:\WINCE500\PRIVATE\WINCEOS\COREOS\FSD\FATFS\fatfs.h): 
 

标志 描述
FATFS_UPDATE_ACCESS0x00000001更新访问时间
FATFS_DISABLE_AUTOSCAN0x00000004不能自动调用ScanVolume
FATFS_VERIFY_WRITES0x00000008检验所有写操作
FATFS_ENABLE_BACKUP_FAT0x00000010备份FAT表
FATFS_FORCE_WRITETHROUGH0x00000020让系统可以直接将任何缓冲区中的数据写到磁盘上,这样系统将加快写数据到磁盘的速度
FATFS_DISABLE_AUTOFORMAT0x00000040禁止自动格式化未格式化的分区
FATFS_DISABLE_COMPCHECK0x00000080禁止自动检测压缩分区

上面把FLAGS定义为 14,也就是备份FAT表、不自动扫描卷标。这样8G的SD卡,3秒就可以出现盘符了。

 

原创文章,转载请注明:转载自 风雨无阻博客(http://Apollo5520.cublog.cn

本文链接地址:http://blog.chinaunix.net/u3/105764/showart_2114352.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值