📄 os_handle.c
字号:
/*- * See the file LICENSE for redistribution information. * * Copyright (c) 1998-2002 * Sleepycat Software. All rights reserved. */#include "db_config.h"#ifndef lintstatic const char revid[] = "$Id: os_handle.c,v 1.1.1.1 2004/08/19 23:53:56 gopalan Exp $";#endif /* not lint */#ifndef __KERNEL__#ifndef NO_SYSTEM_INCLUDES#include <sys/types.h>#include <fcntl.h>#include <string.h>#include <unistd.h>#endif#else#include <linux/slab.h>#include <linux/file.h>#include <linux/types.h>#include <linux/string.h>#endif /* __KERNEL__ */#include "db_int.h"//static int temp_flag=O_CREAT | O_EXCL | O_RDWR;/* * __os_openhandle -- * Open a file, using POSIX 1003.1 open flags. * * PUBLIC: int __os_openhandle __P((DB_ENV *, const char *, int, int, DB_FH *)); */int__os_openhandle(dbenv, name, flags, mode, fhp) DB_ENV *dbenv; const char *name; int flags, mode; DB_FH *fhp;{ int ret, nrepeat; print_entry_location(); memset(fhp, 0, sizeof(*fhp)); /* If the application specified an interface, use it. */ if (DB_GLOBAL(j_open) != NULL) { if ((fhp->fd = DB_GLOBAL(j_open)(name, flags, mode)) == NULL) return (__os_get_errno()); F_SET(fhp, DB_FH_VALID); return (0); } for (nrepeat = 1; nrepeat < 4; ++nrepeat) { ret = 0; fhp->fd = filp_open(name, flags, mode); if (IS_ERR(fhp->fd)) { (void)__os_sleep(dbenv, nrepeat * 2, 0); continue; } //XXX in user level db3 here there fcntl system call. But from the comments there it only //applies to user level processes XXX F_SET(fhp, DB_FH_VALID); break; } if (IS_ERR(fhp->fd)) { ret = PTR_ERR(fhp->fd); } print_exit_location(ret); return (ret);}/* * __os_closehandle -- * Close a file. * * PUBLIC: int __os_closehandle __P((DB_ENV *, DB_FH *)); */int__os_closehandle(dbenv, fhp) DB_ENV *dbenv; DB_FH *fhp;{ int ret = 0; print_entry_location(); if (F_ISSET(fhp, DB_FH_UNLINK)) { (void)__os_unlink(dbenv, fhp->name); (void)__os_free(dbenv, fhp->name); } fput(fhp->fd); F_CLR(fhp, DB_FH_VALID); print_exit_location(ret); return ret; #if 0 print_entry_location();#ifndef __KERNEL__ /* Don't close file descriptors that were never opened. */ DB_ASSERT(F_ISSET(fhp, DB_FH_VALID) && fhp->fd != -1); do { ret = DB_GLOBAL(j_close) != NULL ? DB_GLOBAL(j_close)(fhp->fd) : close(fhp->fd); } while (ret != 0 && (ret = __os_get_errno()) == EINTR);#else fput(fhp->fd);#endif /* __KERNEL__ */ /* Unlink the file if we haven't already done so. */ if (F_ISSET(fhp, DB_FH_UNLINK)) { (void)__os_unlink(dbenv, fhp->name); (void)__os_free(dbenv, fhp->name); } /* * Smash the POSIX file descriptor -- it's never tested, but we want * to catch any mistakes. */#ifndef __KERNEL__ fhp->fd = -1;#else fhp->fd = NULL; ret = 0;#endif F_CLR(fhp, DB_FH_VALID); print_exit_location(ret);#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -