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