@@ -5,22 +5,29 @@ package winio
55import (
66 "os"
77 "runtime"
8+ "syscall"
89 "unsafe"
10+ )
11+
12+ //sys getFileInformationByHandleEx(h syscall.Handle, class uint32, buffer *byte, size uint32) (err error) = GetFileInformationByHandleEx
13+ //sys setFileInformationByHandle(h syscall.Handle, class uint32, buffer *byte, size uint32) (err error) = SetFileInformationByHandle
914
10- "golang.org/x/sys/windows"
15+ const (
16+ fileBasicInfo = 0
17+ fileIDInfo = 0x12
1118)
1219
1320// FileBasicInfo contains file access time and file attributes information.
1421type FileBasicInfo struct {
15- CreationTime , LastAccessTime , LastWriteTime , ChangeTime windows .Filetime
22+ CreationTime , LastAccessTime , LastWriteTime , ChangeTime syscall .Filetime
1623 FileAttributes uint32
1724 pad uint32 // padding
1825}
1926
2027// GetFileBasicInfo retrieves times and attributes for a file.
2128func GetFileBasicInfo (f * os.File ) (* FileBasicInfo , error ) {
2229 bi := & FileBasicInfo {}
23- if err := windows . GetFileInformationByHandleEx ( windows .Handle (f .Fd ()), windows . FileBasicInfo , (* byte )(unsafe .Pointer (bi )), uint32 (unsafe .Sizeof (* bi ))); err != nil {
30+ if err := getFileInformationByHandleEx ( syscall .Handle (f .Fd ()), fileBasicInfo , (* byte )(unsafe .Pointer (bi )), uint32 (unsafe .Sizeof (* bi ))); err != nil {
2431 return nil , & os.PathError {Op : "GetFileInformationByHandleEx" , Path : f .Name (), Err : err }
2532 }
2633 runtime .KeepAlive (f )
@@ -29,32 +36,13 @@ func GetFileBasicInfo(f *os.File) (*FileBasicInfo, error) {
2936
3037// SetFileBasicInfo sets times and attributes for a file.
3138func SetFileBasicInfo (f * os.File , bi * FileBasicInfo ) error {
32- if err := windows . SetFileInformationByHandle ( windows .Handle (f .Fd ()), windows . FileBasicInfo , (* byte )(unsafe .Pointer (bi )), uint32 (unsafe .Sizeof (* bi ))); err != nil {
39+ if err := setFileInformationByHandle ( syscall .Handle (f .Fd ()), fileBasicInfo , (* byte )(unsafe .Pointer (bi )), uint32 (unsafe .Sizeof (* bi ))); err != nil {
3340 return & os.PathError {Op : "SetFileInformationByHandle" , Path : f .Name (), Err : err }
3441 }
3542 runtime .KeepAlive (f )
3643 return nil
3744}
3845
39- // FileStandardInfo contains extended information for the file.
40- // FILE_STANDARD_INFO in WinBase.h
41- // https://docs.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-file_standard_info
42- type FileStandardInfo struct {
43- AllocationSize , EndOfFile int64
44- NumberOfLinks uint32
45- DeletePending , Directory bool
46- }
47-
48- // GetFileStandardInfo retrieves ended information for the file.
49- func GetFileStandardInfo (f * os.File ) (* FileStandardInfo , error ) {
50- si := & FileStandardInfo {}
51- if err := windows .GetFileInformationByHandleEx (windows .Handle (f .Fd ()), windows .FileStandardInfo , (* byte )(unsafe .Pointer (si )), uint32 (unsafe .Sizeof (* si ))); err != nil {
52- return nil , & os.PathError {Op : "GetFileInformationByHandleEx" , Path : f .Name (), Err : err }
53- }
54- runtime .KeepAlive (f )
55- return si , nil
56- }
57-
5846// FileIDInfo contains the volume serial number and file ID for a file. This pair should be
5947// unique on a system.
6048type FileIDInfo struct {
@@ -65,7 +53,7 @@ type FileIDInfo struct {
6553// GetFileID retrieves the unique (volume, file ID) pair for a file.
6654func GetFileID (f * os.File ) (* FileIDInfo , error ) {
6755 fileID := & FileIDInfo {}
68- if err := windows . GetFileInformationByHandleEx ( windows .Handle (f .Fd ()), windows . FileIdInfo , (* byte )(unsafe .Pointer (fileID )), uint32 (unsafe .Sizeof (* fileID ))); err != nil {
56+ if err := getFileInformationByHandleEx ( syscall .Handle (f .Fd ()), fileIDInfo , (* byte )(unsafe .Pointer (fileID )), uint32 (unsafe .Sizeof (* fileID ))); err != nil {
6957 return nil , & os.PathError {Op : "GetFileInformationByHandleEx" , Path : f .Name (), Err : err }
7058 }
7159 runtime .KeepAlive (f )
0 commit comments