accessing /dev/fd0 directly for sector reads/writes

accessing /dev/fd0 directly for sector reads/writes

Post by Jeff Week » Wed, 06 May 1998 04:00:00



Hi there,

I'm getting into some operating system development, and it would make my
life a lot easier right now if I could use the Linux device drivers for
the time being to format my disks and such.

My question then becomes, how can I use /dev/fd0 directly?  I realise
I'd have to be root, that's no problem.  My understanding would be that
I can just open /dev/fd0 as a file and read and write to it.  I tried
this, but had some troubles.  I think I was reading correctly, but not
writting.

I know a "cat /dev/fd0" will give me the contents of the disk, so it
obviously acts as if it's a file, but it's actually a block device.
Does this mean that "fseek(file, 10, SEEK_SET)" will get me to the 10th
byte, or the 10th block?  If block, how do I find out the size (I'm
assuming it'd be 512 bytes, for a regular disk) of the block?

Any information on this topic would be helpfull.

Thanks,
Jeff

PS: Please respond via email if possible.

--------------------------------------------
            - Code X Software -
       Programming to a Higher Power


        web:   http://www.codex.nu/
--------------------------------------------

 
 
 

accessing /dev/fd0 directly for sector reads/writes

Post by Andreas Schwa » Thu, 07 May 1998 04:00:00


|> I know a "cat /dev/fd0" will give me the contents of the disk, so it
|> obviously acts as if it's a file, but it's actually a block device.
|> Does this mean that "fseek(file, 10, SEEK_SET)" will get me to the 10th
|> byte, or the 10th block?

The offset will always be in bytes, for all types of files.  (Actually you
will get at the 11th byte, the first one being at offset 0.)

--
Andreas Schwab                                      "And now for something



 
 
 

accessing /dev/fd0 directly for sector reads/writes

Post by Kaz Kylhe » Thu, 07 May 1998 04:00:00



>Hi there,

>I'm getting into some operating system development, and it would make my
>life a lot easier right now if I could use the Linux device drivers for
>the time being to format my disks and such.

>My question then becomes, how can I use /dev/fd0 directly?  I realise
>I'd have to be root, that's no problem.  My understanding would be that
>I can just open /dev/fd0 as a file and read and write to it.  I tried
>this, but had some troubles.  I think I was reading correctly, but not
>writting.

>I know a "cat /dev/fd0" will give me the contents of the disk, so it
>obviously acts as if it's a file, but it's actually a block device.
>Does this mean that "fseek(file, 10, SEEK_SET)" will get me to the 10th
>byte, or the 10th block?  If block, how do I find out the size (I'm
>assuming it'd be 512 bytes, for a regular disk) of the block?

The fd0 is a block device which means that you can treat it as though
it were a file. The seek operation works in bytes, so the above
gets you to the 11th byte (starting from zero).

Block size is irrelevant because you are dealing with a block
device, not a raw or character device. All block devices have
the same logical block size of one kilobyte, but this is
an implementation detail of the operating system that you
don't need to worry about.

Blocks don't necessarily correspond to physical sectors; they are a
logical entity defined by the buffer cache implementation.
When you write to the floppy, you are actually writing to the
system's buffer cache which will be flushed at some later time.

Block sizes do matter when you write to a raw character device
such as a tape drive, because then each read() or write() request
may be interpreted as writing or reading a new tape block.
The use of an incorrect block size can lead to blocks
that are partially filled, or worse, that are truncated.

This could never happen with a block device. You can write
one byte, or you can write a megabyte. In all cases, the
opearting system will properly execute the request and
update the appropriate buffers. The low-level driver will
then correctly write the modified buffers to the hardware
device.

 
 
 

1. how to boot from /dev/fd0 and mount /dev/fd0 as root

How can I mount /dev/fd0 as the root partition when it is the drive
that I boot from, even though the boot disk is different.  The steps
that I want to do is to insert the boot disk first and boot the
machine, then insert the root disk at the appropriate time to be
used as the root filesystem.  I prefer to not use /dev/fd1 for this.
--
/***********************************************************************\

| depending on government is that you cannot depend on it" - Tony Brown |
\***********************************************************************/

2. show memory chip info for Ultra 5/10?

3. let users access /dev/modem or /dev/fd0

4. gcc2.2

5. Mtools "cannot access /dev/fd0 :access denied"

6. Sportster VI series?

7. /dev/fd0 /dev/fd1 /dev/scd0 problems

8. reset: Routing table & ifconfig

9. /dev/fd0 write errors [RH6.2, gateway2000]

10. Oops when accessing /dev/fd0 (kernel 2.4.7 and devfsd 1.3.11)

11. Kernel Panic when reading/writing to fd0

12. Verbose debug messages when accessing /dev/fd0

13. /dev/fd0 suddenly becomes read-only