FreeBSD/sbin/savecore/savecore.c
/*
 * Check that sufficient space is available on the disk that holds the
 * save directory.
 */
Check that sufficient space is available on the disk that holds the
save directory.
Check that sufficient space is available on the disk that holds the save directory .
static int
check_space(const char *savedir, off_t dumpsize, int bounds)
{
	FILE *fp;
	off_t minfree, spacefree, totfree, needed;
	struct statfs fsbuf;
	char buf[100];
	if (statfs(".", &fsbuf) < 0) {
		syslog(LOG_ERR, "%s: %m", savedir);
		exit(1);
	}
	spacefree = ((off_t) fsbuf.f_bavail * fsbuf.f_bsize) / 1024;
	totfree = ((off_t) fsbuf.f_bfree * fsbuf.f_bsize) / 1024;
	if ((fp = fopen("minfree", "r")) == NULL)
		minfree = 0;
	else {
		if (fgets(buf, sizeof(buf), fp) == NULL)
			minfree = 0;
		else
			minfree = atoi(buf);
		(void)fclose(fp);
	}
	needed = dumpsize / 1024 + 2;	
	needed -= saved_dump_size(bounds);
	if ((minfree > 0 ? spacefree : totfree) - needed < minfree) {
		syslog(LOG_WARNING,
	"no dump, not enough free space on device (%lld available, need %lld)",
		    (long long)(minfree > 0 ? spacefree : totfree),
		    (long long)needed);
		return (0);
	}
	if (spacefree - needed < 0)
		syslog(LOG_WARNING,
		    "dump performed, but free space threshold crossed");
	return (1);
}
static int check_space ( const char * savedir , off_t dumpsize , int bounds ) { FILE * fp ; off_t minfree , spacefree , totfree , needed ; struct statfs fsbuf ; char buf [ 100 ] ; if ( statfs ( " " , & fsbuf ) < 0 ) { syslog ( LOG_ERR , " " , savedir ) ; exit ( 1 ) ; } spacefree = ( ( off_t ) fsbuf . f_bavail * fsbuf . f_bsize ) / 1024 ; totfree = ( ( off_t ) fsbuf . f_bfree * fsbuf . f_bsize ) / 1024 ; if ( ( fp = fopen ( " " , " " ) ) == NULL ) minfree = 0 ; else { if ( fgets ( buf , sizeof ( buf ) , fp ) == NULL ) minfree = 0 ; else minfree = atoi ( buf ) ; ( void ) fclose ( fp ) ; } needed = dumpsize / 1024 + 2 ; needed -= saved_dump_size ( bounds ) ; if ( ( minfree > 0 ? spacefree : totfree ) - needed < minfree ) { syslog ( LOG_WARNING , " " , ( long long ) ( minfree > 0 ? spacefree : totfree ) , ( long long ) needed ) ; return ( 0 ) ; } if ( spacefree - needed < 0 ) syslog ( LOG_WARNING , " " ) ; return ( 1 ) ; }
Check that sufficient space is available on the disk that holds the
 save directory.
Check that sufficient space is available on the disk that holds the save directory .
/* 2 for info file */