Skip to content

Conversation

StefanoBalzarottiNozomi
Copy link
Contributor

Fix to use correct paths/buffer lengths, consider that NTFS supports also paths longer than 256 (windows.MAX_PATH)

volumeNameBufferLength = uint32(windows.MAX_PATH + 1)
volumePathBufferLength = volumeNameBufferLength
maxWarningsInDrive = 5
maxVolumeNameLength = uint32(windows.MAX_PATH + 1) // this should be a GUID (50), but for safety I keep max_path
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's a guid in string format that represent the volume, as far as I know all volumes are in guid format, but it's not well specified in documentation, so I keep MAX_PATH in case a volume can have a name in a longer format.

return partitionStats, err
}
drivesString := windows.UTF16ToString(lpBuffer)
drives := strings.Split(drivesString, "\x00")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

all drive names are separated by an UTF-16 null character

uintptr(0),
uintptr(0))

lpBuffer := make([]uint16, bufferLen)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this fixes the call when you have many drives mounted and a buffer > windows.MAX_PATH

uintptr(len(volumeName)),
uintptr(unsafe.Pointer(&serialNumber)),
uintptr(unsafe.Pointer(&maxComponentLength)),
uintptr(0), // serial numbrt
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these data are not used, so it's better to don't request them

return nil, fmt.Errorf("failed to get volume paths size for volume %s: %w", windows.UTF16ToString(volNameBuf), volumePathFirstErr)
}

volPathsBuf := make([]uint16, returnLen)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this fixes the call when a volume is mounted as a folder in a path longer than 256 characters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant