Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

编程去格式化存储卡(E盘)将会导致KErrInUse错误

From Wiki
Jump to: navigation, search
Article Metadata

测试基于
设备:: Nokia N95, Nokia N82

兼容于
平台: S60 3rd Edition FP1
S60 3rd Edition FP1

文章
翻译:
hoolee
最后由 hamishwillee 在 09 Aug 2012 编辑

详细描述

当我们使用RFormat这个API去格式化一个存储卡时在某些S60第三版FP1手机上会出现KErrInUse错误。这是因为一个程序可以需要经常访问存储卡。


如何重演

下列代码在N95和N82手机上将会导致KErrInUse错误

_LIT(KDriveE,"E:");
RFs fs;
User::LeaveIfError(fs.Connect());
RFormat format;
TInt tracksRemaining;
User::LeaveIfError(format.Open(fs,KDriveE,EHighDensity,tracksRemaining));
while (tracksRemaining)
{
User::LeaveIfError(format.Next(tracksRemaining));
}
format.Close();


解决方案

为了确保没有其他程序正在访问存储卡,我们需要在格式化前停顿一会(通常1秒左右)然后移除存储卡。

_LIT(KDriveE,"E:");
_LIT( KFSName, "Fat" );
RFs fs;
RFormat format;
TInt tracksRemaining;
TRequestStatus stat;
User::LeaveIfError(fs.Connect());
fs.NotifyDismount(EDriveE, stat, EFsDismountForceDismount);//Dismount the drive
User::WaitForRequest(stat);
User::After(1000000); //we have to wait until clients have received notification about card dismount
fs.MountFileSystem(KFSName,EDriveE);//Mount drive back in
User::LeaveIfError(format.Open(fs,KDriveE,EHighDensity,tracksRemaining));
while (tracksRemaining)
{
User::LeaveIfError(format.Next(tracksRemaining));
}
format.Close();
This page was last modified on 9 August 2012, at 05:28.
38 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×