1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 1999-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_is_winnt -- 15 * Return 1 if Windows/NT, otherwise 0. 16 * 17 * PUBLIC: int __os_is_winnt __P((void)); 18 */ 19int 20__os_is_winnt() 21{ 22#ifdef DB_WINCE 23 return (1); 24#else 25 static int __os_type = -1; 26 27 /* 28 * The value of __os_type is computed only once, and cached to 29 * avoid the overhead of repeated calls to GetVersion(). 30 */ 31 if (__os_type == -1) { 32 if ((GetVersion() & 0x80000000) == 0) 33 __os_type = 1; 34 else 35 __os_type = 0; 36 } 37 return (__os_type); 38#endif 39} 40 41/* 42 * __os_fs_notzero -- 43 * Return 1 if allocated filesystem blocks are not zeroed. 44 */ 45int 46__os_fs_notzero() 47{ 48#ifdef DB_WINCE 49 return (1); 50#else 51 static int __os_notzero = -1; 52 OSVERSIONINFO osvi; 53 54 /* 55 * Windows/NT zero-fills pages that were never explicitly written to 56 * the file. Note however that this is *NOT* documented. In fact, the 57 * Win32 documentation makes it clear that there are no guarantees that 58 * uninitialized bytes will be zeroed: 59 * 60 * If the file is extended, the contents of the file between the old 61 * EOF position and the new position are not defined. 62 * 63 * Experiments confirm that NT/2K/XP all zero fill for both NTFS and 64 * FAT32. Cygwin also relies on this behavior. This is the relevant 65 * comment from Cygwin: 66 * 67 * Oops, this is the bug case - Win95 uses whatever is on the disk 68 * instead of some known (safe) value, so we must seek back and fill 69 * in the gap with zeros. - DJ 70 * Note: this bug doesn't happen on NT4, even though the 71 * documentation for WriteFile() says that it *may* happen on any OS. 72 * 73 * We're making a bet, here, but we made it a long time ago and haven't 74 * yet seen any evidence that it was wrong. 75 * 76 * Windows 95/98 and On-Time give random garbage, and that breaks 77 * Berkeley DB. 78 * 79 * The value of __os_notzero is computed only once, and cached to 80 * avoid the overhead of repeated calls to GetVersion(). 81 */ 82 if (__os_notzero == -1) { 83 if (__os_is_winnt()) { 84 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 85 GetVersionEx(&osvi); 86 if (_tcscmp(osvi.szCSDVersion, _T("RTTarget-32")) == 0) 87 __os_notzero = 1; /* On-Time */ 88 else 89 __os_notzero = 0; /* Windows/NT */ 90 } else 91 __os_notzero = 1; /* Not Windows/NT */ 92 } 93 return (__os_notzero); 94#endif 95} 96 97/* 98 * __os_support_direct_io -- 99 * Check to see if we support direct I/O. 100 */ 101int 102__os_support_direct_io() 103{ 104 return (1); 105} 106 107/* 108 * __os_support_db_register -- 109 * Return 1 if the system supports DB_REGISTER. 110 */ 111int 112__os_support_db_register() 113{ 114#ifdef DB_WINCE 115 return (0); 116#else 117 return (__os_is_winnt()); 118#endif 119} 120 121/* 122 * __os_support_replication -- 123 * Return 1 if the system supports replication. 124 */ 125int 126__os_support_replication() 127{ 128#ifdef DB_WINCE 129 return (0); 130#else 131 return (__os_is_winnt()); 132#endif 133} 134