You are not logged in.

#1 2010-03-01 10:41:33

leniviy
Member
Registered: 2009-05-23
Posts: 177

owner of autocreated mount point in /media

Hi. When Gnome automounts a USB disk it creates a mount point for it in /media .
For vfat/ntfs it passes options uid=me,gid=me to the "mount" program.

Before mounting it creates a mount point with Owner/Group = root/root . Because of that I can't use the advanced ntfs-3g ownership and permissions.
How to tell Gnome to create the mount point with the same Owner/Group that are passed as options to "mount" (uid=me,gid=me)? Before Gnome 2.28 some default settings were stored in gconf at "/system/storage" , but in current versions there's no such key.

http://www.tuxera.com/community/ntfs-3g … rmissions/

If no mapping file is found, an attempt to build a default single user mapping is made by mapping the owner and group of the mount point to the owner of the root of the mounted file system. This is only possible if the full path to the mount point is given, its owner is not root, and the owner of the file system is not an Administrator. This default mapping is most suited for pluggable file systems (such as USB keys) which have to be used on several Linux systems. The owner of the file system root has to be defined on Windows.

This works with manual mount.


Arch 64, xfce4

Offline

#2 2010-03-02 14:30:46

leniviy
Member
Registered: 2009-05-23
Posts: 177

Re: owner of autocreated mount point in /media

[off]Heh, I'm often the only person on the forum who doesn't get any replys[/off]. Anyway, you know that currently we have a symlink

/sbin/mount.ntfs -> /bin/ntfs-3g

So I decided to redirect this symlink to my own script. In short, if "mount.ntfs" is called by Gnome, it'll change the owner/group of the mount point.

#!/bin/bash

fn_parents() {
  while [ "$1" -a "$1" != "0" ]; do
    P="$1"
    set -- `ps -p "$1" -o ppid= -o comm=`
    echo "$P" "$2"
  done
}

fn_parse_mount_options() {
  oldIFS=$IFS
  IFS=,
  for fn_parse_mount_options_param in $@; do
    fn_parse_mount_options_name=${fn_parse_mount_options_param%%=*}        # restrict name to first word only (even if there's another = in the value)
    eval "optset_$fn_parse_mount_options_name=1"
    case "$fn_parse_mount_options_param" in
    *=* )
      fn_parse_mount_options_value=${fn_parse_mount_options_param#*=}        # value is whatever's after first word and =
      eval "opt_$fn_parse_mount_options_name=\$fn_parse_mount_options_value"
      ;;
    esac
  done
  IFS=$oldIFS
}

fn_parse_args() {
  device=
  dir=
  while [ "$1" ]; do
    case "${1}" in
    -o )
      shift
      fn_parse_mount_options "$1"
      ;;
    -o* )
      fn_parse_mount_options "${1:2}"
      ;;
    -* )
      # unknown opt
      ;;
    * )
      if [ -z "$device" ]; then
        device=$1
      elif [ -z "$dir" ]; then
        dir=$1
      fi
      ;;
    esac
    shift
  done
}

#/usr/bin/logger -t "" "mount -i $*"
fn_parse_args "$@"

if ( [ -r /sbin/mount.ntfs-3g ] && fn_parents $$ | grep "devkit-disks-da" >/dev/null ); then
  /usr/bin/logger "NTFS automount. Selecting ntfs-3g"
  echo "$dir"
  if [ -n "$dir" -a "$opt_uid" ]; then
    /usr/bin/logger "running command: chown $opt_uid $dir"
    chown "$opt_uid" "$dir"
  fi
  if [ "$dir" -a "$opt_gid" ]; then
    /usr/bin/logger "running command: chgrp $opt_gid $dir"
    chgrp "$opt_gid" "$dir"
  fi
  /usr/bin/logger "running command: /sbin/mount.ntfs-3g $*"
  /sbin/mount.ntfs-3g "$@"
  exit $?
else
  /usr/bin/logger "NTFS manual mount. Selecting ntfs" 
  mount -i "$@"
  exit $?
fi

Arch 64, xfce4

Offline

Board footer

Powered by FluxBB