Index: savecore.c =================================================================== RCS file: /home/ncvs/src/sbin/savecore/savecore.c,v retrieving revision 1.36 diff -u -r1.36 savecore.c --- savecore.c 2000/10/17 22:43:41 1.36 +++ savecore.c 2001/02/13 12:33:27 @@ -346,8 +346,8 @@ void save_core() { - register FILE *fp; - register int bounds, ifd, nr, nw; + FILE *fp; + int bounds, ifd, nr, nw, he, hs; char path[MAXPATHLEN]; mode_t oumask; @@ -405,7 +405,39 @@ syslog(LOG_ERR, "%s: %m", ddname); goto err2; } - nw = fwrite(buf, 1, nr, fp); + for (nw = 0; nw < nr; nw = he) { + /* find a contiguous block of zeroes */ + for (hs = nw; hs < nr; hs += PAGE_SIZE) { + for (he = hs; he < nr && buf[he] == 0; ++he) + /* nothing */ ; + + /* round down to a block boundary */ + he &= ~PAGE_MASK; + + /* if we're still > hs, we've found a hole */ + if (he > hs) + break; + } + + /* + * 1) Don't go beyond the end of the buffer. + * 2) If the end of the buffer is less than + * BLOCKSIZE bytes away, we're at the end + * of the file, so just grab what's left. + */ + if (hs + PAGE_SIZE > nr) + hs = he = nr; + + /* nw <= hs <= nr */ + if (hs > nw) + if (fwrite(buf + nw, hs - nw, 1, fp) != 1) + break; + + /* hs <= he <= nr */ + if (he > hs) + if (fseek(fp, he - hs, SEEK_CUR) == -1) + break; + } if (nw != nr) { syslog(LOG_ERR, "%s: %m", path); err2: syslog(LOG_WARNING, @@ -457,7 +489,7 @@ int verify_dev(name, dev) char *name; - register dev_t dev; + dev_t dev; { struct stat sb; @@ -477,7 +509,7 @@ */ void find_dev(dev) - register dev_t dev; + dev_t dev; { struct dirent *ent; char *dn, *dnp; @@ -551,7 +583,7 @@ int check_space() { - register FILE *fp; + FILE *fp; const char *tkernel; off_t minfree, spacefree, totfree, kernelsize, needed; struct stat st;