NFS Component

Properties   Methods   Events   Config Settings   Errors  

This class is used to create a Network File System (NFS) server based on NFS version 4.1.

Syntax

cbfsconnect.NFS

Remarks

This component provides a simple way to create a Network File System (NFS) server, enabling NFS clients the ability to access and share files seamlessly across a network.

Getting Started

To begin, call StartListening to start listening for incoming connections. The component will listen on the interface defined by LocalHost and LocalPort. For example:

Component.LocalHost = "localhost"; Component.LocalPort = 2049; // default Component.StartListening(); while (Component.Listening) { Component.DoEvents(); }

StopListening may be called to stop listening for incoming connections. Shutdown may be called to stop listening for incoming connections and disconnect all existing connections.

Handling Connections

Once listening, the component can accept (or reject) incoming connections. Incoming connection details are first available through the ConnectionRequest event. Here, the connection's originating address and port can be queried. By default, the component will accept all incoming connections, but this behavior can be overridden within this event.

Once a connection is complete, the Connected event will fire. Note that this event will fire if a connection succeeds or fails. If successful, the event will fire with a StatusCode of 0. A non-zero value indicates the connection was unsuccessful, and the Description parameter will contain relevant details.

After a successful connection, relevant connection-specific details will be available within the Connections collection. Each connection will be assigned a unique ConnectionId which may be used to access these details.

To manually disconnect a connected client call the Disconnect method and pass the ConnectionId. After a connection has disconnected, the Disconnected event will fire. In the case a connection ends and an error is encountered, the StatusCode and Description parameters will contain relevant details regarding the error. Once disconnected, the connection will be removed from the Connections collection.

Handling Events

File and folder operations are serviced through the events listed below. In addition to the connection-related events discussed in the previous section, the following events may fire while the component is listening:

EventUsage
AccessFires when a client verifies its access permissions for an object.
ChmodFires when a client attempts to modify the permission bits of an object.
ChownFires when a client attempts to modify an object's owner attribute, group attribute, or both.
CloseFires when a client requests the closure of a previously opened file.
CommitFires upon when a client attempts to flush any uncommitted file data from a previous Write operation to stable storage.
GetAttrFires when a client requests attributes for an object (such as the owner, group, or mode attributes).
LockFires when a client attempts to create or test a byte-range lock for a file.
LookupFires when the component needs to determine the existence of an object in the current directory.
MkDirFires when a client attempts to create a new directory.
OpenFires when a client attempts to create or open a file.
ReadFires when a client attempts to read any part of a file.
ReadDirFires when a client attempts to list the contents of a directory.
RenameFires when a client attempts to rename or move an object.
RmDirFires when a client attempts to remove a directory.
TruncateFires when a client attempts to modify a file's size attribute.
UnlinkFires when a client attempts to unlink (or delete) a file.
UnlockFires when a client attempts to release a lock.
UtimensFires when a client attempts to change a file's last access time, last modification time, or both.
WriteFires when a client attempts to write data to a file.

Many of the listed events expose a Result parameter, which communicates the operation's success (or failure) to the component and connection. This parameter is always 0 (NFS4_OK) when relevant events fire. If the event, or operation, cannot be handled successfully, this parameter should be set to a non-zero value. Possible Result codes and their descriptions are defined in RFC 7530 section 13.

For more information on how to handle each of these events, please refer to the event's documentation.

Property List


The following is the full list of the properties of the component with short descriptions. Click on the links for further details.

NFSConnectionCountThe number of records in the NFSConnection arrays.
NFSConnectionConnectedThis property shows the status of a particular connection (connected/disconnected).
NFSConnectionCurrentFileThis property represents the current file opened by the connection.
NFSConnectionRemoteHostThis property indicates the IP address of the remote host through which the connection is coming.
NFSConnectionRemotePortThis property indicates the TCP port on the remote host through which the connection is coming.
ListeningThis property indicates whether the class is listening for incoming connections.
LocalHostThis property includes the name of the local host or user-assigned IP interface through which connections are initiated or accepted.
LocalPortThe TCP port in the local host where the class listens.

Method List


The following is the full list of the methods of the component with short descriptions. Click on the links for further details.

ConfigThis method sets or retrieves a configuration setting.
DisconnectThis method disconnects the specified client.
DoEventsThis method processes events from the internal message queue.
FillDirThis method fills the buffer with information about a directory entry.
ShutdownThis method shuts down the server.
StartListeningThis method starts listening for incoming connections.
StopListeningThis method stops listening for new connections.

Event List


The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.

AccessThis event fires when a client verifies their access permissions for an object.
ChmodThis event fires when a client attempts to modify the permission bits of an object.
ChownThis event fires when a client attempts to modify an object's owner attribute, group attribute, or both.
CloseThis event fires when a client requests the closure of a previously opened file.
CommitThis event fires when a client attempts to flush any uncommitted file data from a previous Write operation to stable storage.
ConnectedThis event fires immediately after a connection completes (or fails).
ConnectionRequestThis event fires when a connection request comes from a remote host.
DisconnectedThis event fires when a connection is closed.
ErrorThis event fires information about errors during data delivery.
GetAttrThis event fires when a client requests attributes for an object (such as the owner, group, or mode attributes).
LockThis event fires when a client attempts to create or test a byte-range lock for a file.
LogThis event fires once for each log message.
LookupThis event fires when the class needs to determine the existence of an object in the current directory.
MkDirThis event fires when a client attempts to create a new directory.
OpenThis event fires when a client attempts to create or open a file.
ReadThis event fires when a client attempts to read any part of a file.
ReadDirThis event fires when a client attempts to list the contents of a directory.
RenameThis event fires when a client attempts to rename or move an object.
RmDirThis event fires when a client attempts to remove a directory.
TruncateThis event fires when a client attempts to modify a file's size attribute.
UnlinkThis event fires when a client attempts to unlink (or delete) a file.
UnlockThis event fires when a client attempts to release a lock.
UtimensThis event fires when a client attempts to change a file's last access time, last modification time, or both.
WriteThis event fires when a client attempts to write data to a file.

Config Settings


The following is a list of config settings for the component with short descriptions. Click on the links for further details.

AllowedClientsA comma-separated list of host names or IP addresses that can access the class.
BindExclusivelyWhether or not the class considers a local port reserved for exclusive use.
BlockedClientsA comma-separated list of host names or IP addresses that cannot access the class.
ClientAuthUIDSpecifies a client's authentication UID for use during authentication.
ConnectionUIDThe unique connectionId for a connection.
DefaultConnectionTimeoutThe inactivity timeout applied to the SSL handshake.
InBufferSizeThe size in bytes of the incoming queue of the socket.
KeepAliveIntervalThe retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received.
KeepAliveRetryCountThe number of keep-alive packets to be sent before the remotehost is considered disconnected.
KeepAliveTimeThe inactivity time in milliseconds before a TCP keep-alive packet is sent.
LogLevelSpecifies the level of detail that is logged.
MaxConnectionsThe maximum number of connections available.
MaxReadTimeThe maximum time spent reading data from each connection.
MountPointA path to an empty directory to mount the NFS server to.
OutBufferSizeThe size in bytes of the outgoing queue of the socket.
SpaceAvailSpecifies the amount of space available on the server, in bytes.
SpaceUsedSpecifies the amount of space used by the current filesystem object, in bytes.
UseIOCPWhether to use the completion port I/O model.
UseIPv6Whether to use IPv6.
UseWindowsMessagesWhether to use the WSAAsyncSelect I/O model.
BuildInfoInformation about the product's build.
LicenseInfoInformation about the current license.

NFSConnectionCount Property (NFS Component)

The number of records in the NFSConnection arrays.

Syntax

func (obj *NFS) NFSConnectionCount() (int32, error)

Default Value

0

Remarks

This property controls the size of the following arrays:

The array indices start at 0 and end at NFSConnectionCount - 1.

This property is read-only.

Data Type

int32

NFSConnectionConnected Property (NFS Component)

This property shows the status of a particular connection (connected/disconnected).

Syntax

func (obj *NFS) NFSConnectionConnected(ConnectionId int32) (bool, error)

Default Value

false

Remarks

This property shows the status of a particular connection (connected/disconnected).

The ConnectionId parameter specifies the index of the item in the array. The size of the array is controlled by the NFSConnectionCount property.

This property is read-only.

Data Type

bool

NFSConnectionCurrentFile Property (NFS Component)

This property represents the current file opened by the connection.

Syntax

func (obj *NFS) NFSConnectionCurrentFile(ConnectionId int32) (string, error)

Default Value

""

Remarks

This property represents the current file opened by the connection. An empty string indicates the connection has no file opened.

The ConnectionId parameter specifies the index of the item in the array. The size of the array is controlled by the NFSConnectionCount property.

This property is read-only.

Data Type

string

NFSConnectionRemoteHost Property (NFS Component)

This property indicates the IP address of the remote host through which the connection is coming.

Syntax

func (obj *NFS) NFSConnectionRemoteHost(ConnectionId int32) (string, error)

Default Value

""

Remarks

This property indicates the IP address of the remote host through which the connection is coming.

The connection must be valid or an error will be fired.

If the component is configured to use a SOCKS firewall, the value assigned to this property may be preceded with an "*". If this is the case, the host name is passed to the firewall unresolved and the firewall performs the DNS resolution.

The ConnectionId parameter specifies the index of the item in the array. The size of the array is controlled by the NFSConnectionCount property.

This property is read-only.

Data Type

string

NFSConnectionRemotePort Property (NFS Component)

This property indicates the TCP port on the remote host through which the connection is coming.

Syntax

func (obj *NFS) NFSConnectionRemotePort(ConnectionId int32) (int32, error)

Default Value

0

Remarks

This property indicates the TCP port on the remote host through which the connection is coming.

The connection must be valid or an error will be fired.

The ConnectionId parameter specifies the index of the item in the array. The size of the array is controlled by the NFSConnectionCount property.

This property is read-only.

Data Type

int32

Listening Property (NFS Component)

This property indicates whether the class is listening for incoming connections.

Syntax

func (obj *NFS) Listening() (bool, error)

Default Value

false

Remarks

This property indicates whether the component is listening for incoming connections on the interface identified by LocalHost and LocalPort.

Upon the successful return of StartListening or StopListening, this property will be adjusted accordingly.

This property is read-only.

Data Type

bool

LocalHost Property (NFS Component)

This property includes the name of the local host or user-assigned IP interface through which connections are initiated or accepted.

Syntax

func (obj *NFS) LocalHost() (string, error)
func (obj *NFS) SetLocalHost(value string) error

Default Value

""

Remarks

The LocalHost property contains the name of the local host as obtained by the gethostname() system call, or if the user has assigned an IP address, the value of that address.

In multihomed hosts (machines with more than one IP interface) setting LocalHost to the IP address of an interface will make the component initiate connections (or accept in the case of server components) only through that interface. It is recommended to provide an IP address rather than a hostname when setting this property to ensure the desired interface is used.

If the component is connected, the LocalHost property shows the IP address of the interface through which the connection is made in internet dotted format (aaa.bbb.ccc.ddd). In most cases, this is the address of the local host, except for multihomed hosts (machines with more than one IP interface).

Note: LocalHost is not persistent. You must always set it in code, and never in the property window.

Data Type

string

LocalPort Property (NFS Component)

The TCP port in the local host where the class listens.

Syntax

func (obj *NFS) LocalPort() (int32, error)
func (obj *NFS) SetLocalPort(value int32) error

Default Value

2049

Remarks

The LocalPort property must be set before the server starts listening. By default, this value is 2049. If its value is 0, then the TCP/IP subsystem picks a port number at random. The port number can be found by checking the value of the LocalPort property after successfully calling StartListening.

The service port is not shared among servers (i.e. there can be only one server 'listening' on a particular port at one time).

Data Type

int32

Config Method (NFS Component)

This method sets or retrieves a configuration setting.

Syntax

func (obj *NFS) Config(ConfigurationString string) (string, error)

Remarks

Config is a generic method available in every component. It is used to set and retrieve configuration settings for the component.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.

Disconnect Method (NFS Component)

This method disconnects the specified client.

Syntax

func (obj *NFS) Disconnect(ConnectionId int32) error

Remarks

Calling this method will disconnect the client specified by the ConnectionId parameter.

DoEvents Method (NFS Component)

This method processes events from the internal message queue.

Syntax

func (obj *NFS) DoEvents() error

Remarks

When DoEvents is called, the component processes any available events. If no events are available, it waits for a preset period of time, and then returns.

FillDir Method (NFS Component)

This method fills the buffer with information about a directory entry.

Syntax

func (obj *NFS) FillDir(ConnectionId int32, Name string, FileId int64, Cookie int64, Mode int32, User string, Group string, LinkCount int32, Size int64, ATime time.Time, MTime time.Time, CTime time.Time) (int32, error)

Remarks

This method fills the buffer with information about a directory entry. The Path parameter identifies the location and name of this object. The Name parameter identifies only the name of this object.

This method must be called when the component needs to send information regarding a directory entry to a client, specified by ConnectionId.

Information regarding a directory entry is required when the ReadDir event fires. Please see the event description for additional information and sample implementation.

The FileId parameter is used to set the Id of the file, which should be unique within a filesystem. If this parameter is specified as 0, the component will generate an Id which is not guaranteed to be unique.

The Cookie parameter should be set to a value unique to the specific directory entry that can later be used to identify the last returned entry within the listing. As some background, when ReadDir fires, the client is attempting to read all entries within a directory. To start reading from the beginning of a directory, the client will specify a cookie value of 0.

The application is then responsible for calling FillDir for each existing directory entry. In some cases, the directory may contain a large number of entries. This can become problematic as a client will specify a maximum byte limit on the amount of returned data, meaning the application may not be able to return all directory entries in one response.

To ensure the limit is respected, FillDir will return a non-zero value if this limit is reached. After ReadDir returns, the client will follow up with a subsequent request specifying the last cookie value received (the cookie provided in the last successful call to FillDir). This value should be used as a "bookmark", representing a point the application can continue listing directory entries from in subsequent requests.

Note: Cookie values of 0, 1, and 2 should never be specified within this method. These values are considered to be reserved in certain environments.

The Mode parameter is used to specify the mode of the object, indicating its associated file type and permission bits. This parameter should be set to a combination of the following bit flags, as defined in the UNIX standard sys/stat.h header:

File Type

S_IFSOCK0xC000Identifies a socket.
S_IFLNK0xA000Identifies a symbolic link.
S_IFREG0x8000Identifies a regular file.
S_IFBLK0x6000Identifies a block device file.
S_IFDIR0x4000Identifies a directory.
S_IFCHR0x2000Identifies a character device file.
S_IFIFO0x1000Identifies a FIFO or pipe.

File Mode Bits

S_ISUID0x0800Set user ID on execution.
S_ISGID0x0400Set group ID on execution.
S_ISVTX0x0200Save text even after use.
S_IRUSR0x0100Read permission, owner.
S_IWUSR0x0080Write permission, owner.
S_IXUSR0x0040Execute permission, owner.
S_IRGRP0x0020Read permission, group.
S_IWGRP0x0010Write permission, group.
S_IXGRP0x0008Execute permission, group.
S_IROTH0x0004Read permission, others.
S_IWOTH0x0002Write permission, others.
S_IXOTH0x0001Execute permission, others.

The User parameter is used to provide the NFSv4.0 owner attribute, which is a string name of the owner of this filesystem object. Mode flags S_IRUSR, S_IWUSR, and S_IXUSR apply to the principal identified via the User parameter.

The Group parameter is used to provide the NFSv4.0 owner_group attribute, which is a string name of the group ownership of this filesystem object. Mode flags S_IRGRP, S_IWGRP, and S_IXGRP apply to the principals identified via the Group parameter.

Mode flags S_IROTH, S_IWOTH, and S_IXOTH apply to any principal that does that match the User and does not have a group matching the Group.

The LinkCount parameter is used to provide the NFSv4.0 numlinks attribute, which represents the number of hard links associated with this filesystem object.

The Size parameter is used to provide the NFSv4.0 size attribute, which represents the size of the filesystem object in bytes.

The ATime parameter is used to provide the NFSv4.0 time_access attribute, which represents the time of last access to the object by a Read operation sent to the server.

The MTime parameter is used to provide the NFSv4.0 time_modify attribute, which represents the time of the last modification to the object.

The CTime parameter is used to provide the NFSv4.0 time_create attribute, which represents the time the object was created (unrelated to the UNIX file attribute "ctime").

Shutdown Method (NFS Component)

This method shuts down the server.

Syntax

func (obj *NFS) Shutdown() error

Remarks

This method shuts down the server. Calling this method is equivalent to calling StopListening and then breaking every client connection by calling Disconnect.

StartListening Method (NFS Component)

This method starts listening for incoming connections.

Syntax

func (obj *NFS) StartListening() error

Remarks

This method starts listening for incoming connections on the port specified by LocalPort. Once listening, events will fire as new clients connect and data are transferred.

To stop listening for new connections, call StopListening. To stop listening for new connections and to disconnect all existing clients, call Shutdown.

StopListening Method (NFS Component)

This method stops listening for new connections.

Syntax

func (obj *NFS) StopListening() error

Remarks

This method stops listening for new connections. After being called, any new connection attempts will be rejected. Calling this method does not disconnect existing connections.

To stop listening and disconnect all existing clients, call Shutdown instead.

Access Event (NFS Component)

This event fires when a client verifies their access permissions for an object.

Syntax

// NFSAccessEventArgs carries the NFS Access event's parameters.
type NFSAccessEventArgs struct {...}

func (args *NFSAccessEventArgs) ConnectionId() int32
func (args *NFSAccessEventArgs) Path() string
func (args *NFSAccessEventArgs) Access() int32
func (args *NFSAccessEventArgs) SetAccess(value int32)

func (args *NFSAccessEventArgs) Supported() int32
func (args *NFSAccessEventArgs) SetSupported(value int32)

// NFSAccessEvent defines the signature of the NFS Access event's handler function.
type NFSAccessEvent func(sender *NFS, args *NFSAccessEventArgs)

func (obj *NFS) GetOnAccessHandler() NFSAccessEvent
func (obj *NFS) SetOnAccessHandler(handlerFunc NFSAccessEvent)

Remarks

This event fires when a client verifies their access permissions for an object, identified by the Path parameter.

The ConnectionId parameter indicates the client requesting the file access permissions.

The Access parameter contains an encoded bitmask of access rights that the application should check. This parameter can be a combination of the following flags (or access permissions):

ACCESS4_READ0x00000001Read data from a file or read a directory.
ACCESS4_LOOKUP0x00000002Look up a name in a directory (no meaning for non-directory objects).
ACCESS4_MODIFY0x00000004Rewrite existing file data or modify existing directory entries.
ACCESS4_EXTEND0x00000008Write new data or add directory entries.
ACCESS4_DELETE0x00000010Delete an existing directory entry.
ACCESS4_EXECUTE0x00000020Execute a file (no meaning for a directory).

To handle this event appropriately, the application should set the Supported parameter to the access rights which the server can verify reliably. The application should then set the Access parameter to the access rights available to this client for the specified object.

Note that the Supported parameter should only contain as many values as were originally present in the provided Access parameter. For example, if the client is only checking the ACCESS4_READ permission, the application should only set the ACCESS4_READ permission in Supported, assuming it can reliably verify this permission.

In general, this operation only serves as an advisement to the client. The return of a certain access permission does not imply such access for this object will be permitted in the future, as the application can revoke or change access rights at any time.

Chmod Event (NFS Component)

This event fires when a client attempts to modify the permission bits of an object.

Syntax

// NFSChmodEventArgs carries the NFS Chmod event's parameters.
type NFSChmodEventArgs struct {...}

func (args *NFSChmodEventArgs) ConnectionId() int32
func (args *NFSChmodEventArgs) Path() string
func (args *NFSChmodEventArgs) FileContext() int64
func (args *NFSChmodEventArgs) Mode() int32
func (args *NFSChmodEventArgs) Result() int32
func (args *NFSChmodEventArgs) SetResult(value int32)

// NFSChmodEvent defines the signature of the NFS Chmod event's handler function.
type NFSChmodEvent func(sender *NFS, args *NFSChmodEventArgs)

func (obj *NFS) GetOnChmodHandler() NFSChmodEvent
func (obj *NFS) SetOnChmodHandler(handlerFunc NFSChmodEvent)

Remarks

This event fires when a client attempts to modify the permission bits of an object, identified by the FileContext and/or Path parameters.

The ConnectionId parameter indicates the client attempting to set this attribute.

The Mode parameter specifies the new permission bits the client wishes to set for this object. The client may specify a combination of the following permission bits, as defined in the UNIX standard sys/stat.h header:

S_ISUID0x800Set user ID on execution.
S_ISGID0x400Set group ID on execution.
S_ISVTX0x200Save text even after use.
S_IRUSR0x100Read permission, owner.
S_IWUSR0x080Write permission, owner.
S_IXUSR0x040Execute permission, owner.
S_IRGRP0x020Read permission, group.
S_IWGRP0x010Write permission, group.
S_IXGRP0x008Execute permission, group.
S_IROTH0x004Read permission, others.
S_IWOTH0x002Write permission, others.
S_IXOTH0x001Execute permission, others.

Example: Modifying the permission bits and preserving stored file type nfs.OnChmod += (o, e) => { string path = "C:\\NFSRootDir" + e.Path; int currentFileMode = GetFileMode(path); // Arbitrary function to retrieve stored mode int currentType = currentFileMode & 0xF000; // 0xF000 == S_IFMT // Client cannot change type bits, only permission bits SetFileMode(e.Path, currentType | e.Mode); }; The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

Chown Event (NFS Component)

This event fires when a client attempts to modify an object's owner attribute, group attribute, or both.

Syntax

// NFSChownEventArgs carries the NFS Chown event's parameters.
type NFSChownEventArgs struct {...}

func (args *NFSChownEventArgs) ConnectionId() int32
func (args *NFSChownEventArgs) Path() string
func (args *NFSChownEventArgs) FileContext() int64
func (args *NFSChownEventArgs) User() string
func (args *NFSChownEventArgs) Group() string
func (args *NFSChownEventArgs) Result() int32
func (args *NFSChownEventArgs) SetResult(value int32)

// NFSChownEvent defines the signature of the NFS Chown event's handler function.
type NFSChownEvent func(sender *NFS, args *NFSChownEventArgs)

func (obj *NFS) GetOnChownHandler() NFSChownEvent
func (obj *NFS) SetOnChownHandler(handlerFunc NFSChownEvent)

Remarks

This event fires when a client attempts to modify an object's owner attribute, group attribute, or both. The object is identified by the FileContext and/or Path parameters.

The ConnectionId parameter indicates the client attempting to set these attributes.

The User parameter indicates the desired value the client wishes to set the NFSv4.0 owner attribute to. The owner attribute specifies the owner of a file.

The Group parameter indicates the desired value the client wishes to set the NFSv4.0 owner_group attribute to. The owner_group attribute specifies the group ownership of a file.

Note that if the User or Group parameter is equal to an empty string, the client does not wish to modify the associated attribute and the parameter should be ignored.

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

Close Event (NFS Component)

This event fires when a client requests the closure of a previously opened file.

Syntax

// NFSCloseEventArgs carries the NFS Close event's parameters.
type NFSCloseEventArgs struct {...}

func (args *NFSCloseEventArgs) ConnectionId() int32
func (args *NFSCloseEventArgs) Path() string
func (args *NFSCloseEventArgs) FileContext() int64
func (args *NFSCloseEventArgs) SetFileContext(value int64)

func (args *NFSCloseEventArgs) Result() int32
func (args *NFSCloseEventArgs) SetResult(value int32)

// NFSCloseEvent defines the signature of the NFS Close event's handler function.
type NFSCloseEvent func(sender *NFS, args *NFSCloseEventArgs)

func (obj *NFS) GetOnCloseHandler() NFSCloseEvent
func (obj *NFS) SetOnCloseHandler(handlerFunc NFSCloseEvent)

Remarks

This event fires when a client requests the closure of a previously opened file, identified by the Path and/or FileContext parameters.

The ConnectionId parameter indicates the client performing this operation.

To handle this event properly, the application should release the share reservations for this specific file created during a previous Open operation. This operation is only applicable to the Open operation performed by a given client for the specified file and does not apply to any Open operations performed by other clients for the same file.

Note that clients should release any byte-range locks currently held for this file before this operation. However, applications should not assume this. In the event any relevant locks exist, the application may release all locks and return NFS4_OK. Alternatively, if the application chooses not to release the locks, it must respond with NFS4ERR_LOCKS_HELD, offloading the task to the client.

Assuming the operation was successful, applications should free the associated FileContext and set this parameter to IntPtr.Zero, if applicable.

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

Commit Event (NFS Component)

This event fires when a client attempts to flush any uncommitted file data from a previous Write operation to stable storage.

Syntax

// NFSCommitEventArgs carries the NFS Commit event's parameters.
type NFSCommitEventArgs struct {...}

func (args *NFSCommitEventArgs) ConnectionId() int32
func (args *NFSCommitEventArgs) Path() string
func (args *NFSCommitEventArgs) FileContext() int64
func (args *NFSCommitEventArgs) Offset() int64
func (args *NFSCommitEventArgs) Count() int32
func (args *NFSCommitEventArgs) Result() int32
func (args *NFSCommitEventArgs) SetResult(value int32)

// NFSCommitEvent defines the signature of the NFS Commit event's handler function.
type NFSCommitEvent func(sender *NFS, args *NFSCommitEventArgs)

func (obj *NFS) GetOnCommitHandler() NFSCommitEvent
func (obj *NFS) SetOnCommitHandler(handlerFunc NFSCommitEvent)

Remarks

This event fires when a client attempts to flush any uncommitted file data from a previous Write operation to stable storage. The file is identified by the FileContext and/or Path parameters.

The ConnectionId parameter indicates the client performing this operation.

The data to flush to stable storage is the data that was cached in a previous Write operation. This operation will only occur when the previous Write operation returns a commitment level of UNSTABLE4 or DATA_SYNC4 to the client. If FILE_SYNC4 was returned previously and all data was written to stable storage, this event will not fire.

Note that the application may cache multiple Write operations. If the Offset and Count parameters are equal to zero, this indicates that the application should flush all cached data, buffered with each previous Write operation, for this file to stable storage.

It is also possible that Offset and Count are non-zero. In this case, the application should flush only the specified cached data, buffered with a specific Write operation.

If the data has already been written to stable storage, and no cached data exists for this value (depending on Offset and Count), the operation should succeed.

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

Connected Event (NFS Component)

This event fires immediately after a connection completes (or fails).

Syntax

// NFSConnectedEventArgs carries the NFS Connected event's parameters.
type NFSConnectedEventArgs struct {...}

func (args *NFSConnectedEventArgs) ConnectionId() int32
func (args *NFSConnectedEventArgs) StatusCode() int32
func (args *NFSConnectedEventArgs) Description() string
// NFSConnectedEvent defines the signature of the NFS Connected event's handler function.
type NFSConnectedEvent func(sender *NFS, args *NFSConnectedEventArgs)

func (obj *NFS) GetOnConnectedHandler() NFSConnectedEvent
func (obj *NFS) SetOnConnectedHandler(handlerFunc NFSConnectedEvent)

Remarks

If the connection is made normally, StatusCode is 0, and Description is "OK".

If the connection fails, StatusCode has the error code returned by the system. Description contains a description of this code. The value of StatusCode is equal to the value of the system error.

Please refer to the Error Codes section for more information.

ConnectionRequest Event (NFS Component)

This event fires when a connection request comes from a remote host.

Syntax

// NFSConnectionRequestEventArgs carries the NFS ConnectionRequest event's parameters.
type NFSConnectionRequestEventArgs struct {...}

func (args *NFSConnectionRequestEventArgs) Address() string
func (args *NFSConnectionRequestEventArgs) Port() int32
func (args *NFSConnectionRequestEventArgs) Accept() bool
func (args *NFSConnectionRequestEventArgs) SetAccept(value bool)

// NFSConnectionRequestEvent defines the signature of the NFS ConnectionRequest event's handler function.
type NFSConnectionRequestEvent func(sender *NFS, args *NFSConnectionRequestEventArgs)

func (obj *NFS) GetOnConnectionRequestHandler() NFSConnectionRequestEvent
func (obj *NFS) SetOnConnectionRequestHandler(handlerFunc NFSConnectionRequestEvent)

Remarks

This event indicates an incoming connection. The connection is accepted by default. Address and Port will contain information about the remote host requesting the inbound connection. If you want to refuse it, you can set the Accept parameter to False.

Disconnected Event (NFS Component)

This event fires when a connection is closed.

Syntax

// NFSDisconnectedEventArgs carries the NFS Disconnected event's parameters.
type NFSDisconnectedEventArgs struct {...}

func (args *NFSDisconnectedEventArgs) ConnectionId() int32
func (args *NFSDisconnectedEventArgs) StatusCode() int32
func (args *NFSDisconnectedEventArgs) Description() string
// NFSDisconnectedEvent defines the signature of the NFS Disconnected event's handler function.
type NFSDisconnectedEvent func(sender *NFS, args *NFSDisconnectedEventArgs)

func (obj *NFS) GetOnDisconnectedHandler() NFSDisconnectedEvent
func (obj *NFS) SetOnDisconnectedHandler(handlerFunc NFSDisconnectedEvent)

Remarks

If the connection is broken normally, StatusCode is 0, and Description is "OK".

If the connection is broken for any other reason, StatusCode has the error code returned by the system. Description contains a description of this code. The value of StatusCode is equal to the value of the system error.

Please refer to the Error Codes section for more information.

Error Event (NFS Component)

This event fires information about errors during data delivery.

Syntax

// NFSErrorEventArgs carries the NFS Error event's parameters.
type NFSErrorEventArgs struct {...}

func (args *NFSErrorEventArgs) ConnectionId() int32
func (args *NFSErrorEventArgs) ErrorCode() int32
func (args *NFSErrorEventArgs) Description() string
// NFSErrorEvent defines the signature of the NFS Error event's handler function.
type NFSErrorEvent func(sender *NFS, args *NFSErrorEventArgs)

func (obj *NFS) GetOnErrorHandler() NFSErrorEvent
func (obj *NFS) SetOnErrorHandler(handlerFunc NFSErrorEvent)

Remarks

The Error event is fired in case of exceptional conditions during message processing. Normally, the component returns an error.

ErrorCode contains an error code and Description contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the Error Codes section.

ConnectionId indicates the connection for which the error is applicable.

GetAttr Event (NFS Component)

This event fires when a client requests attributes for an object (such as the owner, group, or mode attributes).

Syntax

// NFSGetAttrEventArgs carries the NFS GetAttr event's parameters.
type NFSGetAttrEventArgs struct {...}

func (args *NFSGetAttrEventArgs) ConnectionId() int32
func (args *NFSGetAttrEventArgs) Path() string
func (args *NFSGetAttrEventArgs) FileContext() int64
func (args *NFSGetAttrEventArgs) FileId() int64
func (args *NFSGetAttrEventArgs) SetFileId(value int64)

func (args *NFSGetAttrEventArgs) Mode() int32
func (args *NFSGetAttrEventArgs) SetMode(value int32)

func (args *NFSGetAttrEventArgs) User() string
func (args *NFSGetAttrEventArgs) SetUser(value string)

func (args *NFSGetAttrEventArgs) Group() string
func (args *NFSGetAttrEventArgs) SetGroup(value string)

func (args *NFSGetAttrEventArgs) LinkCount() int32
func (args *NFSGetAttrEventArgs) SetLinkCount(value int32)

func (args *NFSGetAttrEventArgs) Size() int64
func (args *NFSGetAttrEventArgs) SetSize(value int64)

func (args *NFSGetAttrEventArgs) ATime() time.Time
func (args *NFSGetAttrEventArgs) SetATime(value time.Time)

func (args *NFSGetAttrEventArgs) MTime() time.Time
func (args *NFSGetAttrEventArgs) SetMTime(value time.Time)

func (args *NFSGetAttrEventArgs) CTime() time.Time
func (args *NFSGetAttrEventArgs) SetCTime(value time.Time)

func (args *NFSGetAttrEventArgs) NFSHandleHex() string
func (args *NFSGetAttrEventArgs) SetNFSHandleHex(value string)

func (args *NFSGetAttrEventArgs) Result() int32
func (args *NFSGetAttrEventArgs) SetResult(value int32)

// NFSGetAttrEvent defines the signature of the NFS GetAttr event's handler function.
type NFSGetAttrEvent func(sender *NFS, args *NFSGetAttrEventArgs)

func (obj *NFS) GetOnGetAttrHandler() NFSGetAttrEvent
func (obj *NFS) SetOnGetAttrHandler(handlerFunc NFSGetAttrEvent)

Remarks

This event fires when a client requests attributes for an object (such as the owner, group, or mode attributes), identified by the FileContext, NFSHandleHex, and/or Path parameters.

The NFSHandleHex parameter is the hex-encoded value of the internal handle representation, which is a SHA256 hash of the full path of the relevant filesystem object (e.g., /path/to/file.txt). If needed, this value can be modified to contain any extra information about the filesystem object. Note the handle must be no more than 128 bytes (NFS4_FHSIZE).

The ConnectionId parameter indicates the client requesting information about the filesystem object.

To handle this event properly, applications should set the below parameters to relevant attributes of the filesystem object.

The FileId parameter is used to set the Id of the file, which should be unique within a filesystem.

The Mode parameter is used to specify the mode of the object, indicating its associated file type and permission bits. This parameter should be set to a combination of the following flags, as defined in the UNIX standard sys/stat.h header:

File Type

S_IFSOCK0xC000Identifies a socket.
S_IFLNK0xA000Identifies a symbolic link.
S_IFREG0x8000Identifies a regular file.
S_IFBLK0x6000Identifies a block device file.
S_IFDIR0x4000Identifies a directory.
S_IFCHR0x2000Identifies a character device file.
S_IFIFO0x1000Identifies a FIFO or pipe.

File Mode Bits

S_ISUID0x0800Set user ID on execution.
S_ISGID0x0400Set group ID on execution.
S_ISVTX0x0200Save text even after use.
S_IRUSR0x0100Read permission, owner.
S_IWUSR0x0080Write permission, owner.
S_IXUSR0x0040Execute permission, owner.
S_IRGRP0x0020Read permission, group.
S_IWGRP0x0010Write permission, group.
S_IXGRP0x0008Execute permission, group.
S_IROTH0x0004Read permission, others.
S_IWOTH0x0002Write permission, others.
S_IXOTH0x0001Execute permission, others.

The User parameter is used to set the NFSv4.0 owner attribute, which is a string name of the owner of this filesystem object. Mode flags S_IRUSR, S_IWUSR, and S_IXUSR apply to the principal identified via the User parameter.

The Group parameter is used to set the NFSv4.0 owner_group attribute, which is a string name of the group ownership of this filesystem object. Mode flags S_IRGRP, S_IWGRP, and S_IXGRP apply to the principals identified via the Group parameter.

Mode flags S_IROTH, S_IWOTH, and S_IXOTH apply to any principal that does not match the User and does not have a group matching the Group.

The LinkCount parameter is used to set the NFSv4.0 numlinks attribute, which represents the number of hard links associated with this filesystem object.

The Size parameter is used to set the NFSv4.0 size attribute, which represents the size of the filesystem object in bytes.

The ATime parameter is used to set the NFSv4.0 time_access attribute, which represents the time of last access to the object by a Read operation sent to the server.

The MTime parameter is used to set the NFSv4.0 time_modify attribute, which represents the time of the last modification to the object.

The CTime parameter is used to set the NFSv4.0 time_create attribute, which represents the time the object was created (unrelated to the UNIX file attribute "ctime").

Example: Retrieving file or directory attributes nfs.OnGetAttr += (o, e) => { string path = "C:\\NFSRootDir" + e.Path; if (!File.Exists(path) && !Directory.Exists(path)) { e.Result = NFS4ERR_NOENT; return; } e.User = OWNER; e.Group = OWNER_GROUP; e.LinkCount = 1; if (Directory.Exists(path)) { int fileMode = S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; // Indicates file type (S_IFDIR) and permissions (755) e.Mode = fileMode; e.Size = 4096; e.ATime = Directory.GetLastAccessTime(real); e.CTime = Directory.GetCreationTime(real); e.MTime = Directory.GetLastWriteTime(real); } else { int fileMode = S_IFREG | S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH; // Indicates file type (S_IFREG) and permissions (644) e.Mode = fileMode; e.Size = new FileInfo(path).Length; e.ATime = File.GetLastAccessTime(path); e.MTime = File.GetLastWriteTime(path); e.CTime = File.GetCreationTime(path); } }; The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

Lock Event (NFS Component)

This event fires when a client attempts to create or test a byte-range lock for a file.

Syntax

// NFSLockEventArgs carries the NFS Lock event's parameters.
type NFSLockEventArgs struct {...}

func (args *NFSLockEventArgs) ConnectionId() int32
func (args *NFSLockEventArgs) Path() string
func (args *NFSLockEventArgs) FileContext() int64
func (args *NFSLockEventArgs) LockType() int32
func (args *NFSLockEventArgs) LockOffset() int64
func (args *NFSLockEventArgs) SetLockOffset(value int64)

func (args *NFSLockEventArgs) LockLen() int64
func (args *NFSLockEventArgs) SetLockLen(value int64)

func (args *NFSLockEventArgs) Test() bool
func (args *NFSLockEventArgs) Result() int32
func (args *NFSLockEventArgs) SetResult(value int32)

// NFSLockEvent defines the signature of the NFS Lock event's handler function.
type NFSLockEvent func(sender *NFS, args *NFSLockEventArgs)

func (obj *NFS) GetOnLockHandler() NFSLockEvent
func (obj *NFS) SetOnLockHandler(handlerFunc NFSLockEvent)

Remarks

This event fires when a client attempts to create or test a byte-range lock for a file, indicated by the FileContext or Path parameters.

The ConnectionId parameter indicates the client requesting the lock.

The LockOffset parameter specifies the position (or byte) within the file where the lock should begin. The LockLen parameter specifies the number of bytes that should be locked after the specified offset, indicating a range of bytes to lock. If the LockLen parameter is 0, the application should return NFS4ERR_INVAL. If the LockLen parameter is -1, this indicates the client wishes to lock all bytes from the specified LockOffset to the end of the file.

The LockType parameter specifies the type of lock to be created or tested on the file (read or write, blocking or non-blocking). This parameter may be equal to one of the following values:

READ_LT1Indicates a non-blocking read lock.
WRITE_LT2Indicates a non-blocking write lock.
READW_LT3Indicates a blocking read lock.
WRITEW_LT4Indicates a blocking write lock.

Note a blocking lock type indicates the client wishes to 'wait' for the mentioned lock if a conflicting lock exists. Please see below for more information regarding blocking locks.

To handle this event properly, applications should determine whether the client wishes to create or test the lock by examining the Test parameter.

Testing a Lock

If the Test parameter is True, the client only intends to test the lock. In this case, no lock should be created. First, the application should determine whether a conflicting lock exists for this file based on the semantics of the server-exported file system. The test for a conflicting lock should exclude any locks held by the client making this request, identified by ConnectionId. If a conflicting lock exists, the application should set the LockOffset and LockLen parameters to that of the conflicting lock and return NFS4ERR_DENIED.

If the application chooses not to exclude these locks, and the client making this request owns the conflicting lock, NFS4ERR_LOCK_RANGE may be returned if any overlap exists between the conflicting lock and the range specified by LockOffset and LockLen.

Additionally, when Test is True, the lock types READ_LT and READW_LT should be interpreted in the same way, without regard to blocking or non-blocking behavior. This is also true for READW_LT and WRITEW_LT.

If no conflicting lock exists, no lock should be created and the operation should succeed.

Creating a Lock

If the Test parameter is False, the client wishes to create the lock. First, the application should determine whether a conflicting lock exists for this file based on the semantics of the server-exported file system. If the client making this request is the owner of the conflicting lock, NFS4ERR_LOCK_RANGE may be returned under the same conditions as described when testing a lock. Otherwise, the application should set the LockOffset and LockLen parameters to that of the conflicting lock and return NFS4ERR_DENIED. If the conflicting lock's offset and length cannot be determined by the application, the corresponding parameters should remain unchanged and NFS4ERR_DENIED should be returned.

If no conflicting lock exists, the application should create the lock and the operation should succeed.

Upgrading and Downgrading Locks

If a client has an existing write lock, they may request an atomic downgrade of the lock to a read lock. This is done by sending a LOCK request with the same LockOffset and LockLen, but specifying the LockType as READ_LT.

If a client has an existing read lock, they may request an atomic upgrade of the lock to a write lock. This is done by sending a LOCK request with the same LockOffset and LockLen, but specifying the LockType as WRITE_LT or WRITEW_LT. If a conflicting lock exists, the application should set the LockOffset and LockLen parameters to that of the conflicting lock and return NFS4ERR_DENIED. Additionally, if the LockType is specified as WRITEW_LT, the application should return NFS4ERR_DEADLOCK if a deadlock condition is detected.

In either case, if the application does not support upgrading or downgrading a lock, NFS4ERR_LOCK_NOTSUPP should be returned.

Blocking Locks

To ensure fairness and to support blocking locks, applications may maintain an ordered list of clients waiting to obtain a conflicting lock. Note this is only applicable to blocking locks. If implemented, it's important to note that clients will poll for the lock, following up with the identical lock request until accepted. Once a conflicting lock is released, the application may wait a fixed time (lease period) to grant the lock to the first waiting client. Since clients will poll for previously denied locks, this period ensures the client still wants the lock. If the application does not receive the re-request within this period, the application should assume the client no longer wants the lock, and the client should be removed from the ordered list. This process repeats with the next waiting client, and so on.

If implementing an ordered list, it may be the case that a waiting client sends the same lock request with a non-blocking lock type specified. If this occurs and the non-blocking request is denied, it can be assumed the client will no longer poll for this lock. The client may then be removed from the ordered list.

If the application determines a file locking deadlock condition would exist after a specific lock request, Result should be set to NFS4ERR_DEADLOCK.

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

Log Event (NFS Component)

This event fires once for each log message.

Syntax

// NFSLogEventArgs carries the NFS Log event's parameters.
type NFSLogEventArgs struct {...}

func (args *NFSLogEventArgs) ConnectionId() int32
func (args *NFSLogEventArgs) LogLevel() int32
func (args *NFSLogEventArgs) Message() string
func (args *NFSLogEventArgs) LogType() string
// NFSLogEvent defines the signature of the NFS Log event's handler function.
type NFSLogEvent func(sender *NFS, args *NFSLogEventArgs)

func (obj *NFS) GetOnLogHandler() NFSLogEvent
func (obj *NFS) SetOnLogHandler(handlerFunc NFSLogEvent)

Remarks

This event fires once for each log message generated by the component. The verbosity is controlled by the LogLevel configuration.

LogLevel indicates the detail level of the message. Possible values are:

0 (None)No messages are logged.
1 (Info - Default)Informational events are logged.
2 (Verbose)Detailed data is logged.
3 (Debug)Debug data including all sent and received NFS operations are logged.

Message is the log message.

LogType identifies the type of log entry. Possible values are as follows:

  • NFS

ConnectionId identifies the connection to which the log message applies.

Lookup Event (NFS Component)

This event fires when the class needs to determine the existence of an object in the current directory.

Syntax

// NFSLookupEventArgs carries the NFS Lookup event's parameters.
type NFSLookupEventArgs struct {...}

func (args *NFSLookupEventArgs) ConnectionId() int32
func (args *NFSLookupEventArgs) Name() string
func (args *NFSLookupEventArgs) Path() string
func (args *NFSLookupEventArgs) Result() int32
func (args *NFSLookupEventArgs) SetResult(value int32)

// NFSLookupEvent defines the signature of the NFS Lookup event's handler function.
type NFSLookupEvent func(sender *NFS, args *NFSLookupEventArgs)

func (obj *NFS) GetOnLookupHandler() NFSLookupEvent
func (obj *NFS) SetOnLookupHandler(handlerFunc NFSLookupEvent)

Remarks

This event fires when the component needs to determine the existence of an object in the current directory. The Path parameter identifies the location and name of this object. The Name parameter identifies only the name of this object.

The ConnectionId parameter indicates the client this information is required for.

The existence of a filesystem object can be requested in either of the following cases:

  • When a client is attempting to open and/or create a regular file. In this case, Open will fire shortly after this event returns.
  • When a client is performing a LOOKUP operation on a filesystem object.

To handle this event properly, the application should check whether this object exists within the specified directory. If the object does not exist, the Result parameter should be set to NFS4ERR_NOENT. Otherwise, NFS4_OK indicates the object exists.

Example: Check if object exists nfs.OnLookup += (o, e) => { string path = e.Path; // Varies depending on underlying filesystem implementation if (File.Exists(path)) { return; } if (Directory.Exists(path)) { return; } // Object does not exist e.Result = NFS4ERR_NOENT; };

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

MkDir Event (NFS Component)

This event fires when a client attempts to create a new directory.

Syntax

// NFSMkDirEventArgs carries the NFS MkDir event's parameters.
type NFSMkDirEventArgs struct {...}

func (args *NFSMkDirEventArgs) ConnectionId() int32
func (args *NFSMkDirEventArgs) Path() string
func (args *NFSMkDirEventArgs) Result() int32
func (args *NFSMkDirEventArgs) SetResult(value int32)

// NFSMkDirEvent defines the signature of the NFS MkDir event's handler function.
type NFSMkDirEvent func(sender *NFS, args *NFSMkDirEventArgs)

func (obj *NFS) GetOnMkDirHandler() NFSMkDirEvent
func (obj *NFS) SetOnMkDirHandler(handlerFunc NFSMkDirEvent)

Remarks

This event fires when a client attempts to create a new directory, identified by the Path parameter.

The ConnectionId parameter indicates the client attempting to create a directory.

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

Open Event (NFS Component)

This event fires when a client attempts to create or open a file.

Syntax

// NFSOpenEventArgs carries the NFS Open event's parameters.
type NFSOpenEventArgs struct {...}

func (args *NFSOpenEventArgs) ConnectionId() int32
func (args *NFSOpenEventArgs) Path() string
func (args *NFSOpenEventArgs) ShareAccess() int32
func (args *NFSOpenEventArgs) ShareDeny() int32
func (args *NFSOpenEventArgs) CreateMode() int32
func (args *NFSOpenEventArgs) OpenType() int32
func (args *NFSOpenEventArgs) FileContext() int64
func (args *NFSOpenEventArgs) SetFileContext(value int64)

func (args *NFSOpenEventArgs) Result() int32
func (args *NFSOpenEventArgs) SetResult(value int32)

// NFSOpenEvent defines the signature of the NFS Open event's handler function.
type NFSOpenEvent func(sender *NFS, args *NFSOpenEventArgs)

func (obj *NFS) GetOnOpenHandler() NFSOpenEvent
func (obj *NFS) SetOnOpenHandler(handlerFunc NFSOpenEvent)

Remarks

This event fires when a client attempts to create or open a file. This event is not applicable to directories (please see MkDir, ReadDir, and RmDir for further details).

The client where the request originates from is specified via ConnectionId.

The Path parameter contains the path to the file to open, along with the file name. Unless the file is already open, the FileContext parameter will initially be IntPtr.Zero. The application may use the FileContext parameter to store a file handle or other information related to the open file.

To appropriately handle this event, the application should perform any actions needed to create or open the requested file as indicated by the OpenType and CreateMode parameters, with the desired share reservations as specified by the ShareAccess and ShareDeny parameters. Please see the parameter descriptions below for additional information.

The OpenType parameter specifies how the client would like to open the file. This parameter may be equal to one of the following values:

OPEN4_NOCREATE0Indicates the file should be opened if it exists, but if the file does not exist, the file should not be created. In this case, the operation should fail with the error NFS4ERR_NOENT.
OPEN4_CREATE1Indicates the file should be created using the method specified by the CreateMode parameter.

The CreateMode parameter indicates the file creation method specified by the client. This parameter is only relevant when OpenType is equal to rsOPEN4CREATE;, and may be equal to one of the following values:

UNCHECKED40Indicates the file should be created without checking for the existence of a duplicate file in the associated directory.
GUARDED41Indicates the file should be created, but the server should check for the presence of a duplicate file before doing so. If the file exists, the open operation should fail with the error NFS4ERR_EXIST.
EXCLUSIVE42Indicates the file should be exclusively created, or created with the condition that no other client should be concurrently creating or opening a file with the same name. If a file with the same name does exist, the operation should fail with the error NFS4ERR_EXIST.

Note GUARDED4 only indicates that if the file already exists, the OPEN operation will fail. It does not imply exclusive creation, which would ensure only one client can create or open a file with a specific name at once. If the mentioned exclusive creation semantics cannot be supported by the file system, the OPEN operation should fail and NFS4ERR_NOTSUPP should be returned.

The ShareAccess parameter specifies the client's desired share access utilized when opening a file. This value may be equal to one of the following access flags:

OPEN4_SHARE_ACCESS_READ0x00000001Indicates the client desires read-only access to the file.
OPEN4_SHARE_ACCESS_WRITE0x00000002Indicates the client desires write-only access to the file.
OPEN4_SHARE_ACCESS_BOTH0x00000003Indicates the client desires both read and write access to the file.

In the case that there is an existing share reservation that conflicts with the request, NFS4ERR_SHARE_DENIED should be returned. If the underlying file system is only accessible in a read-only mode, and OPEN4_SHARE_ACCESS_WRITE or OPEN4_SHARE_ACCESS_BOTH are requested, NFS4ERR_ROFS should be returned to indicate a read-only file system.

The ShareDeny parameter defines the client's desired restrictions on share access for other clients when this file is open. This value may be equal to one of the following deny flags:

OPEN4_SHARE_DENY_NONE0x00000000Indicates no denial of share access to other clients while the file is open.
OPEN4_SHARE_DENY_READ0x00000001Indicates denial of read access to other clients while the file is open.
OPEN4_SHARE_DENY_WRITE0x00000002Indicates denial of write access to other clients while the file is open.
OPEN4_SHARE_DENY_BOTH0x00000003Indicates denial of both read and write access to other clients while the file is open.

Note that if OPEN4_SHARE_DENY_WRITE or OPEN4_SHARE_DENY_BOTH are specified and Unlink is fired while the object is still open, the application should not delete the file. If OPEN4_SHARE_DENY_NONE or OPEN4_SHARE_DENY_READ are specified and Unlink is fired while the object is still open, the application should delete the file.

Example: Opening or creating a file with share reservations

nfs.OnOpen += (o, e) => { string path = "C:\\NFSRootDir" + e.Path; FileStream fs = null; FileAccess shareAccess = (FileAccess)e.ShareAccess; // ShareAccess correlates directly with FileAccess FileShare shareDeny = 0; // ShareDeny does not correlate directly with FileShare, so let's translate ShareDeny to FileShare switch (e.ShareDeny) { case OPEN4_SHARE_DENY_BOTH: { shareDeny = FileShare.None; // Allow no access by other clients break; } case OPEN4_SHARE_DENY_WRITE: { shareDeny = FileShare.Read; // Allow read access by other clients break; } case OPEN4_SHARE_DENY_READ: { shareDeny = FileShare.Write | FileShare.Delete; // Allow write access and deletion by other clients break; } default: { // Default OPEN4_SHARE_DENY_NONE shareDeny = FileShare.ReadWrite | FileShare.Delete; // Allow read and write access and deletion by other clients break; } } FileMode createMode = FileMode.Open; if (e.OpenType == OPEN4_NOCREATE) { // The client wishes to open the file without creating it. If it doesn't exist, return NFS4ERR_NOENT, otherwise open with FileMode.Open. if (!File.Exists(e.Path)) { e.Result = NFS4ERR_NOENT; return; } } else { // The client wishes to create a file, with the specified CreateMode switch (e.CreateMode) { case UNCHECKED4: { createMode = FileMode.Create; // If a duplicate exists, no error is returned break; } default: { // Implies e.CreateMode == GUARDED4 || EXCLUSIVE4. If a duplicate exists, NFS4ERR_EXIST is returned if (File.Exists(path)) { e.Result = NFS4ERR_EXIST; return; } // Otherwise, proceed with creating the file. createMode = FileMode.CreateNew; break; } } } fs = File.Open(path, createMode, shareAccess, shareDeny); e.FileContext = (IntPtr)GCHandle.Alloc(fs); };

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

Read Event (NFS Component)

This event fires when a client attempts to read any part of a file.

Syntax

// NFSReadEventArgs carries the NFS Read event's parameters.
type NFSReadEventArgs struct {...}

func (args *NFSReadEventArgs) ConnectionId() int32
func (args *NFSReadEventArgs) Path() string
func (args *NFSReadEventArgs) FileContext() int64
func (args *NFSReadEventArgs) Buffer() []byte
func (args *NFSReadEventArgs) Count() int32
func (args *NFSReadEventArgs) SetCount(value int32)

func (args *NFSReadEventArgs) Offset() int64
func (args *NFSReadEventArgs) Eof() bool
func (args *NFSReadEventArgs) SetEof(value bool)

func (args *NFSReadEventArgs) Result() int32
func (args *NFSReadEventArgs) SetResult(value int32)

// NFSReadEvent defines the signature of the NFS Read event's handler function.
type NFSReadEvent func(sender *NFS, args *NFSReadEventArgs)

func (obj *NFS) GetOnReadHandler() NFSReadEvent
func (obj *NFS) SetOnReadHandler(handlerFunc NFSReadEvent)

Remarks

This event fires when a client attempts to read any part of a file, identified by the FileContext and/or Path parameters. Note this operation is subject to access permissions checking performed by the application.

The ConnectionId parameter indicates the client this information is required for.

To handle this event properly, applications should read up to Count bytes of data from the specified file into the byte array provided by Buffer. Reading must begin at the specified Offset in the file, and applications must not copy more than Count bytes into the buffer. Note the server may read less data than requested by the client, though this should only be done under particular circumstances, and will ultimately result in the client sending another read operation (unless EOF was reached) to finish reading the file data.

After the appropriate amount of data is read, the application must set the Count parameter to the number of bytes written to the buffer. The application should also update the last accessed time of the file upon a successful read.

If the EOF is reached (e.g., the offset and count are equal to or greater than the size of the file), the Eof parameter should be set to True.

If Count is specified by the client as 0, this value should remain unchanged and the operation should succeed subject to permissions checking. No data should be returned (Buffer should be empty), and the operation should return success.

If Offset is greater than or equal to the size of the file, Count should be set to 0, Eof should be set to True, and the operation should succeed.

If mandatory byte-range locking is in effect, and the current file has a write lock held by another client that conflicts with the data to be read, the operation should fail and Result should be set to NFS4ERR_LOCKED.

Example: Reading data from a file nfs.OnRead += (o, e) => { if (e.Count == 0) { return; } try { IntPtr p = e.FileContext; GCHandle h = (GCHandle)p; FileStream fs = h.Target as FileStream; if (e.Offset >= fs.Length) { e.Count = 0; e.Eof = true; return; } fs.Position = e.Offset; int count = fs.Read(e.BufferB, 0, e.Count); // If EOF was reached, notify the client if (fs.Position == fs.Length) { e.Eof = true; } else { e.Eof = false; } // Return number of bytes read e.Count = c; } catch (Exception ex) { e.Result = NFS4ERR_IO; } };

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

ReadDir Event (NFS Component)

This event fires when a client attempts to list the contents of a directory.

Syntax

// NFSReadDirEventArgs carries the NFS ReadDir event's parameters.
type NFSReadDirEventArgs struct {...}

func (args *NFSReadDirEventArgs) ConnectionId() int32
func (args *NFSReadDirEventArgs) FileContext() int64
func (args *NFSReadDirEventArgs) SetFileContext(value int64)

func (args *NFSReadDirEventArgs) Path() string
func (args *NFSReadDirEventArgs) Cookie() int64
func (args *NFSReadDirEventArgs) Result() int32
func (args *NFSReadDirEventArgs) SetResult(value int32)

// NFSReadDirEvent defines the signature of the NFS ReadDir event's handler function.
type NFSReadDirEvent func(sender *NFS, args *NFSReadDirEventArgs)

func (obj *NFS) GetOnReadDirHandler() NFSReadDirEvent
func (obj *NFS) SetOnReadDirHandler(handlerFunc NFSReadDirEvent)

Remarks

This event fires when a client attempts to list the contents of a directory, identified by the Path parameter. Similar to Open, the application may use the FileContext parameter to store a handle or other information related to the directory.

The FileContext parameter is initially IntPtr.Zero when a directory listing begins, as indicated by a Cookie value of 0. In this case, the application may assign this parameter for future reference, as the directory listing operation could span multiple ReadDir events. See below for more information regarding this case. Note that if all directory entries have been listed, the FileContext should be freed and set to IntPtr.Zero before ReadDir returns.

The ConnectionId parameter indicates the client requesting the directory information.

The Cookie parameter represents where the application should start reading entries from within the directory. A cookie value of 0 is used by the client to start reading at the beginning of the directory. Please see FillDir and below for more details regarding non-zero cookie values.

To handle this event properly, the application must call the FillDir method for each existing entry within the associated directory. Doing so will buffer the relevant directory entry information to be sent to the client upon the return of this event.

Note when listing a directory, the client will specify a limit on the amount of data (or number of entries) to return in a single response. To handle this, the application should analyze the returned value of each call to FillDir within this event to ensure the limit is not exceeded. A non-zero return value indicates that the most recent call to FillDir would have caused the application to send more data than the limit specified by the client. In this case, the event should return immediately with a Result of NFS4_OK.

Afterwards, the client will send subsequent requests to continue retrieving entries. In these requests, the Cookie parameter will be equal to the cookie value the application specified in the last successful entry provided by FillDir. Note that the cookie value provided in FillDir and the Cookie parameter specified by the client are only meaningful to the server. The cookie values should be interpreted and utilized as a "bookmark" of the directory entry, indicating a point for continuing the directory listing.

Note if a single directory entry is unable to be returned by the application within this operation, the event should return immediately with a Result of NFS4ERR_TOOSMALL. Please see FillDir for further details. Additionally, please see below for a simple implementation of ReadDir.

Example: Starting or continuing a directory listing

int baseCookie = 0x12345678; nfs.OnReadDir += (o, e) => { int dirOffset = 0; // Initial directory offset // Arbitrary base cookie to start at for listing directory entries. // On calls to FillDir, this value will be incremented, so subsequent READDIR operations can resume from a specified cookie. long cookie = baseCookie; // If e.Cookie == 0, we start listing from the beginning of the directory. // Otherwise, we start listing from the offset indicated by this parameter. if (e.Cookie != 0) { offset = e.Cookie - baseCookie + 1; cookie = e.Cookie + 1; } string path = "C:\\NFSRootDir" + e.Path; var entries = Directory.GetFileSystemEntries(path, "*", SearchOption.TopDirectoryOnly); // Iterate through all directory entries. // dirOffset indicates the next entry to be listed given the client's provided Cookie. for (int i = dirOffset; i < entries.Length; i++) { string name = Path.GetFileName(entries[i]); bool isDir = Directory.Exists(entries[i]); int result = 0; if (isDir) { int fileMode = S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; // Indicates file type (S_IFDIR) and permissions (755) result = nfs.FillDir(e.ConnectionId, name, cookie++, fileMode, "OWNER", "OWNER_GROUP", 1, 4096, new DirectoryInfo(path).LastAccessTime, new DirectoryInfo(path).LastWriteTime, new DirectoryInfo(path).CreationTime); } else { int fileMode = S_IFREG | S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH; // Indicates file type (S_IFREG) and permissions (644). result = nfs.FillDir(e.ConnectionId, name, cookie++, fileMode, "OWNER", "OWNER_GROUP", 1, FileInfo(path).Length, new FileInfo(path).LastAccessTime, new FileInfo(path).LastWriteTime, new FileInfo(path).CreationTime); } // Return if FillDir returned non-zero value (client's entry limit has been reached) if (result != 0) { // No entries were returned, set Result in this case to alert client if (i == dirOffset) { e.Result = NFS4ERR_TOOSMALL; } return; } } };

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

Rename Event (NFS Component)

This event fires when a client attempts to rename or move an object.

Syntax

// NFSRenameEventArgs carries the NFS Rename event's parameters.
type NFSRenameEventArgs struct {...}

func (args *NFSRenameEventArgs) ConnectionId() int32
func (args *NFSRenameEventArgs) OldPath() string
func (args *NFSRenameEventArgs) NewPath() string
func (args *NFSRenameEventArgs) Result() int32
func (args *NFSRenameEventArgs) SetResult(value int32)

// NFSRenameEvent defines the signature of the NFS Rename event's handler function.
type NFSRenameEvent func(sender *NFS, args *NFSRenameEventArgs)

func (obj *NFS) GetOnRenameHandler() NFSRenameEvent
func (obj *NFS) SetOnRenameHandler(handlerFunc NFSRenameEvent)

Remarks

This event fires when a client attempts to rename or move an object from OldPath to NewPath.

If OldPath and NewPath refer to the same object, the application should perform no action and return success immediately.

The ConnectionId parameter indicates the client attempting to rename the file or directory.

If an entry already exists with the name NewPath, the source object must be compatible with the target. To clarify, to be compatible, either both objects must be non-directories, or both objects must be directories. If both objects are directories, the target must be empty.

Assuming the objects are compatible, the existing target is removed before the rename (or move) occurs.

If the objects are incompatible, or if the target is a directory but not empty, the application must set Result to NFS4ERR_EXIST.

Example: Renaming a file or directory nfs.OnRename += (o, e) => { string oldPath = "C:\\NFSRootDir" + e.OldPath; string newPath = "C:\\NFSRootDir" + e.NewPath; // Check if oldPath and newPath refer to the exact same file. If so, return successfully. if (oldPath.Equals(newPath)) { return; } // Check whether oldPath is a file or directory if (Directory.Exists(oldPath)) { // oldPath is a directory. Check for incompatible rename operation. if (File.Exists(newPath)) { // Incompatible, Directory -> File e.Result = NFS4ERR_EXIST; return; } // Check if target directory exists. If so, check the number of files in this directory. int fileCount = 0; if (Directory.Exists(newPath)) { fileCount = Directory.GetFiles(newPath, "*", SearchOption.TopDirectoryOnly).Length; } // If files exist in the target directory, return error. if (fileCount == 0) { Directory.Move(oldPath, newPath); } else { e.Result = NFS4ERR_EXIST; } } else { // oldPath is a file. Check for incompatible rename operation. if (Directory.Exists(newPath)) { // Incompatible, File -> Directory e.Result = NFS4ERR_EXIST; return; } if (File.Exists(newPath)) { File.Delete(newPath); } File.Move(oldPath, newPath); } };

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

RmDir Event (NFS Component)

This event fires when a client attempts to remove a directory.

Syntax

// NFSRmDirEventArgs carries the NFS RmDir event's parameters.
type NFSRmDirEventArgs struct {...}

func (args *NFSRmDirEventArgs) ConnectionId() int32
func (args *NFSRmDirEventArgs) Path() string
func (args *NFSRmDirEventArgs) Result() int32
func (args *NFSRmDirEventArgs) SetResult(value int32)

// NFSRmDirEvent defines the signature of the NFS RmDir event's handler function.
type NFSRmDirEvent func(sender *NFS, args *NFSRmDirEventArgs)

func (obj *NFS) GetOnRmDirHandler() NFSRmDirEvent
func (obj *NFS) SetOnRmDirHandler(handlerFunc NFSRmDirEvent)

Remarks

This event fires when a client attempts to remove a directory, identified by the Path parameter.

The ConnectionId parameter indicates the client attempting to delete the directory.

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

Truncate Event (NFS Component)

This event fires when a client attempts to modify a file's size attribute.

Syntax

// NFSTruncateEventArgs carries the NFS Truncate event's parameters.
type NFSTruncateEventArgs struct {...}

func (args *NFSTruncateEventArgs) ConnectionId() int32
func (args *NFSTruncateEventArgs) Path() string
func (args *NFSTruncateEventArgs) FileContext() int64
func (args *NFSTruncateEventArgs) Size() int64
func (args *NFSTruncateEventArgs) Result() int32
func (args *NFSTruncateEventArgs) SetResult(value int32)

// NFSTruncateEvent defines the signature of the NFS Truncate event's handler function.
type NFSTruncateEvent func(sender *NFS, args *NFSTruncateEventArgs)

func (obj *NFS) GetOnTruncateHandler() NFSTruncateEvent
func (obj *NFS) SetOnTruncateHandler(handlerFunc NFSTruncateEvent)

Remarks

This event fires when a client attempts to modify a file's size attribute, identified by the FileContext and/or Path parameters.

The ConnectionId parameter indicates the client attempting to truncate the file.

The Size parameter indicates the desired value the client wishes to set the NFSv4.0 size attribute to.

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

Unlink Event (NFS Component)

This event fires when a client attempts to unlink (or delete) a file.

Syntax

// NFSUnlinkEventArgs carries the NFS Unlink event's parameters.
type NFSUnlinkEventArgs struct {...}

func (args *NFSUnlinkEventArgs) ConnectionId() int32
func (args *NFSUnlinkEventArgs) Path() string
func (args *NFSUnlinkEventArgs) Result() int32
func (args *NFSUnlinkEventArgs) SetResult(value int32)

// NFSUnlinkEvent defines the signature of the NFS Unlink event's handler function.
type NFSUnlinkEvent func(sender *NFS, args *NFSUnlinkEventArgs)

func (obj *NFS) GetOnUnlinkHandler() NFSUnlinkEvent
func (obj *NFS) SetOnUnlinkHandler(handlerFunc NFSUnlinkEvent)

Remarks

This event fires when a client attempts to unlink (or delete) a file, identified by the Path parameter.

The ConnectionId parameter indicates the client attempting to delete the file.

Note the file may still be open when this event fires. In this case, the application should not delete the file if the file was opened with OPEN4_SHARE_DENY_WRITE or OPEN4_SHARE_DENY_BOTH (see Open for additional details). If the file was opened with OPEN4_SHARE_DENY_NONE or OPEN4_SHARE_DENY_READ, the application should delete the file.

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

Unlock Event (NFS Component)

This event fires when a client attempts to release a lock.

Syntax

// NFSUnlockEventArgs carries the NFS Unlock event's parameters.
type NFSUnlockEventArgs struct {...}

func (args *NFSUnlockEventArgs) ConnectionId() int32
func (args *NFSUnlockEventArgs) Path() string
func (args *NFSUnlockEventArgs) FileContext() int64
func (args *NFSUnlockEventArgs) LockType() int32
func (args *NFSUnlockEventArgs) LockOffset() int64
func (args *NFSUnlockEventArgs) LockLen() int64
func (args *NFSUnlockEventArgs) Result() int32
func (args *NFSUnlockEventArgs) SetResult(value int32)

// NFSUnlockEvent defines the signature of the NFS Unlock event's handler function.
type NFSUnlockEvent func(sender *NFS, args *NFSUnlockEventArgs)

func (obj *NFS) GetOnUnlockHandler() NFSUnlockEvent
func (obj *NFS) SetOnUnlockHandler(handlerFunc NFSUnlockEvent)

Remarks

This event fires when a client attempts to release a lock, indicated by the FileContext and/or Path parameters.

The ConnectionId parameter indicates the client requesting to release the lock.

The LockOffset parameter specifies the position (or byte) within the file where the unlock should begin at. The LockLen parameter specifies the number of bytes that should be unlocked after the specified offset, effectively creating a range of bytes to unlock. If the LockLen parameter is 0, the application should return NFS4ERR_INVAL. If the LockLen parameter is -1, this indicates the client wishes to lock all bytes from the specified LockOffset to the end of the file.

The LockType parameter indicates the type of lock used on the file (read or write, blocking or non-blocking). Please see Lock for possible values. This parameter should not affect the success or failure of this operation.

If the LockOffset and LockLen parameters do not correspond exactly to a lock held by the client, NFS4ERR_LOCK_RANGE may be returned.

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

Utimens Event (NFS Component)

This event fires when a client attempts to change a file's last access time, last modification time, or both.

Syntax

// NFSUtimensEventArgs carries the NFS Utimens event's parameters.
type NFSUtimensEventArgs struct {...}

func (args *NFSUtimensEventArgs) ConnectionId() int32
func (args *NFSUtimensEventArgs) Path() string
func (args *NFSUtimensEventArgs) FileContext() int64
func (args *NFSUtimensEventArgs) ATime() time.Time
func (args *NFSUtimensEventArgs) MTime() time.Time
func (args *NFSUtimensEventArgs) Result() int32
func (args *NFSUtimensEventArgs) SetResult(value int32)

// NFSUtimensEvent defines the signature of the NFS Utimens event's handler function.
type NFSUtimensEvent func(sender *NFS, args *NFSUtimensEventArgs)

func (obj *NFS) GetOnUtimensHandler() NFSUtimensEvent
func (obj *NFS) SetOnUtimensHandler(handlerFunc NFSUtimensEvent)

Remarks

This event fires when a client attempts to change a file's access time, modification time, or both.

The ConnectionId parameter indicates the client attempting to modify these values.

The ATime parameter indicates the desired value the client wishes to set the NFSv4.0 time_access attribute to.

The MTime parameter indicates the desired value the client wishes to set the NFSv4.0 time_modify attribute to.

Note that if the ATime or MTime parameter is equal to the smallest possible time allowed for the given parameter type, the client does not wish to modify the associated attribute and the parameter should be ignored.

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

Write Event (NFS Component)

This event fires when a client attempts to write data to a file.

Syntax

// NFSWriteEventArgs carries the NFS Write event's parameters.
type NFSWriteEventArgs struct {...}

func (args *NFSWriteEventArgs) ConnectionId() int32
func (args *NFSWriteEventArgs) Path() string
func (args *NFSWriteEventArgs) FileContext() int64
func (args *NFSWriteEventArgs) Offset() int64
func (args *NFSWriteEventArgs) Buffer() []byte
func (args *NFSWriteEventArgs) Count() int32
func (args *NFSWriteEventArgs) SetCount(value int32)

func (args *NFSWriteEventArgs) Stable() int32
func (args *NFSWriteEventArgs) SetStable(value int32)

func (args *NFSWriteEventArgs) Result() int32
func (args *NFSWriteEventArgs) SetResult(value int32)

// NFSWriteEvent defines the signature of the NFS Write event's handler function.
type NFSWriteEvent func(sender *NFS, args *NFSWriteEventArgs)

func (obj *NFS) GetOnWriteHandler() NFSWriteEvent
func (obj *NFS) SetOnWriteHandler(handlerFunc NFSWriteEvent)

Remarks

This event fires when a client attempts to write data to a file, identified by the FileContext and/or Path parameters. Note this operation is subject to access permissions checking performed by the application.

The ConnectionId parameter indicates the client writing to a file.

To handle this event properly, applications should write Count bytes of data from the byte array specified by Buffer to the relevant file. Writing must begin at the indicated Offset in the file. Note the server may write less data than requested by the client.

After the appropriate amount of data is written, the application must set the Count parameter to the number of bytes written to the relevant file.

If Count is specified by the client as 0, this value should remain unchanged and the operation should succeed (subject to permissions checking). In this case, the application should also ensure the modified time of the file is not changed.

The Stable parameter is specified by the client to indicate how the write operation should be performed, or how the data should be committed by the application. This parameter may be equal to one of the following values as specified by the connection:

UNSTABLE40Indicates the application is free to commit any part of the data written and filesystem metadata before returning any results.
DATA_SYNC41Indicates the application must commit all of the data to stable storage and enough filesystem metadata to retrieve the data before returning any results.
FILE_SYNC42Indicates the application must commit the data written plus all filesystem metadata to stable storage before returning any results.

The application must also specify the level of commitment fulfilled and can do so by modifying the Stable parameter to one of the above values. Note that the level of commitment must at least be as strong as the value specified in Stable (with FILE_SYNC4 being the strongest and UNSTABLE4 being the weakest). A returned level of commitment less than the provided value of Stable constitutes a protocol violation.

Assuming UNSTABLE4 or DATA_SYNC4 are returned by the application, it can be expected that the client will follow up to ensure the data and metadata are written to stable storage. In this case, Commit will fire.

If mandatory byte-range locking is in effect, and the current file has a read or write lock held by another client that conflicts with the data to be written, the operation should fail and Result should be set to NFS4ERR_LOCKED.

Example: Writing data to a file nfs.OnWrite += (o, e) => { if (e.Count == 0) { return; } try { IntPtr p = e.FileContext; GCHandle h = (GCHandle)p; FileStream fs = h.Target as FileStream; fs.Position = e.Offset; fs.Write(e.BufferB, 0, e.Count); fs.Flush(); // All data was written to disk, indicate this via Stable. e.Stable = FILE_SYNC4; } catch (Exception ex) { e.Result = NFS4ERR_IO; } };

The Result parameter will always be 0 (NFS4_OK) when this event fires. If the event cannot be handled successfully, set it to a nonzero value to report an appropriate error. Possible Result codes and their descriptions are listed in the NFS Result Codes section. Additional information regarding these result codes may be found in RFC 7530 Section 13.

Config Settings (NFS Component)

The component accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

NFS Config Settings

AllowedClients:   A comma-separated list of host names or IP addresses that can access the component.

This configuration setting defines a comma-separated list of host names or IPv4 addresses that may access the component. The wildcard character "*" is supported. The default value is "*" and all connections are accepted.

When a client connects, the client's address is checked against the list defined here. If there is no match, the ConnectionRequest event fires with an Accept value set to False. If no action is taken within the ConnectionRequest event, the client will be disconnected.

BindExclusively:   Whether or not the component considers a local port reserved for exclusive use.

If this is True (default), the component will bind to the local port with the ExclusiveAddressUse option set, meaning that nothing else can bind to the same port. Also the component will not be able to bind to local ports that are already in use by some other instance, and attempts to do so will result in failure.

BlockedClients:   A comma-separated list of host names or IP addresses that cannot access the component.

This configuration setting defines a comma-separated list of host names or IPv4 addresses that cannot access the component.The default value is "" and all connections are accepted.

When a client connects, the client's address is checked against the list defined here. If there is a match, the ConnectionRequest event fires with an Accept value set to False. If no action is taken within the ConnectionRequest event, the client will not be connected.

ClientAuthUID:   Specifies a client's authentication UID for use during authentication.

This configuration specifies a client's authentication UID. This may be set to enable authentication for a single user. Upon an authentication request, the server will compare this UID with that provided by the connection. If equal, the authentication request will succeed.

ConnectionUID:   The unique connectionId for a connection.

Connection Ids may be reused as clients connect and disconnect. Querying ConnectionUID will return a unique identifier for that connection Id. If the specified connection Id does not exist, then ConnectionUID will return 0. For example:

Connection5UID = obj.config("ConnectionUID[5]")

DefaultConnectionTimeout:   The inactivity timeout applied to the SSL handshake.

This configuration setting specifies the inactivity (in seconds) to apply to incoming Secure Sockets Layer (SSL) connections. When set to a positive value, if the other end is unresponsive for the specified number of seconds, the connection will timeout. This is not applicable to the entire handshake. It is applicable only to the inactivity of the connecting client during the handshake if a response is expected and none is received within the timeout window. The default value is 0, and no connection-specific timeout is applied.

Note: This is applicable only to incoming SSL connections. This should be set only if there is a specific reason to do so.

InBufferSize:   The size in bytes of the incoming queue of the socket.

This is the size of an internal queue in the Transmission Control Protocol (TCP)/IP stack. You can increase or decrease its size depending on the amount of data that you will be receiving. Increasing the value of the InBufferSize setting can provide significant improvements in performance in some cases.

Some TCP/IP implementations do not support variable buffer sizes. If that is the case, when the component is activated, the InBufferSize reverts to its defined size. The same thing will happen if you attempt to make it too large or too small.

InBufferSize is shared among incoming connections. When the property is set, the corresponding value is set for incoming connections as they are accepted. Existing connections are not modified.

KeepAliveInterval:   The retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received.

A TCP keep-alive packet will be sent after a period of inactivity, as defined by KeepAliveTime. If no acknowledgment is received from the remote host, the keep-alive packet will be sent again. This setting specifies the interval at which the successive keep-alive packets are sent in milliseconds. If this value is not specified here, the system default is 1 second. This setting is applicable to all connections.

Note: This value is not applicable in macOS.

KeepAliveRetryCount:   The number of keep-alive packets to be sent before the remotehost is considered disconnected.

A TCP keep-alive packet will be sent after a period of inactivity, as defined by KeepAliveTime. If no acknowledgment is received from the remote host, the keep-alive packet will be sent again. This setting specifies the number of times that the keep-alive packets will be sent again before the remote host is considered disconnected. If this value is not specified here, the system default is 9.

Note: This configuration setting is available only in the Unix platform, and it is not supported in macOS or FreeBSD.

KeepAliveTime:   The inactivity time in milliseconds before a TCP keep-alive packet is sent.

By default, the operating system will determine the time a connection is idle before a TCP keep-alive packet is sent. If this value is not specified here, the system default is 2 hours. In many cases, a shorter interval is more useful. Set this value to the desired interval in milliseconds. This setting is applicable to all connections.

LogLevel:   Specifies the level of detail that is logged.

This configuration controls the level of detail that is logged through the Log event. Possible values are:

0 (None)No messages are logged.
1 (Info - Default)Informational events are logged.
2 (Verbose)Detailed data is logged.
3 (Debug)Debug data including all relevant sent and received NFS operations are logged.
MaxConnections:   The maximum number of connections available.

This is the maximum number of connections available. This property must be set before Listening is set to True, and once set, it can no longer be changed for the current instance of the component. The maximum value for this setting is 100,000 connections. Use this setting with caution. Extremely large values may affect performance. The default value is 1000.

Note: Unix/Linux operating systems limit the number of simultaneous connections to 1024.

MaxReadTime:   The maximum time spent reading data from each connection.

This setting specifies the maximum time in milliseconds that the component will spend reading data from a particular connection before servicing other connections. When a single client is sending data to the component at a high rate this setting is used to ensure that other connections are serviced in a timely manner. Specifying a positive value prevents a single client from monopolizing the component's resources. The special value of 0 indicates no limit and is generally not recommended.

The default value is 50 (milliseconds).

MountPoint:   A path to an empty directory to mount the NFS server to.

This configuration setting makes it possible for an application to automatically mount the NFS server as a local directory. For this, set the value to point to an empty directory, to which the connection will be mounted.

This setting works on Linux and macOS. On Windows, this setting is not used due to the lack of the NFS 4 client in Windows.

OutBufferSize:   The size in bytes of the outgoing queue of the socket.

This is the size of an internal queue in the TCP/IP stack. You can increase or decrease its size depending on the amount of data that you will be sending. Increasing the value of the OutBufferSize setting can provide significant improvements in performance in some cases.

Some TCP/IP implementations do not support variable buffer sizes. If that is the case, when the component is activated the OutBufferSize reverts to its defined size. The same thing will happen if you attempt to make it too large or too small.

OutBufferSize is shared among incoming connections. When the property is set, the corresponding value is set for incoming connections as they are accepted. Existing connections are not modified.

SpaceAvail:   Specifies the amount of space available on the server, in bytes.

This configuration specifies the amount of space available on the server, in bytes. By default, this configuration is equal to the maximum value of a long. Setting this value will limit the amount of total space available for connections.

SpaceUsed:   Specifies the amount of space used by the current filesystem object, in bytes.

This configuration specifies the amount of space used by the current filesystem object, in bytes. This value is 0 by default and may be set to the size (in bytes) of the filesystem object currently being used.

UseIOCP:   Whether to use the completion port I/O model.

The default value is False. When set to True, the component will use an I/O Completion Port (IOCP) to manage operations on sockets. A single completion port allows the asynchronous notification of network events on an entire group of sockets. This property must be set before Listening is set to True.

Nothing else is required to begin accepting IOCP connections. One major benefit to using this model is that there will be no thread blocked waiting for a request to complete. The system notifies the process through an Asynchronous Procedure Call (APC) once the device driver finishes servicing the I/O request. IOCP allows a single I/O worker thread handle multiple clients' input/output "fairly".

Note: When set to True, this setting will automatically set UseWindowsMessages to False.

UseIPv6:   Whether to use IPv6.

When set to 0 (default), the component will use IPv4 exclusively. When set to 1, the component will use IPv6 exclusively. When set to 2, the component will listen for both IPv4 and IPv6 connections. If IPv6 is not available on the system, only IPv4 will be used. The default value is 0. Possible values are as follows:

0 IPv4 Only
1 IPv6 Only
2 IPv6 and IPv4
UseWindowsMessages:   Whether to use the WSAAsyncSelect I/O model.

The default value is True, and the component will receive a Windows message-based notification of network events. Turning on Windows message notifications allows the application to get connect, send, receive, and socket closure network event notifications on a socket. This property must be set before Listening is set to True.

Nothing else is required to begin accepting connections using the Windows message queue. In high-traffic environments, messages will be discarded if the queue is full. Additionally, because a single window procedure will service all events on thousands of sockets, the Windows message queue is not scalable from a performance perspective.

If this setting is set to False, the component will instead use the Winsock select model instead.

Base Config Settings

BuildInfo:   Information about the product's build.

When queried, this setting will return a string containing information about the product's build.

LicenseInfo:   Information about the current license.

When queried, this setting will return a string containing information about the license this instance of a component is using. It will return the following information:

  • Product: The product the license is for.
  • Product Key: The key the license was generated from.
  • License Source: Where the license was found (e.g., RuntimeLicense, License File).
  • License Type: The type of license installed (e.g., Royalty Free, Single Server).

Trappable Errors (NFS Component)

NFS Errors

104   The component is already listening.
106   Cannot change LocalPort when NFSServer is listening.
107   Cannot change LocalHost when NFSServer is listening.
126   Invalid ConnectionId.
500   Invalid Cookie specified in FillDir (0, 1, or 2).