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
31 disks and disk partitions,
32 as well as plain files.
37 for reading and stores the file descriptor in
49 for writing and stores that file descriptor in
51 The two file descriptors are kept separate to
52 help prevent accidents.
60 file in the same directory as the
62 if it finds one, it declares
81 declares the disk to be
82 a floppy disk, of type
86 file is found, it is opened for reading
87 and writing, and the resulting file descriptor
90 Otherwise the returned disk
95 then stats the file and stores its length in
101 reads the sector size from the
103 file and stores it in
105 otherwise the sector size is assumed to be 512,
106 as is the case for floppy disks.
108 then stores the disk size measured in sectors in
117 file to find the partition's offset
122 If the disk is an ATA disk,
125 the disk geometry (number of cylinders, heads, and sectors)
131 otherwise it sets these to zero as well.
133 is initialized with the base name of
134 the disk partition, and is useful for forming messages to the
138 is set to the passed filename without
143 The IBM PC BIOS interface allocates
144 10 bits for the number of cylinders, 8 for
145 the number of heads, and 6 for the number of sectors per track.
146 Disk geometries are not quite so simple
147 anymore, but to keep the interface useful,
148 modern disks and BIOSes present geometries
149 that still fit within these constraints.
150 These numbers are still used when partitioning
151 and formatting disks.
153 employs a number of heuristics to discover this
154 supposed geometry and store it in the
160 Disk offsets in partition tables and
161 in FAT descriptors are stored in a form
162 dependent upon these numbers, so
164 works hard to report numbers that
165 agree with those used by other operating
166 systems; the numbers bear little or no resemblance
169 .B /sys/src/libdisk/disk.c