Mounting filesystems

If you use the USB launcher service for device publishing, you can configure it to mount the filesystems of USB devices; that way, you don't need to use a separate service to mount filesystems (unless you also need to mount non-USB devices).

The USB launcher service can mount the filesystems of attached USB devices based on the rules in a mount-rules file. The service reads either the default mount-rules file, /etc/usblauncher/rules.mnt, or another file specified with the -M command-line option. The service uses the standard mount() function call to do the actual mounting.

Content detection rules

The format for the mount-rules file is one rule per line, with each line containing fields (Device, Mountpoint, FS type, Options) separated by whitespace. The USB launcher service processes the rules in order, starting at the first line and stopping at the first match that either succeeds or tells the service to skip the device (i.e. when the rule has only a glob pattern and no mount information). If a rule fails to execute, USB launcher goes to the next line, until it successfully executes a matching rule or reaches the end of the file. To select the appropriate filesystem, you can specify multiple rules for a removable device.

Here's an example of the mount-rules file:

# Device                    Mountpoint  FS type Options
/dev/umass[0-9]*            /           enum
/dev/umass[0-9]*t1[1234]    /fs/usb%0   dos
/dev/umass[0-9]*t1[1234].*  /fs/usb%0   dos
/dev/umass[0-9]*t[146]      /fs/usb%0   dos
/dev/umass[0-9]*t[146].*    /fs/usb%0   dos
/dev/umass*t17[789]         /fs/usb%0   qnx6    sync=optional
/dev/umass[0-9]*            /fs/usb%0   dos

Note the following:

  • Device column — contains pathnames in the form /dev/umassXtN, where X is a storage-device number (0, 1, 2, etc.) and N is a partition type (4, 11, 12, etc.). Thus, a path with umassX refers to a device, while a path with umassXtN refers to a partition.
  • Mountpoint column — supports the following special sequences:
    Sequence Description
    %#

    Expands to the major device number of the storage device.

    For example, with /fs/usb%#, /dev/umass0 will be mounted at /fs/usb0 and /dev/umass1 will be mounted at /fs/usb1. But %# does not permit multiple partitions, so it's better to use %0.

    %0

    Used principally to support multiple USB partition rules in the /etc/usblauncher/rules.mnt file, all with mountpoint names of the form /fs/usb%0.

    If you specify %0 in the name, the USB launcher service tries to allocate /fs/usb0, /fs/usb1, and so on (starting from 0) until it finds a unique mountpoint name. For example, if filesystems are already mounted at those first two paths, the service expands /fs/usb%0 to /fs/usb2.

  • FS type column — contains either the filesystem type or an enum command that instructs USB launcher to enumerate any partitions found for the device that matches the rule in the Device column.
  • Options column — contains any options passed to the filesystem driver. The sync=optional parameter in the above example is specific to the filesystem driver DLL; see the driver documentation for more information.

Mounting a filesystem

Given the content-detection rules and example mount-rules file described above, here's what happens when you insert a USB stick that contains one or more filesystems:
  1. USB launcher attempts to identify a matching rule for the USB stick and finds the enum rule, which enumerates the partition. At this point, USB launcher has completed processing the mount rules, and the enumeration proceeds.
  2. The enumeration makes /dev/umassXtN pathnames appear. In response, USB launcher resumes processing the mount rules, skipping the enumeration rule and skipping the rule to mount the whole device as a filesystem. Instead, it tries an fs-dos mount on a partition, resulting in the appearance of an /fs/usb* pathname.
  3. USB launcher publishes a mount object for the raw device and for each partition that has been enumerated. When it subsequently mounts a filesystem on a partition, it will update the mount object for that partition with mountpoint information.

Preventing USB launcher from mounting filesystems

By default, the USB launcher service automatically attempts to mount filesystems on USB devices. To disable the auto-mounter feature, use the -M option to point to an empty mount-rules file or to /dev/null. If you use this technique, USB launcher won't log mount attempts or publish accurate mnt_status values through the PPS mount object.