RFB Raw Block Transfer Protocol Extension

Author: Ian Reinhart Geiser <geiseri@yahoo.com>
Version: 0.1 (Draft)

Table of Contents

1   Protocol overview

This is the specification extends the core RFB specification to allow a RFB server to read and write blocks from a clients local file system. File access is done in server defined data blocks. This block based approach enables the server to access only the parts of the file that it requires and to interleave block messages with other RFB messages.

The client can have multiple numbers of shared local directories. It will advertise these to the server where the user can decide the share they wish to access. The server will provide some sort of user space application or device driver to present the remote files to the user. The server will then communicate with the VNC server to forward the request to the client over the RFB connection. The client in turn will use the local file system APIs to perform the file system operation. Once the operation is complete the client will send a response back to the server over the RFB connection. The server will then interpret this response and will forward this response to the user space application.

It is recommended that the server exposes shares via a local device driver so that it will closely mirror a normal physical file system. It is the server's responsibility though to provide some sort of security to limit access the the share to the currently attached client. This behavior is up to the server implementations to further define. This protocol accounts for multiple shared to be provided to the server, but it is the server's prerogative whether to allow this feature. To accommodate the lowest common denominator of file system's volume names are limited to 11 characters not including a trailing null character. It is the servers responsibility to enforce this either by truncating the name or not accepting the share.

Server implementations may use some sort of cache system provided it follow the semantics of a write through cache. This cache will always be considered valid for reads, but any writes performed must be transfered to the client immediately. To accommodate this behavior it is recommended that if possible file system modifications from outside of the RFB client be prohibited. If a file is modified outside of client the server and the client may become out of sync. This could result in a corrupt file on the client file system.

1.1   Transaction IDs

This protocol is intended to be completely asynchronous. To facilitate this each message that requires a response contains a transaction identifier (transaction-id). These identifiers allow messages to pair themselves back together in an asynchronous manner. These must be unique for all messages currently being sent and received.

2   File sharing session overview

2.1   Handshake sequence

When the client attaches initially and sends the supported encoding it will add the RFB_BLOCK_XFR (???) to the list of supported encodings. If the server supports this encoding the following sequence will take place:

  1. The server sends a Request enable share message when the server is ready to handle file transfers. This is usually when the server has started and the file system driver is ready.
  2. Once the client has received the Request enable share message it will respond by sending Client enable share message messages for each of the local directories that are to be shared. These messages will contain a unique identifier to identify the device to the local system.
  3. When the file system driver requests access to a share it sends a Request share open message for the specific share.
  4. The client will respond to the Request share open message with a Share open result message. This will contain the label for the remote server to display as well as if the share is to be read only. In the event of an error status will be set to a non-zero number, otherwise on success it will remain 0.
  5. At this point the share should be considered configured so Directory access and File access parts of the protocol may be used.

2.2   Directory access

To traverse the local file system the Request directory info message will provide the contents of a specific path relative to the root of the share. This closely mirrors the behavior of running stat on each directory entry item of a specific path. The information returned is only a subset of the client file system because it must suit the lowest common denominator of file system features.

Directories may be created, removed or moved on the local file system. This operation may or may not succeed when the file system is in use.1

2.3   File access

It is the responsibility of the client to manage the actual creation, tear down and freeing of local resources. It is the servers responsibility to manage the lifetime of the access to the file. When the file system driver requests access to a specific file the following sequence will take place:

  1. The server issues a Request open file message. The client will then respond back with a Open file response message that will contain either a valid file handle or a specific error status. Open requests can be called multiple times on a file in read only mode. Each time a unique file handle is returned. Open requests may be called multiple times on a file in read/write mode, but the behavior of this is undefined and is discouraged.
  2. Once the client has responded to the server with the file handle Request read file block message and Request write file block message operations can be performed.
  3. To notify the client that the server is finished accessing the file it will send a Request close file message. This is non blocking on the server end and it is discarded from the server. If this method is not called the resources referenced by the file-id could be left open on the client.

Files can be removed or moved by an absolute path based off of the root of the shared folder. The underlying client file system may or may not succeed if the file is currently in use.1

Symbolic links are not supported so if the server requests that a symbolic link be created it will result in an error. On the client symbolic links are not to be presented to the server in directory listings or in file open requests.

2.4   Ending the session

There are two ways that the share can be removed from the server. The first is that the server can request the share be removed using the Request share close message. This is usually called when the server's file system driver unmounts the share. This can also happen during shutdown of the server to ensure the client can cleanly tear things down. The second way is that the client can send a Client disable share message to the server. The server will then respond back with a Request share close message after notifying the file system driver and performing any cleanup tasks that must happen on the server to cleanly remove the share. The client must keep the share active until the Request share close message is received from the server.

In the event that the connection is severed during the session it is the server and the client's responsibility to clean up resources and notify the user of the error.

3   Protocol messages

3.2   Common message properties

message-type
This is the message ID for the block transfer extension.
message-sub-type
This is the sub-message ID declaring the type of block transfer message this is. These are defined in the Message list.
transaction-id
This is the transaction ID specified by the server. This must be returned with the client's response to a message so that the server can match up the request and response. This is described more in the Transaction IDs section.

3.3   Request enable share message

If the server supports block transfers it will respond to the client asking for its shares. This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
1 U8 10 message-sub-type

3.4   Client enable share message

This message is sent from the client in response to the to the Request enable share message declaring that there is a new share available. The server will then respond with a Request share open message message. This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
1 U8 10 message-sub-type
1 U8   local-fs-identifier
local-fs-identifier
This is the local index of the share used to pair the Request share open message back with the correct share.

3.5   Client disable share message

This message is sent to notify the server that the share wishes to be removed. The actual share is not removed from the client though until the server responds back with a Request share close message.

No. of bytes Type Value Description
1 U8 249 message-type
1 U8 12 message-sub-type
1 U8   local-fs-identifier

3.6   Request share open message

This message is sent from the server to the client requesting that a share is ready to be accessed by the server. The local-fs-identifier must match one of the shares specified in the Client enable share message. This should only succeed once, multiple requests to an already opened share message should return an error status. This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
1 U8 11 message-sub-type
4 U32   transaction-id
1 U8   local-fs-identifier

3.7   Share open result message

This message is sent from the client to the server as a response to a Client enable share message. This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 11 message-sub-type
4 U32   transaction-id
1 U8   open-status
1 U8   share-label-length
share-label-length U8 array   share-label
1 U8   read-only-flag
4 U32   share-size
open-status
The status code of the result. 0 for success, nonzero for any errors encountered during the operations the client needs to perform to make the share ready for access.
share-label-length
This is the length of the label. This number is in a range of 1 to 11 characters. Because of portability there is a hard limit of 11 characters.
share-label
The actual label for the share.
read-only-flag
A flag showing if the share is read only.
share-size
The total size of the share as it will be exposed to the server. This is really the maximum size of the share, and usually will be the size of the volume the share resides on.

3.8   Request share status message

This message is sent from the server to query the client about file system statistics of a specific share. The share must be open before this message can be sent. This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 22 message-sub-type
4 U32   transaction-id
1 U8   local-fs-identifier

3.9   Share status response message

This message contains the local file system information for a specific share. If the resulting data is valid a status of 0 is returned along with the file system data. In the event of a non-zero response the following errors are defined:

Status Description
1 Share not open.
2 Underlying file system error.
3 Undefined error

This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 22 message-sub-type
4 U32   transaction-id
1 U32   status
2 U16   block-size
4 U32   total-blocks
4 U32   free-blocks
4 U32   total-files
block-size
The size of individual file blocks on the share.
total-blocks
The total number of blocks on the share. The client may choose to expose less blocks than the underlying share's volume to the server.
free-blocks
The number of unused blocks on the share.
total-files
The total number of files on the share.

3.10   Request share close message

This message is sent from the server to notify the client that the share is no longer needed. This is useful if the remote host would like to "eject" the media and re-open it as a different volume. The local-fs-identifier must match one of the shares specified in the Client enable share message. This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 12 message-sub-type
1 U8   local-fs-identifier

3.11   Generic status response message

This is a generic response message for operations that just need to report back a status of the last operation. This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 20 message-sub-type
4 U32   transaction-id
1 U8   status
status
Reports the result of an operation. A status of 0 is always a success, and any nonzero number is considered an error. These non-zero numbers can later be defined by specific messages.

3.12   Request directory info message

This message requests file system information for a specific path. This path is defined as being based off of the root of the share. So for example if the share is providing the local path of /home/user/Documents and the host would like to see the entries for that share it would ask for the path /. It is important to note that the paths supplied to the client use the Unix style of path separators. This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 13 message-sub-type
4 U32   transaction-id
4 U32   path-length
path-length U8 array   path
path-length
The size of the path string.
path
The specific path to retrieve directory information on.

3.13   Directory info response message

This message contains high level file system information for each child entry in a path. It is the client's responsibility to ensure the underlying read of the directory has returned before it returns the result.2 If there is a non-zero status the errors are as follows:

Status Description
1 Permission denied.
2 Path not found.
3 Undefined error

This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 13 message-sub-type
4 U32   transaction-id
1 U8   status
4 U32   entry-count

followed by entry-count repetitions of the following:

No. of bytes Type Value Description
1 U8   is-dir
1 U8   file-name-length
file-name-length U8 array   file-name
1 U8   attributes
4 U32   create-time
4 U32   last-access-time
4 U32   last-modify-time
4 U32   size
entry-count
The number of entries in the current path. This includes the entries for . and ...
is-dir
Reports if the current entry is a directory or not. At this point the protocol only understands Directories and Files. Other files are not currently exposed at this time. Hidden and system files will be exposed though, and it is up to the host to use the attributes field to decide if the entry is to be displayed.
file-name-length
The length of the current filename.
file-name
The name of the entry. This is the absolute path as seen from the root of the share.
attributes

A bit mask of the attributes that this file contains. This protocol only supports exporting very limited sets of attributes. Currently they are as follows:

Value Description
1 The file is readable
2 The file is writable
4 The file is hidden
8 The file is executable
create-time
The date and time the file was created. This is expressed as the number of seconds that have passed since 1970-01-01T00:00:00, UTC. On most Unix based clients, this function returns the time of the last status change. A status change occurs when the file is created, but it also occurs whenever the user writes or sets inode information (for example, changing the file permissions). If neither creation time nor "last status change" time are not available, returns the same as the last-modify-time message.
last-access-time
The date and time the file was last modified. This is expressed as the number of seconds that have passed since 1970-01-01T00:00:00, UTC.
last-modify-time
The date and time the file was last accessed. This is expressed as the number of seconds that have passed since 1970-01-01T00:00:00, UTC. On clients where this information is not available, returns the same as the last-modify-time message.
size
The size in bytes of the entry. If the entry has a result 0 is returned. If the file does not exist or cannot be fetched, 0 is also returned. In situations where the entry is a directory it depends on the client implementation as to if a size is returned.

3.14   Request directory entry attributes message

This message is sent by the server to query the current attributes for the directory entry. This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 23 message-sub-type
4 U32   transaction-id
4 U32   path-length
path-length U8 array   path

3.15   Directory entry attributes response message

This message contains high level file system information for a specific path. It is the client's responsibility to ensure the underlying read of the directory has returned before it returns the result.2 If there is a non-zero status the errors are as follows:

Status Description
1 Permission denied.
2 Path not found.
3 Undefined error

This message shares many of the same fields as the Directory info response message but with only information for a specific directory entry. This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 23 message-sub-type
4 U32   transaction-id
1 U8   status
1 U8   is-dir
1 U8   attributes
4 U32   create-time
4 U32   last-access-time
4 U32   last-modify-time
4 U32   size

3.16   Request set directory entry attributes message

This message is sent by the server to set the attributes for a specific directory entry. This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 24 message-sub-type
4 U32   transaction-id
4 U32   path-length
path-length U8 array   path
1 U8   attributes

This message returns a Generic status response message. If there is a non-zero status the errors are as follows:

Status Description
1 Permission denied.
2 Path not found.
3 Undefined error

3.17   Request open file message

This request notifies the host would like to access a file on the local client. The path is given as an absolute path.

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 14 message-sub-type
4 U32   transaction-id
4 U32   path-length
path-length U8 array   path
1 U8   mode
mode

A bit field defining the access mode that the file should be opened as. These are defined below:

Value Description
1 Open for reading.
2 Open for writing.

3.18   Open file response message

If a file is successfully opened then it will return a valid file-id. This is a unique value that will allow the host to manage the lifetime of its access to the file. It is the client's responsibility to ensure the open operation has returned before it returns the result.2 If there is a non-zero status the errors are as follows:

Status Description
1 Permission denied.
2 File not found.
3 Undefined error

This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 14 message-sub-type
4 U32   transaction-id
1 U8   status
2 U16   file-id
file-id
This is a unique handle to the file. This can be used to further access this specific file in the defined mode. The server is responsible for managing the lifetime of this handle and the client should not release any resources until the server informs them to.

3.19   Request close file message

The host uses this message to inform the client that it is done accessing a specific file and the client can discard any information associated with it. The file-id must match the result returned by the Open file response message. This message is nonblocking and will not get a response. This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 15 message-sub-type
2 U16   file-id

3.20   Request truncate file message

This is a helper message that will notify the client to truncate a specific file based off of a path. It is the client's responsibility to ensure the truncation of the path returns before it returns the result.2 If there is a non-zero status the errors are as follows:

Status Description
1 Permission denied.
2 File not found.
3 Not regular file.

This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 16 message-sub-type
4 U32   transaction-id
4 U32   path-length
path-length U8 array   path
4 U32   new-file-size
new-file-size
The new size of the file. If the size is bigger than the original size the file is expanded to the new size and filled with zeros.

3.21   Request read file block message

This message requests a specific block of a currently open file. The server decides the size of the block to read so it is responsible for breaking up any large reads into smaller chunks.3

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 17 message-sub-type
4 U32   transaction-id
2 U16   file-id
4 U32   file-offset
4 U32   read-size
file-offset
The number of bytes to seek into the file.
read-size
The actual number of bytes to read from the file.

3.22   Read file block response message

The client will read a specific block from an open file and return the status along with the actual data. The data is not encoded in any way, and should be transfered verbatim. On a successful read status will be set to 0, and the read-data-size will be set to the size of the data.2 If there is a non-zero status the errors are as follows:

Status Description
1 File not open.
2 Read out of bounds.
3 General IO error.

This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 17 message-sub-type
4 U32   transaction-id
1 U8   status
4 U32   read-data-size
read-data-size U8 array   read-data
read-data-size
The number of bytes of data to be returned.
read-data
The actual data read.

3.23   Request write file block message

This message is passed from the server to the client when a block of data is to be written to an open file at an offset. The server is responsible for the size of the block to be written.3 The client will then respond with a Generic status response message providing the server with the status of the operation. It is the client's responsibility to ensure the entire block of data is written before it returns the result.2 If there is a non-zero status the errors are as follows:

Status Description
1 File not open.
2 Write out of bounds.
3 General IO error.

This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 18 message-sub-type
4 U32   transaction-id
2 U16   file-id
4 U32   file-offset
4 U32   write-data-size
write-data-size U8 array   write-data
write-data-size
The number of bytes to be written to the file.
write-data
The actual bytes that are to be written to the file.

3.24   Request remove directory entry message

To remove a file or directory from the share the server will send this message. The client will then respond with a Generic status response message providing the server with the status of the operation.1 It is the client's responsibility to ensure the path is removed before it returns the result.2 If there is a non-zero status the errors are as follows:

Status Description
1 Permission denied.
2 Entry not found.
3 Entry busy.
4 General IO error.

This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 19 message-sub-type
4 U32   transaction-id
4 U32   path-length
path-length U8 array   path

3.25   Request move directory entry message

To move a file or directory from the share the server will send this message. The client will then respond with a Generic status response message providing the server with the status of the operation.1 It is the client's responsibility to ensure the requested path is moved before it returns the result.2 If there is a non-zero status the errors are as follows:

Status Description
1 Permission denied.
2 Entry not found.
3 Entry busy.
4 General IO error.

This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 20 message-sub-type
4 U32   transaction-id
4 U32   path-length
path-length U8 array   path
4 U32   new-path-length
new-path-length U8 array   new-path
new-path-length
The length of the new path.
new-path
The absolute path to the entry.

3.26   Request make directory message

To create directory from the share the server will send this message. The client will then respond with a Generic status response message providing the server with the status of the operation. It is the client's responsibility to ensure the requested path is created before it returns the result.2 If there is a non-zero status the errors are as follows:

Status Description
1 Permission denied.
2 Directory exists.
3 Parent path not found.
4 General IO error.

This message contains the following structure:

No. of bytes Type Value Description
1 U8 249 message-type
4 U32 21 message-sub-type
4 U32   transaction-id
4 U32   path-length
path-length U8 array   path

4   Changelog

0.1
Initial version.
[1](1, 2, 3, 4) The client's underlying file system will limit if a file or directory may be moved or removed if it is currently in use. The client will have to report this error up to the server so that it can give the appropriate message to the host operating system.
[2](1, 2, 3, 4, 5, 6, 7, 8, 9) The client should have a provision for timing out on a file system operation and returning an error to the server. This means the server must wait for a response from the client before continuing. The only exception to this is if the client disconnects during the specified operation the server can continue and return an error to the host operating system.
[3](1, 2) It is in the best interest of performance to manage block size keeping in mind that larger block sizes will give faster file transfer while smaller block sizes will allow servers to interleave framebuffer updates in between blocks.