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


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


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:

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

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


The Storage Kit Table of Contents     The Storage Kit Index


The Be Book,
...in lovely HTML...
for BeOS Release 5.

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