1 /*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1997, 2013 Oracle and/or its affiliates. All rights reserved.
5 *
6 * $Id$
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 *
17 * PUBLIC: int __os_seek __P((ENV *,
18 * PUBLIC: DB_FH *, db_pgno_t, u_int32_t, off_t));
19 */
20 int
__os_seek(env,fhp,pgno,pgsize,relative)21 __os_seek(env, fhp, pgno, pgsize, relative)
22 ENV *env;
23 DB_FH *fhp;
24 db_pgno_t pgno;
25 u_int32_t pgsize;
26 off_t relative;
27 {
28 DB_ENV *dbenv;
29 off_t offset;
30 int ret;
31
32 dbenv = env == NULL ? NULL : env->dbenv;
33
34 DB_ASSERT(env, F_ISSET(fhp, DB_FH_OPENED) && fhp->fd != -1);
35
36 #if defined(HAVE_STATISTICS)
37 ++fhp->seek_count;
38 #endif
39
40 offset = (off_t)pgsize * pgno + relative;
41
42 if (dbenv != NULL && FLD_ISSET(dbenv->verbose, DB_VERB_FILEOPS_ALL))
43 __db_msg(env, DB_STR_A("0170",
44 "fileops: seek %s to %lu", "%s %lu"),
45 fhp->name, (u_long)offset);
46
47 if (DB_GLOBAL(j_seek) != NULL)
48 ret = DB_GLOBAL(j_seek)(fhp->fd, offset, SEEK_SET);
49 else
50 RETRY_CHK((lseek(
51 fhp->fd, offset, SEEK_SET) == -1 ? 1 : 0), ret);
52
53 if (ret == 0) {
54 fhp->pgsize = pgsize;
55 fhp->pgno = pgno;
56 fhp->offset = relative;
57 } else {
58 __db_syserr(env, ret, DB_STR_A("0171",
59 "seek: %lu: (%lu * %lu) + %lu", "%lu %lu %lu %lu"),
60 (u_long)offset, (u_long)pgno, (u_long)pgsize,
61 (u_long)relative);
62 ret = __os_posix_err(ret);
63 }
64
65 return (ret);
66 }
67