Detecting cards in USB card reader
jmc-freebsd2 at milibyte.co.uk
Wed Feb 10 17:54:02 UTC 2010
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
> > lab# echo > /dev/da0
> > lab# echo $?
> > 1
> > lab# /bin/echo asd > /dev/da0
> > /bin/echo: write: Invalid argument
> Closer look:
> > lab# truss sh -c "echo > /dev/da0"
> > open("/dev/da0",O_WRONLY|O_CREAT|O_TRUNC,0666) = 2 (0x2)
> > dup2(0x2,0x1,0x1b6,0x1000008,0x2830d040,0x2830235c) = 1 (0x1)
> > close(2) = 0 (0x0)
> > write(1,"\n",1) ERR#22 'Invalid
> > argument'
> 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
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
More information about the freebsd-questions