Go to the documentation of this file.
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);
virtual FileSystem::Result write(IOBuffer &buffer, Size &size, const Size offset)
Write bytes to the file.
Unidirectional point-to-point messaging channel.
static Size copy(void *dest, const void *src, Size count)
Copy memory from one place to another.
FileSystem::Result flushWrite()
Flush write buffers.
Simple filesystem path parser.
IOBuffer & getBuffer()
Get IOBuffer.
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.
Result
Enumeration of generic kernel API result codes.
#define NOTICE(msg)
Output a notice message.
FileCache * findFileCache(const char *path) const
Search the cache for an entry.
void setRoot(Directory *newRoot)
Change the filesystem root directory.
Size length() const
Same as count().
static void * set(void *dest, int ch, unsigned count)
Fill memory with a constant byte.
Size getCount() const
Get byte count.
char * buffer
Points to a buffer for I/O.
u32 getNextInode()
Get next unused inode.
FileCache * parent
Parent.
HashTable< String, FileCache * > entries
Contains childs.
virtual File * lookup(const char *name)
Retrieve a File from storage.
FileType
All possible filetypes.
FileCache * lookupFile(const FileSystemPath &path)
Retrieve a File from storage.
Represents a mounted filesystem.
virtual bool retryRequests()
Retry any pending requests.
Directory File functionality.
FileSystemClient provides a simple interface to a FileSystemServer.
Iterate through a HashTable.
FileSystem::FileStat * stat
File Statistics.
const String & full() const
Get the full path as a String.
Provides information about an inode.
void insert(FileSystem::FileType type, const char *name)
Insert a new directory entry.
ChannelRegistry & m_registry
Contains registered channels.
Type type
Message type is either a request or response.
FileSystem::Result mountFileSystem(const char *mountPath) const
Mount the current process as a file system on the rootfs.
Provides the timer of the kernel.
void sendResponse(FileSystemMessage *msg) const
Send response for a FileSystemMessage.
FileSystem::Result unregisterFile(const char *path)
Remove a File from the FileSystemServer.
unsigned long Address
A memory address.
FileSystem::FileType getType() const
Retrieve our filetype.
Abstract filesystem class.
Size offset
Offset in the file for I/O.
API::Result ProcessCtl(const ProcessID proc, const ProcessOperation op, const Address addr=0, const Address output=0)
Prototype for user applications.
virtual int compareTo(const String &str) const
Compares this String to the given String.
FileSystem::Result result
Result code.
u32 getInode() const
Get inode number.
FileSystemMessage * getMessage()
Get message.
Represents a file present on a FileSystem.
const String & base() const
The name of the last element in the path.
struct FileSystemMount FileSystemMount
Represents a mounted filesystem.
virtual int remove(const K &key)
Remove value(s) for the given key.
u32 inode
Inode number of the file.
void removeFileFromCache(FileCache *cache, File *file)
Remove a File from the cache.
ProcessID m_self
ProcessID of ourselves.
void mountHandler(FileSystemMessage *msg)
Process a filesystem mount request message.
#define DEBUG(msg)
Output a debug message to standard output.
FileCache * insertFileCache(File *file, const char *pathFormat)
Inserts a file into the in-memory filesystem tree.
static const Size MaximumLength
Maximum length of a filesystem path in bytes.
Encapsulates a pending FileSystemMessage.
FileSystem::Result waitFileHandler(FileSystemRequest &req)
Handle a WaitFile request.
FileSystemMount * m_mounts
Table with mounted file systems (only used by the root file system).
virtual bool contains(const K &key) const
Check if the given key exists.
virtual Result write(const void *buffer)
Write a message.
virtual bool hasCurrent() const
Check if there is a current item on the List.
ulong options
Mount options.
virtual const V * get(const K &key) const
Returns the first value for the given key.
const List< String > & split() const
Returns a List of separate path elements.
FileSystemServer(Directory *root, const char *path)
Constructor function.
ProcessID procID
Server which is responsible for the mount.
void append(T t)
Insert an item at the end of the list.
HashTable< u32, File * > m_inodeMap
Contains a mapping of inode number to file of all cached files.
const char * m_mountPath
Mount point path.
void pathHandler(FileSystemMessage *msg)
Process an incoming filesystem request using a path.
Abstract Input/Output buffer.
virtual Size count() const
Get the number of values stored in the HashTable.
Datastore::Result registerBuffer(const char *key, void *buffer, const Size size) const
Add a new buffer.
#define NULL
NULL means zero.
unsigned int u32
Unsigned 32-bit number.
FileSystem::Result inodeHandler(FileSystemRequest &req)
Handle a request for a File specified by its inode.
unsigned int Size
Any sane size indicator cannot go negative.
virtual File * createFile(const FileSystem::FileType type)
Create a new file.
bool isExpired(const Info &info) const
Check if a timer value is expired.
Size length() const
Get Length of our full path.
FileSystem::Result processRequest(FileSystemRequest &req)
Process a FileSystemRequest.
FileSystem::Result registerDirectory(Directory *dir, const char *path)
Register a new Directory.
virtual FileSystem::Result status(FileSystem::FileStat &st)
Retrieve file statistics.
struct FileCache FileCache
Cached in-memory file.
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Read bytes from the file.
Template class which serves incoming messages from Channels using MessageHandlers.
FileSystem::Result mount()
Mount the FileSystem.
static const Size MaximumFileSystemMounts
Maximum number of supported file system mount entries.
const char * getMountPath() const
Get mount path.
u16 current
< Requested status flags of the inode
const ProcessID m_pid
Process identifier.
const String & parent() const
Retrieve the full path of our parent.
#define assert(exp)
Insert program diagnostics.
Contains file information.
#define ERROR(msg)
Output an error message.
virtual ~FileSystemServer()
Destructor function.
virtual Result tick()
Process timer tick.
Result
Result code for filesystem Actions.
Timer::Info m_expiry
System timer expiration value.
static const Size MaximumWaitSetCount
Maximum number of WaitSet entries supported.
ProcessID from
Source process of the message.
Size pathMountLength
Length of the mounted path (used for redirection)
ProcessID pid
Process identifier (used for redirection)
void addIPCHandler(const Size slot, IPCHandlerFunction h, const bool sendReply=true)
Register a new IPC message action handler.
FileSystem::Result bufferedRead()
Buffered read bytes from the I/O buffer.
FileSystem::Action action
Action to perform.
FileSystem::Result read(void *buffer, const Size size, const Size offset=ZERO)
Read bytes from the I/O buffer.
virtual bool hasCurrent() const
Check if there is a current item.
Simple linked list template class.
FileSystem::Result write(const void *buffer, const Size size, const Size offset=ZERO)
Write bytes to the I/O buffer.
Channel * getProducer(const ProcessID pid)
Get one producer.
API::Result VMCopy(const ProcessID proc, const API::Operation how, const Address ours, const Address theirs, const Size sz)
Prototype for user applications.
@ Writable
< File can be read without blocking
Timer::Info timeout
Timeout value for the action.
ProcessID pid
< Inode number
void clearFileCache(FileCache *cache=ZERO)
Cleans up the entire file cache (except opened file caches and root).
virtual bool insert(const K &key, const V &value)
Inserts the given item to the HashTable.
FileCache * m_root
Root entry of the filesystem tree.
virtual const V value(const K &key, const V defaultValue=V()) const
Return the first value for the given key.
Directory * getParentDirectory(const char *path)
Retrieve parent Directory for a file.
Size size
Size of the buffer.
void getFileSystemsHandler(FileSystemMessage *msg)
Read the file system mounts table.
FileSystem::Result registerFile(File *file, const char *path)
Register a new File.