FAT | RFS | XFS | ZFS

viter_reset()

PROTOTYPE

#include <posix.h>

void viter_reset(void);

DESCRIPTION

viter_reset() is a non-standard routine that resets the current position of the internal volume list to its first entry. Every installed volume (by XfsAddVol(), FatAddVol(), etc.) is on this list. The next viter_next() call will output the name of the first volume, if any.

EXAMPLE

  /*-------------------------------------------------------------------*/
  /* Try to mount each volume.                                         */
  /*-------------------------------------------------------------------*/
  for (viter_reset(); (vol_type = viter_next(vol_name, FILENAME_MAX));)
  {
    /*-----------------------------------------------------------------*/
    /* Okay if able to mount or already mounted.                       */
    /*-----------------------------------------------------------------*/
    if (mount(vol_name) == 0) || errno == EEXIST)
      printf("Volume \"%s\" is mounted\n", vol_name);

    /*-----------------------------------------------------------------*/
    /* Else if not unformatted, should have succeeded.                 */
    /*-----------------------------------------------------------------*/
    else if (errno != EINVAL)
      error("mount() failed.");

    /*-----------------------------------------------------------------*/
    /* Else volume was unformatted.                                    */
    /*-----------------------------------------------------------------*/
    else
    {
      /*---------------------------------------------------------------*/
      /* Try to format this volume. Check if format fails.             */
      /*---------------------------------------------------------------*/
      if (format(vol_name))
        error("format() failed.");

      /*---------------------------------------------------------------*/
      /* Else format succeeded, make another attempt to mount volume.  */
      /*---------------------------------------------------------------*/
      else if (mount(vol_name))
          error("mount() failed.");
    }
  }