Re: gpart FTBFS
Hi Harish,
2012/2/9 Jérémie Koenig <jk@jk.fr.eu.org>:
> I'll try to have a look at your work this week-end, if nobody get to it by then.
The issue seems to be with the disk geometry detection code in
src/disku.c, which returns an uninitialized structure on Hurd. I
attach a correction (use the size returned by stat(), as for disk
image files)
There also seems to be a problem with the way the geometry of disk
image files is detected, though. As far as I can tell, the code
computes the LBA address of the last sector, not actually the disk
geometry.
--
Jérémie Koenig <jk@jk.fr.eu.org>
http://jk.fr.eu.org/
Index: gpart-0.1h/src/disku.c
===================================================================
--- gpart-0.1h.orig/src/disku.c 2012-02-12 13:42:17.000000000 +0000
+++ gpart-0.1h/src/disku.c 2012-02-13 00:57:20.000000000 +0000
@@ -25,14 +25,15 @@
#include <errno.h>
#include <sys/mount.h>
#include <linux/hdreg.h>
-#endif
-
-#if defined(__FreeBSD__)
+#elif defined(__FreeBSD__)
#include <errno.h>
#include <sys/disklabel.h>
+#elif defined(__GNU__)
+#include <errno.h>
#endif
#include <unistd.h>
+#include <errno.h>
/*
* get disk geometry. The medium is opened for reading,
@@ -46,8 +47,7 @@
#if defined(__linux__)
struct hd_geometry hg;
-#endif
-#if defined(__FreeBSD__)
+#elif defined(__FreeBSD__)
struct disklabel dl;
#endif
@@ -57,7 +57,10 @@
ret = stat(d->d_dev, &st);
if (ret == 0)
{
+/* On Hurd, stat() returns the correct size even for block devices */
+#ifndef __GNU__
if (S_ISREG(st.st_mode))
+#endif
{
nsects = st.st_size / 512;
if (nsects == 0)
@@ -88,14 +91,23 @@
g.d_h = hg.heads;
g.d_s = hg.sectors;
-#endif
+#elif defined(__FreeBSD__)
-#if defined(__FreeBSD__)
if (ioctl(d->d_fd,DIOCGDINFO,&dl) == -1)
pr(FATAL,EM_IOCTLFAILED,"DIOCGDINFO",strerror(errno));
g.d_c = dl.d_ncylinders;
g.d_h = dl.d_ntracks;
g.d_s = dl.d_nsectors;
+
+#elif defined(__GNU__)
+
+ pr(FATAL,"%s: stat: %s",d->d_dev,strerror(errno));
+
+#else
+# warning "Unknown OS, please implement geometry probing"
+
+ pr(FATAL,"Cannot probe disk geometry on this system, please use -C or -g");
+
#endif
return (&g);
Reply to: