Chapter 23
Filesystem Namespace: liboskit_fsnamespace.a

23.1 Introduction

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:

23.1.1 oskit_create_fsnamespace: Create a filesystem namespace object

SYNOPSIS

#include <oskit/fs/fsnamespace.h>

oskit_error_t oskit_create_fsnamespace(struct oskit_dir *rootdir, struct oskit_dir *cwd, oskit_fsnamespace_t **out_fsnamespace);

DESCRIPTION

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.

PARAMETERS
rootdir:
The OSKit oskit_dir of the initial root directory.
cwd:
The OSKit oskit_dir of the initial current working directory.
out_fsnamespace:
The oskit_fsnamespace COM interface for the new object.
RETURNS

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:

chroot:
Set the root directory for subsequent absolute path translation.
chcwd:
Set the current working directory for subsequent relative path translation.
lookup:
Convert a multi component pathname into a file or directory object.
mount:
Mount a filesystem at a given point in the namespace.
unmount:
Unmount a filesystem from the namespace.
clone:
Make a duplicate copy of a filesystem namespace object.

23.1.2 chroot: Set the root directory for absolute pathname translation

SYNOPSIS

#include <oskit/fs/fsnamespace.h>

oskit_error_t oskit_fsnamespace_chroot(oskit_fsnamespace_t *f, const char *name);

DESCRIPTION

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.

PARAMETERS
f :
The OSKit filesysem namespace interface object.
name:
The pathname of the new root directory.
RETURNS

Returns 0 on success, or an error code specified in <oskit/error.h>, on error.

23.1.3 chcwd: Set the current directory for relative pathname translation

SYNOPSIS

#include <oskit/fs/fsnamespace.h>

oskit_error_t oskit_fsnamespace_chcwd(oskit_fsnamespace_t *f, oskit_dir_t *cwd);

DESCRIPTION

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.

PARAMETERS
f :
The OSKit filesysem namespace interface object.
cwd:
The directory object of the new current directory.
RETURNS

Returns 0 on success, or an error code specified in <oskit/error.h>, on error.

23.1.4 lookup: Translate a multi component path to a directory or file object

SYNOPSIS

#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);

DESCRIPTION

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:

FSLOOKUP_FOLLOW:
Follow symlinks when translating the final component of a pathname. This is the default operation. Note that when translating symlinks, the “last” component refers to whatever the current last component is. If the last component is a multi componet symlink, that new path will be followed until its last component. If the new last component is again a symlink, it will be followed (or not followed) according to the same flag.
FSLOOKUP_NOFOLLOW:
Do not follow symlinks when translating the final component of a pathname. Instead, return the oskit_file COM object of the symlink itself. For example, the lstat system call uses this option to that it can operate on the symlink itself, rather than the target of the symlink.
FSLOOKUP_PARENT:
Instead of returning the oskit_file COM object of the translated pathname, return the COM object of the parent directory instead. The translation is subject to the same rules as any other translation; the file in question must exist in order to return its parent.
PARAMETERS
f :
The OSKit filesysem namespace interface object.
pathname:
The pathname to be translated.
flags:
Flags to modify the translation operation.
out_file:
The oskit_file COM interface for the file.
RETURNS

Returns 0 on success, or an error code specified in <oskit/error.h>, on error.

23.1.5 mount: Mount a filesystem at a given point in the namespace

SYNOPSIS

#include <oskit/fs/fsnamespace.h>

oskit_error_t oskit_fsnamespace_mount(oskit_fsnamespace_t *f, const char *pathname, oskit_file_t *filesystem);

DESCRIPTION

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:

         oskit_fsnamespace_mount(fsn, "/bmod",
                                 (oskit_file_t *) start_bmod());
         
PARAMETERS
f :
The OSKit filesysem namespace interface object.
pathname:
The pathname of the directory to mount over.
filesystem:
The oskit_file COM interface for the mounted subtree.
RETURNS

Returns 0 on success, or an error code specified in <oskit/error.h>, on error.

23.1.6 unmount: Unmount a filesystem from the filesystem namespace

SYNOPSIS

#include <oskit/fs/fsnamespace.h>

oskit_error_t oskit_fsnamespace_unmount(oskit_fsnamespace_t *f, const char pathname);

DESCRIPTION

Unmount the filesystem that was previously mounted over pathname with the mount method.

PARAMETERS
f :
The OSKit filesysem namespace interface object.
mountname:
The pathname of the directory to unmount.
RETURNS

Returns 0 on success, or an error code specified in <oskit/error.h>, on error.

23.1.7 clone: Duplicate a filesystem namespace object

SYNOPSIS

#include <oskit/fs/fsnamespace.h>

oskit_error_t oskit_fsnamespace_clone(oskit_fsnamespace_t *f, oskit_fsnamespace_t **out_fsnamespace);

DESCRIPTION

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.

PARAMETERS
f :
The OSKit filesysem namespace interface object.
out_fsnamespace:
The oskit_fsnamespace COM interface for the new copy.
RETURNS

Returns 0 on success, or an error code specified in <oskit/error.h>, on error.