From owner-freebsd-hackers@FreeBSD.ORG Fri Feb 17 17:49:21 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 66D27106564A for ; Fri, 17 Feb 2012 17:49:21 +0000 (UTC) (envelope-from vermaden@interia.pl) Received: from smtpo.poczta.interia.pl (smtpo.poczta.interia.pl [217.74.65.207]) by mx1.freebsd.org (Postfix) with ESMTP id D870E8FC1C for ; Fri, 17 Feb 2012 17:49:20 +0000 (UTC) Date: Fri, 17 Feb 2012 18:49:17 +0100 From: vermaden To: freebsd-hackers@freebsd.org, freebsd-current@freebsd.org, freebsd-stable@FreeBSD.org X-Mailer: interia.pl/pf09 X-Originating-IP: 85.89.187.172 Message-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interia.pl; s=biztos; t=1329500958; bh=SryWECdGWvUbfmxaVo93dEJ0eU2ybjVooud7hOM6YHo=; h=Date:From:Subject:To:X-Mailer:X-Originating-IP:Message-Id: MIME-Version:Content-Type:Content-Transfer-Encoding; b=FA14eL5cVhvKO1viBUZ89uN/5Y3h9VFU7kDefeztMNaxlM6Jj9iV9bD7OrkRV13dA teELeG2V14Y5AK3mxYk4KSiClCxc8S+BHXHmm5tOoVfvwWwnuGYFfyc1R00n8RbJx7 pylQOH1fh0260qTnhKwWx/VW5IhSugFRQjaT4DDE= X-Mailman-Approved-At: Fri, 17 Feb 2012 18:06:06 +0000 Cc: Subject: devd based AUTOMOUNTER X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Feb 2012 17:49:21 -0000 Hi, I have finally made some effort on writing flexible yet very simple automou= nter for FreeBSD desktop. Feel free to submit me BUG reports ;) It currently supports these file formats: -- NTFS(rw) requires [port]sysutils/fusefs-ntfs[/port] -- FAT/FAT32 -- exFAT requires [port]sysutils/fusefs-exfat[/port] -- EXT2 -- EXT3 -- EXT4 requires [port]sysutils/fusefs-ext4fuse[/port] -- UFS (DOH!) It keeps state of the mounted devices at /var/run/automount.state and logs = all activities to /var/log/automount.log file. The place for the script is at /usr/local/sbin/automount.sh executable. The only additional configuration it requires are those lines at the end of= /etc/devd.conf file along with restarting /etc/rc.d/devd daemon. notify 200 { match "system" "DEVFS"; match "type" "CREATE"; match "cdev" "(da|mmcsd)[0-9]+"; action "/usr/local/sbin/automount.sh $cdev attach"; }; notify 200 { match "system" "DEVFS"; match "type" "DESTROY"; match "cdev" "(da|mmcsd)[0-9]+"; action "/usr/local/sbin/automount.sh $cdev detach"; }; The /usr/local/sbin/automount.sh executable is here: #! /bin/sh PATH=3D/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin LOG=3D"/var/log/automount.log" STATE=3D"/var/run/automount.state" DATEFMT=3D"%Y-%m-%d %H:%M:%S" __create_mount_point() { # /* 1=3DDEV */ MNT=3D"/mnt/$( 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=3DDEV 2=3DPROVIDER 3=3DMNT */ __state_lock echo "${1} ${2} ${3}" >> ${STATE} __state_unlock } __state_remove() { # /* 1=3DMNT 2=3DSTATE 3=3DLINE */ LINE=3D$( grep -n -E "${1}$" ${2} | cut -d : -f 1 ) sed -i '' ${3}d ${2} } __log() { # /* @=3DMESSAGE */ echo $( date +"${DATEFMT}" ) ${@} >> ${LOG} } case ${2} in (attach) for I in /dev/${1}* do case $( file -L -s ${I} ) in (*NTFS*) __create_mount_point ${I} ntfs-3g ${I} ${MNT} # /* sysutils/fusefs-ntfs */ __log "${I}:mount (ntfs)" ;; (*FAT*) __create_mount_point ${I} fsck_msdosfs -y ${I} mount_msdosfs -o large -o longnames -l -L pl_PL.ISO8859-2 -D cp85= 2 ${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 < ${O} count=3D1 | 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 " ${MNT} " | awk '{printf $1}' ) ${M= NT} done ;; (detach) MOUNTED=3D$( mount ) __state_lock while read DEV PROVIDER MNT do TARGET=3D$( echo "${MOUNTED}" | 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} __state_unlock __log "/dev/${1}:detach" ;; esac PS. Below are links for 'mirror' threads. http://forums.freebsd.org/showthread.php?t=3D29895 http://daemonforums.org/showthread.php?t=3D6838 Regards, vermaden ---