gtpc2mjfC/C++ Language Support User's Guide

TPF_FSDD_OPEN-Open a File

This type of function is specified as part of the file system device driver interface. This function is called by the creat, fopen, freopen, and open functions to make a special file accessible to the TPF file system.

Format

typedef int TPF_FSDD_OPEN(int minordevice, char *location,
                          int opentype, TPF_FSDD_FILEDATA *filedata,
                          Ino_t inodeIno);

minordevice
The minor device number associated with a special file, defined by the mknod library function call that created the special file. minordevice ranges from 0 to 65 535 (2**16 - 1) inclusive. The meaning of the minor device number depends on the specific device driver.

location
The location information included in the tail of the pathname string passed to the creat, fopen, freopen, or open function for a special file. For example, if the special file "my.special.file" is opened as:
    FILE *a_stream = fopen("my.special.file/at.XYZ", "r+b");

the pathname tail "at.XYZ" will be passed to this device driver function.

location points to a heap block that contains a '\0'-terminated character array. It is the responsibility of the device driver to free this block. The meaning of the location information depends on the specific device driver.

opentype
The indicator to open for read, write, or read and write access. The value of opentype is one of O_WRONLY (write only), O_RDONLY (read only), or O_RDWR (read and write access), defined in fcntl.h.
Note:
O_RDWR is equal to O_WRONLY | O_RDONLY

filedata
The address of an object of type TPF_FSDD_FILEDATA, defined in c$spif.h as:
typedef struct TPF_FSDD_FILEDATA {
    long filedata_length;
    void * filedata_state_ptr;
} TPF_FSDD_FILEDATA;

This object can be used by the device driver to save state information between calls to the various device driver functions. It is passed to the TPF_FSDD_OPEN-type device driver function with filedata_length initialized to zero and filedata_state_ptr initialized to a NULL pointer. The TPF_FSDD_OPEN-type device driver function can store any file state information in this object. All other device driver functions can read, but cannot modify this object.

Each device driver function, which is called on a special file from the time it is opened to the time it is closed, will be passed the same TPF_FSDD_FILEDATA object that was passed to the TPF_FSDD_OPEN-type device driver function that opened the file. The actual types and values of the data referenced by this object are known only to the specific device driver and do not change after they have been set by the TPF_FSDD_OPEN-type device driver function.

inodeIno
The i-node ordinal number of type Ino_t, as defined in sys/stat.h, that has a one-to-one correspondence to the opened file.

Normal Return

0
The special file has been opened as requested.

Error Return

-1
The special file could not be opened as requested. The device driver should set errno to an appropriate error code.

Programming Considerations

Examples

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

#include <c$spif.h> /* Device driver interface */
#include <errno.h>  /* errno, ENOTDIR */
#include <stdlib.h> /* free() */
#include <sys/types.h> /* Ino_t type */
 
/**********************************************************************/
/* The null_open() function opens a null file.  It only fails if      */
/* location data is passed to it (it is not a directory); otherwise   */
/* it always succeeds.                                                */
/**********************************************************************/
int null_open(int minor_device, char *location, int open,
              TPF_FSDD_FILEDATA *filedata, (Ino_t)0)
{
    if (location)   /* Invalid path name. */
    {
        free(location);
        errno = ENOTDIR;    /* I am not a directory. */
        return -1;
    }
    return 0;
}

Related Information