[Previous]
[Contents]
[Next]

disk_get_entry()

get information about a disk for a file descriptor

Synopsis:

#include <sys/types.h>
#include <sys/disk.h>
int disk_get_entry( int fildes,
                    struct _disk_entry *d_bfr );

Description:

The disk_get_entry() function obtains information about the disk (both logical partition and physical disk) associated with the file descriptor fildes. For example, this function may be used to determine the type of disk (FLOPPY, HARD DISK or RAM DISK), the size of the disk, the number of heads, and so on. The information is placed in the structure located at the address indicated by d_bfr. The file descriptor fildes may have been obtained by a successful open() of any file or directory on the disk, or by opening the block special device directly.

The file <sys/disk.h> contains definitions for the structure _disk_entry, and describes the contents of its fields.

Returns:

0
Success
-1
An error occurred. errno is set to indicate the error.

Errors:

EBADF
The fildes argument is not a valid open file descriptor.
ENOSYS
An attempt was made to get disk information using a file descriptor that isn't associated with a block-oriented device (for example, a file descriptor associated with the device manager).

Examples:

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/disk.h>

int main( int argc, char **argv )
  {
    struct _disk_entry     de;
    int                    fd;
    char                   *dsk,
                           *tp;

    dsk = argv[1];
    if( ( fd = open( dsk, O_RDONLY ) ) == ( -1 ) ) {
      perror( "example" );
      exit( EXIT_FAILURE );
    }

    if( disk_get_entry( fd, &de ) == ( -1 ) )
      fprintf( stderr,
           "could not find disk '%s'\n", dsk );
    else {
      switch( de.disk_type ) {
      case _FLOPPY:      tp = "Floppy";    break;
      case _HARD:        tp = "Hard";      break;
      case _RAMDISK:     tp = "Ram";       break;
      case _REMOVABLE:   tp = "Removable"; break;
      default:           tp = "?";
      }
      printf( "'%s' is a %s disk.\n", dsk, tp );
    }

    close( fd );
    return( EXIT_SUCCESS );
  }

Classification:

QNX

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

See also:

disk_space(), errno, open()


[Previous]
[Contents]
[Next]