Use sysctl() to determine maxpartitions. Fixes pr #970.

This commit is contained in:
thorpej 1995-06-28 02:21:02 +00:00
parent c93ec6801c
commit d535998d4b
2 changed files with 53 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: newfs.c,v 1.18 1995/03/18 14:58:43 cgd Exp $ */
/* $NetBSD: newfs.c,v 1.19 1995/06/28 02:21:02 thorpej Exp $ */
/*
* Copyright (c) 1983, 1989, 1993, 1994
@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)newfs.c 8.8 (Berkeley) 4/18/94";
#else
static char rcsid[] = "$NetBSD: newfs.c,v 1.18 1995/03/18 14:58:43 cgd Exp $";
static char rcsid[] = "$NetBSD: newfs.c,v 1.19 1995/06/28 02:21:02 thorpej Exp $";
#endif
#endif /* not lint */
@ -56,6 +56,7 @@ static char rcsid[] = "$NetBSD: newfs.c,v 1.18 1995/03/18 14:58:43 cgd Exp $";
#include <sys/disklabel.h>
#include <sys/file.h>
#include <sys/mount.h>
#include <sys/sysctl.h>
#include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h>
@ -89,6 +90,8 @@ void fatal(const char *fmt, ...);
void fatal();
#endif
int getmaxpartitions __P((void));
#define COMPAT /* allow non-labeled disks */
/*
@ -201,7 +204,7 @@ main(argc, argv)
struct partition oldpartition;
struct stat st;
struct statfs *mp;
int fsi, fso, len, n;
int fsi, fso, len, n, maxpartitions;
char *cp, *s1, *s2, *special, *opstring, buf[BUFSIZ];
if (progname = strrchr(*argv, '/'))
@ -214,6 +217,10 @@ main(argc, argv)
Nflag++;
}
maxpartitions = getmaxpartitions();
if (maxpartitions > 26)
fatal("insane maxpartitions value %d", maxpartitions);
opstring = mfs ?
"NT:a:b:c:d:e:f:i:m:o:s:" :
"NOS:T:a:b:c:d:e:f:i:k:l:m:n:o:p:r:s:t:u:x:";
@ -412,7 +419,8 @@ main(argc, argv)
printf("%s: %s: not a character-special device\n",
progname, special);
cp = strchr(argv[0], '\0') - 1;
if (cp == 0 || (*cp < 'a' || *cp > 'h') && !isdigit(*cp))
if (cp == 0 || (*cp < 'a' || *cp > ('a' + maxpartitions - 1))
&& !isdigit(*cp))
fatal("%s: can't figure out file system partition",
argv[0]);
#ifdef COMPAT
@ -673,6 +681,21 @@ fatal(fmt, va_alist)
/*NOTREACHED*/
}
int
getmaxpartitions()
{
int maxpart, mib[2];
size_t varlen;
mib[0] = CTL_KERN;
mib[1] = KERN_MAXPARTITIONS;
varlen = sizeof(maxpart);
if (sysctl(mib, 2, &maxpart, &varlen, NULL, 0) < 0)
fatal("getmaxpartitions: %s", strerror(errno));
return (maxpart);
}
usage()
{
if (mfs) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: newfs.c,v 1.3 1995/03/18 14:58:53 cgd Exp $ */
/* $NetBSD: newfs.c,v 1.4 1995/06/28 02:21:32 thorpej Exp $ */
/*-
* Copyright (c) 1989, 1992, 1993
@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)newfs.c 8.3 (Berkeley) 4/22/94";
#else
static char rcsid[] = "$NetBSD: newfs.c,v 1.3 1995/03/18 14:58:53 cgd Exp $";
static char rcsid[] = "$NetBSD: newfs.c,v 1.4 1995/06/28 02:21:32 thorpej Exp $";
#endif
#endif /* not lint */
@ -57,6 +57,7 @@ static char rcsid[] = "$NetBSD: newfs.c,v 1.3 1995/03/18 14:58:53 cgd Exp $";
#include <sys/disklabel.h>
#include <sys/file.h>
#include <sys/mount.h>
#include <sys/sysctl.h>
#include <ufs/ufs/dir.h>
#include <ufs/ufs/dinode.h>
@ -118,6 +119,7 @@ char *progname, *special;
static struct disklabel *getdisklabel __P((char *, int));
static struct disklabel *debug_readlabel __P((int));
static void rewritelabel __P((char *, int, struct disklabel *));
static int getmaxpartitions __P((void));
static void usage __P((void));
int
@ -130,7 +132,7 @@ main(argc, argv)
register struct disklabel *lp;
struct partition oldpartition;
struct stat st;
int debug, lfs, fsi, fso, segsize;
int debug, lfs, fsi, fso, segsize, maxpartitions;
char *cp, *opstring;
if (progname = strrchr(*argv, '/'))
@ -143,6 +145,10 @@ main(argc, argv)
Nflag++;
}
maxpartitions = getmaxpartitions();
if (maxpartitions > 26)
fatal("insane maxpartitions value %d", maxpartitions);
/* -F is mfs only and MUST come first! */
opstring = "F:B:DLNS:T:a:b:c:d:e:f:i:k:l:m:n:o:p:r:s:t:u:x:";
if (!mfs)
@ -300,7 +306,8 @@ main(argc, argv)
(void)printf("%s: %s: not a character-special device\n",
progname, special);
cp = strchr(argv[0], '\0') - 1;
if (!debug && (cp == 0 || (*cp < 'a' || *cp > 'h') && !isdigit(*cp)))
if (!debug && (cp == 0 || (*cp < 'a' || *cp > ('a' + maxpartitions - 1))
&& !isdigit(*cp)))
fatal("%s: can't figure out file system partition", argv[0]);
#ifdef COMPAT
@ -425,6 +432,21 @@ rewritelabel(s, fd, lp)
#endif
}
static int
getmaxpartitions()
{
int maxpart, mib[2];
size_t varlen;
mib[0] = CTL_KERN;
mib[1] = KERN_MAXPARTITIONS;
varlen = sizeof(maxpart);
if (sysctl(mib, 2, &maxpart, &varlen, NULL, 0) < 0)
fatal("getmaxpartitions: %s", strerror(errno));
return (maxpart);
}
void
usage()
{