Пример #1
0
int libambit_pmem20_gps_orbit_write(ambit_object_t *object, uint8_t *data, size_t datalen)
{
    int ret = -1;
    uint8_t *bufptrs[2];
    size_t bufsizes[2];
    uint8_t startheader[4];
    uint8_t tailbuf[8];
    uint32_t *_sizeptr = (uint32_t*)&startheader[0];
    uint32_t address = PMEM20_GPS_ORBIT_START;
    size_t offset = 0;

    *_sizeptr = htole32(datalen);
    bufptrs[0] = startheader;
    bufsizes[0] = 4;
    bufptrs[1] = data;
    bufsizes[1] = object->pmem20.chunk_size - 4; // We assume that data is
                                                 // always > chunk_size

    // Write first chunk (including length)
    ret = write_data_chunk(object, address, 2, bufptrs, bufsizes);
    offset += bufsizes[1];
    address += object->pmem20.chunk_size;

    // Write rest of the chunks
    while (ret == 0 && offset < datalen) {
        bufptrs[0] = data + offset;
        bufsizes[0] = (datalen - offset > object->pmem20.chunk_size ? object->pmem20.chunk_size : datalen - offset);

        ret = write_data_chunk(object, address, 1, bufptrs, bufsizes);
        offset += bufsizes[0];
        address += bufsizes[0];
    }

    // Write tail length (or what is really!?)
    if (ret == 0) {
        *((uint32_t*)(&tailbuf[0])) = htole32(PMEM20_GPS_ORBIT_START);
        *((uint32_t*)(&tailbuf[4])) = htole32(bufsizes[0]);
        ret = libambit_protocol_command(object, ambit_command_data_tail_len, tailbuf, sizeof(tailbuf), NULL, NULL, 0);
    }

    return ret;
}
Пример #2
0
static void sparse_file_write_block(struct output_file *out,
		struct backed_block *bb)
{
	switch (backed_block_type(bb)) {
	case BACKED_BLOCK_DATA:
		write_data_chunk(out, backed_block_len(bb), backed_block_data(bb));
		break;
	case BACKED_BLOCK_FILE:
		write_file_chunk(out, backed_block_len(bb),
				backed_block_filename(bb), backed_block_file_offset(bb));
		break;
	case BACKED_BLOCK_FD:
		write_fd_chunk(out, backed_block_len(bb),
				backed_block_fd(bb), backed_block_file_offset(bb));
		break;
	case BACKED_BLOCK_FILL:
		write_fill_chunk(out, backed_block_len(bb),
				backed_block_fill_val(bb));
		break;
	}
}