os_open.c

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1997, 1998, 1999, 2000
00005  *      Sleepycat Software.  All rights reserved.
00006  */
00007 
00008 #include "config.h"
00009 
00010 #ifndef lint
00011 static const char revid[] = "$Id: os__open_8c-source.html,v 1.1 2008/06/08 10:21:26 sebdiaz Exp $";
00012 #endif /* not lint */
00013 
00014 #ifndef NO_SYSTEM_INCLUDES
00015 #include <sys/types.h>
00016 
00017 #include <fcntl.h>
00018 #include <string.h>
00019 #endif
00020 
00021 #include "db_int.h"
00022 
00023 /*
00024  * CDB___os_open --
00025  *      Open a file.
00026  *
00027  * PUBLIC: int CDB___os_open __P((DB_ENV *, const char *, u_int32_t, int, DB_FH *));
00028  */
00029 int
00030 CDB___os_open(dbenv, name, flags, mode, fhp)
00031         DB_ENV *dbenv;
00032         const char *name;
00033         u_int32_t flags;
00034         int mode;
00035         DB_FH *fhp;
00036 {
00037         int oflags, ret;
00038 
00039         oflags = 0;
00040 
00041         /*
00042          * DB requires the POSIX 1003.1 semantic that two files opened at the
00043          * same time with DB_OSO_CREATE/O_CREAT and DB_OSO_EXCL/O_EXCL flags
00044          * set return an EEXIST failure in at least one.
00045          */
00046         if (LF_ISSET(DB_OSO_CREATE))
00047                 oflags |= O_CREAT;
00048 
00049         if (LF_ISSET(DB_OSO_EXCL))
00050                 oflags |= O_EXCL;
00051 
00052 #if defined(O_DSYNC) && defined(XXX_NEVER_SET)
00053         /*
00054          * !!!
00055          * We should get better performance if we push the log files to disk
00056          * immediately instead of waiting for the sync.  However, Solaris
00057          * (and likely any other system based on the 4BSD filesystem releases),
00058          * doesn't implement O_DSYNC correctly, only flushing data blocks and
00059          * not inode or indirect blocks.
00060          */
00061         if (LF_ISSET(DB_OSO_LOG))
00062                 oflags |= O_DSYNC;
00063 #endif
00064 
00065         if (LF_ISSET(DB_OSO_RDONLY))
00066                 oflags |= O_RDONLY;
00067         else
00068                 oflags |= O_RDWR;
00069 
00070         if (LF_ISSET(DB_OSO_TRUNC))
00071                 oflags |= O_TRUNC;
00072 
00073         /* Open the file. */
00074         if ((ret = CDB___os_openhandle(dbenv, name, oflags, mode, fhp)) != 0)
00075                 return (ret);
00076 
00077         /*
00078          * Delete any temporary file.
00079          *
00080          * !!!
00081          * There's a race here, where we've created a file and we crash before
00082          * we can unlink it.  Temporary files aren't common in DB, regardless,
00083          * it's not a security problem because the file is empty.  There's no
00084          * reasonable way to avoid the race (playing signal games isn't worth
00085          * the portability nightmare), so we just live with it.
00086          */
00087         if (LF_ISSET(DB_OSO_TEMP))
00088                 (void)CDB___os_unlink(dbenv, name);
00089 
00090         return (0);
00091 }

Generated on Sun Jun 8 10:56:38 2008 for GNUmifluz by  doxygen 1.5.5