gtpc2mjf | C/C++ Language Support User's Guide |
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);
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.
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.
Normal Return
Error Return
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