From eda6e4cca4b63ba31f327a07f0484fa4d32c5ebe Mon Sep 17 00:00:00 2001 From: perseant Date: Thu, 22 Jul 1999 20:14:29 +0000 Subject: [PATCH] Address PR bin/7623: if the filesystem is so small (or segment size so large) that not enough segments are available for the second superblock, or to have MIN_FREE_SEGS free for work room for the cleaner, newfs_lfs will now exit with an error. --- sbin/newfs_lfs/lfs.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sbin/newfs_lfs/lfs.c b/sbin/newfs_lfs/lfs.c index 6944487e3dd5..f4a7ddc64398 100644 --- a/sbin/newfs_lfs/lfs.c +++ b/sbin/newfs_lfs/lfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: lfs.c,v 1.4 1999/06/24 16:45:14 perseant Exp $ */ +/* $NetBSD: lfs.c,v 1.5 1999/07/22 20:14:29 perseant Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)lfs.c 8.5 (Berkeley) 5/24/95"; #else -__RCSID("$NetBSD: lfs.c,v 1.4 1999/06/24 16:45:14 perseant Exp $"); +__RCSID("$NetBSD: lfs.c,v 1.5 1999/07/22 20:14:29 perseant Exp $"); #endif #endif /* not lint */ @@ -290,6 +290,9 @@ make_lfs(fd, lp, partp, minfree, block_size, frag_size, seg_size) lfsp->lfs_nclean = lfsp->lfs_nseg = lfsp->lfs_dsize / lfsp->lfs_ssize; lfsp->lfs_maxfilesize = maxtable[lfsp->lfs_bshift] << lfsp->lfs_bshift; + if(lfsp->lfs_nseg < MIN_FREE_SEGS + 1) + fatal("Could not allocate %d segments; please decrease the segment size\n", MIN_FREE_SEGS+1); + /* * The number of free blocks is set from the number of segments times * the segment size - MIN_FREE_SEGS (that we never write because we need to make @@ -324,6 +327,12 @@ make_lfs(fd, lp, partp, minfree, block_size, frag_size, seg_size) break; lfsp->lfs_sboffs[i] = sb_addr; } + + /* We need >= 2 superblocks */ + if(lfsp->lfs_sboffs[1] == 0x0) { + fatal("Could not assign a disk adress for the second superblock.\nPlease decrease the segment size.\n"); + } + last_sb_addr = lfsp->lfs_sboffs[i - 1]; lfsp->lfs_lastseg = lfsp->lfs_sboffs[0]; lfsp->lfs_nextseg =