tags 255457 + patch thanks Hi,
I couldn't sleep, so I found a bug tagged 'help' to do a patch for. [EMAIL PROTECTED]:~/debian/nbd$ du -h reallargefile ; zum reallargefile ; du -h reallargefile 4.1G reallargefile reallargefile [33587168K] [1 link] 12K reallargefile [EMAIL PROTECTED]:~/debian/nbd$ Whee. Real large file support. While I was at it, I cleaned up the source a bit so that it doesn't produce any warnings anymore. I should note that the use of gets() in the source is worrisome; it might be a good idea to contact people from the security (audit) team to verify whether there's a threat here, because every use of gets() is a potential buffer overflow (I don't think there is, but then I'm not that experienced with security issues). Anyway, here's the patch: 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 04:07:46.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,25 @@ 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; lseek(fdd, 0L, SEEK_SET); if(ftruncate(fdd, 0) < 0) { @@ -36,23 +57,31 @@ return -1; } - if((ms = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fds, 0)) == -1) { + if((ms = my_mmap(NULL, fds, size, &pos)) == MAP_FAILED) { perror("mmap"); return -1; } - p = ms; ep = ms + size; + p = ms; ep = ms + (size - pos > 1<<30 ? 1<<30 : size - pos); 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, (size - pos > 1<<30 ? 1<<30 : size - pos)); return -1; } for(bp = p; p < ep && !*p; p++); if(p != bp) lseek(fdd, p-bp, SEEK_CUR); + if((size > 1<<30) && (ep != (ms + size - pos))) { + if((ms = my_mmap(ms, fds, size, &pos)) == MAP_FAILED) { + perror("mmap"); + return -1; + } else { + p = ms; ep = ms + (size - pos > 1<<30 ? 1<<30 : size - pos); + } + } } munmap(ms, size); return ftruncate(fdd, size); @@ -102,7 +131,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 +170,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]