w_getmntent() — Get information on mounted file systems

Standards

Standards / Extensions C or C++ Dependencies
z/OS® UNIX both  

Format

#define _OPEN_SYS
#include <sys/mntent.h>

int w_getmntent(char *buffer, int size);

General description

Gets information about all currently mounted file systems.

buffer
A pointer to storage that is to be filled with the retrieved information. The storage consists of a header and an entry table that correspond to one of the available mapping formats. The mappings available are defined in the <sys/mntent.h> header file. Each entry in the entry table contains information for a single mounted file system.
size
The length of the buffer. If size is zero, the total number of mount entries is returned. You can use this information to obtain a buffer large enough to hold all the information about all the entries. Use the new buffer on the subsequent call.

Three mapping formats available. Their corresponding headers are as follows:

  Header Eye Catcher Entry
struct mnte3 MNTE3H (struct mnte3h) MNTE3H_ID ("MNT3") W_MNTENT3 (struct w_mntent3)
struct mnte2 MNTE2H (struct mnte2h) MNTE2H_ID ("MNT2") W_MNTENT2 (struct w_mntent2)
struct mnte W_MNTH (struct w_mnth) "MNTE" W_MNTENT (struct w_mntent)

The buffer should be set to zero before setting of fields or the w_getmntent() call. The default mapping format is struct mnte when the eyecatcher field is unset.

Using structure w_mntent3: Before calling w_getmntent() with the w_mntent3 structure mapping, set the following fields in MNTE3H:

  1. mnt3H_cbid eyecatcher to MNTE3H_ID
  2. mnt3H_cblen to the size of struct mnte3
  3. mnt3H_bodylen to the size of struct w_mntent3
  4. [Optional] mh3_devno to the device number

In the header, the field mnt3H_cblen returns the number of bytes of data that is put in the buffer. The field mh3_cursor contains positioning information that w_getmntent() uses to store the information. If multiple calls are made, use the same buffer because the positioning information in mh3_cursor indicates where the function should continue with its list. The positioning information should not be changed between calls. Information about a specific file system can be obtained if the device number of that file system is known. In this case, the device number can be filled into the field mh3_devno, and the w_getmntent call returns a single entry with information about that file system. Or a device number value of x40000000 can be used to indicate that the returned path name should be up to 64 bytes of the mount point path name at the time of the mount.

After a successful call to w_getmntent(), the following w_mntent3 structure fields will be available for reference:
mnt3_fstype
The file system type.
mnt3_mode

The mount mode of the file system. A flag field that specifies the mount mode and more mount options: mntentfsaunmount.

mntentfsaunmount
If it is 1 after the file system is mounted, the file system will be unmounted when a system leaves the sysplex. If it is 0, then the setting of mntentfsnoautomove is used. See mntentfsnoautomove below.
mntentfsclient
If it is 0, then the file system is a sysplex client. If it is 1, then the file system is not a sysplex client.
mntentfsnoautomove
If it is 0 after the file system is mounted, it can be moved automatically. If it is 1 after the file system is mounted, it will not be moved automatically.
mntentfsmodenosec
If it is 1, then the file system will not enforce security checks. If it is 0, then the file system will enforce security checks.
mntentfsmodeexport
If it is 0, then the file system has not been exported by DFS. If it is 1, then the file system has been exported by DFS.
mntentfsmoderdonly
If it is 0, then the file system is mounted as read/write. If it is 1, then the file system is mounted as read-only.
mntentfsmodenosuid
If it is 1, then the SETUID and SETGID mode flags will be ignored for programs that reside in this file system. If it is 0 then the SETUID and SETGID mode flags will be enforced for programs that reside in this file system.
mnt3_dev
Device number which stat() will return for all files in this file system.
mnt3_parentdev
st_dev of parent file system.
mnt3_rootino
The ino of the mount point.
mnt3_status
The status of the file system
mnt3_ddname
The ddname specified on mount.
mnt3_fstname
The name of the file system type that is specified by the FILESYS statement. The name for the file system that performed the mount.
mnt3_fsname
The name of the file system that was mounted.
mnt3_pathlen
The length of mount point path.
mnt3_mountpoint
The name of the directory where the file system is mounted.
mnt3_jobname
If this file system is quiesced, this is the job that made the request.
mnt3_PID
If this file system is quiesced, this is the PID that made the request.
mnt3_parmoffset
Offset of mount parameter parm_point, starting from the address of the mnt3_fstype member of the w_mnte3 struct.
mnt3_parmlen
The length of the mount parameter parm_point.
mnt3_sysname
The name of the target system.
mnt3_qsystem
The name of the quiesce system.
mnt3_fromsys
The name of the system from which the file system has moved.
mnt3_flags
The field containing the request flags.
mnt3_status2
The file system status extensions.
mnt3_readct
The number of reads done.
mnt3_writect
The number of writes done.
mnt3_diribc
The number of directory I/O blocks.
mnt3_readibc
The number of read I/O blocks.
mnt3_writeibc
The number of write I/O blocks.
mnt3_bytesreadhw
Total number of bytes read from high word.
mnt3_bytesreadlw
Total number of bytes read from low word.
mnt3_byteswrittenhw
Total number of bytes written to high word.
mnt3_byteswrittenlw
Total number of bytes written to low word.
mnt3_filetag
Mount tag.
mnt3_syslistoffset
Offset of system list.
mnt3_syslistlength
Length of system list.
mnt3_aggnamelength
Length of the aggregate name in mnt2_aggname. The length does not include the null terminating character, and is only valid if mnt3_aggnameoffset has a nonzero value.
mnt3_aggnameoffset
The offset of mnt2_aggname from w_mntent3. If the value is zero, then no aggregate name is returned.
mnt3_mntsec
The mount time in seconds when the file system was mounted.
mnt3_fstoken
This field is a virtual file system pointer for the file system.
mnt3_pfsnormalstatusoffset
This field provides the offset of the physical file system normal status string location.
mnt3_pfsnormalstatuslength
This field provides the length of the physical file system normal status string.
mnt3_pfsexcpstatuslength
This field provides the length of the exception status string of the physical file system.
mnt3_pfsexcptstatusoffset
This field provides the offset of the exception status string of the physical file system.
mnt3_fsusrmntUID
The effective UID (EUID) of the user that mounted the file system.
mnt3_unmntver

If this field is 1, the file system is automatically unmounted when no longer being used as a version file system. If this field is 0, the file system is not automatically unmounted when no longer being used as a version file system.

parm_point
This field contains the mount point parameters to be used when mounting a file system. It is a separate field in the mnte3 structure but contiguously allocated following the w_mnte3 body, its address is the sum of the address of w_mnte3 and mnt3_parmoffset.

If all entries do not fit in the buffer that is supplied, multiple calls are required. If an entry together with its mount parameter will not fit in the buffer, the entry is returned without the mount parameter. In this case, mnt3_parmlen contains the length of the mount parameter, and mnt3_parmoffset is zero.

To assure that at least one entry, including the mount parameter, is returned, it is advisable to allocate space for at least two entries.

When the final entry has been placed in the buffer, w_getmntent() returns no entries.

Using structure w_mntent2: Before calling w_getmntent() with the w_mntent2 structure mapping, set the following fields in MNTE2H:
  1. mh2_hdr.mnth2_cbid eyecatcher to MNTE2H_ID
  2. mh2_hdr.mnt2h_cblen to the size of struct mnte2
  3. mh_bodylen to the size of struct w_mntent2
  4. [Optional] mh2_devno to the device number

In the header, the field mnt2h_cblen returns the number of bytes of data that is put in the buffer. The field mh2_cursor contains positioning information that w_getmntent() uses to store the information. If multiple calls are made, use the same buffer because the positioning information in mh2_cursor indicates where the function should continue with its list. The positioning information should not be changed between calls. Information about a specific file system can be obtained if the device number of that file system is known. In this case, the device number can be filled into the field mh2_devno, and the w_getmntent call returns a single entry with information about that file system. Or a device number value of x40000000 can be used to indicate that the returned path name should be up to 64 bytes of the mount point path name at the time of the mount.

After a successful call to w_getmntent(), the following w_mntent2 structure fields will be available for reference:
mnt2_fstype
The file system type.
mnt2_mode

The mount mode of the file system. A flag field that specifies the mount mode and additional mount options:

mntentfsaunmount
If it is 1 after the file system is mounted, the file system will be unmounted when a system leaves the sysplex. If it is 0, then the setting of mntentfsnoautomove is used. See mntentfsnoautomove below.
mntentfsclient
If it is 0, then the file system is a sysplex client. If it is 1, then the file system is not a sysplex client.
mntentfsnoautomove
If it is 0 after the file system is mounted, it can be moved automatically. If it is 1 after the file system is mounted, it will not be moved automatically.
mntentfsmodenosec
If it is 1, then the file system will not enforce security checks. If it is 0, then the file system will enforce security checks.
mntentfsmodeexport
If it is 0, then the file system has not been exported by DFS. If it is 1, then the file system has been exported by DFS.
mntentfsmoderdonly
If it is 0, then the file system is mounted as read/write. If it is 1, then the file system is mounted as read-only.
mntentfsmodenosuid
If it is 1, then the SETUID and SETGID mode flags will be ignored for programs that reside in this file system. If it is 0 then the SETUID and SETGID mode flags will be enforced for programs that reside in this file system.
mnt2_dev
Device # which stat() returns for all files in this file system.
mnt2_parentdev
st_dev of parent file system.
mnt2_rootino
The ino of the mount point.
mnt2_status
status of the file system.
mnt2_ddname
The ddname that is specified on mount.
mnt2_fstname
The name of the file system type that is specified by the FILESYS statement. The name for the file system that performed the mount.
mnt2_fsname
The name of the file system that was mounted.
mnt2_pathlen
The length of mount point path.
mnt2_mountpoint
The name of the directory where the file system is mounted.
mnt2_jobname
If this file system is quiesced, this is the job that made the request.
mnt2_PID
If this file system is quiesced, this is the PID that made the request.
mnt2_parmoffset
Offset of mount parameter parm_point, starting from the address of the mnt2_fstype member of the w_mnte2 struct.
mnt2_parmlen
The length of the mount parameter parm_point.
mnt2_sysname
The name of the target system.
mnt2_qsystem
The name of the quiesce system.
mnt2_fromsys
The name of the system from which the file system has moved.
mnt2_flags
The field containing the request flags.
mnt2_status2
The file system status extensions.
mnt2_success
This field is used to return the number of successfully moved file systems when moving a collection of file systems.
mnt2_readct
The number of reads done.
mnt2_writect
The number of writes done.
mnt2_diribc
The number of directory I/O blocks.
mnt2_readibc
The number of read I/O blocks.
mnt2_writeibc
The number of write I/O blocks.
mnt2_bytesreadhw
Total number of bytes read from high word.
mnt2_bytesreadlw
Total number of bytes read from low word.
mnt2_byteswrittenhw
Total number of bytes written to high word.
mnt2_byteswrittenlw
Total number of bytes written to low word.
mnt2_filetag
Mount tag.
mnt2_syslistoffset
Offset of system list.
mnt2_syslistlength
Length of system list.
mnt2_aggnamelength
Length of the aggregate name in mnt2_aggname. The length does not include the null terminating character, and is only valid if mnt2_aggnameoffset has a nonzero value.
mnt2_aggnameoffset
The offset of mnt2_aggname from w_mntent2. If the value is zero, then no aggregate name is returned.
parm_point
This field contains the mountpoint parameters to be used when mounting a file system. It is a separate field in the mnte2 structure but contiguously allocated following the w_mnte2 body, its address is the sum of the address of w_mnte2 and mnt2_parmoffset.

If all entries do not fit in the buffer that is supplied, multiple calls are required. If an entry together with its mount parameter will not fit in the buffer, the entry is returned without the mount parameter. In this case, mnt2_parmlen contains the length of the mount parameter, and mnt2_parmoffset is zero.

To assure that at least one entry, including the mount parameter, is returned, it is advisable to allocate space for at least two entries.

When the final entry has been placed in the buffer, w_getmntent() returns no entries.

Using structure w_mntent: Before calling w_getmntent() with the w_mntent structure mapping, set the following fields in W_MNTH:
  1. mnth_hid eyecather to "MNTE"
  2. mnth_size to the size of struct mnte
  3. mh_bodylen to the size of struct w_mntent
  4. [Optional] mnth_devno to the device number

In the header, the field mnth_size returns the number of bytes of data that is put in the buffer. The fields mnth_cur1 and mnth_cur2 contain positioning information that w_getmntent() uses to store the information. If multiple calls are made, use the same buffer because the positioning information in mnth_cur1 and mnth_cur2 indicates where the function should continue with its list. The positioning information should not be changed between calls. Information about a specific file system can be obtained if the device number of that file system is known. In this case, the device number can be filled into the field mnth_devno, and the w_getmntent call returns a single entry with information about that file system. Or a device number value of x40000000 can be used to indicate that the returned path name should be up to 64 bytes of the mount point path name at the time of the mount.

After a successful call to w_getmntent(), the following w_mntent structure fields will be available for reference:
mnt_fstype
The file system type.
mnt_mode
File system mount mode.
mnt_dev
Device # which stat() returns for all files in this file system.
mnt_parentdev
st_dev of parent file system.
mnt_rootino
The ino of the mount point.
mnt_status
The status of the file system.
mnt_ddname
The ddname that is specified on mount.
mnt_fstname
The name of the file system type that is specified by the FILESYS statement.
mnt_fsname
The file system name, which is up to 45 characters long and ends with a NULL.
mnt_pathlen
The length of mount point path.
mnt_mountpoint

The pathname of the directory where the file system is mounted. This field ends with a NULL.

If the caller of w_getmntent() lacks search authorization to one or more of the directories in the mount point pathname, mnt_mountpoint is returned empty. That is, mnt_pathlen is zero and mnt_mountpoint contains a NULL as the first character.

mnt_jobname
If the file system is quiesced, this is the job that made the request.
mnt_PID
If the file system is quiesced, this is the PID that made the request.
mnt_parmoffset
Offset of mount parameter from w_mntent.
mnt_parmlen
Length of mount parameter.
mnt_parm

The file-system-specific parameter that is specified on the mount() function when the file system was mounted. This field ends with a NULL.

If no parameter was specified, mnt_parmlen and mnt_parmoffset are each zero. If a parameter was specified, its address is the sum of the address of w_mntent and mnt_parmoffset.

If all entries do not fit in the buffer that is supplied, multiple calls are required. If an entry together with its mount parameter will not fit in the buffer, the entry is returned without the mount parameter. In this case, mnt_parmlen contains the length of the mount parameter, and mnt_parmoffset is zero.

To assure that at least one entry, including the mount parameter, is returned, it is advisable to allocate space for at least two entries.

When the final entry has been placed in the buffer, w_getmntent() returns no entries.

Returned value

If successful, w_getmntent() returns the number of entries in the buffer.

If unsuccessful, w_getmntent() returns -1 and sets errno to one of the following values:
Error Code
Description
EINVAL
A parameter was specified incorrectly.
ERANGE
The result is too large to fit in the available buffer space.

Example

CELEBW49
/* CELEBW49

   This example uses w_getmntent() to retrieve information 
   about currently mounted systems in the MNTE3 mapping format.

   The MNTE3 mapping format is only available on z/OS V1.10 or higher,
   target value of 0x410A0000.

*/
#define _OPEN_SYS
#include <sys/mntent.h>
#include <stdio.h>

main() {
  int entries, entry;
  struct {
    MNTE3H   header;
    W_MNTENT3 mount_table[10];
  } work_area;

  memset(&work_area, 0x00, sizeof(work_area));

  /* 'header' initialization to specify MNTE3 mapping format */
  memcpy(work_area.header.mnt3H_cbid, MNTE3H_ID, 4);
  work_area.header.mnt3H_cblen = sizeof(struct mnte3);
  work_area.header.mnt3H_bodylen = sizeof(struct w_mntent3);

  do {
    if ((entries = w_getmntent((char *) &work_area,
                               sizeof(work_area))) == -1)
      perror("w_getmntent() error");

    else for (entry=0; entry<entries; entry++) {
      printf("filesystem %s is mounted at %s\n",
             work_area.mount_table[entry].mnt3_fsname,
             work_area.mount_table[entry].mnt3_mountpoint);
      printf("  MNTE2 and MNTE3 common: reads done is %i, writes done is %i\n",
             work_area.mount_table[entry].mnt3_readct,
             work_area.mount_table[entry].mnt3_writect);
      printf("  MNTE3 specific: mount time in seconds is %i\n",
             work_area.mount_table[entry].mnt3_mntsec);
    }
  } while (entries > 0);
}
Output
filesystem ZOS110.LPP.HFS is mounted at /usr/lpp
  MNTE2 and MNTE3 common: reads done is 0, writes done is 0
  MNTE3 specific: mount time in seconds is 5833
filesystem ZOS110.NLS.HFS is mounted at /usr/lib/nls
  MNTE2 and MNTE3 common: reads done is 0, writes done is 0
  MNTE3 specific: mount time in seconds is 5833
filesystem ZOS110.MAN.HFS is mounted at /usr/man
  MNTE2 and MNTE3 common: reads done is 0, writes done is 0
  MNTE3 specific: mount time in seconds is 5833
filesystem ZOS110.VAR.HFS is mounted at /SYSTEM/var
  MNTE2 and MNTE3 common: reads done is 0, writes done is 0
  MNTE3 specific: mount time in seconds is 5833
filesystem ZOS110.ETC.HFS is mounted at /SYSTEM/etc
  MNTE2 and MNTE3 common: reads done is 0, writes done is 0
  MNTE3 specific: mount time in seconds is 5833
filesystem ZOS110.ROOT.HFS is mounted at /
  MNTE2 and MNTE3 common: reads done is 0, writes done is 0
  MNTE3 specific: mount time in seconds is 5833   
CELEBW48
/* CELEBW48

   This example uses w_getmntent() to retrieve information 
   about currently mounted systems in the MNTE2 mapping format.

*/
#define _OPEN_SYS
#include <sys/mntent.h>
#include <stdio.h>

main() {
  int entries, entry;
  struct {
    MNTE2H   header;
    W_MNTENT2 mount_table[10];
  } work_area;

  memset(&work_area, 0x00, sizeof(work_area));

  /* 'header' initialization to specify MNTE2 mapping format */
  memcpy(work_area.header.mh2_hdr.mnt2h_cbid, MNTE2H_ID, 4);
  work_area.header.mh2_hdr.mnt2h_cblen = sizeof(struct mnte2);
  work_area.header.mh_bodylen = sizeof(struct w_mntent2);

  do {
    if ((entries = w_getmntent((char *) &work_area,
                               sizeof(work_area))) == -1)
      perror("w_getmntent() error");

    else for (entry=0; entry<entries; entry++) {
      printf("filesystem %s is mounted at %s\n",
             work_area.mount_table[entry].mnt2_fsname,
             work_area.mount_table[entry].mnt2_mountpoint);
      printf("  MNTE2 specific: reads done is %i, writes done is %i\n",
             work_area.mount_table[entry].mnt2_readct,
             work_area.mount_table[entry].mnt2_writect);
    }
  } while (entries > 0);
}
Output
filesystem ZOS110.LPP.HFS is mounted at /usr/lpp    
  MNTE2 specific: reads done is 0, writes done is 0 
filesystem ZOS110.NLS.HFS is mounted at /usr/lib/nls
  MNTE2 specific: reads done is 0, writes done is 0 
filesystem ZOS110.MAN.HFS is mounted at /usr/man    
  MNTE2 specific: reads done is 0, writes done is 0 
filesystem ZOS110.VAR.HFS is mounted at /SYSTEM/var 
  MNTE2 specific: reads done is 0, writes done is 0 
filesystem ZOS110.ETC.HFS is mounted at /SYSTEM/etc 
  MNTE2 specific: reads done is 0, writes done is 0 
filesystem ZOS110.ROOT.HFS is mounted at /          
  MNTE2 specific: reads done is 0, writes done is 0   
CELEBW32
/* CELEBW32

   This example uses w_getmntent() to retrieve information
   about currently mounted systems in the MNTE mapping format.

*/
#define _OPEN_SYS
#include <sys/mntent.h>
#include <stdio.h>

main() {
  int entries, entry;
  struct {
    struct w_mnth   header;
    struct w_mntent mount_table[10];
  } work_area;

  memset(&work_area, 0x00, sizeof(work_area));
  do {
    if ((entries = w_getmntent((char *) &work_area,
                               sizeof(work_area))) == -1)
      perror("w_getmntent() error");

    else for (entry=0; entry<entries; entry++) {
      printf("filesystem %s is mounted at %s\n",
             work_area.mount_table[entry].mnt_fsname,
             work_area.mount_table[entry].mnt_mountpoint);
    }
  } while (entries > 0);
}
Output
filesystem ZOS110.LPP.HFS is mounted at /usr/lpp     
filesystem ZOS110.NLS.HFS is mounted at /usr/lib/nls 
filesystem ZOS110.MAN.HFS is mounted at /usr/man     
filesystem ZOS110.VAR.HFS is mounted at /SYSTEM/var  
filesystem ZOS110.ETC.HFS is mounted at /SYSTEM/etc  
filesystem ZOS110.ROOT.HFS is mounted at /    

Related information