7
#include <libpsio/psio.h>
9
/* This is strictly used to avoid overflow errors on lseek() calls */
10
#define PSIO_BIGNUM 10000
18
int psio_volseek(psio_vol *vol, ULI page, ULI offset, ULI numvols) {
20
ULI bignum, total_offset;
22
bignum = PSIO_BIGNUM*numvols;
26
/* Set file pointer to beginning of file */
27
errcod = lseek(stream, (ULI) 0, SEEK_SET);
31
/* lseek() through large chunks of the file to avoid offset overflows */
32
for (; page > bignum; page -= bignum) {
33
total_offset = PSIO_BIGNUM * PSIO_PAGELEN;
34
errcod = lseek(stream, total_offset, SEEK_CUR);
39
/* Now compute the final offset including the page-relative term */
40
total_offset = (ULI) page/numvols; /* This should truncate */
41
total_offset *= PSIO_PAGELEN;
42
total_offset += offset; /* Add the page-relative term */
43
errcod = lseek(stream, total_offset, SEEK_CUR);