Re: Confused about RAW devices ...

DAVID BALAZIC (david.balazic@uni-mb.si)
Sat, 23 Oct 1999 13:31:20 +0100 (MET)


>From: "Stephen C. Tweedie" <sct@redhat.com>
>>> I did a small test :
>>> (2) fd=open("/dev/cdrom",O_RDONLY);
>>> read(fd,buffer,1);
>>> wait_a_second();
>>> read(fd,buffer,1);
>>>
>>> When the second read is done , the CD-drive spins the CD up and the drive LED
>>> blinks. No sign of caching. ( kernel v2.2.12 )
>
>If the reads are truly sequential and only 1 byte long, then the only
>time this should happen is if the buffer cache is busy enough that the
>block has been discarded from the cache between the reads.
>
>> If you really did this, the second read does not read the same as the
>> first. So, it could not be satisfied from the cache.
>
>Yes it will be: the cache reads entire blocks/sectors at a time, necessarily.
>
>> A 2nd read from the hardware is ok. What you could claim is: there is
>> no read ahead.
>
>There is, but it will only be triggered on the next actual IO in this
>case.
>
>> Now, you say, but I only read 1 byte, the next one is on the same block,
>> so in cache already. Well, but /dev/cdrom is a block device, you can't
>> read one byte at all.
>
>Yes you can. The kernel will cache the rest of the block for you.
>
>> All that said; In addition: a cdrom is removable. The kernel has to check
>> the CD didn't change.
>
>No it doesn't: the kernel locks the drive door while the file is open,
>and only tests disk change when it is closed and then reopened.
>
>--Stephen

How does it test the disk change ?

My program is :
open//dev/cdrom)
seek to 12000345
read one byte
close

If I call this program from shell twice , each will spin up the
drive.
kernel is 2.2.12

-- 
David Balazic , student
E-mail   : 1stein@writeme.com     |     living in  sLOVEnija
home page: http://surf.to/stein
Computer: Amiga 1200 + Quantum LPS-340AT
--

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/