summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-08-26 14:52:31 -0700
committerKartik Null Cating-Subramanian <ksubramanian@chef.io>2015-08-27 11:54:52 -0400
commit763d15a07d76c21cba72527a6134ecf353909f91 (patch)
tree30c13ed39dc8bfe8d6346911e55c9a6b43fb312d
parent5a863dc4331799b5876edcf5fdc31666f47888d6 (diff)
downloadchef-763d15a07d76c21cba72527a6134ecf353909f91.tar.gz
Use ffi for GetVolumeNameForVolumeMountPoint
-rw-r--r--lib/chef/util/windows/volume.rb9
-rw-r--r--lib/chef/win32/api/file.rb7
-rw-r--r--lib/chef/win32/file.rb7
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