Lines Matching refs:reader

112 static void read_ahead(struct buffered_reader *reader, sector_t block_number)  in read_ahead()  argument
114 if (block_number < reader->limit) { in read_ahead()
116 reader->limit - block_number); in read_ahead()
118 dm_bufio_prefetch(reader->client, block_number, read_ahead); in read_ahead()
122 void uds_free_buffered_reader(struct buffered_reader *reader) in uds_free_buffered_reader() argument
124 if (reader == NULL) in uds_free_buffered_reader()
127 if (reader->buffer != NULL) in uds_free_buffered_reader()
128 dm_bufio_release(reader->buffer); in uds_free_buffered_reader()
130 dm_bufio_client_destroy(reader->client); in uds_free_buffered_reader()
131 uds_put_io_factory(reader->factory); in uds_free_buffered_reader()
132 vdo_free(reader); in uds_free_buffered_reader()
141 struct buffered_reader *reader = NULL; in uds_make_buffered_reader() local
147 result = vdo_allocate(1, struct buffered_reader, "buffered reader", &reader); in uds_make_buffered_reader()
153 *reader = (struct buffered_reader) { in uds_make_buffered_reader()
163 read_ahead(reader, 0); in uds_make_buffered_reader()
165 *reader_ptr = reader; in uds_make_buffered_reader()
169 static int position_reader(struct buffered_reader *reader, sector_t block_number, in position_reader() argument
175 if ((reader->end == NULL) || (block_number != reader->block_number)) { in position_reader()
176 if (block_number >= reader->limit) in position_reader()
179 if (reader->buffer != NULL) in position_reader()
180 dm_bufio_release(vdo_forget(reader->buffer)); in position_reader()
182 data = dm_bufio_read(reader->client, block_number, &buffer); in position_reader()
186 reader->buffer = buffer; in position_reader()
187 reader->start = data; in position_reader()
188 if (block_number == reader->block_number + 1) in position_reader()
189 read_ahead(reader, block_number + 1); in position_reader()
192 reader->block_number = block_number; in position_reader()
193 reader->end = reader->start + offset; in position_reader()
197 static size_t bytes_remaining_in_read_buffer(struct buffered_reader *reader) in bytes_remaining_in_read_buffer() argument
199 return (reader->end == NULL) ? 0 : reader->start + UDS_BLOCK_SIZE - reader->end; in bytes_remaining_in_read_buffer()
202 static int reset_reader(struct buffered_reader *reader) in reset_reader() argument
206 if (bytes_remaining_in_read_buffer(reader) > 0) in reset_reader()
209 block_number = reader->block_number; in reset_reader()
210 if (reader->end != NULL) in reset_reader()
213 return position_reader(reader, block_number, 0); in reset_reader()
216 int uds_read_from_buffered_reader(struct buffered_reader *reader, u8 *data, in uds_read_from_buffered_reader() argument
223 result = reset_reader(reader); in uds_read_from_buffered_reader()
227 chunk_size = min(length, bytes_remaining_in_read_buffer(reader)); in uds_read_from_buffered_reader()
228 memcpy(data, reader->end, chunk_size); in uds_read_from_buffered_reader()
231 reader->end += chunk_size; in uds_read_from_buffered_reader()
241 int uds_verify_buffered_data(struct buffered_reader *reader, const u8 *value, in uds_verify_buffered_data() argument
246 sector_t start_block_number = reader->block_number; in uds_verify_buffered_data()
247 int start_offset = reader->end - reader->start; in uds_verify_buffered_data()
250 result = reset_reader(reader); in uds_verify_buffered_data()
256 chunk_size = min(length, bytes_remaining_in_read_buffer(reader)); in uds_verify_buffered_data()
257 if (memcmp(value, reader->end, chunk_size) != 0) { in uds_verify_buffered_data()
264 reader->end += chunk_size; in uds_verify_buffered_data()
268 position_reader(reader, start_block_number, start_offset); in uds_verify_buffered_data()