209f5a292bbd785761aeccfcced67b893fe05f3b
[symlink] / src / windows / c.rs
1 // These are copied from libstd/sys/windows/c.rs out of necessity.
2 // Note that I *can’t* use the winapi crate only, apparently, as it curiously lacks
3 // REPARSE_DATA_BUFFER and MAXIMUM_REPARSE_DATA_BUFFER_SIZE (at 0.2.8, anyway). So I just threw in
4 // the towel and decided not to use kernel32-sys and winapi at all.
5
6 #![allow(non_snake_case, non_camel_case_types)]
7
8 use std::os::raw::{c_int, c_uint, c_ushort, c_ulong, c_void};
9 use std::os::windows::raw::HANDLE;
10
11 pub type WCHAR = u16;
12 pub type DWORD = c_ulong;
13 pub type BOOL = c_int;
14 pub type LPVOID = *mut c_void;
15 pub type LPDWORD = *mut DWORD;
16 pub type LPCWSTR = *const WCHAR;
17 pub type LPOVERLAPPED = *mut OVERLAPPED;
18 pub type LPBY_HANDLE_FILE_INFORMATION = *mut BY_HANDLE_FILE_INFORMATION;
19 pub type LPSECURITY_ATTRIBUTES = *mut SECURITY_ATTRIBUTES;
20
21 pub const FILE_ATTRIBUTE_DIRECTORY: DWORD = 0x10;
22 pub const FILE_ATTRIBUTE_REPARSE_POINT: DWORD = 0x400;
23
24 pub const IO_REPARSE_TAG_SYMLINK: DWORD = 0xa000000c;
25 pub const IO_REPARSE_TAG_MOUNT_POINT: DWORD = 0xa0000003;
26
27 pub const FILE_SHARE_DELETE: DWORD = 0x4;
28 pub const FILE_SHARE_READ: DWORD = 0x1;
29 pub const FILE_SHARE_WRITE: DWORD = 0x2;
30
31 pub const OPEN_EXISTING: DWORD = 3;
32 pub const FILE_FLAG_BACKUP_SEMANTICS: DWORD = 0x02000000;
33
34 pub const INVALID_HANDLE_VALUE: HANDLE = !0 as HANDLE;
35
36 pub const MAXIMUM_REPARSE_DATA_BUFFER_SIZE: usize = 16 * 1024;
37 pub const FSCTL_GET_REPARSE_POINT: DWORD = 0x900a8;
38
39 #[repr(C)]
40 pub struct BY_HANDLE_FILE_INFORMATION {
41 pub dwFileAttributes: DWORD,
42 pub ftCreationTime: FILETIME,
43 pub ftLastAccessTime: FILETIME,
44 pub ftLastWriteTime: FILETIME,
45 pub dwVolumeSerialNumber: DWORD,
46 pub nFileSizeHigh: DWORD,
47 pub nFileSizeLow: DWORD,
48 pub nNumberOfLinks: DWORD,
49 pub nFileIndexHigh: DWORD,
50 pub nFileIndexLow: DWORD,
51 }
52
53 #[repr(C)]
54 pub struct REPARSE_DATA_BUFFER {
55 pub ReparseTag: c_uint,
56 pub ReparseDataLength: c_ushort,
57 pub Reserved: c_ushort,
58 pub rest: (),
59 }
60
61 #[repr(C)]
62 #[derive(Copy, Clone)]
63 pub struct FILETIME {
64 pub dwLowDateTime: DWORD,
65 pub dwHighDateTime: DWORD,
66 }
67
68 #[repr(C)]
69 pub struct OVERLAPPED {
70 pub Internal: *mut c_ulong,
71 pub InternalHigh: *mut c_ulong,
72 pub Offset: DWORD,
73 pub OffsetHigh: DWORD,
74 pub hEvent: HANDLE,
75 }
76
77 #[repr(C)]
78 pub struct SECURITY_ATTRIBUTES {
79 pub nLength: DWORD,
80 pub lpSecurityDescriptor: LPVOID,
81 pub bInheritHandle: BOOL,
82 }
83
84 extern "system" {
85 pub fn CreateFileW(lpFileName: LPCWSTR,
86 dwDesiredAccess: DWORD,
87 dwShareMode: DWORD,
88 lpSecurityAttributes: LPSECURITY_ATTRIBUTES,
89 dwCreationDisposition: DWORD,
90 dwFlagsAndAttributes: DWORD,
91 hTemplateFile: HANDLE)
92 -> HANDLE;
93 pub fn GetFileInformationByHandle(hFile: HANDLE,
94 lpFileInformation: LPBY_HANDLE_FILE_INFORMATION)
95 -> BOOL;
96 pub fn DeviceIoControl(hDevice: HANDLE,
97 dwIoControlCode: DWORD,
98 lpInBuffer: LPVOID,
99 nInBufferSize: DWORD,
100 lpOutBuffer: LPVOID,
101 nOutBufferSize: DWORD,
102 lpBytesReturned: LPDWORD,
103 lpOverlapped: LPOVERLAPPED) -> BOOL;
104 pub fn CloseHandle(hObject: HANDLE) -> BOOL;
105 }