The OSKit filesystem namespace COM interface provides “namei” style translation for the application, as well as high level mount and unmount capabilities. As noted in Section 9, all name parameters to OSKit directory methods must be a single component entry in one of the specified directories. That is, a name with no “slashes” in it. On the other hand, the POSIX library interface to the filesystem namespace is in terms of multi-component absolute and relative pathnames. In addition, since a filesystem namespace may consist of multiple independent filesystems in a hierarchy, the ability to compose filesystems into a larger namespace is also required. The OSKit filesystem namespace COM interface bridges this gap between the interfaces by providing pathname translation from multi-component names to OSKit directory and file objects. Also included is symbolic link translation, mount and umount operations, and mountpoint traversal.
Both single and multithreaded versions of the fsnamespace component are provided. Both of these libraries can be found in the lib directory as oskit_fsnamespace.a and oskit_fsnamespace_r.a. While pathname lookup is nominally thread safe, it should be noted that changing the root or current working directory, or mounting and unmounting filesystems in a multithreaded application should be done with extreme caution. Unmounting a filesystem while another thread is translating a pathname can lead to very odd situations!
A filesystem namespace object is created with the following interface function:
#include <oskit/fs/fsnamespace.h>
oskit_error_t oskit_create_fsnamespace(struct oskit_dir *rootdir, struct oskit_dir *cwd, oskit_fsnamespace_t **out_fsnamespace);
Create a new fileystem namespace object, with the given root and current working directories. Typically, this routine will be called when the client OS is initialized. Once the root filesystem has been opened, the client OS will call this routine to create a namespace object, specifying the root directory of the root filesystem as the root directory and current working directory of the new namespace. Subsequent pathname translation is then “rooted” at these locations.
Returns 0 on success, or an error code specified in <oskit/error.h>, on error.
The oskit_fsnamespace COM interface inherits from IUnknown, and has the following additional methods:
#include <oskit/fs/fsnamespace.h>
oskit_error_t oskit_fsnamespace_chroot(oskit_fsnamespace_t *f, const char *name);
Set the root directory for subsequent absolute pathname translation (lookup). By default, the root directory is established when the filesystem namespace object is created (oskit_create_fsnamespace), and is typically the root directory of the root filesystem. An application may then change the current root directory so that subsequent translation of pathnames starting with ’\’ start at the new directory.
Returns 0 on success, or an error code specified in <oskit/error.h>, on error.
#include <oskit/fs/fsnamespace.h>
oskit_error_t oskit_fsnamespace_chcwd(oskit_fsnamespace_t *f, oskit_dir_t *cwd);
Set the current working directory for subsequent relative pathname translation (lookup). By default, the current working directory is established when the filesystem namespace object is created (oskit_create_fsnamespace), and is typically the root directory of the root filesystem. An application may then change the current working directory so that subsequent translation of pathnames not starting with ’\’, start at the new directory.
Returns 0 on success, or an error code specified in <oskit/error.h>, on error.
#include <oskit/fs/fsnamespace.h>
oskit_error_t oskit_fsnamespace_lookup(oskit_fsnamespace_t *f, const char *pathname, int flags, [out] oskit_file_t **out_file);
Translate a multi component pathname (ie: one with slashes) into an oskit_file COM object. The root and current working directories for the pathname translation are a function of the filesystem namespace object (See the chroot and chcwd interface methods). Pathname lookup is subject to certain flags. They are:
Returns 0 on success, or an error code specified in <oskit/error.h>, on error.
#include <oskit/fs/fsnamespace.h>
oskit_error_t oskit_fsnamespace_mount(oskit_fsnamespace_t *f, const char *pathname, oskit_file_t *filesystem);
The mount method provides the BSD-like ability to compose a filesystem namespace out of individual filesystems. Since the underlying oskit_dir COM object does not support mountpoints, this capability must be provided at a higher level. The mount method requires a valid pathname (which must be a directory) in the current filesystem on which to mount the new filesystem. Subsequent pathname translation that crosses the pathname will instead be redirected into the new filesystem. For example, one could mount a BMOD filesystem (see Section 15.20) at an arbitrary point in a regular filesystem with the following code fragment:
|
Returns 0 on success, or an error code specified in <oskit/error.h>, on error.
#include <oskit/fs/fsnamespace.h>
oskit_error_t oskit_fsnamespace_unmount(oskit_fsnamespace_t *f, const char pathname);
Unmount the filesystem that was previously mounted over pathname with the mount method.
Returns 0 on success, or an error code specified in <oskit/error.h>, on error.
#include <oskit/fs/fsnamespace.h>
oskit_error_t oskit_fsnamespace_clone(oskit_fsnamespace_t *f, oskit_fsnamespace_t **out_fsnamespace);
Duplicate a filesystem namespace object. A new filesystem namespace object is created, with its own references to the root and current working directory. All other state contained within the namespace object is shared with the parent object. For example, the results of mounting and unmounting filesystem will be seen by both the parent and child objects. The only state that is local to the new object are the root and cwd directories.
Returns 0 on success, or an error code specified in <oskit/error.h>, on error.