1 //go:build windows 2 3 package winapi 4 5 //sys CopyFileW(existingFileName *uint16, newFileName *uint16, failIfExists int32) (err error) = kernel32.CopyFileW 6 //sys NtCreateFile(handle *uintptr, accessMask uint32, oa *ObjectAttributes, iosb *IOStatusBlock, allocationSize *uint64, fileAttributes uint32, shareAccess uint32, createDisposition uint32, createOptions uint32, eaBuffer *byte, eaLength uint32) (status uint32) = ntdll.NtCreateFile 7 //sys NtSetInformationFile(handle uintptr, iosb *IOStatusBlock, information uintptr, length uint32, class uint32) (status uint32) = ntdll.NtSetInformationFile 8 9 //sys NtOpenDirectoryObject(handle *uintptr, accessMask uint32, oa *ObjectAttributes) (status uint32) = ntdll.NtOpenDirectoryObject 10 //sys NtQueryDirectoryObject(handle uintptr, buffer *byte, length uint32, singleEntry bool, restartScan bool, context *uint32, returnLength *uint32)(status uint32) = ntdll.NtQueryDirectoryObject 11 12 const ( 13 FileLinkInformationClass = 11 14 FileDispositionInformationExClass = 64 15 16 FILE_READ_ATTRIBUTES = 0x0080 17 FILE_WRITE_ATTRIBUTES = 0x0100 18 DELETE = 0x10000 19 20 FILE_OPEN = 1 21 FILE_CREATE = 2 22 23 FILE_LIST_DIRECTORY = 0x00000001 24 FILE_DIRECTORY_FILE = 0x00000001 25 FILE_SYNCHRONOUS_IO_NONALERT = 0x00000020 26 FILE_OPEN_FOR_BACKUP_INTENT = 0x00004000 27 FILE_OPEN_REPARSE_POINT = 0x00200000 28 29 FILE_DISPOSITION_DELETE = 0x00000001 30 31 OBJ_DONT_REPARSE = 0x1000 32 33 STATUS_MORE_ENTRIES = 0x105 34 STATUS_NO_MORE_ENTRIES = 0x8000001a 35 ) 36 37 // Select entries from FILE_INFO_BY_HANDLE_CLASS. 38 // 39 // C declaration: 40 // 41 // typedef enum _FILE_INFO_BY_HANDLE_CLASS { 42 // FileBasicInfo, 43 // FileStandardInfo, 44 // FileNameInfo, 45 // FileRenameInfo, 46 // FileDispositionInfo, 47 // FileAllocationInfo, 48 // FileEndOfFileInfo, 49 // FileStreamInfo, 50 // FileCompressionInfo, 51 // FileAttributeTagInfo, 52 // FileIdBothDirectoryInfo, 53 // FileIdBothDirectoryRestartInfo, 54 // FileIoPriorityHintInfo, 55 // FileRemoteProtocolInfo, 56 // FileFullDirectoryInfo, 57 // FileFullDirectoryRestartInfo, 58 // FileStorageInfo, 59 // FileAlignmentInfo, 60 // FileIdInfo, 61 // FileIdExtdDirectoryInfo, 62 // FileIdExtdDirectoryRestartInfo, 63 // FileDispositionInfoEx, 64 // FileRenameInfoEx, 65 // FileCaseSensitiveInfo, 66 // FileNormalizedNameInfo, 67 // MaximumFileInfoByHandleClass 68 // } FILE_INFO_BY_HANDLE_CLASS, *PFILE_INFO_BY_HANDLE_CLASS; 69 // 70 // Documentation: https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ne-minwinbase-file_info_by_handle_class 71 const ( 72 FileIdInfo = 18 73 ) 74 75 type FileDispositionInformationEx struct { 76 Flags uintptr 77 } 78 79 type IOStatusBlock struct { 80 Status, Information uintptr 81 } 82 83 type ObjectAttributes struct { 84 Length uintptr 85 RootDirectory uintptr 86 ObjectName *UnicodeString 87 Attributes uintptr 88 SecurityDescriptor uintptr 89 SecurityQoS uintptr 90 } 91 92 type ObjectDirectoryInformation struct { 93 Name UnicodeString 94 TypeName UnicodeString 95 } 96 97 type FileLinkInformation struct { 98 ReplaceIfExists bool 99 RootDirectory uintptr 100 FileNameLength uint32 101 FileName [1]uint16 102 } 103 104 // C declaration: 105 // 106 // typedef struct _FILE_ID_INFO { 107 // ULONGLONG VolumeSerialNumber; 108 // FILE_ID_128 FileId; 109 // } FILE_ID_INFO, *PFILE_ID_INFO; 110 // 111 // Documentation: https://docs.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-file_id_info 112 type FILE_ID_INFO struct { 113 VolumeSerialNumber uint64 114 FileID [16]byte 115 } 116