You are not logged in.

#1 2008-02-21 09:05:59

bsdson.tw
Member
From: Taiwan
Registered: 2005-05-06
Posts: 161

dirty patch for exo-mount

Hi,
I've looked around for an easy solution to the problem that xfce4 would NOT mount with extra options suggested by HAL, but no luck,
so... I made this dirty patch.

<BACKGROUND>
1. After you plugged-in your USB drive, HAL will know, and it will setup hardware information according to your configurations, which are the policies in /etc/hal/fdi/policy and/or /usr/share/hal/fdi/policy.
    In theory, we should setup configurations here, by some "key/value" pairs, which will be accepted by the programs who really handle the "plugged-in" event.
    In this case, the program is just exo-mount. Unfortunately, exo-mount doesn't care about any information provided by HAL. And so the problem comes.

2. I guess/believe there should be some standards that define how to "explain/interpret" these policies, but I did not search information about them,
    and that is why this patch is so called "dirty", I don't care about the information, neither. tongue

<DIFFERENCES>
What I do is to add following options:
1. nodev, noexec for ntfs-3g and vfat
2. rw, utf8 for vfat
3. umask=0, locale=zh_TW.utf8 for ntfs-3g

Before adding these options, I'd better check out if they are appropriate, but I did NOT, which is tho other reason why this patch is dirty.

"exo-0.3.4/exo-mount/exo-mount-hal.c" line 678, which looks like this:

          else if (strcmp (device->fsoptions[m], "longnames") == 0
                && strcmp (device->fstype, "vfat") == 0)
            {
              /* however this one is FreeBSD specific */
              options[n++] = g_strdup ("longnames");
            }

Add following after above code:

          else if (strcmp (device->fsoptions[m], "nodev") == 0
                && (strcmp (device->fstype, "vfat") == 0
                 || strcmp (device->fstype, "ntfs-3g") == 0))
            {
                // we'd better check the environment first
                options[n++] = g_strdup ("nodev");
            }
          else if (strcmp (device->fsoptions[m], "noexec") == 0
                && (strcmp (device->fstype, "vfat") == 0
                 || strcmp (device->fstype, "ntfs-3g") == 0))
            {
                // we'd better check the environment first
                options[n++] = g_strdup ("noexec");
            }
          else if (strcmp (device->fsoptions[m], "utf8") == 0
                && strcmp (device->fstype, "vfat") == 0)
            {
                // we'd better check the environment first
                options[n++] = g_strdup ("utf8");
            }
          else if (strcmp (device->fsoptions[m], "rw") == 0
                && strcmp (device->fstype, "vfat") == 0)
            {
                // we'd better check the environment first
                options[n++] = g_strdup ("rw");
            }
          else if (strcmp (device->fsoptions[m], "umask=") == 0
                && strcmp (device->fstype, "ntfs-3g") == 0)
            {
                // we'd better check the environment first
                options[n++] = g_strdup ("umask=0");
            }
          else if (strcmp (device->fsoptions[m], "locale=") == 0
                && strcmp (device->fstype, "ntfs-3g") == 0)
            {
                // we'd better check the environment first
                options[n++] = g_strdup ("locale=zh_TW.utf8");
            }

<BUILD>
configure and make as usual, and
replace the original exo-mount with this: /exo-0.3.4/exo-mount/.libs/exo-mount

And that is down.
Remember to add following to the HAL policy:

        <match key="volume.fstype" string="ntfs">
            <match key="@block.storage_device:storage.hotpluggable" bool="true">
                <merge key="volume.fstype" type="string">ntfs-3g</merge>
            </match>
        </match>

which will make "mount" to use ntfs-3g.

<CAUTION>
the options for ntfs-3g does NOT work, and I don't know why currently.

BR,
bsdson.tw

Last edited by bsdson.tw (2008-02-21 09:06:52)

Offline

#2 2008-06-20 10:08:28

bsdson.tw
Member
From: Taiwan
Registered: 2005-05-06
Posts: 161

Re: dirty patch for exo-mount

okay, here comes the version 2, but not in a patch. it's now a replacement.

I made 2 replacement scripts for exo-mount and exo-unmount.
just backup the original files and put these 2 in place, and it's done.

[why to do this? and what's wrong with the original one?]
exo-mount only knows a few mount option hints, which is not enough especially while English is not my native language (locale).
and I think exo-mount should take "all" mount option hints (volume.policy.mount_option.*) if applicable.*

* by applicable, I mean the option is in volume.mount.valid_options
  although, current implementation does not check if a hint is in the valid_options.

[exo-mount]

#!/bin/sh

# usage: $0 -n -h <udi>

# init
date
echo $0 $@
echo

# check
if [ $# -ne 3 -o "$1" != "-n" -o "$2" != "-h" ]; then
    # @todo: error handling
    exit 4
fi

# figure out mount parameter
buf=$(lshal -u "$3")
if [ -z "$buf" ]; then
    # @todo: error handling
    echo find no specified node
    exit 6
fi

dev=$(echo "$buf" | grep block.device | cut -d = -f 2 | cut -d "'" -f 2)
echo dev=$dev
echo

mount_point=$(echo "$buf" | grep volume.label | cut -d = -f 2 | cut -d "'" -f 2)
if [ -z "$mount_point" ]; then
    mount_point=$(basename $dev)
fi
echo mount_point=$mount_point
echo

filesystem=$(echo "$buf" | grep volume.policy.mount_filesystem)
if [ -z "$filesystem" ]; then
    filesystem=auto
else
    filesystem=$(echo $filesystem | cut -d "'" -f 2)
fi
echo filesystem=$filesystem
echo

echo "$buf" | grep volume.policy.mount_option. > /tmp/exo-mount.sh.buf
while read line; do
    key=$(echo $line | cut -d = -f 1)
    key=${key#volume.policy.mount_option.}
    key=$(echo $key)
    value=$(echo $line | cut -d = -f 2)
    echo parsing key=$key value=$value

    if [ "$value" != "${value%(bool)}" ]; then
        value=${value%(bool)}
        value=$(echo $value)
        if [ "$value" = true ]; then
            options=$options,$key
            echo add $key
        fi

    elif [ "$value" != "${value%(string)}" ]; then
        value=${value%(string)}
        value=$(echo $value | cut -d "'" -f 2)
        options=$options,$key=$value
        echo add $key=$value

    elif [ "$value" != "${value%(int)}" ]; then
        value=${value%(int)}
        value=$(echo $value | cut -d " " -f 1)
        options=$options,$key=$value
        echo add $key=$value
    fi
    echo
done < /tmp/exo-mount.sh.buf
echo options=$options

# check mount point
if [ ! -d /media/$mount_point ]; then
    sudo mkdir -p /media/$mount_point
fi

# do mount
# @todo change to hal mount
if [ -z "$options" ]; then
    echo sudo mount -t $filesystem $dev /media/$mount_point
    sudo mount -t $filesystem $dev /media/$mount_point
else
    echo sudo mount -t $filesystem -o ${options#,} $dev /media/$mount_point
    sudo mount -t $filesystem -o ${options#,} $dev /media/$mount_point
fi

[exo-unmount]

#!/bin/sh

# usage: $0 -n -h <udi>

# init
date
echo "$0 $@"
echo

# check
if [ $# -ne 3 -o "$1" != "-n" -o "$2" != "-h" ]; then
    # @todo: error handling
    exit 4
fi

# figure out mount point
mount_point=$(lshal -u $3 | grep "volume.mount_point" | cut -d "'" -f 2)
echo mount_point=$mount_point

# do umount
echo sudo umount $mount_point
sudo umount $mount_point

and below is an example of hal's policy configuration:

<deviceinfo version="0.2">
  <device>
    <match key="volume.fstype" string="ntfs">
    <merge key="volume.policy.mount_option.nodev" type="bool">true</merge>
    <merge key="volume.policy.mount_option.noexec" type="bool">true</merge>
    <merge key="volume.policy.mount_option.rw" type="bool">true</merge>
    <merge key="volume.policy.mount_option.umask" type="int">0</merge>
    <merge key="volume.policy.mount_option.locale" type="string">zh_TW.utf8</merge>
    <merge key="volume.policy.mount_filesystem" type="string">ntfs-3g</merge>
  </match>
</device>
<device>
  <match key="volume.fstype" string="vfat">
    <merge key="volume.policy.mount_option.nodev" type="bool">true</merge>
    <merge key="volume.policy.mount_option.noexec" type="bool">true</merge>
    <merge key="volume.policy.mount_option.rw" type="bool">true</merge>
    <merge key="volume.policy.mount_option.umask" type="int">0</merge>
    <merge key="volume.policy.mount_option.utf8" type="bool">true</merge>
  </match>
</device>
</deviceinfo>

BR,
bsdson.tw

PS. in the next version, if any, I will try to change "sudo mount" to "hal-mount".

Last edited by bsdson.tw (2008-06-20 10:12:11)

Offline

#3 2008-06-20 11:21:24

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: dirty patch for exo-mount

I didn't read this carefully, and I don't use exo-mount, but it looks to me that you should discuss this with upstream. That means, report the problem to them, and then propose your solutions.


pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#4 2008-06-21 08:13:45

jarryson
Member
Registered: 2007-02-18
Posts: 298

Re: dirty patch for exo-mount

im also using a exo-mount with some utf8 patchs for showing Chinese correctly.

diff --git a/exo-mount/exo-mount-hal.c b/exo-mount/exo-mount-hal.c
index 791a536..4b130c3 100644
--- a/exo-mount/exo-mount-hal.c
+++ b/exo-mount/exo-mount-hal.c
@@ -34,6 +34,8 @@
 #include <unistd.h>
 #endif
 
+#include <langinfo.h>
+
 #include <libhal-storage.h>
 
 #include <exo-hal/exo-hal.h>
@@ -616,6 +618,30 @@ oom:  g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_NOMEM, g_strerror (ENOMEM))
 
 
 /**
+ * exo_mount_hal_iocharset:
+ *
+ * Determines the preferred iocharset for filesystems
+ * that support it.
+ *
+ * Return value: iocharset string or %NULL if none.
+ **/
+static const gchar*
+exo_mount_hal_iocharset ()
+{
+  const gchar* cs = g_getenv("EXO_MOUNT_IOCHARSET");
+  if (cs != NULL)
+    return cs;
+
+  const char* codeset = nl_langinfo (CODESET);
+  if (codeset && !strcmp (codeset, "UTF-8"))
+    return "utf8";
+
+  return NULL;
+}
+
+
+
+/**
  * exo_mount_hal_device_mount:
  * @device : an #ExoMountHalDevice.
  * @error  : return location for errors or %NULL.
@@ -676,6 +702,12 @@ exo_mount_hal_device_mount (ExoMountHalDevice *device,
               /* however this one is FreeBSD specific */
               options[n++] = g_strdup ("longnames");
             }
+          else if (strcmp (device->fsoptions[m], "iocharset=") == 0)
+            {
+              const gchar* iocharset = exo_mount_hal_iocharset();
+              if (iocharset != NULL)
+                options[n++] = g_strdup_printf ("iocharset=%s", iocharset);
+            }
         }
     }
 
diff --git a/exo-mount/main.c b/exo-mount/main.c
index 80eae1d..f442019 100644
--- a/exo-mount/main.c
+++ b/exo-mount/main.c
@@ -39,6 +39,8 @@
 #include <string.h>
 #endif
 
+#include <locale.h>
+
 #include <glib/gstdio.h>
 
 #include <exo-hal/exo-hal.h>
@@ -97,6 +99,8 @@ main (int argc, char **argv)
   /* initialize the i18n support */
   xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
 
+  setlocale(LC_CTYPE, "");
+
   /* initialize GTK+ */
   if (!gtk_init_with_args (&argc, &argv, "Xfce mount", entries, GETTEXT_PACKAGE, &err))
     {

Offline

Board footer

Powered by FluxBB