Add Book to My BookshelfPurchase This Book Online

Appendix B - Accessing Filesystem Data Structures

UNIX Systems Programming for SVR4
David A. Curry
 Copyright © 1996 O'Reilly & Associates, Inc.

The Filesystem Defaults File
The file /etc/vfstab contains “default” information about filesystems. This information includes device names, mount points, mount options, and so forth. The table is used by the system bootstrap procedure to mount the filesystems that should be mounted automatically. It may also be used to record the location of other filesystems that are mounted only on command. A filesystem does not have to be listed in this file to be mounted; listing it here simply makes the mount command simpler.
On most other versions of UNIX, including HP-UX 10.x and IRIX 5.x, this file is called /etc/fstab, and has a slightly different format.
Each line in the file constitutes an entry, which is described by a structure of type struct vfstab, declared in the include file sys/vfstab.h:
    struct vfstab {
        char    *vfs_special;
        char    *vfs_fsckdev;
        char    *vfs_mountp;
        char    *vfs_fstype;
        char    *vfs_fsckpass;
        char    *vfs_automnt;
        char    *vfs_mntopts;
    };
The fields of the structure are:
vfs_special
The name of the block-special device on which the filesystem resides.
vfs_fsckdev
The name of the character-special device on which the filesystem resides. This field is so named because the fsck program uses this device to check the filesystem's integrity at boot time.
vfs_mountp
The name of the filesystem mount point; that is, the directory it is to be mounted on.
vfs_fstype
The type of the filesystem (e.g., ufs, nfs, hsfs, or pcfs).
vfs_fsckpass
When fsck runs, certain filesystems must be checked before others. This number indicates which pass of fsck should check this filesystem.
vfs_automnt
An indication of whether or not the filesystem should be mounted automatically when the system boots.
vfs_mntopts
The options that should be used when mounting this filesystem. These vary with the filesystem type.
Any of these fields that do not apply to the filesystem in question will be null.
Four functions read the /etc/vfstab file:
    #include <stdio.h>
    #include <sys/vfstab.h>
    int getvfsent(FILE *fp, struct vfstab *vfs);
    int getvfsfile(FILE *fp, struct vfstab *vfs, char *file);
    int getvfsspec(FILE *fp, struct vfstab *vfs, char *spec);
    int getvfsany(FILE *fp, struct vfstab *vfs, struct vfstab *vfsref);
The getvfsent function reads the next entry from the file referenced by fp, and stores the broken-out fields of the entry in the area pointed to by vfs. The getvfsfile function searches the file for an entry whose vfs_mountp field is the same as file and stores the broken-out fields of the entry in the area pointed to by vfs. The getvfsspec function searches the file for an entry whose vfs_special field is the same as spec and stores the broken-out fields of the entry in the area pointed to by vfs. The getvfsany function searches the file referenced by fp for an entry that matches the non-null fields of vfsref, and stores the broken-out fields of the entry in the area pointed to by vfs. Note that none of these functions opens, closes, or rewinds the /etc/vfstab file.
All four of these functions return 0 if an entry is successfully read, and -1 if end-of-file is encountered. If a formatting error occurs in the file, they return one of the following:
VFS_TOOLONG
A line in the file exceeded the maximum line length.
VFS_TOOMANY
A line in the file contains too many fields.
VFS_TOOFEW
A line in the file does not contain enough fields.

Previous SectionNext Section
Books24x7.com, Inc © 2000 –  Feedback