Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: simplify scsi_partsize

Call scsi_bios_ptable from scsi_partsize instead of requiring boilerplate
code in the callers. Also switch the calling convention to match that
of the ->bios_param instances calling this function, and use true/false
for the return value instead of the weird -1 convention.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
a10183d7 26ae3533

+46 -95
-21
Documentation/scsi/scsi_mid_low_api.txt
··· 299 299 scsi_host_alloc - return a new scsi_host instance whose refcount==1 300 300 scsi_host_get - increments Scsi_Host instance's refcount 301 301 scsi_host_put - decrements Scsi_Host instance's refcount (free if 0) 302 - scsi_partsize - parse partition table into cylinders, heads + sectors 303 302 scsi_register - create and register a scsi host adapter instance. 304 303 scsi_remove_device - detach and remove a SCSI device 305 304 scsi_remove_host - detach and remove all SCSI devices owned by host ··· 469 470 * Defined in: drivers/scsi/hosts.c 470 471 **/ 471 472 void scsi_host_put(struct Scsi_Host *shost) 472 - 473 - 474 - /** 475 - * scsi_partsize - parse partition table into cylinders, heads + sectors 476 - * @buf: pointer to partition table 477 - * @capacity: size of (total) disk in 512 byte sectors 478 - * @cyls: outputs number of cylinders calculated via this pointer 479 - * @hds: outputs number of heads calculated via this pointer 480 - * @secs: outputs number of sectors calculated via this pointer 481 - * 482 - * Returns 0 on success, -1 on failure 483 - * 484 - * Might block: no 485 - * 486 - * Notes: Caller owns memory returned (free with kfree() ) 487 - * 488 - * Defined in: drivers/scsi/scsicam.c 489 - **/ 490 - int scsi_partsize(unsigned char *buf, unsigned long capacity, 491 - unsigned int *cyls, unsigned int *hds, unsigned int *secs) 492 473 493 474 494 475 /**
+3 -10
drivers/scsi/aic7xxx/aic79xx_osm.c
··· 723 723 ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev, 724 724 sector_t capacity, int geom[]) 725 725 { 726 - uint8_t *bh; 727 726 int heads; 728 727 int sectors; 729 728 int cylinders; 730 - int ret; 731 729 int extended; 732 730 struct ahd_softc *ahd; 733 731 734 732 ahd = *((struct ahd_softc **)sdev->host->hostdata); 735 733 736 - bh = scsi_bios_ptable(bdev); 737 - if (bh) { 738 - ret = scsi_partsize(bh, capacity, 739 - &geom[2], &geom[0], &geom[1]); 740 - kfree(bh); 741 - if (ret != -1) 742 - return (ret); 743 - } 734 + if (scsi_partsize(bdev, capacity, geom)) 735 + return 0; 736 + 744 737 heads = 64; 745 738 sectors = 32; 746 739 cylinders = aic_sector_div(capacity, heads, sectors);
+3 -10
drivers/scsi/aic7xxx/aic7xxx_osm.c
··· 695 695 ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev, 696 696 sector_t capacity, int geom[]) 697 697 { 698 - uint8_t *bh; 699 698 int heads; 700 699 int sectors; 701 700 int cylinders; 702 - int ret; 703 701 int extended; 704 702 struct ahc_softc *ahc; 705 703 u_int channel; ··· 705 707 ahc = *((struct ahc_softc **)sdev->host->hostdata); 706 708 channel = sdev_channel(sdev); 707 709 708 - bh = scsi_bios_ptable(bdev); 709 - if (bh) { 710 - ret = scsi_partsize(bh, capacity, 711 - &geom[2], &geom[0], &geom[1]); 712 - kfree(bh); 713 - if (ret != -1) 714 - return (ret); 715 - } 710 + if (scsi_partsize(bdev, capacity, geom)) 711 + return 0; 712 + 716 713 heads = 64; 717 714 sectors = 32; 718 715 cylinders = aic_sector_div(capacity, heads, sectors);
+4 -9
drivers/scsi/arcmsr/arcmsr_hba.c
··· 353 353 static int arcmsr_bios_param(struct scsi_device *sdev, 354 354 struct block_device *bdev, sector_t capacity, int *geom) 355 355 { 356 - int ret, heads, sectors, cylinders, total_capacity; 357 - unsigned char *buffer;/* return copy of block device's partition table */ 356 + int heads, sectors, cylinders, total_capacity; 358 357 359 - buffer = scsi_bios_ptable(bdev); 360 - if (buffer) { 361 - ret = scsi_partsize(buffer, capacity, &geom[2], &geom[0], &geom[1]); 362 - kfree(buffer); 363 - if (ret != -1) 364 - return ret; 365 - } 358 + if (scsi_partsize(bdev, capacity, geom)) 359 + return 0; 360 + 366 361 total_capacity = capacity; 367 362 heads = 64; 368 363 sectors = 32;
+2 -11
drivers/scsi/megaraid.c
··· 2795 2795 sector_t capacity, int geom[]) 2796 2796 { 2797 2797 adapter_t *adapter; 2798 - unsigned char *bh; 2799 2798 int heads; 2800 2799 int sectors; 2801 2800 int cylinders; 2802 - int rval; 2803 2801 2804 2802 /* Get pointer to host config structure */ 2805 2803 adapter = (adapter_t *)sdev->host->hostdata; ··· 2824 2826 geom[2] = cylinders; 2825 2827 } 2826 2828 else { 2827 - bh = scsi_bios_ptable(bdev); 2828 - 2829 - if( bh ) { 2830 - rval = scsi_partsize(bh, capacity, 2831 - &geom[2], &geom[0], &geom[1]); 2832 - kfree(bh); 2833 - if( rval != -1 ) 2834 - return rval; 2835 - } 2829 + if (scsi_partsize(bdev, capacity, geom)) 2830 + return 0; 2836 2831 2837 2832 dev_info(&adapter->dev->dev, 2838 2833 "invalid partition on this disk on channel %d\n",
+31 -30
drivers/scsi/scsicam.c
··· 48 48 49 49 /** 50 50 * scsi_partsize - Parse cylinders/heads/sectors from PC partition table 51 - * @buf: partition table, see scsi_bios_ptable() 51 + * @bdev: block device to parse 52 52 * @capacity: size of the disk in sectors 53 - * @cyls: put cylinders here 54 - * @hds: put heads here 55 - * @secs: put sectors here 53 + * @geom: output in form of [hds, cylinders, sectors] 56 54 * 57 55 * Determine the BIOS mapping/geometry used to create the partition 58 - * table, storing the results in @cyls, @hds, and @secs 56 + * table, storing the results in @geom. 59 57 * 60 - * Returns: -1 on failure, 0 on success. 58 + * Returns: %false on failure, %true on success. 61 59 */ 62 - 63 - int scsi_partsize(unsigned char *buf, unsigned long capacity, 64 - unsigned int *cyls, unsigned int *hds, unsigned int *secs) 60 + bool scsi_partsize(struct block_device *bdev, sector_t capacity, int geom[3]) 65 61 { 66 - struct partition *p = (struct partition *)buf, *largest = NULL; 67 - int i, largest_cyl; 68 62 int cyl, ext_cyl, end_head, end_cyl, end_sector; 69 63 unsigned int logical_end, physical_end, ext_physical_end; 64 + struct partition *p, *largest = NULL; 65 + void *buf; 66 + int ret = false; 70 67 68 + buf = scsi_bios_ptable(bdev); 69 + if (!buf) 70 + return false; 71 71 72 72 if (*(unsigned short *) (buf + 64) == 0xAA55) { 73 - for (largest_cyl = -1, i = 0; i < 4; ++i, ++p) { 73 + int largest_cyl = -1, i; 74 + 75 + for (i = 0, p = buf; i < 4; i++, p++) { 74 76 if (!p->sys_ind) 75 77 continue; 76 78 #ifdef DEBUG ··· 92 90 end_sector = largest->end_sector & 0x3f; 93 91 94 92 if (end_head + 1 == 0 || end_sector == 0) 95 - return -1; 93 + goto out_free_buf; 96 94 97 95 #ifdef DEBUG 98 96 printk("scsicam_bios_param : end at h = %d, c = %d, s = %d\n", ··· 117 115 ,logical_end, physical_end, ext_physical_end, ext_cyl); 118 116 #endif 119 117 120 - if ((logical_end == physical_end) || 121 - (end_cyl == 1023 && ext_physical_end == logical_end)) { 122 - *secs = end_sector; 123 - *hds = end_head + 1; 124 - *cyls = capacity / ((end_head + 1) * end_sector); 125 - return 0; 118 + if (logical_end == physical_end || 119 + (end_cyl == 1023 && ext_physical_end == logical_end)) { 120 + geom[0] = end_head + 1; 121 + geom[1] = end_sector; 122 + geom[2] = (unsigned long)capacity / 123 + ((end_head + 1) * end_sector); 124 + ret = true; 125 + goto out_free_buf; 126 126 } 127 127 #ifdef DEBUG 128 128 printk("scsicam_bios_param : logical (%u) != physical (%u)\n", 129 129 logical_end, physical_end); 130 130 #endif 131 131 } 132 - return -1; 132 + 133 + out_free_buf: 134 + kfree(buf); 135 + return ret; 133 136 } 134 137 EXPORT_SYMBOL(scsi_partsize); 135 138 ··· 217 210 */ 218 211 int scsicam_bios_param(struct block_device *bdev, sector_t capacity, int *ip) 219 212 { 220 - unsigned char *p; 221 213 u64 capacity64 = capacity; /* Suppress gcc warning */ 222 - int ret; 223 - 224 - p = scsi_bios_ptable(bdev); 225 - if (!p) 226 - return -1; 214 + int ret = 0; 227 215 228 216 /* try to infer mapping from partition table */ 229 - ret = scsi_partsize(p, (unsigned long)capacity, (unsigned int *)ip + 2, 230 - (unsigned int *)ip + 0, (unsigned int *)ip + 1); 231 - kfree(p); 217 + if (scsi_partsize(bdev, capacity, ip)) 218 + return 0; 232 219 233 - if (ret == -1 && capacity64 < (1ULL << 32)) { 220 + if (capacity64 < (1ULL << 32)) { 234 221 /* 235 222 * Pick some standard mapping with at most 1024 cylinders, and 236 223 * at most 62 sectors per track - this works up to 7905 MB.
+3 -4
include/scsi/scsicam.h
··· 13 13 14 14 #ifndef SCSICAM_H 15 15 #define SCSICAM_H 16 - extern int scsicam_bios_param (struct block_device *bdev, sector_t capacity, int *ip); 17 - extern int scsi_partsize(unsigned char *buf, unsigned long capacity, 18 - unsigned int *cyls, unsigned int *hds, unsigned int *secs); 19 - extern unsigned char *scsi_bios_ptable(struct block_device *bdev); 16 + int scsicam_bios_param(struct block_device *bdev, sector_t capacity, int *ip); 17 + bool scsi_partsize(struct block_device *bdev, sector_t capacity, int geom[3]); 18 + unsigned char *scsi_bios_ptable(struct block_device *bdev); 20 19 #endif /* def SCSICAM_H */