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