ReactOS 0.4.16-dev-334-g4d9f67c
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

◆ RTL_CONSTANT_STRING

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

Definition at line 14 of file tunneltest.c.

Function Documentation

◆ wmain()

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;
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);
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");
85 return GetLastError();
86 }
87
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);
100 {
101 fprintf(stderr, "Failed to create file2\n");
102 return GetLastError();
103 }
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 */
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");
139 return GetLastError();
140 }
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}
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI GetFileTime(IN HANDLE hFile, OUT LPFILETIME lpCreationTime OPTIONAL, OUT LPFILETIME lpLastAccessTime OPTIONAL, OUT LPFILETIME lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:896
BOOL WINAPI MoveFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName)
Definition: move.c:1104
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
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
#define stdout
Definition: stdio.h:99
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define CREATE_ALWAYS
Definition: disk.h:72
_In_ HANDLE hFile
Definition: mswsock.h:90
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
const UNICODE_STRING Fat32Name
Definition: tunneltest.c:17
const UNICODE_STRING NtfsName
Definition: tunneltest.c:18
const UNICODE_STRING FatName
Definition: tunneltest.c:16
uint32_t ULONG
Definition: typedefs.h:59
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
__wchar_t WCHAR
Definition: xmlstorage.h:180

Variable Documentation

◆ Fat32Name

const UNICODE_STRING Fat32Name = RTL_CONSTANT_STRING(L"FAT32")

Definition at line 17 of file tunneltest.c.

Referenced by wmain().

◆ FatName

Definition at line 16 of file tunneltest.c.

Referenced by wmain().

◆ NtfsName

Definition at line 18 of file tunneltest.c.

Referenced by wmain().