def self.stat(path)
bytes_avail = [0].pack('Q')
bytes_free = [0].pack('Q')
total_bytes = [0].pack('Q')
unless GetDiskFreeSpaceEx(path, bytes_avail, total_bytes, bytes_free)
raise Error, get_last_error
end
bytes_avail = bytes_avail.unpack('Q').first
bytes_free = bytes_free.unpack('Q').first
total_bytes = total_bytes.unpack('Q').first
sectors = [0].pack('Q')
bytes = [0].pack('Q')
free = [0].pack('Q')
total = [0].pack('Q')
unless GetDiskFreeSpace(path, sectors, bytes, free, total)
raise Error, get_last_error
end
sectors = sectors.unpack('Q').first
bytes = bytes.unpack('Q').first
free = free.unpack('Q').first
total = total.unpack('Q').first
block_size = sectors * bytes
blocks_avail = total_bytes / block_size
blocks_free = bytes_free / block_size
vol_name = 0.chr * 260
base_type = 0.chr * 260
vol_serial = [0].pack('L')
name_max = [0].pack('L')
flags = [0].pack('L')
bool = GetVolumeInformation(
path,
vol_name,
vol_name.size,
vol_serial,
name_max,
flags,
base_type,
base_type.size
)
unless bool
raise Error, get_last_error
end
vol_serial = vol_serial.unpack('L').first
name_max = name_max.unpack('L').first
flags = flags.unpack('L').first
base_type = base_type[/^[^\0]*/]
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)
stat_obj.instance_variable_set(:@blocks_free, blocks_free)
stat_obj.instance_variable_set(:@name_max, name_max)
stat_obj.instance_variable_set(:@base_type, base_type)
stat_obj.instance_variable_set(:@flags, flags)
stat_obj.instance_variable_set(:@filesystem_id, vol_serial)
stat_obj.freeze
end