Re: devd based AUTOMOUNTER

看板FB_current作者時間14年前 (2012/02/18 03:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/16 (看更多)
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 _______________________________________________ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"
文章代碼(AID): #1FFgioU7 (FB_current)
討論串 (同標題文章)
文章代碼(AID): #1FFgioU7 (FB_current)