ReactOS  0.4.11-dev-765-g5e024bf
tunneltest.c File Reference
#include <stdio.h>
#include <windef.h>
#include <winternl.h>
#include <winbase.h>
Include dependency graph for tunneltest.c:

Go to the source code of this file.

Macros

#define RTL_CONSTANT_STRING(s)   { sizeof(s)-sizeof((s)[0]), sizeof(s), s }
 

Functions

int wmain (int argc, WCHAR *argv[])
 

Variables

const UNICODE_STRING FatName = RTL_CONSTANT_STRING(L"FAT")
 
const UNICODE_STRING Fat32Name = RTL_CONSTANT_STRING(L"FAT32")
 
const UNICODE_STRING NtfsName = RTL_CONSTANT_STRING(L"NTFS")
 

Macro Definition Documentation

#define RTL_CONSTANT_STRING (   s)    { sizeof(s)-sizeof((s)[0]), sizeof(s), s }

Definition at line 14 of file tunneltest.c.

Referenced by _Function_class_(), _IRQL_requires_max_(), _tmain(), acpi_create_volatile_registry_tables(), AcsHlpSendCommand(), AfdCreateSocket(), AllocConsole(), ApphelppInitDebugLevel(), BaseComputeProcessDllPath(), BaseInitializeStaticServerData(), BasepGetComputerNameFromNtPath(), BasepIsProcessAllowed(), BasepReplaceProcessThreadTokens(), BuildUserInfoBuffer(), CmpCreateControlSet(), CmpGetHiveName(), CmpInitializeSystemHive(), CmpIsLoadType(), co_IntInitializeDesktopGraphics(), CompareProductName(), CreateKeyTest(), CreateWindowStationW(), DceCreateDisplayDC(), DeleteKeyTest(), DeleteValueTest(), DriverEntry(), EnumerateDevices(), EnumerateKeyTest(), EnumerateValueTest(), EventThread(), ExpGetCurrentUserUILanguage(), ExpInitializeCallbacks(), ExpLoadInitialProcess(), ExpSetCurrentUserUILanguage(), FindBitmapResource(), FindProductName(), FirstSoundSentry(), FsRtlGetTunnelParameterValue(), FsRtlInitializeTunnels(), GetDllList(), GetFilterAltitude(), GetSourcePaths(), HalpGetNMICrashFlag(), i8042StoreSMBiosTables(), InitApphelp(), InitDevice(), InitializeFmIfsOnce(), InitLogPort(), InstallDevice(), InstallDriver(), InstallFatBootcodeToFloppy(), IntCreateNewRegistryPath(), IntGdiAddFontResource(), IntLoadFontSubstList(), IntLoadSystemFonts(), IntResolveDesktop(), IntSetupDeviceSettingsKey(), IoGetDeviceInterfaces(), IoOpenDeviceInterfaceRegistryKey(), IopActionInterrogateDeviceStack(), IopConnectLogPort(), IopCreateDeviceKeyPath(), IopCreateDeviceNode(), IopDisplayLoadingMessage(), IopEnumerateDetectedDevices(), IopGetParentIdPrefix(), IopInitializePlugPlayServices(), IopInstallCriticalDevice(), IopIsFirmwareMapperDisabled(), IopNormalizeImagePath(), IopOpenInterfaceKey(), IopStartRamdisk(), IopStoreSystemPartitionInformation(), IopUpdateControlKeyWithResources(), IopUpdateRootKey(), IoRegisterDeviceInterface(), IoSetDeviceInterfaceState(), IsAcpiComputer(), IsShimInfrastructureDisabled(), KMix_AddDevice(), KsCacheMedium(), KsCreateBusEnumObject(), KsecOpenDevice(), KsFilterFactoryUpdateCacheData(), KsMapModuleName(), KspReadMediaCategory(), LdrpInitializeProcess(), LsapLookupFullyQualifiedWellKnownNames(), LsapLookupIsolatedNames(), main(), MiBuildImportsForBootDrivers(), MiInitializeMemoryEvents(), MiResolveImageReferences(), MmCallDllInitialize(), MmCreatePhysicalMemorySection(), MmGetSystemRoutineAddress(), NdisOpenConfiguration(), Notify(), NpWaitPipe(), NtGdiOpenDCW(), OpenClassesRootKey(), OpenCurrentConfigKey(), OpenKeyboard(), OpenLocalMachineKey(), OpenUsersKey(), OpenWindowStationW(), PiInitCacheGroupInformation(), PipCallDriverAddDevice(), PipGetDriverTagPriority(), PnpDeviceObjectToDeviceInstance(), PnpRootCreateDevice(), PnpRootDriverEntry(), PopFlushVolumes(), ReadIpConfiguration(), RegOpenKey(), RtlCreateBootStatusDataFile(), RtlCreateUserProcess(), RtlLockBootStatusData(), ScreenAddDevice(), SdbpPropagateEnvLayers(), SearchForLegacyDrivers(), SeiCreateShimModuleInfo(), SeiGetShimData(), SeiInit(), SeiInitDebugSupport(), SeiSetLayerEnvVar(), SetDefaultPagefile(), SetMountedDeviceValue(), SetRosSpecificInfo(), SetValueTest1(), SetValueTest2(), SimpleErrorChecks(), SSI_DEF(), START_TEST(), Substitute(), SymlinkCreateTests(), SysAudio_AddDevice(), SysAudio_Pnp(), SysAudioOpenKMixer(), TCPSendIoctl(), test1(), test9(), Test_KeyFullInformation(), Test_KeyNameInformation(), TestAllInformation(), TestCreateOpen_(), TestDriverObject(), TestFindCharInUnicodeString(), TestHardError(), TestKM(), TestMessageHandler(), TestObRootSecurity(), TestPhysicalMemorySection(), TestPrivateFunctions(), TestProviderInfo(), TestRelativeNames(), TestRtlQueryRegistryValues(), TestTcpConnect(), UnhandledExceptionFilter(), USBH_WriteFailReasonID(), UserpLogHardError(), VdmpInitialize(), vfatGetFCBForFile(), vfatMakeRootFCB(), VfatMount(), vfatOpenRootFCB(), VideoPortIsNoVesa(), WdmAudOpenSysAudioDevices(), WmiInitialize(), WmipInitializeGuidObjectType(), WmipOpenGuidObjectByName(), and WSHOpenSocket2().

Function Documentation

int wmain ( int  argc,
WCHAR argv[] 
)

Definition at line 20 of file tunneltest.c.

21 {
22  WCHAR TempPath[MAX_PATH + 1];
23  WCHAR CopyPath[MAX_PATH + 1];
24  WCHAR RootPath[] = {'A', ':', '\\', '\0'};
25  WCHAR FileSystemName[sizeof("FAT32")]; /* Max we should hold - fail otherwise, we don't care */
26  UNICODE_STRING FSName;
27  WCHAR File1[] = {'\\', 'f', 'i', 'l', 'e', '1', '\0'};
28  WCHAR File2[] = {'\\', 'f', 'i', 'l', 'e', '2', '\0'};
29  ULONG FilePos;
30  HANDLE hFile;
31  FILETIME FileTime, File1Time;
32 
33  /* Get temp path in which will work */
34  if (GetTempPathW(sizeof(TempPath) / sizeof(TempPath[0]), TempPath) == 0)
35  {
36  fprintf(stderr, "Failed to get temp path\n");
37  return GetLastError();
38  }
39 
40  /* Assume it's X:\ something */
41  RootPath[0] = TempPath[0];
42 
43  /* Get information about the volume */
44  if (GetVolumeInformationW(RootPath, NULL, 0, NULL, NULL, NULL, FileSystemName, sizeof(FileSystemName) / sizeof(FileSystemName[0])) == 0)
45  {
46  fprintf(stderr, "Failed to get volume info\n");
47  return GetLastError();
48  }
49 
50  /* Convert to string */
51  RtlInitUnicodeString(&FSName, FileSystemName);
52 
53  /* Bail out if that's not FAT or NTFS */
54  if (RtlCompareUnicodeString(&FSName, &FatName, FALSE) != 0 &&
55  RtlCompareUnicodeString(&FSName, &Fat32Name, FALSE) != 0 &&
56  RtlCompareUnicodeString(&FSName, &NtfsName, FALSE) != 0)
57  {
58  fprintf(stderr, "!(FAT, FAT32, NTFS): \'%S\'\n", FSName.Buffer);
59  return 0;
60  }
61 
62  /* Ensure we can store complete path - no overrun */
63  FilePos = wcslen(TempPath);
64  if (FilePos > MAX_PATH - sizeof(File2) / sizeof(WCHAR))
65  {
66  fprintf(stderr, "Files won't fit\n");
67  return 0;
68  }
69 
70  /* Create first file */
71  wcscat(TempPath, File1);
72  hFile = CreateFileW(TempPath, 0, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
73  if (hFile == INVALID_HANDLE_VALUE)
74  {
75  fprintf(stderr, "Failed to create file1\n");
76  return GetLastError();
77  }
78 
79  /* Get its creation timestamp. It will be our reference */
80  /* Get it in FileTime because file1 will renamed to file */
81  if (GetFileTime(hFile, &FileTime, NULL, NULL) == FALSE)
82  {
83  fprintf(stderr, "Failed to read creation time\n");
84  CloseHandle(hFile);
85  return GetLastError();
86  }
87 
88  CloseHandle(hFile);
89 
90  /* Wait a least 10ms (resolution of FAT) */
91  /* XXX: Increased to 1s for ReactOS... */
92  Sleep(1000);
93 
94  /* Create second file */
95  /* Remove old file from buffer */
96  TempPath[FilePos - 1] = 0;
97  wcscat(TempPath, File2);
98  hFile = CreateFileW(TempPath, 0, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
99  if (hFile == INVALID_HANDLE_VALUE)
100  {
101  fprintf(stderr, "Failed to create file2\n");
102  return GetLastError();
103  }
104  CloseHandle(hFile);
105 
106  /* Rename file1 to file */
107  TempPath[FilePos] = 0;
108  wcscat(TempPath, File1);
109  wcscpy(CopyPath, TempPath);
110  /* Remove number for dest */
111  CopyPath[wcslen(TempPath) - 1] = 0;
112  if (MoveFileW(TempPath, CopyPath) == 0)
113  {
114  fprintf(stderr, "Failed to rename file1\n");
115  return GetLastError();
116  }
117 
118  /* Rename file2 to file1 */
119  wcscpy(CopyPath, TempPath);
120  /* Change 1 to 2 */
121  CopyPath[wcslen(TempPath) - 1] = L'2';
122  if (MoveFileW(CopyPath, TempPath) == 0)
123  {
124  fprintf(stderr, "Failed to rename file2\n");
125  return GetLastError();
126  }
127 
128  /* Open file1 and get its creation time */
130  if (hFile == INVALID_HANDLE_VALUE)
131  {
132  fprintf(stderr, "Failed to open file1\n");
133  return GetLastError();
134  }
135  if (GetFileTime(hFile, &File1Time, NULL, NULL) == FALSE)
136  {
137  fprintf(stderr, "Failed to read creation time\n");
138  CloseHandle(hFile);
139  return GetLastError();
140  }
141  CloseHandle(hFile);
142 
143  /* Delete files */
144  CopyPath[wcslen(TempPath) - 1] = 0;
145  DeleteFileW(TempPath);
146  DeleteFileW(CopyPath);
147 
148  /* Compare both, they have to be strictly identical */
149  if (RtlCompareMemory(&FileTime, &File1Time, sizeof(FILETIME)) == sizeof(FILETIME))
150  {
151  fprintf(stdout, "Tunnel cache in action\n");
152  return 0;
153  }
154 
155  fprintf(stdout, "Tunnel cache NOT in action\n");
156  return 0;
157 }
const UNICODE_STRING FatName
Definition: tunneltest.c:16
const UNICODE_STRING Fat32Name
Definition: tunneltest.c:17
#define CloseHandle
Definition: compat.h:398
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
FILE * stdout
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2079
#define FALSE
Definition: types.h:117
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
BOOL WINAPI MoveFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName)
Definition: move.c:1044
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
#define MAX_PATH
Definition: compat.h:26
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1087
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
#define GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
const UNICODE_STRING NtfsName
Definition: tunneltest.c:18
BOOL WINAPI GetVolumeInformationW(IN LPCWSTR lpRootPathName, IN LPWSTR lpVolumeNameBuffer, IN DWORD nVolumeNameSize, OUT LPDWORD lpVolumeSerialNumber OPTIONAL, OUT LPDWORD lpMaximumComponentLength OPTIONAL, OUT LPDWORD lpFileSystemFlags OPTIONAL, OUT LPWSTR lpFileSystemNameBuffer OPTIONAL, IN DWORD nFileSystemNameSize)
Definition: volume.c:226
#define CREATE_ALWAYS
Definition: disk.h:72
DWORD *typedef HANDLE
Definition: winlogon.h:61
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define CreateFileW
Definition: compat.h:400
unsigned int ULONG
Definition: retypes.h:1
FILE * stderr
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
BOOL WINAPI GetFileTime(IN HANDLE hFile, OUT LPFILETIME lpCreationTime OPTIONAL, OUT LPFILETIME lpLastAccessTime OPTIONAL, OUT LPFILETIME lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:1046
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

Variable Documentation

Definition at line 17 of file tunneltest.c.

Definition at line 16 of file tunneltest.c.

Definition at line 18 of file tunneltest.c.