From 6d4da4c5f20696612e77c2a8d4e5bdad77648e2b Mon Sep 17 00:00:00 2001 From: narph Date: Mon, 1 Nov 2021 14:35:01 +0100 Subject: [PATCH 1/2] fix --- CHANGELOG.md | 6 ++++++ sigar_windows.go | 25 +++++++++++++++++-------- sys/windows/syscall_windows.go | 8 ++------ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bb96701a..a978e2a2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. [#159](https://github.com/elastic/gosigar/pull/159) + ## [0.14.1] ### Fixed diff --git a/sigar_windows.go b/sigar_windows.go index 70abb13b5..4948d1a87 100644 --- a/sigar_windows.go +++ b/sigar_windows.go @@ -136,20 +136,29 @@ func (self *FileSystemList) Get() error { if err != nil { return errors.Wrapf(err, "GetDriveType failed") } - fsType, err := windows.GetFilesystemType(drive) + // GetFilesystemType will fail for external drives like CD-ROM or other type with error codes as ERROR_NOT_READY. ERROR_INVALID_FUNCTION, ERROR_INVALID_PARAMETER, we will do the best effort to retrieve the system type, else value is empty + fsType, subErr := windows.GetFilesystemType(drive) if err != nil { return errors.Wrapf(err, "GetFilesystemType failed") } + fs := FileSystem{ + DirName: drive, + DevName: drive, + TypeName: dt.String(), + } if fsType != "" { - self.List = append(self.List, FileSystem{ - DirName: drive, - DevName: drive, - TypeName: dt.String(), - SysTypeName: fsType, - }) + fs.SysTypeName = fsType + } + self.List = append(self.List, fs) + if subErr != nil { + if err != nil { + err = errors.Wrap(err, subErr.Error()) + } else { + err = subErr + } } } - return nil + return err } // Get retrieves a list of all process identifiers (PIDs) in the system. diff --git a/sys/windows/syscall_windows.go b/sys/windows/syscall_windows.go index 12695fa6c..6920b9def 100644 --- a/sys/windows/syscall_windows.go +++ b/sys/windows/syscall_windows.go @@ -349,15 +349,11 @@ func GetFilesystemType(rootPathName string) (string, error) { if err != nil { return "", errors.Wrapf(err, "UTF16PtrFromString failed for rootPathName=%v", rootPathName) } - buffer := make([]uint16, MAX_PATH+1) 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 - } + // _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, these types of errors will be handled in the main function if !success { - return "", errors.Wrap(err, "GetVolumeInformationW failed") + return "", errors.Wrapf(err, "GetVolumeInformationW failed on disk %s", rootPathName) } return strings.ToLower(syscall.UTF16ToString(buffer)), nil From 7cf3d6c2129924dcd694e423400a4f46324b91f3 Mon Sep 17 00:00:00 2001 From: narph Date: Tue, 2 Nov 2021 13:49:53 +0100 Subject: [PATCH 2/2] ignore error --- CHANGELOG.md | 2 +- sigar_windows.go | 28 ++++++++-------------------- sys/windows/syscall_windows.go | 10 +++++----- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a978e2a2c..ebc11d816 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Fix again unsupported devices for filesystem. [#159](https://github.com/elastic/gosigar/pull/159) +- Fix again unsupported devices for filesystem. [#164](https://github.com/elastic/gosigar/pull/164) ## [0.14.1] diff --git a/sigar_windows.go b/sigar_windows.go index 4948d1a87..7d9652686 100644 --- a/sigar_windows.go +++ b/sigar_windows.go @@ -130,35 +130,23 @@ 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 { return errors.Wrapf(err, "GetDriveType failed") } - // GetFilesystemType will fail for external drives like CD-ROM or other type with error codes as ERROR_NOT_READY. ERROR_INVALID_FUNCTION, ERROR_INVALID_PARAMETER, we will do the best effort to retrieve the system type, else value is empty - fsType, subErr := windows.GetFilesystemType(drive) + fsType, err := windows.GetFilesystemType(drive) if err != nil { return errors.Wrapf(err, "GetFilesystemType failed") } - fs := FileSystem{ - DirName: drive, - DevName: drive, - TypeName: dt.String(), - } - if fsType != "" { - fs.SysTypeName = fsType - } - self.List = append(self.List, fs) - if subErr != nil { - if err != nil { - err = errors.Wrap(err, subErr.Error()) - } else { - err = subErr - } - } + self.List = append(self.List, FileSystem{ + DirName: drive, + DevName: drive, + TypeName: dt.String(), + SysTypeName: fsType, + }) } - return err + return nil } // Get retrieves a list of all process identifiers (PIDs) in the system. diff --git a/sys/windows/syscall_windows.go b/sys/windows/syscall_windows.go index 6920b9def..b5c1b064c 100644 --- a/sys/windows/syscall_windows.go +++ b/sys/windows/syscall_windows.go @@ -346,17 +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) - // _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, these types of errors will be handled in the main function - if !success { - return "", errors.Wrapf(err, "GetVolumeInformationW failed on disk %s", rootPathName) + 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