filesystem.go 3.4 KB

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