Subject: Devices Date: Wed, 6 Nov 1991 19:15:45 +0200 From: Linus Benedict Torvalds <torvalds@cc.helsinki.fi>
Before the actual article: a quick question. Are any of you using DOS
version 5.0 ? If I've understood correctly, 5.0 changes the disk-layout
rather heavily. I doubt mtools can handle the new DOS partitions, and
possibly even the partition table has changed. Again, I'd be interested
to know if everything works fine with DOS 5.0.
Mika Matti Jalava: "device numbers" (Nov 6, 18:08):
> Hi!
>
> Would it be possible to post some kind of a table of valid device
> numbers? [ for people not having minix ]
Ok. Here is a short table:
Memory devices: Major = 1 (characted devices)
minor
0 /dev/ram - not implemented (never will be, I think: minix special)
1 /dev/mem - not implemented (easy, seldom used)
2 /dev/kmem - not implemented (easy, but I haven't done it)
3 /dev/null
4 /dev/port (implemented, but untested - don't play with it)
example: "mknod /dev/null c 1 3"
Floppy disks: Major = 2 (block devices)
minor = drive + 4*type, drive = 0,1,2,3 for A,B,C or D-diskette
type 1: 360kB floppy in 360kB drive (5.25")
2: 1.2M floppy in 1.2M drive (5.25")
3: 360kB floppy in 720kB/1.44Mb drive (3.5")
4: 720kB floppy in 720kB/1.44Mb drive (3.5")
5: 360kB floppy in 1.2M drive (5.25")
6: 720kB floppy in 1.2M drive (5.25")
7: 1.44M floppy in 1.44M drive (3.5")
Thus minor nr for a 1.44Mb floppy in B is: 1 + 4*7 = 29, and to read an
old 360kB floppy in a 1.2M A-drive you need to use minor= 0 + 4*5 = 20.
Example: "mknod /dev/PS0 b 2 28" (b for block: 2 for floppy, 28 for 1.44
in A)
Hard disks: Major = 3 (block devices)
minor
0 /dev/hd0 - The whole hd0, including partition table sectors etc.
1 /dev/hd1 - first partition on hd0
...
4 /dev/hd4 - fourth partition on hd0
5 /dev/hd5 - The whole hd1, again including partition table info
6 /dev/hd6 - first partition on hd1
...
9 /dev/hd9 - fourth partition on hd1
NOTE! Be /very/ careful with /dev/hd0 and /dev/hd5 - you seldom need
them, and if you write to them you can destroy the partition tables:
something you probably don't want.
The only things that use /dev/hd0 are things like "fdisk" etc.
NOTE 2!! The names for hd's are the same as under minix, but I think
minix orders the partitions in some way (so that the partition numbers
will be in the same order as the partitions are physically on the disk).
Linux doesn't order anything: it has the partitions in the same order as
in the partition table (ie /dev/hd1 might be physically after /dev/hd2).
NOTE 3!! Somebody wrote he trashed his DOS-partition with mtools. Are
you sure you didn't do a "mkfs /dev/hdX" with the demo-minix, where the
X was a DOS-partition and not an empty one? One way to be sure to trash
a DOS-partition is to overwrite it with a minix filesystem. Not that
I'm sure that mtools works (/I/ didn't write it :-), just wondering...
Tty's: Major = 4 (character devices)
minor
0 /dev/tty0 - console
1 /dev/tty1 - serial 1
2 /dev/tty2 - serial 2
Example: "mknod /dev/tty2 c 4 2"
Personal tty: Major = 5 (character device)
minor: 0 /dev/tty - "linked" to the tty that your process has got:
normally /dev/tty0 in linux (until someone makes a init/login).
Example: "mknod /dev/tty c 5 0"
> I think I'll have to try a couple of old MFM disks, as my ESDI does
> not seem to like Linux. The test that someone suggested,
> cat </dev/hd1>/dev/null probably did not do what it should have done,
> it just hung the machine.
Don't be so sure: using direct reads/writes on a device is rather slow,
and on a bigger partition (>10M) this can take some time even for a
harddisk. I've never tried to optimize direct devices for performance.
If you can get out from the "cat" with ^C, it probably works. If ^C
doesn't kill it, ESDI drives probably won't work.
Another way to test the drive would be to write "cat /dev/hd1". This
prints anything it reads onto the screen: if nothing appears, linux is
unable to read the drive. Use ^C to break when you have got enough.
Again, if ^C won't work, the drive is unsupported. (note: pressing ^C
repeadetly may kill the shell, as it will catch only the first one).
Note to everybody: currently I have these debug-statements in the
kernel, so that when you try to read past the end of a partition or
diskette you will get "xxx I/O error". This is normal (but reading
beyond the end of the disk may not be :-).
> BTW, Is it possible to use a secondary HD controller? If not, will it
> be some day?
Not currently, and as I haven't got a second controller... It should be
relatively easy to add a driver for it: copy the code from hd.c to
hd2.c, change the MAJOR_NR to 6 (or something), and change all the IO
port addresses. That /might/ do it (VERY simplified explanation). I
won't be able to do it - no way to debug the thing.
Linus