From owner-freebsd-doc@FreeBSD.ORG Tue Nov 22 00:18:13 2005 Return-Path: X-Original-To: freebsd-doc@freebsd.org Delivered-To: freebsd-doc@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4782916A41F for ; Tue, 22 Nov 2005 00:18:13 +0000 (GMT) (envelope-from littlesavage@rambler.ru) Received: from mxb.rambler.ru (mxb.rambler.ru [81.19.66.30]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7BB3143D5D for ; Tue, 22 Nov 2005 00:18:12 +0000 (GMT) (envelope-from littlesavage@rambler.ru) Received: from mailc.rambler.ru (mailc.rambler.ru [81.19.66.27]) by mxb.rambler.ru (Postfix) with ESMTP id 839D4837F3 for ; Tue, 22 Nov 2005 03:18:11 +0300 (MSK) Received: from ls.orionet.ru ([213.24.220.11]) (authenticated bits=0) by mailc.rambler.ru (8.12.10/8.12.10) with ESMTP id jAM0I8ev012517 for ; Tue, 22 Nov 2005 03:18:10 +0300 (MSK) Date: Tue, 22 Nov 2005 03:17:07 +0300 From: Alexey Illarionov To: freebsd-doc@freebsd.org Message-ID: <20051122031707.4e27f929@ls.orionet.ru> X-Mailer: Sylpheed-Claws 1.9.100 (GTK+ 2.6.4; i386-portbld-freebsd5.4) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Auth-User: littlesavage, whoson: (null) Subject: Arch-handbook, scsi-general, typos in XPT_CALC_GEOMETRY? X-BeenThere: freebsd-doc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Documentation project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Nov 2005 00:18:13 -0000 http://www.freebsd.org/doc/en_US.ISO8859-1/books/arch-handbook/scsi-general.html Quote: XPT_CALC_GEOMETRY - calculate logical (BIOS) geometry of the disk The arguments are transferred in the instance “struct ccb_calc_geometry ccg” of the union ccb: * block_size - input, block (A.K.A sector) size in bytes * volume_size - input, volume size in bytes (???) * cylinders - output, logical cylinders * heads - output, logical heads * secs_per_track - output, logical sectors per track The typical calculation example taken from the aic7xxx driver is: struct ccb_calc_geometry *ccg; u_int32_t size_mb; u_int32_t secs_per_cylinder; int extended; ccg = &ccb->ccg; size_mb = ccg->volume_size / ((1024L * 1024L) / ccg->block_size); extended = check_cards_EEPROM_for_extended_geometry(softc); The volume_size argument whether really it is the size of volume in bytes or in sectors? If it in bytes, how it seems to me, the variable size_mb is calculated not correctly ( should be size_mb = ccg->volume_size / (1024L * 1024L) ) If it in sectors it calculated not correctly too. It can cause division by zero, if ccg->block_size will be more than one mbyte ( > 1024L * 1024L) I understand, that it is almost impossible, but I get this in result of different error (usb/73307). If I remember arithmetics, ccg->volume_size / ((1024L * 1024L) / ccg->block_size) == ccg->volume_size * ((ccg->block_size / (1024L * 1024L)) == (ccg->volume_size * ccg->block_size) / (1024L * 1024L) Such formula is more intuitively clear and will not cause division by zero. It is only necessary for (ccg->volume_size * ccg->block_size) to use u_int64_t or manually check for overflows Besides aic7xxx driver now have this code: #if __FreeBSD_version >= 500000 cam_calc_geometry(ccg, extended); #else ... I think, it can be added to this part of handbook. What do you think about this?