00001 /*- 00002 * See the file LICENSE for redistribution information. 00003 * 00004 * Copyright (c) 1999-2005 00005 * Sleepycat Software. All rights reserved. 00006 * 00007 * $Id: os_config.c,v 12.2 2005/06/16 20:23:28 bostic Exp $ 00008 */ 00009 00010 #include "db_config.h" 00011 00012 #include "db_int.h" 00013 00014 /* 00015 * __os_is_winnt -- 00016 * Return 1 if Windows/NT, otherwise 0. 00017 * 00018 * PUBLIC: int __os_is_winnt __P((void)); 00019 */ 00020 int 00021 __os_is_winnt() 00022 { 00023 static int __os_type = -1; 00024 00025 /* 00026 * The value of __os_type is computed only once, and cached to 00027 * avoid the overhead of repeated calls to GetVersion(). 00028 */ 00029 if (__os_type == -1) { 00030 if ((GetVersion() & 0x80000000) == 0) 00031 __os_type = 1; 00032 else 00033 __os_type = 0; 00034 } 00035 return (__os_type); 00036 } 00037 00038 /* 00039 * __os_fs_notzero -- 00040 * Return 1 if allocated filesystem blocks are not zeroed. 00041 */ 00042 int 00043 __os_fs_notzero() 00044 { 00045 static int __os_notzero = -1; 00046 OSVERSIONINFO osvi; 00047 00048 /* 00049 * Windows/NT zero-fills pages that were never explicitly written to 00050 * the file. Note however that this is *NOT* documented. In fact, the 00051 * Win32 documentation makes it clear that there are no guarantees that 00052 * uninitialized bytes will be zeroed: 00053 * 00054 * If the file is extended, the contents of the file between the old 00055 * EOF position and the new position are not defined. 00056 * 00057 * Experiments confirm that NT/2K/XP all zero fill for both NTFS and 00058 * FAT32. Cygwin also relies on this behavior. This is the relevant 00059 * comment from Cygwin: 00060 * 00061 * Oops, this is the bug case - Win95 uses whatever is on the disk 00062 * instead of some known (safe) value, so we must seek back and fill 00063 * in the gap with zeros. - DJ 00064 * Note: this bug doesn't happen on NT4, even though the 00065 * documentation for WriteFile() says that it *may* happen on any OS. 00066 * 00067 * We're making a bet, here, but we made it a long time ago and haven't 00068 * yet seen any evidence that it was wrong. 00069 * 00070 * Windows 95/98 and On-Time give random garbage, and that breaks 00071 * Berkeley DB. 00072 * 00073 * The value of __os_notzero is computed only once, and cached to 00074 * avoid the overhead of repeated calls to GetVersion(). 00075 */ 00076 if (__os_notzero == -1) { 00077 if (__os_is_winnt()) { 00078 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 00079 GetVersionEx(&osvi); 00080 if (_tcscmp(osvi.szCSDVersion, _T("RTTarget-32")) == 0) 00081 __os_notzero = 1; /* On-Time */ 00082 else 00083 __os_notzero = 0; /* Windows/NT */ 00084 } else 00085 __os_notzero = 1; /* Not Windows/NT */ 00086 } 00087 return (__os_notzero); 00088 } 00089 00090 /* 00091 * __os_support_db_register -- 00092 * Return 1 if the system supports DB_REGISTER. 00093 */ 00094 int 00095 __os_support_db_register() 00096 { 00097 return (__os_is_winnt()); 00098 } 00099 00100 /* 00101 * __os_support_replication -- 00102 * Return 1 if the system supports replication. 00103 */ 00104 int 00105 __os_support_replication() 00106 { 00107 return (__os_is_winnt()); 00108 }