diff options
Diffstat (limited to 'os_qnx')
-rw-r--r-- | os_qnx/os_qnx_fsync.c | 73 | ||||
-rw-r--r-- | os_qnx/os_qnx_open.c | 79 |
2 files changed, 152 insertions, 0 deletions
diff --git a/os_qnx/os_qnx_fsync.c b/os_qnx/os_qnx_fsync.c new file mode 100644 index 0000000..f22f995 --- /dev/null +++ b/os_qnx/os_qnx_fsync.c @@ -0,0 +1,73 @@ +/*- + * See the file LICENSE for redistribution information. + * + * Copyright (c) 1997-2009 Oracle. All rights reserved. + * + * $Id$ + */ + +#include "db_config.h" + +#include "db_int.h" + +/* + * QNX has special requirements on FSYNC: if the file is a shared memory + * object, we can not call fsync because it is not implemented, instead, + * we set the O_DSYNC flag to the file descriptor and then do an empty + * write so that all data are synced. We only sync this way if the file + * is a shared memory object, other types of ordinary files are still synced + * using fsync, to be not only faster but also atomic. + * We don't just set the O_DSYNC flag on open, since it would force all writes + * to be sync'ed. And we remove the O_DSYNC if it is not originally set to + * the file descriptor before passed in to this function. + * This is slightly different to the VxWorks and hp code above, since QNX does + * supply a fsync call, it just has a unique requirement. + */ +int +__qnx_fsync(fhp) + DB_FH *fhp; +{ + int ret; + int fd, unset, flags; + + fd = fhp->fd; + unset = 1; + ret = flags = 0; + if (F_ISSET(fhp, DB_FH_REGION)) + { + RETRY_CHK(fcntl(fd, F_GETFL), ret); + if (ret == -1) + goto err; + /* + * if already has O_DSYNC flag, we can't remove it + * after the empty write + */ + if (ret & O_DSYNC != 0) + unset = 0; + else { + ret |= O_DSYNC; + flags = ret; + RETRY_CHK(fcntl(fd, F_SETFL, flags), ret); + if (ret == -1) + goto err; + } + /* Do an empty write, to force a sync */ + RETRY_CHK(write(fd, "", 0), ret); + if (ret == -1) + goto err; + /* remove the O_DSYNC flag if necessary */ + if (unset) { + RETRY_CHK(fcntl(fd, F_GETFL), ret); + if (ret == -1) + goto err; + ret &= ~O_DSYNC; + flags = ret; + RETRY_CHK(fcntl(fd, F_SETFL, flags), ret); + if (ret == -1) + goto err; + } + } else + RETRY_CHK(fdatasync(fd), ret); + +err: return (ret); +} diff --git a/os_qnx/os_qnx_open.c b/os_qnx/os_qnx_open.c new file mode 100644 index 0000000..ff45da3 --- /dev/null +++ b/os_qnx/os_qnx_open.c @@ -0,0 +1,79 @@ +/*- + * See the file LICENSE for redistribution information. + * + * Copyright (c) 1997-2009 Oracle. All rights reserved. + * + * $Id$ + */ + +#include "db_config.h" + +#include "db_int.h" + +/* + * __os_qnx_region_open -- + * Open a shared memory region file using POSIX shm_open. + * + * PUBLIC: #ifdef HAVE_QNX + * PUBLIC: int __os_qnx_region_open + * PUBLIC: __P((ENV *, const char *, int, int, DB_FH **)); + * PUBLIC: #endif + */ +int +__os_qnx_region_open(env, name, oflags, mode, fhpp) + ENV *env; + const char *name; + int oflags, mode; + DB_FH **fhpp; +{ + DB_FH *fhp; + int fcntl_flags; + int ret; + + /* + * Allocate the file handle and copy the file name. We generally only + * use the name for verbose or error messages, but on systems where we + * can't unlink temporary files immediately, we use the name to unlink + * the temporary file when the file handle is closed. + * + * Lock the ENV handle and insert the new file handle on the list. + */ + if ((ret = __os_calloc(env, 1, sizeof(DB_FH), &fhp)) != 0) + return (ret); + if ((ret = __os_strdup(env, name, &fhp->name)) != 0) + goto err; + if (env != NULL) { + MUTEX_LOCK(env, env->mtx_env); + TAILQ_INSERT_TAIL(&env->fdlist, fhp, q); + MUTEX_UNLOCK(env, env->mtx_env); + F_SET(fhp, DB_FH_ENVLINK); + } + + /* + * Once we have created the object, we don't need the name + * anymore. Other callers of this will convert themselves. + */ + if ((fhp->fd = shm_open(name, oflags, mode)) == -1) { + ret = __os_posix_err(__os_get_syserr()); +err: (void)__os_closehandle(env, fhp); + return (ret); + } + + F_SET(fhp, DB_FH_OPENED); + +#ifdef HAVE_FCNTL_F_SETFD + /* Deny file descriptor access to any child process. */ + if ((fcntl_flags = fcntl(fhp->fd, F_GETFD)) == -1 || + fcntl(fhp->fd, F_SETFD, fcntl_flags | FD_CLOEXEC) == -1) { + ret = __os_get_syserr(); + __db_syserr(env, ret, "fcntl(F_SETFD)"); + (void)__os_closehandle(env, fhp); + return (__os_posix_err(ret)); + } +#else + COMPQUIET(fcntl_flags, 0); +#endif + F_SET(fhp, DB_FH_OPENED); + *fhpp = fhp; + return (0); +} |