Re: Detecting cards in USB card reader

2010-02-10 Thread Mike Clarke
On Sunday 07 February 2010, Nikos Vassiliadis wrote:

 While it may feel dangerous, is perfectly safe. There is no
 way doing an IO operation on a disk-like device using requests
 othen than multiplies of the physical block which currently is
 512 bytes. Opening the disk for writing and trying to do a
 write request, will just force GEOM to re-examine the device.

  lab# echo asd | cat  /dev/da0
  cat: stdout: Invalid argument

 failed

  lab# echo  /dev/da0
  lab# echo $?
  1

 failed

  lab# /bin/echo asd  /dev/da0
  /bin/echo: write: Invalid argument

 failed

 Closer look:
  lab# truss sh -c echo  /dev/da0

 snip

  open(/dev/da0,O_WRONLY|O_CREAT|O_TRUNC,0666)   = 2 (0x2)
  dup2(0x2,0x1,0x1b6,0x108,0x2830d040,0x2830235c) = 1 (0x1)
  close(2) = 0 (0x0)
  write(1,\n,1)  ERR#22 'Invalid
  argument'

 failed

 FreeBSD lost the ability of doing such transparent
 transformations when the support for block devices
 went away.

 Yes, I know, it feels awkward.

 Apparently, you can easily drop the support for block
 devices but not the habitual feeling of danger of UNIX
 tradition.

Thanks for the enlightening information. Although I didn't doubt that 
this was safe I couldn't help feeling that it seemed a wrong thing to 
do - a case of old habits being hard to loose. After seeing your 
explanation I feel much more confident about this.

It does seem a pity though that we have to rely on the side effect of 
having no support for writing to block devices instead of having a 
specific means of detecting or checking for a media change in the card 
reader.

-- 
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: Detecting cards in USB card reader

2010-02-10 Thread Warren Block

On Wed, 10 Feb 2010, Mike Clarke wrote:

It does seem a pity though that we have to rely on the side effect of
having no support for writing to block devices instead of having a
specific means of detecting or checking for a media change in the card
reader.


I agree that attempting a write to an unsuspecting device to signal a 
media change just looks wrong.


usbconfig -d 3.3 reset seemed to work with my Sandisk card reader just 
now.  This is still a side effect, but doesn't look as bad.


-Warren Block * Rapid City, South Dakota USA
___
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: Detecting cards in USB card reader

2010-02-07 Thread Nikos Vassiliadis

On 2/7/2010 1:28 AM, Mike Clarke wrote:

curlew:/root# cat /dev/null  /dev/da0
curlew:/root# ls -l /dev/da0*
crw-r-  1 root  operator0, 176  6 Feb 23:15 /dev/da0
crw-r-  1 root  operator0, 129  6 Feb 23:18 /dev/da0s1

I can use this to initialise the card reader but I'd feel more
comfortable with something a bit less dangerous looking.


While it may feel dangerous, is perfectly safe. There is no
way doing an IO operation on a disk-like device using requests
othen than multiplies of the physical block which currently is
512 bytes. Opening the disk for writing and trying to do a
write request, will just force GEOM to re-examine the device.


lab# echo asd | cat  /dev/da0
cat: stdout: Invalid argument

failed


lab# echo  /dev/da0
lab# echo $?
1

failed


lab# /bin/echo asd  /dev/da0
/bin/echo: write: Invalid argument

failed

Closer look:

lab# truss sh -c echo  /dev/da0

snip

open(/dev/da0,O_WRONLY|O_CREAT|O_TRUNC,0666)   = 2 (0x2)
dup2(0x2,0x1,0x1b6,0x108,0x2830d040,0x2830235c) = 1 (0x1)
close(2) = 0 (0x0)
write(1,\n,1)  ERR#22 'Invalid argument'

failed

FreeBSD lost the ability of doing such transparent
transformations when the support for block devices
went away.

Yes, I know, it feels awkward.

Apparently, you can easily drop the support for block
devices but not the habitual feeling of danger of UNIX
tradition.

HTH, Nikos
___
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


Detecting cards in USB card reader

2010-02-06 Thread Mike Clarke
In an attempt to get round the problem that my Olympus C-2040Z camera 
won't communicate with FreeBSD versions above 6.4 I've installed an 
Akasa AK-ICR-01B internal card reader on my 8.0-RELEASE-p2 system.

The reader is detected when the system boots and device nodes are 
created for da0, da1, da2 and da3. If a card is inserted before booting 
the computer it is detected and the appropriate device node is created 
(e.g. /dev/da0s1) but subsequently inserting a card into a slot which 
was empty fails to create the appropriate device. Playing around with 
camcontrol and restarting devd have no effect either.

After a bit of Googling I found that 'cat /dev/null  /dev/da0' appears 
to be the fix for forcing the creation of /dev/da0s1 after inserting a 
card in the slot associated with da0. Although this gets round the 
problem I can't help feeling uncomfortable about attempting to write to 
raw devices and was wondering if there was any suitable usbconfig or 
HAL incantation which could be used to achieve the desired effect in a 
safer looking way.

-- 
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: Detecting cards in USB card reader

2010-02-06 Thread Polytropon
On Sat, 6 Feb 2010 15:11:11 +, Mike Clarke jmc-freeb...@milibyte.co.uk 
wrote:
 Although this gets round the 
 problem I can't help feeling uncomfortable about attempting to write to 
 raw devices and was wondering if there was any suitable usbconfig or 
 HAL incantation which could be used to achieve the desired effect in a 
 safer looking way.

I can understand this. Maybe accessing the SCSI layer of
the card reader can help? If

% camcontrol reset all

will cause the same effect (of creating the correct nodes in
/dev), you can be more precise (e. g. just reset da0); see

% man camcontrol

for further (and maybe more elegant) details.


-- 
Polytropon
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: Detecting cards in USB card reader

2010-02-06 Thread Mike Clarke
On Saturday 06 February 2010, Polytropon wrote:

 I can understand this. Maybe accessing the SCSI layer of
 the card reader can help? If

 % camcontrol reset all

 will cause the same effect (of creating the correct nodes in
 /dev), you can be more precise (e. g. just reset da0); see

 % man camcontrol

 for further (and maybe more elegant) details.

Neither reset nor rescan have any effect with camcontrol. Without a 
suitable incantation like 'cat /dev/null  /dev/da0' I just 
have /dev/da0 but no /dev/da0s1 after inserting a card. The system 
knows that the media is there, fdisk /dev/da0 can see the slice even, 
but there's no device node for it.

This is what happens after inserting a 16MB card in the reader:

curlew:/root# ls -l /dev/da0*
crw-r-  1 root  operator0, 176  6 Feb 23:15 /dev/da0
curlew:/root# fdisk /dev/da0
*** Working on device /dev/da0 ***
parameters extracted from in-core disklabel are:
cylinders=15 heads=64 sectors/track=32 (2048 blks/cyl)

parameters to be used for BIOS calculations are:
cylinders=15 heads=64 sectors/track=32 (2048 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 1 (0x01),(Primary DOS with 12 bit FAT)
start 32, size 31264 (15 Meg), flag 80 (active)
beg: cyl 0/ head 1/ sector 1;
end: cyl 488/ head 1/ sector 32
The data for partition 2 is:
UNUSED
The data for partition 3 is:
UNUSED
The data for partition 4 is:
UNUSED
curlew:/root# ls -l /dev/da0*
crw-r-  1 root  operator0, 176  6 Feb 23:15 /dev/da0

Still no device for slice 1 until after I attempt to open da0 for 
writing:

curlew:/root# cat /dev/null  /dev/da0
curlew:/root# ls -l /dev/da0*
crw-r-  1 root  operator0, 176  6 Feb 23:15 /dev/da0
crw-r-  1 root  operator0, 129  6 Feb 23:18 /dev/da0s1

I can use this to initialise the card reader but I'd feel more 
comfortable with something a bit less dangerous looking.

-- 
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