3 allocb, iallocb, freeb, freeblist, BLEN, BALLOC, blocklen, blockalloclen, readblist, concatblock, copyblock, trimblock, packblock, padblock, pullblock, pullupblock, adjustblock, checkb \- data block management
7 Block* allocb(int size)
10 Block* iallocb(int size)
16 void freeblist(Block *b)
19 int blocklen(Block *b)
22 int blockalloclen(Block *b)
25 long readblist(Block *b, uchar *p, long n, ulong offset)
28 Block* concatblock(Block *b)
31 Block* copyblock(Block *b, int n)
34 Block* trimblock(Block *b, int offset, int n)
37 Block* packblock(Block *b)
40 Block* padblock(Block *b, int n)
43 int pullblock(Block **bph, int n)
46 Block* pullupblock(Block *b, int n)
49 Block* adjustblock(Block *b, int n)
52 void checkb(Block *b, char *msg)
56 #define BLEN(s) ((s)->wp - (s)->rp)
59 #define BALLOC(s) ((s)->lim - (s)->base)
63 provides a receptacle for data:
72 uchar* rp; /* first unconsumed byte */
73 uchar* wp; /* first empty byte */
74 uchar* lim; /* 1 past the end of the buffer */
75 uchar* base; /* start of the buffer */
78 ushort checksum; /* IP checksum of complete packet */
84 has an associated buffer, located at
88 when filling the buffer, or
90 when fetching data from it.
91 Each pointer should be incremented to reflect the amount of data written or read.
100 bounds the allocated space.
101 Some operations described below accept lists of
106 pointers, with a null pointer ending the list.
108 are usually intended for a
112 but can be used independently.
116 and its buffer are normally allocated by one call to
118 and aligned on an 8 byte (\fLBY2V\fP) boundary.
119 Some devices with particular allocation constraints
120 (eg, requiring certain addresses for DMA) might allocate their own
124 must then point to a function that can deallocate the specially allocated
129 operations cannot be used in interrupt handlers
134 Of operations that allocate blocks, only
149 point to the start of the data.
150 If it cannot allocate memory,
154 it cannot be used by an interrupt handler.
159 but is intended for use by interrupt handlers,
160 and returns a null pointer if no memory is available.
161 It also limits its allocation to a quota allocated at system initialisation to interrupt-time buffering.
170 list of blocks headed by
174 returns the number of unread bytes in a single block.
177 returns the number of allocated bytes in a single block.
180 returns the number of bytes of unread data in the whole list of blocks headed by
184 returns the number of total bytes allocated in the whole list of blocks headed by
190 bytes of data at offset
192 from the list of blocks headed by
196 then returns the amount of bytes copied. It leaves the block list intact.
201 if it is not a list, and otherwise
204 containing all the data in the list of blocks
209 by contrast returns a single
211 containing a copy of the first
213 bytes of data in the block list
215 padding with zeroes if the list contained less than
225 at either end, to reserve space for protocol headers or trailers.
230 bytes at the start of the block,
231 setting the read pointer
233 to point to the new space.
238 bytes at the end of the block,
239 leaving the write pointer
241 pointing at the new space.
242 In both cases, it allocates a new
244 if necessary, freeing the old, and
245 it always returns a pointer to the resulting
251 to contain no more than
255 bytes into the data of the original list.
256 It returns a new list, freeing unneeded parts of the old.
257 If no data remains, it returns a null pointer.
264 reallocating any block in the list that has four times more available space than actual data.
265 It returns a pointer to the revised list.
270 bytes from the start of the list headed by
272 Unneeded blocks are freed.
276 to point to the new list head
277 and returns the number of bytes discarded (which might be less than
279 It is used by transport protocols to discard ack'd data at
280 the head of a retransmission queue.
283 rearranges the data in the list of blocks
285 to ensure that there are at least
287 bytes of contiguous data in the first block,
288 and returns a pointer to the new list head.
289 It frees any blocks that it empties.
290 It returns a null pointer if there is not enough data in the list.
293 ensures that the block
297 bytes of data, reallocating or padding with zero if necessary.
298 It returns a pointer to the new
302 is negative, it frees the block and returns a null pointer.)
305 does some consistency checking of
310 results if things look grim.
311 It is intended for internal use by the queue I/O routines (see
313 but could be used elsewhere.
315 The only functions that can be called at interrupt level are
326 The others allocate memory and can potentially block.
328 .B /sys/src/9/port/allocb.c
330 .B /sys/src/9/port/qio.c
332 Many functions directly or indirectly can raise an
334 and callers must therefore provide for proper error recovery
335 as described therein to prevent memory leaks and other bugs.
338 any functions that allocate new blocks or lists
339 are unsuitable for use by interrupt handlers.
341 returns a null pointer when it runs out of memory.