Chapter Contents

Previous

Next
w_getmntent

w_getmntent



Get Mounted File System Information

Portability: SAS/C extension


SYNOPSIS
DESCRIPTION
RETURN VALUE
PORTABILITY
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

#include <sys/mntent.h>

int w_getmntent(void *sysInfo, int infoSize);


DESCRIPTION

w_getmntent gets information about the mounted file systems and saves that information in w_mntent structures, declared in <sys/mntent.h> . The arguments to w_getmntent are:

sysInfo
is a pointer to a buffer area used to save the file system information. The w_getmntent function copies a w_mntent structure into this area for each file system that is mounted.

infoSize
specifies the size of the sysInfo buffer area. If you are not sure of the required size, you can specify a 0 , which will cause the w_getmntent function to return the number of file systems without actually copying any w_mntent information.

The w_mntent structures contains entries that provide the following information:

mnt_fsname
is the name of a mounted file system. This name can be up to 45 characters in length and ends with a NULL character. You can use this name with the w_statfs function to obtain more information.

mnt_dir
is the null-terminated directory name for the mounted file system.

A w_mnth structure, which is also declared in <sys/mntent.h> , is stored at the beginning to the sysInfo buffer area, before any of the w_mntent structues. The w_mnth structure forms a buffer area header that contains positioning information that is used when multiple calls to w_getmntent are made to store information about several mounted file systems. The following w_mnth entries are used:

mnth_size
is the size in bytes of the buffer area.

mnth_cur
is the current position in the buffer area.

The positioning information should be initialized to 0 s and should not be changed between calls to the w_getmntent function. Subsequent calls to w_getmntent will append new w_mntent structures to the buffer area. A 0 is returned by w_getmntent after information about the last file system has been written to the buffer area.


RETURN VALUE

If successful, w_getmntent returns the number of w_mntent structures that have been copied to the buffer area. If infoSize was 0 , the total number of file systems is returned, but no data are copied. A -1 is returned if w_getmntent is unsuccessful.


PORTABILITY

The w_getmntent function may be useful in USS applications; however, it is not defined by the POSIX.1 standard and should not be used in portable applications.


EXAMPLE

The following example illustrates the use of w_getmntent to obtain information about a mounted file system:

#include <sys/types.h>
#include <sys/mntent.h>
#include <string.h>
#include <stdio.h>

#define MAX_FILE_SYS 10

main()
{
   int lastSys = 0, sysCount;

   struct {
      struct w_mnth header;
      struct w_mntent fileSysInfo[MAX_FILE_SYS];
   } bufferArea;

   memset(&bufferArea, 0, sizeof(bufferArea));

   do {
      lastSys = w_getmntent((char *)
                &bufferArea, sizeof(bufferArea));
      if (lastSys == -1)
         perror("Error during call to w_getmntent.");
      else {
         for (sysCount = 0; sysCount < lastSys; ++ sysCount) {
            printf("File System = %sn",
                  bufferArea.fileSysInfo[sysCount].mnt_fsname);
            printf("Mount Point = %snn",
                  bufferArea.fileSysInfo[sysCount].mnt_mountpoint);
          }
      }
   } while (lastSys < 0);
}


RELATED FUNCTIONS

mount , w_statfs


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.