Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::filesystem::FileSystem Class Reference

Handles the disk operations and file system information. More...

#include <filesystem.h>

Inheritance diagram for MaxOS::filesystem::FileSystem:
MaxOS::filesystem::format::Fat32FileSystem MaxOS::filesystem::format::ext2::Ext2FileSystem

Public Member Functions

virtual ~FileSystem ()
 Destructor for FileSystem, frees the root directory (Which in turn frees all files and subdirectories)
 
Directoryroot_directory ()
 Get the directory at "/".
 
Directoryget_directory (const string &path)
 Get the directory at a given path.
 
bool exists (const string &path)
 Check if a path exists on the filesystem.
 

Protected Attributes

Directorym_root_directory = nullptr
 The fist directory in the file system (not be confused with the system root)
 

Detailed Description

Handles the disk operations and file system information.

Definition at line 96 of file filesystem.h.

Constructor & Destructor Documentation

◆ ~FileSystem()

FileSystem::~FileSystem ( )
virtual

Destructor for FileSystem, frees the root directory (Which in turn frees all files and subdirectories)

Definition at line 285 of file filesystem.cpp.

285 {
286
287 // Free the root directory
288 delete m_root_directory;
289
290}
Directory * m_root_directory
The fist directory in the file system (not be confused with the system root)
Definition filesystem.h:98

References m_root_directory.

Member Function Documentation

◆ exists()

bool FileSystem::exists ( const string path)

Check if a path exists on the filesystem.

Parameters
pathThe path to check
Returns
True if the path exists, false otherwise

Definition at line 342 of file filesystem.cpp.

342 {
343
344 // Get the directory at the path
347
348 // Check if the directory exists
349 if (!directory)
350 return false;
351
352 // Check if the file exists
353 const string file_name = Path::file_name(path);
354 return directory->open_file(file_name) != nullptr;
355}
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
Handles a group of files (directory)
Definition filesystem.h:57
File * open_file(const string &name)
Open a file in the directory.
Directory * get_directory(const string &path)
Get the directory at a given path.
static string file_name(const string &path)
Get the file name component of a path if it exists or an empty string.
Definition path.cpp:54
static string file_path(const string &path)
Finds the path to the directory the file is in.
Definition path.cpp:101

References MaxOS::filesystem::Path::file_name(), MaxOS::filesystem::Path::file_path(), get_directory(), and MaxOS::filesystem::Directory::open_file().

◆ get_directory()

Directory * FileSystem::get_directory ( const string path)

Get the directory at a given path.

Parameters
pathThe path to the directory
Returns
The directory object or null if it could not be opened

Definition at line 307 of file filesystem.cpp.

307 {
308
309 // Check if the path is the root
310 if (path == "/")
311 return root_directory();
312
313 // Recursively open the directory
314 Directory* directory = root_directory();
315 string directory_path = path;
316 while (directory_path.length() > 0) {
317
318 // Get the name of the directory
320
321 // Open the directory
323 if (!subdirectory)
324 return nullptr;
325
326 // Set the new directory
327 directory = subdirectory;
328
329 // Get the path to the next directory
330 directory_path = directory_path.substring(directory_name.length() + 1, directory_path.length() - directory_name.length() - 1);
331 }
332
333 return directory;
334}
Directory * open_subdirectory(const string &name)
Open a directory in the directory.
Directory * root_directory()
Get the directory at "/".
static string top_directory(const string &path)
Get the top directory of a path.
Definition path.cpp:125

References MaxOS::filesystem::Directory::open_subdirectory(), root_directory(), and MaxOS::filesystem::Path::top_directory().

Referenced by exists().

◆ root_directory()

Directory * FileSystem::root_directory ( )

Get the directory at "/".

Returns
The root directory of the filesystem

Definition at line 297 of file filesystem.cpp.

297 {
298 return m_root_directory;
299}

References m_root_directory.

Referenced by get_directory().

Member Data Documentation

◆ m_root_directory

Directory* MaxOS::filesystem::FileSystem::m_root_directory = nullptr
protected

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