1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1997,2008 Oracle.  All rights reserved.
5 *
6 * $Id: os_seek.c,v 1.7 2008/01/08 20:58:44 bostic Exp $
7 */
8
9#include "db_config.h"
10
11#include "db_int.h"
12
13/*
14 * __os_seek --
15 *	Seek to a page/byte offset in the file.
16 */
17int
18__os_seek(env, fhp, pgno, pgsize, relative)
19	ENV *env;
20	DB_FH *fhp;
21	db_pgno_t pgno;
22	u_int32_t pgsize;
23	u_int32_t relative;
24{
25	off_t offset;
26	int ret;
27
28#if defined(HAVE_STATISTICS)
29	++fhp->seek_count;
30#endif
31
32	offset = (off_t)pgsize * pgno + relative;
33
34	/*
35	 * Use BREW's lseek function IFILE_Seek.  If the seek fails, the source
36	 * returns EBADSEEKPOS.
37	 */
38	ret = IFILE_Seek(fhp->ifp, _SEEK_START, offset);
39
40	if (ret == SUCCESS) {
41		fhp->pgsize = pgsize;
42		fhp->pgno = pgno;
43		fhp->offset = relative;
44		ret = 0;
45	} else {
46		__db_syserr(env, ret,
47		    "seek: %lu: (%lu * %lu) + %lu", (u_long)offset,
48		    (u_long)pgno, (u_long)pgsize, (u_long)relative);
49		ret = __os_posix_err(ret);
50	}
51
52	return (ret);
53}
54