From owner-freebsd-hackers@FreeBSD.ORG Sat Feb 18 17:28:13 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 D7044106566B; Sat, 18 Feb 2012 17:28:13 +0000 (UTC) (envelope-from gleb.kurtsou@gmail.com) Received: from mail-lpp01m010-f54.google.com (mail-lpp01m010-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id 26DEA8FC13; Sat, 18 Feb 2012 17:28:12 +0000 (UTC) Received: by lagz14 with SMTP id z14so7242037lag.13 for ; Sat, 18 Feb 2012 09:28:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=PBKAlx46k2x4ueJrx2YXOdyrCBp8k5B/D0Kgf+gCcpE=; b=jCOyAqzwSU32DdZWGZFC+IYGnd5Cfa36GblJeBLI9P/4gErotEK0+/W1U/kZGRxdnu LfuyV0hbTaeZLlD0drdF0XBDqTIqUyGp8wgDBNRulJoqhVyPXAcrtAg8xjLksFqny+z3 4y+Lk0mUwq11RT3HYe8da0ej+YICTkiwDGzCA= Received: by 10.152.130.102 with SMTP id od6mr8395303lab.14.1329584201455; Sat, 18 Feb 2012 08:56:41 -0800 (PST) Received: from localhost ([78.157.92.5]) by mx.google.com with ESMTPS id j4sm16417332lbf.6.2012.02.18.08.56.39 (version=SSLv3 cipher=OTHER); Sat, 18 Feb 2012 08:56:40 -0800 (PST) Date: Sat, 18 Feb 2012 18:56:51 +0200 From: Gleb Kurtsou To: vermaden Message-ID: <20120218165650.GA3552@reks> References: <4F3EA8F6.6040702@gmail.com> <4F3EE186.4020801@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Cc: matt , freebsd-hackers@freebsd.org, freebsd-current@freebsd.org, freebsd-stable@FreeBSD.org 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 17:28:13 -0000 On (18/02/2012 10:48), 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 > } Why not keep it stateless, unmounting by hand would kill integrity. Usage of `file` is a big security concern. I think geom config and list of mounted file systems should be sufficient for collecting information at runtime. Although it may not be that easy for disks without partitioning. I'm using a python script for mounting/unmounting removable disks, but having similar tool written in sh would be great. https://github.com/glk/mmount Thanks, Gleb. > > __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 > ;; > > esac > > > > > Not sure if you've looked at disktype in sysutils > > but it may be useful to you. > > I will get look into that, thanks ;) > > > > > Neat scripts! > > Matt > > Thanks mate. > > > > Regards, > vermaden