get information about a disk for a file descriptor
#include <sys/types.h> #include <sys/disk.h> int disk_get_entry( int fildes, struct _disk_entry *d_bfr );
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.
#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 ); }
QNX
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes, but modifies errno |
Thread | Yes |