FreeNOS
Public Member Functions | Private Member Functions | Private Attributes
LinnFileSystem Class Reference

Linnenbank FileSystem (LinnFS). More...

#include <LinnFileSystem.h>

Inheritance diagram for LinnFileSystem:
FileSystemServer ChannelServer< FileSystemServer, FileSystemMessage >

Public Member Functions

 LinnFileSystem (const char *path, Storage *storage)
 Class constructor function. More...
 
LinnSuperBlockgetSuperBlock ()
 Retrieve the superblock pointer. More...
 
StoragegetStorage ()
 Get the underlying Storage object. More...
 
LinnInodegetInode (u32 inodeNum)
 Read an inode from the filesystem. More...
 
LinnGroupgetGroup (u32 groupNum)
 Read a group descriptor from the filesystem. More...
 
LinnGroupgetGroupByInode (u32 inodeNum)
 Read a group descriptor from the filesystem, given an inode number. More...
 
u64 getOffsetRange (const LinnInode *inode, const u32 blk, Size &numContiguous)
 Calculates the offset inside storage for a given block. More...
 
- Public Member Functions inherited from FileSystemServer
 FileSystemServer (Directory *root, const char *path)
 Constructor function. More...
 
virtual ~FileSystemServer ()
 Destructor function. More...
 
const char * getMountPath () const
 Get mount path. More...
 
u32 getNextInode ()
 Get next unused inode. More...
 
FileSystem::Result mount ()
 Mount the FileSystem. More...
 
FileSystem::Result registerFile (File *file, const char *path)
 Register a new File. More...
 
FileSystem::Result registerDirectory (Directory *dir, const char *path)
 Register a new Directory. More...
 
FileSystem::Result unregisterFile (const char *path)
 Remove a File from the FileSystemServer. More...
 
virtual FilecreateFile (const FileSystem::FileType type)
 Create a new file. More...
 
void pathHandler (FileSystemMessage *msg)
 Process an incoming filesystem request using a path. More...
 
void mountHandler (FileSystemMessage *msg)
 Process a filesystem mount request message. More...
 
void getFileSystemsHandler (FileSystemMessage *msg)
 Read the file system mounts table. More...
 
virtual bool retryRequests ()
 Retry any pending requests. More...
 
- Public Member Functions inherited from ChannelServer< FileSystemServer, FileSystemMessage >
 ChannelServer (FileSystemServer *inst)
 Constructor function. More...
 
virtual ~ChannelServer ()
 Destructor function. More...
 
int run ()
 Enters an infinite loop, serving incoming requests. More...
 
void setTimeout (const uint msec)
 Set a sleep timeout. More...
 

Private Member Functions

void notSupportedHandler (FileSystemMessage *msg)
 Callback handler for unsupported operations. More...
 

Private Attributes

Storagestorage
 Provides storage. More...
 
LinnSuperBlock super
 Describes the filesystem. More...
 
Vector< LinnGroup * > * groups
 Group descriptors. More...
 
HashTable< u32, LinnInode * > inodes
 Inode cache. More...
 

Additional Inherited Members

- Public Types inherited from ChannelServer< FileSystemServer, FileSystemMessage >
enum  Result
 Result codes. More...
 
- Protected Types inherited from ChannelServer< FileSystemServer, FileSystemMessage >
typedef void(FileSystemServer ::* IPCHandlerFunction) (FileSystemMessage *)
 Member function pointer inside Base, to handle IPC messages. More...
 
typedef void(FileSystemServer ::* IRQHandlerFunction) (Size)
 Member function pointer inside Base, to handle interrupts. More...
 
- Protected Member Functions inherited from FileSystemServer
FileSystem::Result processRequest (FileSystemRequest &req)
 Process a FileSystemRequest. More...
 
FileSystem::Result inodeHandler (FileSystemRequest &req)
 Handle a request for a File specified by its inode. More...
 
FileSystem::Result waitFileHandler (FileSystemRequest &req)
 Handle a WaitFile request. More...
 
void sendResponse (FileSystemMessage *msg) const
 Send response for a FileSystemMessage. More...
 
bool redirectRequest (const char *path, FileSystemMessage *msg)
 Try to forward the given FileSystemMessage to a mount file system. More...
 
void setRoot (Directory *newRoot)
 Change the filesystem root directory. More...
 
DirectorygetParentDirectory (const char *path)
 Retrieve parent Directory for a file. More...
 
FileCachelookupFile (const FileSystemPath &path)
 Retrieve a File from storage. More...
 
FileCachefindFileCache (const char *path) const
 Search the cache for an entry. More...
 
FileCachefindFileCache (const String &path) const
 Search the cache for an entry. More...
 
FileCachefindFileCache (const FileSystemPath &path) const
 Search the cache for an entry. More...
 
FileCacheinsertFileCache (File *file, const char *pathFormat)
 Inserts a file into the in-memory filesystem tree. More...
 
void removeFileFromCache (FileCache *cache, File *file)
 Remove a File from the cache. More...
 
void clearFileCache (FileCache *cache=ZERO)
 Cleans up the entire file cache (except opened file caches and root). More...
 
- Protected Member Functions inherited from ChannelServer< FileSystemServer, FileSystemMessage >
void addIPCHandler (const Size slot, IPCHandlerFunction h, const bool sendReply=true)
 Register a new IPC message action handler. More...
 
void addIRQHandler (const Size slot, IRQHandlerFunction h)
 Register a new IRQ message vector handler. More...
 
virtual void timeout ()
 Called when sleep timeout is reached. More...
 
virtual void onProcessTerminated (const ProcessID pid)
 Called whenever another Process is terminated. More...
 
void retryAllRequests ()
 Keep retrying requests until all served. More...
 
- Protected Attributes inherited from FileSystemServer
const ProcessID m_pid
 Process identifier. More...
 
FileCachem_root
 Root entry of the filesystem tree. More...
 
HashTable< u32, File * > m_inodeMap
 Contains a mapping of inode number to file of all cached files. More...
 
const char * m_mountPath
 Mount point path. More...
 
FileSystemMountm_mounts
 Table with mounted file systems (only used by the root file system). More...
 
List< FileSystemRequest * > * m_requests
 Contains ongoing requests. More...
 
- Protected Attributes inherited from ChannelServer< FileSystemServer, FileSystemMessage >
FileSystemServerm_instance
 Server object instance. More...
 
ChannelClientm_client
 Client for sending replies. More...
 
ChannelRegistrym_registry
 Contains registered channels. More...
 
MemoryChannel m_kernelEvent
 Kernel event channel. More...
 
Index< MessageHandler< IPCHandlerFunction >, MaximumHandlerCountm_ipcHandlers
 IPC handler functions. More...
 
Index< MessageHandler< IRQHandlerFunction >, MaximumHandlerCountm_irqHandlers
 IRQ handler functions. More...
 
ProcessID m_self
 ProcessID of ourselves. More...
 
Timer::Info m_time
 System timer value. More...
 
Timer::Info m_expiry
 System timer expiration value. More...
 

Detailed Description

Linnenbank FileSystem (LinnFS).

This filesystem is rougly based on the Extended 2 FileSystem. Some changes have been made to the superblock: leaving out unused fields and simplified the meaning of existing onces. Directory entries are now static in size, i.e. 64-bytes. Those changes make it easier to program the FileSystem implementation, thus easier to understand and learn from.

Todo:
Currently the LinnFileSystem is read-only and does not support writing.
See also
FileSystemServer
Ext2FileSystem

Definition at line 73 of file LinnFileSystem.h.

Constructor & Destructor Documentation

◆ LinnFileSystem()

LinnFileSystem::LinnFileSystem ( const char *  path,
Storage storage 
)

Member Function Documentation

◆ getGroup()

LinnGroup * LinnFileSystem::getGroup ( u32  groupNum)

Read a group descriptor from the filesystem.

Parameters
groupNumGroup descriptor number.
Returns
Pointer to an LinnGroup on success, ZERO on failure.
See also
LinnGroup

Definition at line 122 of file LinnFileSystem.cpp.

References groups.

Referenced by getGroupByInode().

◆ getGroupByInode()

LinnGroup * LinnFileSystem::getGroupByInode ( u32  inodeNum)

Read a group descriptor from the filesystem, given an inode number.

Parameters
inodeNumFind the corresponding group via this inode number.
Returns
Pointer to an LinnGroup on success, ZERO on failure.
See also
LinnGroup
LinnInode

Definition at line 127 of file LinnFileSystem.cpp.

References getGroup(), LinnSuperBlock::inodesPerGroup, and super.

Referenced by getInode().

◆ getInode()

LinnInode * LinnFileSystem::getInode ( u32  inodeNum)

◆ getOffsetRange()

u64 LinnFileSystem::getOffsetRange ( const LinnInode inode,
const u32  blk,
Size numContiguous 
)

Calculates the offset inside storage for a given block.

Parameters
inodeLinnInode pointer.
blkCalculate the offset for this block.
numContiguousNumber of contiguous blocks inside the same Inode starting at the given offset.
Returns
Offset in bytes in storage.
See also
LinnInode

Definition at line 132 of file LinnFileSystem.cpp.

References assert, LinnInode::block, LinnSuperBlock::blockSize, LINN_INODE_DIR_BLOCKS, LINN_INODE_NUM_BLOCKS, LINN_MAX_BLOCK_SIZE, LINN_SUPER_NUM_PTRS, Storage::read(), storage, FileSystem::Success, super, and ZERO.

Referenced by LinnFile::read().

◆ getStorage()

Storage* LinnFileSystem::getStorage ( )
inline

Get the underlying Storage object.

Returns
Storage pointer.
See also
Storage

Definition at line 104 of file LinnFileSystem.h.

References storage.

Referenced by LinnDirectory::getLinnDirectoryEntry(), LinnFile::read(), and LinnDirectory::read().

◆ getSuperBlock()

LinnSuperBlock* LinnFileSystem::getSuperBlock ( )
inline

Retrieve the superblock pointer.

Returns
Pointer to the superblock for this filesystem.
See also
LinnSuperBlock

Definition at line 92 of file LinnFileSystem.h.

References super.

Referenced by LinnDirectory::getLinnDirectoryEntry(), LinnFile::read(), and LinnDirectory::read().

◆ notSupportedHandler()

void LinnFileSystem::notSupportedHandler ( FileSystemMessage msg)
private

Callback handler for unsupported operations.

Parameters
msgFileSystemMessage pointer

Definition at line 223 of file LinnFileSystem.cpp.

References FileSystem::NotSupported, FileSystemMessage::result, and FileSystemServer::sendResponse().

Field Documentation

◆ groups

Vector<LinnGroup *>* LinnFileSystem::groups
private

Group descriptors.

Definition at line 177 of file LinnFileSystem.h.

Referenced by getGroup(), and LinnFileSystem().

◆ inodes

HashTable<u32, LinnInode *> LinnFileSystem::inodes
private

Inode cache.

Definition at line 180 of file LinnFileSystem.h.

Referenced by getInode().

◆ storage

Storage* LinnFileSystem::storage
private

Provides storage.

Definition at line 171 of file LinnFileSystem.h.

Referenced by getInode(), getOffsetRange(), and getStorage().

◆ super

LinnSuperBlock LinnFileSystem::super
private

Describes the filesystem.

Definition at line 174 of file LinnFileSystem.h.

Referenced by getGroupByInode(), getInode(), getOffsetRange(), getSuperBlock(), and LinnFileSystem().


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