Permalink
Browse files

Add functions to get chunk number and get chunk by number

Signed-off-by: Jonathan Dieter <jdieter@gmail.com>
  • Loading branch information...
jdieter committed Dec 2, 2018
1 parent 8108cb3 commit 692dded4de3e1ca2f9417449c98cd05116ccdaca
Showing with 44 additions and 4 deletions.
  1. +6 −0 include/zck.h.in
  2. +22 −0 src/lib/index/index_read.c
  3. +5 −4 src/zck_read_header.c
  4. +11 −0 test/read_single_chunk.c
@@ -232,6 +232,9 @@ bool zck_validate_lead(zckCtx *zck)
/* Get chunk count */
ssize_t zck_get_chunk_count(zckCtx *zck)
__attribute__ ((warn_unused_result));
/* Get chunk by number */
zckChunk *zck_get_chunk(zckCtx *zck, size_t number)
__attribute__ ((warn_unused_result));
/* Get first chunk */
zckChunk *zck_get_first_chunk(zckCtx *zck)
__attribute__ ((warn_unused_result));
@@ -247,6 +250,9 @@ ssize_t zck_get_chunk_size(zckChunk *idx)
/* Get compressed chunk size */
ssize_t zck_get_chunk_comp_size(zckChunk *idx)
__attribute__ ((warn_unused_result));
/* Get chunk number */
ssize_t zck_get_chunk_number(zckChunk *idx)
__attribute__ ((warn_unused_result));
/* Get validity of current chunk - 1 = valid, 0 = missing, -1 = invalid */
int zck_get_chunk_valid(zckChunk *idx)
__attribute__ ((warn_unused_result));
@@ -118,6 +118,17 @@ ssize_t PUBLIC zck_get_chunk_count(zckCtx *zck) {
return zck->index.count;
}

zckChunk PUBLIC *zck_get_chunk(zckCtx *zck, size_t number) {
VALIDATE_PTR(zck);

for(zckChunk *idx=zck->index.first; idx!=NULL; idx=idx->next) {
if(idx->number == number)
return idx;
}
zck_log(ZCK_LOG_WARNING, "Chunk %lu not found", number);
return NULL;
}

zckChunk PUBLIC *zck_get_first_chunk(zckCtx *zck) {
VALIDATE_PTR(zck);

@@ -171,6 +182,17 @@ ssize_t PUBLIC zck_get_chunk_comp_size(zckChunk *idx) {
return idx->comp_length;
}

ssize_t PUBLIC zck_get_chunk_number(zckChunk *idx) {
if(idx && idx->zck) {
VALIDATE_INT(idx->zck);
ALLOCD_INT(idx->zck, idx);
} else {
ALLOCD_INT(NULL, idx);
}

return idx->number;
}

int PUBLIC zck_get_chunk_valid(zckChunk *idx) {
if(idx && idx->zck) {
VALIDATE_INT(idx->zck);
@@ -169,15 +169,16 @@ int main (int argc, char *argv[]) {
if(arguments.show_chunks) {
printf(" Chunk Checksum %*c Start Comp size Size\n",
(((int)zck_get_chunk_digest_size(zck)*2)-9), ' ');
ssize_t count=0;
for(zckChunk *chk = zck_get_first_chunk(zck); chk;
chk=zck_get_next_chunk(chk), count++) {
for(zckChunk *chk=zck_get_first_chunk(zck); chk;
chk=zck_get_next_chunk(chk)) {
char *digest = zck_get_chunk_digest(chk);
if(digest == NULL) {
dprintf(STDERR_FILENO, "%s", zck_get_error(zck));
exit(1);
}
printf("%12lu %s %12lu %12lu %12lu", count, digest,
printf("%12lu %s %12lu %12lu %12lu",
(long unsigned)zck_get_chunk_number(chk),
digest,
(long unsigned)zck_get_chunk_start(chk),
(long unsigned)zck_get_chunk_comp_size(chk),
(long unsigned)zck_get_chunk_size(chk));
@@ -68,6 +68,17 @@ int main (int argc, char *argv[]) {
zck_free(&zck);
exit(1);
}
zckChunk *chunk1 = zck_get_chunk(zck, 1);
if(chunk == NULL) {
printf("%s", zck_get_error(zck));
zck_free(&zck);
exit(1);
}
if(chunk != chunk1) {
printf("Chunk first->next != chunk 1\n");
zck_free(&zck);
exit(1);
}
ssize_t chunk_size = zck_get_chunk_size(chunk);
if(chunk_size < 0) {
printf("%s", zck_get_error(zck));

0 comments on commit 692dded

Please sign in to comment.