On Tue, 12 Sep 2006 17:31:38 -0401
Ray Lai <[EMAIL PROTECTED]> wrote:

> Try to minimize the changes in your diff.  Remember, these diffs may be
> sent upstream.  No way they will accept a diff that removes __sun__ and
> _WIN32 defines!
> 
> There is no need to change the !fstat() and if (ioctl()) to
> 0 == fstat() and 1 != ioctl().  While this may be your preference,
> sneaking in stylistic changes makes it more difficult to judge a diff's
> correctness.
> 
> Are you trying to check that the file is a block device with
> S_IFBLK == (S_IFBLK & sb.st_mode)?  If so, (S_IFBLK & sb.st_mode) is
> clearer.

Well, S_IFBLK is _two_ bits (check /usr/include/sys/stat.h).

> Why do you only check for block devices in the new code?  The original
> code checks for character devices.  Do we now ignore character devices?
> 
> Should you be checking the ioctl return value against -1?  I'm not
> sure, I don't use ioctl.

Yes, that's an error!  A revised patch-block_c is attached
for readers' convenience.  Now it tries DIOCGDINFO on both
character and block devices, falling back to lseek.

> This diff should be sent to the port maintainer after tree unlocks.

That would be [EMAIL PROTECTED]  I guess he, or anyone with commit priv, could
just pick it up from ports@ if they like it.  Wrong?

> 
> -Ray-

You've improved the diff a great deal.  Thank you.

Paul


--- block.c.orig        Wed May  3 20:32:58 2006
+++ block.c     Tue Sep 12 22:52:56 2006
@@ -30,6 +30,7 @@
 #include <sys/ioctl.h>
 #include <sys/queue.h>
 #include <sys/disk.h>
+#include <sys/disklabel.h>
 #endif
 
 #ifdef CONFIG_COCOA
@@ -671,6 +672,7 @@
     int64_t size;
 #ifdef _BSD
     struct stat sb;
+    struct disklabel lab;
 #endif
 #ifdef __sun__
     struct dk_minfo minfo;
@@ -688,6 +690,10 @@
     if (!fstat(fd, &sb) && (S_IFCHR & sb.st_mode)) {
 #ifdef DIOCGMEDIASIZE
        if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size))
+#elif defined(DIOCGDINFO)
+       if (ioctl(fd, DIOCGDINFO, &lab) != -1)
+           size = (int64_t)lab.d_secsize * (int64_t)lab.d_secperunit;
+       else
 #endif
 #ifdef CONFIG_COCOA
         size = LONG_LONG_MAX;

Reply via email to