FreeNOS
FileSystemServer.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009 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_FILESYSTEMSERVER_H
19#define __LIB_LIBFS_FILESYSTEMSERVER_H
20
21#include <ChannelServer.h>
22#include <Vector.h>
23#include "Directory.h"
24#include "Device.h"
25#include "File.h"
26#include "FileCache.h"
27#include "FileSystem.h"
28#include "FileSystemPath.h"
29#include "FileSystemMessage.h"
30#include "FileSystemRequest.h"
31#include "FileSystemMount.h"
32
44class FileSystemServer : public ChannelServer<FileSystemServer, FileSystemMessage>
45{
46 private:
47
49 static const Size MaximumFileSystemMounts = 32;
50
52 static const Size MaximumWaitSetCount = 32;
53
54 public:
55
62 FileSystemServer(Directory *root, const char *path);
63
67 virtual ~FileSystemServer();
68
74 const char * getMountPath() const;
75
82
91
100 FileSystem::Result registerFile(File *file, const char *path);
101
111 const char *path);
112
120 FileSystem::Result unregisterFile(const char *path);
121
129 virtual File * createFile(const FileSystem::FileType type);
130
143
150
157
163 virtual bool retryRequests();
164
165 protected:
166
174
183
192
198 void sendResponse(FileSystemMessage *msg) const;
199
208 bool redirectRequest(const char *path, FileSystemMessage *msg);
209
222 void setRoot(Directory *newRoot);
223
231 Directory * getParentDirectory(const char *path);
232
245 FileCache * lookupFile(const FileSystemPath &path);
246
254 FileCache * findFileCache(const char *path) const;
255
263 FileCache * findFileCache(const String &path) const;
264
272 FileCache * findFileCache(const FileSystemPath &path) const;
273
282 FileCache * insertFileCache(File *file, const char *pathFormat);
283
290 void removeFileFromCache(FileCache *cache, File *file);
291
297 void clearFileCache(FileCache *cache = ZERO);
298
299 protected:
300
303
306
309
311 const char *m_mountPath;
312
315
318};
319
325#endif /* __LIB_LIBFS_FILESYSTEMSERVER_H */
u8 type
Definition IntelACPI.h:0
Template class which serves incoming messages from Channels using MessageHandlers.
Directory File functionality.
Definition Directory.h:60
Simple filesystem path parser.
Encapsulates a pending FileSystemMessage.
Abstract filesystem class.
FileCache * m_root
Root entry of the filesystem tree.
FileSystem::Result mount()
Mount the FileSystem.
FileCache * findFileCache(const char *path) const
Search the cache for an entry.
void setRoot(Directory *newRoot)
Change the filesystem root directory.
virtual bool retryRequests()
Retry any pending requests.
void sendResponse(FileSystemMessage *msg) const
Send response for a FileSystemMessage.
static const Size MaximumFileSystemMounts
Maximum number of supported file system mount entries.
FileSystem::Result waitFileHandler(FileSystemRequest &req)
Handle a WaitFile request.
HashTable< u32, File * > m_inodeMap
Contains a mapping of inode number to file of all cached files.
FileSystem::Result processRequest(FileSystemRequest &req)
Process a FileSystemRequest.
virtual ~FileSystemServer()
Destructor function.
static const Size MaximumWaitSetCount
Maximum number of WaitSet entries supported.
u32 getNextInode()
Get next unused inode.
FileSystem::Result inodeHandler(FileSystemRequest &req)
Handle a request for a File specified by its inode.
FileCache * lookupFile(const FileSystemPath &path)
Retrieve a File from storage.
FileSystem::Result unregisterFile(const char *path)
Remove a File from the FileSystemServer.
virtual File * createFile(const FileSystem::FileType type)
Create a new file.
const ProcessID m_pid
Process identifier.
void mountHandler(FileSystemMessage *msg)
Process a filesystem mount request message.
const char * getMountPath() const
Get mount path.
void clearFileCache(FileCache *cache=ZERO)
Cleans up the entire file cache (except opened file caches and root).
FileSystemMount * m_mounts
Table with mounted file systems (only used by the root file system).
FileSystem::Result registerDirectory(Directory *dir, const char *path)
Register a new Directory.
FileSystem::Result registerFile(File *file, const char *path)
Register a new File.
void removeFileFromCache(FileCache *cache, File *file)
Remove a File from the cache.
List< FileSystemRequest * > * m_requests
Contains ongoing requests.
bool redirectRequest(const char *path, FileSystemMessage *msg)
Try to forward the given FileSystemMessage to a mount file system.
void getFileSystemsHandler(FileSystemMessage *msg)
Read the file system mounts table.
void pathHandler(FileSystemMessage *msg)
Process an incoming filesystem request using a path.
const char * m_mountPath
Mount point path.
FileCache * insertFileCache(File *file, const char *pathFormat)
Inserts a file into the in-memory filesystem tree.
Directory * getParentDirectory(const char *path)
Retrieve parent Directory for a file.
Represents a file present on a FileSystem.
Definition File.h:40
Efficient key -> value lookups.
Definition HashTable.h:45
Simple linked list template class.
Definition List.h:37
Abstraction of strings.
Definition String.h:42
u32 ProcessID
Process Identification Number.
Definition Types.h:140
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
#define ZERO
Zero value.
Definition Macros.h:43
FileType
All possible filetypes.
Definition FileSystem.h:71
Result
Result code for filesystem Actions.
Definition FileSystem.h:53
Cached in-memory file.
Definition FileCache.h:36
FileSystem IPC message.
Represents a mounted filesystem.