@@ -5,29 +5,22 @@ package winio
55import (
66 "os"
77 "runtime"
8- "syscall"
98 "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
149
15- const (
16- fileBasicInfo = 0
17- fileIDInfo = 0x12
10+ "golang.org/x/sys/windows"
1811)
1912
2013// FileBasicInfo contains file access time and file attributes information.
2114type FileBasicInfo struct {
22- CreationTime , LastAccessTime , LastWriteTime , ChangeTime syscall .Filetime
15+ CreationTime , LastAccessTime , LastWriteTime , ChangeTime windows .Filetime
2316 FileAttributes uint32
2417 pad uint32 // padding
2518}
2619
2720// GetFileBasicInfo retrieves times and attributes for a file.
2821func GetFileBasicInfo (f * os.File ) (* FileBasicInfo , error ) {
2922 bi := & FileBasicInfo {}
30- if err := getFileInformationByHandleEx ( syscall .Handle (f .Fd ()), fileBasicInfo , (* byte )(unsafe .Pointer (bi )), uint32 (unsafe .Sizeof (* bi ))); err != nil {
23+ if err := windows . GetFileInformationByHandleEx ( windows .Handle (f .Fd ()), windows . FileBasicInfo , (* byte )(unsafe .Pointer (bi )), uint32 (unsafe .Sizeof (* bi ))); err != nil {
3124 return nil , & os.PathError {Op : "GetFileInformationByHandleEx" , Path : f .Name (), Err : err }
3225 }
3326 runtime .KeepAlive (f )
@@ -36,13 +29,32 @@ func GetFileBasicInfo(f *os.File) (*FileBasicInfo, error) {
3629
3730// SetFileBasicInfo sets times and attributes for a file.
3831func SetFileBasicInfo (f * os.File , bi * FileBasicInfo ) error {
39- if err := setFileInformationByHandle ( syscall .Handle (f .Fd ()), fileBasicInfo , (* byte )(unsafe .Pointer (bi )), uint32 (unsafe .Sizeof (* bi ))); err != nil {
32+ if err := windows . SetFileInformationByHandle ( windows .Handle (f .Fd ()), windows . FileBasicInfo , (* byte )(unsafe .Pointer (bi )), uint32 (unsafe .Sizeof (* bi ))); err != nil {
4033 return & os.PathError {Op : "SetFileInformationByHandle" , Path : f .Name (), Err : err }
4134 }
4235 runtime .KeepAlive (f )
4336 return nil
4437}
4538
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+
4658// FileIDInfo contains the volume serial number and file ID for a file. This pair should be
4759// unique on a system.
4860type FileIDInfo struct {
@@ -53,7 +65,7 @@ type FileIDInfo struct {
5365// GetFileID retrieves the unique (volume, file ID) pair for a file.
5466func GetFileID (f * os.File ) (* FileIDInfo , error ) {
5567 fileID := & FileIDInfo {}
56- if err := getFileInformationByHandleEx ( syscall .Handle (f .Fd ()), fileIDInfo , (* byte )(unsafe .Pointer (fileID )), uint32 (unsafe .Sizeof (* fileID ))); err != nil {
68+ if err := windows . GetFileInformationByHandleEx ( windows .Handle (f .Fd ()), windows . FileIdInfo , (* byte )(unsafe .Pointer (fileID )), uint32 (unsafe .Sizeof (* fileID ))); err != nil {
5769 return nil , & os.PathError {Op : "GetFileInformationByHandleEx" , Path : f .Name (), Err : err }
5870 }
5971 runtime .KeepAlive (f )
0 commit comments