The Pedigree Project  0.1
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
FatFilesystem Class Reference

#include <FatFilesystem.h>

+ Inheritance diagram for FatFilesystem:
+ Collaboration diagram for FatFilesystem:

Classes

union  RootDirInfo
 

Public Member Functions

virtual bool initialise (Disk *pDisk)
 
virtual FilegetRoot () const
 
virtual String getVolumeLabel () const
 
virtual uint64_t read (File *pFile, uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
 
virtual uint64_t write (File *pFile, uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
 
virtual void truncate (File *pFile)
 
virtual void fileAttributeChanged (File *pFile)
 
virtual void cacheDirectoryContents (File *pFile)
 
virtual void extend (File *pFile, size_t size)
 
- Public Member Functions inherited from Filesystem
 Filesystem ()
 
virtual ~Filesystem ()
 
virtual Filefind (const StringView &path)
 
virtual Filefind (const String &path)
 
virtual Filefind (const StringView &path, File *pStartNode)
 
virtual Filefind (const String &path, File *pStartNode)
 
bool createFile (const StringView &path, uint32_t mask, File *pStartNode=0)
 
bool createDirectory (const StringView &path, uint32_t mask, File *pStartNode=0)
 
bool createSymlink (const StringView &path, const String &value, File *pStartNode=0)
 
bool createLink (const StringView &path, File *target, File *pStartNode=0)
 
bool remove (const StringView &path, File *pStartNode=0)
 
DiskgetDisk ()
 
bool isReadOnly ()
 
virtual bool isCaseSensitive ()
 

Static Public Member Functions

static Filesystemprobe (Disk *pDisk)
 

Protected Member Functions

virtual bool createFile (File *parent, const String &filename, uint32_t mask)
 
virtual bool createDirectory (File *parent, const String &filename, uint32_t mask)
 
virtual bool createSymlink (File *parent, const String &filename, const String &value)
 
virtual bool remove (File *parent, File *file)
 
 FatFilesystem (const FatFilesystem &)
 
void operator= (const FatFilesystem &)
 
void loadRootDir ()
 
void cacheVolumeLabel ()
 
bool readCluster (uint32_t block, uintptr_t buffer) const
 
bool writeCluster (uint32_t block, uintptr_t buffer)
 
bool writeSectorBlock (uint32_t sec, size_t size, uintptr_t buffer)
 
bool readSectorBlock (uint32_t sec, size_t size, uintptr_t buffer) const
 
uint32_t getSectorNumber (uint32_t cluster) const
 
uint32_t getClusterEntry (uint32_t cluster, bool bLock=true)
 
uint32_t setClusterEntry (uint32_t cluster, uint32_t value, bool bLock=true)
 
String convertFilenameTo (String filename) const
 
String convertFilenameFrom (String filename) const
 
uint32_t findFreeCluster (bool bLock=false)
 
void updateFileSize (File *pFile, int64_t sizeChange)
 
void setCluster (File *pFile, uint32_t clus)
 
void * readDirectoryPortion (uint32_t clus) const
 
void writeDirectoryPortion (uint32_t clus, void *p)
 
FilecreateFile (File *parentDir, const String &filename, uint32_t mask, bool bDirectory=false, uint32_t dirClus=0)
 
DirgetDirectoryEntry (uint32_t clus, uint32_t offset) const
 
void writeDirectoryEntry (Dir *dir, uint32_t clus, uint32_t offset)
 
bool isEof (uint32_t cluster) const
 
uint32_t eofValue () const
 
Time::Timestamp getUnixTimestamp (uint16_t time, uint16_t date) const
 
uint16_t getFatDate (Time::Timestamp timestamp) const
 
- Protected Member Functions inherited from Filesystem
virtual bool createLink (File *parent, const String &filename, File *target)
 

Protected Attributes

Superblock m_Superblock
 
Superblock16 m_Superblock16
 
Superblock32 m_Superblock32
 
FSInfo32 m_FsInfo
 
FatType m_Type
 
uint64_t m_DataAreaStart
 
uint32_t m_RootDirCount
 
uint16_t m_FatSector
 
union FatFilesystem::RootDirInfo m_RootDir
 
uint32_t m_BlockSize
 
uint8_t * m_pFatCache
 
UnlikelyLock m_FatLock
 
Filem_pRoot
 
Tree< uintptr_t, uintptr_t > m_FatCache
 
uint32_t m_FreeClusterHint
 
String m_VolumeLabel
 
- Protected Attributes inherited from Filesystem
bool m_bReadOnly
 
Diskm_pDisk
 

Friends

class FatFile
 
class FatDirectory
 

Additional Inherited Members

- Public Types inherited from Filesystem
typedef Filesystem *(* ProbeCallback) (Disk *)
 

Detailed Description

This class provides an implementation of the FAT filesystem.

Definition at line 38 of file FatFilesystem.h.

Member Function Documentation

String FatFilesystem::convertFilenameFrom ( String  filename) const
protected

Converts a string from 8.3 format

Definition at line 1242 of file FatFilesystem.cc.

References NOTICE.

Referenced by FatDirectory::cacheDirectoryContents().

+ Here is the caller graph for this function:

String FatFilesystem::convertFilenameTo ( String  filename) const
protected

Converts a string to 8.3 format

Todo:
This should increment if a file is found with the same name!

todo Increment on duplicate

Definition at line 1146 of file FatFilesystem.cc.

References String::rstrip().

Referenced by FatDirectory::addEntry().

+ Here is the caller graph for this function:

bool FatFilesystem::createDirectory ( File parent,
const String filename,
uint32_t  mask 
)
protectedvirtual

createDirectory calls this after it has parsed the string path.

Implements Filesystem.

Definition at line 1473 of file FatFilesystem.cc.

References Filesystem::createFile(), and FatDirectory::setInode().

bool FatFilesystem::createFile ( File parent,
const String filename,
uint32_t  mask 
)
protectedvirtual

createFile calls this after it has parsed the string path.

Implements Filesystem.

Definition at line 1466 of file FatFilesystem.cc.

References Filesystem::createFile().

File * FatFilesystem::createFile ( File parentDir,
const String filename,
uint32_t  mask,
bool  bDirectory = false,
uint32_t  dirClus = 0 
)
protected

Creates a file - actual doer for the public createFile

Definition at line 1403 of file FatFilesystem.cc.

References FatDirectory::addEntry(), FatFile::FatFile(), Directory::fromFile(), and File::isDirectory().

bool FatFilesystem::createSymlink ( File parent,
const String filename,
const String value 
)
protectedvirtual

createSymlink calls this after it has parsed the string path.

Implements Filesystem.

Definition at line 1515 of file FatFilesystem.cc.

References FatDirectory::addEntry(), Directory::fromFile(), File::isDirectory(), and File::write().

uint32_t FatFilesystem::eofValue ( ) const
inlineprotected

EOF values

Definition at line 149 of file FatFilesystem.h.

References m_Type.

Referenced by FatDirectory::addEntry(), and isEof().

+ Here is the caller graph for this function:

uint32_t FatFilesystem::findFreeCluster ( bool  bLock = false)
protected

Finds a free cluster - bLock determines if we should enforce locking, defaults to false because findFreeCluster is generally called within a function that has already locked the FAT

Todo:
For FAT32, update the FSInfo structure

Definition at line 459 of file FatFilesystem.cc.

References Dec, FATAL, File::getName(), Hex, Filesystem::m_bReadOnly, and NOTICE.

Referenced by FatDirectory::addEntry().

+ Here is the caller graph for this function:

uint32_t FatFilesystem::getClusterEntry ( uint32_t  cluster,
bool  bLock = true 
)
protected

Grabs a cluster entry - bLock determines if this should enforce locking internally or allow the caller to ensure the FAT is locked.

Todo:

Definition at line 904 of file FatFilesystem.cc.

References ERROR, FATAL, Scheduler::instance(), NOTICE, and Scheduler::yield().

Referenced by FatDirectory::addEntry(), and FatDirectory::cacheDirectoryContents().

+ Here is the caller graph for this function:

Dir * FatFilesystem::getDirectoryEntry ( uint32_t  clus,
uint32_t  offset 
) const
protected

Reads a directory entry from disk

Definition at line 783 of file FatFilesystem.cc.

Referenced by FatDirectory::removeEntry().

+ Here is the caller graph for this function:

uint16_t FatFilesystem::getFatDate ( Time::Timestamp  timestamp) const
inlineprotected

Gets a FAT date from a UNIX timestamp

Todo:
Write

Definition at line 213 of file FatFilesystem.h.

File * FatFilesystem::getRoot ( ) const
virtual

Returns the root filesystem node.

Implements Filesystem.

Definition at line 260 of file FatFilesystem.cc.

uint32_t FatFilesystem::getSectorNumber ( uint32_t  cluster) const
protected

Obtains the first sector given a cluster number

Definition at line 899 of file FatFilesystem.cc.

Time::Timestamp FatFilesystem::getUnixTimestamp ( uint16_t  time,
uint16_t  date 
) const
inlineprotected

Gets a UNIX timestamp from a FAT date/time

This should actually work for practically any year.

Definition at line 161 of file FatFilesystem.h.

Referenced by FatDirectory::cacheDirectoryContents().

+ Here is the caller graph for this function:

String FatFilesystem::getVolumeLabel ( ) const
virtual

Returns a string identifying the volume label.

Implements Filesystem.

Definition at line 335 of file FatFilesystem.cc.

References File::getFullPath(), File::isDirectory(), and WARNING.

bool FatFilesystem::initialise ( Disk pDisk)
virtual

Populates this filesystem with data from the given Disk device.

Returns
true on success, false on failure.

Validate the BPB and check for FAT FS

Check the FAT FS itself, ensuring it's valid

Start loading actual FS info

Implements Filesystem.

Definition at line 76 of file FatFilesystem.cc.

References ERROR, Disk::getName(), Filesystem::getRoot(), initialise(), Filesystem::m_pDisk, NOTICE, and Disk::read().

Referenced by initialise(), and FatSymlink::writeBytewise().

+ Here is the caller graph for this function:

bool FatFilesystem::isEof ( uint32_t  cluster) const
inlineprotected

Is a given cluster VALUE EOF?

Definition at line 143 of file FatFilesystem.h.

References eofValue().

Referenced by FatDirectory::addEntry(), and FatDirectory::cacheDirectoryContents().

+ Here is the caller graph for this function:

bool FatFilesystem::readCluster ( uint32_t  block,
uintptr_t  buffer 
) const
protected

Reads a cluster from the disk.

Definition at line 828 of file FatFilesystem.cc.

Referenced by FatDirectory::addEntry(), and FatDirectory::cacheDirectoryContents().

+ Here is the caller graph for this function:

void * FatFilesystem::readDirectoryPortion ( uint32_t  clus) const
protected

Reads part of a directory into a buffer, returns the allocated buffer (which needs to be freed

Definition at line 732 of file FatFilesystem.cc.

Referenced by FatDirectory::addEntry(), and FatDirectory::cacheDirectoryContents().

+ Here is the caller graph for this function:

bool FatFilesystem::readSectorBlock ( uint32_t  sec,
size_t  size,
uintptr_t  buffer 
) const
protected

Writes a block starting from a specific sector to the disk.

Definition at line 835 of file FatFilesystem.cc.

References Filesystem::m_pDisk, and Disk::read().

bool FatFilesystem::remove ( File parent,
File file 
)
protectedvirtual

Remove a file given a parent and file, assuming path parsing already completed.

Implements Filesystem.

Definition at line 1559 of file FatFilesystem.cc.

References VFS::addProbeCallback(), ERROR, Directory::fromFile(), VFS::instance(), and FatDirectory::removeEntry().

void FatFilesystem::setCluster ( File pFile,
uint32_t  clus 
)
protected

Sets the cluster for a file on disk

Definition at line 713 of file FatFilesystem.cc.

uint32_t FatFilesystem::setClusterEntry ( uint32_t  cluster,
uint32_t  value,
bool  bLock = true 
)
protected

Sets a cluster entry - bLock determines if this should enforce locking internally or allow the caller to ensure the FAT is locked.

Todo:

Definition at line 1011 of file FatFilesystem.cc.

References ERROR, and FATAL.

Referenced by FatDirectory::addEntry().

+ Here is the caller graph for this function:

void FatFilesystem::updateFileSize ( File pFile,
int64_t  sizeChange 
)
protected

Updates the size of a file on disk

Definition at line 695 of file FatFilesystem.cc.

bool FatFilesystem::writeCluster ( uint32_t  block,
uintptr_t  buffer 
)
protected

Writes a cluster to the disk.

Definition at line 862 of file FatFilesystem.cc.

void FatFilesystem::writeDirectoryEntry ( Dir dir,
uint32_t  clus,
uint32_t  offset 
)
protected

Writes a directry entry to disk

Definition at line 799 of file FatFilesystem.cc.

Referenced by FatDirectory::removeEntry().

+ Here is the caller graph for this function:

void FatFilesystem::writeDirectoryPortion ( uint32_t  clus,
void *  p 
)
protected

Writes part of a directory from a buffer

Definition at line 759 of file FatFilesystem.cc.

Referenced by FatDirectory::addEntry().

+ Here is the caller graph for this function:

bool FatFilesystem::writeSectorBlock ( uint32_t  sec,
size_t  size,
uintptr_t  buffer 
)
protected

Reads a block starting from a specific sector from the disk.

Definition at line 869 of file FatFilesystem.cc.

References Filesystem::m_pDisk, Disk::read(), and Disk::write().

Member Data Documentation

uint32_t FatFilesystem::m_BlockSize
protected

Size of a block (in this case, a cluster)

Definition at line 243 of file FatFilesystem.h.

Referenced by FatDirectory::FatDirectory().

uint64_t FatFilesystem::m_DataAreaStart
protected

Required information

Definition at line 229 of file FatFilesystem.h.

UnlikelyLock FatFilesystem::m_FatLock
protected

FAT lock

Definition at line 250 of file FatFilesystem.h.

uint16_t FatFilesystem::m_FatSector
protected

FAT sector

Definition at line 233 of file FatFilesystem.h.

uint32_t FatFilesystem::m_FreeClusterHint
protected

Hint for the free cluster code, to avoid searching the ENTIRE FAT each time someone wants a free cluster (on non-FAT32 volumes).

Definition at line 263 of file FatFilesystem.h.

uint8_t* FatFilesystem::m_pFatCache
protected

FAT cache

Definition at line 246 of file FatFilesystem.h.

File* FatFilesystem::m_pRoot
protected

Root filesystem node.

Definition at line 253 of file FatFilesystem.h.

Superblock FatFilesystem::m_Superblock
protected

Our superblocks

Definition at line 220 of file FatFilesystem.h.

Referenced by FatDirectory::setInode().

FatType FatFilesystem::m_Type
protected

Type of the FAT

Definition at line 226 of file FatFilesystem.h.

Referenced by eofValue(), FatDirectory::FatDirectory(), and FatDirectory::setInode().

String FatFilesystem::m_VolumeLabel
protected

Cached volume label for the filesystem.

Definition at line 266 of file FatFilesystem.h.


The documentation for this class was generated from the following files: