forked from winfsp/winfsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsl-test.c
188 lines (171 loc) · 6.3 KB
/
wsl-test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/**
* @file wsl-test.c
*
* @copyright 2015-2020 Bill Zissimopoulos
*/
/*
* This file is part of WinFsp.
*
* You can redistribute it and/or modify it under the terms of the GNU
* General Public License version 3 as published by the Free Software
* Foundation.
*
* Licensees holding a valid commercial license may use this software
* in accordance with the commercial license agreement provided in
* conjunction with the software. The terms and conditions of any such
* commercial license agreement shall govern, supersede, and render
* ineffective any application of the GPLv3 license to this software,
* notwithstanding of any reference thereto in the software or
* associated repository.
*/
#include <winfsp/winfsp.h>
#include <tlib/testsuite.h>
#include <strsafe.h>
#include "memfs.h"
#include "winfsp-tests.h"
typedef struct _FILE_STAT_INFORMATION
{
LARGE_INTEGER FileId;
LARGE_INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
LARGE_INTEGER LastWriteTime;
LARGE_INTEGER ChangeTime;
LARGE_INTEGER AllocationSize;
LARGE_INTEGER EndOfFile;
ULONG FileAttributes;
ULONG ReparseTag;
ULONG NumberOfLinks;
ACCESS_MASK EffectiveAccess;
} FILE_STAT_INFORMATION, *PFILE_STAT_INFORMATION;
typedef struct _FILE_STAT_LX_INFORMATION
{
LARGE_INTEGER FileId;
LARGE_INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
LARGE_INTEGER LastWriteTime;
LARGE_INTEGER ChangeTime;
LARGE_INTEGER AllocationSize;
LARGE_INTEGER EndOfFile;
ULONG FileAttributes;
ULONG ReparseTag;
ULONG NumberOfLinks;
ACCESS_MASK EffectiveAccess;
ULONG LxFlags;
ULONG LxUid;
ULONG LxGid;
ULONG LxMode;
ULONG LxDeviceIdMajor;
ULONG LxDeviceIdMinor;
} FILE_STAT_LX_INFORMATION, *PFILE_STAT_LX_INFORMATION;
NTSTATUS NTAPI NtQueryInformationFile(
HANDLE FileHandle,
PIO_STATUS_BLOCK IoStatusBlock,
PVOID FileInformation,
ULONG Length,
FILE_INFORMATION_CLASS FileInformationClass);
static void wsl_stat_dotest(ULONG Flags, PWSTR Prefix, ULONG FileInfoTimeout)
{
void *memfs = memfs_start_ex(Flags, FileInfoTimeout);
HANDLE Handle;
WCHAR FilePath[MAX_PATH];
FILE_STAT_INFORMATION StatInfo;
FILE_STAT_LX_INFORMATION StatLxInfo;
FILETIME FileTime;
LONGLONG TimeLo, TimeHi;
IO_STATUS_BLOCK IoStatus;
NTSTATUS Result;
GetSystemTimeAsFileTime(&FileTime);
TimeLo = ((PLARGE_INTEGER)&FileTime)->QuadPart;
TimeHi = TimeLo + 10000 * 10000/* 10 seconds */;
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\file0",
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
Handle = CreateFileW(FilePath,
GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
CREATE_NEW, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, 0);
ASSERT(INVALID_HANDLE_VALUE != Handle);
for (int repeat = 0; 2 > repeat; repeat++)
{
/* repeat this test to ensure that any caches are tested */
Result = NtQueryInformationFile(Handle, &IoStatus, &StatInfo, sizeof StatInfo,
68/*FileStatInformation*/);
if (STATUS_SUCCESS == Result)
{
ASSERT(STATUS_SUCCESS == Result);
if (-1 != Flags)
ASSERT(
TimeLo <= StatInfo.CreationTime.QuadPart &&
TimeHi > StatInfo.CreationTime.QuadPart);
ASSERT(
TimeLo <= StatInfo.LastAccessTime.QuadPart &&
TimeHi > StatInfo.LastAccessTime.QuadPart);
ASSERT(
TimeLo <= StatInfo.LastWriteTime.QuadPart &&
TimeHi > StatInfo.LastWriteTime.QuadPart);
ASSERT(
TimeLo <= StatInfo.ChangeTime.QuadPart &&
TimeHi > StatInfo.ChangeTime.QuadPart);
ASSERT(0 == StatInfo.AllocationSize.QuadPart);
ASSERT(0 == StatInfo.EndOfFile.QuadPart);
//ASSERT(FILE_ATTRIBUTE_ARCHIVE == StatInfo.FileAttributes);
ASSERT(0 == StatInfo.ReparseTag);
ASSERT(1 == StatInfo.NumberOfLinks);
//tlib_printf("%lx %lx", FILE_GENERIC_READ | FILE_GENERIC_WRITE, StatInfo.EffectiveAccess);
//ASSERT((FILE_GENERIC_READ | FILE_GENERIC_WRITE) == StatInfo.EffectiveAccess);
Result = NtQueryInformationFile(Handle, &IoStatus, &StatLxInfo, sizeof StatLxInfo,
70/*FileStatLxInformation*/);
ASSERT(STATUS_SUCCESS == Result);
if (-1 != Flags)
ASSERT(
TimeLo <= StatLxInfo.CreationTime.QuadPart &&
TimeHi > StatLxInfo.CreationTime.QuadPart);
ASSERT(
TimeLo <= StatLxInfo.LastAccessTime.QuadPart &&
TimeHi > StatLxInfo.LastAccessTime.QuadPart);
ASSERT(
TimeLo <= StatLxInfo.LastWriteTime.QuadPart &&
TimeHi > StatLxInfo.LastWriteTime.QuadPart);
ASSERT(
TimeLo <= StatLxInfo.ChangeTime.QuadPart &&
TimeHi > StatLxInfo.ChangeTime.QuadPart);
ASSERT(0 == StatLxInfo.AllocationSize.QuadPart);
ASSERT(0 == StatLxInfo.EndOfFile.QuadPart);
//ASSERT(FILE_ATTRIBUTE_ARCHIVE == StatLxInfo.FileAttributes);
ASSERT(0 == StatLxInfo.ReparseTag);
ASSERT(1 == StatLxInfo.NumberOfLinks);
//tlib_printf("%lx %lx", FILE_GENERIC_READ | FILE_GENERIC_WRITE, StatLxInfo.EffectiveAccess);
//ASSERT((FILE_GENERIC_READ | FILE_GENERIC_WRITE) == StatLxInfo.EffectiveAccess);
}
else
{
ASSERT(
STATUS_INVALID_INFO_CLASS == Result ||
STATUS_NOT_IMPLEMENTED == Result/* value returned under WOW64 */);
FspDebugLog(__FUNCTION__ ": only works in Win10 with WSLinux\n");
}
}
CloseHandle(Handle);
memfs_stop(memfs);
}
static void wsl_stat_test(void)
{
if (NtfsTests)
{
WCHAR DirBuf[MAX_PATH];
GetTestDirectory(DirBuf);
wsl_stat_dotest(-1, DirBuf, 0);
}
if (WinFspDiskTests)
{
wsl_stat_dotest(MemfsDisk, 0, 0);
wsl_stat_dotest(MemfsDisk, 0, 1000);
}
if (WinFspNetTests)
{
wsl_stat_dotest(MemfsNet, L"\\\\memfs\\share", 0);
wsl_stat_dotest(MemfsNet, L"\\\\memfs\\share", 1000);
}
}
void wsl_tests(void)
{
TEST_OPT(wsl_stat_test);
}