[comp.os.minix] Hard Disk Partitioning Tutorial

hcj@lzaz.ATT.COM (HC Johnson) (03/06/89)

This is meant to be a tutorial on partitioning a hard disk connected
to an Atari ST computer.  It will address TOS, Minix, PC-Ditto, and 
Spectre 128 usage.

There is considerable mysticism about the partitioning hard disks for
the Atari.  It isn't as complicated as it may appear.  

OVERVIEW

A hard disk is just a collection of sectors, numbered 0 to MAX, where
MAX is the total good sectors on a given hard disk.  Within most of the
disk interfaces is an Adaptec 4000 controller.  When told which sectors
are bad this device automatically squeezes them out, leaving MAX-N good
sectors.

Rule one:  Always subtract a reasonably small (128) number from the total
size of the disk to allow for this shrinkage.

PARTITIONS

Partitioning is just a way of thinking of the whole disk in parts.  It
occures in UNIX and MS-DOS because the original files systems could not
exceed numbers which were small compared to the total disk.  The most
current limit is TOS, which cannot handle a file system larger than
16 megabytes (32767 sectors of 512 bytes each). 

Sector 0 of the hard disk holds three kinds of information.  Within a
total of 512 bytes there exists:  First, an area reserved for a boot program.
Second,  sixteen bytes to describe the physical parameters of the disk; and 
ten bytes to support bad sectoring.  Third, an array of four partitions.
Each entry in this array describe the partitions storage area on the disk.

This is the 'C' description of a partion:

/*
 * Partition information (part of sector 0)
 */
struct pi {
  char	pi_flag;		/* active byte */
  char	pi_id[3];		/* partition id (GEM or MIX(?)) */
  long	pi_start;		/* first sector */
  long	pi_size;		/* total number of sectors */
};

If a partition is allocated, the flag is set to '1', and the  size is set
to the actual size of the partition is sectors.  Usually both the flag and
size will be 0 when a partition is unused.  Start is the actual physical
sector of the hard disk where this partition begins.  Within the partition
we talk of logical sector numbers from 0 to size -1. Additionally the 
partition may have a name (ID) to descibe who might expect to use it.

It is not uncommon to find several different names in the partitions, to
indicate that each different name is organized logically different from
the other.
Some examples of this:
A. TOS and PC-Ditto can process partions containing MS-DOS file systems.
   They use the ID 'GEM' to indicate this.  When they boot, only the 'GEM'
   partitions are given ICONs on the desktop.  Intervening partitions of
   other types are ignored.  Thus the First GEM partition is called C:, 
   the Second GEM partition is called D:, etc.
B. Spectre 128 and Magic Sac store Macintosh file systems on the hard
   disk.  They are given a uniq ID of (ACK) so that they will not be 
   used by TOS since they are not organized like a MS-DOS file system.
   Only the partitions with an ID of (ACK) are availiable to be mounted
   when the Macintosh emulator is running.  Again they are numbered from
   first to last, and need not be adjacent. These partitions use
   both 1 and -1 as the active flag.
C. Minix, is a UNIX feel alike, and utilizes yet another file system 
   organization.  It does not label its partitions, but they should
   have an ID of 'MIX'.  Minix, in the tradition of UNIX, allows all 
   partitions to be accessed, although its only sensible to mount as
   a filesystem one known to belong to Minix.  This allows great flexibility
   to Minix, for it is then possible to write a program to access a 
   different area of the disk (different partition), and interpret its
   blocks according to the rules of its own file system.  The 'tos'
   program in Minix does this to allow it to read and write files to
   and from GEM partitions.

FORMATTING

To physically format and partition the hard disk requires interaction
with the formatter and file system builder (vendor supplied), the 
hard disk driver for TOS (vendor supplied) and TOS's demands on the disk
(Atari supplied).
 - TOS expects that there is a file system name GEM
and that it is no larger than the 16 Meg maximum TOS can handle.
 - The driver expects to find 4 or 12 potential partitions, and stores the
starting address and size for each GEM partition.  These stored quantities
are accessed by refering to them as logical drives (C:,D:, etc).
 - The formatter and file system builder are usually supplied a one
program called a formatter.  The true formatter function issues one command
to the Adaptec 4000, who in tern formats the drive.  A good formatter will
also allow entering a list of bad areas on the disk, which can also be
input to the Adaptec 4000.
 - The file system builder wants to 1) establish the size of a partition
and 2) fill up the partition with a GEM file system.  These are really two 
separate acts.  This is the only component of the whole system that links
these two concepts.

The important thing to remember here is that a partition may be much larger
than the file system in it.  Consider a 100 MB disk with 4 GEM partitions.
If we try to get the most disk usage:
A. Partition 1, 16 mb, ID=GEM, logical drive C: start=0x1 size=0xfffe
B. Partition 2, 16 mb, ID=GEM, logical drive D: start=0x10000 size=0xfffe
C. Partition 3, 16 mb, ID=GEM, logical drive E: start=0x20000 size=0xfffe
D. Partition 4, 16 mb, ID=GEM, logical drive F: start=0x30000 size=0xfffe

What about the area on the disk that starts at 0x40000 that continues to
the end of the disk?  Its not being used.  If there were a way to describe
a fifth partition, it could start there.  This is what the Supra partitioning
scheem does.  It adds 8 more partition slots in a separate array.  Please 
realize that the space is available on the disk with or without the slots.
While Spectre 128 and PC-Ditto are Binary distributions there is little
one can do to use an area of the disk that does not follow the Supra scheme.
But Minix, for example, is a Source distribution, and its hard disk driver
can be modified to utilize the remaining space any way the author wishes.
Consider what happens if:
 - Minix slice 6 starts after partition 4, of size 512 blocks.  We have a nice
Root partion.
 - Minix slice 7 starts after slice 6.  The whole rest of the disk is available
as a Minix file system.

SECTOR 0 of the HARD DISK

The Following is the way Sector 0 of the hard disk is organized:

struct hi {
  char		hi_gap1[0x156];	/* reserved */
  union {
    char	hi_xgap1[0x60];	/* reserved */
    struct pi	hi_supra[8];
  }
  short		hi_cc;		/* number of cylinders */
  char		hi_dhc;		/* number of heads */
  char		hi_gap2[1];	/* reserved */
  short		hi_rwcc;	/* reduced write current cyl */
  short		hi_wpc;		/* write-precompensation cyl */
  char		hi_lz;		/* landing zone */
  char		hi_rt;		/* seek rate code */
  char		hi_in;		/* interleave factor */
  char		hi_spt;		/* sectors per track */
  long		hd_size;	/* size of disk in sectors */
  struct pi	hd_pi[NPARTS];	/* 4 partition descriptors */
  long		bsl_start;	/* start of bad sector table */
  long		bsl_count;	/* number of bad sectors */
  short		hi_magic;	/* reserved for checksum */
};

SUPRA PARTITIONING

The Supra partitioning scheme has become a defacto standard.  It adds
8 partitions to the 4 original ones, by taking 0x60 bytes from the end
of the boot area and allocating a array of 8 more partitions.  Supra
also supplies a hard disk boot program that will run in the reduced 
space.

LOGICAL SECTOR 0

It is well here to emphasize the difference between sector 0 of a hard disk,
and sector 0 of a partition.  When a MS-DOS file system occupies a partition
its first sector is also called the boot sector (of the file system).  This
sector describes the structure of the rest of the file system.  Utilities
such as memfile display only partitions, and sector 0 is that of the partition
not the hard disk.  Using TOS, the only way to display sector 0 of a
hard disk is with a specially written program to address the disk directly.
The Abacus books contain a sample program that works.  In MINIX, /dev/rhd0
accesses sector 0; so 'od -x /dev/rhd0' can be used to display the
information.

When Magic Sac first came out with hard diks support it was found that TOS
seemed to have a boundary problem, and if it wrote on the last sector it
seemed to damage the Magic area on the disk.  While I will not comment on
this, both Magic/Spectre and Minix, worry about this situation.

Howard C. Johnson
ATT Bell Labs
att!lzaz!hcj
hcj@lzaz.att.com