Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::filesystem::DirectoryResource Class Referencefinal

A wrapper for a Directory which exposes Directory operations as Resource operations. More...

#include <vfsresource.h>

Inheritance diagram for MaxOS::filesystem::DirectoryResource:
MaxOS::processes::Resource

Public Member Functions

 DirectoryResource (const string &name, size_t flags, processes::resource_type_t type)
 Construct a new Directory Resource object.
 
int read (void *buffer, size_t size, size_t flags) final
 read from a directory resource
 
int write (const void *buffer, size_t size, size_t flags) final
 write to a directory resource
 
- Public Member Functions inherited from MaxOS::processes::Resource
 Resource (const string &name, size_t flags, resource_type_t type)
 Constructs a new Resource object.
 
string name ()
 Gets the name of this resource.
 
resource_type_t type ()
 Gets the type of this resource.
 
virtual void open (size_t flags)
 Opens the resource.
 
virtual void close (size_t flags)
 Closes the resource.
 

Public Attributes

Directorydirectory
 The directory that this resource handles & exposes.
 

Detailed Description

A wrapper for a Directory which exposes Directory operations as Resource operations.

Definition at line 49 of file vfsresource.h.

Constructor & Destructor Documentation

◆ DirectoryResource()

DirectoryResource::DirectoryResource ( const string name,
size_t  flags,
processes::resource_type_t  type 
)

Construct a new Directory Resource object.

Parameters
nameThe name of the resource
flagsThe flags for the resource when opened
typeThe type of the resource

Definition at line 134 of file vfsresource.cpp.

135: Resource(name, flags, type),
136 directory(nullptr)
137{
138
139}
Directory * directory
The directory that this resource handles & exposes.
Definition vfsresource.h:61
Represents a generic resource that can be opened, closed, read from and written to.
Definition resource.h:29
string name()
Gets the name of this resource.
Definition resource.cpp:79
resource_type_t type()
Gets the type of this resource.
Definition resource.cpp:88

Member Function Documentation

◆ read()

int DirectoryResource::read ( void buffer,
size_t  size,
size_t  flags 
)
finalvirtual

read from a directory resource

Parameters
bufferThe buffer to read into
sizeThe number of bytes to read
flagsThe flags to pass to the reading
Returns
The number of bytes successfully read or -1 on error

Reimplemented from MaxOS::processes::Resource.

Definition at line 230 of file vfsresource.cpp.

230 {
231
232 // Directory not found
233 if(!directory)
234 return -1;
235
236 switch ((DirectoryFlags)flags){
237 case DirectoryFlags::READ_ENTRIES:{
238 write_entries(buffer, size);
239 break;
240 }
241
242 case DirectoryFlags::READ_ENTRIES_SIZE:{
243 return entries_size();
244 }
245
246 default:
247 return -1;
248 }
249
250 return size;
251
252}
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22

References directory.

◆ write()

int DirectoryResource::write ( const void buffer,
size_t  size,
size_t  flags 
)
finalvirtual

write to a directory resource

Parameters
bufferThe buffer to write from
sizeThe number of bytes to write
flagsThe flags to pass to the writing
Returns
The number of bytes successfully written or -1 on error

Reimplemented from MaxOS::processes::Resource.

Definition at line 262 of file vfsresource.cpp.

262 {
263
264 // Directory not found
265 if(!directory)
266 return -1;
267
268 auto registry = GlobalResourceRegistry::get_registry(resource_type_t::FILESYSTEM);
269
270 switch ((DirectoryFlags)flags){
271
272 case DirectoryFlags::WRITE_NAME : {
273
274 // Open the parent
276 auto parent_directory = ((DirectoryResource*)parent)->directory;
277
278 // Rename
279 string new_name = string((uint8_t*)buffer, size);
280 parent_directory->rename_subdirectory(directory, new_name);
281 break;
282 }
283
284 case DirectoryFlags::WRITE_NEW_FILE:{
285
286 string new_name = string((uint8_t*)buffer, size);
288 break;
289 }
290
291
292 case DirectoryFlags::WRITE_NEW_DIR:{
293
294 string new_name = string((uint8_t*)buffer, size);
296 break;
297 }
298
299 case DirectoryFlags::WRITE_REMOVE_FILE:{
300
301 string new_name = string((uint8_t*)buffer, size);
303 break;
304 }
305 case DirectoryFlags::WRITE_REMOVE_DIR:{
306
307 string new_name = string((uint8_t*)buffer, size);
309 break;
310 }
311
312 default:
313 return -1;
314 }
315
316 return size;
317}
A wrapper for a Directory which exposes Directory operations as Resource operations.
Definition vfsresource.h:49
virtual Directory * create_subdirectory(const string &name)
Create a directory in the directory.
virtual void remove_subdirectory(const string &name)
Try to remove a directory in the directory.
virtual void remove_file(const string &name)
Delete a file in the directory.
virtual File * create_file(const string &name)
Create a file in the directory.
static string parent_directory(const string &path)
Get the parent directory of the path.
Definition path.cpp:148
static BaseResourceRegistry * get_registry(resource_type_t type)
Gets a registry of a type.
Definition resource.cpp:217
class MaxOS::String string
Typedef for String.

References MaxOS::filesystem::Directory::create_file(), MaxOS::filesystem::Directory::create_subdirectory(), directory, MaxOS::processes::GlobalResourceRegistry::get_registry(), MaxOS::processes::Resource::name(), MaxOS::filesystem::Path::parent_directory(), MaxOS::filesystem::Directory::remove_file(), and MaxOS::filesystem::Directory::remove_subdirectory().

Member Data Documentation

◆ directory

Directory* MaxOS::filesystem::DirectoryResource::directory

The directory that this resource handles & exposes.

Definition at line 61 of file vfsresource.h.

Referenced by read(), and write().


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