mount utility

By covering the mount() library function and the operation in the resource manager, we've pretty well covered the mount utility. The usage for the utility is shown here for reference:

mount [-wreuv] -t type [-o options] [special] mntpoint

mount [-wreuv] -T type [-o options] special [mntpoint]


The options are:

Indicates the special device, if it's present, is generally a real device and the same server will handle the mountpoint.
Indicates the special device isn't a real device but rather a key for the server. The server will automatically create an appropriate mountpoint if mntpoint isn't specified.
Increases the verbosity.
Mount read/write.
Mount read-only.
Mount for update (remount).

However, if you're writing a mount handler, there may be occasions when you want to do custom parsing of arguments and provide your own data structure to your server. This is why the mount command will always first try and call out to a separate program named mount_XXX, where XXX is the type that you specified with the -t option. To see just what would be called (in terms of options, etc.), you can use the -v option, which should provide you with the command line that would be exec()'ed.

In order to help with the argument parsing, there's a utility function, mount_parse_generic_args(), that you can call to process the common options. The function is defined in <sys/mount.h> as:

char *mount_parse_generic_args(char *options, int *flags);

This function parses the given options, removes any options that it recognizes, and sets or clears the appropriate bits in the flags. It returns a pointer to the modified version of options containing any options that it didn't recognize, or NULL if it recognized all the options. You use mount_parse_generic_args() like this:

while ((c = getopt(argv, argc, "o:"))) {
   switch (c) {

      case 'o':

        if ((mysteryop = mount_parse_generic_args(optarg, &flags))) {

           /* You can do your own getsubopt-type processing here.
              The common options are removed from mysteryop. */


For more information about the stripped options and the corresponding flags, see the entry for mount_parse_generic_args(), in the QNX Neutrino C Library Reference.