Skip to content

Commit

Permalink
Handle ERROR_INVALID_PARAMETER error for GetVolumeInformationW win32 …
Browse files Browse the repository at this point in the history
…api (#164)

* fix

* ignore error
  • Loading branch information
narph authored Nov 9, 2021
1 parent 44ffe8b commit 9d6c926
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Deprecated

## [0.14.2]

### Fixed

- Fix again unsupported devices for filesystem. [#164](https://github.com/elastic/gosigar/pull/164)

## [0.14.1]

### Fixed
Expand Down
15 changes: 6 additions & 9 deletions sigar_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ func (self *FileSystemList) Get() error {
if err != nil {
return errors.Wrap(err, "GetAccessPaths failed")
}

for _, drive := range drives {
dt, err := windows.GetDriveType(drive)
if err != nil {
Expand All @@ -140,14 +139,12 @@ func (self *FileSystemList) Get() error {
if err != nil {
return errors.Wrapf(err, "GetFilesystemType failed")
}
if fsType != "" {
self.List = append(self.List, FileSystem{
DirName: drive,
DevName: drive,
TypeName: dt.String(),
SysTypeName: fsType,
})
}
self.List = append(self.List, FileSystem{
DirName: drive,
DevName: drive,
TypeName: dt.String(),
SysTypeName: fsType,
})
}
return nil
}
Expand Down
14 changes: 5 additions & 9 deletions sys/windows/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,21 +346,17 @@ func GetDriveType(rootPathName string) (DriveType, error) {
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumeinformationw
func GetFilesystemType(rootPathName string) (string, error) {
rootPathNamePtr, err := syscall.UTF16PtrFromString(rootPathName)
var systemType = "unavailable"
if err != nil {
return "", errors.Wrapf(err, "UTF16PtrFromString failed for rootPathName=%v", rootPathName)
}

buffer := make([]uint16, MAX_PATH+1)
// _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
success, err := _GetVolumeInformation(rootPathNamePtr, nil, 0, nil, nil, nil, &buffer[0], MAX_PATH)
// check if CD-ROM or other type that is not supported in GetVolumeInformation function
if err == ERROR_NOT_READY || err == ERROR_INVALID_FUNCTION {
return "", nil
}
if !success {
return "", errors.Wrap(err, "GetVolumeInformationW failed")
if success {
systemType = strings.ToLower(syscall.UTF16ToString(buffer))
}

return strings.ToLower(syscall.UTF16ToString(buffer)), nil
return systemType, nil
}

// EnumProcesses retrieves the process identifier for each process object in the
Expand Down

0 comments on commit 9d6c926

Please sign in to comment.