コード例 #1
0
ファイル: plog.c プロジェクト: mewbak/panda
// uncompress this chunk, ready for use
void unmarshall_chunk(uint32_t chunk_num) {
    printf ("unmarshalling chunk %d\n", chunk_num);
    PandalogChunk *chunk = &(thePandalog->chunk);
    // read compressed chunk data off disk
    int ret = fseek(thePandalog->file, thePandalog->dir.pos[chunk_num], SEEK_SET);
    assert (ret == 0);
    unsigned long compressed_size = thePandalog->dir.pos[chunk_num+1] - thePandalog->dir.pos[chunk_num] + 1;
    size_t bytes_read = fread(chunk->zbuf, 1, compressed_size, thePandalog->file);
    assert (bytes_read == compressed_size);
    unsigned long uncompressed_size = chunk->size;
    // uncompress it
    printf ("chunk size=%lu compressed=%lu\n", uncompressed_size, compressed_size);
    while (true) {
        ret = uncompress(chunk->buf, &uncompressed_size, chunk->zbuf, compressed_size);
        printf ("ret = %d\n", ret);
        if (ret == Z_BUF_ERROR) {
            // need a bigger buffer
            // make sure we won't int overflow
            assert (chunk->size < UINT32_MAX/2);
            chunk->size *= 2;
            printf ("grew chunk buffer to %d\n", chunk->size);
            free(chunk->buf);
            chunk->buf = (unsigned char *)malloc(chunk->size);
            chunk->buf_p = chunk->buf;
            uncompressed_size = chunk->size;
        } else if (ret == Z_OK) {
            break;
        } else {
            assert(false && "Decompression failed");
        }
    }

    // need to free previous chunk's pandalog entries
    unsigned i;
    for (i = 0; i < chunk->num_entries; i++) {
        __pandalog_free_entry(chunk->entry[i]);
    }

    thePandalog->chunk_num = chunk_num;
    // realloc current chunk arrays if necessary. this always happens on first call.
    if (chunk->max_num_entries < thePandalog->dir.num_entries[chunk_num]) {
        chunk->max_num_entries = thePandalog->dir.num_entries[chunk_num];
        free(chunk->entry);
        chunk->entry = (Panda__LogEntry **)malloc(
                sizeof(Panda__LogEntry *) * chunk->max_num_entries);
    }
    chunk->num_entries = thePandalog->dir.num_entries[chunk_num];
    // unpack pandalog entries out of uncompressed buffer into array of pl entries
    unsigned char *p = chunk->buf;
    for (i = 0; i < chunk->num_entries; i++) {
        assert (p < chunk->buf + chunk->size);
        uint32_t n = *((uint32_t *) p);
        p += sizeof(uint32_t);
        Panda__LogEntry *ple = panda__log_entry__unpack(NULL, n, p);
        p += n;
        chunk->entry[i] = ple;
    }
    chunk->ind_entry = 0;  // a guess
}
コード例 #2
0
ファイル: pandalog.c プロジェクト: EgoIncarnate/panda
Panda__LogEntry *pandalog_read_entry(void) {
    // read the size of the log entry
    size_t n,nbr;
    nbr = gzread(pandalog_file, (void *) &n, sizeof(n));
    if (nbr == 0) {
        return NULL;
    }
    resize_pandalog(n);
    // and then read the entry iself
    gzread(pandalog_file, pandalog_buf, n);
    // and unpack it
    Panda__LogEntry *ple = panda__log_entry__unpack(NULL, n, pandalog_buf);                                             
    if (ple == NULL) {
	return (Panda__LogEntry *)1; //yay special values
    }
    return ple;
}
コード例 #3
0
ファイル: pandalog.c プロジェクト: dagelf/panda
// uncompress this chunk, ready for use
void unmarshall_chunk(uint32_t c) {
    printf ("unmarshalling chunk %d\n", c);
    PandalogChunk *chunk = &(thePandalog->chunk);
    // read compressed chunk data off disk
    int ret = fseek(thePandalog->file, thePandalog->dir.pos[c], SEEK_SET);
    assert (ret == 0);
    unsigned long ccs = thePandalog->dir.pos[c+1] - thePandalog->dir.pos[c] + 1;
    uint32_t n = fread(chunk->zbuf, 1, ccs, thePandalog->file);
    assert (ccs == n);
    unsigned long cs = chunk->size;
    // uncompress it
    printf ("cs=%d ccs=%d\n", (int) cs, (int) ccs);
    ret = uncompress(chunk->buf, &cs, chunk->zbuf, ccs);
    assert (ret == Z_OK);
    thePandalog->chunk_num = c;
    // realloc current chunk arrays if necessary
    if (chunk->max_num_entries < thePandalog->dir.num_entries[c]) {
        chunk->max_num_entries = thePandalog->dir.num_entries[c] * SLACK_MULT;
        chunk->entry = 
            (Panda__LogEntry **) 
            realloc(chunk->entry, 
                    sizeof(Panda__LogEntry *) * chunk->max_num_entries);
    }      
    chunk->num_entries = thePandalog->dir.num_entries[c];
    // unpack pandalog entries out of uncompressed buffer into array of pl entries
    unsigned char *p = chunk->buf;
    uint32_t i;
    for (i=0; i<chunk->num_entries; i++) {
        if (!unmarshall_chunk_first_time && chunk->entry[i] != NULL) {
            // need to free previous chunk's pandalog entries
            __pandalog_free_entry(chunk->entry[i]);
        }
        assert (p < chunk->buf + cs);
        uint32_t n = *((uint32_t *) p);
        p += sizeof(uint32_t);
        Panda__LogEntry *ple = panda__log_entry__unpack(NULL, n, p);
        p += n;
        chunk->entry[i] = ple;
    }
    chunk->ind_entry = 0;  // a guess 
    unmarshall_chunk_first_time = 0;
}
コード例 #4
0
ファイル: plog.c プロジェクト: AmesianX/panda
// uncompress this chunk, ready for use
void unmarshall_chunk(uint32_t c) {
    printf ("unmarshalling chunk %d\n", c);
    PandalogChunk *chunk = &(thePandalog->chunk);
    // read compressed chunk data off disk
    int ret = fseek(thePandalog->file, thePandalog->dir.pos[c], SEEK_SET);
    assert (ret == 0);
    unsigned long ccs = thePandalog->dir.pos[c+1] - thePandalog->dir.pos[c] + 1;
    uint32_t n = fread(chunk->zbuf, 1, ccs, thePandalog->file);
    assert (ccs == n);
    unsigned long cs = chunk->size;
    // uncompress it
    printf ("cs=%d ccs=%d\n", (int) cs, (int) ccs);
    uint8_t done = 0;
    while (!done) {
        ret = uncompress(chunk->buf, &cs, chunk->zbuf, ccs);
        printf ("ret = %d\n", ret);
        if (ret == Z_OK) done = 1;
        else {
            if (ret == Z_BUF_ERROR) {
                // need a bigger buffer
                // make sure we won't int overflow
                assert (chunk->size < UINT32_MAX/2);
                chunk->size *= 2;
                printf ("grew chunk buffer to %d\n", chunk->size);
                chunk->buf = (unsigned char *)
                    realloc(chunk->buf,chunk->size);
                chunk->buf_p = chunk->buf;
                cs = chunk->size;
            }
        }
    }
    printf ("ret =%d\n", ret);
    assert (ret == Z_OK);
    thePandalog->chunk_num = c;
    // realloc current chunk arrays if necessary
    if (chunk->max_num_entries < thePandalog->dir.num_entries[c]) {
        chunk->max_num_entries = thePandalog->dir.num_entries[c];
        chunk->entry =
            (Panda__LogEntry **)
            realloc(chunk->entry,
                    sizeof(Panda__LogEntry *) * chunk->max_num_entries);
    }
    chunk->num_entries = thePandalog->dir.num_entries[c];
    // unpack pandalog entries out of uncompressed buffer into array of pl entries
    unsigned char *p = chunk->buf;
    uint32_t i;
    for (i=0; i<chunk->num_entries; i++) {
        if (!unmarshall_chunk_first_time && chunk->entry[i] != NULL) {
            // need to free previous chunk's pandalog entries
            __pandalog_free_entry(chunk->entry[i]);
        }
        assert (p < chunk->buf + cs);
        uint32_t n = *((uint32_t *) p);
        p += sizeof(uint32_t);
        Panda__LogEntry *ple = panda__log_entry__unpack(NULL, n, p);
        p += n;
        chunk->entry[i] = ple;
    }
    chunk->ind_entry = 0;  // a guess
    unmarshall_chunk_first_time = 0;
}