|
@@ -41,6 +41,8 @@ void init_buffer ( struct buffer *buffer, physaddr_t start, size_t len ) {
|
41
|
41
|
char tail = 1;
|
42
|
42
|
copy_to_phys ( start, &tail, sizeof ( tail ) );
|
43
|
43
|
}
|
|
44
|
+
|
|
45
|
+ DBG ( "BUFFER [%x,%x) initialised\n", buffer->start, buffer->end );
|
44
|
46
|
}
|
45
|
47
|
|
46
|
48
|
/*
|
|
@@ -57,6 +59,9 @@ static void split_free_block ( struct buffer_free_block *desc,
|
57
|
59
|
if ( split >= desc->end )
|
58
|
60
|
return;
|
59
|
61
|
|
|
62
|
+ DBG ( "BUFFER splitting [%x,%x) into [%x,%x) and [%x,%x)\n",
|
|
63
|
+ block, desc->end, block, split, split, desc->end );
|
|
64
|
+
|
60
|
65
|
/* Create descriptor for new free block */
|
61
|
66
|
copy_to_phys ( split, &desc->tail, sizeof ( desc->tail ) );
|
62
|
67
|
if ( ! desc->tail )
|
|
@@ -80,6 +85,8 @@ static inline void unfree_block ( struct buffer *buffer,
|
80
|
85
|
|
81
|
86
|
/* If this is the first block, just update first_free */
|
82
|
87
|
if ( ! prev_block ) {
|
|
88
|
+ DBG ( "BUFFER marking [%x,%x) as used\n",
|
|
89
|
+ buffer->first_free, desc->end );
|
83
|
90
|
buffer->first_free = desc->next_free;
|
84
|
91
|
return;
|
85
|
92
|
}
|
|
@@ -87,6 +94,9 @@ static inline void unfree_block ( struct buffer *buffer,
|
87
|
94
|
/* Get descriptor for previous block (which cannot be a tail block) */
|
88
|
95
|
copy_from_phys ( &prev_desc, prev_block, sizeof ( prev_desc ) );
|
89
|
96
|
|
|
97
|
+ DBG ( "BUFFER marking [%x,%x) as used\n",
|
|
98
|
+ prev_desc.next_free, desc->end );
|
|
99
|
+
|
90
|
100
|
/* Modify descriptor for previous block and write it back */
|
91
|
101
|
prev_desc.next_free = desc->next_free;
|
92
|
102
|
copy_to_phys ( prev_block, &prev_desc, sizeof ( prev_desc ) );
|
|
@@ -114,6 +124,8 @@ off_t fill_buffer ( struct buffer *buffer, void *data,
|
114
|
124
|
/* Calculate start and end addresses of data */
|
115
|
125
|
data_start = buffer->start + offset;
|
116
|
126
|
data_end = data_start + len;
|
|
127
|
+ DBG ( "BUFFER [%x,%x) writing portion [%x,%x)\n",
|
|
128
|
+ buffer->start, buffer->end, data_start, data_end );
|
117
|
129
|
|
118
|
130
|
/* Iterate through the buffer's free blocks */
|
119
|
131
|
prev_block = 0;
|
|
@@ -133,7 +145,7 @@ off_t fill_buffer ( struct buffer *buffer, void *data,
|
133
|
145
|
/* Block is now either completely contained by or
|
134
|
146
|
* completely outside the data area
|
135
|
147
|
*/
|
136
|
|
- if ( ( block >= data_start ) && ( block <= data_end ) ) {
|
|
148
|
+ if ( ( block >= data_start ) && ( block < data_end ) ) {
|
137
|
149
|
/* Block is within the data area */
|
138
|
150
|
unfree_block ( buffer, &desc, prev_block );
|
139
|
151
|
copy_to_phys ( block, data + ( block - data_start ),
|
|
@@ -147,5 +159,8 @@ off_t fill_buffer ( struct buffer *buffer, void *data,
|
147
|
159
|
block = desc.next_free;
|
148
|
160
|
}
|
149
|
161
|
|
|
162
|
+ DBG ( "BUFFER [%x,%x) full up to %x\n",
|
|
163
|
+ buffer->start, buffer->end, buffer->first_free );
|
|
164
|
+
|
150
|
165
|
return ( buffer->first_free - buffer->start );
|
151
|
166
|
}
|