Date: Fri, 17 Feb 2012 18:49:17 +0100 From: vermaden <vermaden@interia.pl> To: freebsd-hackers@freebsd.org, freebsd-current@freebsd.org, freebsd-stable@FreeBSD.org Subject: devd based AUTOMOUNTER Message-ID: <hkubftdrahxmtuzcfqzh@ziad>
next in thread | raw e-mail | index | archive | help
Hi,
I have finally made some effort on writing flexible yet very simple automou=
nter 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 logs =
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 end 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 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}
done
;;
(detach)
MOUNTED=3D$( mount )
__state_lock
while read DEV PROVIDER MNT
do
TARGET=3D$( echo "${MOUNTED}" | 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}
__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
---
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?hkubftdrahxmtuzcfqzh>
