xref: /netbsd-src/sbin/newfs_lfs/misc.c (revision df06563bc365c878634a893c496b4af0a5e07ff4)
1*df06563bShubertf /*	$NetBSD: misc.c,v 1.7 2007/01/17 21:59:49 hubertf Exp $	*/
20a849c91Sperseant 
30a849c91Sperseant /*-
40a849c91Sperseant  * Copyright (c) 1991, 1993
50a849c91Sperseant  *	The Regents of the University of California.  All rights reserved.
60a849c91Sperseant  *
70a849c91Sperseant  * Redistribution and use in source and binary forms, with or without
80a849c91Sperseant  * modification, are permitted provided that the following conditions
90a849c91Sperseant  * are met:
100a849c91Sperseant  * 1. Redistributions of source code must retain the above copyright
110a849c91Sperseant  *    notice, this list of conditions and the following disclaimer.
120a849c91Sperseant  * 2. Redistributions in binary form must reproduce the above copyright
130a849c91Sperseant  *    notice, this list of conditions and the following disclaimer in the
140a849c91Sperseant  *    documentation and/or other materials provided with the distribution.
15276d62f6Sagc  * 3. Neither the name of the University nor the names of its contributors
160a849c91Sperseant  *    may be used to endorse or promote products derived from this software
170a849c91Sperseant  *    without specific prior written permission.
180a849c91Sperseant  *
190a849c91Sperseant  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
200a849c91Sperseant  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
210a849c91Sperseant  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
220a849c91Sperseant  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
230a849c91Sperseant  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
240a849c91Sperseant  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
250a849c91Sperseant  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
260a849c91Sperseant  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
270a849c91Sperseant  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
280a849c91Sperseant  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
290a849c91Sperseant  * SUCH DAMAGE.
300a849c91Sperseant  */
310a849c91Sperseant 
320a849c91Sperseant #include <sys/cdefs.h>
330a849c91Sperseant #ifndef lint
340a849c91Sperseant #if 0
350a849c91Sperseant static char sccsid[] = "@(#)misc.c	8.1 (Berkeley) 6/5/93";
360a849c91Sperseant #else
37*df06563bShubertf __RCSID("$NetBSD: misc.c,v 1.7 2007/01/17 21:59:49 hubertf Exp $");
380a849c91Sperseant #endif
390a849c91Sperseant #endif /* not lint */
400a849c91Sperseant 
410a849c91Sperseant #include <sys/types.h>
423d1e464bSriz #include <sys/disk.h>
43c632c8beSwiz #include <stdarg.h>
440a849c91Sperseant #include <stdlib.h>
450a849c91Sperseant #include <stdio.h>
460a849c91Sperseant #include "extern.h"
470a849c91Sperseant 
480a849c91Sperseant u_int
lfs_log2(u_int num)49d2eb498eSmrg lfs_log2(u_int num)
500a849c91Sperseant {
510a849c91Sperseant         u_int i, limit;
520a849c91Sperseant 
530a849c91Sperseant         limit = 1;
540a849c91Sperseant         for (i = 0; limit < num; limit = limit << 1, i++);
550a849c91Sperseant         return (i);
560a849c91Sperseant }
570a849c91Sperseant 
580a849c91Sperseant void
fatal(const char * fmt,...)590a849c91Sperseant fatal(const char *fmt, ...)
600a849c91Sperseant {
610a849c91Sperseant 	va_list ap;
62c632c8beSwiz 
630a849c91Sperseant 	va_start(ap, fmt);
640a849c91Sperseant 	(void)fprintf(stderr, "%s: ", progname);
650a849c91Sperseant 	(void)vfprintf(stderr, fmt, ap);
660a849c91Sperseant 	va_end(ap);
670a849c91Sperseant 	(void)fprintf(stderr, "\n");
680a849c91Sperseant 	exit(1);
690a849c91Sperseant 	/* NOTREACHED */
700a849c91Sperseant }
71