LockFile Event

Fires when the OS needs to lock a range of bytes in a file.

Syntax

// CBFSLockFileEventArgs carries the CBFS LockFile event's parameters.
type CBFSLockFileEventArgs struct {...}

func (args *CBFSLockFileEventArgs) FileName() string
func (args *CBFSLockFileEventArgs) ByteOffset() int64
func (args *CBFSLockFileEventArgs) Length() int64
func (args *CBFSLockFileEventArgs) ExclusiveLock() bool
func (args *CBFSLockFileEventArgs) FailImmediately() bool
func (args *CBFSLockFileEventArgs) HandleInfo() int64
func (args *CBFSLockFileEventArgs) FileContext() int64
func (args *CBFSLockFileEventArgs) SetFileContext(value int64)
func (args *CBFSLockFileEventArgs) HandleContext() int64
func (args *CBFSLockFileEventArgs) SetHandleContext(value int64)
func (args *CBFSLockFileEventArgs) ResultCode() int32
func (args *CBFSLockFileEventArgs) SetResultCode(value int32)

// CBFSLockFileEvent defines the signature of the CBFS LockFile event's handler function.
type CBFSLockFileEvent func(sender *CBFS, args *CBFSLockFileEventArgs)

func (obj *CBFS) GetOnLockFileHandler() CBFSLockFileEvent
func (obj *CBFS) SetOnLockFileHandler(handlerFunc CBFSLockFileEvent)

Remarks

This event fires when the OS needs to lock a range of bytes in the file specified by FileName. Typically, such requests originate from the Windows API's LockFile and LockFileEx functions.

This event is optional. The CBFS component automatically manages file locks in the virtual filesystem, so if the resources an application uses for backend storage (files, memory, a database, etc.) are never directly accessed by anything other than the application itself, then there is no reason to implement this event.

On the other hand, if an application's backend storage involves shared resources (i.e., those which could be accessed by something other than the application at any time), this event should be used to perform any actions needed to propagate the requested lock onto those resources.

For example, if an application's backend storage implementation involves files stored on a network server, then the locking request should be communicated to that server so that it can prevent other accessors from using the locked data.

Applications that implement this event must also implement the UnlockFile event.

The ByteOffset and Length parameters specify the starting position of the range being locked, and the length of that range, respectively.

The ExclusiveLock and FailImmediately parameters are described in-depth in the LockFileEx function's documentation.

The HandleInfo parameter carries a handle to an object with information about the file handle. While within the event handler, it can be used to call any of the following methods: GetHandleCreatorProcessId, GetHandleCreatorProcessName, GetHandleCreatorThreadId, or GetHandleCreatorToken.

The FileContext and HandleContext parameters are placeholders for application-defined data associated with the file and specific handle, respectively. Please refer to the Contexts topic for more information.

The ResultCode parameter will always be 0 when the event is fired. If the event cannot be handled in a "successful" manner for some reason (e.g., a resource isn't available, security checks failed, etc.), set it to a non-zero value to report an appropriate error. Please refer to the Error Reporting and Handling topic for more information.

Copyright (c) 2022 Callback Technologies, Inc. - All rights reserved.
CBFS Connect 2020 Go Edition - Version 20.0 [Build 8348]