gtpc2mjeC/C++ Language Support User's Guide

TPF_FSDD_GET-Read From a File

This type of function is specified as part of the file system device driver interface and is called by TPF file system C functions that require a physical read from a file device to get input data from an open special file.

Format

typedef long TPF_FSDD_GET(void *buffer, long buffer_size, long position,
    int noblock, const TPF_FSDD_FILEDATA *filedata);

buffer
The address of the data buffer into which the input data will be read. buffer is not a null pointer, but the range of addresses buffer through buffer + buffer_size - 1 is not verified to be either addressable or writable.

buffer_size
The size of the input data buffer for the file. buffer_size ranges from 1 to 2 147 483 647 (2**31 - 1) inclusive.

position
The logical position in the file from which the first byte of data will be read. position ranges from 0 to 2 147 483 647 (2**31 - 1) inclusive. The sum of buffer_size + position is guaranteed to range from 1 to 2 147 483 648 (2**31) inclusive.

noblock
Nonblocking read request indicator.

For files that support nonblocking reads and cannot accept data immediately, you can write code to do the following:

filedata
The address of the file data object returned by the TPF_FSDD_OPEN-type device driver function for the special file being read.

Normal Return

The number of bytes read into buffer, from 0 to buffer_size inclusive.

Error Return

-1 means there was an error during the read operation. The device driver should also set errno to specify the type of error. The contents of buffer cannot be predicted.

Programming Considerations

Examples

The following example is the get device driver interface function for the null file (/dev/null).

#include <c$spif.h> /* Device driver interface */
 
/**********************************************************************/
/* The null_get() always returns 0 (signifying, EOF).                 */
/**********************************************************************/
long null_get(void *buffer, long buffer_size, long position,
              int non_block, const TPF_FSDD_FILEDATA *filedata)
{
    return 0;
}

Related Information