1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 1997,2008 Oracle. All rights reserved. 5 * 6 * $Id: os_unlink.c,v 12.18 2008/02/18 19:34:21 bostic Exp $ 7 */ 8 9#include "db_config.h" 10 11#include "db_int.h" 12 13/* 14 * __os_unlink -- 15 * Remove a file. 16 * 17 * PUBLIC: int __os_unlink __P((ENV *, const char *, int)); 18 */ 19int 20__os_unlink(env, path, overwrite_test) 21 ENV *env; 22 const char *path; 23 int overwrite_test; 24{ 25 DB_ENV *dbenv; 26 int ret, t_ret; 27 28 dbenv = env == NULL ? NULL : env->dbenv; 29 30 if (dbenv != NULL && 31 FLD_ISSET(dbenv->verbose, DB_VERB_FILEOPS | DB_VERB_FILEOPS_ALL)) 32 __db_msg(env, "fileops: unlink %s", path); 33 34 /* Optionally overwrite the contents of the file to enhance security. */ 35 if (dbenv != NULL && overwrite_test && F_ISSET(dbenv, DB_ENV_OVERWRITE)) 36 (void)__db_file_multi_write(env, path); 37 38 LAST_PANIC_CHECK_BEFORE_IO(env); 39 40 if (DB_GLOBAL(j_unlink) != NULL) 41 ret = DB_GLOBAL(j_unlink)(path); 42 else { 43 RETRY_CHK((unlink(CHAR_STAR_CAST path)), ret); 44#ifdef HAVE_QNX 45 /* 46 * The file may be a region file created by shm_open, not a 47 * regular file. Try and delete using unlink, and if that 48 * fails for an unexpected reason, try a shared memory unlink. 49 */ 50 if (ret != 0 && __os_posix_err(ret) != ENOENT) 51 RETRY_CHK((shm_unlink(path)), ret); 52#endif 53 } 54 55 /* 56 * !!! 57 * The results of unlink are file system driver specific on VxWorks. 58 * In the case of removing a file that did not exist, some, at least, 59 * return an error, but with an errno of 0, not ENOENT. We do not 60 * have to test for that explicitly, the RETRY_CHK macro resets "ret" 61 * to be the errno, and so we'll just slide right on through. 62 * 63 * XXX 64 * We shouldn't be testing for an errno of ENOENT here, but ENOENT 65 * signals that a file is missing, and we attempt to unlink things 66 * (such as v. 2.x environment regions, in ENV->remove) that we 67 * are expecting not to be there. Reporting errors in these cases 68 * is annoying. 69 */ 70 if (ret != 0) { 71 t_ret = __os_posix_err(ret); 72 if (t_ret != ENOENT) 73 __db_syserr(env, ret, "unlink: %s", path); 74 ret = t_ret; 75 } 76 77 return (ret); 78} 79