18#include <FreeNOS/User.h>
145 ERROR(
"failed to register directory " << path <<
146 ": result = " << (
int) result);
158 ERROR(
"failed to register '.' for directory " << path <<
159 ": result = " << (
int) result);
167 ERROR(
"failed to retrieve parent directory for " << path);
177 DEBUG(
"path = " << path);
210 Size savedMountLength = 0;
221 if (mountStrLen > savedMountLength && mountStr.
compareTo(path,
true, mountStrLen) == 0)
223 savedMountLength = mountStrLen;
313 ERROR(
"failed to read WaitSet input from PID " << msg->
from <<
": result = " << (
int) msg->
result);
322 for (
Size i = 0; i < count; i++)
331 DEBUG(
"inode " << waitBuf[i].inode <<
" is readable");
338 DEBUG(
"inode " << waitBuf[i].inode <<
" is writable");
349 ERROR(
"failed to write WaitSet output to PID " << msg->
from <<
": result = " << (
int) msg->
result);
406 ERROR(
"VMCopy failed: result = " << (
int)result <<
" from = " << msg->
from <<
407 " addr = " << (
void *) msg->
buffer <<
" action = " << (
int) msg->
action);
455 ERROR(
"VMCopy failed for FileStat: result = " << (
int) stResult <<
456 " from = " << msg->
from <<
" addr = " << (
void *) msg->
stat <<
457 " action = " << (
int) msg->
action);
496 ERROR(
"VMCopy failed of FileStat for PID " << msg->
from <<
": result = " << (
int) stResult);
521 ERROR(
"unhandled file I/O operation: " << (
int)msg->
action);
541 " for action = " << (
int) msg->
action <<
542 " with result = " << (
int) msg->
result);
547 ERROR(
"failed to retrieve channel for PID " << msg->
from);
554 ERROR(
"failed to write channel for PID " << msg->
from);
570 ERROR(
"failed to copy mount path: result = " << (
int) result);
584 if (path.equals(
entry))
616 const Size numBytes = msg->
size < mountsSize ? msg->
size : mountsSize;
621 ERROR(
"failed to copy mount table: result = " << (
int) result);
631 bool restartNeeded =
false;
642 restartNeeded =
true;
646 return restartNeeded;
701 if (!(file = dir->
lookup(*i.current())))
706 c =
new FileCache(file, *i.current(), c);
Result
Enumeration of generic kernel API result codes.
virtual bool contains(const K &key) const
Check if the given key exists.
ProcessID from
Source process of the message.
Type type
Message type is either a request or response.
Channel * getProducer(const ProcessID pid)
Get one producer.
Template class which serves incoming messages from Channels using MessageHandlers.
Timer::Info m_expiry
System timer expiration value.
ChannelRegistry & m_registry
Contains registered channels.
ProcessID m_self
ProcessID of ourselves.
void addIPCHandler(const Size slot, IPCHandlerFunction h, const bool sendReply=true)
Register a new IPC message action handler.
Unidirectional point-to-point messaging channel.
virtual Result write(const void *buffer)
Write a message.
Datastore::Result registerBuffer(const char *key, void *buffer, const Size size) const
Add a new buffer.
Directory File functionality.
virtual File * lookup(const char *name)
Retrieve a File from storage.
void insert(FileSystem::FileType type, const char *name)
Insert a new directory entry.
FileSystemClient provides a simple interface to a FileSystemServer.
FileSystem::Result mountFileSystem(const char *mountPath) const
Mount the current process as a file system on the rootfs.
Simple filesystem path parser.
const String & full() const
Get the full path as a String.
static const Size MaximumLength
Maximum length of a filesystem path in bytes.
const List< String > & split() const
Returns a List of separate path elements.
const String & parent() const
Retrieve the full path of our parent.
Size length() const
Get Length of our full path.
const String & base() const
The name of the last element in the path.
Encapsulates a pending FileSystemMessage.
IOBuffer & getBuffer()
Get IOBuffer.
FileSystemMessage * getMessage()
Get message.
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).
FileSystemServer(Directory *root, const char *path)
Constructor function.
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.
FileSystem::FileType getType() const
Retrieve our filetype.
u32 getInode() const
Get inode number.
virtual FileSystem::Result write(IOBuffer &buffer, Size &size, const Size offset)
Write bytes to the file.
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Read bytes from the file.
virtual FileSystem::Result status(FileSystem::FileStat &st)
Retrieve file statistics.
Iterate through a HashTable.
virtual const V value(const K &key, const V defaultValue=V()) const
Return the first value for the given key.
virtual int remove(const K &key)
Remove value(s) for the given key.
virtual const V * get(const K &key) const
Returns the first value for the given key.
virtual Size count() const
Get the number of values stored in the HashTable.
virtual bool insert(const K &key, const V &value)
Inserts the given item to the HashTable.
Abstract Input/Output buffer.
FileSystem::Result flushWrite()
Flush write buffers.
Size getCount() const
Get byte count.
FileSystem::Result read(void *buffer, const Size size, const Size offset=ZERO)
Read bytes from the I/O buffer.
FileSystem::Result write(const void *buffer, const Size size, const Size offset=ZERO)
Write bytes to the I/O buffer.
FileSystem::Result bufferedRead()
Buffered read bytes from the I/O buffer.
Provides the timer of the kernel.
virtual Result tick()
Process timer tick.
virtual bool hasCurrent() const
Check if there is a current item on the List.
Simple linked list template class.
void append(T t)
Insert an item at the end of the list.
static void * set(void *dest, int ch, unsigned count)
Fill memory with a constant byte.
static Size copy(void *dest, const void *src, Size count)
Copy memory from one place to another.
Size length() const
Same as count().
virtual int compareTo(const String &str) const
Compares this String to the given String.
bool isExpired(const Info &info) const
Check if a timer value is expired.
API::Result VMCopy(const ProcessID proc, const API::Operation how, const Address ours, const Address theirs, const Size sz)
Prototype for user applications.
API::Result ProcessCtl(const ProcessID proc, const ProcessOperation op, const Address addr=0, const Address output=0)
Prototype for user applications.
#define assert(exp)
Insert program diagnostics.
#define NULL
NULL means zero.
unsigned int u32
Unsigned 32-bit number.
unsigned long Address
A memory address.
#define ERROR(msg)
Output an error message.
#define NOTICE(msg)
Output a notice message.
unsigned int Size
Any sane size indicator cannot go negative.
#define DEBUG(msg)
Output a debug message to standard output.
FileType
All possible filetypes.
Result
Result code for filesystem Actions.
@ Writable
< File can be read without blocking
HashTable< String, FileCache * > entries
Contains childs.
FileCache * parent
Parent.
u32 inode
Inode number of the file.
Timer::Info timeout
Timeout value for the action.
char * buffer
Points to a buffer for I/O.
FileSystem::Result result
Result code.
FileSystem::Action action
Action to perform.
FileSystem::FileStat * stat
File Statistics.
Size pathMountLength
Length of the mounted path (used for redirection)
Size size
Size of the buffer.
ProcessID pid
Process identifier (used for redirection)
Size offset
Offset in the file for I/O.
Represents a mounted filesystem.
ProcessID procID
Server which is responsible for the mount.
ulong options
Mount options.
Contains file information.
ProcessID pid
< Inode number
Provides information about an inode.
u16 current
< Requested status flags of the inode