Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Apr 2001 14:09:00 +0100 (BST)
From:      Doug Rabson <dfr@nlsystems.com>
To:        Michael Richards <michael@fastmail.ca>
Cc:        <jhb@FreeBSD.org>, Matthew Jacob <mjacob@feral.com>, <freebsd-alpha@FreeBSD.org>, <msmith@FreeBSD.org>
Subject:   Re: Proposed Loader fix
Message-ID:  <Pine.BSF.4.33.0104031407110.10147-200000@herring.nlsystems.com>
In-Reply-To: <3AC8CA0E.00003D.26518@frodo.searchcanada.ca>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
On Mon, 2 Apr 2001, Michael Richards wrote:

> Yes, after posting that proposed fix, I realised that it wouldn't
> work properly that way. I was unable to apply the posted patches to
> srmdisk.c I get:

Hmm. Must have been garbled somewhere. I've attached another patch here in
the hope that attachments get less mailer mangling than plain text. This
version of the patch does reference counting so that we can actually call
prom_close(). Its still untested though :-).

-- 
Doug Rabson				Mail:  dfr@nlsystems.com
					Phone: +44 20 8348 6160


[-- Attachment #2 --]
Index: srmdisk.c
===================================================================
RCS file: /home/ncvs/src/sys/boot/alpha/libalpha/srmdisk.c,v
retrieving revision 1.9
diff -u -r1.9 srmdisk.c
--- srmdisk.c	2000/03/15 01:53:34	1.9
+++ srmdisk.c	2001/04/03 13:05:24
@@ -96,6 +96,8 @@
     int		bd_unit;		/* SRM unit number */
     int		bd_namelen;
     int		bd_flags;
+    int		bd_fd;
+    int		bd_opencount;
 } bdinfo [MAXBDDEV];
 static int nbdinfo = 0;
 
@@ -113,6 +115,8 @@
     ret.bits = prom_getenv(PROM_E_BOOTED_DEV,
 			   bdinfo[0].bd_name, sizeof(bdinfo[0].bd_name));
     bdinfo[0].bd_namelen = ret.u.retval;
+    bdinfo[0].bd_fd = -1;
+    bdinfo[0].bd_opencount = 0;
     nbdinfo++;
 
     return (0);
@@ -155,7 +159,7 @@
     struct disklabel		*lp;
     int				sector, slice, i;
     int				error;
-    int				unit;
+    int				unit, fd;
     prom_return_t		ret;
 
     va_start(args, f);
@@ -169,11 +173,17 @@
     }
     
     /* Call the prom to open the disk. */
-    ret.bits = prom_open(bdinfo[unit].bd_name, bdinfo[unit].bd_namelen);
-    if (ret.u.status == 2)
-	return (ENXIO);
-    if (ret.u.status == 3)
-	return (EIO);
+    if (bdinfo[unit].bd_fd < 0) {
+	ret.bits = prom_open(bdinfo[unit].bd_name, bdinfo[unit].bd_namelen);
+	if (ret.u.status == 2)
+	    return (ENXIO);
+	if (ret.u.status == 3)
+	    return (EIO);
+	bdinfo[unit].bd_fd = fd = ret.u.retval;
+    } else {
+	fd = bdinfo[unit].bd_fd;
+    }
+    bdinfo[unit].bd_opencount++;
 
     od = (struct open_disk *) malloc(sizeof(struct open_disk));
     if (!od) {
@@ -182,7 +192,7 @@
     }
 
     /* Look up SRM unit number, intialise open_disk structure */
-    od->od_fd = ret.u.retval;
+    od->od_fd = fd;
     od->od_unit = dev->d_kind.srmdisk.unit;
     od->od_flags = bdinfo[od->od_unit].bd_flags;
     od->od_boff = 0;
@@ -321,7 +331,11 @@
 {
     struct open_disk	*od = f->f_devdata;
 
-    (void)prom_close(od->od_fd);
+    bdinfo[od->od_unit].bd_opencount--;
+    if (bdinfo[od->od_unit].bd_opencount == 0) {
+	(void)prom_close(od->od_fd);
+	bdinfo[od->od_unit].bd_fd = -1;
+    }
 
     free(od);
     f->f_devdata = NULL;

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.33.0104031407110.10147-200000>