1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 1997-2009 Oracle. All rights reserved. 5 * 6 * $Id$ 7 */ 8 9#include "db_config.h" 10 11#include "db_int.h" 12 13/* 14 * __os_exists -- 15 * Return if the file exists. 16 */ 17int 18__os_exists(env, path, isdirp) 19 ENV *env; 20 const char *path; 21 int *isdirp; 22{ 23 DB_ENV *dbenv; 24 DWORD attrs; 25 _TCHAR *tpath; 26 int ret; 27 28 dbenv = env == NULL ? NULL : env->dbenv; 29 30 TO_TSTRING(env, path, tpath, ret); 31 if (ret != 0) 32 return (ret); 33 34 if (dbenv != NULL && 35 FLD_ISSET(dbenv->verbose, DB_VERB_FILEOPS | DB_VERB_FILEOPS_ALL)) 36 __db_msg(env, "fileops: stat %s", path); 37 38 RETRY_CHK( 39 ((attrs = GetFileAttributes(tpath)) == (DWORD)-1 ? 1 : 0), ret); 40 if (ret == 0) { 41 if (isdirp != NULL) 42 *isdirp = (attrs & FILE_ATTRIBUTE_DIRECTORY); 43 } else 44 ret = __os_posix_err(ret); 45 46 FREE_STRING(env, tpath); 47 return (ret); 48} 49 50/* 51 * __os_ioinfo -- 52 * Return file size and I/O size; abstracted to make it easier 53 * to replace. 54 */ 55int 56__os_ioinfo(env, path, fhp, mbytesp, bytesp, iosizep) 57 ENV *env; 58 const char *path; 59 DB_FH *fhp; 60 u_int32_t *mbytesp, *bytesp, *iosizep; 61{ 62 int ret; 63 BY_HANDLE_FILE_INFORMATION bhfi; 64 unsigned __int64 filesize; 65 66 RETRY_CHK((!GetFileInformationByHandle(fhp->handle, &bhfi)), ret); 67 if (ret != 0) { 68 __db_syserr(env, ret, "GetFileInformationByHandle"); 69 return (__os_posix_err(ret)); 70 } 71 72 filesize = ((unsigned __int64)bhfi.nFileSizeHigh << 32) + 73 bhfi.nFileSizeLow; 74 75 /* Return the size of the file. */ 76 if (mbytesp != NULL) 77 *mbytesp = (u_int32_t)(filesize / MEGABYTE); 78 if (bytesp != NULL) 79 *bytesp = (u_int32_t)(filesize % MEGABYTE); 80 81 /* 82 * The filesystem I/O size is not easily available. In particular, 83 * the values returned by GetDiskFreeSpace() are not very helpful 84 * (NTFS volumes often report 512B clusters, which are too small to 85 * be a useful default). 86 */ 87 if (iosizep != NULL) 88 *iosizep = DB_DEF_IOSIZE; 89 return (0); 90} 91