Return -1 to indicate buffer overflow. Allow buffer fill level to be read

easily from struct buffer.
This commit is contained in:
Michael Brown
2005-05-09 14:26:10 +00:00
parent a89651f3bb
commit bab2924e89
2 changed files with 32 additions and 23 deletions

View File

@@ -3,6 +3,18 @@
#include "stdint.h"
/*
* "start" and "end" denote the real boundaries of the buffer. "fill"
* denotes the offset to the first free block in the buffer. (If the
* buffer is full, "fill" will equal ( end - start ) ).
*
*/
struct buffer {
physaddr_t start;
physaddr_t end;
off_t fill;
};
/*
* Free blocks in the buffer start with a "tail byte". If non-zero,
* this byte indicates that the free block is the tail of the buffer,
@@ -15,24 +27,17 @@
* smaller than a struct buffer_free_block.
*
*/
struct buffer_free_block {
char tail;
physaddr_t next_free;
physaddr_t end;
} __attribute__ (( packed ));
struct buffer {
physaddr_t start;
physaddr_t end;
physaddr_t first_free;
};
/* Functions in buffer.c */
extern void init_buffer ( struct buffer *buffer, physaddr_t start,
size_t len );
extern off_t fill_buffer ( struct buffer *buffer, void *data,
off_t offset, size_t len );
extern int fill_buffer ( struct buffer *buffer, void *data,
off_t offset, size_t len );
#endif /* BUFFER_H */