From owner-freebsd-current@FreeBSD.ORG Fri Feb 17 19:23:34 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 21164106566B; Fri, 17 Feb 2012 19:23:34 +0000 (UTC) (envelope-from sendtomatt@gmail.com) Received: from mail-pz0-f54.google.com (mail-pz0-f54.google.com [209.85.210.54]) by mx1.freebsd.org (Postfix) with ESMTP id E23428FC0C; Fri, 17 Feb 2012 19:23:33 +0000 (UTC) Received: by daec6 with SMTP id c6so4051412dae.13 for ; Fri, 17 Feb 2012 11:23:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=JNFCrQKGrkaT1LY0zYq/eN319AXX8rey1lu3yYTaYZQ=; b=MoX1KzhH+plgWobF+Nz896L4FMbcA7TamsH03huceeQmaopzTEjNM16kbUsyfDG2Gs sybStFNFrgDWTIW0v5SrQNWbt/fHpsp8raUwRLPzDiMqvLjABnjfqU2IS9nWtXYb7Y2i SPTk/3h0Sh5jVRMaz6OFWqPHtgeYDVmZ7QLyM= Received: by 10.68.224.2 with SMTP id qy2mr27166201pbc.48.1329506613481; Fri, 17 Feb 2012 11:23:33 -0800 (PST) Received: from bakeneko.local ([75.101.87.90]) by mx.google.com with ESMTPS id k2sm5857682pba.28.2012.02.17.11.23.31 (version=SSLv3 cipher=OTHER); Fri, 17 Feb 2012 11:23:32 -0800 (PST) Message-ID: <4F3EA8F6.6040702@gmail.com> Date: Fri, 17 Feb 2012 11:22:30 -0800 From: matt User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20120111 Thunderbird/9.0 MIME-Version: 1.0 To: vermaden References: In-Reply-To: X-Enigmail-Version: 1.3.4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org, freebsd-current@freebsd.org Subject: Re: devd based AUTOMOUNTER X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Feb 2012 19:23:34 -0000 On 02/17/12 09:49, vermaden wrote: > Hi, > > I have finally made some effort on writing flexible yet very simple aut= omounter 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 l= ogs 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 en= d 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 = 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 < ${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}' )= ${MNT} > done > ;; > > (detach) > MOUNTED=3D$( mount ) > __state_lock > while read DEV PROVIDER MNT > do > TARGET=3D$( echo "${MOUNTED}" | grep -E "^${PROVIDER} " | awk '{p= rint $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 > > > > > > > > > > > > > > > > > > > > > > > > > --- > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.o= rg" Some things to consider/test: How do I set custom flags, like nosuid,noatime,nodev,noexec,async (or sync) for mounts? What if make a usb drive with an illegal name, existing name or other dangerous values? Can I use the automounter to either mount over another mount to impersonate it, or can I overwrite arbitrary files or directories? Some of these above things don't work on Linux with udev (i.e. gnome-vfs automount gets some fairly generous flags automatically) I didn't get a chance to test some of the naming things on Linux either, as many drive formatting programs validate the name. Something to consider, Matt Matt