Re: devd based AUTOMOUNTER

2012-02-21 Thread vermaden
Hi, 

I have created a PORT at last, its in the 'port' directory in the usual place:

https://github.com/vermaden/automount/

Its my first PORT so feel free to bash me about my mistakes ;)

After latest 'commits' I think that its ready for day-to-day use.

To make 'full advantage' of *automount* install these ports:

sysutils/ntfsprogs
sysutils/fusefs-ntfs
sysutils/fusefs-ext4fuse
sysutils/fusefs-exfat

I will try to add these ports as OPTIONS in the Makefile later.

I will have to think about creating a man page through ...

Feel free to submit Your propositions about next changes/development,
because I think that I already created everything 'I' needed. 

Regards,
vermaden





























---
 
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: devd based AUTOMOUNTER

2012-02-20 Thread Andriy Gapon

[cc list trimmed]

Hey, this seems like a quite nice tool.
Can you create a web-page and/or port for it?  It would be more convenient to
follow its development that way.
Thank you!

on 20/02/2012 10:43 vermaden said the following:
 Hi,
 
 new version with new features (and BUGs ;p)
 
 Added check if ntfsfix from sysutils/ntfsprogs is available, if Yes then
 try to fix the NTFS filesystem before mouting it.
 
 Added GPL3 License ... just joking ;) ... added FreeBSD License to the file.
 
 Added 'noatime' as a default mount option when possible.
 
 Added TIMEOUT so when an 'orphan' STATE file lock remains, it will be deleted 
 after a TIMEOUT.
 
 Added /usr/local/etc/devd/automount.devd file instead of messing with the 
 base system config at /etc/devd.conf.
 
 Added config file to be used from /usr/local/etc/automount.conf file, 
 possible options are (these are defaults):
   MNTPREFIX=/media
   LOG=/var/log/automount.log
   STATE=/var/run/automount.state
   ENCODING=en_US.ISO8859-1
   CODEPAGE=cp437
   DATEFMT=%Y-%m-%d %H:%M:%S
   USERUMOUNT=NO
 
 Mine config currently has only these:
   ENCODING=pl_PL.ISO8859-2
   CODEPAGE=cp852
   USERUMOUNT=YES
 
 The USERMOUNT otions if set to YES (default to NO) will 'chmod +s 
 /sbin/umount',
 so You can click the ^ button on the devices list in NAUTILUS.
 
 These newly mounted devices appear on NAUTILUS sidebar (only with /media 
 prefix).
 
 But THUNAR and PCMANFM does not do that, You know any other FMs that display 
 mounted thumb drives/devices?
 
 EXAMPLE: http://i.imgur.com/qdKdl.png
 
 First BUG: (not fixed yet, but workaround already is working)
 
 TEST/BUG/CASE:
 Plug in FAT32 and NTFS drives at the same time, when FAT32 device will be 
 detected first, it will get mounted and the NTFS drive will be mounted TWICE, 
 so I added __check_already_mounted function to check if it is not already 
 mounted.
 
 
 
 Below are current script and config files.


-- 
Andriy Gapon
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: devd based AUTOMOUNTER

2012-02-20 Thread Ivan Klymenko
В Mon, 20 Feb 2012 09:43:59 +0100
vermaden verma...@interia.pl пишет:

 Hi,
 
 new version with new features (and BUGs ;p)
 
 Added check if ntfsfix from sysutils/ntfsprogs is available, if Yes
 then try to fix the NTFS filesystem before mouting it.
 
 Added GPL3 License ... just joking ;) ... added FreeBSD License to
 the file.
 
 Added 'noatime' as a default mount option when possible.
 
 Added TIMEOUT so when an 'orphan' STATE file lock remains, it will be
 deleted after a TIMEOUT.
 
 Added /usr/local/etc/devd/automount.devd file instead of messing with
 the base system config at /etc/devd.conf.
 
 Added config file to be used from /usr/local/etc/automount.conf file,
 possible options are (these are defaults): MNTPREFIX=/media
   LOG=/var/log/automount.log
   STATE=/var/run/automount.state
   ENCODING=en_US.ISO8859-1
   CODEPAGE=cp437
   DATEFMT=%Y-%m-%d %H:%M:%S
   USERUMOUNT=NO
 
 Mine config currently has only these:
   ENCODING=pl_PL.ISO8859-2
   CODEPAGE=cp852
   USERUMOUNT=YES
 
 The USERMOUNT otions if set to YES (default to NO) will 'chmod
 +s /sbin/umount', so You can click the ^ button on the devices list
 in NAUTILUS.
 
 These newly mounted devices appear on NAUTILUS sidebar (only
 with /media prefix).
 
 But THUNAR and PCMANFM does not do that, You know any other FMs that
 display mounted thumb drives/devices?
 
 EXAMPLE: http://i.imgur.com/qdKdl.png
 
 First BUG: (not fixed yet, but workaround already is working)
 
 TEST/BUG/CASE:
 Plug in FAT32 and NTFS drives at the same time, when FAT32 device
 will be detected first, it will get mounted and the NTFS drive will
 be mounted TWICE, so I added __check_already_mounted function to
 check if it is not already mounted.

Thank you so much!

Could you update, please first post in the forum?
http://forums.freebsd.org/showthread.php?t=29895

Thanks!
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: devd based AUTOMOUNTER

2012-02-20 Thread vermaden
Hi,

new version with new features (and BUGs ;p)

Added check if ntfsfix from sysutils/ntfsprogs is available, if Yes then
try to fix the NTFS filesystem before mouting it.

Added GPL3 License ... just joking ;) ... added FreeBSD License to the file.

Added 'noatime' as a default mount option when possible.

Added TIMEOUT so when an 'orphan' STATE file lock remains, it will be deleted 
after a TIMEOUT.

Added /usr/local/etc/devd/automount.devd file instead of messing with the base 
system config at /etc/devd.conf.

Added config file to be used from /usr/local/etc/automount.conf file, possible 
options are (these are defaults):
  MNTPREFIX=/media
  LOG=/var/log/automount.log
  STATE=/var/run/automount.state
  ENCODING=en_US.ISO8859-1
  CODEPAGE=cp437
  DATEFMT=%Y-%m-%d %H:%M:%S
  USERUMOUNT=NO

Mine config currently has only these:
  ENCODING=pl_PL.ISO8859-2
  CODEPAGE=cp852
  USERUMOUNT=YES

The USERMOUNT otions if set to YES (default to NO) will 'chmod +s /sbin/umount',
so You can click the ^ button on the devices list in NAUTILUS.

These newly mounted devices appear on NAUTILUS sidebar (only with /media 
prefix).

But THUNAR and PCMANFM does not do that, You know any other FMs that display 
mounted thumb drives/devices?

EXAMPLE: http://i.imgur.com/qdKdl.png

First BUG: (not fixed yet, but workaround already is working)

TEST/BUG/CASE:
Plug in FAT32 and NTFS drives at the same time, when FAT32 device will be 
detected first, it will get mounted and the NTFS drive will be mounted TWICE, 
so I added __check_already_mounted function to check if it is not already 
mounted.



Below are current script and config files.

/usr/local/etc/devd/automount.devd
---
notify 0 {
  match system DEVFS;
match type CREATE;
match cdev (da|mmcsd)[0-9]+;
action /usr/local/sbin/automount.sh $cdev attach;
};

notify 0 {
match system DEVFS;
match type DESTROY;
match cdev (da|mmcsd)[0-9]+;
action /usr/local/sbin/automount.sh $cdev detach;
};
---

/usr/local/etc/automout.conf (can be empty)
---
MNTPREFIX=/media
LOG=/var/log/automount.log
STATE=/var/run/automount.state
ENCODING=en_US.ISO8859-1
CODEPAGE=cp437
DATEFMT=%Y-%m-%d %H:%M:%S
USERUMOUNT=NO
---

/usr/local/sbin/automount.sh
---
#! /bin/sh

# Copyright (c) 2011 Slawomir Wojciech Wojtczak (vermaden)
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
#notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#notice, this list of conditions and the following disclaimer in the
#documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS 'AS IS' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

[ -f /usr/local/etc/automount.conf ]  . /usr/local/etc/automount.conf

: ${MNTPREFIX=/media}
: ${LOG=/var/log/automount.log}
: ${STATE=/var/run/automount.state}
: ${ENCODING=en_US.ISO8859-1}   # /* US/Canada */
: ${CODEPAGE=cp437} # /* US/Canada */
: ${DATEFMT=%Y-%m-%d %H:%M:%S}  # /* 2012-02-20 07:49:09 */
: ${USERUMOUNT=NO}  # /* when YES add suid bit to umount(8) */

[ ${USERUMOUNT} = YES ]  chmod u+s /sbin/umount # /* WHEEL group member */

__create_mount_point() { # /* 1=DEV */
  MNT=${MNTPREFIX}/$( basename ${1} )
  mkdir -p ${MNT}
  chown 1000 ${MNT}
}

__check_already_mounted() { # /* 1=MNT */
  mount | grep  ${1}  1 /dev/null 2 /dev/null  {
__log ${I}:already mounted (ntfs)
continue
  }
}

__state_lock() {
  TIMEOUT=60
  COUNT=0
  while [ -f ${STATE}.lock ]
  do
sleep 0.5
[ ${COUNT} -gt ${TIMEOUT} ]  break
COUNT=$(( ${COUNT} + 1 ))
  done
  : ${STATE}.lock
}


Re: devd based AUTOMOUNTER

2012-02-20 Thread vermaden
written by Andriy Gapon ...

 Hey, this seems like a quite nice tool.
 Can you create a web-page and/or port for it?
 It would be more convenient to follow its development that way.
 Thank you!

Sure, its now available here, I will try to create port later:

https://github.com/vermaden/automount



written by Ivan Klymenko ...

 Thank you so much!
Welcome ;)

 Could you update, please first post in the forum?
 http://forums.freebsd.org/showthread.php?t=29895

I will do that after I sent this mail ;)

Regards,
vermaden































...
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: devd based AUTOMOUNTER

2012-02-20 Thread vermaden
written by ${ME} ...

 First BUG: (not fixed yet, but workaround already is working)
 
 TEST/BUG/CASE:
 Plug in FAT32 and NTFS drives at the same time, when FAT32 device
 will be detected first, it will get mounted and the NTFS drive will be
 mounted TWICE, so I added  __check_already_mounted function
 to check if it is not already mounted.

This BUG is fixed, I was in wrong assumption, that the script would
be only executed for /dev/da0 but it was executed for every
device/partition node that appeared separately, like /dev/da0,
/dev/da0s1, /dev/da0s2 etc.

Currently there is no knows bugs, but the prepared earlier
'workaround functions' remain just in case.

As I written before its now available here:
https://github.com/vermaden/automount

Regards,
vermaden


















---
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: devd based AUTOMOUNTER

2012-02-20 Thread vermaden
Hi,

I removed the state_lock and stat_unlock mechanisms as they
appeared to be not needed, I have shufled with 3 drives all
the time and the 'integrity' has not been lost, at it was a lot
faster, because the lock always had to wait for the 'slowest'
drive (in term of initializing the device, like USB hard drive).

I simplified the 'attach' section a lot, now each filesystem
contains only check/fsck (if possible), mount and log info.

I also simplified and improved the 'detach' section a little.

I have added an option to automatically launch the set-up
in config file manager (Yes, like in Windows ;p). 

These are options that I currently successfully use for
NAUTILUS file manager, You need to set-up all three of
them to make it work.

| POPUP=YES
| FM=nautilus --browser --no-desktop
| USER=vermaden

My whole config looks like that now:

| USERUMOUNT=YES
| POPUP=YES
| FM=nautilus --browser --no-desktop
| USER=vermaden
| ENCODING=pl_PL.ISO8859-2
| CODEPAGE=cp852

All latest updates are available at GITHUB:
https://github.com/vermaden/automount



written by Freddie Cash ...

 Konqueror (KDE 3.x and 4.x) and Dolphin (KDE 4.x mainly, but I
 believe there's a KDE 3.x version) also show automatically
 mounted and removable media in the sidebar.  Works nicely
 with HAL.  Haven't tested your script yet, but am intrigued by it.
 Will see if I can test it sometime this week.
 
 Native solutions are so much nicer than ported ones.  :)

Thanks, looking forward to hear some more input about it from You ;)



written by Fernando Apesteguía ...

 What a nice piece of work.

Thanks mate.

 I just downloaded it and try it on a FreeBSD 9.0-RELEASE with
 custom kernel. It works like a charm. I tried three different
 USB devices without noticing any problems (and I was very
 impolite when I unplugged them).
 
 Thanks for this script.

Good to know, try the latest new version from repo, should be even better ;)

Regards,
vermaden
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: devd based AUTOMOUNTER

2012-02-19 Thread vermaden
Hi,

sorry for late response, but I currently have quite a
lot 'weekend activities' that are definitely not near
a computer ;)



written by Gleb Kurtsou ... 
 __state_lock() {
   while [ -f ${STATE}.lock ]; do sleep 0.5; done
   : ${STATE}.lock
 }

 Why not keep it stateless, unmounting by hand would kill integrity.

The state file is needed for automatic umount of fuse-based mounts,
the device that script would be triggered will be /dev/da0 for example
while the 'virtual' device that was actually used for the mount was
/dev/fuse0, that is why I need to track what is mounted and how.

These functions are mostly to keep that 'state file' integral,
to prevent two various event writing at the file simultanously,
which would probable killed the information integrity.

Unmounting the device does not kill integrity at all, I also thought
about that, You may plug the device, do whatever You want, event
change the filesystem there and mount it again, but when You umount
it and unplug it, then the script will umount that device (yes
pointless here at this moment) and remove the entry from state file.

 Usage of `file` is a big security concern.
Can You explain why?

 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.
geom config?

I also make use of the list of mounted filesystems, but the problem
with fuse-based devices remain as I stated earlier.

 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 for sharing, maybe I will find some ideas there ;)



written by Uffe Jakobsen ...

 Nice,
Thanks.

 Instead of requiring modification to /etc/devd.conf why not just
 put a plugin conf-file in /etc/devd/ - well even better put in
 /usr/local/etc/devd/ - that way your devd.conf modifications are
 not lost upon patching/updating base os.
Great advice, I will do that in the next 'release' ;)

 There is an existing port called automounter by Dominic Fandrey
 which is much similar to your work.
Yes but its amd based.

 His automounter also works with disk labels
 (as found in /dev/ufs/ and /dev/msdosfs/ etc)
The labels are only 'an addition' to appearing device nodes at /dev,
Yes it would be nice to see that /dev/msdosfs/BACKUP is mounted
instead of /dev/da0s1, but I will have to make a lot of additional
check to see if that new label is part of that or other device etc.

 You should consider make a port out of your work.
I probably will try to do that, but I think it stil needs polish ;)



written by Lars Engels ...

 And please don't hardcode polish locales in mount_msdosfs :-)

I already changed that, I also plan to create simple config file,
it was just not 'the most important thing' that I was dealing
with at that time, its easy to move options into variables,
its harder to make script work the way it should ;)

But thanks for suggestion, good point.



written by Joe Culler ...

 Thanks for working on it. It works great for me, thanks!
Thanks, good to know ;)

 I have a question, could you export a fusefs-exfat or
 fusefs-ntfs share directory over NFS? I can't get it work.
 If you have a solution, please let me know, thanks.
I will try to do that tomorrow ane let You know.



Regards,
vermaden
































---
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: devd based AUTOMOUNTER

2012-02-18 Thread vermaden
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
}

__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



-- 








































...
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: devd based AUTOMOUNTER

2012-02-18 Thread Hans Petter Selasky
On Saturday 18 February 2012 10:48:11 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
 
 }
 
 __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.
 

Hi,

Should your script be written like an rc.d script, so that one can 
enable/disable this automounting from /etc/rc.conf?

--HPS
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: devd based AUTOMOUNTER

2012-02-18 Thread Gleb Kurtsou
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
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: devd based AUTOMOUNTER

2012-02-17 Thread matt
On 02/17/12 09:49, vermaden wrote:
 Hi,

 I have finally made some effort on writing flexible yet very simple 
 automounter 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=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
 LOG=/var/log/automount.log
 STATE=/var/run/automount.state
 DATEFMT=%Y-%m-%d %H:%M:%S

 __create_mount_point() { # /* 1=DEV */
   MNT=/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=DEV 2=PROVIDER 3=MNT */
   __state_lock
   echo ${1} ${2} ${3}  ${STATE}
   __state_unlock
 }

 __state_remove() { # /* 1=MNT 2=STATE 3=LINE */
   LINE=$( grep -n -E ${1}$ ${2} | cut -d : -f 1 )
   sed -i '' ${3}d ${2}
 }

 __log() { # /* @=MESSAGE */
   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=1 | 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=$( mount )
 __state_lock
 while read DEV PROVIDER MNT
 do
   TARGET=$( 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=29895
 http://daemonforums.org/showthread.php?t=6838

 Regards,
 vermaden
























 ---
 ___
 freebsd-hack...@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
 To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
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 

Re: devd based AUTOMOUNTER

2012-02-17 Thread vermaden
I already made some changes for the 'better' ...

Here is the latest version:

#! /bin/sh

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
LOG=/var/log/automount.log
STATE=/var/run/automount.state
DATEFMT=%Y-%m-%d %H:%M:%S

__create_mount_point() { # /* 1=DEV */
  MNT=/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=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} ) 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=1 | 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} 
|| continue
done
;;

  (detach)
__state_lock
grep ${1} ${STATE} \
  | while read DEV PROVIDER MNT
do
  TARGET=$( 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 
failesystems, connecting them all at once, disconnecting all at once, random 
connect, disconnect etc.

Currently it seems to work ok but suggestions are very welcome.


 Some things to consider/test:
 
 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, but 
its definitely possible.

 What if make a usb drive with an illegal name, existing name or other 
 dangerous 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


-- 








































...
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: devd based AUTOMOUNTER

2012-02-17 Thread vermaden
... even newer version, seems to have all 'problems' fixed now ;)

#! /bin/sh

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
LOG=/var/log/automount.log
STATE=/var/run/automount.state
DATEFMT=%Y-%m-%d %H:%M:%S

__create_mount_point() { # /* 1=DEV */
  MNT=/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=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} ) 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 -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=1 | 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
;;

esac

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org


Re: devd based AUTOMOUNTER

2012-02-17 Thread vermaden
Latest version with additional checks for NTFS and FAT32, to be precise,
for NTFS filesystem with label FAT and for FAT filesystem with label NTFS ;)

#! /bin/sh

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
LOG=/var/log/automount.log
STATE=/var/run/automount.state
DATEFMT=%Y-%m-%d %H:%M:%S

__create_mount_point() { # /* 1=DEV */
  MNT=/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=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}
  ntfs-3g ${I} ${MNT} # /* sysutils/fusefs-ntfs */
  __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
;;

esac


___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to freebsd-current-unsubscr...@freebsd.org