Opening and Creating Large Files

How to open and create large files.

Both the 32-bit and the 64-bit functions can be used to open files. However, when using a 32-bit RFile handle (sub-session connection) a file cannot be increased to greater than 2GB-1.

To increase the size of a file beyond this limit, open it using the 64-bit RFile64 functions.

If a file is opened simultaneously by RFile and RFile64, using the RFile64 handle the file can be made larger than 2GB-1 (even if there is an RFile sub-session open).

The RFile64::AdoptFromXXX() functions allow a server to adopt a file that is already open from a client, a server or even from another process (creator).

The File Server enables a large file access mode for the adopter. For example, the server that obtains the file handle from its client can use RFile64, irrespective of whether the client has opened the file in large file mode or not.

Use RFile64 instead of RFile.
// RFile file;
RFile64 file;

Increasing the size of existing files example

Large file access is supported when using RFile64. The file can be increased to a size larger than 2GB-1 and the error KErrTooBig will not be returned when using RFile64.

This example shows the Temp() function but the same concepts apply for the others.

    // RFile file;
    RFile64 file;
    TInt err;

    TFileName myTempFile;
    err = file.Temp(TheFs, _L(“D:\\Private\\”), myTempFile, EFileWrite);

    if(err != KErrNone)
         {
        return err;
         }
    ...
    err = file.Write(myDesc);
    If(err != KErrNone)
        {
        // handle error
        return err;
     }
        ...