forked from winfsp/winfsp
-
Notifications
You must be signed in to change notification settings - Fork 5
/
devctl-test.c
78 lines (65 loc) · 2.08 KB
/
devctl-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
/**
* @file devctl-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"
static void devctl_dotest(ULONG Flags, PWSTR Prefix, PWSTR Drive)
{
void *memfs = memfs_start(Flags);
WCHAR FilePath[1024];
HANDLE Handle;
BOOL Success;
CHAR Buffer[26];
DWORD BytesTransferred;
StringCbPrintfW(FilePath, sizeof FilePath, L"%s%s\\",
Prefix ? L"" : L"\\\\?\\GLOBALROOT", Prefix ? Prefix : memfs_volumename(memfs));
Handle = CreateFileW(FilePath,
GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS, 0);
ASSERT(INVALID_HANDLE_VALUE != Handle);
Success = DeviceIoControl(Handle,
CTL_CODE(0x8000 + 'M', 'R', METHOD_BUFFERED, FILE_ANY_ACCESS),
"ABCDEFghijklmNOPQRStuvwxyz", 26,
Buffer, sizeof Buffer,
&BytesTransferred,
0);
ASSERT(Success);
ASSERT(26 == BytesTransferred);
ASSERT(0 == memcmp("NOPQRStuvwxyzABCDEFghijklm", Buffer, BytesTransferred));
Success = CloseHandle(Handle);
ASSERT(Success);
memfs_stop(memfs);
}
static void devctl_test(void)
{
if (WinFspDiskTests)
devctl_dotest(MemfsDisk, 0, 0);
if (WinFspNetTests)
devctl_dotest(MemfsNet, L"\\\\memfs\\share", L"\\\\memfs\\share");
}
void devctl_tests(void)
{
if (OptExternal)
return;
TEST(devctl_test);
}