1.Dd August 27, 1993 2.Dt SD 4 3.Os FreeBSD 4.Sh NAME 5.Nm sd 6.Nd scsi disk driver 7.Sh SYNOPSIS 8.Nm device-driver sd 9.Op Ar count 10.Sh DESCRIPTION 11The 12.Xr sd 13driver provides support for a 14.Em scsi 15disk. It allows the disk 16to be divided up into a set of pseudo devices called 17.Em partitions. 18A Partition can have both a 19.Em raw 20interface 21and a 22.Em Block mode 23interface. 24In general the interfaces are similar to those described by 25.Xr wd 4 26or 27.Xr dk 4 . 28 29.Pp 30Where the 31.Xr wd 4 32device has a fairly low level interface to the system, 33.Em SCSI 34devices have a much higher level interface and talk to the system via 35a 36.Em SCSI Adapter 37and a 38.Em Scsi Adapter driver 39e.g. 40.Xr AHA1542 . 41A scsi adapter must also be separatly configured into the system 42before a scsi disk can be configured. 43.Pp 44As the scsi adapter is probed during boot, the 45.Em SCSI 46bus is scanned for devices. Any devices found which answer as 'Direct' 47type devices will be 'attached' to the 48.Nm 49driver. The first found will be attached as 50.Em sd0 51and the next, 52.Em sd1 53etc. 54.Pp 55.Sh PARTITIONING 56The 57.Nm 58driver allows the disk to have two levels of partitioning. 59One which allows it to have 60partitions for different Operating systems, (one of which is BSD unix), 61(see also for the 386 port, 62.Xr fdisk 1 63), and within a BSD partition, further partitions which are individually 64addressable as separate entries in the 65.Em /dev 66directory. The second level of partitioning is controlled by the program 67.Xr disklabel 1 68and is common in format across most BSD operating systems. In most of 69the original BSD ports, what is the 70BSD part here, is the entire disk, and the outer layer of partitionning 71does not exist. 72.Nm 73will also run in this manner if 74.Xr disklabel 1 75is run with a blank disk, without first partitioning it 76with 77.Xr fdisk 1 78(or similar). 79 80.Pp 81Apologies for the two conflicting usages of the word Partition, but 82it's a historical artifact, and the meaning must be judged from context 83in each case. The next paragraph will discuss partitions exclusively 84in the context of WITHIN a BSD partition on the disk. 85.Pp 86The first few blocks of the BSD section (maybe all) of the disk contain 87some boot code, and a structure, known as the 88.Xr disklabel 5 89which describes the disk's characteristics and partitioning for BSD. 90It is set up by the 91.Xr disklabel 1 92program, and read in by the kernel when the device is first initialised 93during boot. It describes how the drive is further divided. The 94.Xr disklabel 5 95structure contains room for 8 (usually) partitions. Usually these 96partitions are calculated so as to fall evenly on cylinder boundaries, 97however on a 98.Em SCSI 99disk this is sometimes not possible. The reason for doing this is historically 100to get better performance, however modern 101.Em SCSI 102disks often have a variable format, so that it is hard to know at any point 103in the disk, where the cylinder or track boundaries are. Added to this, the 104fact that 105.Em SCSI 106disk blocks are addressed soley by their 'block number' and not by 107any geometry, leads to the common occurance on 108.Em SCSI 109disks, of laying out partitions on arbitrary boundaries. Because 110modern disks often have large track caches, this often leads to only small 111degadations of performance, and is in fact sometimes unavoidable. The 112boot messages will suggest a geometry similar in heads and cylinders 113to the real geometry, but the disklable need not agree with this for the 114system to be able to successfully work with the disk. 115.Pp 116During booting 117with an uninitialised disk, the 118.Nm 119driver will initialise the 'in-core' copy of the disklabel to the suggested 120values, however they are not written to the disk. 121.Pp 122The fourth partition is special. No matter what the disklabel 123says, the fourth partition (partition d) reflectls the entire disk, including 124those areas OUTSIDE the BSD partitions. At some times it is suggested that 125the c partition might be used to represent the entire BSD partition, so these 126two partitions should be avoided when laying out filesystems. The fourth 127partition must be used for general 128.Xr scsi 4 129ioctls. 130.Pp 131While partitions are only theoretically valid within the BSD partition, they 132are specified in terms of absolute block numbers, so it is possible to 133specify a partition that lies outside of the BSD partition. This is useful 134if one wants to have a /dev entry that points to a partition belonging 135to another OS (e.g. DOS). 136.Pp 137.Sh KERNEL CONFIGURATION 138In configuring, if an optional 139.Ar count 140is given in 141the specification, that number of scsi disks are configured; 142Most storage for them is allocated only when found so a large number 143of configured devices is cheap. (once the first has included the driver). 144 145.Pp 146.Sh IOCTLS 147The following 148.Xr ioctl 2 149calls apply to scsi disks as well as to other disks. They are defined 150in the header file 151.Em disklabel.h. 152 153.Bl -tag -width DIOCSDINFO 154 155.It Dv DIOCSBAD 156Usually used to set up a bad-block mapping system on the disk. Scsi 157drive incorporate their own bad-block mapping so this is not implimented, 158however it MAY be implimented in the future as a 'kludged' interface to the 159scsi bad-block mapping. 160.It Dv DIOCGDINFO 161Read, from the kernel, the in-core copy of the disklabel for the 162drive. This may be a ficticious disklabel if the drive has never 163been initialised, in which case it will contain information read 164from the scsi inquiry commands, and should be the same as 165the information printed at boot. 166.It Dv DIOCSDINFO 167Give the driver a new disklabel to use. The driver will NOT try write the new 168disklabel to the disk. 169.It Dv DIOCWLABEL 170Enable or Disable the driver's software 171write protect of the disklabel on the disk. 172.It Dv DIOCWDINFO 173Give the driver a new disklabel to use. The driver WILL try write the new 174disklabel to the disk. 175.El 176.Pp 177In addition, the 178.Xr scsi 4 179general ioctls may be used with the 180.Nm 181driver, but only against the fourth (whole disk) partition. 182.Sh NOTES 183If a removable device is attached to the 184.Nm 185driver, then the act of changing the media will invalidate the 186disklabel and information held within the kernel. To stop corruption, 187All accesses to the device will be discarded until there are no more 188open file descriptors referencing the device. During this period, all 189new open attempts will be rejected. When No more open file descriptors 190reference the device, the first next open will load a new set of 191figures (including disklabel) for the drive. 192 193An ioctl to map out a bad block is planned. (the code is already present 194in the driver). 195 196.Sh FILES 197.Bl -tag -width /dev/rsd[0-9][a-h] -compact 198.It Pa /dev/sd[0-9][a-h] 199block mode scsi disks 200.It Pa /dev/rsd[0-9][a-h] 201raw scsi disks 202.El 203.Sh DIAGNOSTICS 204None. 205.Sh SEE ALSO 206.Xr disklabel 1 207.Xr disklabel 5 208.Xr fdisk 1 209.Xr wd 4 210.Xr dk 4 211(on other systems) 212.Sh HISTORY 213The 214.Nm 215driver appeared in MACH 2.5 . 216 217