lib/windows/sys/filesystem.rb in sys-filesystem-1.1.2 vs lib/windows/sys/filesystem.rb in sys-filesystem-1.1.3

- old
+ new

@@ -17,11 +17,11 @@ # Error typically raised if any of the Sys::Filesystem methods fail. class Error < StandardError; end # The version of the sys-filesystem library. - VERSION = '1.1.2' + VERSION = '1.1.3' class Mount # The name of the volume. This is the device mapping. attr_reader :name @@ -253,24 +253,27 @@ nil end end # Returns a Filesystem::Stat object that contains information about the - # +path+ file system. + # +path+ file system. On Windows this will default to using the root + # path for volume information. # # Examples: # - # File.stat("C:\\") - # File.stat("C:\\Documents and Settings\\some_user") + # Sys::Filesystem.stat("C:\\") + # Sys::Filesystem.stat("C:\\Documents and Settings\\some_user") # def self.stat(path) bytes_avail = FFI::MemoryPointer.new(:ulong_long) bytes_free = FFI::MemoryPointer.new(:ulong_long) total_bytes = FFI::MemoryPointer.new(:ulong_long) - wpath = path.wincode + mpoint = mount_point(path) + wpath = path.wincode + # We need this call for the 64 bit support unless GetDiskFreeSpaceExW(wpath, bytes_avail, total_bytes, bytes_free) raise SystemCallError.new('GetDiskFreeSpaceEx', FFI.errno) end bytes_avail = bytes_avail.read_ulong_long @@ -280,10 +283,11 @@ sectors = FFI::MemoryPointer.new(:ulong_long) bytes = FFI::MemoryPointer.new(:ulong_long) free = FFI::MemoryPointer.new(:ulong_long) total = FFI::MemoryPointer.new(:ulong_long) + # We need this call for the total/cluster info, which is not in the Ex call. unless GetDiskFreeSpaceW(wpath, sectors, bytes, free, total) raise SystemCallError.new('GetDiskFreeSpace', FFI.errno) end sectors = sectors.read_ulong_long @@ -293,36 +297,42 @@ block_size = sectors * bytes blocks_avail = total_bytes / block_size blocks_free = bytes_free / block_size - vol_name = FFI::MemoryPointer.new(:char, MAXPATH) - base_type = FFI::MemoryPointer.new(:char, MAXPATH) - vol_serial = FFI::MemoryPointer.new(:ulong) - name_max = FFI::MemoryPointer.new(:ulong) - flags = FFI::MemoryPointer.new(:ulong) + vol_name_ptr = FFI::MemoryPointer.new(:char, MAXPATH) + base_type_ptr = FFI::MemoryPointer.new(:char, MAXPATH) + vol_serial_ptr = FFI::MemoryPointer.new(:ulong) + name_max_ptr = FFI::MemoryPointer.new(:ulong) + flags_ptr = FFI::MemoryPointer.new(:ulong) bool = GetVolumeInformationW( - wpath, - vol_name, - vol_name.size, - vol_serial, - name_max, - flags, - base_type, - base_type.size + mpoint.wincode, + vol_name_ptr, + vol_name_ptr.size, + vol_serial_ptr, + name_max_ptr, + flags_ptr, + base_type_ptr, + base_type_ptr.size ) unless bool raise SystemCallError.new('GetVolumInformation', FFI.errno) end - vol_serial = vol_serial.read_ulong - name_max = name_max.read_ulong - flags = flags.read_ulong - base_type = base_type.read_string(base_type.size).tr(0.chr, '') + vol_serial = vol_serial_ptr.read_ulong + name_max = name_max_ptr.read_ulong + flags = flags_ptr.read_ulong + base_type = base_type_ptr.read_string(base_type_ptr.size).tr(0.chr, '') + vol_name_ptr.free + vol_serial_ptr.free + name_max_ptr.free + flags_ptr.free + base_type_ptr.free + stat_obj = Stat.new stat_obj.instance_variable_set(:@path, path) stat_obj.instance_variable_set(:@block_size, block_size) stat_obj.instance_variable_set(:@blocks, blocks_avail) stat_obj.instance_variable_set(:@blocks_available, blocks_avail) @@ -416,6 +426,10 @@ # # Returns +num+ in terms of terabytes. def to_tb self / 1099511627776 end +end + +if $0 == __FILE__ + p Sys::Filesystem.stat("C:/Users/djberge") end