allocb, iallocb, freeb, freeblist, BLEN, BALLOC, blocklen, blockalloclen, readblist, concatblock, copyblock, trimblock, packblock, padblock, pullblock, pullupblock, adjustblock, checkb – data block management
Block* allocb(int size)
Block* iallocb(int size)
void freeb(Block *b)
void freeblist(Block *b)
int blocklen(Block *b)
int blockalloclen(Block *b)
long readblist(Block *b, uchar *p, long n, ulong offset)
Block* concatblock(Block *b)
Block* copyblock(Block *b, int n)
Block* trimblock(Block *b, int offset, int n)
Block* packblock(Block *b)
Block* padblock(Block *b, int n)
int pullblock(Block **bph, int n)
Block* pullupblock(Block *b, int n)
Block* adjustblock(Block *b, int n)
void checkb(Block *b, char *msg)
unhandled troff command .sp
#define BLEN(s) ((s)->wp - (s)->rp)
#define BALLOC(s) ((s)->lim - (s)->base)
provides a receptacle for data:
unhandled troff command .DT
uchar* rp; /* first unconsumed byte */
uchar* wp; /* first empty byte */
uchar* lim; /* 1 past the end of the buffer */
uchar* base; /* start of the buffer */
ushort checksum; /* IP checksum of complete packet */
has an associated buffer, located at
and accessed via
when filling the buffer, or
when fetching data from it.
Each pointer should be incremented to reflect the amount of data written or read.
is empty when
bounds the allocated space.
Some operations described below accept lists of
chained via their
pointers, with a null pointer ending the list.
are usually intended for a
but can be used independently.
and its buffer are normally allocated by one call to
and aligned on an 8 byte (BY2V) boundary.
Some devices with particular allocation constraints
(eg, requiring certain addresses for DMA) might allocate their own
must then point to a function that can deallocate the specially allocated
operations cannot be used in interrupt handlers
because they either
or raise an
Of operations that allocate blocks, only
of at least
is initially empty:
point to the start of the data.
If it cannot allocate memory,
it cannot be used by an interrupt handler.
is similar to
but is intended for use by interrupt handlers,
and returns a null pointer if no memory is available.
It also limits its allocation to a quota allocated at system initialisation to interrupt-time buffering.
frees a single
(and its buffer).
frees the whole
list of blocks headed by
returns the number of unread bytes in a single block.
returns the number of allocated bytes in a single block.
returns the number of bytes of unread data in the whole list of blocks headed by
returns the number of total bytes allocated in the whole list of blocks headed by
bytes of data at offset
from the list of blocks headed by
then returns the amount of bytes copied. It leaves the block list intact.
if it is not a list, and otherwise
returns a single
containing all the data in the list of blocks
which it frees.
by contrast returns a single
containing a copy of the first
bytes of data in the block list
padding with zeroes if the list contained less than
can pad a single
at either end, to reserve space for protocol headers or trailers.
bytes at the start of the block,
setting the read pointer
to point to the new space.
bytes at the end of the block,
leaving the write pointer
pointing at the new space.
In both cases, it allocates a new
if necessary, freeing the old, and
it always returns a pointer to the resulting
trims the list
to contain no more than
bytes starting at
bytes into the data of the original list.
It returns a new list, freeing unneeded parts of the old.
If no data remains, it returns a null pointer.
in the list
reallocating any block in the list that has four times more available space than actual data.
It returns a pointer to the revised list.
discards up to
bytes from the start of the list headed by
Unneeded blocks are freed.
to point to the new list head
and returns the number of bytes discarded (which might be less than
It is used by transport protocols to discard ack’d data at
the head of a retransmission queue.
rearranges the data in the list of blocks
to ensure that there are at least
bytes of contiguous data in the first block,
and returns a pointer to the new list head.
It frees any blocks that it empties.
It returns a null pointer if there is not enough data in the list.
ensures that the block
has at least
bytes of data, reallocating or padding with zero if necessary.
It returns a pointer to the new
is negative, it frees the block and returns a null pointer.)
does some consistency checking of
the state of
results if things look grim.
It is intended for internal use by the queue I/O routines (see
but could be used elsewhere.
The only functions that can be called at interrupt level are
The others allocate memory and can potentially block.
Many functions directly or indirectly can raise an
and callers must therefore provide for proper error recovery
as described therein to prevent memory leaks and other bugs.
any functions that allocate new blocks or lists
are unsuitable for use by interrupt handlers.
returns a null pointer when it runs out of memory.