From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1NLfWM-0006sR-Vg for mharc-grub-devel@gnu.org; Fri, 18 Dec 2009 11:17:39 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NLfWJ-0006qJ-OV for grub-devel@gnu.org; Fri, 18 Dec 2009 11:17:35 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NLfWF-0006nP-0X for grub-devel@gnu.org; Fri, 18 Dec 2009 11:17:35 -0500 Received: from [199.232.76.173] (port=47721 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLfWE-0006nK-SF for grub-devel@gnu.org; Fri, 18 Dec 2009 11:17:30 -0500 Received: from mail-ew0-f224.google.com ([209.85.219.224]:40976) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NLfWE-0002vh-Dz for grub-devel@gnu.org; Fri, 18 Dec 2009 11:17:30 -0500 Received: by ewy24 with SMTP id 24so3594126ewy.26 for ; Fri, 18 Dec 2009 08:17:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:x-enigmail-version:content-type; bh=3NeQRywBJ94VASdRh0xg9LtiD9rtUo4n8MepONs16a4=; b=nGlPOvWCN9Z2kMARfh5LDPL8ZI0PDWUgL+WOMCWLfSlXZHDGMNFGR1zW11xe+4C7VO iXi/nG0HCAYkS3CPL/taCO4aGu7EEqRGVCa61J5x2KMWqXJN6/SoJYVqRx6yMBOnVlie rzfDyCCjYjMMCOilFj2jCA973UhnEgbPJZ3Uk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :x-enigmail-version:content-type; b=rSnoMu0Sw31jGaX+w6MqUbrcn3kLbBe/9roOtkLfpKdGXifVzIVZnvXQBzdn6pQzFX FIIWxmijkMg1PdN07TxGsZNk6bv9XCuzuSnTiPTKQgStCkZkO87eHoNEUIHhNFO2OcrU Go9sOoSFp5Uuls6qPwzNtfZzqH4IzWDi0cIyM= Received: by 10.213.96.3 with SMTP id f3mr5084340ebn.51.1261153049124; Fri, 18 Dec 2009 08:17:29 -0800 (PST) Received: from debian.bg45.phnet (gprs22.swisscom-mobile.ch [193.247.250.22]) by mx.google.com with ESMTPS id 13sm2021101ewy.13.2009.12.18.08.17.21 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 18 Dec 2009 08:17:25 -0800 (PST) Message-ID: <4B2BAB09.1070208@gmail.com> Date: Fri, 18 Dec 2009 17:17:13 +0100 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20091109) MIME-Version: 1.0 To: The development of GRUB 2 , David Miller X-Enigmail-Version: 0.95.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig97B867245E73756760E70175" X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: Subject: [PATCH] Don't open same disk twice on OpenFirmware. X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Dec 2009 16:17:36 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig97B867245E73756760E70175 Content-Type: multipart/mixed; boundary="------------000707010705020809060209" This is a multi-part message in MIME format. --------------000707010705020809060209 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello, all. According to David Miller sparc's openboot doesn't support opening same disk twice. So I implemented handle reusage logic. Tested on imac g3 --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------000707010705020809060209 Content-Type: text/x-diff; name="ofdisk.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="ofdisk.diff" =3D=3D=3D modified file 'disk/ieee1275/ofdisk.c' --- disk/ieee1275/ofdisk.c 2009-12-07 10:54:25 +0000 +++ disk/ieee1275/ofdisk.c 2009-12-18 16:12:28 +0000 @@ -1,7 +1,7 @@ /* ofdisk.c - Open Firmware disk access. */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2004,2006,2007,2008 Free Software Foundation, Inc. + * Copyright (C) 2004,2006,2007,2008,2009 Free Software Foundation, In= c. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by= @@ -26,6 +26,8 @@ struct ofdisk_hash_ent { char *devpath; + int refs; + grub_ieee1275_ihandle_t dev_ihandle; struct ofdisk_hash_ent *next; }; =20 @@ -65,6 +67,8 @@ ofdisk_hash_add (char *devpath) { p->devpath =3D devpath; p->next =3D *head; + p->refs =3D 0; + p->dev_ihandle =3D 0; *head =3D p; } return p; @@ -170,6 +174,23 @@ grub_ofdisk_open (const char *name, grub if (!op) return grub_errno; =20 + if (op->dev_ihandle) + { + op->refs++; + + /* XXX: There is no property to read the number of blocks. There + should be a property `#blocks', but it is not there. Perhaps it + is possible to use seek for this. */ + disk->total_sectors =3D 0xFFFFFFFFUL; + + disk->id =3D (unsigned long) op; + + /* XXX: Read this, somehow. */ + disk->has_partitions =3D 1; + disk->data =3D op; + return 0; + } + grub_dprintf ("disk", "Opening `%s'.\n", op->devpath); =20 grub_ieee1275_open (op->devpath, &dev_ihandle); @@ -179,8 +200,8 @@ grub_ofdisk_open (const char *name, grub goto fail; } =20 - grub_dprintf ("disk", "Opened `%s' as handle %p.\n", op->devpath, - (void *) (unsigned long) dev_ihandle); + grub_dprintf ("disk", "Opened `%s' as handle 0x%lx.\n", op->devpath, + (unsigned long) dev_ihandle); =20 if (grub_ieee1275_finddevice (op->devpath, &dev)) { @@ -201,6 +222,9 @@ grub_ofdisk_open (const char *name, grub goto fail; } =20 + op->dev_ihandle =3D dev_ihandle; + op->refs++; + /* XXX: There is no property to read the number of blocks. There should be a property `#blocks', but it is not there. Perhaps it is possible to use seek for this. */ @@ -210,7 +234,7 @@ grub_ofdisk_open (const char *name, grub =20 /* XXX: Read this, somehow. */ disk->has_partitions =3D 1; - disk->data =3D (void *) (unsigned long) dev_ihandle; + disk->data =3D op; return 0; =20 fail: @@ -222,9 +246,15 @@ grub_ofdisk_open (const char *name, grub static void grub_ofdisk_close (grub_disk_t disk) { - grub_dprintf ("disk", "Closing handle %p.\n", - (void *) disk->data); - grub_ieee1275_close ((grub_ieee1275_ihandle_t) (unsigned long) disk->d= ata); + struct ofdisk_hash_ent *data =3D disk->data; + + data->refs--; + if (data->refs) + return; + + grub_dprintf ("disk", "Closing handle %p.\n", data); + grub_ieee1275_close (data->dev_ihandle); + data->dev_ihandle =3D 0; } =20 static grub_err_t @@ -233,21 +263,21 @@ grub_ofdisk_read (grub_disk_t disk, grub { grub_ssize_t status, actual; unsigned long long pos; + struct ofdisk_hash_ent *data =3D disk->data; =20 grub_dprintf ("disk", "Reading handle %p: sector 0x%llx, size 0x%lx, buf %p.\n", - (void *) disk->data, (long long) sector, (long) size, buf); + data, (long long) sector, (long) size, buf); =20 pos =3D sector * 512UL; =20 - grub_ieee1275_seek ((grub_ieee1275_ihandle_t) (unsigned long) disk->da= ta, + grub_ieee1275_seek (data->dev_ihandle, (int) (pos >> 32), (int) pos & 0xFFFFFFFFUL, &status); if (status < 0) return grub_error (GRUB_ERR_READ_ERROR, "Seek error, can't seek block %llu", (long long) sector); - grub_ieee1275_read ((grub_ieee1275_ihandle_t) (unsigned long) disk->da= ta, - buf, size * 512UL, &actual); + grub_ieee1275_read (data->dev_ihandle, buf, size * 512UL, &actual); if (actual !=3D actual) return grub_error (GRUB_ERR_READ_ERROR, "Read error on block: %llu",= (long long) sector); --------------000707010705020809060209-- --------------enig97B867245E73756760E70175 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iF4EAREKAAYFAksrqw8ACgkQNak7dOguQgkVSAEAkTqB6zif2NDRPRU+ssmqVYUJ +Hbb7yYaQ4VtGbmlrKIA/3r47DyeIi4UdEodlAbBb78WjHh8Vdyy9DgX57U40ruK =Hqut -----END PGP SIGNATURE----- --------------enig97B867245E73756760E70175--