diff options
-rw-r--r-- | lib/chef/util/windows/volume.rb | 9 | ||||
-rw-r--r-- | lib/chef/win32/api/file.rb | 7 | ||||
-rw-r--r-- | lib/chef/win32/file.rb | 7 |
3 files changed, 18 insertions, 5 deletions
diff --git a/lib/chef/util/windows/volume.rb b/lib/chef/util/windows/volume.rb index e28a5091ac..e29179277c 100644 --- a/lib/chef/util/windows/volume.rb +++ b/lib/chef/util/windows/volume.rb @@ -35,11 +35,10 @@ class Chef::Util::Windows::Volume < Chef::Util::Windows end def device - buffer = 0.chr * 256 - if GetVolumeNameForVolumeMountPoint(@name, buffer, buffer.size) - return buffer[0,buffer.size].unpack("Z*")[0] - else - raise ArgumentError, get_last_error + begin + Chef::ReservedNames::Win32::File.get_volume_name_for_volume_mount_point(@name) + rescue Chef::Exceptions::Win32APIError => e + raise ArgumentError, e end end diff --git a/lib/chef/win32/api/file.rb b/lib/chef/win32/api/file.rb index c48e992882..728a6c14df 100644 --- a/lib/chef/win32/api/file.rb +++ b/lib/chef/win32/api/file.rb @@ -462,6 +462,13 @@ BOOL WINAPI DeviceIoControl( #); safe_attach_function :SetVolumeMountPointW, [:LPCTSTR, :LPCTSTR], :BOOL +#BOOL WINAPI GetVolumeNameForVolumeMountPoint( + #_In_ LPCTSTR lpszVolumeMountPoint, + #_Out_ LPTSTR lpszVolumeName, + #_In_ DWORD cchBufferLength +#); + safe_attach_function :GetVolumeNameForVolumeMountPointW, [:LPCTSTR, :LPTSTR, :DWORD], :BOOL + ############################################### # Helpers ############################################### diff --git a/lib/chef/win32/file.rb b/lib/chef/win32/file.rb index f62f9333f5..57347643fc 100644 --- a/lib/chef/win32/file.rb +++ b/lib/chef/win32/file.rb @@ -192,6 +192,13 @@ class Chef end end + def self.get_volume_name_for_volume_mount_point(mount_point) + buffer = FFI::MemoryPointer.new(2, 128) + unless GetVolumeNameForVolumeMountPointW(wstring(mount_point), buffer, buffer.size/buffer.type_size) + Chef::ReservedNames::Win32::Error.raise! + end + buffer.read_wstring + end # ::File compat class << self |