Lines Matching full:to

20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * bits for parity marking and such. This mechanism is similar to the
49 * old clists, but only contains the features we need to buffer the
60 #define TTYOUTQ_INSERT_TAIL(to, tob) do { \ argument
61 if (to->to_end == 0) { \
62 tob->tob_next = to->to_firstblock; \
63 to->to_firstblock = tob; \
65 tob->tob_next = to->to_lastblock->tob_next; \
66 to->to_lastblock->tob_next = tob; \
68 to->to_nblocks++; \
71 #define TTYOUTQ_REMOVE_HEAD(to) do { \ argument
72 to->to_firstblock = to->to_firstblock->tob_next; \
73 to->to_nblocks--; \
76 #define TTYOUTQ_RECYCLE(to, tob) do { \ argument
77 if (to->to_quota <= to->to_nblocks) \
80 TTYOUTQ_INSERT_TAIL(to, tob); \
84 ttyoutq_flush(struct ttyoutq *to) in ttyoutq_flush() argument
87 to->to_begin = 0; in ttyoutq_flush()
88 to->to_end = 0; in ttyoutq_flush()
92 ttyoutq_setsize(struct ttyoutq *to, struct tty *tp, size_t size) in ttyoutq_setsize() argument
96 to->to_quota = howmany(size, TTYOUTQ_DATASIZE); in ttyoutq_setsize()
98 while (to->to_quota > to->to_nblocks) { in ttyoutq_setsize()
101 * Add new blocks to the tail of the list. in ttyoutq_setsize()
104 * to allocate memory. This won't be a problem, because in ttyoutq_setsize()
106 * may cause us to allocate too many blocks, but this in ttyoutq_setsize()
118 TTYOUTQ_INSERT_TAIL(to, tob); in ttyoutq_setsize()
124 ttyoutq_free(struct ttyoutq *to) in ttyoutq_free() argument
128 ttyoutq_flush(to); in ttyoutq_free()
129 to->to_quota = 0; in ttyoutq_free()
131 while ((tob = to->to_firstblock) != NULL) { in ttyoutq_free()
132 TTYOUTQ_REMOVE_HEAD(to); in ttyoutq_free()
136 MPASS(to->to_nblocks == 0); in ttyoutq_free()
140 ttyoutq_read(struct ttyoutq *to, void *buf, size_t len) in ttyoutq_read() argument
149 if (to->to_begin == to->to_end) in ttyoutq_read()
151 tob = to->to_firstblock; in ttyoutq_read()
161 cbegin = to->to_begin; in ttyoutq_read()
162 cend = MIN(MIN(to->to_end, to->to_begin + len), in ttyoutq_read()
171 if (cend == to->to_end) { in ttyoutq_read()
173 to->to_begin = 0; in ttyoutq_read()
174 to->to_end = 0; in ttyoutq_read()
177 TTYOUTQ_REMOVE_HEAD(to); in ttyoutq_read()
178 to->to_begin = 0; in ttyoutq_read()
179 to->to_end -= TTYOUTQ_DATASIZE; in ttyoutq_read()
180 TTYOUTQ_RECYCLE(to, tob); in ttyoutq_read()
183 to->to_begin += clen; in ttyoutq_read()
192 * TTY drivers to directly copy data from the outq to userspace, instead
195 * We can only copy data directly if we need to read the entire block
196 * back to the user, because we temporarily remove the block from the
197 * queue. Otherwise we need to copy it to a temporary buffer first, to
201 ttyoutq_read_uio(struct ttyoutq *to, struct tty *tp, struct uio *uio) in ttyoutq_read_uio() argument
210 if (to->to_begin == to->to_end) in ttyoutq_read_uio()
212 tob = to->to_firstblock; in ttyoutq_read_uio()
222 cbegin = to->to_begin; in ttyoutq_read_uio()
223 cend = MIN(MIN(to->to_end, to->to_begin + uio->uio_resid), in ttyoutq_read_uio()
229 * - We need to read the block until the end. in ttyoutq_read_uio()
230 * - We don't need to read the block until the end, but in ttyoutq_read_uio()
231 * there is no data beyond it, which allows us to move in ttyoutq_read_uio()
232 * the write pointer to a new block. in ttyoutq_read_uio()
234 if (cend == TTYOUTQ_DATASIZE || cend == to->to_end) { in ttyoutq_read_uio()
239 TTYOUTQ_REMOVE_HEAD(to); in ttyoutq_read_uio()
240 to->to_begin = 0; in ttyoutq_read_uio()
241 if (to->to_end <= TTYOUTQ_DATASIZE) in ttyoutq_read_uio()
242 to->to_end = 0; in ttyoutq_read_uio()
244 to->to_end -= TTYOUTQ_DATASIZE; in ttyoutq_read_uio()
246 /* Temporary unlock and copy the data to userspace. */ in ttyoutq_read_uio()
251 /* Block can now be readded to the list. */ in ttyoutq_read_uio()
252 TTYOUTQ_RECYCLE(to, tob); in ttyoutq_read_uio()
260 to->to_begin += clen; in ttyoutq_read_uio()
261 MPASS(to->to_begin < TTYOUTQ_DATASIZE); in ttyoutq_read_uio()
263 /* Temporary unlock and copy the data to userspace. */ in ttyoutq_read_uio()
277 ttyoutq_write(struct ttyoutq *to, const void *buf, size_t nbytes) in ttyoutq_write() argument
285 boff = to->to_end % TTYOUTQ_DATASIZE; in ttyoutq_write()
287 if (to->to_end == 0) { in ttyoutq_write()
289 MPASS(to->to_begin == 0); in ttyoutq_write()
290 tob = to->to_firstblock; in ttyoutq_write()
295 to->to_lastblock = tob; in ttyoutq_write()
298 tob = to->to_lastblock->tob_next; in ttyoutq_write()
303 to->to_lastblock = tob; in ttyoutq_write()
305 tob = to->to_lastblock; in ttyoutq_write()
315 to->to_end += l; in ttyoutq_write()
322 ttyoutq_write_nofrag(struct ttyoutq *to, const void *buf, size_t nbytes) in ttyoutq_write_nofrag() argument
326 if (ttyoutq_bytesleft(to) < nbytes) in ttyoutq_write_nofrag()
329 /* We should always be able to write it back. */ in ttyoutq_write_nofrag()
330 ret = ttyoutq_write(to, buf, nbytes); in ttyoutq_write_nofrag()