From owner-freebsd-stable@FreeBSD.ORG Fri Feb 17 20:41:09 2012 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0DC4F1065672; Fri, 17 Feb 2012 20:41:09 +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 7E7058FC1D; Fri, 17 Feb 2012 20:41:08 +0000 (UTC) Date: Fri, 17 Feb 2012 21:41:06 +0100 From: vermaden To: matt X-Mailer: interia.pl/pf09 In-Reply-To: <4F3EA8F6.6040702@gmail.com> References: <4F3EA8F6.6040702@gmail.com> 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=1329511266; bh=ngddleKd97CoYvRfe/1NV/RUwArZ3nb7wf7lqdu+V/w=; h=Date:From:Subject:To:Cc:X-Mailer:In-Reply-To:References: X-Originating-IP:Message-Id:MIME-Version:Content-Type: Content-Transfer-Encoding; b=RJLtUwqxMALnXxOW9du9hD7jxHYCXkE7UFDX1H8B/Y37WXioL9E9iOe5zANpBL9cX RpwBkuUmh/8D7Z9t07+kwzvX3zzc/Dp3Cdx/4yf1kyt5BcmveOB5DpzAv9bnX4RSWv fcU4E/wpXU9MoIrB/KzxzkracUPuqT+lgBhTmIcg= Cc: freebsd-hackers@freebsd.org, freebsd-current@freebsd.org, freebsd-stable@FreeBSD.org Subject: Re: devd based AUTOMOUNTER X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Feb 2012 20:41:09 -0000 I already made some changes for the 'better' ... Here is the latest version: #! /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 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} ) 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} || continue done ;; (detach) __state_lock grep ${1} ${STATE} \ | while read DEV PROVIDER MNT do TARGET=3D$( 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" ;; esac I have made tests with 3 different USB drives, with different and same fail= esystems, connecting them all at once, disconnecting all at once, random co= nnect, disconnect etc. Currently it seems to work ok but suggestions are very welcome. > Some things to consider/test: >=20 > How do I set custom flags, like nosuid,noatime,nodev,noexec,async (or > sync) for mounts? Currently You can add these options to filesystem specific mount command, b= ut its definitely possible. > What if make a usb drive with an illegal name, existing name or other dan= gerous values? The filesystem label is not used at all, I just use device names, which are= reported by FreeBSD, so quite bulletproof here and then create appreciate = /mnt/da0s1 directories. > Can I use the automounter to either mount over another mount to > impersonate it, or can I overwrite arbitrary files or directories? I have done everything to check that and to omit that, if not, then submit = a BUG ;) Thanks for suggestions Matt. Regards, vermaden --=20 ...