Re: How to auto-detect a USB drive?

2009-03-12 Thread Peter Steele
I do something like this. Here's the rules I have 
in /usr/local/etc/devd.conf 
... 
 attach 10 { 
 match device-name umass0; 
 action sleep 2; /root/bin/usbstick_attach  /dev/console; 
}; 

I've tried something similar and I'm having good success. I should be able 
accomplish what I need with this approach. 

One question: Is there a way to check the label of a device before mounting it? 
I assume so, since when I insert a FAT32 formatted USB stick I see the 
messages: 

Mar 12 10:29:05 r02s17 kernel: GEOM_LABEL: Label for provider da0s1 is 
msdosfs/MAXIFS. 
Mar 12 10:29:06 r02s17 kernel: GEOM_LABEL: Label msdosfs/MAXIFS removed. 

Can I easily get this same information? 

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


How to auto-detect a USB drive?

2009-03-11 Thread Peter Steele
I want to have a process running on my FreeBSD box that automatically detects 
when a USB drive is inserted. What's the easiest way to accomplish this? I know 
I could simply monitor /var/log/messages and look for the appropriate events to 
appear, but is there a more elegant way? 


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


Re: How to auto-detect a USB drive?

2009-03-11 Thread Polytropon
On Wed, 11 Mar 2009 07:42:04 -0700 (PDT), Peter Steele pste...@maxiscale.com 
wrote:
 I want to have a process running on my FreeBSD box that
 automatically detects when a USB drive is inserted. What's
 the easiest way to accomplish this? I know I could simply
 monitor /var/log/messages and look for the appropriate
 events to appear, but is there a more elegant way? 

The system will monitor it itself. :-)

My question to you would be: What exactly do you mean by
automatically detect? The drive *is* automatically detected.
Should it be mounted afterwards?

The creation of the device files (after system startup) is
controlled by the file /etc/devfs.rules.

You can use automounters to automatically mount devices when
they appear. In order how to determine file systems, slices
and partitions on such an USB device, you could, for example,
have a look at how FreeSBIE does it.

Additionally, there are already tools integrated in KDE and
Gnome that automount USB devices.


-- 
Polytropon
From Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: How to auto-detect a USB drive?

2009-03-11 Thread Wojciech Puchar

devd.conf

On Wed, 11 Mar 2009, Peter Steele wrote:


I want to have a process running on my FreeBSD box that automatically detects 
when a USB drive is inserted. What's the easiest way to accomplish this? I know 
I could simply monitor /var/log/messages and look for the appropriate events to 
appear, but is there a more elegant way?


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



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


Re: How to auto-detect a USB drive?

2009-03-11 Thread Peter Steele
My question to you would be: What exactly do you mean by 
automatically detect? The drive *is* automatically detected. 
Should it be mounted afterwards? 

Yeah, I guess my wording was a little vague. I know that the system 
automatically detects when a USB drive is inserted, and creates the appropriate 
entries under /dev. I want to follow this up with having the drive 
automatically mounted, and I'll then examine the USB drive for specific files I 
expect to be present, and possible run something that's installed on the disk, 
then unmount the disk. We want to use this approach to deploy our software on 
large clusters of machines that may not have an IP identity. 

You can use automounters to automatically mount devices when 
they appear. In order how to determine file systems, slices 
and partitions on such an USB device, you could, for example, 
have a look at how FreeSBIE does it. 

If I can hook into an event that signals when a USB disk is inserted, I can 
take care of verifying the disk is in the format we expect it to be. 

Additionally, there are already tools integrated in KDE and 
Gnome that automount USB devices. 

Our boxes have no GUI so these may not work for us. We have a more specific 
application though and do not need a general purpose automounter. 

-- 
Polytropon 
From Magdeburg, Germany 
Happy FreeBSD user since 4.0 
Andra moi ennepe, Mousa, ... 
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: How to auto-detect a USB drive?

2009-03-11 Thread Peter Steele
This looks like it will do exactly what I need. Thanks for the pointer! 

- Original Message - 
From: Wojciech Puchar woj...@wojtek.tensor.gdynia.pl 
To: Peter Steele pste...@maxiscale.com 
Cc: questi...@freebsd.org 
Sent: Wednesday, March 11, 2009 8:08:20 AM GMT -08:00 US/Canada Pacific 
Subject: Re: How to auto-detect a USB drive? 

devd.conf 

On Wed, 11 Mar 2009, Peter Steele wrote: 

 I want to have a process running on my FreeBSD box that automatically detects 
 when a USB drive is inserted. What's the easiest way to accomplish this? I 
 know I could simply monitor /var/log/messages and look for the appropriate 
 events to appear, but is there a more elegant way? 
 
 
 ___ 
 freebsd-questions@freebsd.org mailing list 
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions 
 To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org 
 
 
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: How to auto-detect a USB drive?

2009-03-11 Thread Roland Smith
On Wed, Mar 11, 2009 at 08:10:46AM -0700, Peter Steele wrote:
 My question to you would be: What exactly do you mean by 
 automatically detect? The drive *is* automatically detected. 
 Should it be mounted afterwards? 
 
 Yeah, I guess my wording was a little vague. I know that the system
 automatically detects when a USB drive is inserted, and creates the
 appropriate entries under /dev. I want to follow this up with having
 the drive automatically mounted, and I'll then examine the USB drive
 for specific files I expect to be present, and possible run something
 that's installed on the disk, then unmount the disk. We want to use
 this approach to deploy our software on large clusters of machines
 that may not have an IP identity.

The easiest way (I think) is to use devd, in combination with a USB
drive that has a unique label.

Say you have a USB drive formatted with a UFS filesystem. You use
'tunefs -L' to give this drive a unique label,
e.g. 'FOO'. Then you can put the following in /etc/devd.conf

notify 1000 {
match   systemDEVFS;
match   subsystem CDEV;
match   cdev  /dev/ufs/FOO;
action  sh /usr/local/sbin/autorun /dev/ufs/FOO ;
};

Where the script /usr/local/sbin/autorun would contain the required actions
(mount, check, run, umount, beep).

The reason for using a labeled device is that you might not want to run
the script on any old USB drive! If you want to use a FAT formatted
drive you should use /dev/msdosfs/FOO for the path.

Last week I submitted a patch to get this system and subsystem
documented in the manual page of devd.conf. It should be in CURRENT now,
and will be MFC'd to STABLE in a week or so.

Roland
-- 
R.F.Smith   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)


pgpktjpteoFPZ.pgp
Description: PGP signature


Re: How to auto-detect a USB drive?

2009-03-11 Thread Peter Steele
 Last week I submitted a patch to get this system and subsystem 
documented in the manual page of devd.conf. It should be in CURRENT now, 
and will be MFC'd to STABLE in a week or so. 

This looks like exactly what we need, except we're using 7.0, and are too close 
to releasing 1.0 of our software to make a switch to 7.1 now (QA would want to 
run weeks of testing). 

What are the issues with devd and 7.0? 

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


Re: How to auto-detect a USB drive?

2009-03-11 Thread Roland Smith
On Wed, Mar 11, 2009 at 10:49:18AM -0700, Peter Steele wrote:
  Last week I submitted a patch to get this system and subsystem
  documented in the manual page of devd.conf. It should be in CURRENT now,
  and will be MFC'd to STABLE in a week or so.
 
  This looks like exactly what we need, except we're using 7.0, and are
  too close to releasing 1.0 of our software to make a switch to 7.1
  now (QA would want to run weeks of testing).
 
  What are the issues with devd and 7.0?

It's missing the call to devctl_notify in the devfs handling. This was
added to RELENG_7 on the 28th of May 2008.  You'll need at least
rev. 1.208.2.4 of /usr/src/sys/kern/kern_conf.c. See:
http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/kern/kern_conf.c?f=uonly_with_tag=RELENG_7logsort=date

Roland
-- 
R.F.Smith   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)


pgpSm2i7ZRcDO.pgp
Description: PGP signature


Re: How to auto-detect a USB drive?

2009-03-11 Thread Mike Clarke
On Wednesday 11 March 2009, Peter Steele wrote:

 Yeah, I guess my wording was a little vague. I know that the system
 automatically detects when a USB drive is inserted, and creates the
 appropriate entries under /dev. I want to follow this up with having
 the drive automatically mounted, and I'll then examine the USB drive
 for specific files I expect to be present, and possible run something
 that's installed on the disk, then unmount the disk. We want to use
 this approach to deploy our software on large clusters of machines
 that may not have an IP identity.

I do something like this. Here's the rules I have 
in /usr/local/etc/devd.conf

#-
#
# Generic USB devices
#
attach 10 {
match device-name umass0;
action sleep 2; /root/bin/usbstick_attach  /dev/console;
};
#
# Cameras
#
attach 20 {
match device-name umass0;
match  vendor 0x(07b4|04b0);
action /bin/sleep 2  mount -t msdosfs /dev/da0s1 /camera 
 /root/bin/camcopy  umount /camera  echo ^G  /dev/console;
};
#-

For most USB storage devices /root/bin/usbstick_attach parses the output 
of `camcontrol devlist` looking for entries like (da*,pass*) or 
(pass*,da*) and then it sets the permissions on the device to 660 and, 
for convenience, creates a link called usbstick in the dev directory 
pointing to the real device. This way the I can always 
mount /dev/usbstick on one of my own subdirectories without having to 
determine what device was created. I could have made the script mount 
the USB stick but if I have to make the effort to mount it myself I 
might be more likely to remember to unmount it afterwards.

The cameras are a special case since all I want to do is to check for 
new photos and copy them to my photo archive so if devd detects one of 
my cameras it mounts the camera with the higher priority attach 20 
rule which invokes /root/bin/camcopy to copy the photos before 
unmounting the camera and sounding the console bell to let me know I 
can unplug it.

The scripts are a bit primitive and get totally confused if I insert 
more than one USB storage device at a time so would need some 
refinement for general use but work OK for me as the only user on this 
PC.

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


Re: How to auto-detect a USB drive?

2009-03-11 Thread Peter Steele
It's missing the call to devctl_notify in the devfs handling. This was 
added to RELENG_7 on the 28th of May 2008. You'll need at least 
rev. 1.208.2.4 of /usr/src/sys/kern/kern_conf.c. See: 
http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/kern/kern_conf.c?f=uonly_with_tag=RELENG_7logsort=date
 

Looks like were out of luck then. Our version is 1.208.2.1 from circa 
2007/12/07. I assume we can't just replace this one file with the latest 
version? We simply cannot move to 7.1 at this point. We have some substantial 
kernel mods that would need to be ported and tested in the 7.1 code base and 
there simply isn't time for that. 


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


Re: How to auto-detect a USB drive?

2009-03-11 Thread Roland Smith
On Wed, Mar 11, 2009 at 10:49:18AM -0700, Peter Steele wrote:
  Last week I submitted a patch to get this system and subsystem
  documented in the manual page of devd.conf. It should be in CURRENT now,
  and will be MFC'd to STABLE in a week or so.
 
  This looks like exactly what we need, except we're using 7.0, and are
  too close to releasing 1.0 of our software to make a switch to 7.1
  now (QA would want to run weeks of testing).

An alternative solution is to run a script from a cron job that checks
for the labeled device and performs the necessary actions if found.

It could mean that you have to wait up to a minute (the minimum
granularity of cron) for the process to start. You have to make sure
that the script fails gracefully if it is started while a previous
instance is still running!

Roland
-- 
R.F.Smith   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)


pgplYcLWbu2Ah.pgp
Description: PGP signature


Re: How to auto-detect a USB drive?

2009-03-11 Thread Peter Steele
 The scripts are a bit primitive and get totally confused if I insert 
more than one USB storage device at a time so would need some 
refinement for general use but work OK for me as the only user on this 
PC. 

Thanks, I'll give this a try and see how it works. We have a very simple 
requirement as well so something primitive will be enough, as long as it works. 

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


Re: How to auto-detect a USB drive?

2009-03-11 Thread Roland Smith
On Wed, Mar 11, 2009 at 06:09:24PM +, Mike Clarke wrote:
snip 
 The scripts are a bit primitive and get totally confused if I insert 
 more than one USB storage device at a time so would need some 
 refinement for general use but work OK for me as the only user on this 
 PC.

If you give the msdosfs filesystem a unique label (with e.g. mlabel from
emulators/mtools), you'll get a unique device in /dev/msdosfs/.

Roland
-- 
R.F.Smith   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)


pgpGZFmxDKnA1.pgp
Description: PGP signature


Re: How to auto-detect a USB drive?

2009-03-11 Thread Roland Smith
On Wed, Mar 11, 2009 at 11:13:08AM -0700, Peter Steele wrote:
  It's missing the call to devctl_notify in the devfs handling. This was
  added to RELENG_7 on the 28th of May 2008.  You'll need at least
  rev. 1.208.2.4 of /usr/src/sys/kern/kern_conf.c. See:
  
 http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/kern/kern_conf.c?f=uonly_with_tag=RELENG_7logsort=date
 
  Looks like were out of luck then. Our version is 1.208.2.1 from circa
  2007/12/07. I assume we can't just replace this one file with the
  latest version? 

It might work. You'd have to look around in the CVS database
[cvsweb.freebsd.org] to see if the changes in question touch other files
as well.

 We simply cannot move to 7.1 at this point. We have
 some substantial kernel mods that would need to be ported and tested
 in the 7.1 code base and there simply isn't time for that.

Then try another solution: a cron job, as explained in another msg.

Roland
-- 
R.F.Smith   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)


pgp6jwfUunvQW.pgp
Description: PGP signature


Re: How to auto-detect a USB drive?

2009-03-11 Thread Peter Steele
Then try another solution: a cron job, as explained in another msg. 

Yeah, that's probably the simplest approach. This was my first thought, but I 
figured there'd be a more elegant way of doing it if I could tie into the drive 
insert event 

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


Re: How to auto-detect a USB drive?

2009-03-11 Thread Mike Clarke
On Wednesday 11 March 2009, Roland Smith wrote:

 If you give the msdosfs filesystem a unique label (with e.g. mlabel
 from emulators/mtools), you'll get a unique device in /dev/msdosfs/.

Yes, but sometimes I'll be transferring data to or from someone else's 
USB stick so I can't make any assumptions about how the filesystem has 
been labeled.

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