summaryrefslogtreecommitdiffstats
path: root/src/include/buffer.h
blob: 0085c7d16ffdbe2f5c94ae45c856afe14e673ceb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef BUFFER_H
#define BUFFER_H

#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,
 * i.e. occupies all the remaining space up to the end of the buffer.
 * When the tail byte is non-zero, it indicates that the remainder of
 * the descriptor (the struct buffer_free_block) follows the tail
 * byte.
 *
 * This scheme is necessary because we may end up with a tail that is
 * smaller than a struct buffer_free_block.
 *
 */
struct buffer_free_block {
	char		tail;
	physaddr_t	next_free;
	physaddr_t	end;
} __attribute__ (( packed ));

/* This must be provided by the architecture-dependent load_buffer.c */
extern struct buffer load_buffer;

/* Functions in buffer.c */

extern void init_buffer ( struct buffer *buffer );
extern int fill_buffer ( struct buffer *buffer, const void *data,
			 off_t offset, size_t len );

#endif /* BUFFER_H */