Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 07 Feb 2010 13:27:16 +0200
From:      Nikos Vassiliadis <nvass9573@gmx.com>
To:        Mike Clarke <jmc-freebsd2@milibyte.co.uk>
Cc:        Polytropon <freebsd@edvax.de>, freebsd-questions@freebsd.org
Subject:   Re: Detecting cards in USB card reader
Message-ID:  <4B6EA394.5050604@gmx.com>
In-Reply-To: <201002062328.27744.jmc-freebsd2@milibyte.co.uk>
References:  <201002061511.11639.jmc-freebsd2@milibyte.co.uk>	<20100206192540.bb4ce11b.freebsd@edvax.de> <201002062328.27744.jmc-freebsd2@milibyte.co.uk>

next in thread | previous in thread | raw e-mail | index | archive | help
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  operator    0, 176  6 Feb 23:15 /dev/da0
> crw-r-----  1 root  operator    0, 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,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.

HTH, Nikos



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4B6EA394.5050604>