Home
Developer Resources
QNX RTOS v4
QNX RTOS v4 Knowledge Base

QNX RTOS v4 Knowledge Base

Foundry27
Foundry27
QNX RTOS v4 project
Resources

QNX RTOS v4 Knowledge Base

Title Finding out where devices are mounted
Ref. No. QNX.000009306
Category(ies) Network, Development, Configuration
Issue What's the easiest way of finding out where devices are mounted?  We wanted to take some files home on diskette but didn't know what the hard drive was mounted as.  We are using a co-worker's machine and didn't want to start unmounting and remounting drives.



Solution The WATCOM C libraries include some handy functions that address this problem. I've incorporated these functions in a simple utility, mountlist, that works for both, local and remote nodes. For example, if you simply typed mountlist on node 107, you'd see output similar to:

x09/x09isx09//107/
x09/dev/fd0x09mounted asx09//107/dfd

and if you typed mountlist -n 3, you'd see output similar to:

x09/dev/hd0t77x09mounted as //3/
x09/dev/hd0t78x09mounted as //3/.bootable
x09/dev/consolex09is //3/dev/con1
x09/dev/hd1t77x09mounted as //3/src
x09/dev/fd1x09mounted as //3/fd1

Here's the source for mountlist:

// mountlist.c

#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/prfx.h>
#include <sys/fsys.h>
#include <sys/types.h>

#define BUFLEN 1000

extern char *optarg;
extern int optind, opterr, optopt;

main( int argc, char *argv[] ){
x09char buffer[BUFLEN], directory[30], realdev[300];
x09char *device, *next_dev, *pdir = NULL;
x09pid_t nid;
x09int realdevlen;

x09if ( getopt ( argc, argv, "n:" ) != -1)
x09x09mod = atoi ( optarg );

x09else
x09x09nid = getnid();
x09sprintf(realdev,"//%d", nid); // used to specify realdev in
x09realdevlen = strlen ( realdev ); // fsys_get_mount_pt call
x09x09// Get prefix list to look for mounted devices/directories
x09if ( qnx_prefix_query ( nid, "*", buffer, BUFLEN ) != 0 ) {
x09x09printf ( "Prefix query failed... exitingn");
x09x09exit(-1);
x09}
x09next_dev = device = buffer;

x09while ( device ) {
x09x09next_dev = strchr ( device, '=' );

x09x09*next_dev++ = NULL;
x09x09if ( *next_dev = '/' ) pdir = next_dev;
x09x09// found aliased directory.. will display as "dirname is realdir"

x09x09if  (next_dev = strchr ( next_dev, ';' ) ) != NULL )
x09x09x09*next_dev++ = NULL;
x09x09if ( pdir != NULL ) {
x09x09// Display aliased dir as described above.
x09x09x09printf ( "%-15s is %sn", device, pdir );
x09x09x09pdir NULL;
x09x09x09}
x09x09else {
x09x09x09// Is a device, adjust name and query fsys for mount pt
x09x09x09strcpy( realdev+realdevlen, device ); // check dev on correct node
x09x09x09if ( fsys_get_mount_pt ( realdev, directory ) = 0 )
x09x09x09printf ( "%-15s mounted as %sn", device, directory );
x09x09}
x09x09device = next_dev;
x09}
}