getmnt(2)
NAME
getmnt − get information about mounted file systems
SYNTAX
#include <sys/types.h>
#include <sys/param.h>
#include <sys/mount.h>
getmnt(start, buffer, nbytes, mode, path)
struct fs_data *buffer;
intnbytes, mode;
char *path;
DESCRIPTION
The getmnt system call retrieves information about mounted file systems.
The mode argument is one of the following: STAT_ONE, NOSTAT_ONE, STAT_MANY, or NOSTAT_MANY.
If mode is STAT_ONE or NOSTAT_ONE, then path is the name of a single file system for which information is desired, start and nbytes are ignored, and buffer is assumed to be large enough to hold one fs_data structure.
If mode is STAT_MANY or NOSTAT_MANY, then path is ignored. The start argument is the current logical location within the internal system mount table and must be initially set to 0. The start argument is updated to reflect the current logical location within the system mount table, allowing successive executions of getmnt to retrieve information about all the mounted file systems. The nbytes argument defines the size of buffer, into which the file system information is returned. Buffer sizes must be a multiple of sizeof(structfs_data) bytes. Larger buffer sizes allow information about multiple file systems to be returned.
If mode is NOSTAT_ONE or NOSTAT_MANY, then dynamic fs_data information (the number of free inodes and the number of free blocks) could be out of date, but these calls are guaranteed to return. The file system information in memory is not updated.
If mode is STAT_ONE or STAT_MANY, then the file system information in memory is updated. However, if the server of any file system for which information is being retrieved is down, then these calls will hang until the server responds.
When information about multiple file systems is returned, it is stored within consecutive buffer locations. The information for each file system is described by the structure fs_data:
struct fs_data {
structfs_data_reqfd_req;/* required data */
u_intfd_spare[113];/* spare */
};/* 2560 bytes */
struct fs_data_req { /* required part for all file systems */
u_intflags; /* how mounted */
u_intmtsize; /* max transfer size in bytes */
u_intotsize; /* optimal transfer size in bytes */
u_intbsize; /* fs block size in bytes for vm code */
u_intfstype; /* see ../h/fs_types.h */
u_intgtot; /* total number of gnodes */
u_intgfree; /* # of free gnodes */
u_intbtot; /* total number of 1K blocks */
u_intbfree; /* # of free 1K blocks */
u_intbfreen; /* user consumable 1K blocks */
u_intpgthresh; /* min size in bytes before paging*/
intuid; /* uid that mounted me */
dev_tdev; /* major/minor of fs */
dev_tpad; /* alignment: dev_t is a short*/
chardevname[MAXPATHLEN + 4]; /* name of dev */
charpath[MAXPATHLEN + 4]; /* name of mount point */
}
RETURN VALUE
Upon successful completion, a value indicating the number of fs_data structures stored in buffer is returned. If the file system is not mounted (mode is STAT_ONE or NOSTAT_ONE) or there are no more file systems in the mount table (mode is STAT_MANY or NOSTAT_MANY), 0 is returned. Otherwise, −1 is returned and the global variable errno is set to indicate the error.
DIAGNOSTICS
[ENOTDIR] A component of the path prefix of path is not a directory.
[EINVAL] Invalid argument.
[ENAMETOOLONG]
The length of a component of path exceeds 255 characters, or the length of path exceeds 1023 characters.
[ENOENT] The file referred to by path does not exist.
[EACCESS] Search permission is denied for a component of the path prefix of path.
[ELOOP] Too many symbolic links were encountered in translating path.
[EFAULT] Either buffer or start causes an illegal address to be referenced.
[EIO] An I/O error occurred while reading from the file system.
SEE ALSO
System Calls