@@ -222,10 +222,10 @@ static int read_block(struct reftable_block_source *source,
222
222
return block_source_read_data (source , dest , off , sz );
223
223
}
224
224
225
- int block_reader_init (struct block_reader * br ,
226
- struct reftable_block_source * source ,
227
- uint32_t offset , uint32_t header_size ,
228
- uint32_t table_block_size , uint32_t hash_size )
225
+ int reftable_block_init (struct reftable_block * block ,
226
+ struct reftable_block_source * source ,
227
+ uint32_t offset , uint32_t header_size ,
228
+ uint32_t table_block_size , uint32_t hash_size )
229
229
{
230
230
uint32_t guess_block_size = table_block_size ?
231
231
table_block_size : DEFAULT_BLOCK_SIZE ;
@@ -236,59 +236,59 @@ int block_reader_init(struct block_reader *br,
236
236
uint8_t block_type ;
237
237
int err ;
238
238
239
- err = read_block (source , & br -> block_data , offset , guess_block_size );
239
+ err = read_block (source , & block -> block_data , offset , guess_block_size );
240
240
if (err < 0 )
241
241
goto done ;
242
242
243
- block_type = br -> block_data .data [header_size ];
243
+ block_type = block -> block_data .data [header_size ];
244
244
if (!reftable_is_block_type (block_type )) {
245
245
err = REFTABLE_FORMAT_ERROR ;
246
246
goto done ;
247
247
}
248
248
249
- block_size = reftable_get_be24 (br -> block_data .data + header_size + 1 );
249
+ block_size = reftable_get_be24 (block -> block_data .data + header_size + 1 );
250
250
if (block_size > guess_block_size ) {
251
- err = read_block (source , & br -> block_data , offset , block_size );
251
+ err = read_block (source , & block -> block_data , offset , block_size );
252
252
if (err < 0 )
253
253
goto done ;
254
254
}
255
255
256
256
if (block_type == BLOCK_TYPE_LOG ) {
257
257
uint32_t block_header_skip = 4 + header_size ;
258
258
uLong dst_len = block_size - block_header_skip ;
259
- uLong src_len = br -> block_data .len - block_header_skip ;
259
+ uLong src_len = block -> block_data .len - block_header_skip ;
260
260
261
261
/* Log blocks specify the *uncompressed* size in their header. */
262
- REFTABLE_ALLOC_GROW_OR_NULL (br -> uncompressed_data , block_size ,
263
- br -> uncompressed_cap );
264
- if (!br -> uncompressed_data ) {
262
+ REFTABLE_ALLOC_GROW_OR_NULL (block -> uncompressed_data , block_size ,
263
+ block -> uncompressed_cap );
264
+ if (!block -> uncompressed_data ) {
265
265
err = REFTABLE_OUT_OF_MEMORY_ERROR ;
266
266
goto done ;
267
267
}
268
268
269
269
/* Copy over the block header verbatim. It's not compressed. */
270
- memcpy (br -> uncompressed_data , br -> block_data .data , block_header_skip );
270
+ memcpy (block -> uncompressed_data , block -> block_data .data , block_header_skip );
271
271
272
- if (!br -> zstream ) {
273
- REFTABLE_CALLOC_ARRAY (br -> zstream , 1 );
274
- if (!br -> zstream ) {
272
+ if (!block -> zstream ) {
273
+ REFTABLE_CALLOC_ARRAY (block -> zstream , 1 );
274
+ if (!block -> zstream ) {
275
275
err = REFTABLE_OUT_OF_MEMORY_ERROR ;
276
276
goto done ;
277
277
}
278
278
279
- err = inflateInit (br -> zstream );
279
+ err = inflateInit (block -> zstream );
280
280
} else {
281
- err = inflateReset (br -> zstream );
281
+ err = inflateReset (block -> zstream );
282
282
}
283
283
if (err != Z_OK ) {
284
284
err = REFTABLE_ZLIB_ERROR ;
285
285
goto done ;
286
286
}
287
287
288
- br -> zstream -> next_in = br -> block_data .data + block_header_skip ;
289
- br -> zstream -> avail_in = src_len ;
290
- br -> zstream -> next_out = br -> uncompressed_data + block_header_skip ;
291
- br -> zstream -> avail_out = dst_len ;
288
+ block -> zstream -> next_in = block -> block_data .data + block_header_skip ;
289
+ block -> zstream -> avail_in = src_len ;
290
+ block -> zstream -> next_out = block -> uncompressed_data + block_header_skip ;
291
+ block -> zstream -> avail_out = dst_len ;
292
292
293
293
/*
294
294
* We know both input as well as output size, and we know that
@@ -297,71 +297,71 @@ int block_reader_init(struct block_reader *br,
297
297
* here to instruct zlib to inflate the data in one go, which
298
298
* is more efficient than using `Z_NO_FLUSH`.
299
299
*/
300
- err = inflate (br -> zstream , Z_FINISH );
300
+ err = inflate (block -> zstream , Z_FINISH );
301
301
if (err != Z_STREAM_END ) {
302
302
err = REFTABLE_ZLIB_ERROR ;
303
303
goto done ;
304
304
}
305
305
err = 0 ;
306
306
307
- if (br -> zstream -> total_out + block_header_skip != block_size ) {
307
+ if (block -> zstream -> total_out + block_header_skip != block_size ) {
308
308
err = REFTABLE_FORMAT_ERROR ;
309
309
goto done ;
310
310
}
311
311
312
312
/* We're done with the input data. */
313
- block_source_release_data (& br -> block_data );
314
- br -> block_data .data = br -> uncompressed_data ;
315
- br -> block_data .len = block_size ;
316
- full_block_size = src_len + block_header_skip - br -> zstream -> avail_in ;
313
+ block_source_release_data (& block -> block_data );
314
+ block -> block_data .data = block -> uncompressed_data ;
315
+ block -> block_data .len = block_size ;
316
+ full_block_size = src_len + block_header_skip - block -> zstream -> avail_in ;
317
317
} else if (full_block_size == 0 ) {
318
318
full_block_size = block_size ;
319
- } else if (block_size < full_block_size && block_size < br -> block_data .len &&
320
- br -> block_data .data [block_size ] != 0 ) {
319
+ } else if (block_size < full_block_size && block_size < block -> block_data .len &&
320
+ block -> block_data .data [block_size ] != 0 ) {
321
321
/* If the block is smaller than the full block size, it is
322
322
padded (data followed by '\0') or the next block is
323
323
unaligned. */
324
324
full_block_size = block_size ;
325
325
}
326
326
327
- restart_count = reftable_get_be16 (br -> block_data .data + block_size - 2 );
327
+ restart_count = reftable_get_be16 (block -> block_data .data + block_size - 2 );
328
328
restart_off = block_size - 2 - 3 * restart_count ;
329
329
330
- br -> block_type = block_type ;
331
- br -> hash_size = hash_size ;
332
- br -> restart_off = restart_off ;
333
- br -> full_block_size = full_block_size ;
334
- br -> header_off = header_size ;
335
- br -> restart_count = restart_count ;
330
+ block -> block_type = block_type ;
331
+ block -> hash_size = hash_size ;
332
+ block -> restart_off = restart_off ;
333
+ block -> full_block_size = full_block_size ;
334
+ block -> header_off = header_size ;
335
+ block -> restart_count = restart_count ;
336
336
337
337
err = 0 ;
338
338
339
339
done :
340
340
if (err < 0 )
341
- block_reader_release ( br );
341
+ reftable_block_release ( block );
342
342
return err ;
343
343
}
344
344
345
- void block_reader_release (struct block_reader * br )
345
+ void reftable_block_release (struct reftable_block * block )
346
346
{
347
- inflateEnd (br -> zstream );
348
- reftable_free (br -> zstream );
349
- reftable_free (br -> uncompressed_data );
350
- block_source_release_data (& br -> block_data );
351
- memset (br , 0 , sizeof (* br ));
347
+ inflateEnd (block -> zstream );
348
+ reftable_free (block -> zstream );
349
+ reftable_free (block -> uncompressed_data );
350
+ block_source_release_data (& block -> block_data );
351
+ memset (block , 0 , sizeof (* block ));
352
352
}
353
353
354
- uint8_t block_reader_type (const struct block_reader * r )
354
+ uint8_t reftable_block_type (const struct reftable_block * b )
355
355
{
356
- return r -> block_data .data [r -> header_off ];
356
+ return b -> block_data .data [b -> header_off ];
357
357
}
358
358
359
- int block_reader_first_key (const struct block_reader * br , struct reftable_buf * key )
359
+ int reftable_block_first_key (const struct reftable_block * block , struct reftable_buf * key )
360
360
{
361
- int off = br -> header_off + 4 , n ;
361
+ int off = block -> header_off + 4 , n ;
362
362
struct string_view in = {
363
- .buf = br -> block_data .data + off ,
364
- .len = br -> restart_off - off ,
363
+ .buf = block -> block_data .data + off ,
364
+ .len = block -> restart_off - off ,
365
365
};
366
366
uint8_t extra = 0 ;
367
367
@@ -376,33 +376,33 @@ int block_reader_first_key(const struct block_reader *br, struct reftable_buf *k
376
376
return 0 ;
377
377
}
378
378
379
- static uint32_t block_reader_restart_offset (const struct block_reader * br , size_t idx )
379
+ static uint32_t block_restart_offset (const struct reftable_block * b , size_t idx )
380
380
{
381
- return reftable_get_be24 (br -> block_data .data + br -> restart_off + 3 * idx );
381
+ return reftable_get_be24 (b -> block_data .data + b -> restart_off + 3 * idx );
382
382
}
383
383
384
- void block_iter_seek_start (struct block_iter * it , const struct block_reader * br )
384
+ void block_iter_seek_start (struct block_iter * it , const struct reftable_block * b )
385
385
{
386
- it -> block = br -> block_data .data ;
387
- it -> block_len = br -> restart_off ;
388
- it -> hash_size = br -> hash_size ;
386
+ it -> block = b -> block_data .data ;
387
+ it -> block_len = b -> restart_off ;
388
+ it -> hash_size = b -> hash_size ;
389
389
reftable_buf_reset (& it -> last_key );
390
- it -> next_off = br -> header_off + 4 ;
390
+ it -> next_off = b -> header_off + 4 ;
391
391
}
392
392
393
393
struct restart_needle_less_args {
394
394
int error ;
395
395
struct reftable_buf needle ;
396
- const struct block_reader * reader ;
396
+ const struct reftable_block * block ;
397
397
};
398
398
399
399
static int restart_needle_less (size_t idx , void * _args )
400
400
{
401
401
struct restart_needle_less_args * args = _args ;
402
- uint32_t off = block_reader_restart_offset (args -> reader , idx );
402
+ uint32_t off = block_restart_offset (args -> block , idx );
403
403
struct string_view in = {
404
- .buf = args -> reader -> block_data .data + off ,
405
- .len = args -> reader -> restart_off - off ,
404
+ .buf = args -> block -> block_data .data + off ,
405
+ .len = args -> block -> restart_off - off ,
406
406
};
407
407
uint64_t prefix_len , suffix_len ;
408
408
uint8_t extra ;
@@ -477,12 +477,12 @@ void block_iter_close(struct block_iter *it)
477
477
reftable_buf_release (& it -> scratch );
478
478
}
479
479
480
- int block_iter_seek_key (struct block_iter * it , const struct block_reader * br ,
480
+ int block_iter_seek_key (struct block_iter * it , const struct reftable_block * block ,
481
481
struct reftable_buf * want )
482
482
{
483
483
struct restart_needle_less_args args = {
484
484
.needle = * want ,
485
- .reader = br ,
485
+ .block = block ,
486
486
};
487
487
struct reftable_record rec ;
488
488
int err = 0 ;
@@ -500,7 +500,7 @@ int block_iter_seek_key(struct block_iter *it, const struct block_reader *br,
500
500
* restart point. While that works alright, we would end up scanning
501
501
* too many record.
502
502
*/
503
- i = binsearch (br -> restart_count , & restart_needle_less , & args );
503
+ i = binsearch (block -> restart_count , & restart_needle_less , & args );
504
504
if (args .error ) {
505
505
err = REFTABLE_FORMAT_ERROR ;
506
506
goto done ;
@@ -525,21 +525,21 @@ int block_iter_seek_key(struct block_iter *it, const struct block_reader *br,
525
525
* starting from the preceding restart point.
526
526
*/
527
527
if (i > 0 )
528
- it -> next_off = block_reader_restart_offset ( br , i - 1 );
528
+ it -> next_off = block_restart_offset ( block , i - 1 );
529
529
else
530
- it -> next_off = br -> header_off + 4 ;
531
- it -> block = br -> block_data .data ;
532
- it -> block_len = br -> restart_off ;
533
- it -> hash_size = br -> hash_size ;
530
+ it -> next_off = block -> header_off + 4 ;
531
+ it -> block = block -> block_data .data ;
532
+ it -> block_len = block -> restart_off ;
533
+ it -> hash_size = block -> hash_size ;
534
534
535
- err = reftable_record_init (& rec , block_reader_type ( br ));
535
+ err = reftable_record_init (& rec , reftable_block_type ( block ));
536
536
if (err < 0 )
537
537
goto done ;
538
538
539
539
/*
540
540
* We're looking for the last entry less than the wanted key so that
541
541
* the next call to `block_reader_next()` would yield the wanted
542
- * record. We thus don't want to position our reader at the sought
542
+ * record. We thus don't want to position our iterator at the sought
543
543
* after record, but one before. To do so, we have to go one entry too
544
544
* far and then back up.
545
545
*/
0 commit comments