From akiyama@kme.mei.co.jp  Tue Feb 11 18:49:56 1997
Received: from who.cdrom.com (who.cdrom.com [204.216.27.3])
          by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id SAA12880
          for <freebsd-gnats-submit@freebsd.org>; Tue, 11 Feb 1997 18:49:56 -0800 (PST)
Received: from vcgate3.mei.co.jp (vcgate3.mei.co.jp [202.32.14.53])
          by who.cdrom.com (8.7.5/8.6.11) with ESMTP id SAA03361
          for <freebsd-gnats-submit@freebsd.org>; Tue, 11 Feb 1997 18:36:37 -0800 (PST)
Received: by vcgate3.mei.co.jp (8.7.5+2.6Wbeta7/5.9:4.9:vcgate0:961204)
	id LAA19266; Wed, 12 Feb 1997 11:35:17 +0900 (JST)
Received: by vcmei.vanc.mei.co.jp (5.65mei1.1/5.9:4.9:vcmei:970206)
	id AA17581; Wed, 12 Feb 97 11:36:13 +0900
Received: by kmegate.kme.mei.co.jp (4.1/5.5:4.6:kmegate:970203)
	id AA15048; Wed, 12 Feb 97 11:35:32 JST
Message-Id: <9702120235.AA15048@kmegate.kme.mei.co.jp>
Date: Wed, 12 Feb 97 11:35:32 JST
From: Shunsuke Akiyama <akiyama@kme.mei.co.jp>
Reply-To: akiyama@kme.mei.co.jp
To: FreeBSD-gnats-submit@freebsd.org
Subject: MSDOS-FS 1024/2048 byte/sector media support.
X-Send-Pr-Version: 3.2

>Number:         2715
>Category:       kern
>Synopsis:       MSDOS-FS 1024/2048 byte/sector media support.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb 11 18:50:02 PST 1997
>Closed-Date:    Tue Sep 8 08:03:42 PDT 1998
>Last-Modified:  Tue Sep  8 08:08:20 PDT 1998
>Originator:     Shunsuke Akiyama
>Release:        FreeBSD 3.0-970124-SNAP i386
>Organization:
Kyushu Matsushita Electric Co., Ltd.
>Environment:

	FreeBSD 3.0-970124-SNAP/MSDOS-FS

>Description:

	In freebsd-scsi list, John Gumb (john@talisker.demon.co.uk) and
	Barry Scott (barry@scottb.demon.co.uk) posted their 1024 & 2048
	byte/sector media support patches.
	I've tested their patches and improved for MSDOS-FS support.
	It's works fine for me and other some FreeBSD environments with
	Fujitsu M2513A MO drive and 2048 byte/sector media.

>How-To-Repeat:

	N/A

>Fix:
	
===================================================================
--- sys/msdosfs/msdosfs_fat.c	1997/01/14 06:47:15	1.11
+++ sys/msdosfs/msdosfs_fat.c	1997/02/11 13:21:57
@@ -116,7 +116,7 @@
 	    * pmp->pm_BytesPerSec;
 	bn += pmp->pm_fatblk;
 	if (bnp)
-		*bnp = bn;
+		*bnp = bn * pmp->pm_SecBlkRatio;
 	if (sizep)
 		*sizep = size;
 	if (bop)
@@ -185,7 +185,7 @@
 				return E2BIG;
 			}
 			if (bnp)
-				*bnp = pmp->pm_rootdirblk + (findcn * pmp->pm_SectPerClust);
+				*bnp = (pmp->pm_rootdirblk + (findcn * pmp->pm_SectPerClust)) * pmp->pm_SecBlkRatio;
 			if (cnp)
 				*cnp = MSDOSFSROOT;
 			return 0;
@@ -340,7 +340,7 @@
 	 * bwrite()'s and really slow things down.
 	 */
 	for (i = 1; i < pmp->pm_FATs; i++) {
-		fatbn += pmp->pm_FATsecs;
+		fatbn += pmp->pm_FATsecs * pmp->pm_SecBlkRatio;
 		/* getblk() never fails */
 		bpn = getblk(pmp->pm_devvp, fatbn, bp->b_bcount, 0, 0);
 		bcopy(bp->b_data, bpn->b_data, bp->b_bcount);
===================================================================
--- sys/msdosfs/msdosfs_vfsops.c	1997/02/10 02:16:37	1.15
+++ sys/msdosfs/msdosfs_vfsops.c	1997/02/11 13:21:58
@@ -58,6 +58,9 @@
 #include <sys/mount.h>
 #include <sys/buf.h>
 #include <sys/file.h>
+#include <sys/disklabel.h>
+#include <sys/ioctl.h>
+#include <sys/errno.h>
 #include <sys/malloc.h>
 
 #include <msdosfs/bpb.h>
@@ -273,6 +276,8 @@
 	struct buf *bp0 = NULL;
 	struct byte_bpb33 *b33;
 	struct byte_bpb50 *b50;
+	struct partinfo msdosfspart;
+	int secsize;
 #ifdef	PC98
 	u_int	pc98_wrk;
 	u_int	Phy_Sector_Size;
@@ -300,14 +305,16 @@
 	if (error)
 		return error;
 	needclose = 1;
-#ifdef HDSUPPORT
+
 	/*
 	 * Put this in when we support reading dos filesystems from
 	 * partitioned harddisks.
 	 */
-	if (VOP_IOCTL(devvp, DIOCGPART, &msdosfspart, FREAD, NOCRED, p) == 0) {
+	if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&msdosfspart, FREAD, NOCRED, p) == 0) {
+		secsize = msdosfspart.disklab->d_secsize;
+	} else {
+		secsize = DEV_BSIZE;
 	}
-#endif
 
 	/*
 	 * Read the boot sector of the filesystem, and then check the boot
@@ -319,7 +326,7 @@
 	devvp->v_flag &= 0xffff; 
 	error = bread(devvp, 0, 1024, NOCRED, &bp0);
 #else
-	error = bread(devvp, 0, 512, NOCRED, &bp0);
+	error = bread(devvp, 0, secsize, NOCRED, &bp0);
 #endif
 	if (error)
 		goto error_exit;
@@ -349,6 +356,9 @@
 	pmp = malloc(sizeof *pmp, M_MSDOSFSMNT, M_WAITOK);
 	bzero((caddr_t)pmp, sizeof *pmp);
 	pmp->pm_mountp = mp;
+
+	/* calculate the ratio of sector size to DEV_BSIZE */
+	pmp->pm_SecBlkRatio = secsize/DEV_BSIZE;
 
 	/*
 	 * Compute several useful quantities from the bpb in the
===================================================================
--- sys/msdosfs/msdosfsmount.h	1997/02/10 02:16:44	1.8
+++ sys/msdosfs/msdosfsmount.h	1997/02/11 13:21:58
@@ -60,6 +60,9 @@
 	mode_t pm_mask;		/* mask to and with file protection bits */
 	struct vnode *pm_devvp;	/* vnode for block device mntd */
 	struct bpb50 pm_bpb;	/* BIOS parameter blk for this fs */
+	int pm_SecBlkRatio;	/* How many DEV_BSIZE blocks fit inside
+				 * a physical sector
+				 */
 	u_long pm_fatblk;	/* block # of first FAT */
 	u_long pm_rootdirblk;	/* block # of root directory */
 	u_long pm_rootdirsize;	/* size in blocks (not clusters) */
@@ -124,20 +127,20 @@
  * Map a cluster number into a filesystem relative block number.
  */
 #define	cntobn(pmp, cn) \
-	((((cn)-CLUST_FIRST) * (pmp)->pm_SectPerClust) + (pmp)->pm_firstcluster)
+	(((((cn)-CLUST_FIRST) * (pmp)->pm_SectPerClust) + (pmp)->pm_firstcluster) * (pmp)->pm_SecBlkRatio)
 
 /*
  * Map a filesystem relative block number back into a cluster number.
  */
 #define	bntocn(pmp, bn) \
-	((((bn) - pmp->pm_firstcluster)/ (pmp)->pm_SectPerClust) + CLUST_FIRST)
+	(((((bn)/((pmp)->pm_SecBlkRatio)) - pmp->pm_firstcluster)/ (pmp)->pm_SectPerClust) + CLUST_FIRST)
 
 /*
  * Calculate block number for directory entry in root dir, offset dirofs
  */
 #define	roottobn(pmp, dirofs) \
-	(((dirofs) / (pmp)->pm_depclust) * (pmp)->pm_SectPerClust \
-	+ (pmp)->pm_rootdirblk)
+	((((dirofs) / (pmp)->pm_depclust) * (pmp)->pm_SectPerClust \
+	+ (pmp)->pm_rootdirblk) * (pmp)->pm_SecBlkRatio)
 
 /*
  * Calculate block number for directory entry at cluster dirclu, offset

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: bde 
State-Changed-When: Tue Sep 8 08:03:42 PDT 1998 
State-Changed-Why:  
Superseded by PR 7210. 
>Unformatted:
