[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: FreeBSD 5.x fixes
From: |
Sergey Matveychuk |
Subject: |
Re: FreeBSD 5.x fixes |
Date: |
Sun, 25 Jan 2004 00:16:48 +0300 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113 |
Yoshinori K. Okuji wrote:
I think there are some bugs in your patch.
[skipped]
Here, you use hdg.d_secperunit, but this is uninitialized. If my
understanding is correct, you need this kind of code to get it:
You are right. I've missed couple lines when borrow the code from
bsdlabel programm.
[skipped]
Here, you change the device names regardless of the version of FreeBSD,
but I guess you need additional "#if __FreeBSD__ ...".
Agree. Here is a next try.
---
Sem.
--- grub/asmstub.c.orig Sat Jan 24 01:52:56 2004
+++ grub/asmstub.c Sat Jan 24 19:11:23 2004
@@ -779,7 +779,7 @@
if (disks[drive].flags == -1)
{
- if (read_only || errno == EACCES || errno == EROFS)
+ if (read_only || errno == EACCES || errno == EROFS || errno == EPERM)
{
disks[drive].flags = open (devname, O_RDONLY);
if (disks[drive].flags == -1)
--- lib/device.c.orig Sat Jan 24 01:52:56 2004
+++ lib/device.c Sun Jan 25 00:07:02 2004
@@ -78,6 +78,12 @@
# include <sys/ioctl.h> /* ioctl */
# include <sys/disklabel.h>
# include <sys/cdio.h> /* CDIOCCLRDEBUG */
+#if defined(__FreeBSD__)
+#include <sys/param.h>
+#if __FreeBSD_version >= 500040
+#include <sys/disk.h>
+#endif
+#endif
#endif /* __FreeBSD__ || __NetBSD__ || __OpenBSD__ */
#ifdef HAVE_OPENDISK
@@ -123,6 +129,7 @@
/* FreeBSD, NetBSD or OpenBSD */
{
struct disklabel hdg;
+#if __FreeBSD_version < 500040
if (ioctl (fd, DIOCGDINFO, &hdg))
goto fail;
@@ -131,6 +138,38 @@
geom->sectors = hdg.d_nsectors;
geom->total_sectors = hdg.d_secperunit;
+#else
+ u_int u, secsize;
+ off_t mediasize;
+
+ if(ioctl(f, DIOCGSECTORSIZE, &secsize) != 0)
+ secsize = 512;
+
+ if (ioctl(f, DIOCGMEDIASIZE, &mediasize) != 0)
+ goto fail;
+
+ hdg.d_secperunit = mediasize / secsize;
+
+ if (ioctl(fd, DIOCGFWSECTORS, &u) == 0)
+ hdg.d_nsectors = u;
+ else
+ hdg.d_nsectors = 63;
+ if (ioctl(fd, DIOCGFWHEADS, &u) == 0)
+ hdg.d_ntracks = u;
+ else if (hdg.d_secperunit <= 63*1*1024)
+ hdg.d_ntracks = 1;
+ else if (hdg.d_secperunit <= 63*16*1024)
+ hdg.d_ntracks = 16;
+ else
+ hdg.d_ntracks = 255;
+ hdg.d_secpercyl = hdg.d_ntracks * hdg.d_nsectors;
+ hdg.d_ncylinders = hdg.d_secperunit / hdg.d_secpercyl;
+
+ geom->cylinders = hdg.d_ncylinders;
+ geom->heads = hdg.d_ntracks;
+ geom->sectors = hdg.d_nsectors;
+ geom->total_sectors = hdg.d_secperunit;
+#endif
close (fd);
return;
}
@@ -233,7 +272,7 @@
#elif defined(__FreeBSD__)
/* FreeBSD */
# if __FreeBSD__ >= 4
- sprintf (name, "/dev/rad%d", unit);
+ sprintf (name, "/dev/ad%d", unit);
# else /* __FreeBSD__ <= 3 */
sprintf (name, "/dev/rwd%d", unit);
# endif /* __FreeBSD__ <= 3 */
@@ -274,7 +313,11 @@
sprintf (name, "/dev/sd%d", unit);
#elif defined(__FreeBSD__)
/* FreeBSD */
+# if __FreeBSD__ >= 4
+ sprintf (name, "/dev/da%d", unit);
+# else /* __FreeBSD__ <= 3 */
sprintf (name, "/dev/rda%d", unit);
+# endif /* __FreeBSD__ <= 3 */
#elif defined(__NetBSD__) && defined(HAVE_OPENDISK)
/* NetBSD */
char shortname[16];