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

Directory File functionality. More...

#include <Directory.h>

Inheritance diagram for Directory:
File LinnDirectory NetworkProtocol ARP Ethernet ICMP IPV4 UDP

Public Member Functions

 Directory (const u32 inode)
 Constructor. More...
 
virtual ~Directory ()
 Destructor. More...
 
virtual FileSystem::Result read (IOBuffer &buffer, Size &size, const Size offset)
 Read directory entries. More...
 
virtual Filelookup (const char *name)
 Retrieve a File from storage. More...
 
void insert (FileSystem::FileType type, const char *name)
 Insert a new directory entry. More...
 
void remove (const char *name)
 Remove a directory entry. More...
 
void clear ()
 Clears the internal list of entries. More...
 
- Public Member Functions inherited from File
 File (const u32 inode, const FileSystem::FileType type=FileSystem::RegularFile, const UserID uid=ZERO, const GroupID gid=ZERO)
 Constructor function. More...
 
virtual ~File ()
 Destructor function. More...
 
u32 getInode () const
 Get inode number. More...
 
FileSystem::FileType getType () const
 Retrieve our filetype. More...
 
virtual FileSystem::Result write (IOBuffer &buffer, Size &size, const Size offset)
 Write bytes to the file. More...
 
virtual FileSystem::Result status (FileSystem::FileStat &st)
 Retrieve file statistics. More...
 
virtual bool canRead () const
 Check if the File has data ready for reading. More...
 
virtual bool canWrite () const
 Check if the File can be written to. More...
 

Private Member Functions

Direntget (const char *name)
 Retrieve a directory entry by it's name. More...
 

Private Attributes

List< Dirent * > entries
 List of directory entries. More...
 

Additional Inherited Members

- Protected Attributes inherited from File
const u32 m_inode
 Inode number. More...
 
const FileSystem::FileType m_type
 Type of this file. More...
 
UserID m_uid
 Owner of the file. More...
 
GroupID m_gid
 Group of the file. More...
 
FileSystem::FileModes m_access
 Access permissions. More...
 
Size m_size
 Size of the file, in bytes. More...
 

Detailed Description

Directory File functionality.

A Directory is a File which may have several child File's. Each child File which also is a Directory, may in turn have child File's. This way, a FileSystem can form a tree of File's and Directories.

See also
FileSystem
File

Definition at line 59 of file Directory.h.

Constructor & Destructor Documentation

◆ Directory()

Directory::Directory ( const u32  inode)

Constructor.

Parameters
inodeInode number for this Directory

Definition at line 23 of file Directory.cpp.

References FileSystem::DirectoryFile, and insert().

◆ ~Directory()

Directory::~Directory ( )
virtual

Destructor.

Definition at line 30 of file Directory.cpp.

References List< T >::clear(), entries, and ListIterator< T >::hasCurrent().

Member Function Documentation

◆ clear()

void Directory::clear ( )

Clears the internal list of entries.

Definition at line 99 of file Directory.cpp.

References List< T >::clear(), entries, and ListIterator< T >::hasCurrent().

◆ get()

Dirent * Directory::get ( const char *  name)
private

Retrieve a directory entry by it's name.

Parameters
nameName of the entry to get.
Returns
Direct pointer on success, ZERO otherwise.

Definition at line 107 of file Directory.cpp.

References String::compareTo(), entries, ListIterator< T >::hasCurrent(), and ZERO.

Referenced by insert().

◆ insert()

void Directory::insert ( FileSystem::FileType  type,
const char *  name 
)

Insert a new directory entry.

FileSystem implementations should implement this function to insert a new implementation defined directory entry into the underlying Storage.

Parameters
typeFile type.
nameName of the entry to add.
Note
Entry names must be unique within the same Directory.
See also
FileSystem
Storage

Definition at line 66 of file Directory.cpp.

References List< T >::append(), assert, MemoryBlock::copy(), DIRENT_LEN, entries, get(), File::m_size, Dirent::name, NULL, Dirent::type, and type.

Referenced by Directory(), and FileSystemServer::registerFile().

◆ lookup()

File * Directory::lookup ( const char *  name)
virtual

Retrieve a File from storage.

This virtual function is responsible for reading a directory entry from storage which is not already in the FileCache. It creates a File object for the directory entry and returns a pointer to it, if found.

Parameters
nameName of the directory entry to lookup.
Returns
Pointer to a File on success, ZERO otherwise.
See also
File
Dirent
Storage

Reimplemented in LinnDirectory.

Definition at line 61 of file Directory.cpp.

References ZERO.

Referenced by FileSystemServer::lookupFile().

◆ read()

FileSystem::Result Directory::read ( IOBuffer buffer,
Size size,
const Size  offset 
)
virtual

Read directory entries.

This default read implementation reads the private List of Dirent entries from memory. It can be usefull for pseudo filesystems which don't have any real data on Storage. Filesystem that do have date on Storage should implement their version of read().

Parameters
bufferInput/Output buffer to output bytes to.
sizeMaximum number of bytes to read on input. On output, the actual number of bytes read.
offsetOffset inside the file to start reading.
Returns
Result code
See also
FileSystem
Storage
Dirent

Reimplemented from File.

Reimplemented in LinnDirectory.

Definition at line 38 of file Directory.cpp.

References entries, ListIterator< T >::hasCurrent(), FileSystem::Success, and IOBuffer::write().

◆ remove()

void Directory::remove ( const char *  name)

Remove a directory entry.

A FileSystem implemenatation should lookup the internal entry for the given name, and update the underlying Storage to remove any references for it inside this Directory.

Parameters
nameName of the entry to remove.
See also
FileSystem
Storage

Definition at line 83 of file Directory.cpp.

References String::compareTo(), entries, ListIterator< T >::hasCurrent(), and File::m_size.

Field Documentation

◆ entries

List<Dirent *> Directory::entries
private

List of directory entries.

This List should only be used for pseudo filesystems, which use the default implementations of read(), insert() and remove().

See also
List
Directory::read
Directory::insert
Directory::remove

Definition at line 176 of file Directory.h.

Referenced by clear(), get(), insert(), read(), remove(), and ~Directory().


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