hd(7) UNIX System V hd(7)
NAME
hd - hard (fixed) disk
DESCRIPTION
The hard disk driver supports handle up to two hard disk drives and two
diskette drives. The drive characteristics are read from the CMOS RAM at
boot time; these characteristics are defined during system setup by using
the setup program on the AT Diagnostics diskette. The driver determines
the layout of the disk dynamically, as described below. It provides
block and character (raw) access to the individual partitions of the
disk, as well as the entire physical disk.
The minor device number of the device being accessed determines how the
drive is treated: the low-order 4 bits determine the partition (0-15),
and the fifth bit determines the drive number (0 or 1). Partition 0
represents the entire UNIX system partition (as defined by the fdisk
table). Other partitions are defined by information in the volume table
of contents (VTOC). When accessing partition 0, other partition
boundaries are ignored, and no bad block mapping occurs. Thus, the user
must take care when using the disk in this way.
The full fixed disk is partitioned at two levels: first, sections of the
disk to be used by different operating systems are described by the fdisk
table contained in the first block of the disk. Second, the UNIX system
sections of the disk are further partitioned according to information
contained in the VTOC, which may be located in any block. [The VTOC is
currently in the 30th sector of the UNIX system partition.] block on the
second track of the disk; see mkpart (1M).] The VTOC also contains
information about the non-UNIX system partitions described in the fdisk
table. When the disk device is opened, the VTOC is read by the driver
and is used to fill out its tables of logical disks, assigned by minor
device number.
Each partition in the fdisk table is specified as to its type (e.g., DOS,
UNIX system, or other). A partition (file system) is usable by the UNIX
system only if its type is correct (e.g., a DOS partition is not usable
by the UNIX system, except as a raw, non-file system device.)
On each drive, sector 0 contains the primary bootstrap and the fdisk
table. The first 29 sectors of the UNIX system partition contain the
first-stage and second-stage bootstraps. The 30th sector contains the
pdinfo and VTOC table. Sectors 31-34 contain the bad block and track
mapping tables. As many sectors as needed, beginning with the 35th
sector, are used for alternate tracks and sectors.
The fdisk table indicates which of the partitions is the 'active', or
bootable, partition. When the machine is booted, the primary boot code
looks in the fdisk table for the active partition and jumps to sector 0
of that partition to find the first-stage bootstrap. If the first-stage
bootstrap is over one sector in length, it is the responsibility of the
first-stage bootstrap to understand this. Note that both the first
cylinder (containing the fdisk table, first-stage bootstrap, VTOC, and
10/89 Page 1
hd(7) UNIX System V hd(7)
alternate sectors) and the first track of the active partition
(containing the first-stage bootstrap) can only be accessed using
partition 0, since these tracks are normally not considered part of any
other partition in the VTOC.
Bad sectors are mapped out by the driver as follows: The bad block map
is read by the driver when the drive is first opened. The map is an
array of pairs of numbers, representing a bad sector and its assigned
alternate, each entry being an absolute sector number, starting with 0
for the first sector of the disk.
Before each I/O operation, the driver looks through the map to determine
if any sector in the requested transfer is bad. If there is a bad sector
within the request, all the I/O up to the bad sector is done, then the
bad sector is remapped, and finally the I/O following the bad sector is
done.
Note that this scheme requires running mkpart (1M) before bringing up the
system from the hard disk for the first time. The mkpart program will
attempt to optionally write and then read every sector on the disk,
looking for sectors where this operation fails. All bad sectors will be
placed in alternates map, which is built by mkpart and installed on the
disk at the same time that the VTOC is installed. If this verification
pass is not done, however, the system will still work. Since the driver
will notice that the table is empty, it will not attempt to map bad
sectors.
In the event that a disk develops bad blocks once the system is running,
mkpart may run (with the -A option) to add the new bad blocks to the map.
However, the user may have to restore the file system from the last full
dump, depending on where the bad block occurred.
Ioctl Calls
VCONFIG
This call is used by mkpart to reconfigure the drive, so that the
drive configuration matches the parameters specified in the
/etc/partitions file. This is useful because the disk type read
from the CMOS RAM is limited to one of 23 types defined in a table
in the system BIOS. If the disk installed on the system does not
exactly match one of the table entries, the machine is set up using
the closest table entry, and mkpart will tell the driver the true
disk parameters (as defined by the /etc/partitions file) by using
the VCONFIG ioctl. The argument to the ioctl is the address of
one of the following structures, defined in <sys/vtoc.h>,
containing the new configuration parameters:
union ioarg {
struct {
ushort ncyl; /* number of cylinders */
unchar nhead; /* heads/cylinder */
unchar nsec; /* sectors/track */
Page 2 10/89
hd(7) UNIX System V hd(7)
ushort secsiz; /* bytes/sector */
} iacd;
}
Note that it is not possible to change the sector size on the hard
disk, and that an attempt to do so will result in the ioctl
failing, with errno set to EINVAL.
VREMOUNT
This call is used to force the driver to re-read the VTOC on the
next open of the drive. It will fail if any partition other than
partition 0 is currently open, since changing the partition table
information is potentially disastrous for a process using the
partition. This is used by mkpart when it changes the VTOC, so
that the driver will update its internal tables.
VGETPARMS
This call is used to get information about the current drive
configuration. The argument to the ioctl is the address of one of
the following structures, defined in <sys/vtoc.h>, which will be
filled in by the ioctl:
struct diskparms {
char dptype; /* Disk type (see below) */
unchar dpheads; /* Number of heads */
ushort dpcyls; /* Number of cylinders */
unchar dpsectors; /* Number of sectors/track */
ushort dpsecsiz; /* Number of bytes/sector */
ushort dpptag; /* Partition tag */
ushort dppflag; /* Partition flag */
daddrt dppstartsec; /* Starting absolute sector
number */
daddrt dppnumsec; /* Number of sectors */
}
/* Disk types */
#define DPTWINI 1 /* Winchester disk */
#define DPTFLOPPY 2 /* Floppy */
#define DPTOTHER 3 /* Other type of disk */
#define DPTNOTDISK 0 /* Not a disk device */
/* Partition tag */
#define VBOOT 1 /* bootable partition */
#define VROOT 2 /* root filesystem */
#define VSWAP 3 /* swap filesystem */
#define VUSR 4 /* usr filesystem */
#define VBACKUP 5 /* entire disk */
#define VALTS 6 /* alternate sectors */
#define VOTHER 7 /* non-UNIX system partition */
10/89 Page 3
hd(7) UNIX System V hd(7)
/* Partition flag */
#define VUNMNT 0x001 /* unmountable partition */
#define VRONLY 0x010 /* read only partition */
#define VOPEN 0x100 /* partition open */
#define VVALID 0x200 /* partition valid to use */
For the hard disk driver, the disk type will always be DPT_WINI.
Since the structure returned by VGETPARMS is the same for both the
diskette and hard disk drivers, programs may be written to
understand either one.
VFORMAT
This call is used to format tracks on a disk. The argument passed
to the ioctl is the address of one of the following structures,
defined in <sys/vtoc.h>, containing the starting track, number of
tracks, and interleave factor:
union ioarg {
struct {
ushort starttrk; /* first track */
ushort numtrks; /* number of tracks
to format */
ushort intlv; /* interleave factor */
} iafmt;
}
Note that the file descriptor argument to the ioctl must refer to
the character (raw) special device for the desired drive, and the
file must have been opened in exclusive mode (i.e., O_EXCL).
GETALTTBL
This call returns the four pieces of alternates information. The
four pieces are the sanity value, the version number, the bad track
table, and the bad sector. The alt_info structure is defined in
<sys/alttbl.h>.
struct altinfo { /* table length should be multiple of 512 */
long altsanity; /* to validate correctness */
ushort altversion; /* to corroborate vintage */
ushort altpad; /* padding for alignment */
struct alttable alttrk; /* bad track table */
struct alttable altsec; /* bad sector table */
};
VVERIFY
Page 4 10/89
hd(7) UNIX System V hd(7)
This call has a dual purpose. Its primary role is to do a read
verify of any portion of the disk. The desired start sector is
placed in abs_sec, and the desired number of sectors is placed in
num_sec. If an error occurs it is placed in err_code. The other
purpose of the routine is to do timings of the read verify. This
task is accomplised by setting the time_flg. The time required to
do the verify is then placed in deltatime. The vfy_io structure is
defined in <sys/vtoc.h>.
union vfyio {
struct {
daddrt abssec;
/* absolute sector number */
ushort numsec;
/* number of sectors to verify */
ushort timeflg;
/* flag to time the operation */
}vfyin;
struct {
timet deltatime;
/* duration of operation */
ushort errcode;
/* reason for failure */
}vfyout;
};
VPDLOC
This call simply returns the logical sector address of the PDinfo
structure. The value is returned in pdloc.
unsigned long pdloc;
VRDABS
This call is used as a method of reading any sector on the hard
disk. Only users with root privilege can freely access any sector.
Users who do not have root privilege can access the partition table
(sector 0) or the boot slice (to allow access to the vtoc). The
logical sector address is placed abs_sec. The 512 bytes of sector
information are returned in abs_buf. The absio structure is defined
in <sys/vtoc.h>.
struct absio {
daddrt abssec;
/* Absolute sector number (from 0) */
char *absbuf;
/* Sector buffer */
};
10/89 Page 5
hd(7) UNIX System V hd(7)
VWRABS
This call is used to write 512 bytes to any sector on the disk.
Only users with root privilege can make use of the call. The
logical sector location to be written to is placed in abs_sec. The
512 bytes of data to be written are placed in abs_buf. The absio
structure is defined in <sys/vtoc.h>.
struct absio {
daddrt abssec;
/* Absolute sector number (from 0) */
char *absbuf;
/* Sector buffer */
};
Partitions
The fdisk table allows partitions to be assigned at cylinder boundaries;
however, the VTOC will allow partitions to start on track boundaries.
This is used in the bootable UNIX system partition to make the first
track (containing the bootstrap code) not be an actual part of the
partition. The fdisk table allows at most four partitions on a fixed
disk, but the VTOC allows the UNIX system portion to be divided into at
most 16 partitions. Each partition is identified by a minor device
number; the mapping from partition to minor device number is made at the
time the disk is first accessed, and is determined by the /etc/partitions
file. This mapping will remain the same until the /etc/partitions file
is changed and the mkpart program rerun.
Attempts to open file systems for which there are no partitions will fail
(non-existent device). Likewise, attempts to mount [see
mount (8)] partitions that do not contain UNIX file systems will fail.
FILES
/dev/dsk/0s0, ...
/dev/rdsk/0s0, ..\f1.
SEE ALSO
fdisk(1M), mkpart(1M), ioctl(2), fs(4), fd(7).
DIAGNOSTICS
The driver will retry failed transfers up to ten times depending on the
error type. Certain errors are not retried. The driver will display an
appropriate message upon encountering an error during the transfer.
Error types that are retried are indicated in the table below. Errors
from the fixed disk controller are displayed as follows:
HD error: drive n, cyl c, head h, sector s: drive error message
HD controller: controller error message
The first message occurs on an error after a transfer has begun, where n
is the drive where the error occurred, c is the cylinder, h is the head,
and s is the sector being read or written. The drive error message is
Page 6 10/89
hd(7) UNIX System V hd(7)
one of the messages appearing in the following list:
Track 0 not found
The disk may not be formatted properly.
Uncorrectable data read error
The controller detected a CRC error when attempting to read the
requested block.
Data address mark not found
The disk may not be formatted properly.
Sector not found
The disk may not be formatted properly.
Command aborted
The controller did not complete execution of a command.
Bad track flag detected
The block requested has been marked bad, but does not appear in the
bad block map.
The second message occurs when there is a controller error during the
setup for, or actual transfer of, a block. The controller error message
is one of the messages appearing in the following list:
command aborted
The controller failed to complete the requested command.
write fault
The controller detected some error on the hard disk drive.
stays busy During an attempt to access the controller, a timeout occurred.
There is one additional message which indicates a controller-corrected
error occurred:
NOTE: Soft read error corrected by ECC algorithm: unit n, sector s
where n is the drive where the error occurred, and s is the sector being
read. This warning indicates that the controller's error-correction
algorithm successfully recovered from an error. This may be a symptom of
a sector going bad. If this message appears several times for the same
sector, that sector should probably be marked bad.
NOTES
The VTOC and alternate sector mapping scheme requires that no bad sectors
occur in cylinder 0. The mkpart program will issue a fatal error message
when it attempts to configure a drive where there are bad sectors in the
first cylinder. Also, since the second-stage bootstrap must be installed
on the first track of the bootable partition, this track must also
contain no bad sectors.
10/89 Page 7