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 
44 class 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 
81  u32 getNextInode();
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 
142  void pathHandler(FileSystemMessage *msg);
143 
149  void mountHandler(FileSystemMessage *msg);
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 */
HashTable< u32, File * >
FileSystemPath
Simple filesystem path parser.
Definition: FileSystemPath.h:37
FileSystem.h
Device.h
FileSystemServer::m_requests
List< FileSystemRequest * > * m_requests
Contains ongoing requests.
Definition: FileSystemServer.h:317
FileSystemServer::redirectRequest
bool redirectRequest(const char *path, FileSystemMessage *msg)
Try to forward the given FileSystemMessage to a mount file system.
Definition: FileSystemServer.cpp:208
FileSystemPath.h
Vector.h
FileSystemMount.h
FileSystemServer::findFileCache
FileCache * findFileCache(const char *path) const
Search the cache for an entry.
Definition: FileSystemServer.cpp:758
FileSystemServer::setRoot
void setRoot(Directory *newRoot)
Change the filesystem root directory.
Definition: FileSystemServer.cpp:649
FileSystemServer::getNextInode
u32 getNextInode()
Get next unused inode.
Definition: FileSystemServer.cpp:66
FileSystem::FileType
FileType
All possible filetypes.
Definition: FileSystem.h:70
FileSystemServer::lookupFile
FileCache * lookupFile(const FileSystemPath &path)
Retrieve a File from storage.
Definition: FileSystemServer.cpp:680
FileCache.h
FileSystemMount
Represents a mounted filesystem.
Definition: FileSystemMount.h:35
FileSystemServer::retryRequests
virtual bool retryRequests()
Retry any pending requests.
Definition: FileSystemServer.cpp:629
String
Abstraction of strings.
Definition: String.h:41
Directory
Directory File functionality.
Definition: Directory.h:59
ProcessID
u32 ProcessID
Process Identification Number.
Definition: Types.h:140
FileSystemServer::sendResponse
void sendResponse(FileSystemMessage *msg) const
Send response for a FileSystemMessage.
Definition: FileSystemServer.cpp:536
FileSystemServer::unregisterFile
FileSystem::Result unregisterFile(const char *path)
Remove a File from the FileSystemServer.
Definition: FileSystemServer.cpp:175
FileSystemMessage
FileSystem IPC message.
Definition: FileSystemMessage.h:37
FileSystemServer
Abstract filesystem class.
Definition: FileSystemServer.h:44
File
Represents a file present on a FileSystem.
Definition: File.h:39
FileSystemServer::removeFileFromCache
void removeFileFromCache(FileCache *cache, File *file)
Remove a File from the cache.
Definition: FileSystemServer.cpp:794
FileSystemServer::mountHandler
void mountHandler(FileSystemMessage *msg)
Process a filesystem mount request message.
Definition: FileSystemServer.cpp:561
FileSystemServer::insertFileCache
FileCache * insertFileCache(File *file, const char *pathFormat)
Inserts a file into the in-memory filesystem tree.
Definition: FileSystemServer.cpp:731
FileSystemRequest
Encapsulates a pending FileSystemMessage.
Definition: FileSystemRequest.h:35
FileSystemServer::waitFileHandler
FileSystem::Result waitFileHandler(FileSystemRequest &req)
Handle a WaitFile request.
Definition: FileSystemServer.cpp:301
FileSystemServer::m_mounts
FileSystemMount * m_mounts
Table with mounted file systems (only used by the root file system).
Definition: FileSystemServer.h:314
FileSystemServer::FileSystemServer
FileSystemServer(Directory *root, const char *path)
Constructor function.
Definition: FileSystemServer.cpp:29
FileSystemServer::m_inodeMap
HashTable< u32, File * > m_inodeMap
Contains a mapping of inode number to file of all cached files.
Definition: FileSystemServer.h:308
FileSystemServer::m_mountPath
const char * m_mountPath
Mount point path.
Definition: FileSystemServer.h:311
FileSystemServer::pathHandler
void pathHandler(FileSystemMessage *msg)
Process an incoming filesystem request using a path.
Definition: FileSystemServer.cpp:194
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
FileSystemServer::inodeHandler
FileSystem::Result inodeHandler(FileSystemRequest &req)
Handle a request for a File specified by its inode.
Definition: FileSystemServer.cpp:246
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
FileSystemServer::createFile
virtual File * createFile(const FileSystem::FileType type)
Create a new file.
Definition: FileSystemServer.cpp:110
FileSystemServer::processRequest
FileSystem::Result processRequest(FileSystemRequest &req)
Process a FileSystemRequest.
Definition: FileSystemServer.cpp:383
FileSystemServer::registerDirectory
FileSystem::Result registerDirectory(Directory *dir, const char *path)
Register a new Directory.
Definition: FileSystemServer.cpp:138
ChannelServer
Template class which serves incoming messages from Channels using MessageHandlers.
Definition: ChannelServer.h:79
FileSystemServer::mount
FileSystem::Result mount()
Mount the FileSystem.
Definition: FileSystemServer.cpp:77
FileSystemServer::MaximumFileSystemMounts
static const Size MaximumFileSystemMounts
Maximum number of supported file system mount entries.
Definition: FileSystemServer.h:49
FileSystemServer::getMountPath
const char * getMountPath() const
Get mount path.
Definition: FileSystemServer.cpp:61
FileSystemServer::m_pid
const ProcessID m_pid
Process identifier.
Definition: FileSystemServer.h:302
FileSystemServer::~FileSystemServer
virtual ~FileSystemServer()
Destructor function.
Definition: FileSystemServer.cpp:51
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
FileSystemServer::MaximumWaitSetCount
static const Size MaximumWaitSetCount
Maximum number of WaitSet entries supported.
Definition: FileSystemServer.h:52
Directory.h
List< FileSystemRequest * >
ChannelServer.h
type
u8 type
Definition: IntelACPI.h:63
FileCache
Cached in-memory file.
Definition: FileCache.h:35
ZERO
#define ZERO
Zero value.
Definition: Macros.h:43
FileSystemRequest.h
FileSystemServer::clearFileCache
void clearFileCache(FileCache *cache=ZERO)
Cleans up the entire file cache (except opened file caches and root).
Definition: FileSystemServer.cpp:813
File.h
FileSystemMessage.h
FileSystemServer::m_root
FileCache * m_root
Root entry of the filesystem tree.
Definition: FileSystemServer.h:305
FileSystemServer::getParentDirectory
Directory * getParentDirectory(const char *path)
Retrieve parent Directory for a file.
Definition: FileSystemServer.cpp:659
FileSystemServer::getFileSystemsHandler
void getFileSystemsHandler(FileSystemMessage *msg)
Read the file system mounts table.
Definition: FileSystemServer.cpp:612
FileSystemServer::registerFile
FileSystem::Result registerFile(File *file, const char *path)
Register a new File.
Definition: FileSystemServer.cpp:115