# File lib/file_systems/RsDos.rb, line 73
def self.files(file_system_image)
  files=FileContainer.new
  granule_allocation_table=file_system_image.get_sector(directory_track,2)
  return files if granule_allocation_table.nil?
#  file_system_image.volume_name="RSDOS Disk"
  (file_system_image.sectors_in_track(directory_track)-[1,2,12,13,14,15,16,17,18]).each do |sector_no|
    fde_sector=file_system_image.get_sector(directory_track,sector_no)
    (fde_sector.length/FDE_SIZE).times do |fde_number|
      fde=fde_sector[fde_number*FDE_SIZE,FDE_SIZE]
      next if fde[0]==0
      break if fde[0]==0xff
      
      filename_base=fde[0,8].unpack("A8")
      filename_extension=fde[8,3].unpack("A8")
      filename="#{filename_base}/#{filename_extension}"
      file_type, ascii_flag, granule, last_sector_bytes = fde[11,5].unpack("CCCS")
      contents=""
      granules = []
      
#      puts "#{filename}: first gran:#{granule} file type #{file_type} ascii flag #{ascii_flag}"
      
      while granule < 67
        break if granules.include?(granule)==true
        granules << granule
        track_no = Integer(granule/2)
        (track_no += 1) if granule>33
        start_sector = (granule % 2) == 0 ? 1 : 10
        #puts "Start sector: #{start_sector}"
        
        granule_value = granule_allocation_table[ granule ]
        
        if granule_value < 68 then
          9.times {|i| contents<<file_system_image.get_sector(track_no,start_sector+i)}
        else
          count = (granule_value & 0b00011111) - 1
          count.times {|i| contents<<file_system_image.get_sector(track_no,start_sector+i)}
          contents<<(file_system_image.get_sector(track_no,start_sector+count))[0,last_sector_bytes]
        end
        #puts "#{granule} = #{granule_value}"
        granule = granule_value
      end

      files<<NativeFileType.best_fit(file_system_image,filename,contents,file_type,ascii_flag)      
    end
  end
  files
end