FreeBSD/sbin/savecore/savecore.c
/*
 * Specialized version of dump-reading logic for use with textdumps, which
 * are written backwards from the end of the partition, and must be reversed
 * before being written to the file.  Textdumps are small, so do a bit less
 * work to optimize/sparsify.
 */
Specialized version of dump-reading logic for use with textdumps, which
are written backwards from the end of the partition, and must be reversed
before being written to the file.  Textdumps are small, so do a bit less
work to optimize/sparsify.
Specialized version of dump - reading logic for use with textdumps which are written backwards from the end of the partition and must be reversed before being written to the file . Textdumps are small so do a bit less work to optimize / sparsify .
static int
DoTextdumpFile(int fd, off_t dumpsize, off_t lasthd, char *buf,
    const char *device, const char *filename, FILE *fp)
{
	int nr, nw, wl;
	off_t dmpcnt, totsize;
	totsize = dumpsize;
	dmpcnt = 0;
	wl = 512;
	if ((dumpsize % wl) != 0) {
		syslog(LOG_ERR, "textdump uneven multiple of 512 on %s",
		    device);
		nerr++;
		return (-1);
	}
	while (dumpsize > 0) {
		nr = pread(fd, buf, wl, lasthd - (totsize - dumpsize) - wl);
		if (nr != wl) {
			if (nr == 0)
				syslog(LOG_WARNING,
				    "WARNING: EOF on dump device");
			else
				syslog(LOG_ERR, "read error on %s: %m", device);
			nerr++;
			return (-1);
		}
		nw = fwrite(buf, 1, wl, fp);
		if (nw != wl) {
			syslog(LOG_ERR,
			    "write error on %s file: %m", filename);
			syslog(LOG_WARNING,
			    "WARNING: textdump may be incomplete");
			nerr++;
			return (-1);
		}
		if (verbose) {
			dmpcnt += wl;
			printf("%llu\r", (unsigned long long)dmpcnt);
			fflush(stdout);
		}
		dumpsize -= wl;
	}
	return (0);
}
static int DoTextdumpFile ( int fd , off_t dumpsize , off_t lasthd , char * buf , const char * device , const char * filename , FILE * fp ) { int nr , nw , wl ; off_t dmpcnt , totsize ; totsize = dumpsize ; dmpcnt = 0 ; wl = 512 ; if ( ( dumpsize % wl ) != 0 ) { syslog ( LOG_ERR , " " , device ) ; nerr ++ ; return ( -1 ) ; } while ( dumpsize > 0 ) { nr = pread ( fd , buf , wl , lasthd - ( totsize - dumpsize ) - wl ) ; if ( nr != wl ) { if ( nr == 0 ) syslog ( LOG_WARNING , " " ) ; else syslog ( LOG_ERR , " " , device ) ; nerr ++ ; return ( -1 ) ; } nw = fwrite ( buf , 1 , wl , fp ) ; if ( nw != wl ) { syslog ( LOG_ERR , " " , filename ) ; syslog ( LOG_WARNING , " " ) ; nerr ++ ; return ( -1 ) ; } if ( verbose ) { dmpcnt += wl ; printf ( " \r " , ( unsigned long long ) dmpcnt ) ; fflush ( stdout ) ; } dumpsize -= wl ; } return ( 0 ) ; }
Specialized version of dump-reading logic for use with textdumps, which
 are written backwards from the end of the partition, and must be reversed
 before being written to the file.
Specialized version of dump - reading logic for use with textdumps which are written backwards from the end of the partition and must be reversed before being written to the file .