HAL and ROX (auto-detecting USB sticks, etc)

HAL and ROX

With httpHAL and httpIvman and httppmount,
you can have devices like CD-ROMs and USB flash sticks be automatically mounted and added to your panel. When you unmount it the mountpoint will be removed from your panel.

Setup

The following was tried with Udev 070, HAL 0.5.4, DBus 0.50, Ivman 0.6.4, and pmount 0.9.3.
We are going to set things up so that Ivman is run as root and handles the automounting under /media , with the help of pmount.
Then users can run their own instances of Ivman too, to handle desktop specific stuff (like adding devices to the panel).

dbus-daemon --system
hald --daemon=yes --retain-privileges
ivman

NOTE: If all this works, don't forget to check that dbus, hald and ivman is started as above in your bootscripts...

#!/bin/sh
exec 1>&2
echo -n "Launching volume manager... "
if ps -C ivman -o user | grep -q $USER
then
  echo "Already running."
  exit
else
  echo "OK"
  exec ivman
fi
<!--
    <ivm:Match name="ivm.mountable" value="true">
        <ivm:Option name="mount" value="true" />
    </ivm:Match>

-->

Ivman rules to add devices to your panel

--- hal-0.5.4/hald/linux2/blockdev.c    2005-08-10 06:05:58.000000000 -0300
+++ hal-0.5.4-lijon/hald/linux2/blockdev.c      2005-10-21 19:15:28.000000000 -0200
@@ -202,7 +202,7 @@

        device_property_atomic_update_begin ();
        hal_device_property_set_bool (d, "volume.is_mounted", FALSE);
-       hal_device_property_set_string (d, "volume.mount_point", "");
+//     hal_device_property_set_string (d, "volume.mount_point", "");
        device_property_atomic_update_end ();

        HAL_INFO (("Clearing mount point for %s", device_file));
#!/bin/sh
### Change "Top" below to the panel you want your devices on...
rox --RPC << EOF
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope">
 <env:Body xmlns="http://rox.sourceforge.net/SOAP/ROX-Filer">
  <Panel$1>
   <Side>Top</Side>

   <Path>$2</Path>
  </Panel$1>
 </env:Body>
</env:Envelope>
EOF
    <ivm:Match name="ivm.mountable" value="true">
        <ivm:Property name="hal.volume.is_mounted">
          <ivm:Action value="true" exec='rox.panelput Add "$hal.volume.mount_point$"' />
          <ivm:Action value="false" exec='rox.panelput Remove "$hal.volume.mount_point$"' />
        </ivm:Property>
    </ivm:Match>

A nice ~/bin/eject script:

This lets you unmount your media and also FUSE mountpoints with the Eject entry on the ROX-Filer file menu.
Don't forget to make the script executable.

#!/bin/sh
pumount "$1" 2>/dev/null || fusermount -u "$1" 2>/dev/null ||
echo "Could not unmount with pumount or fusermount -u" >&2

More patches

Spaces in mountpoint names

Ivman 0.9.3 has the problem that mountpoints are not enclosed by quotes when passed as arg to pmount. So if a inserted media has spaces in the desired mount point, pmount will fail! look in ivmans src/manager.c:619 and put \" around the $hal.volume.desired_mount_point$ thing...

Better mountpoint names

At least for me, my CD-ROM's got mounted as /media/hde and stuff like that, this patch to /usr/share/hal/fdi/policy/10osvendor/10-storage-policy.fdi fixed it so that media is mounted with the volume label as mountpoint:

--- /System/Links/Shared/hal/fdi/policy/10osvendor/10-storage-policy.fdi        2005-10-21 19:18:07.000000000 -0200
+++ /System/Settings/hal/fdi/policy/10-storage-policy.fdi       2005-10-22 13:12:44.000000000 -0200
@@ -96,8 +96,7 @@
     <match key="block.is_volume" bool="true">
       <match key="volume.fsusage" string="filesystem">
        <!-- skip for drives with the no partitions hint (they are handled above) -->
-       <match key="@block.storage_device:storage.no_partitions_hint" bool="false">
-
+<!--   <match key="@block.storage_device:storage.no_partitions_hint" bool="false"> -->

          <merge key="volume.policy.should_mount" type="bool">true</merge>
          <merge key="volume.policy.mount_filesystem" type="copy_property">volume.fstype</merge>

@@ -173,7 +172,7 @@
              <merge key="volume.policy.should_mount" type="bool">true</merge>
            </match>

          </match>
-       </match>
+<!--   </match> -->
       </match>
     </match>

Good luck!

Making different types of media get different icons

<?xml version="1.0" encoding="UTF-8"?> <!-- -*- SGML -*- -->

<deviceinfo version="0.2">
  <device>
    <match key="@block.storage_device:storage.bus" string="usb">
      <match key="info.category" string="volume">
        <merge key="volume.is_usb_storage" type="bool">true</merge>
      </match>

    </match>
  </device>
</deviceinfo>
  • Change your ~/.ivman/IvmConfigProperties.xml rule to this:
   <ivm:Match name="ivm.mountable" value="true">

        <ivm:Property name="hal.volume.is_mounted">
          <ivm:Action value="true" exec='rox.seticon Set "$hal.volume.mount_point$" $HOME/.ivman/other.png' />
          <ivm:Action value="false" exec='rox.seticon Unset "$hal.volume.mount_point$"' />
        </ivm:Property>

        <ivm:Match name="hal.volume.is_usb_storage" value="true">
        <ivm:Property name="hal.volume.is_mounted">

                <ivm:Action value="true" exec='rox.seticon Set "$hal.volume.mount_point$" $HOME/.ivman/usb.png' />
                <ivm:Action value="false" exec='rox.seticon Unset "$hal.volume.mount_point$"' />
        </ivm:Property>
        </ivm:Match>

        <ivm:Match name="hal.volume.is_disc" value="true">
        <ivm:Property name="hal.volume.is_mounted">

                <ivm:Action value="true" exec='rox.seticon Set "$hal.volume.mount_point$" $HOME/.ivman/cdr.png' />
                <ivm:Action value="false" exec='rox.seticon Unset "$hal.volume.mount_point$"' />
        </ivm:Property>
        </ivm:Match>

        <ivm:Property name="hal.volume.is_mounted">
          <ivm:Action value="true" exec='rox.panelput Add "$hal.volume.mount_point$"' />

          <ivm:Action value="false" exec='rox.panelput Remove "$hal.volume.mount_point$"' />
        </ivm:Property>
    </ivm:Match>
  • Create this script in ~/bin/rox.seticon and make it executable:
rox --RPC << EOF

<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope">
 <env:Body xmlns="http://rox.sourceforge.net/SOAP/ROX-Filer">
  <$1Icon>
   <Path>$2</Path>
   <Icon>$3</Icon>

  </$1Icon>
 </env:Body>
</env:Envelope>
EOF
  • And put some icons for other.png, cdr.png and usb.png in ~/.ivman/ and you're done!