class SlowFat::Directory
Directory
represents one directory on a FAT filesystem.
Attributes
@return [Array<Dentry>] an array of directory entries within this directory
Public Class Methods
Initialize a new Directory
object (normally only called from Filesystem.dir
) @param backing [IO] the storage containing the filesystem (e.g. open file) @param base [Integer] the location of the beginning of this directory structure within the backing device @param max_entries [Integer] the maximum number of entries that can be in this directory
# File lib/slowfat/dir.rb, line 13 def initialize(backing:, base:, max_entries:) @backing = backing @entries = [] (0..max_entries-1).each do |idx| @backing.seek base+idx*32 dir_data = @backing.read(32) entry = Dentry.new(dir_data) break if entry.type == :end_of_dentries @entries << entry end end
Public Instance Methods
Return a directory entry for a specific subdirectory within this directory @param filename [String] the name of the directory to access @return [Dentry] the directory entry object matching the requested subdirectory
# File lib/slowfat/dir.rb, line 42 def dir_entry(filename) @entries.each do |dentry| full_dentry_filename = dentry.extension.length > 0 ? "#{dentry.filename}.#{dentry.extension}".downcase : dentry.filename.downcase return dentry if dentry.type == :directory and filename.downcase == full_dentry_filename end nil end
Return a directory entry for a specific file within this directory @param filename [String] the name of the file to access @return [Dentry] the directory entry object matching the requested file
# File lib/slowfat/dir.rb, line 29 def file_entry(filename) @entries.each do |dentry| full_dentry_filename = dentry.extension.length > 0 ? "#{dentry.filename}.#{dentry.extension}".downcase : dentry.filename.downcase return dentry if dentry.type == :file and filename.downcase == full_dentry_filename end nil end
Convert a Directory
into a vaguely DOS-style file listing @return [String] the contents of this directory, formatted as a human-readable listing
# File lib/slowfat/dir.rb, line 54 def to_s buf = "" @entries.each do |dentry| if(dentry.type == :file) then buf += sprintf("%-8s %-3s %d\n", dentry.filename, dentry.extension, dentry.size) elsif(dentry.type == :directory) buf += sprintf("%-8s %-3s <DIR>\n", dentry.filename, dentry.extension) end end buf end