Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle ERROR_INVALID_PARAMETER error for GetVolumeInformationW win32 api #164

Merged
merged 2 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we should report err somewhere, if possible?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could do 2 things, either in the beats code check for unavailable and add an info message in the logs or add a note in the documentation regarding this specific field. I would go for the docs in this case, with this occasion maybe also clarify in some cases the field values in windows might have a different meaning .
Either way I don't think we should complicate the code in the gosigar lib.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, that makes sense. Do you want to add the doc line in the PR to update beats ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that will be a separate PR with the new version of gosigar

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! I'm a little paranoid about weird errors/edge cases going undocumented, so I like to make sure.

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