sbin/fsck/utilities.c
/*
 * Malloc buffers and set up cache.
 */
Malloc buffers and set up cache.
Malloc buffers and set up cache .
void
bufinit()
{
	register struct bufarea *bp;
	long bufcnt, i;
	char *bufp;
	pbp = pdirbp = (struct bufarea *)0;
	bufp = malloc((unsigned int)sblock.fs_bsize);
	if (bufp == 0)
		errx(EEXIT, "cannot allocate buffer pool");
	cgblk.b_un.b_buf = bufp;
	initbarea(&cgblk);
	bufhead.b_next = bufhead.b_prev = &bufhead;
	bufcnt = MAXBUFSPACE / sblock.fs_bsize;
	if (bufcnt < MINBUFS)
		bufcnt = MINBUFS;
	for (i = 0; i < bufcnt; i++) {
		bp = (struct bufarea *)malloc(sizeof(struct bufarea));
		bufp = malloc((unsigned int)sblock.fs_bsize);
		if (bp == NULL || bufp == NULL) {
			if (i >= MINBUFS)
				break;
			errx(EEXIT, "cannot allocate buffer pool");
		}
		bp->b_un.b_buf = bufp;
		bp->b_prev = &bufhead;
		bp->b_next = bufhead.b_next;
		bufhead.b_next->b_prev = bp;
		bufhead.b_next = bp;
		initbarea(bp);
	}
	bufhead.b_size = i;	
}
void bufinit ( ) { register struct bufarea * bp ; long bufcnt , i ; char * bufp ; pbp = pdirbp = ( struct bufarea * ) 0 ; bufp = malloc ( ( unsigned int ) sblock . fs_bsize ) ; if ( bufp == 0 ) errx ( EEXIT , " " ) ; cgblk . b_un . b_buf = bufp ; initbarea ( & cgblk ) ; bufhead . b_next = bufhead . b_prev = & bufhead ; bufcnt = MAXBUFSPACE / sblock . fs_bsize ; if ( bufcnt < MINBUFS ) bufcnt = MINBUFS ; for ( i = 0 ; i < bufcnt ; i ++ ) { bp = ( struct bufarea * ) malloc ( sizeof ( struct bufarea ) ) ; bufp = malloc ( ( unsigned int ) sblock . fs_bsize ) ; if ( bp == NULL || bufp == NULL ) { if ( i >= MINBUFS ) break ; errx ( EEXIT , " " ) ; } bp -> b_un . b_buf = bufp ; bp -> b_prev = & bufhead ; bp -> b_next = bufhead . b_next ; bufhead . b_next -> b_prev = bp ; bufhead . b_next = bp ; initbarea ( bp ) ; } bufhead . b_size = i ; }
Malloc buffers and set up cache.
Malloc buffers and set up cache .
/* save number of buffers */