# File lib/file_systems/AppleDos.rb, line 114
def self.files(file_system_image)
  files=FileContainer.new
  vtoc_sector=file_system_image.get_sector(vtoc_track_no,vtoc_sector_no)
  catalog_sector=file_system_image.get_sector(vtoc_sector[01],vtoc_sector[02])
  done=false
  visited_sectors={}
  while !done
    break if catalog_sector.nil?
    (0..6).each {|file_number|
      file_descriptive_entry_start=11+file_number*35
      file_descriptive_entry=catalog_sector[file_descriptive_entry_start,36]                                    
      break if (file_descriptive_entry[0]==0xFF) # skip deleted files
      filename=""
      file_descriptive_entry[3..32].to_s.each_byte{|b| filename+=(b.%128).chr}
      filename.gsub!(/ *$/,"") #strip off trailing spaces
      filename.tr!("\x00-\x1f","\x40-\x5f") #convert non-printable chars to corresponding uppercase letter
      locked=(file_descriptive_entry[2]>=0x80)
      sector_count=file_descriptive_entry[0x21]+file_descriptive_entry[0x22]*256
  
      file_type_code=file_descriptive_entry[2]%0x80
#      puts "filename #{filename} sector count #{sector_count}"
      contents=""
      ts_list_track_no=file_descriptive_entry[0]
      ts_list_sector_no=file_descriptive_entry[1]
      while (ts_list_track_no>0) && (ts_list_track_no<=0X22) && (ts_list_sector_no<=0x0f)
        ts_list_sector=file_system_image.get_sector(ts_list_track_no,ts_list_sector_no)
        ts_list_track_no=ts_list_sector[1]
        ts_list_sector_no=ts_list_sector[2]

        0x0C.step(0xff,2) {|i|                                          
          data_track_no=ts_list_sector[i]
          data_sector_no=ts_list_sector[i+1]
          if (data_track_no>0) && (data_track_no<=0X22) && (data_sector_no<=0x0f) then
            contents+=file_system_image.get_sector(data_track_no,data_sector_no)
          end
        }
        if contents.length>0 then
          files<<NativeFileType.best_fit(file_system_image,filename,contents,file_type_code)
        end
      end
    }
    next_track=catalog_sector[1]                
    next_sector=catalog_sector[2]%0x10
    if (next_track==0) &&( next_sector==0) then
      done=true
    else 
      #check we haven't got into an endless loop
      s="#{next_track}/#{next_sector}"
  #    puts s
      if (!visited_sectors[s].nil?) then
        done=true
      end
      visited_sectors[s]=true
      catalog_sector=file_system_image.get_sector(next_track,next_sector)
    end
  end
  files
end