3 opendisk, Disk \- generic disk device interface
16 int fd, wfd, ctlfd, rdonly;
18 vlong secs, secsize, size, offset;
24 Disk* opendisk(char *file, int rdonly, int noctl)
26 These routines provide a simple way to gather
27 and use information about
28 disks and disk partitions,
29 as well as plain files.
34 for reading and stores the file descriptor in
46 for writing and stores that file descriptor in
48 The two file descriptors are kept separate to
49 help prevent accidents.
57 file in the same directory as the
59 if it finds one, it declares
78 declares the disk to be
79 a floppy disk, of type
83 file is found, it is opened for reading
84 and writing, and the resulting file descriptor
87 Otherwise the returned disk
92 then stats the file and stores its length in
98 reads the sector size from the
100 file and stores it in
102 otherwise the sector size is assumed to be 512,
103 as is the case for floppy disks.
105 then stores the disk size measured in sectors in
114 file to find the partition's offset
119 If the disk is an ATA disk,
122 the disk geometry (number of cylinders, heads, and sectors)
128 otherwise it sets these to zero as well.
130 is initialized with the base name of
131 the disk partition, and is useful for forming messages to the
135 is set to the passed filename without
140 The IBM PC BIOS interface allocates
141 10 bits for the number of cylinders, 8 for
142 the number of heads, and 6 for the number of sectors per track.
143 Disk geometries are not quite so simple
144 anymore, but to keep the interface useful,
145 modern disks and BIOSes present geometries
146 that still fit within these constraints.
147 These numbers are still used when partitioning
148 and formatting disks.
150 employs a number of heuristics to discover this
151 supposed geometry and store it in the
157 Disk offsets in partition tables and
158 in FAT descriptors are stored in a form
159 dependent upon these numbers, so
161 works hard to report numbers that
162 agree with those used by other operating
163 systems; the numbers bear little or no resemblance
166 .B /usr/local/plan9/src/libdisk/disk.c
169 \fIfloppy\fR(3) and \fIsd\fR(3)
171 Disks on Unix systems do not present the interface