FreeNOS
FileSystemClient.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __LIB_LIBFS_FILESYSTEMCLIENT_H
19 #define __LIB_LIBFS_FILESYSTEMCLIENT_H
20 
21 #include <FreeNOS/API/ProcessID.h>
22 #include <Types.h>
23 #include <Memory.h>
24 #include "FileSystem.h"
25 #include "FileSystemMount.h"
26 
27 struct FileSystemMessage;
28 
43 {
44  private:
45 
47  static const Size MaximumFileSystemMounts = 16;
48 
49  public:
50 
57  FileSystemClient(const ProcessID pid = ANY);
58 
64  const String * getCurrentDirectory() const;
65 
71  void setCurrentDirectory(const String &directory);
72 
81  void setCurrentDirectory(String *directory);
82 
92  FileSystem::Result createFile(const char *path,
94  const FileSystem::FileModes mode) const;
95 
104  FileSystem::Result statFile(const char *path,
105  FileSystem::FileStat *st) const;
106 
115  FileSystem::Result openFile(const char *path,
116  Size & descriptor) const;
117 
125  FileSystem::Result closeFile(const Size descriptor) const;
126 
136  FileSystem::Result readFile(const Size descriptor,
137  void *buf,
138  Size *size) const;
139 
149  FileSystem::Result writeFile(const Size descriptor,
150  const void *buf,
151  Size *size) const;
152 
160  FileSystem::Result deleteFile(const char *path) const;
161 
172  FileSystem::Result waitFile(const char *filesystemPath,
173  const FileSystem::WaitSet *waitSet,
174  const Size count,
175  const Size msecTimeout) const;
176 
184  FileSystem::Result mountFileSystem(const char *mountPath) const;
185 
195  FileSystem::Result waitFileSystem(const char *path) const;
196 
204  FileSystemMount * getFileSystems(Size &numberOfMounts) const;
205 
206  private:
207 
216  FileSystem::Result request(const char *path, FileSystemMessage &msg) const;
217 
226  FileSystem::Result request(const ProcessID pid, FileSystemMessage &msg) const;
227 
235  ProcessID findMount(const char *path) const;
236 
237  private:
238 
241 
244 
247 };
248 
254 #endif /* __LIB_LIBFS_FILESYSTEMCLIENT_H */
FileSystemClient::createFile
FileSystem::Result createFile(const char *path, const FileSystem::FileType type, const FileSystem::FileModes mode) const
Create a new file.
Definition: FileSystemClient.cpp:169
FileSystem.h
FileSystemClient::MaximumFileSystemMounts
static const Size MaximumFileSystemMounts
Maximum number of mounted filesystems.
Definition: FileSystemClient.h:47
FileSystemMount.h
Types.h
FileSystem::FileType
FileType
All possible filetypes.
Definition: FileSystem.h:70
FileSystemMount
Represents a mounted filesystem.
Definition: FileSystemMount.h:35
FileSystemClient::statFile
FileSystem::Result statFile(const char *path, FileSystem::FileStat *st) const
Retrieve status of a file.
Definition: FileSystemClient.cpp:186
String
Abstraction of strings.
Definition: String.h:41
FileSystemClient
FileSystemClient provides a simple interface to a FileSystemServer.
Definition: FileSystemClient.h:42
FileSystemClient::waitFileSystem
FileSystem::Result waitFileSystem(const char *path) const
Blocking wait for a mounted filesystem.
Definition: FileSystemClient.cpp:334
FileSystem::WaitSet
Provides information about an inode.
Definition: FileSystem.h:127
FileSystemClient::mountFileSystem
FileSystem::Result mountFileSystem(const char *mountPath) const
Mount the current process as a file system on the rootfs.
Definition: FileSystemClient.cpp:324
ProcessID
u32 ProcessID
Process Identification Number.
Definition: Types.h:140
FileSystemClient::deleteFile
FileSystem::Result deleteFile(const char *path) const
Remove a file from the file system.
Definition: FileSystemClient.cpp:286
FileSystemMessage
FileSystem IPC message.
Definition: FileSystemMessage.h:37
FileSystemClient::FileSystemClient
FileSystemClient(const ProcessID pid=ANY)
Class constructor function.
Definition: FileSystemClient.cpp:29
FileSystemClient::request
FileSystem::Result request(const char *path, FileSystemMessage &msg) const
Send an IPC request to the target file system.
Definition: FileSystemClient.cpp:34
FileSystemClient::m_pid
const ProcessID m_pid
ProcessID of the target file system or ANY to lookup in mounts table.
Definition: FileSystemClient.h:246
FileSystemClient::m_currentDirectory
static String * m_currentDirectory
Current directory path is prefixed to relative path inputs.
Definition: FileSystemClient.h:243
FileSystemClient::getCurrentDirectory
const String * getCurrentDirectory() const
Get current directory String.
Definition: FileSystemClient.cpp:146
FileSystemClient::writeFile
FileSystem::Result writeFile(const Size descriptor, const void *buf, Size *size) const
Write a file.
Definition: FileSystemClient.cpp:257
FileSystemClient::closeFile
FileSystem::Result closeFile(const Size descriptor) const
Close a file.
Definition: FileSystemClient.cpp:218
FileSystemClient::openFile
FileSystem::Result openFile(const char *path, Size &descriptor) const
Open a file.
Definition: FileSystemClient.cpp:198
FileSystemClient::setCurrentDirectory
void setCurrentDirectory(const String &directory)
Set new current directory.
Definition: FileSystemClient.cpp:151
FileSystemClient::m_mounts
static FileSystemMount m_mounts[MaximumFileSystemMounts]
FileSystem mounts table.
Definition: FileSystemClient.h:240
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
FileSystemClient::getFileSystems
FileSystemMount * getFileSystems(Size &numberOfMounts) const
Get file system mounts table.
Definition: FileSystemClient.cpp:344
FileSystemClient::readFile
FileSystem::Result readFile(const Size descriptor, void *buf, Size *size) const
Read a file.
Definition: FileSystemClient.cpp:229
FileSystemClient::findMount
ProcessID findMount(const char *path) const
Retrieve the ProcessID of the FileSystemMount for the given path.
Definition: FileSystemClient.cpp:105
Memory.h
FileSystem::FileModes
u16 FileModes
Multiple FileMode values combined.
Definition: FileSystem.h:108
FileSystem::FileStat
Contains file information.
Definition: FileSystem.h:113
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
ANY
#define ANY
Definition: ProcessID.h:34
FileSystemClient::waitFile
FileSystem::Result waitFile(const char *filesystemPath, const FileSystem::WaitSet *waitSet, const Size count, const Size msecTimeout) const
Wait for one or more files to become readable/writable.
Definition: FileSystemClient.cpp:296
type
u8 type
Definition: IntelACPI.h:63