Chapter 34
File System Reader: liboskit_fsread.a

34.1 Introduction

The fsread library provides simple read-only access to Linux ext2fs, BSD FFS, and MINIX filesystems and is useful for small programs, such as boot loaders, that need to read files from the local disk but don’t have the space for or need the features of the larger OSKit filesystem libraries.

Typically this library is used with the disk partitioning library (Section 33) and one of the driver libraries.

34.2 External dependencies

This depends on several memory and string routines from the OSKit C library, more specifically it depends on

34.3 Limitations

34.4 API reference

Each of these functions takes an oskit_blkio_t (Section 7.3) interface to the underlying device and a pathname relative to the root directory of the file system, and if the specified file can be found, returns an oskit_blkio_t object that can be used to read from that file. The blkio object returned will have a block size of 1, meaning that there are no alignment restrictions on file reads. The blkio object passed, representing the underlying device, can have a block size greater than 1, but if it is larger than the file system’s block size, file system interpretation will fail. Also, any absolute symlinks followed during the open will be interpreted as if this is the root file system.

34.4.1 fsread_open: Open a file on various filesystems

SYNOPSIS

#include <oskit/fs/read.h>

oskit_error_t fsread_open(oskit_blkio_t *device, const char *path, [out] oskit_blkio_t **out_file);

DESCRIPTION

Tries to open a file named by path in the filesystem on device. If successful, returns a blkio into out_file that can be used to read the file.

This function is just a wrapper that calls the various filesystem-specific fsread functions, failing if none of them recognize the filesystem.

PARAMETERS
device:
An oskit_blkio_t (Section 7.3) representing a device containing a filesystem.
path:
A pathname indicating an existing file to open. This pathname is taken relative to the root of the filesystem
out_file:
Upon success, this is set to an oskit_blkio_t that can be used to read from the file.
RETURNS

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

34.4.2 fsread_FSTYPE _open: Open a file on the FSTYPE filesystem

SYNOPSIS

#include <oskit/fs/read.h>

oskit_error_t fsread_FSTYPE_open(oskit_blkio_t *device, const char *path, [out] oskit_blkio_t **out_file);

DESCRIPTION

Tries to open a file named by path in the FSTYPE filesystem on device. If successful, returns a blkio into out_file that can be used to read the file.

FSTYPE can be one of ext2, ffs, minix.

PARAMETERS
device:
An oskit_blkio_t (Section 7.3) representing a device containing a FSTYPE filesystem.
path:
A pathname indicating an existing file to open. This pathname is taken relative to the root of the filesystem
out_file:
Upon success, this is set to an oskit_blkio_t that can be used to read from the file.
RETURNS

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