返回 DeepSeek-Reasonix
open_regular_windows.go
根目录 / internal / repair / open_regular_windows.go
1 //go:build windows
2
3 package repair
4
5 import (
6 "os"
7
8 "golang.org/x/sys/windows"
9 )
10
11 func openRepairRegularRead(path string) (*os.File, error) {
12 path16, err := windows.UTF16PtrFromString(path)
13 if err != nil {
14 return nil, err
15 }
16 handle, err := windows.CreateFile(
17 path16,
18 windows.GENERIC_READ,
19 windows.FILE_SHARE_READ|windows.FILE_SHARE_WRITE|windows.FILE_SHARE_DELETE,
20 nil,
21 windows.OPEN_EXISTING,
22 windows.FILE_ATTRIBUTE_NORMAL|windows.FILE_FLAG_OPEN_REPARSE_POINT,
23 0,
24 )
25 if err != nil {
26 return nil, err
27 }
28 file := os.NewFile(uintptr(handle), path)
29 if file == nil {
30 _ = windows.CloseHandle(handle)
31 return nil, os.ErrInvalid
32 }
33 return file, nil
34 }
35
35 lines GO