On Sat, Nov 26, 2005 at 08:24:32PM +0100, Amaya wrote:
> Sorry, Wouter
> 
> I cannot find a use for the patch you sent me.
> It patches files under debian/perforate/DEBIAN/ and I can't make any
> sense of it.

Thing is, I made the mistake of diffing a clean build directory against
one in which I had just built the package (to test). My mistake :-)

The only relevant changes are the ones to zum.c (though the debian/rules
changes that I made might also be of interest):

diff -ruN perforate-1.1/zum.c perforate-1.1.mine/zum.c
--- perforate-1.1/zum.c 1996-09-11 00:15:34.000000000 +0200
+++ perforate-1.1.mine/zum.c    2005-11-11 11:02:27.000000000 +0100
@@ -2,6 +2,8 @@
  * zum 1.00 - free more disk space by making holes in files.
  *
  * Oleg Kibirev * April 1995 * [EMAIL PROTECTED]
+ * 2005-11-11: Wouter Verhelst <[EMAIL PROTECTED]>: clean up the code a bit (so
+ *     that it no longer produces any warnings, add large file support.
  *
  * This code is covered by General Public License, version 2 or any later
  * version of your choice. You should recieve file "COPYING" which contains
@@ -9,7 +11,11 @@
  * have it, a copy is available from ftp.gnu.ai.mit.edu.
  */
 
+#define _FILE_OFFSET_BITS 64
+#define _LARGEFILE_SOURCE
+
 #include <stdio.h>
+#include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/file.h>
@@ -25,10 +31,26 @@
 
 static char suffix[] = "__zum__";
 
-static int zero_copy(int fds, int fdd, int size)
+static void* my_mmap(void *ptr, int fd, off_t size, off_t *pos)
+{
+  if(size-(*pos) > (off_t)1<<30) {
+    size=1<<30;
+  } else {
+    size=size-(*pos);
+  }
+  if(ptr)
+    munmap(ptr, 1<<30);
+  ptr=mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, (*pos));
+  (*pos)+=size;
+  return ptr;
+}
+
+static int zero_copy(int fds, int fdd, off_t size)
 {
   char *ms;
   char *bp, *p, *ep;
+  off_t pos=0;
+  int offset;
   
   lseek(fdd, 0L, SEEK_SET);
   if(ftruncate(fdd, 0) < 0) {
@@ -36,23 +58,33 @@
     return -1;
   }
   
-  if((ms = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fds, 0)) == -1) {
+  offset = (size > 1<<30) ? 1<<30 : size;
+  if((ms = my_mmap(NULL, fds, size, &pos)) == MAP_FAILED) {
     perror("mmap");
     return -1;
   }
 
-  p = ms; ep = ms + size;
+  p = ms; ep = ms + offset;
   
   while(p < ep) {
     for(bp = p; p < ep && *p; p++);
     if(p != bp && write(fdd, bp, p-bp) != p-bp) {
        perror("write");
-       munmap(ms, size);
+       munmap(ms, offset);
        return -1;
       }
     for(bp = p; p < ep && !*p; p++);
     if(p != bp)
       lseek(fdd, p-bp, SEEK_CUR);
+    if((p == ep) && (size > 1<<30) && (size != pos)) {
+      offset = ((size - pos) > 1<<30) ? 1<<30 : (size - pos);
+      if((ms = my_mmap(ms, fds, size, &pos)) == MAP_FAILED) {
+       perror("mmap");
+       return -1;
+      } else {
+       p = ms; ep = ms + offset;
+      }
+    }
   }
   munmap(ms, size);
   return ftruncate(fdd, size);
@@ -102,7 +134,7 @@
     return;
   }
 
-  printf(" [%uK] ", (st.st_blocks-std.st_blocks)*st.st_blksize/1024);
+  printf(" [%uK] ", (unsigned 
int)((st.st_blocks-std.st_blocks)*st.st_blksize/1024));
   fflush(stdout);
 
   if(st.st_nlink == 1) {
@@ -141,16 +173,16 @@
   }
 }
 
-main(int argc, char **argv)
+int main(int argc, char **argv)
 {
   char *p;
 
   if(argc > 1)
-    while(p = *(++argv))
+    while((p = *(++argv)))
       zero_unmap(p);
   else {
     char buf[MAXPATHLEN];
-    while(gets(buf))
+    while(fgets(buf, MAXPATHLEN, stdin))
       zero_unmap(buf);
   }
   return 0;

-- 
.../ -/ ---/ .--./ / .--/ .-/ .../ -/ ../ -./ --./ / -.--/ ---/ ..-/ .-./ / -/
../ --/ ./ / .--/ ../ -/ ..../ / -../ ./ -.-./ ---/ -../ ../ -./ --./ / --/
-.--/ / .../ ../ --./ -./ .-/ -/ ..-/ .-./ ./ .-.-.-/ / --/ ---/ .-./ .../ ./ /
../ .../ / ---/ ..-/ -/ -../ .-/ -/ ./ -../ / -/ ./ -.-./ ..../ -./ ---/ .-../
---/ --./ -.--/ / .-/ -./ -.--/ .--/ .-/ -.--/ .-.-.-/ / ...-.-/


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to