Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Feb 2010 17:53:59 +0000
From:      Mike Clarke <jmc-freebsd2@milibyte.co.uk>
To:        freebsd-questions@freebsd.org
Cc:        Nikos Vassiliadis <nvass9573@gmx.com>
Subject:   Re: Detecting cards in USB card reader
Message-ID:  <201002101753.59159.jmc-freebsd2@milibyte.co.uk>
In-Reply-To: <4B6EA394.5050604@gmx.com>
References:  <201002061511.11639.jmc-freebsd2@milibyte.co.uk> <201002062328.27744.jmc-freebsd2@milibyte.co.uk> <4B6EA394.5050604@gmx.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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,0x1000008,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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201002101753.59159.jmc-freebsd2>