[BE SURE TO READ THE WARNING AT THE END OF THIS FILE BEFORE USING
THIS CODE.]

These diffs enhance the Minix 1.5 AT harddisk driver and some other
programs to allow Minix to

a) handle all extended partitons as introduced with DOS 3.30,
   DOS 4.00 and OS/2. All extended partitions are assigned new minor
   device numbers.

b) make file systems on extended partitions to have much more than
   four file systems on a disk even in addition to multile DOS
   file systems.

c) access DOS file systems on extended partitions. Even OS/2 HPFS
   partitions could be accessed if code similar to dos[read,write]
   is added for HPFS.

d) let the fdisk program detect disk geometrics. No values have to
   be hardcoded into fdisk or given to it on the command line.

e) for Minix-386 (1.5.10) the 64MB limit on block devices is removed.
   This does *not* allow larger Minix file systems but allows
   access to larger DOS file systems.

The following files have to be changed:

at_wini.c:	The harddisk device driver. Patch versions are provided
		for both the standard and the multisector-patched driver
		(by Bert Gijsbers). The patch files are at_wini.cdif and
		atms_wini.cdif.

minix/type.h:	Small patch to remove the 64MB limit by making block_nr
		int instead of short.

minix/partition.h:
		Addition of the drive info structure for fdisk.

fdisk.c:	Changes for the geometry detection.

dosread.c:	Changes for big DOS 4.0 file systems. They were made by
		someone else (don't know who) and posted in comp.os.minix,
		but are included here for completeness.

The minor device names have changed. Minors 0-63 are for hard disk 0
where minors 64-127 are for hard disk 1. Minor 128 is a *character*
device used by fdisk to communicate with the hard disk driver and
should be created as /dev/hdisk.

The patch should work with two hard disks (to my best knowledge) but I
cannot test it because I have only one (although very large) disk.
Having a very large disk (400MB) was the reason for these patches
because four partition table entries are far not enough for me.

For those not familiar with DOS 3.30 and up extended partitions, a
short explanation:

If a partition is marked with type 5 (extended partition), then it
contains  a complete virtual hard disk. It has itself a new partition
table, which has again four entries. There may be in turn an extended
partition within this already extended partition. This may be nested to
any level.

Example: you have a disk with a bootable partition and an extended
partition containing 5 drives (as viewed by DOS fdisk.exe) and a Minix
partition. Then the root partition table contains three entries, the
bootable DOS partition, the extended DOS partition and your Minix
partition. The extended partition covers *all* the space allocated to
the 5 drives in it. The partition table inside it contains three normal
DOS partitions and again an extended partition. All four partitions are
 completely within the parent extended partition. The nested extended
partition then contains again a partition table with two normal DOS
partitions and covers the space within the parent extended partition
that is allocated to the remaining two DOS partitions.

Now, with the patched Minix, the minor devices look as follows:

0	the entire hard disk

1	DOS bootable partition
2	DOS extended partition 1
3	Minix partition
4	<unused>

5	DOS extended partition
6	DOS partition
7	DOS partition
8	DOS partition

9	DOS partition
10	DOS partition
11	<unused>
12	<unused>

So your hard disk has three partition tables, /dev/hd0, /dev/hd2 and
/dev/hd5. You can access each of them by passing the device name to
fdisk. The patched fdisk checks if the device passed to it is really a
hard disk minor and contains a partition table and rejects all other
devices. It does so by asking the hard disk driver in the kernel via
/dev/hdisk (minor 128). The hard disk driver knows, which minors
contain partition tables. If you create a new extended partition, you
have to reboot, before you can access the partition table within it
with fdisk.

Link /dev/hd[6789] and /dev/hd10 to your dos[DEFGH] devices for
dosread/write/dir in this example.

Another example: my setup is as follows, a bootable DOS partition,
an extended partition and two Minix partitions. The extended
partition contains another DOS partition and an OS/2 HPFS.

The minors are:

0	entire disk

1	DOS bootable partition
2	DOS extended partition
3	Minix partition 1
4	Minix partition 2

5	DOS extended partition
6	DOS partition
7	<unused>
8	<unused>

9	OS/2 HPFS
10	<unused>
11	<unused>
12	<unused>

Note that like in this example, extended partition need not to be
filled completely before a new one is started. The OS/2 fdisk program
instead prefers to create a new nested extended partition for the HPFS
partition.

Limits:

Because of the minors required fo the partition tables of the
extended partitions themselves, with 64 minors you can have up to
48 partitions on a disk with file systems on those 48 devices.
This is probably enough ...

Installation:

- patch your at_wini.c (use the correct patch, if you have multisector
  version by Bert Gijsbers).

- patch minix/type.h and minix/partition.h

- recompile kernel and fs (fs because of the removed 64MB limit, you
  don't need to recompile fs if you don't have Minix-386).

- patch and compile dosread.c and fdisk.c, be sure to link dosread
  to doswrite and dosdir when installing it in .../bin.

Remember to create /dev/hdisk to 3/128 and to change the devices
for you possible second hard disk to start at minor 64.

Warning:

I am not responsible for any loss of data caused by incorrect use of or
bugs in this code. Make backups of your disk before changing the
partition structure of extended partitions from within Minix with
fdisk. However, read-only use of this code, to access existent DOS
extended partitions should be safe :-)

If you are a beginner and not experienced in applying diffs (and
perhaps fixing rejects if your and my sources of the system differ, a
very likely situation), then don't use this code. I am probably not
able to answer e-mail messages like "patch xxx.cdif fails when using
the patch program to apply it to xxx.c, what can I do?". It is the
situation with Minix, that people's systems all diverge because of
the numerous (and different) extensions, that all people apply to
their systems (I can no longer count all the extensions and patches
I have in my Minix 1.5.10/386). If you are not sure if you can
apply all patches correctly, then don't use this code. 

This code, if incorrectly installed, can easily damage file systems.
So, be careful. Sorry, but you get what you pay for ...

Kai Uwe Rommel
rommel@informatik.tu-muenchen.de

