userlibandfileserver/fileserver/sfsrv/cl_fraw.cpp
changeset 9 96e5fb8b040d
equal deleted inserted replaced
-1:000000000000 9:96e5fb8b040d
       
     1 // Copyright (c) 1996-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 "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // f32\sfsrv\cl_fraw.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "cl_std.h"
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 /**
       
    24 Opens a direct access channel to the disk.
       
    25 
       
    26 Other resources are disabled from accessing the disk until Close() is called.
       
    27 
       
    28 Note that if any resources are currently open on the disk, an error
       
    29 is returned.
       
    30 
       
    31 @param aFs    The file server session.
       
    32 @param aDrive The drive containing the disk to be accessed. Specify a drive
       
    33               in the range EDriveA to EDriveZ for drives A to Z.
       
    34 
       
    35 @return KErrNone, if successful;
       
    36         KErrInUse is returned if any resources are currently open on the disk;
       
    37         otherwise one of the other system-wide error codes.
       
    38 
       
    39 @capability TCB
       
    40 
       
    41 */
       
    42 EXPORT_C TInt RRawDisk::Open(RFs& aFs,TInt aDrive)
       
    43 	{
       
    44 	if (!RFs::IsValidDrive(aDrive))
       
    45 		return(KErrArgument);
       
    46 	iDrive=aDrive;
       
    47 	return(CreateSubSession(aFs,EFsRawDiskOpen,TIpcArgs(aDrive)));
       
    48 	}
       
    49 
       
    50 
       
    51 
       
    52 
       
    53 /**
       
    54 Closes the direct access channel to the disk, and allows other resources
       
    55 to access the disk.
       
    56 */
       
    57 EXPORT_C void RRawDisk::Close()
       
    58 	{
       
    59 	CloseSubSession(EFsRawSubClose);
       
    60 	}
       
    61 
       
    62 
       
    63 
       
    64 
       
    65 /**
       
    66 Reads directly from the disk.
       
    67 
       
    68 The function reads a number of bytes into the specified descriptor from
       
    69 the disk, beginning at the specified position.
       
    70 
       
    71 @param aPos The position on the disk at which to begin reading.
       
    72 @param aDes The descriptor into which data is to be read. 
       
    73             On return aDes contains the data read.
       
    74 
       
    75 @panic User In debug builds, the media driver panics if aPos is larger than 
       
    76             the size of the physical media or if the end address, given by 
       
    77             aPos + the maximum length of the descriptor, is greater than 
       
    78             the size of the physical media.
       
    79 
       
    80 @return KErrNone, if successful, otherwise one of the other system-wide error
       
    81         codes.
       
    82 
       
    83 @capability TCB
       
    84 
       
    85 */
       
    86 EXPORT_C TInt RRawDisk::Read(TInt64 aPos,TDes8& aDes)
       
    87 	{
       
    88 	TInt maxLength = aDes.MaxLength();
       
    89 	if (maxLength==0)
       
    90 		return(KErrNone);
       
    91 	TPtrC8 tBuf((TUint8*)&aPos,sizeof(TInt64));
       
    92 	return(SendReceive(EFsRawDiskRead,TIpcArgs(&aDes,maxLength,&tBuf)));
       
    93 	}
       
    94 
       
    95 
       
    96 
       
    97 
       
    98 /**
       
    99 Writes directly to the disk.
       
   100 
       
   101 The function writes the contents of the specified descriptor to the 
       
   102 disk at position aPos.
       
   103 
       
   104 @param aPos The position at which to begin writing.
       
   105 @param aDes The descriptor containing the data to be written to the disk.
       
   106 
       
   107 @panic User In debug builds, the media driver panics if aPos is larger than 
       
   108             the size of the physical media or if the end address, given by 
       
   109             aPos + the maximum length of the descriptor, is greater than 
       
   110             the size of the physical media.
       
   111 
       
   112 @return KErrNone, if successful, otherwise one of the other system-wide error
       
   113         codes.
       
   114 
       
   115 @capability TCB
       
   116 
       
   117 */
       
   118 EXPORT_C TInt RRawDisk::Write(TInt64 aPos,TDesC8& aDes)
       
   119 	{
       
   120 	TInt length = aDes.Length();
       
   121 	if (length==0)
       
   122 		return(KErrNone);
       
   123 	TPtrC8 tBuf((TUint8*)&aPos,sizeof(TInt64));
       
   124 	return(SendReceive(EFsRawDiskWrite,TIpcArgs(&aDes,length,&tBuf)));
       
   125 	}
       
   126 
       
   127 
       
   128 
       
   129 
       
   130 //
       
   131 // Old read / write methods left in to be BC
       
   132 //
       
   133 class _RRawDisk : public RRawDisk
       
   134 	{
       
   135 public:
       
   136 	IMPORT_C TInt Read(TInt aPos,TDes8& aDes);
       
   137 	IMPORT_C TInt Write(TInt aPos,TDesC8& aDes);
       
   138 	};
       
   139 
       
   140 
       
   141 
       
   142 
       
   143 /**
       
   144 Reads directly from the disk.
       
   145 
       
   146 The function reads a number of bytes into the specified descriptor from
       
   147 the disk beginning at the specified position.
       
   148 
       
   149 @param aPos The position on the disk at which to begin reading.
       
   150 @param aDes The descriptor into which data is to be read. On return, contains the
       
   151             data read. The number of bytes read is the smaller of:
       
   152             a) the total number of bytes on the disk minus aPos;
       
   153             b) the maximum length of the descriptor.
       
   154 
       
   155 @return KErrNone, if successful, otherwise one of the other system-wide error
       
   156         codes.
       
   157 
       
   158 @capability TCB
       
   159 @deprecated
       
   160 */
       
   161 EXPORT_C TInt _RRawDisk::Read(TInt aPos,TDes8& aDes)
       
   162 	{
       
   163 	TInt maxLength = aDes.MaxLength();
       
   164 	if (maxLength==0)
       
   165 		return(KErrNone);
       
   166 	TInt64 pos = MAKE_TINT64(0,aPos);
       
   167 	TPtrC8 tBuf((TUint8*)&pos,sizeof(TInt64));
       
   168 	return(SendReceive(EFsRawDiskRead,TIpcArgs(&aDes,maxLength,&tBuf)));
       
   169 	}
       
   170 
       
   171 
       
   172 
       
   173 
       
   174 /**
       
   175 Writes directly to the disk.
       
   176 
       
   177 The function writes the contents of the specified descriptor to the 
       
   178 disk at position aPos.
       
   179 
       
   180 @param aPos The position at which to begin writing.
       
   181 @param aDes The descriptor containing the data to be written to the disk.
       
   182 
       
   183 @return KErrNone, if successful, otherwise one of the other system-wide error
       
   184         codes.
       
   185 
       
   186 @capability TCB
       
   187 @deprecated
       
   188 */
       
   189 EXPORT_C TInt _RRawDisk::Write(TInt aPos,TDesC8& aDes)
       
   190 	{
       
   191 	TInt length = aDes.Length();
       
   192 	if (length==0)
       
   193 		return(KErrNone);
       
   194 	TInt64 pos = MAKE_TINT64(0,aPos);
       
   195 	TPtrC8 tBuf((TUint8*)&pos,sizeof(TInt64));
       
   196 	return(SendReceive(EFsRawDiskWrite,TIpcArgs(&aDes,length,&tBuf)));
       
   197 	}