patch-2.4.0-test6 linux/fs/partitions/acorn.c

Next file: linux/fs/partitions/acorn.h
Previous file: linux/fs/open.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.0-test5/linux/fs/partitions/acorn.c linux/fs/partitions/acorn.c
@@ -1,11 +1,10 @@
 /*
  * linux/arch/arm/drivers/block/adfspart.c
  *
- * Copyright (c) 1996,1997 Russell King.
+ * Copyright (c) 1996-2000 Russell King.
  *
  * Scan ADFS partitions on hard disk drives.
  */
-
 #include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/kdev_t.h>
@@ -30,17 +29,9 @@
 #endif
 }
 
-#define LINUX_NATIVE_MAGIC 0xdeafa1de
-#define LINUX_SWAP_MAGIC   0xdeafab1e
-
-struct linux_part {
-	unsigned long magic;
-	unsigned long start_sect;
-	unsigned long nr_sects;
-};
-
-static struct adfs_discrecord *adfs_partition(struct gendisk *hd, char *name, char *data,
-					   unsigned long first_sector, unsigned int minor)
+static struct adfs_discrecord *
+adfs_partition(struct gendisk *hd, char *name, char *data,
+	       unsigned long first_sector, int minor)
 {
 	struct adfs_discrecord *dr;
 	unsigned int nr_sects;
@@ -63,8 +54,9 @@
 }
 
 #ifdef CONFIG_ACORN_PARTITION_RISCIX
-static int riscix_partition(struct gendisk *hd, kdev_t dev, unsigned long first_sect,
-			     unsigned int minor, unsigned long nr_sects)
+static int
+riscix_partition(struct gendisk *hd, kdev_t dev, unsigned long first_sect,
+		 int minor, unsigned long nr_sects)
 {
 	struct buffer_head *bh;
 	struct riscix_record *rr;
@@ -76,7 +68,8 @@
 	printk(" [RISCiX]");
 
 	add_gd_partition(hd, riscix_minor = minor++, first_sect, nr_sects);
-	hd->sizes[riscix_minor] = hd->part[riscix_minor].nr_sects >> (BLOCK_SIZE_BITS - 9);
+	hd->sizes[riscix_minor] = hd->part[riscix_minor].nr_sects >>
+					(BLOCK_SIZE_BITS - 9);
 	dev = MKDEV(hd->major, riscix_minor);
 
 	if (!(bh = bread(dev, 0, 1024)))
@@ -109,8 +102,9 @@
 }
 #endif
 
-static int linux_partition(struct gendisk *hd, kdev_t dev, unsigned long first_sect,
-			    unsigned int minor, unsigned long nr_sects)
+static int
+linux_partition(struct gendisk *hd, kdev_t dev, unsigned long first_sect,
+		int minor, unsigned long nr_sects)
 {
 	struct buffer_head *bh;
 	struct linux_part *linuxp;
@@ -122,7 +116,8 @@
 	printk(" [Linux]");
 
 	add_gd_partition(hd, linux_minor = minor++, first_sect, nr_sects);
-	hd->sizes[linux_minor] = hd->part[linux_minor].nr_sects >> (BLOCK_SIZE_BITS - 9);
+	hd->sizes[linux_minor] = hd->part[linux_minor].nr_sects >>
+					(BLOCK_SIZE_BITS - 9);
 	dev = MKDEV(hd->major, linux_minor);
 
 	if (!(bh = bread(dev, 0, 1024)))
@@ -151,8 +146,9 @@
 }
 
 #ifdef CONFIG_ACORN_PARTITION_CUMANA
-static int adfspart_check_CUMANA(struct gendisk *hd, kdev_t dev, unsigned long first_sector,
-				  unsigned int minor)
+static int
+adfspart_check_CUMANA(struct gendisk *hd, kdev_t dev,
+		      unsigned long first_sector, int minor)
 {
 	unsigned int start_blk = 0, mask = (1 << hd->minor_shift) - 1;
 	struct buffer_head *bh = NULL;
@@ -163,16 +159,17 @@
 		return 0;
 
 	/*
-	 * Try Cumana style partitions - sector 3 contains ADFS boot block with pointer
-	 * to next 'drive'.
+	 * Try Cumana style partitions - sector 3 contains ADFS boot block
+	 * with pointer to next 'drive'.
 	 *
-	 * There are unknowns in this code - is the 'cylinder number' of the next
-	 * partition relative to the start of this one - I'm assuming it is.
+	 * There are unknowns in this code - is the 'cylinder number' of the
+	 * next partition relative to the start of this one - I'm assuming
+	 * it is.
 	 *
 	 * Also, which ID did Cumana use?
 	 *
-	 * This is totally unfinished, and will require more work to get it going.
-	 * Hence it is totally untested.
+	 * This is totally unfinished, and will require more work to get it
+	 * going. Hence it is totally untested.
 	 */
 	do {
 		struct adfs_discrecord *dr;
@@ -184,7 +181,8 @@
 		if (!(bh = bread(dev, start_blk + 3, 1024)))
 			return -1;
 
-		dr = adfs_partition(hd, name, bh->b_data, first_sector, minor++);
+		dr = adfs_partition(hd, name, bh->b_data,
+				    first_sector, minor++);
 		if (!dr)
 			break;
 		name = NULL;
@@ -206,13 +204,16 @@
 			break;
 
 #ifdef CONFIG_ACORN_PARTITION_RISCIX
-		case PARTITION_RISCIX_SCSI: /* RiscIX - we don't know how to find the next one. */
-			minor = riscix_partition(hd, dev, first_sector, minor, nr_sects);
+		case PARTITION_RISCIX_SCSI:
+			/* RISCiX - we don't know how to find the next one. */
+			minor = riscix_partition(hd, dev, first_sector,
+						 minor, nr_sects);
 			break;
 #endif
 
 		case PARTITION_LINUX:
-			minor = linux_partition(hd, dev, first_sector, minor, nr_sects);
+			minor = linux_partition(hd, dev, first_sector,
+						minor, nr_sects);
 			break;
 		}
 		brelse(bh);
@@ -221,7 +222,7 @@
 			return minor;
 	} while (1);
 	if (bh)
-		brelse(bh);
+		bforget(bh);
 	return first ? 0 : 1;
 }
 #endif
@@ -241,8 +242,9 @@
  *	    hda1 = ADFS partition on first drive.
  *	    hda2 = non-ADFS partition.
  */
-static int adfspart_check_ADFS(struct gendisk *hd, kdev_t dev, unsigned long first_sector,
-				unsigned int minor)
+static int
+adfspart_check_ADFS(struct gendisk *hd, kdev_t dev,
+		   unsigned long first_sector, int minor)
 {
 	unsigned long start_sect, nr_sects, sectscyl, heads;
 	struct buffer_head *bh;
@@ -256,12 +258,13 @@
 
 	dr = adfs_partition(hd, "ADFS", bh->b_data, first_sector, minor++);
 	if (!dr) {
-	    	brelse(bh);
+		bforget(bh);
     		return 0;
 	}
 
 	heads = dr->heads + ((dr->lowsector >> 6) & 1);
-	adfspart_setgeometry(dev, dr->secspertrack, heads, hd->part[MINOR(dev)].nr_sects);
+	adfspart_setgeometry(dev, dr->secspertrack, heads,
+			     hd->part[MINOR(dev)].nr_sects);
 	sectscyl = dr->secspertrack * heads;
 
 	/*
@@ -272,21 +275,19 @@
 
 	if (start_sect) {
 		first_sector += start_sect;
-		/*
-		 * we now have a problem - how to set the origional disk size if the
-		 * disk doesn't report it, since there is no standard way of getting
-		 * that info.
-		 */
+
 		switch (bh->b_data[0x1fc] & 15) {
 #ifdef CONFIG_ACORN_PARTITION_RISCIX
 		case PARTITION_RISCIX_SCSI:
 		case PARTITION_RISCIX_MFM:
-			minor = riscix_partition(hd, dev, first_sector, minor, nr_sects);
+			minor = riscix_partition(hd, dev, first_sector,
+						 minor, nr_sects);
 			break;
 #endif
 
 		case PARTITION_LINUX:
-			minor = linux_partition(hd, dev, first_sector, minor, nr_sects);
+			minor = linux_partition(hd, dev, first_sector,
+						minor, nr_sects);
 			break;
 		}
 	}
@@ -326,13 +327,14 @@
  *	    hda2 = ADFS partition 1 on first drive.
  *		..etc..
  */
-static int adfspart_check_ICS(struct gendisk *hd, kdev_t dev, unsigned long first_sector,
-			       unsigned int minor)
+static int
+adfspart_check_ICS(struct gendisk *hd, kdev_t dev,
+		   unsigned long first_sector, int minor)
 {
 	struct buffer_head *bh;
 	unsigned long sum;
 	unsigned int i, mask = (1 << hd->minor_shift) - 1;
-	struct ics_part { unsigned long start; signed long size; } *p;
+	struct ics_part *p;
 
 	if(get_ptable_blocksize(dev)!=1024)
 		return 0;
@@ -349,9 +351,9 @@
 	for (i = 0, sum = 0x50617274; i < 508; i++)
 		sum += bh->b_data[i];
 
-	sum -= le32_to_cpu(*(unsigned long *)(&bh->b_data[508]));
+	sum -= le32_to_cpu(*(__u32 *)(&bh->b_data[508]));
 	if (sum) {
-	    	brelse(bh);
+	    	bforget(bh);
 		return 0; /* not ICS partition table */
 	}
 
@@ -392,15 +394,6 @@
 #endif
 
 #ifdef CONFIG_ACORN_PARTITION_POWERTEC
-struct ptec_partition {
-	u32 unused1;
-	u32 unused2;
-	u32 start;
-	u32 size;
-	u32 unused5;
-	char type[8];
-};
-	
 /*
  * Purpose: allocate ICS partitions.
  * Params : hd		- pointer to gendisk structure to store partition info.
@@ -413,8 +406,9 @@
  *	    hda2 = ADFS partition 1 on first drive.
  *		..etc..
  */
-static int adfspart_check_POWERTEC(struct gendisk *hd, kdev_t dev, unsigned long first_sector,
-				   unsigned int minor)
+static int
+adfspart_check_POWERTEC(struct gendisk *hd, kdev_t dev,
+			unsigned long first_sector, int minor)
 {
 	struct buffer_head *bh;
 	struct ptec_partition *p;
@@ -428,7 +422,7 @@
 		checksum += bh->b_data[i];
 
 	if (checksum != bh->b_data[511]) {
-		brelse(bh);
+		bforget(bh);
 		return 0;
 	}
 
@@ -452,44 +446,44 @@
 }
 #endif
 
+static int (*partfn[])(struct gendisk *, kdev_t, unsigned long, int) = {
+#ifdef CONFIG_ACORN_PARTITION_ICS
+	adfspart_check_ICS,
+#endif
+#ifdef CONFIG_ACORN_PARTITION_CUMANA
+	adfspart_check_CUMANA,
+#endif
+#ifdef CONFIG_ACORN_PARTITION_ADFS
+	adfspart_check_ADFS,
+#endif
+#ifdef CONFIG_ACORN_PARTITION_POWERTEC
+	adfspart_check_POWERTEC,
+#endif
+	NULL
+};
 /*
  * Purpose: initialise all the partitions on an ADFS drive.
- *          These may be other ADFS partitions or a Linux/RiscBSD/RiscIX
+ *          These may be other ADFS partitions or a Linux/RiscBSD/RISCiX
  *	    partition.
  *
- * Params : hd		 - pointer to gendisk structure to store devices partitions.
- *          dev		 - device number to access
- *	    first_sector - first available sector on the disk.
- *	    minor	 - first available minor on this device.
+ * Params : hd		- pointer to gendisk structure
+ *          dev		- device number to access
+ *	    first_sect  - first available sector on the disk.
+ *	    first_minor	- first available minor on this device.
  *
  * Returns: -1 on error, 0 if not ADFS format, 1 if ok.
  */
 int acorn_partition(struct gendisk *hd, kdev_t dev,
-		    unsigned long first_sector, int first_part_minor)
+		    unsigned long first_sect, int first_minor)
 {
-	int r = 0;
+	int r = 0, i;
 
-#ifdef CONFIG_ACORN_PARTITION_ICS
-	if (r == 0)
-		r = adfspart_check_ICS(hd, dev, first_sector, first_part_minor);
-#endif
-#ifdef CONFIG_ACORN_PARTITION_CUMANA
-	if (r == 0)    
-		r = adfspart_check_CUMANA(hd, dev, first_sector, first_part_minor);
-#endif
-#ifdef CONFIG_ACORN_PARTITION_ADFS
-	if (r == 0)
-		r = adfspart_check_ADFS(hd, dev, first_sector, first_part_minor);
-#endif
-#ifdef CONFIG_ACORN_PARTITION_POWERTEC
-	if (r == 0)
-		r = adfspart_check_POWERTEC(hd, dev, first_sector, first_part_minor);
-#endif
-	if (r < 0) {
-		if (warn_no_part)
-			printk(" unable to read boot sectors / partition sectors\n");
-	} else if (r) {
+	for (i = 0; partfn[i] && r == 0; i++)
+		r = partfn[i](hd, dev, first_sect, first_minor);
+
+	if (r < 0 && warn_no_part)
+		printk(" unable to read boot sectors / partition sectors\n");
+	if (r > 0)
 		printk("\n");
-	}
 	return r;
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)