Annotation of coherent/g/usr/lib/misc/fifo_b.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * fifo_b.c -- Extra routines for handling typed fifos.
        !             3:  * Both fifo_b.c (boot fifo) and fifo_k.c (kernel fifo) are needed by the
        !             4:  * boot code.
        !             5:  */
        !             6: #include <kernel/typed.h>
        !             7: 
        !             8: #ifndef T_NULL
        !             9: #define T_NULL ((char *)0)
        !            10: #endif
        !            11: 
        !            12: /* How long is an open fifo?  */
        !            13: long
        !            14: fifo_len(ffp)
        !            15:        FIFO *ffp;
        !            16: {
        !            17:        /* ffp->f_offset points at the terminating NUL space.  */
        !            18:        return(sizeof(typed_space) +
        !            19:                ((char *) ffp->f_offset) - ((char *)ffp->f_space));
        !            20: } /* fifo_len() */
        !            21: 
        !            22: /* Write a typed space into a FIFO.  */
        !            23: typed_space *
        !            24: fifo_write(ffp, space)
        !            25:        FIFO *ffp;
        !            26:        typed_space *space;
        !            27: {
        !            28:        return  (fifo_write_untyped(
        !            29:                        ffp,
        !            30:                        space->ts_data,
        !            31:                        (int32) (space->ts_size - sizeof(typed_space)),
        !            32:                        space->ts_type)
        !            33:                );
        !            34: } /* fifo_write() */
        !            35: 
        !            36: /* Write a chunk of data into an open fifo as a typed space.
        !            37:  * Takes a FIFO to be written to, ffp; a pointer to the data, datum; a
        !            38:  * size for the datum, size; and a type for the new space, type.
        !            39:  *
        !            40:  * Returns a pointer to the newly written space.  Returns NULL if the
        !            41:  * new space could not be written.
        !            42:  *
        !            43:  * Note that while sizes throughout this package refer to TOTAL sizes
        !            44:  * including headers, the size argument here is ONLY for the datum.
        !            45:  *
        !            46:  * Only FIFOs of type T_FIFO_SIC are implimented.
        !            47:  */
        !            48: typed_space *
        !            49: fifo_write_untyped(ffp, datum, size, type)
        !            50:        FIFO *ffp;
        !            51:        char *datum;
        !            52:        long size;
        !            53:        space_type type;
        !            54: {
        !            55:        long needed_space;      /* Total space we need to add.  */
        !            56:        typed_space *retval;    /* Return the space we just wrote.  */
        !            57: 
        !            58:        /* Write MUST be set.  */
        !            59:        if (F_WRITE != F_WRITE & ffp->f_flags ) {
        !            60:                /* Write on closed ffp. */
        !            61:                return(T_NULL);  /* This ffp is not open for writing.  */
        !            62:        }
        !            63: 
        !            64:        /* From here to end of fifo_write_untyped() is really fifo_write_sic().  */
        !            65: 
        !            66:        /* Check to see that there is enough space for the new datum.
        !            67:         * We need space for another typed_space header, size bytes of
        !            68:         * data, and space for a terminating typed_space header.
        !            69:         */
        !            70:        needed_space = sizeof(typed_space) + size + sizeof(typed_space);
        !            71: 
        !            72:        if (ffp->f_space->ts_size <
        !            73:            ((char *)ffp->f_offset - (char *)ffp->f_space) + needed_space) {
        !            74:                /* Write on insufficient space. */
        !            75:                return(T_NULL);         /* Insufficient space.  */
        !            76:        }
        !            77: 
        !            78:        /* ASSERTION:  There is enough space remaining in ffp->f_space for
        !            79:         * two more headers and the datum.
        !            80:         */
        !            81: 
        !            82:        retval = ffp->f_offset;
        !            83: 
        !            84:        /* Create the new header.  */
        !            85:        ffp->f_offset->ts_size = sizeof(typed_space) + size;
        !            86:        ffp->f_offset->ts_type = type;
        !            87: 
        !            88:        /* Copy the datum in place.  */
        !            89:        memcpy(ffp->f_offset->ts_data, datum, size);
        !            90: 
        !            91:        /* Advance the write pointer.  */
        !            92:        ffp->f_offset += 1;             /* Skip the header.     */
        !            93:        (char *) ffp->f_offset += size; /* Skip the data.       */
        !            94: 
        !            95:        /* Terminate the fifo.  */
        !            96:        ffp->f_offset->ts_size = (int32) 0;
        !            97:        ffp->f_offset->ts_type = T_UNKNOWN;
        !            98: 
        !            99:        return(retval);
        !           100: } /* fifo_write_untyped() */
        !           101: 

unix.superglobalmegacorp.com

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