gtpc2mjiC/C++ Language Support User's Guide

TPF_FSDD_PUT-Write to 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 write to a file device to put output data to an open special file. When a process ends, any data remaining in file stream buffers is flushed to the file as part of the process of closing the open files.

Format

typedef long TPF_FSDD_PUT(void *buffer, long data_size, long position,
    int noblock, const TPF_FSDD_FILEDATA *filedata);

buffer
The address of the data buffer from which the output data will be written. The range of addresses buffer through buffer + data_size - 1 is not verified to be addressable.

data_size
The size of the output data to be written to file. data_size ranges from 1 to 2 147 483 647 (2**31 - 1) inclusive.

position
The logical position in the file to which the first byte of data will be written. position ranges from 0 to 2 147 483 647 (2**31 - 1) inclusive. The sum of data_size + position is guaranteed to range from 1 to 2 147 483 648 (2**31) inclusive. If position is greater than the current logical file size and the put operation is successful, the bytes between the old end of data and the new data (logically) contain \0.

noblock
Nonblocking write request indicator.

For files that support nonblocking writes 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 written.

Normal Return

The number of bytes written from buffer, from 1 to data_size inclusive.

Note:
When zero bytes of data are requested to be written, TPF file system C functions return zero without calling this device driver function.

Error Return

-1 means there was an error during the write operation. The device driver should also set errno to specify the type of error.

Programming Considerations

Examples

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

#include <c$spif.h> /* Device driver interface */
 
/**********************************************************************/
/* The null_put() function writes to a null file.  It always           */
/* succeeds.                                                          */
/**********************************************************************/
long null_put(void *data, long data_size, long position, int non_block,
              const TPF_FSDD_FILEDATA *filedata)
{
    return data_size;
}

Related Information