// SPDX-License-Identifier: GPL-2.0 /* * scsicam.c - SCSI CAM support functions, use for HDIO_GETGEO, etc. * * Copyright 1993, 1994 Drew Eckhardt * Visionary Computing * (Unix and Linux consulting and custom programming) * [email protected] * +1 (303) 786-7975 * * For more information, please consult the SCSI-CAM draft. */ #include <linux/module.h> #include <linux/slab.h> #include <linux/fs.h> #include <linux/kernel.h> #include <linux/blkdev.h> #include <linux/pagemap.h> #include <linux/msdos_partition.h> #include <linux/unaligned.h> #include <scsi/scsicam.h> /** * scsi_bios_ptable - Read PC partition table out of first sector of device. * @dev: from this device * * Description: Reads the first sector from the device and returns %0x42 bytes * starting at offset %0x1be. * Returns: partition table in kmalloc(GFP_KERNEL) memory, or NULL on error. */ unsigned char *scsi_bios_ptable(struct block_device *dev) { … } EXPORT_SYMBOL(…); /** * scsi_partsize - Parse cylinders/heads/sectors from PC partition table * @bdev: block device to parse * @capacity: size of the disk in sectors * @geom: output in form of [hds, cylinders, sectors] * * Determine the BIOS mapping/geometry used to create the partition * table, storing the results in @geom. * * Returns: %false on failure, %true on success. */ bool scsi_partsize(struct block_device *bdev, sector_t capacity, int geom[3]) { … } EXPORT_SYMBOL(…); /* * Function : static int setsize(unsigned long capacity,unsigned int *cyls, * unsigned int *hds, unsigned int *secs); * * Purpose : to determine a near-optimal int 0x13 mapping for a * SCSI disk in terms of lost space of size capacity, storing * the results in *cyls, *hds, and *secs. * * Returns : -1 on failure, 0 on success. * * Extracted from * * WORKING X3T9.2 * DRAFT 792D * see http://www.t10.org/ftp/t10/drafts/cam/cam-r12b.pdf * * Revision 6 * 10-MAR-94 * Information technology - * SCSI-2 Common access method * transport and SCSI interface module * * ANNEX A : * * setsize() converts a read capacity value to int 13h * head-cylinder-sector requirements. It minimizes the value for * number of heads and maximizes the number of cylinders. This * will support rather large disks before the number of heads * will not fit in 4 bits (or 6 bits). This algorithm also * minimizes the number of sectors that will be unused at the end * of the disk while allowing for very large disks to be * accommodated. This algorithm does not use physical geometry. */ static int setsize(unsigned long capacity, unsigned int *cyls, unsigned int *hds, unsigned int *secs) { … } /** * scsicam_bios_param - Determine geometry of a disk in cylinders/heads/sectors. * @bdev: which device * @capacity: size of the disk in sectors * @ip: return value: ip[0]=heads, ip[1]=sectors, ip[2]=cylinders * * Description : determine the BIOS mapping/geometry used for a drive in a * SCSI-CAM system, storing the results in ip as required * by the HDIO_GETGEO ioctl(). * * Returns : -1 on failure, 0 on success. */ int scsicam_bios_param(struct block_device *bdev, sector_t capacity, int *ip) { … } EXPORT_SYMBOL(…);