From owner-freebsd-hackers@FreeBSD.ORG Sat Feb 18 20:20:57 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 807A61065674 for ; Sat, 18 Feb 2012 20:20:57 +0000 (UTC) (envelope-from lars@e-new.0x20.net) Received: from mail.0x20.net (mail.0x20.net [IPv6:2001:aa8:fffb:1::3]) by mx1.freebsd.org (Postfix) with ESMTP id D55078FC22 for ; Sat, 18 Feb 2012 20:20:56 +0000 (UTC) Received: from mail.0x20.net (mail.0x20.net [217.69.76.211]) by mail.0x20.net (Postfix) with ESMTP id 70F446A6648; Sat, 18 Feb 2012 21:20:55 +0100 (CET) X-Virus-Scanned: amavisd-new at mail.0x20.net Received: from mail.0x20.net ([217.69.76.211]) by mail.0x20.net (mail.0x20.net [217.69.76.211]) (amavisd-new, port 10024) with ESMTP id fN9cuwnWfKWo; Sat, 18 Feb 2012 21:20:55 +0100 (CET) Received: from e-new.0x20.net (mail.0x20.net [IPv6:2001:aa8:fffb:1::3]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.0x20.net (Postfix) with ESMTPS id 1DEDB6A6647; Sat, 18 Feb 2012 21:20:55 +0100 (CET) Received: from e-new.0x20.net (localhost [127.0.0.1]) by e-new.0x20.net (8.14.4/8.14.4) with ESMTP id q1IKKshJ078834; Sat, 18 Feb 2012 21:20:54 +0100 (CET) (envelope-from lars@e-new.0x20.net) Received: (from lars@localhost) by e-new.0x20.net (8.14.4/8.14.4/Submit) id q1IKKsaD078550; Sat, 18 Feb 2012 21:20:54 +0100 (CET) (envelope-from lars) Date: Sat, 18 Feb 2012 21:20:54 +0100 From: Lars Engels To: Uffe Jakobsen Message-ID: <20120218202054.GK14469@e-new.0x20.net> References: <4F3EE186.4020801@gmail.com> <201202181409.08859.hselasky@c2i.net> <4F3FDA8F.7080807@uffe.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Ah40dssYA/cDqAW1" Content-Disposition: inline In-Reply-To: <4F3FDA8F.7080807@uffe.org> X-Editor: VIM - Vi IMproved 7.3 X-Operation-System: FreeBSD 8.2-RELEASE-p3 User-Agent: Mutt/1.5.21 (2010-09-15) X-Mailman-Approved-At: Sat, 18 Feb 2012 20:26:59 +0000 Cc: freebsd-hackers@freebsd.org, vermaden Subject: Re: 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: Sat, 18 Feb 2012 20:20:57 -0000 --Ah40dssYA/cDqAW1 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Feb 18, 2012 at 06:06:23PM +0100, Uffe Jakobsen wrote: >=20 >=20 > 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=3D/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin > >> MNTPREFIX=3D"/media" > >> 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"${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=3DDEV 2=3DPROVIDER 3=3DMNT */ > >> __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=3DMNT 2=3DSTATE 3=3DLINE */ > >> BSMNT=3D$( echo ${1} | sed 's/\//\\\//g' ) > >> sed -i '' "/${BSMNT}\$/d" ${2} > >> } > >> > >> __log() { # /* @=3DMESSAGE */ > >> 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=3D1 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=3D1 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=3D1 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=3D$( mount ) > >> __state_lock > >> grep ${1} ${STATE} \ > >> > >> | while read DEV PROVIDER MNT > >> > >> do > >> TARGET=3D$( 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 > >> ;; > >> > >> esac > >> > >>> 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? > > >=20 > Nice, >=20 > Some comments: >=20 > Instead of requiring modification to /etc/devd.conf why not just put a=20 > "plugin" conf-file in /etc/devd/ - well even better put in=20 > /usr/local/etc/devd/ - that way your devd.conf modifications are not=20 > lost upon patching/updating base os. >=20 > There is an existing port called "automounter" by Dominic Fandrey which= =20 > is much similar to your work. >=20 > You can get inspired of how he places his devd.conf in /usr/local/etc/dev= d/ > His "automounter" also works with disk labels (as found in /dev/ufs/ and= =20 > /dev/msdosfs/ etc) >=20 > You should consider make a port out of your work. And please don't hardcode polish locales in mount_msdosfs :-) --Ah40dssYA/cDqAW1 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (FreeBSD) iEYEARECAAYFAk9ACCYACgkQKc512sD3afiYdgCfVrqmbXw8NMRQfdq4BvDQtGbd EE8An1oxGxkJHj9kBj1SEq/IAF7wKPY5 =rfsh -----END PGP SIGNATURE----- --Ah40dssYA/cDqAW1--