#include "board.h"
#include "filesys.h"
#include "storage.h"
#include "console.h"
#include "mmc.h"
#include "display.h"
Include dependency graph for filesys.c:
Go to the source code of this file.
Classes | |
struct | fragmentEntry |
Fragment Table. More... | |
struct | directoryStack |
Directory traversing structure. More... | |
Defines | |
#define | MAX_NUMBER_FRAGMENTS 10 |
Maximum allowable number of fragments in file. | |
#define | MAX_NUMBER_SUBDIRECTORIES 5 |
Maximum number of nested subdirectories. | |
Functions | |
void | PConvertSectorToCluster (unsigned long *sector) |
Convert sector number to cluster number. | |
void | PConvertClusterToSector (unsigned long *cluster) |
Convert cluster number to sector number. | |
unsigned long | GetFatEntry (unsigned long clusterNumber) |
Return the FAT entry for cluster clusterNumber. | |
void | WriteClusterChain () |
Write a cluster chain to FAT for a fragment. | |
unsigned char | ScanForFreeSector () |
Search for next free sector. | |
unsigned long | GetNextSector (unsigned long currentSector) |
Calculate next sector from currentSector. | |
Public unsigned char | BuildFragmentTable () |
Build a fragment table starting from current sector. | |
unsigned char | LoadNextSector () |
Traverse to next sector in file or directory. | |
Public unsigned char | FGetChar () |
Read a character from current file. | |
Public unsigned char | OpenFile (unsigned int fileNumber) |
Open a file for reading. | |
unsigned char | FatInitGlobals () |
Decipher structure of FAT volume and set globals accordingly. | |
Public unsigned char | InitFileSystem () |
Start the filing system and initialize all necessary subsystems. | |
Variables | |
data unsigned long | fatStart |
Starting sector of FAT table. | |
data unsigned long | rootStart |
Starting sector of root directory. | |
data unsigned long | dataStart |
(In FAT the start is cluster 2, so dataStart actually points to 2 clusters before the start of data area) | |
data unsigned char | fatSectorsPerCluster |
FAT Global sectors per cluster. | |
xdata struct fragmentEntry | fragment [MAX_NUMBER_FRAGMENTS] |
Fragment Table. | |
xdata unsigned long | fileSize |
Size of current file to play. | |
xdata struct directoryStack | dirStack [MAX_NUMBER_SUBDIRECTORIES] |
Directory traversing structure. | |
xdata unsigned char | dirLevel = 0 |
Current directory level, 0=Root directory. | |
xdata unsigned long | freeSector = 0 |
Next free cluster number. | |
xdata char | currentFileName [12] |
8 first characters of current file name |
Definition in file filesys.c.
|
Maximum allowable number of fragments in file.
Definition at line 37 of file filesys.c. Referenced by BuildFragmentTable(). |
|
Maximum number of nested subdirectories.
Definition at line 50 of file filesys.c. Referenced by OpenFile(). |
|
Build a fragment table starting from current sector. Returns number of fragments in song. This function is used to get fast access to the filesystem when playing so cluster chain needs not be followed when the song is playing, that would be too slow with MMC cards without extra buffer memory for the file allocation tables. Note: filesys.c module does not use the fragment table internally. it is written to be a service to the player routine, which uses storage.c module directly for disk access after using the filesys.c module for finding a file to play. I am listening to Darude's Sandstorm while coding this. In terms of memory allocation, this function is devilish. At one stage temp.l is used just to make compiler use memory at temp.l instead of spilling to another unnecessary temp variable... Definition at line 397 of file filesys.c. References Address::b, Address::B::b0, Address::B::b1, Address::B::b3, dataStart, diskSect, DiskBlock::Fat16Table, DiskBlock::Fat32Table, fatSectorsPerCluster, fatStart, fragment, IS_FAT_32, Address::l, Temp::l, fragmentEntry::length, MAX_NUMBER_FRAGMENTS, Public, ReadDiskSector(), sectorAddress, fragmentEntry::start, and temp. Referenced by PlayCurrentFile().
Here is the call graph for this function: |
|
Decipher structure of FAT volume and set globals accordingly.
Definition at line 794 of file filesys.c. References DiskBlock::Fat::Extensions::_16, DiskBlock::Fat::Extensions::_32, DiskBlock::Fat::BPB_BytsPerSec, DiskBlock::Fat::BPB_FATSz16, DiskBlock::Fat::Extensions::Fat32Specific::BPB_FATSz32, DiskBlock::Fat::BPB_HiddSec, DiskBlock::Fat::BPB_NumFATs, DiskBlock::Fat::BPB_RootEntCnt, DiskBlock::Fat::BPB_RsvdSecCnt, DiskBlock::Fat::BPB_SecPerClus, DiskBlock::Fat::BPB_TotSec16, DiskBlock::Fat::BPB_TotSec32, DiskBlock::Fat::Extensions::Fat16Specific::BS_FilSysType, DiskBlock::Fat::Extensions::Fat32Specific::BS_FilSysType, DiskBlock::Fat::BS_OEMName, DiskBlock::Fat::Extensions::Fat16Specific::BS_VolLab, DiskBlock::Fat::Extensions::Fat32Specific::BS_VolLab, Temp::c, dataStart, diskSect, DiskBlock::Fat::ext, DiskBlock::fat, fatSectorsPerCluster, fatStart, IS_FAT_32, Address::l, rootStart, sectorAddress, and temp. Referenced by InitFileSystem().
|
|
Read a character from current file. This can be called after calling OpenFile. It is a slow method for reading character based file data. fileSize holds the number of characters still left in file to be read, check for fileSize=0 to detect end-of-file. If FGetChar is called after the end of file is reached, it does nothing and returns 0. Definition at line 549 of file filesys.c. References DiskBlock::Raw::buf, dataBufPtr, diskSect, fileSize, Address::l, LoadNextSector(), Public, DiskBlock::raw, ReadDiskSector(), and sectorAddress. Referenced by GetAVIBlock().
Here is the call graph for this function: |
|
Return the FAT entry for cluster clusterNumber.
Definition at line 81 of file filesys.c. References diskSect, DiskBlock::Fat16Table, DiskBlock::Fat32Table, fatStart, IS_FAT_32, Address::l, ReadDiskSector(), and sectorAddress. Referenced by ScanForFreeSector().
Here is the call graph for this function: |
|
Calculate next sector from currentSector. Return sector address with MSB set if end of file. This is the essence of FAT filesystem: traversing through the file allocation table to scan for cluster chains. Definition at line 299 of file filesys.c. References Address::b, Address::B::b0, Address::B::b1, Address::B::b3, dataStart, diskSect, DiskBlock::Fat16Table, DiskBlock::Fat32Table, fatSectorsPerCluster, fatStart, IS_FAT_32, Address::l, ReadDiskSector(), and sectorAddress. Referenced by LoadNextSector(), and OpenFile().
Here is the call graph for this function: |
|
Start the filing system and initialize all necessary subsystems. Init storage and file system. FAT16 and FAT32 are supported Definition at line 902 of file filesys.c. References Address::b, Address::B::b0, Address::B::b1, Address::B::b2, Address::B::b3, DiskBlock::Raw::buf, dataStart, diskSect, FatInitGlobals(), fatStart, freeSector, InitStorage(), Address::l, Public, DiskBlock::raw, ReadDiskSector(), rootStart, and sectorAddress. Referenced by main().
Here is the call graph for this function: |
|
Traverse to next sector in file or directory.
End of File Definition at line 529 of file filesys.c. References Address::b, Address::B::b1, GetNextSector(), Address::l, ReadDiskSector(), and sectorAddress. Referenced by FGetChar().
Here is the call graph for this function: |
|
Open a file for reading. Prepares the Filing System to read a data file from the storage. Files are referred to by their numbers, not file names. This makes the system generic, not necessarily needing a complex file system such as FAT. The way to assign numbers to files is implementation dependent. Returns 0 when ok, error code otherwise.
Additionally, if it's called with 0 as the fileNumber and it happens to see an empty directory record, it registers a new file with name RECnnnnn.WAV starting from cluster fragment[0].start with file size from fragment[0].length Definition at line 598 of file filesys.c. References DirRecordUnion::Entry::Attr, Temp::c, currentFileName, dataBufPtr, dataStart, DiskBlock::dir, dirLevel, dirStack, diskSect, displayText, directoryStack::entry, DirRecordUnion::entry, fatSectorsPerCluster, DirRecordUnion::Entry::FileSize, fileSize, fragment, DirRecordUnion::Entry::FstClusHi, DirRecordUnion::Entry::FstClusLo, GetNextSector(), InitMMC(), Address::l, fragmentEntry::length, MAX_NUMBER_SUBDIRECTORIES, DirRecordUnion::Entry::Name, Public, ReadDiskSector(), rootStart, directoryStack::sector, sectorAddress, fragmentEntry::start, temp, and WriteDiskSector(). Referenced by main(), and WriteClusterChain().
Here is the call graph for this function: |
|
Convert cluster number to sector number.
Definition at line 74 of file filesys.c. References dataStart, and fatSectorsPerCluster. Referenced by ScanForFreeSector().
|
|
Convert sector number to cluster number.
Definition at line 68 of file filesys.c. References dataStart, and fatSectorsPerCluster. Referenced by ScanForFreeSector(), and WriteClusterChain().
|
|
Search for next free sector. If freeSector is zero, a new file should be allocated. Definition at line 244 of file filesys.c. References dataStart, fatSectorsPerCluster, freeSector, GetFatEntry(), PConvertClusterToSector(), and PConvertSectorToCluster(). Referenced by Record().
Here is the call graph for this function: |
|
Write a cluster chain to FAT for a fragment. This takes its input from the fragment[] table. It currently has the ability to register only single fragment from fragment[0]. fragment[1].start should contain the next cluster number after this fragment or 0x0fffffff if this is the last fragment. This function currently also registers a FAT directory entry for the file to first free entry slot in the directory structure. If no free directory entries are available, it will behave unpredictably. This could happen in FAT32. OpenFile(0) is a special call to register a directory entry for fragment[0].
Definition at line 125 of file filesys.c. References Temp::c, diskSect, DiskBlock::Fat16Table, DiskBlock::Fat32Table, fatSectorsPerCluster, fatStart, fragment, IS_FAT_32, Address::l, fragmentEntry::length, OpenFile(), PConvertSectorToCluster(), ReadDiskSector(), sectorAddress, fragmentEntry::start, temp, and WriteDiskSector(). Referenced by Record().
Here is the call graph for this function: |
|
8 first characters of current file name
Definition at line 65 of file filesys.c. Referenced by main(), and OpenFile(). |
|
(In FAT the start is cluster 2, so dataStart actually points to 2 clusters before the start of data area)
Definition at line 29 of file filesys.c. Referenced by BuildFragmentTable(), FatInitGlobals(), GetNextSector(), InitFileSystem(), OpenFile(), PConvertClusterToSector(), PConvertSectorToCluster(), and ScanForFreeSector(). |
|
Current directory level, 0=Root directory.
Definition at line 59 of file filesys.c. Referenced by OpenFile(). |
|
Directory traversing structure.
Referenced by OpenFile(). |
|
FAT Global sectors per cluster.
Definition at line 32 of file filesys.c. Referenced by BuildFragmentTable(), FatInitGlobals(), GetNextSector(), OpenFile(), PConvertClusterToSector(), PConvertSectorToCluster(), Record(), ScanForFreeSector(), and WriteClusterChain(). |
|
Starting sector of FAT table.
Definition at line 21 of file filesys.c. Referenced by BuildFragmentTable(), FatInitGlobals(), GetFatEntry(), GetNextSector(), InitFileSystem(), and WriteClusterChain(). |
|
Size of current file to play.
Definition at line 47 of file filesys.c. Referenced by FGetChar(), GetAVIBlock(), OpenFile(), and PlayAvi(). |
|
Fragment Table. Maximum fragment size is (4G-1 sectors) Referenced by BuildFragmentTable(), OpenFile(), PlayCurrentFile(), Record(), and WriteClusterChain(). |
|
Next free cluster number.
Definition at line 62 of file filesys.c. Referenced by InitFileSystem(), Record(), and ScanForFreeSector(). |
|
Starting sector of root directory.
Definition at line 24 of file filesys.c. Referenced by FatInitGlobals(), InitFileSystem(), and OpenFile(). |