Fix a bug when ATIME is enabled.

This commit is contained in:
Slawomir Wojciech Wojtczak (vermaden) 2013-03-06 10:01:46 +01:00
parent 1db4bf70e4
commit 6475a583f3
1 changed files with 51 additions and 41 deletions

View File

@ -118,7 +118,7 @@ EOF
if [ "${1}" = "--version" ] if [ "${1}" = "--version" ]
then then
echo "automount 1.4.2 2013/02/15" echo "automount 1.4.3 2013/03/06"
exit 0 exit 0
fi fi
@ -162,17 +162,23 @@ __create_mount_point() { # 1=DEV
} }
__state_add() { # 1=DEV 2=PROVIDER 3=MNT __state_add() { # 1=DEV 2=PROVIDER 3=MNT
if grep -E "${3}$" ${STATE} 1> /dev/null 2> /dev/null if [ -f ${STATE} ]
then then
__log "${1}: duplicated '${STATE}'" if grep -E "${3}$" ${STATE} 1> /dev/null 2> /dev/null
exit 0 then
__log "${1}: duplicated '${STATE}'"
exit 0
fi
fi fi
echo "${1} ${2} ${3}" >> ${STATE} echo "${1} ${2} ${3}" >> ${STATE}
} }
__state_remove() { # 1=MNT __state_remove() { # 1=MNT
BSMNT=$( echo ${1} | sed 's/\//\\\//g' ) # backslash the slashes ;) if [ -f ${STATE} ]
sed -i '' "/${BSMNT}\$/d" ${STATE} then
BSMNT=$( echo ${1} | sed 's/\//\\\//g' ) # backslash the slashes ;)
sed -i '' "/${BSMNT}\$/d" ${STATE}
fi
} }
__remove_dir() { # 1=TARGET __remove_dir() { # 1=TARGET
@ -250,7 +256,7 @@ case ${2} in
__check_already_mounted -m ${MNT} __check_already_mounted -m ${MNT}
if [ "${ATIME}" = NO ] if [ "${ATIME}" = NO ]
then then
OPTS="noatime" OPTS="-o noatime"
fi fi
__wait_for_device ${DEV} __wait_for_device ${DEV}
case $( file -b -L -s ${DEV} | sed -E 's/label:\ \".*\"//g' ) in case $( file -b -L -s ${DEV} | sed -E 's/label:\ \".*\"//g' ) in
@ -263,12 +269,12 @@ case ${2} in
__log "${DEV}: fsck_msdosfs ${LINE}" __log "${DEV}: fsck_msdosfs ${LINE}"
done done
__wait_for_device ${DEV} __wait_for_device ${DEV}
if mount_msdosfs -o large -D ${CODEPAGE} -L ${ENCODING} \ if mount_msdosfs ${OPTS} -o large -D ${CODEPAGE} -L ${ENCODING} \
-m 644 -M 755 ${DEV} ${MNT} -m 644 -M 755 ${DEV} ${MNT}
then then
ADD=1 ADD=1
else else
__log "${DEV}: mount failed (fat) 'mount_msdosfs -o large -D ${CODEPAGE} -L ${ENCODING} -m 644 -M 755 ${DEV} ${MNT}'" __log "${DEV}: mount failed (fat) 'mount_msdosfs ${OPTS} -o large -D ${CODEPAGE} -L ${ENCODING} -m 644 -M 755 ${DEV} ${MNT}'"
exit 1 exit 1
fi fi
__log "${DEV}: mount (fat)" __log "${DEV}: mount (fat)"
@ -279,23 +285,24 @@ case ${2} in
if which ntfs-3g 1> /dev/null 2> /dev/null # sysutils/fusefs-ntfs if which ntfs-3g 1> /dev/null 2> /dev/null # sysutils/fusefs-ntfs
then then
__wait_for_device ${DEV} __wait_for_device ${DEV}
if ntfs-3g -o ${OPTS} ${DEV} ${MNT}
if ntfs-3g ${OPTS} ${DEV} ${MNT}
then then
ADD=1 ADD=1
else else
__log "${DEV}: mount failed (ntfs) 'ntfs-3g -o ${OPTS} ${DEV} ${MNT}'" __log "${DEV}: mount failed (ntfs) 'ntfs-3g ${OPTS} ${DEV} ${MNT}'"
exit 1 exit 1
fi fi
else else
if ! [ "${USER}" = 0 ] if ! [ "${USER}" = 0 ]
then then
OPTS="-u ${USER} -g $( id -g -n ${USER} )" OPTS="${OPTS} -u ${USER} -g $( id -g -n ${USER} )"
fi fi
if mount_ntfs ${OPTS} -o noatime ${DEV} ${MNT} if mount_ntfs ${OPTS} ${DEV} ${MNT}
then then
ADD=1 ADD=1
else else
__log "${DEV}: mount failed (ntfs) 'ntfs-3g -o ${OPTS} ${DEV} ${MNT}'" __log "${DEV}: mount failed (ntfs) 'ntfs-3g ${OPTS} ${DEV} ${MNT}'"
exit 1 exit 1
fi fi
fi fi
@ -310,11 +317,11 @@ case ${2} in
__log "${DEV}: fsck.ext2 ${LINE}" __log "${DEV}: fsck.ext2 ${LINE}"
done done
__wait_for_device ${DEV} __wait_for_device ${DEV}
if mount -t ext2fs -o ${OPTS} ${DEV} ${MNT} if mount -t ext2fs ${OPTS} ${DEV} ${MNT}
then then
ADD=1 ADD=1
else else
__log "${DEV}: mount failed (ext2) 'mount -t ext2fs -o ${OPTS} ${DEV} ${MNT}'" __log "${DEV}: mount failed (ext2) 'mount -t ext2fs ${OPTS} ${DEV} ${MNT}'"
exit 1 exit 1
fi fi
__log "${DEV}: mount (ext2)" __log "${DEV}: mount (ext2)"
@ -328,11 +335,11 @@ case ${2} in
__log "${DEV}: fsck.ext3 ${LINE}" __log "${DEV}: fsck.ext3 ${LINE}"
done done
__wait_for_device ${DEV} __wait_for_device ${DEV}
if mount -t ext2fs -o ${OPTS} ${DEV} ${MNT} if mount -t ext2fs ${OPTS} ${DEV} ${MNT}
then then
ADD=1 ADD=1
else else
__log "${DEV}: mount failed (ext3) 'mount -t ext2fs -o ${OPTS} ${DEV} ${MNT}'" __log "${DEV}: mount failed (ext3) 'mount -t ext2fs ${OPTS} ${DEV} ${MNT}'"
exit 1 exit 1
fi fi
__log "${DEV}: mount (ext3)" __log "${DEV}: mount (ext3)"
@ -364,11 +371,11 @@ case ${2} in
__log "${DEV}: fsck_ufs ${LINE}" __log "${DEV}: fsck_ufs ${LINE}"
done done
__wait_for_device ${DEV} __wait_for_device ${DEV}
if mount -t ufs -o ${OPTS} ${DEV} ${MNT} if mount -t ufs ${OPTS} ${DEV} ${MNT}
then then
ADD=1 ADD=1
else else
__log "${DEV}: mount failed (ufs) 'mount -t ufs -o ${OPTS} ${DEV} ${MNT}'" __log "${DEV}: mount failed (ufs) 'mount -t ufs ${OPTS} ${DEV} ${MNT}'"
exit 1 exit 1
fi fi
__log "${DEV}: mount (ufs)" __log "${DEV}: mount (ufs)"
@ -378,11 +385,11 @@ case ${2} in
(*EXFAT*) (*EXFAT*)
__create_mount_point ${DEV} __create_mount_point ${DEV}
__wait_for_device ${DEV} __wait_for_device ${DEV}
if mount.exfat -o ${OPTS} ${DEV} ${MNT} # sysutils/fusefs-exfat if mount.exfat ${OPTS} ${DEV} ${MNT} # sysutils/fusefs-exfat
then then
ADD=1 ADD=1
else else
__log "${DEV}: mount failed (exfat) 'mount.exfat -o ${OPTS} ${DEV} ${MNT}'" __log "${DEV}: mount failed (exfat) 'mount.exfat ${OPTS} ${DEV} ${MNT}'"
exit 1 exit 1
fi fi
__log "${DEV}: mount (exfat)" __log "${DEV}: mount (exfat)"
@ -407,25 +414,28 @@ case ${2} in
(detach) (detach)
__log "${DEV}: detach" __log "${DEV}: detach"
grep -E "${MNTPREFIX}/${1}$" ${STATE} \ if [ -f ${STATE} ]
| while read DEV PROVIDER MNT then
do grep -E "${MNTPREFIX}/${1}$" ${STATE} \
TARGET=$( mount | grep -E "^${PROVIDER} " | awk '{print $3}' ) | while read DEV PROVIDER MNT
__state_remove ${MNT} do
if [ -z ${TARGET} ] TARGET=$( mount | grep -E "^${PROVIDER} " | awk '{print $3}' )
then __state_remove ${MNT}
continue if [ -z ${TARGET} ]
fi then
( # put entire umount/find/rm block into background continue
umount -f ${TARGET} fi
__remove_dir "${TARGET}" ( # put entire umount/find/rm block into background
__log "${DEV}: removed '${TARGET}'" umount -f ${TARGET}
) & __remove_dir "${TARGET}"
unset TARGET __log "${DEV}: removed '${TARGET}'"
__log "${DEV}: umount" ) &
done unset TARGET
__remove_dir "${MNTPREFIX}/${1}" __log "${DEV}: umount"
__log "${DEV}: mount point '${MNTPREFIX}/${1}' removed" done
__remove_dir "${MNTPREFIX}/${1}"
__log "${DEV}: mount point '${MNTPREFIX}/${1}' removed"
fi
;; ;;
esac esac