Resent-Date: Tue, 24 Aug 1999 11:09:25 +0200 (MET DST)
To: zippel@fh-brandenburg.de (Roman Zippel)
Cc: bha@gmx.de (Bernd Harries), linux-m68k@lists.linux-m68k.org
Subject: Re: found problem: ioremap (?)
References: <m11JC8U-002O4HC@zeus.fh-brandenburg.de>
X-Yow: I'm ZIPPY the PINHEAD and I'm totally committed to the festive mode.
From: Andreas Schwab <schwab@suse.de>
Date: 24 Aug 1999 11:08:56 +0200
In-Reply-To: zippel@fh-brandenburg.de's message of "Tue, 24 Aug 1999 10:40:54 +0200 (MET DST)"
User-Agent: Gnus/5.070095 (Pterodactyl Gnus v0.95) Emacs/20.4
Resent-From: linux-m68k@phil.uni-sb.de


--=-=-=

zippel@fh-brandenburg.de (Roman Zippel) writes:

|> > 2.3.13 doesn't even get taht far. It doesn't like what it thinks to be a
|> > partition table.
|> > 
|> > Partition check:
|> >  sda: AHDI sda1 sda2
|> >  sdb: unknown partition table
|> >  sdc: unknown partition table
|> > Probing ACSI devices:
|> > Found 0 ACSI device(s) total.
|> 
|> Someone with some knowledge about the atari partition format could
|> compare the atari partition table code of the different kernels.

The new partition code requires the rootsector to be bootable.  This is
bogus.

Andreas.


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment; filename=partition-atari-patch

Index: fs/partitions/atari.c
===================================================================
RCS file: /usr/local/src/m68k-linux/cvsroot/linux/fs/partitions/atari.c,v
retrieving revision 1.1.1.1
diff -u -a -u -r1.1.1.1 fs/partitions/atari.c
--- fs/partitions/atari.c	1999/08/19 17:49:43	1.1.1.1
+++ fs/partitions/atari.c	1999/08/24 09:06:07
@@ -13,7 +13,9 @@
 #include <linux/major.h>
 #include <linux/string.h>
 #include <linux/blk.h>
+#include <linux/ctype.h>
 
+#include <asm/byteorder.h>
 #include <asm/system.h>
 
 #include "check.h"
@@ -23,6 +25,14 @@
  */
 #define ICD_PARTS
 
+/* check if a partition entry looks valid -- Atari format is assumed if at
+   least one of the primary entries is ok this way */
+#define	VALID_PARTITION(pi,hdsiz)					     \
+    (((pi)->flg & 1) &&							     \
+     isalnum((pi)->id[0]) && isalnum((pi)->id[1]) && isalnum((pi)->id[2]) && \
+     be32_to_cpu((pi)->st) <= (hdsiz) &&				     \
+     be32_to_cpu((pi)->st) + be32_to_cpu((pi)->siz) <= (hdsiz))
+
 int atari_partition (struct gendisk *hd, kdev_t dev,
 		     unsigned long first_sector, int first_part_minor)
 {
@@ -30,9 +40,8 @@
   struct buffer_head *bh;
   struct rootsector *rs;
   struct partition_info *pi;
-  ulong extensect;
-  unsigned int psum;
-  int i;
+  u32 extensect;
+  u32 hd_size;
 #ifdef ICD_PARTS
   int part_fmt = 0; /* 0:unknown, 1:AHDI, 2:ICD/Supra */
 #endif
@@ -44,16 +53,18 @@
   }
 
   /* Verify this is an Atari rootsector: */
-  psum = 0;
-  for (i=0;i<256;i++) {
-    psum+=ntohs(((__u16 *) (bh->b_data))[i]);
-  }
-  if ((psum & 0xFFFF) != 0x1234) {
-    brelse(bh);
-    return 0;
+  rs = (struct rootsector *) bh->b_data;
+  hd_size = hd->part[minor - 1].nr_sects;
+  if (!VALID_PARTITION(&rs->part[0], hd_size) &&
+      !VALID_PARTITION(&rs->part[1], hd_size) &&
+      !VALID_PARTITION(&rs->part[2], hd_size) &&
+      !VALID_PARTITION(&rs->part[3], hd_size)) {
+      /* if there's no valid primary partition, assume that no Atari
+	 format partition table (there's no reliable magic or the like
+	 :-() */
+      return 0;
   }
 
-  rs = (struct rootsector *) bh->b_data;
   pi = &rs->part[0];
   printk (" AHDI");
   for (; pi < &rs->part[4] && minor < m_lim; minor++, pi++)
@@ -72,7 +83,7 @@
 	      part_fmt = 1;
 #endif
 	      printk(" XGM<");
-	      partsect = extensect = ntohl(pi->st);
+	      partsect = extensect = be32_to_cpu(pi->st);
 	      while (1)
 		{
 		  xbh = bread (dev, partsect / 2, get_ptable_blocksize(dev));
@@ -93,8 +104,9 @@
 		    break;
 		  }
 
-		  add_gd_partition(hd, minor, partsect + ntohl(xrs->part[0].st),
-				ntohl(xrs->part[0].siz));
+		  add_gd_partition(hd, minor,
+				   partsect + be32_to_cpu(xrs->part[0].st),
+				   be32_to_cpu(xrs->part[0].siz));
 
 		  if (!(xrs->part[1].flg & 1)) {
 		    /* end of linked partition list */
@@ -107,7 +119,7 @@
 		    break;
 		  }
 
-		  partsect = ntohl(xrs->part[1].st) + extensect;
+		  partsect = be32_to_cpu(xrs->part[1].st) + extensect;
 		  brelse (xbh);
 		  minor++;
 		  if (minor >= m_lim) {
@@ -120,7 +132,8 @@
 	  else
 	    {
 	      /* we don't care about other id's */
-	      add_gd_partition (hd, minor, ntohl(pi->st), ntohl(pi->siz));
+	      add_gd_partition (hd, minor, be32_to_cpu(pi->st),
+				be32_to_cpu(pi->siz));
 	    }
 	}
     }
@@ -147,7 +160,8 @@
              memcmp (pi->id, "RAW", 3) == 0) )
         {
           part_fmt = 2;
-	  add_gd_partition (hd, minor, ntohl(pi->st), ntohl(pi->siz));
+	  add_gd_partition (hd, minor, be32_to_cpu(pi->st),
+			    be32_to_cpu(pi->siz));
         }
       }
       printk(" >");
Index: fs/partitions/atari.h
===================================================================
RCS file: /usr/local/src/m68k-linux/cvsroot/linux/fs/partitions/atari.h,v
retrieving revision 1.1.1.1
diff -u -a -u -r1.1.1.1 fs/partitions/atari.h
--- fs/partitions/atari.h	1999/08/19 17:49:43	1.1.1.1
+++ fs/partitions/atari.h	1999/08/24 09:01:20
@@ -13,10 +13,10 @@
 
 struct partition_info
 {
-  u_char flg;			/* bit 0: active; bit 7: bootable */
+  u8 flg;			/* bit 0: active; bit 7: bootable */
   char id[3];			/* "GEM", "BGM", "XGM", or other */
-  u_long st;			/* start of partition */
-  u_long siz;			/* length of partition */
+  u32 st;			/* start of partition */
+  u32 siz;			/* length of partition */
 };
 
 struct rootsector
@@ -24,11 +24,11 @@
   char unused[0x156];		/* room for boot code */
   struct partition_info icdpart[8];	/* info for ICD-partitions 5..12 */
   char unused2[0xc];
-  u_long hd_siz;		/* size of disk in blocks */
+  u32 hd_siz;			/* size of disk in blocks */
   struct partition_info part[4];
-  u_long bsl_st;		/* start of bad sector list */
-  u_long bsl_cnt;		/* length of bad sector list */
-  u_short checksum;		/* checksum for bootable disks */
+  u32 bsl_st;			/* start of bad sector list */
+  u32 bsl_cnt;			/* length of bad sector list */
+  u16 checksum;			/* checksum for bootable disks */
 } __attribute__((__packed__));
 
 int atari_partition (struct gendisk *hd, kdev_t dev,

--=-=-=
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit


-- 
Andreas Schwab                                  "And now for something
schwab@suse.de                                   completely different."
SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg

--=-=-=--

