1 1 . 1
T H E P O S I X A P I A N D C E X T E N S I O N S
189
there was not sufficient motivation to do so. The C interface to queries was
written to support primitive test applications during the debugging phase (be-
fore the C++ API was coded) and to allow access to extended BFS features from
C programs. Further work to make the C interface to queries more useful will
probably be done in the future.
Volume Functions
This final group of C language interfaces provides a way to find out the
device-id of a file, iterate over the list of available device-ids, and obtain in-
formation about the volume represented by a device-id. The three functions
are
dev_t dev_for_path(char *path);
int
fs_stat_dev(dev_t dev, fs_info *info);
dev_t next_dev(int32 *pos);
The first function,
dev for path()
, returns the device-id of the volume that
contains the file referred to by
path
. There is nothing special about this call;
it is just a convenience call that is a wrapper around the POSIX function
stat()
.
The
fs stat dev()
function returns information about the volume identi-
fied by the device-id specified. The information returned is similar to a stat
structure but contains fields such as the total number of blocks of the device,
how many are used, the type of file system on the volume, and flags indicat-
ing what features the file system supports (queries, indices, attributes, etc.).
This is the function used to get the information printed by a command-line
tool like
df
.
The
next dev()
function allows a program to iterate over all device-ids.
The
pos
argument is a pointer to an integer, which should be initialized to
zero before the first call to
next dev()
. When there are no more device-ids
to return,
next dev()
returns an error code. Using this routine, it is easy
to iterate over all the mounted volumes, get their device-ids, and then do
something for or with that volume (e.g., perform a query, get the volume info
of the volume, etc.).
POSIX API and C Summary
The C APIs provided by the BeOS cover all the standard POSIX file I/O, and
the extensions have a very POSIX-ish feel to them. The desire to keep the
API familiar drove the design of the extension APIs. The functions provided
allow C programs to access most of the features provided by the BeOS with a
minimum of fuss.
Practical File System Design:The Be File System
, Dominic Giampaolo
page 189