Lines Matching +full:block +full:- +full:copy
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
45 * The previous design of the TTY layer offered the so-called clists.
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++; \
72 to->to_firstblock = to->to_firstblock->tob_next; \
73 to->to_nblocks--; \
77 if (to->to_quota <= to->to_nblocks) \
87 to->to_begin = 0; in ttyoutq_flush()
88 to->to_end = 0; in ttyoutq_flush()
96 to->to_quota = howmany(size, TTYOUTQ_DATASIZE); in ttyoutq_setsize()
98 while (to->to_quota > to->to_nblocks) { in ttyoutq_setsize()
129 to->to_quota = 0; in ttyoutq_free()
131 while ((tob = to->to_firstblock) != NULL) { in ttyoutq_free()
136 MPASS(to->to_nblocks == 0); in ttyoutq_free()
149 if (to->to_begin == to->to_end) in ttyoutq_read()
151 tob = to->to_firstblock; in ttyoutq_read()
157 * - The write pointer in ttyoutq_read()
158 * - The blocksize - we can't read beyond the block in ttyoutq_read()
159 * - The end address if we could perform the full read 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()
164 clen = cend - cbegin; in ttyoutq_read()
166 /* Copy the data out of the buffers. */ in ttyoutq_read()
167 memcpy(cbuf, tob->tob_data + cbegin, clen); in ttyoutq_read()
169 len -= clen; 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()
176 /* Read the block until the end. */ in ttyoutq_read()
178 to->to_begin = 0; in ttyoutq_read()
179 to->to_end -= TTYOUTQ_DATASIZE; in ttyoutq_read()
182 /* Read the block partially. */ in ttyoutq_read()
183 to->to_begin += clen; in ttyoutq_read()
187 return (cbuf - (char *)buf); 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
204 while (uio->uio_resid > 0) { in ttyoutq_read_uio()
210 if (to->to_begin == to->to_end) in ttyoutq_read_uio()
212 tob = to->to_firstblock; in ttyoutq_read_uio()
218 * - The write pointer in ttyoutq_read_uio()
219 * - The blocksize - we can't read beyond the block in ttyoutq_read_uio()
220 * - The end address if we could perform the full read 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()
225 clen = cend - cbegin; 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()
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()
236 * Fast path: zero copy. Remove the first block, 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()
248 error = uiomove(tob->tob_data + cbegin, clen, uio); in ttyoutq_read_uio()
251 /* Block can now be readded to the list. */ in ttyoutq_read_uio()
254 char ob[TTYOUTQ_DATASIZE - 1]; in ttyoutq_read_uio()
259 memcpy(ob, tob->tob_data + cbegin, clen); 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()
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()
297 /* We reached the end of this block on last write. */ 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()
308 /* Don't copy more than was requested. */ in ttyoutq_write()
309 l = MIN(nbytes, TTYOUTQ_DATASIZE - boff); in ttyoutq_write()
311 memcpy(tob->tob_data + boff, cbuf, l); in ttyoutq_write()
314 nbytes -= l; in ttyoutq_write()
315 to->to_end += l; in ttyoutq_write()
318 return (cbuf - (const char *)buf); in ttyoutq_write()
327 return (-1); in ttyoutq_write_nofrag()