Skip to content

Commit e453577

Browse files
committed
os: make Stat work on FAT file system
It appears calling GetFileInformationByHandleEx with FILE_ATTRIBUTE_TAG_INFO fails on FAT file system. FAT does not support symlinks, so assume there are no symlnks when GetFileInformationByHandleEx returns ERROR_INVALID_PARAMETER. Fixes #29214 Change-Id: If2d9f3288bd99637681ab5fd4e4581c77b578a69 Reviewed-on: https://go-review.googlesource.com/c/154377 Run-TryBot: Alex Brainman <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent bc175e5 commit e453577

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/os/types_windows.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ func newFileStatFromGetFileInformationByHandle(path string, h syscall.Handle) (f
5151
var ti windows.FILE_ATTRIBUTE_TAG_INFO
5252
err = windows.GetFileInformationByHandleEx(h, windows.FileAttributeTagInfo, (*byte)(unsafe.Pointer(&ti)), uint32(unsafe.Sizeof(ti)))
5353
if err != nil {
54-
return nil, &PathError{"GetFileInformationByHandleEx", path, err}
54+
if errno, ok := err.(syscall.Errno); ok && errno == windows.ERROR_INVALID_PARAMETER {
55+
// It appears calling GetFileInformationByHandleEx with
56+
// FILE_ATTRIBUTE_TAG_INFO fails on FAT file system with
57+
// ERROR_INVALID_PARAMETER. Clear ti.ReparseTag in that
58+
// instance to indicate no symlinks are possible.
59+
ti.ReparseTag = 0
60+
} else {
61+
return nil, &PathError{"GetFileInformationByHandleEx", path, err}
62+
}
5563
}
5664

5765
return &fileStat{

0 commit comments

Comments
 (0)