Browse Source

* imdb_usage_slice()

master
Alex 'AdUser' Z 10 years ago
parent
commit
e8a35c273d
  1. 25
      src/database.c
  2. 13
      src/database.h

25
src/database.c

@ -323,3 +323,28 @@ imdb_usage_map(imdb_db_t * const db,
return records; return records;
} }
uint16_t
imdb_usage_slice(imdb_db_t * const db,
char ** const map,
uint64_t offset,
uint16_t limit) {
imdb_block_t blk;
unsigned char *r; /* mnemonics : block, record */
char *m = NULL; /* mnemonics : map */
memset(&blk, 0x0, sizeof(imdb_block_t));
CALLOC(*map, limit + 1, sizeof(char));
m = *map;
blk.start = offset;
blk.records = limit;
limit = imdb_read_blk(db, &blk);
r = blk.data;
for (uint16_t i = 0; i < blk.records; i++, m++, r += IMDB_REC_LEN) {
*m = (r[REC_OFF_RU] == 0xFF) ? CHAR_USED : CHAR_NONE;
}
return limit;
}

13
src/database.h

@ -130,4 +130,17 @@ imdb_records_count(imdb_db_t * const db);
uint64_t uint64_t
imdb_usage_map(imdb_db_t * const db, imdb_usage_map(imdb_db_t * const db,
char ** const map); char ** const map);
/**
@brief fills buffer 'map' according to records existense in given range
@param offset start of slice position
@param limit slice size
@returns records processed (and also buffer size)
*/
uint16_t
imdb_usage_slice(imdb_db_t * const db,
char ** const map,
uint64_t offset,
uint16_t limit);
#endif #endif

Loading…
Cancel
Save