Archived:Programmatic formatting of the memory card (E:) fails with KErrInUse (Known Issue)
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.
Formatting a memory card using RFormat API's Format function fails with KErrInUse in some S60 3rd Edition, FP1 devices. The reason for this could be an application constantly trying to access the memory card.
Article Metadata
Tested with
Devices(s): Nokia N95, Nokia N82
Compatibility
Platform(s): S60 3rd Editon FP1
Article
Created: User:Technical writer 1
(03 Sep 2008)
Last edited: hamishwillee
(19 Jun 2012)
How to reproduce
The following code fails in the Nokia N95 and the Nokia N82 with 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();
Solution
To ensure that no other application is accessing the memory card, dismount the memory card and remount it after a while (1 second) before formatting it.
_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();


(no comments yet)