Unlocking a Large File

How to unlock a section of a large file.

RFile64::Unlock() allows a section of data within a file to be unlocked. This function uses 64-bit TInt64 variables rather than 32-bit TInt variables. The area to unlock within a file is specified by the starting position and length of the area. Using a 64-bit variable rather than a 32-bit variable allows the specified position and length of the section to be greater than 2GB-1.

  1. Use the 64-bit RFile64 class instead of the 32-bit RFile class.
    //RFile file;
    RFile64 file;
  2. Use a TInt64 variable to specify the position and length of the file to unlock.
    TInt r;
    // TInt lockPosition, lockLength;
    TInt64 lockPosition, lockLength;
    ...
    r = file.UnLock(lockPosition, lockLength);

Unlock example

    // Replace RFile with RFile64
    RFile64 file;
    TInt err = file.Open(TheFs, _L(“BIGFILE.BIG”), EFileWrite);
    if(err != KErrNone)
        {
        // handle unrelated error
        return err;
        }

    // Change the TInt type to TInt64
    TInt64 lockPosition, lockLength;
    err = file.UnLock(lockPosition,lockLength);
    if(err != KErrNone)
        {
        //could return with KErrArgument if lockPosition + lockLength > 63Bytes   
        return err;
        }