Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

os_flock.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1997-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: os_flock.c,v 12.4 2005/06/20 14:59:01 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 
00015 #include <fcntl.h>
00016 #include <string.h>
00017 #endif
00018 
00019 #include "db_int.h"
00020 
00021 /*
00022  * __os_fdlock --
00023  *      Acquire/release a lock on a byte in a file.
00024  *
00025  * PUBLIC: int __os_fdlock __P((DB_ENV *, DB_FH *, off_t, int, int));
00026  */
00027 int
00028 __os_fdlock(dbenv, fhp, offset, acquire, nowait)
00029         DB_ENV *dbenv;
00030         DB_FH *fhp;
00031         int acquire, nowait;
00032         off_t offset;
00033 {
00034         struct flock fl;
00035         int ret;
00036 
00037         DB_ASSERT(F_ISSET(fhp, DB_FH_OPENED) && fhp->fd != -1);
00038 
00039 #ifdef HAVE_FCNTL
00040         fl.l_start = offset;
00041         fl.l_len = 1;
00042         fl.l_type = acquire ? F_WRLCK : F_UNLCK;
00043         fl.l_whence = SEEK_SET;
00044 
00045         RETRY_CHK_EINTR_ONLY(
00046             (fcntl(fhp->fd, nowait ? F_SETLK : F_SETLKW, &fl)), ret);
00047 
00048         if (ret != 0 && ret != EACCES && ret != EAGAIN)
00049                 __db_err(dbenv, "fcntl: %s", strerror(ret));
00050         return (ret);
00051 #else
00052         __db_err(dbenv,
00053             "advisory file locking unavailable: %s", strerror(DB_OPNOTSUP));
00054         return (DB_OPNOTSUP);
00055 #endif
00056 }

Generated on Sun Dec 25 12:14:42 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2