The Storage Kit Table of Contents | The Storage Kit Index

# File System Info C Functions

Declared in: be/kernel/fs_info.h

Library: libroot.so

From time to time, it can be useful to know certain information about the capabilities of the file system on a device. While the BVolume class provides you easy access to this information, it can occasionally be helpful to have more direct access to this information.

This section describes three C functions which can be used to obtain information about the file system on a device. One of these functions, `fs_stat_dev()`, returns this information given a device number. The other two functions, `dev_for_path()` and `next_dev()`, provide two ways to obtain a device number for use with `fs_stat_dev()`.

Note that these functions don't set `errno`.

## C Functions

### dev_for_path()

dev_t`dev_for_path(`const char *path`)`

Given a pathname, returns the device number of the device on which the path is located. If the result is negative, it is a return code specifying an error.

RETURN CODES

- `B_ENTRY_NOT_FOUND.,`path does not exist, or is `NULL` or an empty string.

- `B_BAD_VALUE`. path is null or an empty string.

- `B_NAME_TOO_LONG`. path is too long.

- `B_NO_MEMORY`. Insufficient memory to complete the operation.

- `B_FILE_ERROR`. A file system error prevented the operation from succeeding.

### next_dev()

dev_t `next_dev(`int32 *pos`)`

The `next_dev()` function allows you to iterate through all devices, receiving their device numbers as a result each time. If the result is negative, it is an error code. When the end of the device list is reached, the return value `B_BAD_VALUE` is returned.

You should initially set pos to 0, then call `next_dev()` in a loop to obtain each device number until an error occurs. For example:

       void ScanDevices(void) {
          int pos;

          pos = 0;
          while(next_dev(&pos) >=0) {
             do_something(pos);
          }
       }

RETURN CODES

- B_BAD_VALUE. No matching device found.

### fs_stat_dev()

int `fs_stat_dev(`dev_t dev, fs_info *info`)`
struct {} `fs_info`

`fs_stat_dev()` returns information about the specified device. This can be used in conjunction with `next_dev()` to scan all devices and record information your application requires.

This function returns 0 if the request was successful or -1 if an error occurred. Use the `errno()` function to determine what error in particular occurred.

The `fs_info` structure is defined as:

typedef struct `fs_info` { dev_t `dev`; ino_t `root`; uint32 `flags`; off_t `block_size`; off_t `io_size`; off_t `total_blocks`; off_t `free_blocks`; off_t `total_nodes`; off_t `free_nodes`; char `device_name`[128]; char `volume_name`[`B_FILE_NAME_LENGTH`]; char `fsh_name`[`B_OS_NAME_LENGTH`]; };

The structure's fields are:

- `dev`. The device number of the device.

- root. The inode of the root of the device.

- `flags`. Flags describing the device's capabilities.

- `block_size`. The fundamental block size of the device.

- `io_size`. Optimal I/O size of the device.

- `total_blocks`. The total number of blocks on the device.

- `free_blocks`. The number of free (unused) blocks on the device.

- `total_nodes`. The total number of nodes on the device.

- `free_nodes`. The number of free (unused) nodes on the device.

- `device_name`. Name of the device holding the file system.

- `volume_name`. Name of the volume contained by the device.

- `fsh_name`. Name of the file system handler for the device.

The `flags` can be any combination of the following values, which specify the attributes of the file system on the device:

- `B_FS_IS_READONLY`. The file system on the device is read-only.

- `B_FS_IS_REMOVABLE`. The device contains removable media.

- `B_FS_IS_PERSISTENT`. Data written to the device remains even while the device is off.

- `B_FS_IS_SHARED`. The file system is being shared on a network.

- `B_FS_HAS_MIME`. The file system supports the MIME typing system used by the BeOS.

- `B_FS_HAS_ATTR`. The file system supports node attributes.

- `B_FS_HAS_QUERY`. THe file system supports the BeOS query mechanism.

The information in the `fs_info` structure is guaranteed to be internally consistent, but the structure as a whole should be considered to be out-of-date as soon as you receive it. It provides a picture of a device as it exists just before the info-retrieving function returns. In particular, the number of free blocks and of free nodes can easily change immediately after you receive this information.

RETURN CODES

- `B_OK`. The device was found; info contains valid information.

- `B_BAD_VALUE`. dev doesn't identify an existing device.

The Storage Kit Table of Contents | The Storage Kit Index

The B e Book,
...in lovely HTML...
for BeOS Release 5.

Copyright © 2000 Be, Inc. All rights reserved..