Public bug reported:

Binary package hint: bsdmainutils

referring to hexdump from package bsdmainutils-6.1.10ubuntu3

option skip does lseek() for regular files only, 1-byte read()-calls are 
executed for anything else.
if one wants to look at a disk device at gigabyte offsets, this takes ages.
Here is my patch, I have also added typedefs quad_t for compilation under 
cygwin.

-----------------------------------------------------------------------------------
--- bsdmainutils-6.1.10ubuntu3.orig/usr.bin/hexdump/display.c   2006-08-15 
08:03:30.000000000 +0200
+++ bsdmainutils-6.1.10ubuntu3/usr.bin/hexdump/display.c        2009-07-29 
20:51:51.593750000 +0200
@@ -341,28 +341,43 @@
 doskip(const char *fname, int statok)
 {
        int cnt;
        struct stat sb;
        char ch;
+       off_t rc;

        if (statok) {
                if (fstat(0, &sb))
                        err(1, "%s", fname);
+
                if (S_ISREG(sb.st_mode) && skip >= sb.st_size) {
                        address += sb.st_size;
                        skip -= sb.st_size;
                        return;
                }
        }
-       if (S_ISREG(sb.st_mode)) {
-               if ((lseek(0, skip, SEEK_SET)) == -1)
-                       err(1, "%s", fname);
-               address += skip;
+
+
+       /* try lseek() first */
+       rc = lseek(0, skip, SEEK_SET);
+       if (rc >= 0)
+       {
+          /* should work for files and hard disk devices */
+               address += rc;
                skip = 0;
-       } else {
+       }
+       else
+       {
+           /* calling read() for single bytes results in poor performance */
+               /* probably a pipe or socket file descriptor                   
*/
                for (cnt = 0; cnt < skip; ++cnt)
-                       if (read(0, &ch, 1) != 1)
+               {
+                       rc = read(0, &ch, 1);
+                       if (rc != 1)
                                break;
+               }
                address += cnt;
                skip -= cnt;
        }
+       if (rc == -1)
+               err(1, "%s", fname);
 }
--- bsdmainutils-6.1.10ubuntu3.orig/usr.bin/hexdump/hexdump.h   2006-08-15 
08:03:30.000000000 +0200
+++ bsdmainutils-6.1.10ubuntu3/usr.bin/hexdump/hexdump.h        2009-07-26 
21:26:44.169811000 +0200
@@ -99,5 +99,10 @@
 void    nomem(void);
 void    oldsyntax(int, char ***);
 void    rewrite(FS *);
 int     size(FS *);
 void    usage(void);
+
+#if defined(__CYGWIN__)
+typedef long long quad_t;
+typedef unsigned long long u_quad_t;
+#endif

** Affects: bsdmainutils (Ubuntu)
     Importance: Undecided
         Status: New

-- 
hexdump -s (8GB) /dev/sda - unacceptable performance
https://bugs.launchpad.net/bugs/406583
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to