Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::filesystem::format::ext2::Ext2Directory Class Referencefinal

Handles the directory operations on the ext2 filesystem. More...

#include <ext2.h>

Inheritance diagram for MaxOS::filesystem::format::ext2::Ext2Directory:
MaxOS::filesystem::Directory

Public Member Functions

 Ext2Directory (Ext2Volume *volume, uint32_t inode, const string &name)
 Construct a new Ext2 Directory object.
 
void read_from_disk () final
 read the directory from the inode on the disk
 
Filecreate_file (const string &name) final
 Create a new file in the directory.
 
void remove_file (const string &name) final
 Delete a file from this directory.
 
void rename_file (const string &old_name, const string &new_name) final
 Renames the file from the old name to the new name if it exists.
 
Directorycreate_subdirectory (const string &name) final
 Create a new directory in the directory.
 
void remove_subdirectory (const string &name) final
 Remove a directory entry from the directory.
 
void rename_subdirectory (const string &old_name, const string &new_name) final
 Renames the directory from the old name to the new name if it exists.
 
- Public Member Functions inherited from MaxOS::filesystem::Directory
virtual ~Directory ()
 Destructor for Directory, frees all files and subdirectories.
 
common::Vector< File * > files ()
 Get the files in the directory.
 
common::Vector< Directory * > subdirectories ()
 Get the subdirectories in the directory.
 
Fileopen_file (const string &name)
 Open a file in the directory.
 
Directoryopen_subdirectory (const string &name)
 Open a directory in the directory.
 
void rename_file (File *file, const string &new_name)
 Rename a file in the directory.
 
void rename_subdirectory (Directory *directory, const string &new_name)
 Rename a subdirectory in the directory.
 
string name ()
 Get the name of the directory.
 
size_t size ()
 Get the size of the directory.
 

Additional Inherited Members

- Protected Attributes inherited from MaxOS::filesystem::Directory
common::Vector< File * > m_files
 The files in this directory.
 
common::Vector< Directory * > m_subdirectories
 The subdirectories in this directory.
 
string m_name
 The name of this directory.
 

Detailed Description

Handles the directory operations on the ext2 filesystem.

Definition at line 420 of file ext2.h.

Constructor & Destructor Documentation

◆ Ext2Directory()

Ext2Directory::Ext2Directory ( Ext2Volume volume,
uint32_t  inode,
const string name 
)

Construct a new Ext2 Directory object.

Parameters
volumeThe volume the directory exists on
inodeThe inode number of the directory (will be used to setup the internal InodeHandler)
nameThe name of the directory

Definition at line 854 of file ext2.cpp.

855 : m_volume(volume),
856 m_inode(m_volume, inode) {
857 m_name = name;
858}
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
string m_name
The name of this directory.
Definition filesystem.h:62
string name()
Get the name of the directory.

References MaxOS::filesystem::Directory::m_name, and MaxOS::filesystem::Directory::name().

Member Function Documentation

◆ create_file()

File * Ext2Directory::create_file ( const string name)
finalvirtual

Create a new file in the directory.

Parameters
nameThe name of the file to create
Returns
The new file object or null if it could not be created

Reimplemented from MaxOS::filesystem::Directory.

Definition at line 1090 of file ext2.cpp.

1090 {
1091
1092 // Check if the file already exists
1093 for(auto& file : m_files)
1094 if(file->name() == name)
1096
1097 // Create the file
1098 auto file = new Ext2File(m_volume, create_entry(name, 0, false).inode, name);
1099 m_files.push_back(file);
1100 return file;
1101}
common::Vector< File * > m_files
The files in this directory.
Definition filesystem.h:59
Handles the file operations on the ext2 filesystem.
Definition ext2.h:402

References MaxOS::filesystem::Directory::m_files, and MaxOS::filesystem::Directory::name().

◆ create_subdirectory()

Directory * Ext2Directory::create_subdirectory ( const string name)
finalvirtual

Create a new directory in the directory.

Parameters
nameThe name of the directory to create
Returns
The new directory object or null if it could not be created

Reimplemented from MaxOS::filesystem::Directory.

Definition at line 1128 of file ext2.cpp.

1128 {
1129
1130 // Check if the directory already exists
1131 for(auto& subdirectory : m_subdirectories)
1132 if(subdirectory->name() == name)
1134
1135 // Store the directory
1136 auto directory = new Ext2Directory(m_volume, create_entry(name, 0, true).inode, name);
1137 m_subdirectories.push_back(directory);
1138
1139 // Create self & parent references
1140 directory->create_entry(".", directory->m_inode.inode_number, true);
1141 directory->create_entry("..", m_inode.inode_number, true);
1142
1143 return directory;
1144}
common::Vector< Directory * > m_subdirectories
The subdirectories in this directory.
Definition filesystem.h:60
Handles the directory operations on the ext2 filesystem.
Definition ext2.h:420
uint32_t inode_number
The index of the inode.
Definition ext2.h:385

References MaxOS::filesystem::format::ext2::InodeHandler::inode_number, MaxOS::filesystem::Directory::m_subdirectories, and MaxOS::filesystem::Directory::name().

◆ read_from_disk()

void Ext2Directory::read_from_disk ( )
finalvirtual

read the directory from the inode on the disk

Reimplemented from MaxOS::filesystem::Directory.

Definition at line 959 of file ext2.cpp.

959 {
960
961 m_volume->ext2_lock.lock();
962 m_entries.clear();
963 m_entry_names.clear();
964
965 // Clear the old files & Directories
966 for(auto& file : m_files)
967 delete file;
968 m_files.clear();
969
970 for(auto& directory : m_subdirectories)
971 delete directory;
972 m_subdirectories.clear();
973
974 // Read the direct blocks (cant use for( : ))
975 buffer_t buffer(m_volume->block_size);
976 for(unsigned int block_pointer : m_inode.block_cache) {
977
978 // Invalid block
979 if(block_pointer == 0)
980 break;
981
982 // Parse the block
983 m_volume->read_block(block_pointer, &buffer);
984 parse_block(&buffer);
985 }
986
987 m_volume->ext2_lock.unlock();
988}
Wrapper class for a region of bytes in memor in an attempt to add some memory safety....
Definition buffer.h:25
void lock()
Lock the spinlock once it is available.
Definition spinlock.cpp:24
void unlock()
Unlock the spinlock.
Definition spinlock.cpp:32
void clear()
Removes all elements from the Vector.
Definition vector.h:461
common::Spinlock ext2_lock
Lock for synchronised access to the volume (.
Definition ext2.h:350
size_t block_size
How large each block is (in bytes)
Definition ext2.h:342
void read_block(uint32_t block_num, common::buffer_t *buffer) const
Reads a single block from the disk into a buffer.
Definition ext2.cpp:129

References MaxOS::filesystem::format::ext2::InodeHandler::block_cache, MaxOS::filesystem::format::ext2::Ext2Volume::block_size, MaxOS::common::Vector< Type >::clear(), MaxOS::filesystem::format::ext2::Ext2Volume::ext2_lock, MaxOS::common::Spinlock::lock(), MaxOS::filesystem::Directory::m_files, MaxOS::filesystem::Directory::m_subdirectories, MaxOS::filesystem::format::ext2::Ext2Volume::read_block(), and MaxOS::common::Spinlock::unlock().

◆ remove_file()

void Ext2Directory::remove_file ( const string name)
finalvirtual

Delete a file from this directory.

Parameters
nameThe name of the file to delete

Reimplemented from MaxOS::filesystem::Directory.

Definition at line 1108 of file ext2.cpp.

1108 {
1109 remove_entry(name, false);
1110}

References MaxOS::filesystem::Directory::name().

◆ remove_subdirectory()

void Ext2Directory::remove_subdirectory ( const string name)
finalvirtual

Remove a directory entry from the directory.

Parameters
nameThe name of the entry to remove

Reimplemented from MaxOS::filesystem::Directory.

Definition at line 1151 of file ext2.cpp.

1151 {
1152 remove_entry(name, true);
1153}

References MaxOS::filesystem::Directory::name().

◆ rename_file()

void Ext2Directory::rename_file ( const string old_name,
const string new_name 
)
finalvirtual

Renames the file from the old name to the new name if it exists.

Parameters
old_nameThe current name of the file that is to be changed
new_nameWhat the new name should be

Reimplemented from MaxOS::filesystem::Directory.

Definition at line 1118 of file ext2.cpp.

1118 {
1119 rename_entry(old_name, new_name, false);
1120}

◆ rename_subdirectory()

void Ext2Directory::rename_subdirectory ( const string old_name,
const string new_name 
)
finalvirtual

Renames the directory from the old name to the new name if it exists.

Parameters
old_nameThe current name of the directory that is to be changed
new_nameWhat the new name should be

Reimplemented from MaxOS::filesystem::Directory.

Definition at line 1161 of file ext2.cpp.

1161 {
1162 rename_entry(old_name, new_name, true);
1163}

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