@@ -48,29 +48,31 @@ EXPORT_SYMBOL(scsi_bios_ptable);
4848
4949/**
5050 * scsi_partsize - Parse cylinders/heads/sectors from PC partition table
51- * @buf: partition table, see scsi_bios_ptable()
51+ * @bdev: block device to parse
5252 * @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]
5654 *
5755 * 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.
5957 *
60- * Returns: -1 on failure, 0 on success.
58+ * Returns: %false on failure, %true on success.
6159 */
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 ])
6561{
66- struct partition * p = (struct partition * )buf , * largest = NULL ;
67- int i , largest_cyl ;
6862 int cyl , ext_cyl , end_head , end_cyl , end_sector ;
6963 unsigned int logical_end , physical_end , ext_physical_end ;
64+ struct partition * p , * largest = NULL ;
65+ void * buf ;
66+ int ret = false;
7067
68+ buf = scsi_bios_ptable (bdev );
69+ if (!buf )
70+ return false;
7171
7272 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 ++ ) {
7476 if (!p -> sys_ind )
7577 continue ;
7678#ifdef DEBUG
@@ -90,7 +92,7 @@ int scsi_partsize(unsigned char *buf, unsigned long capacity,
9092 end_sector = largest -> end_sector & 0x3f ;
9193
9294 if (end_head + 1 == 0 || end_sector == 0 )
93- return -1 ;
95+ goto out_free_buf ;
9496
9597#ifdef DEBUG
9698 printk ("scsicam_bios_param : end at h = %d, c = %d, s = %d\n" ,
@@ -115,19 +117,24 @@ int scsi_partsize(unsigned char *buf, unsigned long capacity,
115117 ,logical_end , physical_end , ext_physical_end , ext_cyl );
116118#endif
117119
118- if ((logical_end == physical_end ) ||
119- (end_cyl == 1023 && ext_physical_end == logical_end )) {
120- * secs = end_sector ;
121- * hds = end_head + 1 ;
122- * cyls = capacity / ((end_head + 1 ) * end_sector );
123- return 0 ;
120+ if (logical_end == physical_end ||
121+ (end_cyl == 1023 && ext_physical_end == logical_end )) {
122+ geom [0 ] = end_head + 1 ;
123+ geom [1 ] = end_sector ;
124+ geom [2 ] = (unsigned long )capacity /
125+ ((end_head + 1 ) * end_sector );
126+ ret = true;
127+ goto out_free_buf ;
124128 }
125129#ifdef DEBUG
126130 printk ("scsicam_bios_param : logical (%u) != physical (%u)\n" ,
127131 logical_end , physical_end );
128132#endif
129133 }
130- return -1 ;
134+
135+ out_free_buf :
136+ kfree (buf );
137+ return ret ;
131138}
132139EXPORT_SYMBOL (scsi_partsize );
133140
@@ -210,20 +217,14 @@ static int setsize(unsigned long capacity, unsigned int *cyls, unsigned int *hds
210217 */
211218int scsicam_bios_param (struct block_device * bdev , sector_t capacity , int * ip )
212219{
213- unsigned char * p ;
214220 u64 capacity64 = capacity ; /* Suppress gcc warning */
215- int ret ;
216-
217- p = scsi_bios_ptable (bdev );
218- if (!p )
219- return -1 ;
221+ int ret = 0 ;
220222
221223 /* try to infer mapping from partition table */
222- ret = scsi_partsize (p , (unsigned long )capacity , (unsigned int * )ip + 2 ,
223- (unsigned int * )ip + 0 , (unsigned int * )ip + 1 );
224- kfree (p );
224+ if (scsi_partsize (bdev , capacity , ip ))
225+ return 0 ;
225226
226- if (ret == -1 && capacity64 < (1ULL << 32 )) {
227+ if (capacity64 < (1ULL << 32 )) {
227228 /*
228229 * Pick some standard mapping with at most 1024 cylinders, and
229230 * at most 62 sectors per track - this works up to 7905 MB.
0 commit comments