NetBSD Problem Report #7652

From ISDN
Received: (qmail 16655 invoked from network); 26 May 1999 22:56:28 -0000
Message-Id: <3TIOlMD3CaUz1@mobile.apg.lahn.de>
Date: Wed, 26 May 1999 23:28:37 +0200
From: TetiSoft@apg.lahn.de (=?ISO-8859-1?Q?Detlef_W=FCrkner?=)
To: gnats-bugs@gnats.netbsd.org
Subject: adosfs and media with sector size greater than 512 bytes
References: <3THzhMD3CaUz1@mobile.apg.lahn.de>
X-Send-Pr-Version: 3.95

>Number:         7652
>Category:       port-amiga
>Synopsis:       adosfs doesn't work with media with sector size > 512.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-amiga-maintainer
>State:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed May 26 16:05:01 +0000 1999
>Closed-Date:    Thu Jun 03 12:32:11 +0000 1999
>Last-Modified:  Thu Jun 03 12:33:28 +0000 1999
>Originator:     Detlef Wuerkner
>Release:        Sat May  8 21:10:58 UTC 1999
>Organization:
>Environment:
	Amiga 4000, CyberStorm MkII/060/SCSI, 640MB MO-drive, NetBSD1.4/amiga
System: NetBSD mobile 1.4 NetBSD 1.4 (GENERIC) #50: Sun May 9 17:10:33 MEST 1999 is@jocelyn:/usr/obj/kernel/GENERIC amiga


>Description:
	AmigaDOS-partitions on media with physical sektor size greater
	than the normal 512 bytes can't be mounted with adosfs from
	NetBSD 1.4/amiga.
	I've choosen "port-amiga" as category for this problem report
	since non-Amiga-architectures will almost never try to read
	via adosfs from non-512-bytes/sector media: floppy disks have
	512 byte sectors and other media normally contain an AmigaOS
	rigid disk block, which only the Amiga version of NetBSD can
	read.
>How-To-Repeat:
	Of course you need media with physical sector size greater than
	512 bytes, for example 3,5" 640MB MO-media (2048 bytes/sector).
	Partition it on an amiga with the latest HDToolBox (40.4) and
	AmigaOS fast file system (43.20), format it, copy some data
	on it and try to mount under NetBSD with adosfs.
	You must first apply the patches suggested in the previous
	problem report ("Can't use media with sector size greater than
	512") to be able to find the partition you want to mount.
>Fix:
	The reason for the problem is the fact that NetBSD counts blocks
	in DEV_BSIZE units (always 512?), but AmigaOS and current adosfs
	counts blocks in physical units.

	In /usr/src/sys/dev/scsipi/sd.c, routine sdstart() adjusts the
	block numbers, it changes from DEV_BSIZE units to physical units:
	blkno = bp->b_blkno / (lp->d_secsize / DEV_BSIZE);
	As long as media with sector sizes of 512 bytes are used, this
	doesn't matter (divide by 1), but for successfull usage of media
	with greater sector sizes (e.g. 640MB MO-media with
	2048 bytes/sector) we must multiply block numbers with
	(physical sector size / DEV_BSIZE) to get the DEV_BSIZE units
	sd.c relies on.

	Several other problem reports dealt with the adjustment from
	physical to DEV_BSIZE units in sd.c, especially the PR's
	number 495, 3460, 3790, 3791 and 3792, all years old. Since
	nothing changed until now, I suggest the following changes to
	/usr/src/sys/adosfs/*

	adosfs already contains the correct handling of partitions with
	"File system block size" (HDToolBox) that is a multiple of the
	physical sektor size. This is done by multiplying/dividing the
	block number with amp->secsperblk. Just replace amp->secsperblk
	with (amp->blksize / DEV_BSIZE). amp->blksize already contains
	amp->secsperblk as well as the physical sector size.

	After applying these changes and that from the previous problem
	report, I succesfully managed to mount and read the following
	AmigaDOS-partitions in NetBSD:

	         |physical  |file system
	   medium|block size|block size
	---------+----------+-----------
	 harddisk|    512   |    512
	 harddisk|    512   |   1024
	 harddisk|    512   |   2048
	ZIP drive|    512   |   1024
	 MO drive|   2048   |   2048
	 MO drive|   2048   |  16384

OK, and here are the diffs:

*** adutil.c.orig	Tue May 25 13:33:35 1999
--- adutil.c	Tue May 25 13:35:22 1999
***************
*** 108,114 ****
  	if (adoscksum(bp, amp->nwords)) {
  #ifdef DIAGNOSTIC
  		printf("adosfs: aget: cksum of blk %ld failed\n",
! 		    bp->b_blkno / amp->secsperblk);
  #endif
  		return (-1);
  	}
--- 108,114 ----
  	if (adoscksum(bp, amp->nwords)) {
  #ifdef DIAGNOSTIC
  		printf("adosfs: aget: cksum of blk %ld failed\n",
! 		    bp->b_blkno / (amp->bsize / DEV_BSIZE));
  #endif
  		return (-1);
  	}
***************
*** 119,125 ****
  	if (adoswordn(bp, 0) != BPT_SHORT) {
  #ifdef DIAGNOSTIC
  		printf("adosfs: aget: bad primary type blk %ld (type = %d)\n",
! 		    bp->b_blkno / amp->secsperblk, adoswordn(bp,0));
  #endif
  		return (-1);
  	}
--- 119,125 ----
  	if (adoswordn(bp, 0) != BPT_SHORT) {
  #ifdef DIAGNOSTIC
  		printf("adosfs: aget: bad primary type blk %ld (type = %d)\n",
! 		    bp->b_blkno / (amp->bsize / DEV_BSIZE), adoswordn(bp,0));
  #endif
  		return (-1);
  	}
***************
*** 144,150 ****

  #ifdef DIAGNOSTIC
  	printf("adosfs: aget: bad secondary type blk %ld (type = %d)\n",
! 	    bp->b_blkno / amp->secsperblk, adoswordn(bp, amp->nwords - 1));
  #endif

  	return (-1);
--- 144,150 ----

  #ifdef DIAGNOSTIC
  	printf("adosfs: aget: bad secondary type blk %ld (type = %d)\n",
! 	    bp->b_blkno / (amp->bsize / DEV_BSIZE), adoswordn(bp, amp->nwords - 1));
  #endif

  	return (-1);
*** advfsops.c.orig	Fri Feb 26 23:44:43 1999
--- advfsops.c	Tue May 25 15:01:33 1999
***************
*** 395,401 ****
  	ap->nwords = amp->nwords;
  	adosfs_ainshash(amp, ap);

! 	if ((error = bread(amp->devvp, an * amp->secsperblk,
  			   amp->bsize, NOCRED, &bp)) != 0) {
  		brelse(bp);
  		vput(vp);
--- 395,401 ----
  	ap->nwords = amp->nwords;
  	adosfs_ainshash(amp, ap);

! 	if ((error = bread(amp->devvp, an * amp->bsize / DEV_BSIZE,
  			   amp->bsize, NOCRED, &bp)) != 0) {
  		brelse(bp);
  		vput(vp);
***************
*** 514,520 ****
  		ap->lastindblk = ap->linkto;
  		brelse(bp);
  		bp = NULL;
! 		error = bread(amp->devvp, ap->linkto * amp->secsperblk,
  		    amp->bsize, NOCRED, &bp);
  		if (error) {
  			brelse(bp);
--- 514,520 ----
  		ap->lastindblk = ap->linkto;
  		brelse(bp);
  		bp = NULL;
! 		error = bread(amp->devvp, ap->linkto * amp->bsize / DEV_BSIZE,
  		    amp->bsize, NOCRED, &bp);
  		if (error) {
  			brelse(bp);
***************
*** 595,601 ****

  	bp = mapbp = NULL;
  	bn = amp->rootb;
! 	if ((error = bread(amp->devvp, bn * amp->secsperblk, amp->bsize,
  	    NOCRED, &bp)) != 0) {
  		brelse(bp);
  		return (error);
--- 595,601 ----

  	bp = mapbp = NULL;
  	bn = amp->rootb;
! 	if ((error = bread(amp->devvp, bn * amp->bsize / DEV_BSIZE, amp->bsize,
  	    NOCRED, &bp)) != 0) {
  		brelse(bp);
  		return (error);
***************
*** 613,619 ****
  		if (mapbp != NULL)
  			brelse(mapbp);
  		if ((error = bread(amp->devvp,
! 		    adoswordn(bp, blkix) * amp->secsperblk, amp->bsize,
  		     NOCRED, &mapbp)) != 0)
  			break;
  		if (adoscksum(mapbp, amp->nwords)) {
--- 613,619 ----
  		if (mapbp != NULL)
  			brelse(mapbp);
  		if ((error = bread(amp->devvp,
! 		    adoswordn(bp, blkix) * amp->bsize / DEV_BSIZE, amp->bsize,
  		     NOCRED, &mapbp)) != 0)
  			break;
  		if (adoscksum(mapbp, amp->nwords)) {
***************
*** 640,646 ****
  		if (mapix < bmsize && blkix == endix) {
  			bn = adoswordn(bp, blkix);
  			brelse(bp);
! 			if ((error = bread(amp->devvp, bn * amp->secsperblk,
  			    amp->bsize, NOCRED, &bp)) != 0)
  				break;
  			/*
--- 640,646 ----
  		if (mapix < bmsize && blkix == endix) {
  			bn = adoswordn(bp, blkix);
  			brelse(bp);
! 			if ((error = bread(amp->devvp, bn * amp->bsize / DEV_BSIZE,
  			    amp->bsize, NOCRED, &bp)) != 0)
  				break;
  			/*
*** advnops.c.orig	Mon Mar 22 19:21:07 1999
--- advnops.c	Tue May 25 15:03:36 1999
***************
*** 288,294 ****
  		 * but not much as ados makes little attempt to 
  		 * make things contigous
  		 */
! 		error = bread(sp->a_vp, lbn * amp->secsperblk,
  			      amp->bsize, NOCRED, &bp);
  		if (error) {
  			brelse(bp);
--- 288,294 ----
  		 * but not much as ados makes little attempt to 
  		 * make things contigous
  		 */
! 		error = bread(sp->a_vp, lbn * amp->bsize / DEV_BSIZE,
  			      amp->bsize, NOCRED, &bp);
  		if (error) {
  			brelse(bp);
***************
*** 302,315 ****
  			else if (adoswordn(bp, 0) != BPT_DATA) {
  #ifdef DIAGNOSTIC
  				printf("adosfs: bad primary type blk %ld\n",
! 				    bp->b_blkno / amp->secsperblk);
  #endif
  				error=EINVAL;
  			}
  			else if ( adoscksum(bp, ap->nwords)) {
  #ifdef DIAGNOSTIC
  				printf("adosfs: blk %ld failed cksum.\n",
! 				    bp->b_blkno / amp->secsperblk);
  #endif
  				error=EINVAL;
  			}
--- 302,315 ----
  			else if (adoswordn(bp, 0) != BPT_DATA) {
  #ifdef DIAGNOSTIC
  				printf("adosfs: bad primary type blk %ld\n",
! 				    bp->b_blkno / (amp->bsize / DEV_BSIZE));
  #endif
  				error=EINVAL;
  			}
  			else if ( adoscksum(bp, ap->nwords)) {
  #ifdef DIAGNOSTIC
  				printf("adosfs: blk %ld failed cksum.\n",
! 				    bp->b_blkno / (amp->bsize / DEV_BSIZE));
  #endif
  				error=EINVAL;
  			}
***************
*** 496,502 ****
  	advopprint(sp);
  #endif
  	ap = VTOA(sp->a_vp);
! 	bn = sp->a_bn / ap->amp->secsperblk;
  	bnp = sp->a_bnp;
  	error = 0;

--- 496,502 ----
  	advopprint(sp);
  #endif
  	ap = VTOA(sp->a_vp);
! 	bn = sp->a_bn / (ap->amp->bsize / DEV_BSIZE);
  	bnp = sp->a_bnp;
  	error = 0;

***************
*** 549,555 ****
  			error = EINVAL;
  			goto reterr;
  		}
! 		error = bread(ap->amp->devvp, nb * ap->amp->secsperblk,
  			      ap->amp->bsize, NOCRED, &flbp);
  		if (error) {
  			brelse(flbp);
--- 549,555 ----
  			error = EINVAL;
  			goto reterr;
  		}
! 		error = bread(ap->amp->devvp, nb * ap->amp->bsize / DEV_BSIZE,
  			      ap->amp->bsize, NOCRED, &flbp);
  		if (error) {
  			brelse(flbp);
***************
*** 580,590 ****
  	flblkoff = bn % ANODENDATBLKENT(ap);
  	if (flblkoff < adoswordn(flbp, 2 /* ADBI_NBLKTABENT */)) {
  		flblkoff = (ap->nwords - 51) - flblkoff;
! 		*bnp = adoswordn(flbp, flblkoff) * ap->amp->secsperblk;
  	} else {
  #ifdef DIAGNOSTIC
  		printf("flblk offset %ld too large in lblk %ld blk %d\n", 
! 		    flblkoff, bn / ap->amp->secsperblk , flbp->b_blkno);
  #endif
  		error = EINVAL;
  	}
--- 580,590 ----
  	flblkoff = bn % ANODENDATBLKENT(ap);
  	if (flblkoff < adoswordn(flbp, 2 /* ADBI_NBLKTABENT */)) {
  		flblkoff = (ap->nwords - 51) - flblkoff;
! 		*bnp = adoswordn(flbp, flblkoff) * ap->amp->bsize / DEV_BSIZE;
  	} else {
  #ifdef DIAGNOSTIC
  		printf("flblk offset %ld too large in lblk %ld blk %d\n", 
! 		    flblkoff, bn / (ap->amp->bsize / DEV_BSIZE), flbp->b_blkno);
  #endif
  		error = EINVAL;
  	}

Ciao, Detlef
-- 
_ // TetiSoft@apg.lahn.de
\X/  Detlef Wuerkner, Giessen, Germany

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: is 
State-Changed-When: Thu Jun 3 05:32:11 PDT 1999 
State-Changed-Why:  
Applied submitted changes. 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.49 2026/05/14 01:52:41 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.