2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1997-2009 Oracle. All rights reserved.
15 * Acquire/release a lock on a byte in a file.
18 __os_fdlock(env, fhp, offset, acquire, nowait)
26 * This functionality is not supported by WinCE, so just fail.
28 * Should only happen if an app attempts to open an environment
29 * with the DB_REGISTER flag.
31 __db_errx(env, "fdlock API not implemented for WinCE, DB_REGISTER "
32 "environment flag not supported.");
40 dbenv = env == NULL ? NULL : env->dbenv;
43 F_ISSET(fhp, DB_FH_OPENED) && fhp->handle != INVALID_HANDLE_VALUE);
45 if (dbenv != NULL && FLD_ISSET(dbenv->verbose, DB_VERB_FILEOPS_ALL))
47 "fileops: flock %s %s offset %lu",
48 fhp->name, acquire ? "acquire": "release", (u_long)offset);
51 * Windows file locking interferes with read/write operations, so we
52 * map the ranges to an area past the end of the file.
54 DB_ASSERT(env, offset < (u_int64_t)INT64_MAX);
55 offset = UINT64_MAX - offset;
57 high = (DWORD)(offset >> 32);
62 !LockFile(fhp->handle, low, high, 1, 0), ret);
63 else if (__os_is_winnt()) {
64 memset(&over, 0, sizeof(over));
66 over.OffsetHigh = high;
68 !LockFileEx(fhp->handle, LOCKFILE_EXCLUSIVE_LOCK,
72 /* Windows 9x/ME doesn't support a blocking call. */
75 !LockFile(fhp->handle, low, high, 1, 0),
77 if (__os_posix_err(ret) != EAGAIN)
79 __os_yield(env, 1, 0);
84 !UnlockFile(fhp->handle, low, high, 1, 0), ret);
86 return (__os_posix_err(ret));