Skip to content

Commit 9d6c926

Browse files
authored
Handle ERROR_INVALID_PARAMETER error for GetVolumeInformationW win32 api (#164)
* fix * ignore error
1 parent 44ffe8b commit 9d6c926

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Deprecated
1717

18+
## [0.14.2]
19+
20+
### Fixed
21+
22+
- Fix again unsupported devices for filesystem. [#164](https://github.com/elastic/gosigar/pull/164)
23+
1824
## [0.14.1]
1925

2026
### Fixed

sigar_windows.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ func (self *FileSystemList) Get() error {
130130
if err != nil {
131131
return errors.Wrap(err, "GetAccessPaths failed")
132132
}
133-
134133
for _, drive := range drives {
135134
dt, err := windows.GetDriveType(drive)
136135
if err != nil {
@@ -140,14 +139,12 @@ func (self *FileSystemList) Get() error {
140139
if err != nil {
141140
return errors.Wrapf(err, "GetFilesystemType failed")
142141
}
143-
if fsType != "" {
144-
self.List = append(self.List, FileSystem{
145-
DirName: drive,
146-
DevName: drive,
147-
TypeName: dt.String(),
148-
SysTypeName: fsType,
149-
})
150-
}
142+
self.List = append(self.List, FileSystem{
143+
DirName: drive,
144+
DevName: drive,
145+
TypeName: dt.String(),
146+
SysTypeName: fsType,
147+
})
151148
}
152149
return nil
153150
}

sys/windows/syscall_windows.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -346,21 +346,17 @@ func GetDriveType(rootPathName string) (DriveType, error) {
346346
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumeinformationw
347347
func GetFilesystemType(rootPathName string) (string, error) {
348348
rootPathNamePtr, err := syscall.UTF16PtrFromString(rootPathName)
349+
var systemType = "unavailable"
349350
if err != nil {
350351
return "", errors.Wrapf(err, "UTF16PtrFromString failed for rootPathName=%v", rootPathName)
351352
}
352-
353353
buffer := make([]uint16, MAX_PATH+1)
354+
// _GetVolumeInformation will fail for external drives like CD-ROM or other type with error codes as ERROR_NOT_READY. ERROR_INVALID_FUNCTION, ERROR_INVALID_PARAMETER, etc., these types of errors will be ignored
354355
success, err := _GetVolumeInformation(rootPathNamePtr, nil, 0, nil, nil, nil, &buffer[0], MAX_PATH)
355-
// check if CD-ROM or other type that is not supported in GetVolumeInformation function
356-
if err == ERROR_NOT_READY || err == ERROR_INVALID_FUNCTION {
357-
return "", nil
358-
}
359-
if !success {
360-
return "", errors.Wrap(err, "GetVolumeInformationW failed")
356+
if success {
357+
systemType = strings.ToLower(syscall.UTF16ToString(buffer))
361358
}
362-
363-
return strings.ToLower(syscall.UTF16ToString(buffer)), nil
359+
return systemType, nil
364360
}
365361

366362
// EnumProcesses retrieves the process identifier for each process object in the

0 commit comments

Comments
 (0)