00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "db_config.h"
00011
00012 #include "db_int.h"
00013
00014
00015
00016
00017
00018 int
00019 __os_seek(dbenv, fhp, pgsize, pageno, relative, isrewind, db_whence)
00020 DB_ENV *dbenv;
00021 DB_FH *fhp;
00022 u_int32_t pgsize;
00023 db_pgno_t pageno;
00024 u_int32_t relative;
00025 int isrewind;
00026 DB_OS_SEEK db_whence;
00027 {
00028
00029 union {
00030 __int64 bigint;
00031 struct {
00032 unsigned long low;
00033 long high;
00034 };
00035 } offbytes;
00036 off_t offset;
00037 int ret, whence;
00038 DWORD from;
00039
00040 offset = (off_t)pgsize * pageno + relative;
00041 if (isrewind)
00042 offset = -offset;
00043
00044 if (DB_GLOBAL(j_seek) != NULL) {
00045 switch (db_whence) {
00046 case DB_OS_SEEK_CUR:
00047 whence = SEEK_CUR;
00048 break;
00049 case DB_OS_SEEK_END:
00050 whence = SEEK_END;
00051 break;
00052 case DB_OS_SEEK_SET:
00053 whence = SEEK_SET;
00054 break;
00055 default:
00056 return (EINVAL);
00057 }
00058
00059 ret = DB_GLOBAL(j_seek)(fhp->fd, offset, whence);
00060 } else {
00061 switch (db_whence) {
00062 case DB_OS_SEEK_CUR:
00063 from = FILE_CURRENT;
00064 break;
00065 case DB_OS_SEEK_END:
00066 from = FILE_END;
00067 break;
00068 case DB_OS_SEEK_SET:
00069 from = FILE_BEGIN;
00070 break;
00071 default:
00072 return (EINVAL);
00073 }
00074
00075 offbytes.bigint = offset;
00076 ret = (SetFilePointer(fhp->handle,
00077 offbytes.low, &offbytes.high, from) == (DWORD) - 1) ?
00078 __os_get_errno() : 0;
00079 }
00080
00081 if (ret == 0) {
00082 fhp->pgsize = pgsize;
00083 fhp->pgno = pageno;
00084 fhp->offset = relative;
00085 } else {
00086 __db_err(dbenv, "seek: %lu %d %d: %s",
00087 (u_long)pgsize * pageno + relative,
00088 isrewind, db_whence, strerror(ret));
00089 }
00090
00091 return (ret);
00092 }