Пример #1
0
int read_aux_index_swapped32_(int fd, void *idxv, int num)
{
    AuxIndex *idx = idxv;
    AuxIndex32 rec32;
    int i;

    for (i = 0; i < num; i++) {
        int4 image;

        /* LOW LEVEL IO HERE */
        errno = 0;
        if (read(fd, &rec32, sizeof(rec32)) != (int)(sizeof(rec32)))
            return 1;

        swap_int4(rec32.image[0], image);
        idx->image[0] = image;
        swap_int4(rec32.image[1], image);
        idx->image[1] = image;
        swap_GTimeStamp(rec32.time[0],idx->time[0]);
        swap_GTimeStamp(rec32.time[1],idx->time[1]);
        swap_GCardinal(rec32.used[0],idx->used[0]);
        swap_GCardinal(rec32.used[1],idx->used[1]);

        idx++;
    }

    return 0;

}
Пример #2
0
int write_aux_index_swapped32_(int fd, void *idxv, int num)
{
    AuxIndex *idx = idxv;
    AuxIndex32 rec32;

    /* Convert from 64-bit to 32-bit based data structure */
    rec32.image[0] = idx->image[0];
    rec32.image[1] = idx->image[1];
    rec32.time[0]  = idx->time[0];
    rec32.time[1]  = idx->time[1];
    rec32.used[0]  = idx->used[0];
    rec32.used[1]  = idx->used[1];

    /* Byte-swap */
    swap_int4(rec32.image[0],      rec32.image[0]);
    swap_int4(rec32.image[1],      rec32.image[1]);
    swap_GTimeStamp(rec32.time[0], rec32.time[0]);
    swap_GTimeStamp(rec32.time[1], rec32.time[1]);
    swap_GCardinal(rec32.used[0],  rec32.used[0]);
    swap_GCardinal(rec32.used[1],  rec32.used[1]);

    /* LOW LEVEL IO HERE */
    errno = 0;
    return write(fd, &rec32, sizeof(rec32)) != sizeof(rec32);
}
Пример #3
0
int write_aux_header_swapped32_(int fd, void *headerv, int num)
{
    AuxHeader *rec = headerv;
    AuxHeader32 rec32;

    if (rec->format != G_32BIT) {
        fprintf(stderr, "** Expected 32-bit file size data; not found\n");
        return 1;
    }

    /* Convert to 32-bit format */
    header_64to32(rec, &rec32);

    /* byte-swap */
    swap_int4(rec32.file_size,        rec32.file_size);
    swap_GCardinal(rec32.block_size,  rec32.block_size);
    swap_GCardinal(rec32.num_records, rec32.num_records);
    swap_GCardinal(rec32.max_records, rec32.max_records);
    swap_GTimeStamp(rec32.last_time,  rec32.last_time);
    swap_GHFlags(rec32.flags,         rec32.flags);
    swap_GHFlags(rec32.spare1,        rec32.spare1);
    swap_GTimeStamp(rec32.free_time,  rec32.free_time);
    swap_int4(rec32.spare[0],         rec32.spare[0]);
    swap_int4(rec32.spare[1],         rec32.spare[1]);
    swap_int4(rec32.spare[2],         rec32.spare[2]);
    swap_int4(rec32.spare[3],         rec32.spare[3]);
    swap_int4(rec32.spare[4],         rec32.spare[4]);
    swap_int4(rec32.spare[5],         rec32.spare[5]);
    swap_int4(rec32.spare[6],         rec32.spare[6]);
    swap_int4(rec32.format,           rec32.format);

    /* LOW LEVEL IO HERE */
    errno = 0;
    return write(fd, &rec32, sizeof(rec32)) != sizeof(rec32);
}
Пример #4
0
int write_aux_header_swapped64_(int fd, void *headerv, int num)
{
    AuxHeader *header = headerv;
    AuxHeader swapped;

    if (header->format != G_64BIT) {
        fprintf(stderr, "** Expected 64-bit file size data; not found\n");
        return 1;
    }

    swap_GImage(header->file_size,swapped.file_size);
    swap_GCardinal(header->block_size,swapped.block_size);
    swap_GCardinal(header->num_records,swapped.num_records);
    swap_GCardinal(header->max_records,swapped.max_records);
    swap_GTimeStamp(header->last_time,swapped.last_time);
    swap_GHFlags(header->flags,swapped.flags);
    swap_GHFlags(header->spare1,swapped.spare1);
    swap_GTimeStamp(header->free_time,swapped.free_time);
    swap_int4(header->spare[0],swapped.spare[0]);
    swap_int4(header->spare[1],swapped.spare[1]);
    swap_int4(header->spare[2],swapped.spare[2]);
    swap_int4(header->spare[3],swapped.spare[3]);
    swap_int4(header->spare[4],swapped.spare[4]);
    swap_int4(header->spare[5],swapped.spare[5]);
    swap_int4(header->spare[6],swapped.spare[6]);
    swap_int4(header->format,swapped.format);

    errno = 0;
    return write(fd, &swapped, sizeof(swapped)) != sizeof(swapped);
}
Пример #5
0
IO_stat IO_read_int4(int4 *dest, IO_handle stream)
{
	uint4 n = 1;
	IO_stat stat = MCS_read(dest, sizeof(uint4), n, stream);
	if (stat != IO_ERROR)
		swap_int4(dest);
	return stat;
}
Пример #6
0
IO_stat IO_write_int4(int4 dest, IO_handle stream)
{
	swap_int4(&dest);
	return MCS_write(&dest, sizeof(int4), 1, stream);
}
Пример #7
0
int read_aux_header_swapped_(int fd, void *headerv, int num)
{
    AuxHeader rec;

    /* LOW LEVEL IO HERE */
    errno = 0;
    if (sizeof(rec) != read(fd, &rec, sizeof(rec)))
        return 1;

    swap_int4(rec.format, rec.format);
    if (rec.format == G_32BIT) {
        /* byte-swap and remap to 64-bit at the same time */
        AuxHeader32 *rec32 = (AuxHeader32 *)&rec;
        AuxHeader32 swapped;
        int4 file_size;
        swap_int4(rec32->file_size, file_size);
        swapped.file_size = file_size;
        swap_GCardinal(rec32->block_size,  swapped.block_size);
        swap_GCardinal(rec32->num_records, swapped.num_records);
        swap_GCardinal(rec32->max_records, swapped.max_records);
        swap_GTimeStamp(rec32->last_time,  swapped.last_time);
        swap_GHFlags(rec32->flags,         swapped.flags);
        swap_GHFlags(rec32->spare1,        swapped.spare1);
        swap_GTimeStamp(rec32->free_time,  swapped.free_time);
        swap_int4(rec32->spare[0],         swapped.spare[0]);
        swap_int4(rec32->spare[1],         swapped.spare[1]);
        swap_int4(rec32->spare[2],         swapped.spare[2]);
        swap_int4(rec32->spare[3],         swapped.spare[3]);
        swap_int4(rec32->spare[4],         swapped.spare[4]);
        swap_int4(rec32->spare[5],         swapped.spare[5]);
        swap_int4(rec32->spare[6],         swapped.spare[6]);
        swapped.format = G_32BIT;

        header_32to64(&swapped, (AuxHeader *)headerv);
    } else {
        swap_GImage(rec.file_size,      rec.file_size);
        swap_GCardinal(rec.block_size,  rec.block_size);
        swap_GCardinal(rec.num_records, rec.num_records);
        swap_GCardinal(rec.max_records, rec.max_records);
        swap_GTimeStamp(rec.last_time,  rec.last_time);
        swap_GHFlags(rec.flags,         rec.flags);
        swap_GHFlags(rec.spare1,        rec.spare1);
        swap_GTimeStamp(rec.free_time,  rec.free_time);
        swap_int4(rec.spare[0],         rec.spare[0]);
        swap_int4(rec.spare[1],         rec.spare[1]);
        swap_int4(rec.spare[2],         rec.spare[2]);
        swap_int4(rec.spare[3],         rec.spare[3]);
        swap_int4(rec.spare[4],         rec.spare[4]);
        swap_int4(rec.spare[5],         rec.spare[5]);
        swap_int4(rec.spare[6],         rec.spare[6]);

        memcpy(headerv, &rec, sizeof(AuxHeader));
    }

    return 0;
}