1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\include\d32locd.h
21 #include <partitions.h>
30 A media ID is passed to LocDrv::RegisterMediaDevice() when registering
31 a media driver with the local media subsystem.
33 enum TMediaDevice { EFixedMedia0, EFixedMedia1, EFixedMedia2, EFixedMedia3,
34 EFixedMedia4, EFixedMedia5, EFixedMedia6, EFixedMedia7,
35 ERemovableMedia0, ERemovableMedia1, ERemovableMedia2, ERemovableMedia3,
39 #define __IS_REMOVABLE(aDevice) (aDevice>=ERemovableMedia0 && aDevice<=ERemovableMedia3)
40 #define __IS_FIXED(aDevice) ((TUint)aDevice<=EFixedMedia7)
41 #define MEDIA_DEVICE_IRAM EFixedMedia0
42 #define MEDIA_DEVICE_LFFS EFixedMedia1
43 #define MEDIA_DEVICE_NAND EFixedMedia2
44 #define MEDIA_DEVICE_MMC ERemovableMedia0
45 #define MEDIA_DEVICE_PCCARD ERemovableMedia1
46 #define MEDIA_DEVICE_CSA ERemovableMedia2
48 typedef signed int TSocket;
50 class TLDriveAssignInfo
62 class TMediaDeviceAssignInfo
76 Drives media capabilities fields
83 IMPORT_C TLocalDriveCaps();
88 Note : This is the size of the partition, not the entire media.
89 The entire media size can be obtained from TLocalDriveCapsV4::MediaSizeInBytes()
97 Indicates state of battery if supported
99 TBatteryState iBattery;
101 Attributes of the drive
105 Attributes of underlying media
109 Base address of media
111 TUint8* iBaseAddress;
113 Identity of the file system used for this media
115 TUint16 iFileSystemId;
117 Partition type of media
119 TUint16 iPartitionType;
121 typedef TPckgBuf<TLocalDriveCaps> TLocalDriveCapsBuf;
123 class TLocalDriveCapsV2 : public TLocalDriveCaps
125 Extension to Capabilities fields mainly to support Nor flash
133 Number of hidden sectors on drive
135 TUint iHiddenSectors;
137 Size of erase unit on media
139 TUint iEraseBlockSize;
141 typedef TPckgBuf<TLocalDriveCapsV2> TLocalDriveCapsV2Buf;
147 Format specification for removable media
155 inline TLDFormatInfo();
158 TInt64 iCapacity; ///< Format Capacity
159 TUint16 iSectorsPerCluster; ///< Specified sectors per cluster
160 TUint16 iSectorsPerTrack; ///< Specified sectors per track
161 TUint16 iNumberOfSides; ///< Specified number of sides
163 enum TFATBits {EFBDontCare, EFB12 = 12, EFB16 = 16, EFB32 = 32};
164 TFATBits iFATBits; ///< Specified bits per fat table entry
166 TUint16 iReservedSectors; ///< Reserved sector count, required for SD card compliance
168 // Flags field. Allows the number of FAT tables to be specified: set both bits to zero to use the default.
169 enum TFlags {EOneFatTable = 0x01, ETwoFatTables = 0x02};
172 TUint8 iPad; ///< Padding for offset alignment between kernel and user code
175 typedef TPckgBuf<TLDFormatInfo> TSpecialFormatInfoBuf;
179 class TLocalDriveCapsV3 : public TLocalDriveCapsV2
181 Extension to Capabilities fields mainly to support removable media format specifications
191 TLDFormatInfo iFormatInfo;
193 Set if iFormatInfo is valid
198 TInt iMaxBytesPerFormat;
200 //The following ASSERTs checks for offset of any TInt64 member be a multiple of 8 as per DEF045510
201 __ASSERT_COMPILE(_FOFF(TLocalDriveCaps,iSize)%8 == 0);
202 __ASSERT_COMPILE(_FOFF(TLocalDriveCapsV3,iFormatInfo.iCapacity) % 8 == 0);
205 typedef TPckgBuf<TLocalDriveCapsV3> TLocalDriveCapsV3Buf;
207 class TLocalDriveCapsV4 : public TLocalDriveCapsV3
209 Extension to Capabilities fields mainly to support Nand flash
219 Number of blocks (for NAND flash)
220 - The entire capacity of NAND media can be calculated using:
221 capacity = iNumOfBlocks * iNumPagesPerBlock * iNumBytesMain
225 Number of sectors (for other types of media)
226 - The entire capacity of sector based media can be calculated using:
227 capacity = iNumberOfSectors * iSectorSizeInBytes
229 TUint32 iNumberOfSectors;
233 Number of pages per block
235 TInt iNumPagesPerBlock;
240 Number of Bytes in the main array (for NAND flash)
241 - The entire capacity of NAND media can be calculated using:
242 capacity = iNumOfBlocks * iNumPagesPerBlock * iNumBytesMain
246 Number of Bytes in a sector (for other types of media)
247 - The entire capacity of sector based media can be calculated using:
248 capacity = iNumberOfSectors * iSectorSizeInBytes
250 TUint32 iSectorSizeInBytes;
254 Number of Bytes in the spare array
258 Effective usable blocks
266 inline TInt64 MediaSizeInBytes();
268 typedef TPckgBuf<TLocalDriveCapsV4> TLocalDriveCapsV4Buf;
270 #define KMaxSerialNumLength 64
271 typedef TBuf8<KMaxSerialNumLength> TMediaSerialNumber;
272 class TLocalDriveCapsV5 : public TLocalDriveCapsV4
274 Add serial number support for certain media.
282 Serial number buffer length, 0 if not supported
284 TUint iSerialNumLength;
288 TUint8 iSerialNum[KMaxSerialNumLength];
290 typedef TPckgBuf<TLocalDriveCapsV5> TLocalDriveCapsV5Buf;
293 class TLocalDriveCapsV7 : public TLocalDriveCapsV5
295 Add control mode, object mode, partition size for M18 NOR Flash.
299 TUint32 iWriteBufferSize;
300 TUint32 iPartitionSize;
301 TUint32 iControlModeSize;
302 TUint32 iObjectModeSize;
305 typedef TPckgBuf<TLocalDriveCapsV7> TLocalDriveCapsV7Buf;
310 Extension to Capabilities fields mainly to support reporting block size
311 information of underlying media.
316 class TLocalDriveCapsV6 : public TLocalDriveCapsV5
320 Block size information of underlying media is required to assist in chosing
321 efficient size of buffers for reading and writing.
322 This information can also be accessed through the function
325 These functions retrieve this blocksize information by calling the media
326 driver's Caps() function.
332 Reserved space for future use.
336 typedef TPckgBuf<TLocalDriveCapsV6> TLocalDriveCapsV6Buf;
340 Format information class
347 IMPORT_C TFormatInfo();
349 TBool iFormatIsCurrent;
350 TInt i512ByteSectorsFormatted;
351 TInt iMaxBytesPerFormat;
362 ENoError=0, //No error
363 EBadSector=1, //Error due to corrupt sector
366 TReasonCode iReasonCode;
369 // holds position error occurred for KErrCorrupt
370 // It numerically equals number of bytes succesfully read/written during
371 // last disk operation.
376 typedef TPckgBuf<TErrorInfo> TErrorInfoBuf;
378 class TLocalDriveMessageData
384 inline TLocalDriveMessageData()
386 inline TLocalDriveMessageData(TInt64 aPos, TInt aLength, const TAny* aPtr, TInt aHandle, TInt anOffset, TInt aFlags)
387 : iPos(aPos), iLength(aLength), iPtr(aPtr), iHandle(aHandle), iOffset(anOffset), iFlags(aFlags)
398 class TLocalDriveControlIOData
400 Control IO data class
406 inline TLocalDriveControlIOData()
408 inline TLocalDriveControlIOData(TInt aCommand, TAny* aParam1, TAny* aParam2, TInt aHandle)
409 : iCommand(aCommand), iParam1(aParam1), iParam2(aParam2), iHandle(aHandle)
418 class TLocalDrivePasswordData
420 Password store for password protected media
426 TLocalDrivePasswordData(const TDesC8& aOldPasswd, const TDesC8& aNewPasswd, TBool aStorePasswd)
427 : iOldPasswd(&aOldPasswd), iNewPasswd(&aNewPasswd), iStorePasswd(aStorePasswd)
429 TLocalDrivePasswordData()
430 : iOldPasswd(&KNullDesC8), iNewPasswd(&KNullDesC8), iStorePasswd(EFalse)
433 const TDesC8 *iOldPasswd;
434 const TDesC8 *iNewPasswd;
437 typedef TPckgBuf<TLocalDrivePasswordData> TLocalDrivePasswordDataPckg;
446 virtual TInt Init()=0;
447 virtual TInt ReadPasswordData(TDes8 &aBuf)=0;
448 virtual TInt WritePasswordData(TDesC8 &aBuf)=0;
449 virtual TInt PasswordStoreLengthInBytes()=0;
450 enum {EMaxPasswordLength=1024}; /**< Size of the password store write buffer, which may contain multiple password mappings */
464 const TInt KLocalDriveMajorVersion=1;
465 const TInt KLocalDriveMinorVersion=0;
466 const TInt KLocalDriveBuildVersion=160;
467 _LIT(KLitLocalDriveLddName,"LocDrv");
469 const TInt KLocalMessageHandle=-1;
472 enum TMediaPagingStats
474 EMediaPagingStatsRomAndCode,
475 EMediaPagingStatsRom,
476 EMediaPagingStatsCode
480 class RLocalDrive : public RBusLogicalChannel
482 Interface class to local media
490 EControlRead=0, /**< Read request */
491 EControlWrite=1, /**< Write request */
492 EControlCaps=2, /**< Caps request */
493 EControlFormat=3, /**< Format request */
494 EControlEnlarge=4, /**< Enlarge drive request */
495 EControlReduce=5, /**< Reduce Drive request */
496 EControlForceMediaChange=6, /**< Force media change request */
497 EControlMediaDevice=7, /**< Return the media device request */
498 EControlPasswordLock=8, /**< Password lock media request */
499 EControlPasswordUnlock=9, /**< Password unlock media request */
500 EControlPasswordClear=10, /**< Password clear request */
501 EControlNotifyChange=11, /**< Notify change request */
502 EControlNotifyChangeCancel=12, /**< Notify change cancel request */
503 EControlReadPasswordStore=13, /**< Read password request */
504 EControlWritePasswordStore=14, /**< Write password request */
505 EControlPasswordStoreLengthInBytes=15, /**< Password request */
506 EControlIsRemovable=16, /**< Query removable request */
507 EControlSetMountInfo=17, /**< Set mount info request */
508 EControlControlIO=18, /**< Control IO request */
509 EControlPasswordErase=19, /**< Password erase media request */
510 EControlDeleteNotify=20, /**< Delete notification */
511 EControlGetLastErrorInfo=21, /**< Get last error info request */
516 ELocDrvRemountNotifyChange = 0, /**< Notify clients of media change but don't remount */
517 ELocDrvRemountForceMediaChange = 1, /**< Notify clients of media change and remount */
522 ELocDrvMetaData = 0x80000000, /**< Set if read/write request is for metadata */
523 ELocDrvWholeMedia = 0x40000000 /**< Set to access whole media, rather than partition */
527 inline TVersion VersionRequired() const;
528 inline TInt Connect(TInt aDriveNumber, TBool& aChangedFlag);
529 inline TInt Enlarge(TInt aLength);
530 inline TInt Reduce(TInt aPos, TInt aLength);
531 inline TInt Read(TInt64 aPos, TInt aLength, const TAny* aTrg, TInt aMessageHandle, TInt aOffset, TInt aFlags);
532 inline TInt Read(TInt64 aPos, TInt aLength, const TAny* aTrg, TInt aMessageHandle, TInt anOffset);
533 inline TInt Read(TInt64 aPos, TInt aLength, TDes8& aTrg);
534 inline TInt Write(TInt64 aPos, TInt aLength, const TAny* aSrc, TInt aMessageHandle, TInt aOffset, TInt aFlags);
535 inline TInt Write(TInt64 aPos, TInt aLength, const TAny* aSrc, TInt aMessageHandle, TInt anOffset);
536 inline TInt Write(TInt64 aPos, const TDesC8& aSrc);
537 inline TInt Caps(TDes8& anInfo);
538 inline TInt Format(TInt64 aPos, TInt aLength);
539 inline TInt ForceMediaChange(TInt aMode=0);
540 inline void NotifyChange(TRequestStatus* aStatus);
541 inline void NotifyChangeCancel();
542 inline TInt SetMountInfo(const TDesC8* aInfo,TInt aMessageHandle);
543 inline TMediaDevice MediaDevice();
544 inline TInt IsRemovable(TInt& aSocketNum);
545 inline TInt ControlIO(TInt aCommand, TAny* aParam1, TAny* aParam2);
546 inline TInt Unlock(const TDesC8& aPassword, TBool aStorePassword);
547 inline TInt SetPassword(const TDesC8& aOldPassword, const TDesC8& aNewPassword, TBool aStorePassword);
548 inline TInt Clear(const TDesC8& aPassword);
549 inline TInt ErasePassword();
550 inline TInt ReadPasswordData(TDesC8& aStoreData);
551 inline TInt WritePasswordData(const TDesC8& aStoreData);
552 inline TInt PasswordStoreLengthInBytes();
553 inline TInt DeleteNotify(TInt64 aPos, TInt aLength);
554 inline TInt GetLastErrorInfo(TDesC8& aErrorInfo);
557 #ifndef __KERNEL_MODE__
558 class TBusLocalDrive : public RLocalDrive
564 IMPORT_C TBusLocalDrive();
565 IMPORT_C TInt Connect(TInt aDriveNumber, TBool& aChangedFlag);
566 IMPORT_C void Disconnect();
567 IMPORT_C TInt Enlarge(TInt aLength);
568 IMPORT_C TInt ReduceSize(TInt aPos, TInt aLength);
569 IMPORT_C TInt Read(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt aMessageHandle,TInt aOffset,TInt aFlags);
570 IMPORT_C TInt Read(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt aMessageHandle,TInt anOffset);
571 IMPORT_C TInt Read(TInt64 aPos,TInt aLength,TDes8& aTrg);
572 IMPORT_C TInt Write(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt aMessageHandle,TInt aOffset,TInt aFlags);
573 IMPORT_C TInt Write(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt aMessageHandle,TInt anOffset);
574 IMPORT_C TInt Write(TInt64 aPos,const TDesC8& aSrc);
575 IMPORT_C TInt Caps(TDes8& anInfo);
576 IMPORT_C TInt Format(TFormatInfo& anInfo);
577 IMPORT_C TInt Format(TInt64 aPos,TInt aLength);
578 IMPORT_C TInt SetMountInfo(const TDesC8* aMountInfo,TInt aMessageHandle);
579 IMPORT_C TInt ForceRemount(TUint aFlags=0);
580 IMPORT_C TInt ControlIO(TInt aCommand, TAny* aParam1, TAny* aParam2);
582 IMPORT_C TInt Unlock(const TDesC8& aPassword, TBool aStorePassword);
583 IMPORT_C TInt SetPassword(const TDesC8& aOldPassword, const TDesC8& aNewPassword, TBool aStorePassword);
584 IMPORT_C TInt Clear(const TDesC8& aPassword);
585 IMPORT_C TInt ErasePassword();
586 IMPORT_C TInt ReadPasswordData(TDes8 &aBuf);
587 IMPORT_C TInt WritePasswordData(const TDesC8 &aBuf);
588 IMPORT_C TInt PasswordStoreLengthInBytes();
589 IMPORT_C TInt DeleteNotify(TInt64 aPos, TInt aLength);
590 IMPORT_C TInt GetLastErrorInfo(TDes8& aErrorInfo);
592 inline TInt& Status() {return(iStatus);}
600 #define _LOCKABLE_MEDIA
602 #include <d32locd.inl>