Annotation of coherent/f/etc/conf/streams/src/fhsys.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Functions for dealing with filesystem open object handles.
                      3:  */
                      4: /*
                      5:  *-IMPORTS:
                      6:  *     <common/ccompat.h>
                      7:  *             __USE_PROTO__
                      8:  *             __ARGS ()
                      9:  *     <sys/debug.h>
                     10:  *             ASSERT ()
                     11:  *     <sys/errno.h>
                     12:  *             EMFILE
                     13:  *     <string.h>
                     14:  *             NULL
                     15:  *             memcpy ()
                     16:  */
                     17: 
                     18: #include <common/ccompat.h>
                     19: #include <sys/debug.h>
                     20: #include <sys/errno.h>
                     21: #include <string.h>
                     22: 
                     23: #include <kernel/fhsys.h>
                     24: 
                     25: 
                     26: /*
                     27:  * About open file handles; pointers to objects of type "fhandle_t" are used
                     28:  * in the kernel to represent information about abstract open file objects.
                     29:  * The handles contain pointers to tables of entry points to dispatch abstract
                     30:  * operations such as read and write to routines specific to the type of
                     31:  * object that is referred to.
                     32:  *
                     33:  * Unlike the "vnode" VFS system used in System V and BSD Unix, this system
                     34:  * follows the lead of the Sprite operating system in separating the functions
                     35:  * of naming objects and providing the services specific to the different
                     36:  * types of objects that may be named.
                     37:  *
                     38:  * Neither the internal structure of a handle nor the function dispatch table
                     39:  * is available to implementations of file systems, so that file systems can
                     40:  * be written with maximum binary portability.
                     41:  */
                     42: 
                     43: 
                     44: /*
                     45:  * "fdprocs" structures should be constructed by automated tools like the
                     46:  * device configuration mechanism. As such, users do not get to deal with the
                     47:  * definition of the structure that "fprocs_t" actually refers to.
                     48:  */
                     49: 
                     50: struct fprocs {
                     51:        fh_open_t       fh_open;
                     52:        fh_close_t      fh_close;
                     53:        fh_read_t       fh_read;
                     54:        fh_write_t      fh_write;
                     55:        fh_ioctl_t      fh_ioctl;
                     56:        fh_poll_t       fh_poll;
                     57:        fh_lseek_t      fh_lseek;
                     58:        fh_sync_t       fh_sync;
                     59:        fh_getpmsg_t    fh_getpmsg;
                     60:        fh_putpmsg_t    fh_putpmsg;
                     61:        fh_fstat_t      fh_fstat;
                     62:        fh_statvfs_t    fh_statvfs;
                     63:        fh_mmap_t       fh_mmap;
                     64:        fh_attach_t     fh_attach;
                     65:        fh_detach_t     fh_detach;
                     66: };
                     67: 
                     68: 
                     69: /*
                     70:  * The definition of the body of the "fhandle_t" structure is also kept
                     71:  * totally opaque for maximum binary compatibility between installable
                     72:  * filesystems.
                     73:  */
                     74: 
                     75: 
                     76: #define        FHOPAQUESZ      32
                     77: 
                     78: struct fhandle {
                     79:        fprocs_t      * fh_procs;
                     80:        char            fh_opaque [FHOPAQUESZ];
                     81: };
                     82: 
                     83: 
                     84: /*
                     85:  * This function looks up a system file table entry based on the file
                     86:  * descriptor number.
                     87:  */
                     88: 
                     89: #if    __USE_PROTO__
                     90: sftab_t * (fd_get_sftab) (int fd)
                     91: #else
                     92: sftab_t *
                     93: fd_get_sftab __ARGS ((fd))
                     94: int            fd;
                     95: #endif
                     96: {
                     97:        return NULL;
                     98: }
                     99: 
                    100: 
                    101: /*
                    102:  * This function looks up a file handle based on the file descriptor number.
                    103:  */
                    104: 
                    105: #if    __USE_PROTO__
                    106: fhandle_t * (fd_get_handle) (int fd)
                    107: #else
                    108: fhandle_t *
                    109: fd_get_handle __ARGS ((fd))
                    110: int            fd;
                    111: #endif
                    112: {
                    113:        return NULL;
                    114: }
                    115: 
                    116: 
                    117: /*
                    118:  * This function tries to add a file descriptor to the currently running
                    119:  * process as a clone of some existing system file table entry. The file
                    120:  * descriptor number assigned to the file is returned in the value pointed to
                    121:  * by the "fdp" parameter.
                    122:  *
                    123:  * The file descriptor will be default be set to remain open across exec ()
                    124:  * system calls.
                    125:  *
                    126:  * Returns 0 on success, or an error number on failure.
                    127:  */
                    128: 
                    129: #if    __USE_PROTO__
                    130: int (fd_add_sftab) (sftab_t * sftabp, int * fdp)
                    131: #else
                    132: int
                    133: fd_add_sftab __ARGS ((sftabp, fdp))
                    134: sftab_t              * sftabp;
                    135: int          * fdp;
                    136: #endif
                    137: {
                    138:        return EMFILE;
                    139: }
                    140: 
                    141: 
                    142: /*
                    143:  * This function tests to see whether it is possible to add a new file entry
                    144:  * to the current process (ie, it attempts to tell whether fd_add_sftab ()
                    145:  * would fail with EMFILE).
                    146:  *
                    147:  * Reutrn 0 on success, or an error number on failure.
                    148:  */
                    149: 
                    150: #if    __USE_PROTO__
                    151: int (fd_can_add) (void)
                    152: #else
                    153: int
                    154: fd_can_add __ARGS (())
                    155: #endif
                    156: {
                    157:        return EMFILE;
                    158: }
                    159: 
                    160: 
                    161: /*
                    162:  * This function returns a pointer to the "fprocs" structure member of a file
                    163:  * handle.
                    164:  */
                    165: 
                    166: #if    __USE_PROTO__
                    167: fprocs_t * (fh_procs) (fhandle_t * handle)
                    168: #else
                    169: fprocs_t *
                    170: fh_procs __ARGS ((handle))
                    171: fhandle_t     *        handle;
                    172: #endif
                    173: {
                    174:        ASSERT (handle != NULL);
                    175:        ASSERT (handle->fh_procs != NULL);
                    176: 
                    177:        return handle->fh_procs;
                    178: }
                    179: 
                    180: 
                    181: /*
                    182:  * This function returns a pointer to the opaque part of the file handle.
                    183:  */
                    184: 
                    185: #if    __USE_PROTO__
                    186: __VOID__ * (fh_get_cookie) (fhandle_t * handle)
                    187: #else
                    188: __VOID__ *
                    189: fh_get_cookie __ARGS ((handle))
                    190: fhandle_t     *        handle;
                    191: #endif
                    192: {
                    193:        ASSERT (handle != NULL);
                    194: 
                    195:        return handle->fh_opaque;
                    196: }
                    197: 
                    198: 
                    199: /*
                    200:  * This function accepts a pointer to a data area that will be copied into
                    201:  * the file handle somehow. The only guarantee that is made by this function
                    202:  * is that fh_get_cookie () will return a pointer to data that is identical
                    203:  * in value to that passed to this function.
                    204:  *
                    205:  * This function returns 0 on success or non-zero on failure (such as being
                    206:  * unable to allocate space for the cookie).
                    207:  *
                    208:  * May sleep.
                    209:  */
                    210: 
                    211: #if    __USE_PROTO__
                    212: int (fh_set_cookie) (fhandle_t * handle, __VOID__ * cookie, size_t len)
                    213: #else
                    214: int
                    215: fh_set_cookie __ARGS ((handle, cookie, len))
                    216: fhandle_t     *        handle;
                    217: __VOID__      *        cookie;
                    218: size_t         len;
                    219: #endif
                    220: {
                    221:        if (len > FHOPAQUESZ || cookie == NULL)
                    222:                return -1;
                    223: 
                    224:        (void) memcpy (handle->fh_opaque, cookie, len);
                    225:        return 0;
                    226: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.