atom feed19 messages in org.freebsd.freebsd-hackersRe: devd based AUTOMOUNTER
FromSent OnAttachments
vermadenFeb 17, 2012 9:48 am 
mattFeb 17, 2012 11:22 am 
vermadenFeb 17, 2012 12:40 pm 
vermadenFeb 17, 2012 1:58 pm 
vermadenFeb 17, 2012 3:22 pm 
vermadenFeb 18, 2012 1:47 am 
Hans Petter SelaskyFeb 18, 2012 5:08 am 
Gleb KurtsouFeb 18, 2012 8:56 am 
Uffe JakobsenFeb 18, 2012 9:06 am 
Lars EngelsFeb 18, 2012 12:20 pm 
vermadenFeb 19, 2012 1:46 pm 
vermadenFeb 20, 2012 12:43 am 
Ivan KlymenkoFeb 20, 2012 1:48 am 
vermadenFeb 20, 2012 5:26 am 
Freddie CashFeb 20, 2012 8:38 am 
Fernando ApesteguíaFeb 20, 2012 10:31 am 
vermadenFeb 20, 2012 11:17 am 
vermadenFeb 21, 2012 1:04 am 
Uffe JakobsenFeb 22, 2012 2:57 pm 
Subject:Re: devd based AUTOMOUNTER
From:Uffe Jakobsen (uf@uffe.org)
Date:Feb 18, 2012 9:06:00 am
List:org.freebsd.freebsd-hackers

On 2012-02-18 14:09, Hans Petter Selasky wrote:

On Saturday 18 February 2012 10:48:11 vermaden wrote:

Added a check if ntfs-3g is available, if not then mount_ntfs is used instead. Added deleting of empty directories at ${MNTPREFIX}. Added ${MNTPREFIX} to be set to /mnt or /media according to preference

#! /bin/sh

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin MNTPREFIX="/media" LOG="/var/log/automount.log" STATE="/var/run/automount.state" DATEFMT="%Y-%m-%d %H:%M:%S"

__create_mount_point() { # /* 1=DEV */ MNT="${MNTPREFIX}/$( basename ${1} )" mkdir -p ${MNT} }

__state_lock() { while [ -f ${STATE}.lock ]; do sleep 0.5; done

:> ${STATE}.lock

}

__state_unlock() { rm ${STATE}.lock }

__state_add() { # /* 1=DEV 2=PROVIDER 3=MNT */ __state_lock grep -E "${3}" ${STATE} 1> /dev/null 2> /dev/null&& { __log "${1}:duplicated '${STATE}'" return 1 } echo "${1} ${2} ${3}">> ${STATE} __state_unlock }

__state_remove() { # /* 1=MNT 2=STATE 3=LINE */ BSMNT=$( echo ${1} | sed 's/\//\\\//g' ) sed -i '' "/${BSMNT}\$/d" ${2} }

__log() { # /* @=MESSAGE */ echo $( date +"${DATEFMT}" ) ${@}>> ${LOG} }

case ${2} in (attach) for I in /dev/${1}* do case $( file -L -s ${I} | sed -E 's/label:\ \".*\"//g' ) in (*NTFS*) dd< ${I} count=1 2> /dev/null \

| strings \ | head -1 \ | grep -q "NTFS"&& {

__create_mount_point ${I} which ntfs-3g 1> /dev/null 2> /dev/null&& { ntfs-3g ${I} ${MNT} # /* sysutils/fusefs-ntfs */ } || { mount_ntfs ${I} ${MNT} } __log "${I}:mount (ntfs)" } ;; (*FAT*) dd< ${I} count=1 2> /dev/null \

| strings \ | grep -q "FAT32"&& {

__create_mount_point ${I} fsck_msdosfs -y ${I} mount_msdosfs -o large -l -L pl_PL.ISO8859-2 -D cp852 ${I} ${MNT} __log "${I}:mount (fat)" } ;; (*ext2*) __create_mount_point ${I} fsck.ext2 -y ${I} mount -t ext2fs ${I} ${MNT} __log "${I}:mount (ext2)" ;; (*ext3*) __create_mount_point ${I} fsck.ext3 -y ${I} mount -t ext2fs ${I} ${MNT} __log "${I}:mount (ext3)" ;; (*ext4*) __create_mount_point ${I} fsck.ext4 -y ${I} ext4fuse ${I} ${MNT} # /* sysutils/fusefs-ext4fuse */ __log "${I}:mount (ext4)" ;; (*Unix\ Fast\ File*) __create_mount_point ${I} fsck_ufs -y ${I} mount ${I} ${MNT} __log "${I}:mount (ufs)" ;; (*) case $( dd< ${I} count=1 2> /dev/null | strings | head -1 ) in (EXFAT) __create_mount_point ${I} mount.exfat ${I} ${MNT} # /* sysutils/fusefs-exfat */ __log "${I}:mount (ufs)" ;; (*) continue ;; esac ;; esac __state_add ${I} $( mount | grep -m 1 " ${MNT} " | awk '{printf $1}' ) \ ${MNT} || continue done ;;

(detach) MOUNT=$( mount ) __state_lock grep ${1} ${STATE} \

| while read DEV PROVIDER MNT

do TARGET=$( echo "${MOUNT}" | grep -E "^${PROVIDER} " | awk '{print $3}' ) [ -z ${TARGET} ]&& { __state_remove ${MNT} ${STATE} ${LINE} continue } umount -f ${TARGET}& unset TARGET __state_remove ${MNT} ${STATE} ${LINE} __log "${DEV}:umount" done __state_unlock __log "/dev/${1}:detach" find ${MNTPREFIX} -type d -empty -delete ;;

Not sure if you've looked at disktype in sysutils but it may be useful to you.

Hi,

Should your script be written like an rc.d script, so that one can enable/disable this automounting from /etc/rc.conf?

Nice,

Some comments:

Instead of requiring modification to /etc/devd.conf why not just put a "plugin" conf-file in /etc/devd/ - well even better put in /usr/local/etc/devd/ - that way your devd.conf modifications are not lost upon patching/updating base os.

There is an existing port called "automounter" by Dominic Fandrey which is much similar to your work.

You can get inspired of how he places his devd.conf in /usr/local/etc/devd/ His "automounter" also works with disk labels (as found in /dev/ufs/ and /dev/msdosfs/ etc)

You should consider make a port out of your work.

/Uffe