RFile Class Reference

class RFile : public RSubSessionBase

Creates and opens a file, and performs all operations on a single open file.

These include:

  • reading from and writing to the file

  • seeking to a position within the file

  • locking and unlocking within the file

  • setting file attributes

Before using any of these services, a connection to a file server session must have been made, and the file must be open.

Opening Files:

  • use Open() to open an existing file for reading or writing; an error is returned if it does not already exist. To open an existing file for reading only, use Open() with an access mode of EFileRead, and a share mode of EFileShareReadersOnly.

  • use Create() to create and open a new file for writing; an error is returned if it already exists.

  • use Replace() to open a file for writing, replacing any existing file of the same name if one exists, or creating a new file if one does not exist. Note that if a file exists, its length is reset to zero.

  • use Temp() to create and open a temporary file with a unique name, for writing and reading.

When opening a file, you must specify the file server session to use for operations with that file. If you do not close the file explicitly, it is closed when the server session associated with it is closed.

Reading and Writing:

There are several variants of both Read() and Write(). The basic Read(TDes8& aDes) and Write(const TDesC8& aDes) are supplemented by variants allowing the descriptor length to be overridden, or the seek position of the first byte to be specified, or asynchronous completion, or any combination.

Reading transfers data from a file to a descriptor, and writing transfers data from a descriptor to a file. In all cases, the file data is treated as binary and byte descriptors are used (TDes8, TDesC8).

TDes8

TDesC8

Inherits from

Public Member Functions
EFSRV_IMPORT_C TIntAdopt(RFs &, TInt)
EFSRV_IMPORT_C TIntAdoptFromClient(const RMessage2 &, TInt, TInt)
EFSRV_IMPORT_C TIntAdoptFromCreator(TInt, TInt)
EFSRV_IMPORT_C TIntAdoptFromServer(TInt, TInt)
EFSRV_IMPORT_C TIntAtt(TUint &)
EFSRV_IMPORT_C TIntBlockMap(SBlockMapInfo &, TInt64 &, TInt64, TInt)
EFSRV_IMPORT_C TIntChangeMode(TFileMode)
TInt Clamp(RFileClamp &)
EFSRV_IMPORT_C voidClose()
EFSRV_IMPORT_C TIntCreate(RFs &, const TDesC &, TUint)
EFSRV_IMPORT_C TIntDrive(TInt &, TDriveInfo &)
EFSRV_IMPORT_C TIntDuplicate(const RFile &, TOwnerType)
EFSRV_IMPORT_C TIntFlush()
EFSRV_IMPORT_C voidFlush(TRequestStatus &)
EFSRV_IMPORT_C TIntFullName(TDes &)
EFSRV_IMPORT_C TIntLock(TInt, TInt)
EFSRV_IMPORT_C TIntModified(TTime &)
EFSRV_IMPORT_C TIntName(TDes &)
EFSRV_IMPORT_C TIntOpen(RFs &, const TDesC &, TUint)
EFSRV_IMPORT_C TIntRead(TDes8 &)
EFSRV_IMPORT_C voidRead(TDes8 &, TRequestStatus &)
EFSRV_IMPORT_C TIntRead(TDes8 &, TInt)
EFSRV_IMPORT_C voidRead(TDes8 &, TInt, TRequestStatus &)
EFSRV_IMPORT_C TIntRead(TInt, TDes8 &)
EFSRV_IMPORT_C voidRead(TInt, TDes8 &, TRequestStatus &)
EFSRV_IMPORT_C TIntRead(TInt, TDes8 &, TInt)
EFSRV_IMPORT_C voidRead(TInt, TDes8 &, TInt, TRequestStatus &)
EFSRV_IMPORT_C voidReadCancel(TRequestStatus &)
EFSRV_IMPORT_C voidReadCancel()
EFSRV_IMPORT_C TIntRename(const TDesC &)
EFSRV_IMPORT_C TIntReplace(RFs &, const TDesC &, TUint)
EFSRV_IMPORT_C TIntSeek(TSeek, TInt &)
EFSRV_IMPORT_C TIntSet(const TTime &, TUint, TUint)
EFSRV_IMPORT_C TIntSetAtt(TUint, TUint)
EFSRV_IMPORT_C TIntSetModified(const TTime &)
EFSRV_IMPORT_C TIntSetSize(TInt)
EFSRV_IMPORT_C TIntSize(TInt &)
EFSRV_IMPORT_C TIntTemp(RFs &, const TDesC &, TFileName &, TUint)
EFSRV_IMPORT_C TIntTransferToClient(const RMessage2 &, TInt)
EFSRV_IMPORT_C TIntTransferToProcess(RProcess &, TInt, TInt)
EFSRV_IMPORT_C TIntTransferToServer(TIpcArgs &, TInt, TInt)
EFSRV_IMPORT_C TIntUnLock(TInt, TInt)
EFSRV_IMPORT_C TIntWrite(const TDesC8 &)
EFSRV_IMPORT_C voidWrite(const TDesC8 &, TRequestStatus &)
EFSRV_IMPORT_C TIntWrite(const TDesC8 &, TInt)
EFSRV_IMPORT_C voidWrite(const TDesC8 &, TInt, TRequestStatus &)
EFSRV_IMPORT_C TIntWrite(TInt, const TDesC8 &)
EFSRV_IMPORT_C voidWrite(TInt, const TDesC8 &, TRequestStatus &)
EFSRV_IMPORT_C TIntWrite(TInt, const TDesC8 &, TInt)
EFSRV_IMPORT_C voidWrite(TInt, const TDesC8 &, TInt, TRequestStatus &)
Protected Member Functions
voidCloseSubSession(TInt)
TInt CreateSubSession(const RSessionBase &, TInt, const TIpcArgs &)
TInt DuplicateHandle(TInt &)
TInt SendReceive(TInt, const TIpcArgs &)
Inherited Functions
RSubSessionBase::CreateAutoCloseSubSession(RSessionBase &,TInt,const TIpcArgs &)
RSubSessionBase::CreateSubSession(const RSessionBase &,TInt)
RSubSessionBase::RSubSessionBase()
RSubSessionBase::Send(TInt)const
RSubSessionBase::Send(TInt,const TIpcArgs &)const
RSubSessionBase::SendReceive(TInt)const
RSubSessionBase::SendReceive(TInt,TRequestStatus &)const
RSubSessionBase::SendReceive(TInt,const TIpcArgs &,TRequestStatus &)const
RSubSessionBase::Session()const
RSubSessionBase::SubSessionHandle()const

Member Functions Documentation

Adopt(RFs &, TInt)

EFSRV_IMPORT_C TIntAdopt(RFs &aFs,
TIntaHandle
)

Parameters

RFs & aFs
TInt aHandle

AdoptFromClient(const RMessage2 &, TInt, TInt)

EFSRV_IMPORT_C TIntAdoptFromClient(const RMessage2 &aMsg,
TIntaFsHandleIndex,
TIntaFileHandleIndex
)

Parameters

const RMessage2 & aMsg
TInt aFsHandleIndex
TInt aFileHandleIndex

AdoptFromCreator(TInt, TInt)

EFSRV_IMPORT_C TIntAdoptFromCreator(TIntaFsIndex,
TIntaFileHandleIndex
)

Parameters

TInt aFsIndex
TInt aFileHandleIndex

AdoptFromServer(TInt, TInt)

EFSRV_IMPORT_C TIntAdoptFromServer(TIntaFsHandle,
TIntaFileHandle
)

Parameters

TInt aFsHandle
TInt aFileHandle

Att(TUint &)

EFSRV_IMPORT_C TIntAtt(TUint &aAttValue)const

Parameters

TUint & aAttValue

BlockMap(SBlockMapInfo &, TInt64 &, TInt64, TInt)

EFSRV_IMPORT_C TIntBlockMap(SBlockMapInfo &aInfo,
TInt64 &aStartPos,
TInt64aEndPos = -1,
TIntaBlockMapusage = EBlockMapUsagePaging
)const

Parameters

SBlockMapInfo & aInfo
TInt64 & aStartPos
TInt64 aEndPos = -1
TInt aBlockMapusage = EBlockMapUsagePaging

ChangeMode(TFileMode)

EFSRV_IMPORT_C TIntChangeMode(TFileModeaNewMode)

Parameters

TFileMode aNewMode

Clamp(RFileClamp &)

TInt Clamp(RFileClamp &aHandle)

Parameters

RFileClamp & aHandle

Close()

EFSRV_IMPORT_C voidClose()

CloseSubSession(TInt)

voidCloseSubSession(TIntaFunction)[protected]

Parameters

TInt aFunction

Create(RFs &, const TDesC &, TUint)

EFSRV_IMPORT_C TIntCreate(RFs &aFs,
const TDesC &aName,
TUintaFileMode
)

Parameters

RFs & aFs
const TDesC & aName
TUint aFileMode

CreateSubSession(const RSessionBase &, TInt, const TIpcArgs &)

TInt CreateSubSession(const RSessionBase &aSession,
TIntaFunction,
const TIpcArgs &aArgs
)[protected]

Creates a new sub-session within an existing session.

KErrNone if successful, otherwise one of the system-wide error codes.

Parameters

const RSessionBase & aSessionThe session to which this sub-session will belong.
TInt aFunctionThe opcode specifying the requested service; the server should interpret this as a request to create a sub-session.
const TIpcArgs & aArgsThe message arguments.

Drive(TInt &, TDriveInfo &)

EFSRV_IMPORT_C TIntDrive(TInt &aDriveNumber,
TDriveInfo &aDriveInfo
)const

Parameters

TInt & aDriveNumber
TDriveInfo & aDriveInfo

Duplicate(const RFile &, TOwnerType)

EFSRV_IMPORT_C TIntDuplicate(const RFile &aFile,
TOwnerTypeaType = EOwnerProcess
)

Parameters

const RFile & aFile
TOwnerType aType = EOwnerProcess

DuplicateHandle(TInt &)

TInt DuplicateHandle(TInt &aSubSessionHandle)const [protected]

Parameters

TInt & aSubSessionHandle

Flush()

EFSRV_IMPORT_C TIntFlush()

Flush(TRequestStatus &)

EFSRV_IMPORT_C voidFlush(TRequestStatus &aStatus)

Parameters

TRequestStatus & aStatus

FullName(TDes &)

EFSRV_IMPORT_C TIntFullName(TDes &aName)const

Parameters

TDes & aName

Lock(TInt, TInt)

EFSRV_IMPORT_C TIntLock(TIntaPos,
TIntaLength
)const

Parameters

TInt aPos
TInt aLength

Modified(TTime &)

EFSRV_IMPORT_C TIntModified(TTime &aTime)const

Parameters

TTime & aTime

Name(TDes &)

EFSRV_IMPORT_C TIntName(TDes &aName)const

Parameters

TDes & aName

Open(RFs &, const TDesC &, TUint)

EFSRV_IMPORT_C TIntOpen(RFs &aFs,
const TDesC &aName,
TUintaFileMode
)

Parameters

RFs & aFs
const TDesC & aName
TUint aFileMode

Read(TDes8 &)

EFSRV_IMPORT_C TIntRead(TDes8 &aDes)const

Parameters

TDes8 & aDes

Read(TDes8 &, TRequestStatus &)

EFSRV_IMPORT_C voidRead(TDes8 &aDes,
TRequestStatus &aStatus
)const

Parameters

TDes8 & aDes
TRequestStatus & aStatus

Read(TDes8 &, TInt)

EFSRV_IMPORT_C TIntRead(TDes8 &aDes,
TIntaLength
)const

Parameters

TDes8 & aDes
TInt aLength

Read(TDes8 &, TInt, TRequestStatus &)

EFSRV_IMPORT_C voidRead(TDes8 &aDes,
TIntaLength,
TRequestStatus &aStatus
)const

Parameters

TDes8 & aDes
TInt aLength
TRequestStatus & aStatus

Read(TInt, TDes8 &)

EFSRV_IMPORT_C TIntRead(TIntaPos,
TDes8 &aDes
)const

Parameters

TInt aPos
TDes8 & aDes

Read(TInt, TDes8 &, TRequestStatus &)

EFSRV_IMPORT_C voidRead(TIntaPos,
TDes8 &aDes,
TRequestStatus &aStatus
)const

Parameters

TInt aPos
TDes8 & aDes
TRequestStatus & aStatus

Read(TInt, TDes8 &, TInt)

EFSRV_IMPORT_C TIntRead(TIntaPos,
TDes8 &aDes,
TIntaLength
)const

Parameters

TInt aPos
TDes8 & aDes
TInt aLength

Read(TInt, TDes8 &, TInt, TRequestStatus &)

EFSRV_IMPORT_C voidRead(TIntaPos,
TDes8 &aDes,
TIntaLength,
TRequestStatus &aStatus
)const

Parameters

TInt aPos
TDes8 & aDes
TInt aLength
TRequestStatus & aStatus

ReadCancel(TRequestStatus &)

EFSRV_IMPORT_C voidReadCancel(TRequestStatus &aStatus)const

Parameters

TRequestStatus & aStatus

ReadCancel()

EFSRV_IMPORT_C voidReadCancel()const

Rename(const TDesC &)

EFSRV_IMPORT_C TIntRename(const TDesC &aNewName)

Parameters

const TDesC & aNewName

Replace(RFs &, const TDesC &, TUint)

EFSRV_IMPORT_C TIntReplace(RFs &aFs,
const TDesC &aName,
TUintaFileMode
)

Parameters

RFs & aFs
const TDesC & aName
TUint aFileMode

Seek(TSeek, TInt &)

EFSRV_IMPORT_C TIntSeek(TSeekaMode,
TInt &aPos
)const

Parameters

TSeek aMode
TInt & aPos

SendReceive(TInt, const TIpcArgs &)

TInt SendReceive(TIntaFunction,
const TIpcArgs &aArgs
)const [protected]

Sends a message to the server and waits synchronously for a reply.

An opcode specifies the service required. A set of message arguments is passed that can be used to specify client addresses, which the server can use to read from and write to the client address space.

Note that this function will only fail if the server itself fails or environmental errors occur in the server. All requests made using this function are guaranteed to reach the server. This means that all synchronous client requests (typically those that return void) should be routed through this synchronous variant of SendReceive().

KErrNone if successful, otherwise one of the system-wide error codes.

Parameters

TInt aFunctionThe opcode specifying the requested service.
const TIpcArgs & aArgsThe message arguments.

Set(const TTime &, TUint, TUint)

EFSRV_IMPORT_C TIntSet(const TTime &aTime,
TUintaSetAttMask,
TUintaClearAttMask
)

Parameters

const TTime & aTime
TUint aSetAttMask
TUint aClearAttMask

SetAtt(TUint, TUint)

EFSRV_IMPORT_C TIntSetAtt(TUintaSetAttMask,
TUintaClearAttMask
)

Parameters

TUint aSetAttMask
TUint aClearAttMask

SetModified(const TTime &)

EFSRV_IMPORT_C TIntSetModified(const TTime &aTime)

Parameters

const TTime & aTime

SetSize(TInt)

EFSRV_IMPORT_C TIntSetSize(TIntaSize)

Parameters

TInt aSize

Size(TInt &)

EFSRV_IMPORT_C TIntSize(TInt &aSize)const

Parameters

TInt & aSize

Temp(RFs &, const TDesC &, TFileName &, TUint)

EFSRV_IMPORT_C TIntTemp(RFs &aFs,
const TDesC &aPath,
TFileName &aName,
TUintaFileMode
)

Parameters

RFs & aFs
const TDesC & aPath
TFileName & aName
TUint aFileMode

TransferToClient(const RMessage2 &, TInt)

EFSRV_IMPORT_C TIntTransferToClient(const RMessage2 &aMsg,
TIntaFileHandleIndex
)const

Parameters

const RMessage2 & aMsg
TInt aFileHandleIndex

TransferToProcess(RProcess &, TInt, TInt)

EFSRV_IMPORT_C TIntTransferToProcess(RProcess &aProcess,
TIntaFsHandleIndex,
TIntaFileHandleIndex
)const

Parameters

RProcess & aProcess
TInt aFsHandleIndex
TInt aFileHandleIndex

TransferToServer(TIpcArgs &, TInt, TInt)

EFSRV_IMPORT_C TIntTransferToServer(TIpcArgs &aIpcArgs,
TIntaFsHandleIndex,
TIntaFileHandleIndex
)const

Parameters

TIpcArgs & aIpcArgs
TInt aFsHandleIndex
TInt aFileHandleIndex

UnLock(TInt, TInt)

EFSRV_IMPORT_C TIntUnLock(TIntaPos,
TIntaLength
)const

Parameters

TInt aPos
TInt aLength

Write(const TDesC8 &)

EFSRV_IMPORT_C TIntWrite(const TDesC8 &aDes)

Parameters

const TDesC8 & aDes

Write(const TDesC8 &, TRequestStatus &)

EFSRV_IMPORT_C voidWrite(const TDesC8 &aDes,
TRequestStatus &aStatus
)

Parameters

const TDesC8 & aDes
TRequestStatus & aStatus

Write(const TDesC8 &, TInt)

EFSRV_IMPORT_C TIntWrite(const TDesC8 &aDes,
TIntaLength
)

Parameters

const TDesC8 & aDes
TInt aLength

Write(const TDesC8 &, TInt, TRequestStatus &)

EFSRV_IMPORT_C voidWrite(const TDesC8 &aDes,
TIntaLength,
TRequestStatus &aStatus
)

Parameters

const TDesC8 & aDes
TInt aLength
TRequestStatus & aStatus

Write(TInt, const TDesC8 &)

EFSRV_IMPORT_C TIntWrite(TIntaPos,
const TDesC8 &aDes
)

Parameters

TInt aPos
const TDesC8 & aDes

Write(TInt, const TDesC8 &, TRequestStatus &)

EFSRV_IMPORT_C voidWrite(TIntaPos,
const TDesC8 &aDes,
TRequestStatus &aStatus
)

Parameters

TInt aPos
const TDesC8 & aDes
TRequestStatus & aStatus

Write(TInt, const TDesC8 &, TInt)

EFSRV_IMPORT_C TIntWrite(TIntaPos,
const TDesC8 &aDes,
TIntaLength
)

Parameters

TInt aPos
const TDesC8 & aDes
TInt aLength

Write(TInt, const TDesC8 &, TInt, TRequestStatus &)

EFSRV_IMPORT_C voidWrite(TIntaPos,
const TDesC8 &aDes,
TIntaLength,
TRequestStatus &aStatus
)

Parameters

TInt aPos
const TDesC8 & aDes
TInt aLength
TRequestStatus & aStatus