[parisc-linux-cvs] fix #125, some output cleanup

bame@riverrock.org bame@riverrock.org
Sun, 13 May 2001 22:04:24 -0600


These changes are pretty tedious for the most part.  Fixing bug #125
meant producing and checking error codes in palo/palo/paloio.c

Index: debian/changelog
===================================================================
RCS file: /home/cvs/parisc/palo/debian/changelog,v
retrieving revision 1.4
diff -u -r1.4 changelog
--- changelog	2001/05/11 22:03:27	1.4
+++ changelog	2001/05/14 03:53:35
@@ -1,4 +1,15 @@
+palo (0.89) unstable; urgency=high
+
+
+  * Palo can now prepare disks >2G on 32-bit kernels (even though it
+    is not using large file I/O calls, which are not useful yet anyway).
+    (fixes bugs.parisc-linux.org #125)
+   * fixed bugs.parisc-linux.org #89
+
+ -- Paul Bame <bame@debian.org>  Fri, 11 May 2001 19:07:18 -0600
+
 palo (0.88) unstable; urgency=high
+
   * Fix several lintian bugs by uncommenting 2 lines in debian/rules
 
  -- Paul Bame <bame@debian.org>  Fri, 11 May 2001 16:07:18 -0600
Index: ipl/ipl.c
===================================================================
RCS file: /home/cvs/parisc/palo/ipl/ipl.c,v
retrieving revision 1.15
diff -u -r1.15 ipl.c
--- ipl.c	2001/03/14 00:39:28	1.15
+++ ipl.c	2001/05/14 03:53:35
@@ -116,7 +116,7 @@
 
     if (!prepare_loadable(fd, &loadable, wide))
     {
-	printf("Couldn't grok your kernel executable format\r\n");
+	printf("Couldn't grok your kernel executable format\n\r");
 	return 0;
     }
 
@@ -124,13 +124,13 @@
     loadable.entry = PHYS(loadable.entry);
     loadable.first = PHYS(loadable.first);
 
-    printf("\r\nEntry %08x first %08x n %d\r\n",
+    printf("\n\rEntry %08x first %08x n %d\n\r",
 		loadable.entry, loadable.first, loadable.n);
 
     for (i = 0; i < loadable.n; i++)
     {
 	loadable.segment[i].mem =  PHYS(loadable.segment[i].mem);
-	printf("Segment %d load %08x size %d mediaptr 0x%lx\r\n",
+	printf("Segment %d load %08x size %d mediaptr 0x%lx\n\r",
 		i, loadable.segment[i].mem, loadable.segment[i].length,
 		loadable.segment[i].offset);
     }
@@ -138,7 +138,7 @@
 
     if (!load_loadable((char *)loadable.first, fd, &loadable))
     {
-	printf("Fatal error loading kernel executable\r\n");
+	printf("Fatal error loading kernel executable\n\r");
 	return 0;
     }
 
@@ -167,7 +167,7 @@
 	rd_end = rd + size;
     }
     flush_data_cache((char *)rd, size);
-    puts("\r\n");
+    puts("\n\r");
 
     return (rd_start != 0);
 }
@@ -199,7 +199,7 @@
 
     while (1)
     {
-	printf("Current command line:\r\n%s\r\n", f->cmdline);
+	printf("Current command line:\n\r%s\n\r", f->cmdline);
 	p = f->cmdline;
 	argc = 0;
 	do
@@ -213,13 +213,13 @@
 	} while (1);
 	for (i = 0; i < argc; i++)
 	{
-	    printf("%2d: %s\r\n", i, argv[i]);
+	    printf("%2d: %s\n\r", i, argv[i]);
 	}
-	puts("\r\nEdit which field?\r\n(or 'b' to boot with this command line)? ");
+	puts("\n\rEdit which field?\n\r(or 'b' to boot with this command line)? ");
 	numbuf[0] = '0';
 	numbuf[1] = '\0';
 	enter_text(numbuf, sizeof numbuf - 1);
-	puts("\r\n");
+	puts("\n\r");
 
 	if (numbuf[0] == 'b')
 	{
@@ -233,7 +233,7 @@
 	{
 	    strcpy(fieldbuf, argv[editfield]);
 	    enter_text(fieldbuf, sizeof fieldbuf - 1);
-	    puts("\r\n");
+	    puts("\n\r");
 	    argv[editfield] = fieldbuf;
 	}
 
@@ -253,7 +253,7 @@
     int blocked_bootdev;
     int bootdev;
     int wide;
-    int kern_part, rd_part;
+    int kern_part, rd_part, i;
     char kern_name[128], rd_name[128];
 
     /* BSS clear */
@@ -264,11 +264,11 @@
 
     putchar('p');	/* if you get this p and no more, string storage */
 			/* in $GLOBAL$ is wrong or %dp is wrong */
-    puts("alo ipl ");
+    puts("alo ipl " PALOVERSION " ");
     puts(bld_info);
-    puts("\r\n");
+    puts("\n\r");
     if (0) printf("iplmain(%d)\n\r", is_interactive);
-    if (0) printf("initial-sp %p\r\n", initialstackptr);
+    if (0) printf("initial-sp %p\n\r", initialstackptr);
     blocked_bootdev = pdc_bootdev_open();
     bootdev = byteio_open(blocked_bootdev);
 
@@ -280,20 +280,20 @@
     }
 
     if (f.kern_sz > 0)
-	printf("0/vmlinux %d bytes @ 0x%x\r\n", f.kern_sz, f.kern_offset);
+	printf("0/vmlinux %d bytes @ 0x%x\n\r", f.kern_sz, f.kern_offset);
 
-    if (f.cmdline[0] != '\0')
-	printf("0/palo-cmdline '%s'\r\n", f.cmdline);
+    if (0 && f.cmdline[0] != '\0')
+	printf("0/palo-cmdline '%s'\n\r", f.cmdline);
 
     if (f.rd_sz > 0)
-	printf("0/ramdisk %d bytes @ 0x%x\r\n", f.rd_sz, f.rd_offset);
+	printf("0/ramdisk %d bytes @ 0x%x\n\r", f.rd_sz, f.rd_offset);
 
     memset(&partition, 0, sizeof partition);
     partitioned = load_partitions(bootdev,
 		partition, sizeof partition / sizeof partition[0]);
 
     if (partitioned)
-	print_ptab(partition, sizeof partition / sizeof partition[0]);
+	print_ptab_pretty(partition, sizeof partition / sizeof partition[0]);
 
     if (f.cmdline[0] == '\0')	/* no command line specified */
     {
@@ -306,28 +306,46 @@
     strcpy(commandline,
 	    parse(f.cmdline, &kern_part, kern_name, &rd_part, rd_name));
 
-    printf("Kernel: partition %d file %s\r\n", kern_part, kern_name);
+    printf("Kernel: partition %d file %s\n\r", kern_part, kern_name);
 
     if (rd_part != -1)
-	printf("Ramdisk: partition %d file %s\r\n", rd_part, rd_name);
+	printf("Ramdisk: partition %d file %s\n\r", rd_part, rd_name);
 
+    /* if the F0 partition is the same as the requested kernel partition,
+     * for now change it to zero to re-use the existing logic.  Should do
+     * the reverse in the future probably.
+     */
+    for (i = 0; i < sizeof partition / sizeof partition[0]; i++)
+    {
+	if (partition[i].id == 0xf0)
+	{
+	    if (kern_part == i + 1)
+		kern_part = 0;
+
+	    if (rd_part == i + 1)
+		rd_part = 0;
+
+	    break;
+	}
+    }
+
     if (kern_part == 0 && f.kern_sz == 0)
     {
-	puts("ERROR: No sequential kernel!\r\n");
+	puts("ERROR: No sequential kernel!\n\r");
 	while(1);
     }
 
     if (kern_part > 0 && !partitioned)
     {
 	printf("ERROR: Requesting kernel from partition %d "
-		    "on unpartitioned media!\r\n", kern_part);
+		    "on unpartitioned media!\n\r", kern_part);
 	while(1);
     }
 
     if (rd_part != -1 && rd_part != kern_part)
     {
 	printf("Warning: palo does not support ramdisk on different"
-		" partition than kernel\r\n");
+		" partition than kernel\n\r");
     }
 
     if (kern_part == 0)
@@ -339,7 +357,7 @@
 	/* no need to seek() -- we're here because of size of prior seekread() */
 	if (!load_kernel(kernfd, &entry, &wide))
 	{
-	    printf("failed to load kernel\r\n");
+	    printf("failed to load kernel\n\r");
 	    while(1);
 	}
 
@@ -348,7 +366,7 @@
 	    rdfd = offset_open(bootdev, f.rd_offset, f.rd_sz);
 	    if (!load_rd(rdfd, f.rd_sz))
 	    {
-		printf("failed to load ramdisk - proceeding anyway\r\n");
+		printf("failed to load ramdisk - proceeding anyway\n\r");
 	    }
 	}
     }
@@ -361,7 +379,7 @@
 
 	if (kern_part >= MAXPARTS || partition[kern_part - 1].id != 0x83)
 	{
-	    printf("Partition %d, doesn't look like ext2 to me!\r\n",
+	    printf("Partition %d, doesn't look like ext2 to me!\n\r",
 		    kern_part);
 	    while(1);
 	}
@@ -370,26 +388,26 @@
     
 	part_fd = offset_open(bootdev, 512 * pp->start, 512 * pp->length);
 
-	printf("ext2_mount(partition %d) returns %d\r\n",
+	printf("ext2_mount(partition %d) returns %d\n\r",
 	    kern_part, ext2_mount(part_fd, 0, 0));
 
 	kern_fd = ext2_open(kern_name);
-	printf("ext2_open(%s) = %d\r\n", kern_name, kern_fd);
+	printf("ext2_open(%s) = %d\n\r", kern_name, kern_fd);
 	if (kern_fd < 0)
 	{
-	    printf("open %s failed\r\n", kern_name);
+	    printf("open %s failed\n\r", kern_name);
 	    while(1);
 	}
 
 	bkern_fd = byteio_open(kern_fd);
 	if (!load_kernel(bkern_fd, &entry, &wide))
 	{
-	    printf("failed to load kernel\r\n");
+	    printf("failed to load kernel\n\r");
 	    while(1);
 	}
     }
 
-    printf("branching to kernel entry point 0x%08x\r\n", entry);
+    printf("branching to kernel entry point 0x%08x\n\r", entry);
     /* FIXME!!! need to pass command line to kernel */
     /* could theoretically use a function pointer, but they're ugly on PA */
     pdc_default_width(wide);
Index: ipl/pdc_bootio.c
===================================================================
RCS file: /home/cvs/parisc/palo/ipl/pdc_bootio.c,v
retrieving revision 1.3
diff -u -r1.3 pdc_bootio.c
--- pdc_bootio.c	2000/09/05 16:04:15	1.3
+++ pdc_bootio.c	2001/05/14 03:53:36
@@ -33,6 +33,9 @@
     } else if (n % 2048) {
 	printf("\nERROR: Boot device seekread size not a multiple of 2048.\n");
 	return -1;
+    } else if (seek & 0x8000000) {
+	/* an unreliable test */
+	return -1;
     }
 
     if (PAGE0->mem_boot.cl_class == CL_RANDOM)
Index: lib/common.h
===================================================================
RCS file: /home/cvs/parisc/palo/lib/common.h,v
retrieving revision 1.6
diff -u -r1.6 common.h
--- common.h	2001/02/14 22:10:20	1.6
+++ common.h	2001/05/14 03:53:36
@@ -11,7 +11,7 @@
 #include <asm/byteorder.h>
 #include <linux/genhd.h>
 
-#define PALOVERSION "0.86"
+#define PALOVERSION "0.89"
 
 /* size of I/O block used in HP firmware */
 #define FW_BLOCKSIZE	2048
Index: lib/diskpart.c
===================================================================
RCS file: /home/cvs/parisc/palo/lib/diskpart.c,v
retrieving revision 1.3
diff -u -r1.3 diskpart.c
--- diskpart.c	2000/07/12 21:20:51	1.3
+++ diskpart.c	2001/05/14 03:53:36
@@ -32,7 +32,9 @@
     unsigned offset;
 	
     /* seekread MBR */
-    seekread(bootdev, (char *)&fb, sizeof fb, 0);
+    if (seekread(bootdev, (char *)&fb, sizeof fb, 0) == -1)
+	return 0;
+
     if (fb.dosmagic[0] != 0x55 || fb.dosmagic[1] != 0xaa)
 	return 0;
 
@@ -50,10 +52,16 @@
 	offset = mptab[ex].start;
 	while (extnum < maxparts)
 	{
-	    seekread(bootdev, (char *)&fb, sizeof fb, 512 * offset);
+	    /* we're currently using 32-bit file seeks which is ok since
+	     * the IPL is also limited to 2G right now.  So on big disks
+	     * this next read may fail, and we need to let that happen
+	     * gracefully.
+	     */
+	    if (seekread(bootdev, (char *)&fb, sizeof fb, 512 * offset) == -1)
+		break;
 	    if (fb.dosmagic[0] != 0x55 || fb.dosmagic[1] != 0xaa)
 	    {
-		printf("Bad DOS magic in extended partition\r\n");
+		printf("Bad DOS magic in extended partition\n\r");
 		break;
 	    }
 
@@ -77,10 +85,31 @@
     for (i = 0; i < maxparts; i++)
     {
 	if (mptab[i].id != 0)
-	    printf("/dev/ida%-2d %02x %10u %10u\r\n",
+	    printf("/dev/ida%-2d %02x %10u %10u\n\r",
 		i + 1, mptab[i].id,
 		mptab[i].start,
 		mptab[i].length);
+    }
+}
+
+void
+print_ptab_pretty(struct diskpartition *mptab, int maxparts)
+{
+    int i;
+    const int mbshift = 20 - 9;
+
+    printf("Partition Start(MB) End(MB) Id Type\n\r");
+    for (i = 0; i < maxparts; i++)
+    {
+	if (mptab[i].id != 0 && ! is_extended(mptab[i].id))
+	    printf("%-9x %7d   %5d   %2x %s\n\r",
+		i + 1,
+		1 + (mptab[i].start >> mbshift),
+		(mptab[i].start + mptab[i].length) >> mbshift,
+		mptab[i].id,
+		mptab[i].id == 0x83 ? "ext2" :
+			(mptab[i].id == 0x82 ? "swap" :
+				(mptab[i].id == 0xf0 ? "Palo" : "Unknown")));
     }
 }
 
Index: palo/palo.c
===================================================================
RCS file: /home/cvs/parisc/palo/palo/palo.c,v
retrieving revision 1.11
diff -u -r1.11 palo.c
--- palo.c	2000/12/13 20:54:39	1.11
+++ palo.c	2001/05/14 03:53:36
@@ -88,8 +88,8 @@
     ipl = calloc(ipl_words, sizeof ipl[0]);
 
     /* would be a good idea to check this call? */
-    seekread(media, (char *)ipl, B32(f.ipl_size),
-	B32(f.ipl_addr));
+    if (seekread(media, (char *)ipl, B32(f.ipl_size), B32(f.ipl_addr)) == -1)
+	error(6, "read failed");
 
     /* calculate xsum */
     xsum = checksum(ipl, B32(f.ipl_size));
@@ -711,8 +711,9 @@
 	    }
 	    if (f0 == MAXPARTS)
 		error(11);
+	    print_ptab_pretty(ptab, MAXPARTS);
 
-	    printf("F0 partition start sector %d length %d\n",
+	    if (0) printf("F0 partition start sector %d length %d\n",
 		    ptab[f0].start, ptab[f0].length);
 
 	    do_randomaccess(init, media, kernel, commandline, bootloader,
Index: palo/paloio.c
===================================================================
RCS file: /home/cvs/parisc/palo/palo/paloio.c,v
retrieving revision 1.2
diff -u -r1.2 paloio.c
--- paloio.c	2000/03/09 00:29:53	1.2
+++ paloio.c	2001/05/14 03:53:36
@@ -17,85 +17,98 @@
 {
     char check[1024];
     int n = size < sizeof check ? size : sizeof check;
+    int r = 0;
     off_t off;
 
     if (0) printf("seekwrite(%d, %p, %u, %u)\n", fd, buf, size, where);
 
+    if (where & 0x80000000)
+    {
+	r = -1;
+    }
+
     fsync(fd);
-    if (lseek(fd, where, SEEK_SET) != where)
+    if (r != -1 && lseek(fd, where, SEEK_SET) != where)
     {
 	perror("lseek");
-	exit(10);
+	r = -1;
     }
 
-    if (write(fd, buf, size) == -1)
+    if (r != -1 && (r = write(fd, buf, size)) == -1)
     {
 	perror("write");
-	exit(10);
+	r = -1;
     }
 
-    if ((off = lseek(fd, 0, SEEK_CUR)) != where + size)
+    if (r != -1 && (off = lseek(fd, 0, SEEK_CUR)) != where + size)
     {
 	fprintf(stderr, "position %ld not %u\n", off, where + size);
-	exit(10);
+	r = -1;
     }
 
     fsync(fd);
 
     /* readback */
-    if (lseek(fd, where, SEEK_SET) != where)
+    if (r != -1 && lseek(fd, where, SEEK_SET) != where)
     {
 	perror("lseek2");
-	exit(10);
+	r = -1;
     }
 
-    if (read(fd, check, n) != n)
+    if (r != -1 && read(fd, check, n) != n)
     {
 	perror("readback(check)");
-	exit(10);
+	r = -1;
     }
 
-    if (memcmp(check, buf, n) != 0)
+    if (r != -1 && memcmp(check, buf, n) != 0)
     {
 	fprintf(stderr, "readback failed!\n");
-	exit(10);
+	r = -1;
     }
 
     /* leave the file positioned where expected */
-    if (lseek(fd, where + size, SEEK_SET) != where + size)
+    if (r != -1 && lseek(fd, where + size, SEEK_SET) != where + size)
     {
 	perror("lseek3");
-	exit(10);
+	r = -1;
     }
 
-    return size;
+    return r;
 }
 
 int
 seekread(int fd, char *buf, unsigned size, unsigned where)
 {
     off_t off;
-    if (0) printf("seekread(%d, %p, %u, %u)\n", fd, buf, size, where);
+    int r = 0;
+    if (0) printf("seekread(%d, %p, %x, %x)\n", fd, buf, size, where);
+
+    if (where & 0x80000000)
+    {
+	r = -1;
+    }
 
-    if (lseek(fd, where, SEEK_SET) != where)
+    if (r != -1 && lseek(fd, where, SEEK_SET) != where)
     {
 	perror("lseek");
-	exit(10);
+	r = -1;
     }
 
-    if (read(fd, buf, size) != size)
+    if (r != -1 && (r = read(fd, buf, size)) != size)
     {
 	perror("read");
-	exit(10);
+	r = -1;
     }
 
-    if ((off = lseek(fd, 0, SEEK_CUR)) != where + size)
+    if (r != -1 && (off = lseek(fd, 0, SEEK_CUR)) != where + size)
     {
 	fprintf(stderr, "lseek said %ld not %u\n", off, where + size);
-	exit(10);
+	r = -1;
     }
+    if (0) printf("returning %x\n", size);
 
-    return size;
+    return r;
 }
 
 int