Synchronize on NetBSD-CVS (2013/12/1 12:00:00 UTC)
- Fix for possible unset uid/gid in toproto
- Fix for default mtree style
- Update libelf
- Importing libexecinfo
- Resynchronize GCC, mpc, gmp, mpfr
- build.sh: Replace params with show-params.
This has been done as the make target has been renamed in the same
way, while a new target named params has been added. This new
target generates a file containing all the parameters, instead of
printing it on the console.
- Update test48 with new etc/services (Fix by Ben Gras <ben@minix3.org)
get getservbyport() out of the inner loop
Change-Id: Ie6ad5226fa2621ff9f0dee8782ea48f9443d2091
This commit is contained in:
+57
-7
@@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.123 2011/11/24 15:54:54 ahoka Exp $
|
||||
# $NetBSD: Makefile,v 1.125 2013/10/28 19:05:21 mbalmer Exp $
|
||||
# @(#)Makefile 8.5 (Berkeley) 3/31/94
|
||||
|
||||
# Not ported: XNSrouted enpload scsiformat startslip
|
||||
@@ -8,14 +8,64 @@
|
||||
|
||||
SUBDIR= \
|
||||
\
|
||||
fsck \
|
||||
mknod \
|
||||
nologin \
|
||||
mknod \
|
||||
init \
|
||||
fsck init \
|
||||
mknod nologin \
|
||||
reboot \
|
||||
shutdown
|
||||
shutdown \
|
||||
|
||||
|
||||
# support for various file systems
|
||||
SUBDIR+= newfs_ext2fs fsck_ext2fs
|
||||
.if !defined(__MINIX)
|
||||
SUBDIR+= newfs fsck_ffs fsdb dump restore clri tunefs resize_ffs
|
||||
SUBDIR+= newfs_lfs fsck_lfs dump_lfs resize_lfs
|
||||
SUBDIR+= newfs_msdos fsck_msdos
|
||||
SUBDIR+= newfs_sysvbfs
|
||||
SUBDIR+= newfs_udf
|
||||
SUBDIR+= newfs_v7fs fsck_v7fs
|
||||
SUBDIR+= mount_ados
|
||||
SUBDIR+= mount_cd9660
|
||||
SUBDIR+= mount_chfs
|
||||
SUBDIR+= mount_efs
|
||||
SUBDIR+= mount_ext2fs
|
||||
SUBDIR+= mount_fdesc
|
||||
SUBDIR+= mount_filecore
|
||||
SUBDIR+= mount_ffs
|
||||
SUBDIR+= mount_hfs
|
||||
SUBDIR+= mount_kernfs
|
||||
SUBDIR+= mount_lfs
|
||||
SUBDIR+= mount_msdos
|
||||
SUBDIR+= mount_udf
|
||||
SUBDIR+= mount_nfs
|
||||
SUBDIR+= mount_nilfs
|
||||
SUBDIR+= mount_ntfs
|
||||
SUBDIR+= mount_null
|
||||
SUBDIR+= mount_overlay
|
||||
SUBDIR+= mount_portal
|
||||
SUBDIR+= mount_procfs
|
||||
SUBDIR+= mount_ptyfs
|
||||
SUBDIR+= mount_puffs
|
||||
SUBDIR+= mount_smbfs
|
||||
SUBDIR+= mount_sysvbfs
|
||||
SUBDIR+= mount_tmpfs
|
||||
SUBDIR+= mount_umap
|
||||
SUBDIR+= mount_union
|
||||
SUBDIR+= mount_v7fs
|
||||
|
||||
.if (${MKCRYPTO} != "no")
|
||||
SUBDIR+= cgdconfig
|
||||
.endif
|
||||
|
||||
.if (${USE_INET6} != "no")
|
||||
SUBDIR+= ping6 rtsol
|
||||
.endif
|
||||
|
||||
.if (${MKISCSI} != "no")
|
||||
SUBDIR+= iscsictl iscsid
|
||||
.endif
|
||||
|
||||
# IPsec
|
||||
SUBDIR+= setkey
|
||||
|
||||
.endif # !defined(__MINIX)
|
||||
.include <bsd.subdir.mk>
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
WARNS?= 5
|
||||
BINDIR?= /sbin
|
||||
CPPFLAGS+= -D_NETBSD_SOURCE
|
||||
|
||||
.if (${MKDYNAMICROOT} == "no")
|
||||
LDSTATIC?= -static
|
||||
|
||||
@@ -10,8 +10,4 @@ DPADD+=${LIBUTIL}
|
||||
LDADD+=-lprop
|
||||
DPADD+=${LIBPROP}
|
||||
|
||||
# LSC Does not compile without any warnings...
|
||||
NOGCCERROR:=yes
|
||||
NOCLANGERROR:=yes
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
+17
-27
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: fsck.c,v 1.49 2010/02/24 13:56:07 hannken Exp $ */
|
||||
/* $NetBSD: fsck.c,v 1.51 2012/04/07 04:52:20 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christos Zoulas. All rights reserved.
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: fsck.c,v 1.49 2010/02/24 13:56:07 hannken Exp $");
|
||||
__RCSID("$NetBSD: fsck.c,v 1.51 2012/04/07 04:52:20 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
@@ -89,7 +89,7 @@ static void maketypelist(char *);
|
||||
static void catopt(char **, const char *);
|
||||
static void mangle(char *, int *, const char ** volatile *, int *);
|
||||
static const char *getfslab(const char *);
|
||||
static void usage(void);
|
||||
__dead static void usage(void);
|
||||
static void *isok(struct fstab *);
|
||||
|
||||
int
|
||||
@@ -100,6 +100,7 @@ main(int argc, char *argv[])
|
||||
const char *vfstype = NULL;
|
||||
char globopt[3];
|
||||
int ret = FSCK_EXIT_OK;
|
||||
char buf[MAXPATHLEN];
|
||||
|
||||
globopt[0] = '-';
|
||||
globopt[2] = '\0';
|
||||
@@ -183,11 +184,10 @@ main(int argc, char *argv[])
|
||||
if (flags & CHECK_PROGRESS)
|
||||
maxrun = 1;
|
||||
|
||||
#ifdef __minix
|
||||
#if defined(__minix)
|
||||
/* parallel checking heuristic doesn't work for minix currently */
|
||||
maxrun = 1;
|
||||
#endif
|
||||
|
||||
#endif /* !defined(__minix) */
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
@@ -217,7 +217,9 @@ main(int argc, char *argv[])
|
||||
type = vfstype;
|
||||
}
|
||||
else {
|
||||
spec = fs->fs_spec;
|
||||
spec = getfsspecname(buf, sizeof(buf), fs->fs_spec);
|
||||
if (spec == NULL)
|
||||
err(FSCK_EXIT_CHECK_FAILED, "%s", buf);
|
||||
type = fs->fs_vfstype;
|
||||
if (BADTYPE(fs->fs_type))
|
||||
errx(FSCK_EXIT_CHECK_FAILED,
|
||||
@@ -265,9 +267,9 @@ checkfs(const char *vfst, const char *spec, const char *mntpt, void *auxarg,
|
||||
#endif
|
||||
_PATH_SBIN,
|
||||
_PATH_USRSBIN,
|
||||
#ifdef __minix
|
||||
#if defined(__minix)
|
||||
"/usr/pkg/sbin/",
|
||||
#endif
|
||||
#endif /* defined(__minix) */
|
||||
NULL
|
||||
};
|
||||
const char ** volatile argv, **edir;
|
||||
@@ -276,7 +278,7 @@ checkfs(const char *vfst, const char *spec, const char *mntpt, void *auxarg,
|
||||
int argc, i, status, maxargc;
|
||||
char *optb;
|
||||
char *volatile optbuf;
|
||||
char execname[MAXPATHLEN + 1], execbase1[MAXPATHLEN], execbase2[MAXPATHLEN];
|
||||
char execname[MAXPATHLEN + 1], execbase[MAXPATHLEN];
|
||||
const char *extra = getoptions(vfstype);
|
||||
|
||||
if (!strcmp(vfstype, "ufs"))
|
||||
@@ -292,10 +294,9 @@ checkfs(const char *vfst, const char *spec, const char *mntpt, void *auxarg,
|
||||
maxargc = 64;
|
||||
argv = emalloc(sizeof(char *) * maxargc);
|
||||
|
||||
(void) snprintf(execbase1, sizeof(execbase1), "fsck_%s", vfstype);
|
||||
(void) snprintf(execbase2, sizeof(execbase2), "fsck.%s", vfstype);
|
||||
(void) snprintf(execbase, sizeof(execbase), "fsck_%s", vfstype);
|
||||
argc = 0;
|
||||
argv[argc++] = execbase1;
|
||||
argv[argc++] = execbase;
|
||||
if (optbuf)
|
||||
mangle(optbuf, &argc, &argv, &maxargc);
|
||||
argv[argc++] = spec;
|
||||
@@ -318,7 +319,6 @@ checkfs(const char *vfst, const char *spec, const char *mntpt, void *auxarg,
|
||||
return FSCK_EXIT_CHECK_FAILED;
|
||||
|
||||
case 0: /* Child. */
|
||||
#ifndef __minix
|
||||
if ((flags & CHECK_FORCE) == 0) {
|
||||
struct statvfs sfs;
|
||||
|
||||
@@ -339,7 +339,6 @@ checkfs(const char *vfst, const char *spec, const char *mntpt, void *auxarg,
|
||||
_exit(FSCK_EXIT_CHECK_FAILED); /* fsck [[-p] ...] */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (flags & CHECK_DEBUG)
|
||||
_exit(FSCK_EXIT_OK);
|
||||
@@ -348,16 +347,7 @@ checkfs(const char *vfst, const char *spec, const char *mntpt, void *auxarg,
|
||||
edir = edirs;
|
||||
do {
|
||||
(void)snprintf(execname,
|
||||
sizeof(execname), "%s/%s", *edir, execbase1);
|
||||
execv(execname, (char * const *)__UNCONST(argv));
|
||||
if (errno != ENOENT) {
|
||||
if (spec)
|
||||
warn("exec %s for %s", execname, spec);
|
||||
else
|
||||
warn("exec %s", execname);
|
||||
}
|
||||
(void)snprintf(execname,
|
||||
sizeof(execname), "%s/%s", *edir, execbase2);
|
||||
sizeof(execname), "%s/%s", *edir, execbase);
|
||||
execv(execname, (char * const *)__UNCONST(argv));
|
||||
if (errno != ENOENT) {
|
||||
if (spec)
|
||||
@@ -557,7 +547,7 @@ mangle(char *opts, int *argcp, const char ** volatile *argvp, int *maxargcp)
|
||||
static const char *
|
||||
getfslab(const char *str)
|
||||
{
|
||||
#ifdef __minix
|
||||
#if defined(__minix)
|
||||
errx(1, "cannot determine vfstype under minix");
|
||||
#else
|
||||
static struct dkwedge_info dkw;
|
||||
@@ -597,7 +587,7 @@ getfslab(const char *str)
|
||||
fstypenames[t], str);
|
||||
|
||||
return vfstype;
|
||||
#endif
|
||||
#endif /* defined(__minix) */
|
||||
}
|
||||
|
||||
|
||||
|
||||
+36
-54
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: fsutil.c,v 1.20 2011/06/09 19:57:50 christos Exp $ */
|
||||
/* $NetBSD: fsutil.c,v 1.24 2013/01/13 19:53:16 mlelstv Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1993
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: fsutil.c,v 1.20 2011/06/09 19:57:50 christos Exp $");
|
||||
__RCSID("$NetBSD: fsutil.c,v 1.24 2013/01/13 19:53:16 mlelstv Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
@@ -45,6 +45,7 @@ __RCSID("$NetBSD: fsutil.c,v 1.20 2011/06/09 19:57:50 christos Exp $");
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include <util.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -165,82 +166,68 @@ panic(const char *fmt, ...)
|
||||
exit(FSCK_EXIT_CHECK_FAILED);
|
||||
}
|
||||
|
||||
const char *
|
||||
unrawname(const char *name)
|
||||
{
|
||||
static char unrawbuf[MAXPATHLEN];
|
||||
const char *dp;
|
||||
struct stat stb;
|
||||
|
||||
if ((dp = strrchr(name, '/')) == 0)
|
||||
return (name);
|
||||
if (stat(name, &stb) < 0)
|
||||
return (name);
|
||||
if (!S_ISCHR(stb.st_mode))
|
||||
return (name);
|
||||
if (dp[1] != 'r')
|
||||
return (name);
|
||||
(void)snprintf(unrawbuf, sizeof(unrawbuf), "%.*s/%s",
|
||||
(int)(dp - name), name, dp + 2);
|
||||
return (unrawbuf);
|
||||
}
|
||||
|
||||
const char *
|
||||
rawname(const char *name)
|
||||
{
|
||||
static char rawbuf[MAXPATHLEN];
|
||||
const char *dp;
|
||||
|
||||
if ((dp = strrchr(name, '/')) == 0)
|
||||
return (0);
|
||||
(void)snprintf(rawbuf, sizeof(rawbuf), "%.*s/r%s",
|
||||
(int)(dp - name), name, dp + 1);
|
||||
return (rawbuf);
|
||||
}
|
||||
|
||||
const char *
|
||||
blockcheck(const char *origname)
|
||||
{
|
||||
#ifdef __minix
|
||||
#if defined(__minix)
|
||||
return origname;
|
||||
#else
|
||||
struct stat stslash, stblock, stchar;
|
||||
const char *newname, *raw;
|
||||
const char *newname, *raw, *cooked;
|
||||
struct fstab *fsp;
|
||||
int retried = 0;
|
||||
ssize_t len;
|
||||
char cbuf[MAXPATHLEN];
|
||||
static char buf[MAXPATHLEN];
|
||||
|
||||
hot = 0;
|
||||
if (stat("/", &stslash) < 0) {
|
||||
perr("Can't stat `/'");
|
||||
return (origname);
|
||||
}
|
||||
newname = origname;
|
||||
len = readlink(origname, cbuf, sizeof(cbuf)-1);
|
||||
if (len == -1) {
|
||||
newname = origname;
|
||||
} else {
|
||||
cbuf[len] = '\0';
|
||||
newname = cbuf;
|
||||
}
|
||||
retry:
|
||||
if (stat(newname, &stblock) < 0) {
|
||||
perr("Can't stat `%s'", newname);
|
||||
return (origname);
|
||||
return origname;
|
||||
}
|
||||
if (S_ISBLK(stblock.st_mode)) {
|
||||
if (stslash.st_dev == stblock.st_rdev)
|
||||
hot++;
|
||||
raw = strdup(newname);
|
||||
raw = rawname(newname);
|
||||
raw = getdiskrawname(buf, sizeof(buf), newname);
|
||||
if (raw == NULL) {
|
||||
perr("Can't convert to raw `%s'", newname);
|
||||
return origname;
|
||||
}
|
||||
if (stat(raw, &stchar) < 0) {
|
||||
perr("Can't stat `%s'", raw);
|
||||
return (origname);
|
||||
return origname;
|
||||
}
|
||||
if (S_ISCHR(stchar.st_mode)) {
|
||||
return (raw);
|
||||
return raw;
|
||||
} else {
|
||||
printf("%s is not a character device\n", raw);
|
||||
return (origname);
|
||||
perr("%s is not a character device\n", raw);
|
||||
return origname;
|
||||
}
|
||||
} else if (S_ISCHR(stblock.st_mode) && !retried) {
|
||||
newname = unrawname(newname);
|
||||
cooked = getdiskcookedname(cbuf, sizeof(cbuf), newname);
|
||||
if (cooked == NULL) {
|
||||
perr("Can't convert to cooked `%s'", newname);
|
||||
return origname;
|
||||
} else
|
||||
newname = cooked;
|
||||
retried++;
|
||||
goto retry;
|
||||
} else if ((fsp = getfsfile(newname)) != 0 && !retried) {
|
||||
newname = fsp->fs_spec;
|
||||
newname = getfsspecname(cbuf, sizeof(cbuf), fsp->fs_spec);
|
||||
if (newname == NULL)
|
||||
perr("%s", buf);
|
||||
retried++;
|
||||
goto retry;
|
||||
}
|
||||
@@ -248,8 +235,8 @@ retry:
|
||||
* Not a block or character device, just return name and
|
||||
* let the user decide whether to use it.
|
||||
*/
|
||||
return (origname);
|
||||
#endif
|
||||
return origname;
|
||||
#endif /* defined(__minix) */
|
||||
}
|
||||
|
||||
const char *
|
||||
@@ -265,13 +252,8 @@ print_mtime(time_t t)
|
||||
}
|
||||
|
||||
|
||||
#ifdef __minix
|
||||
__dead void
|
||||
catch(int n)
|
||||
#else
|
||||
void
|
||||
catch(int n)
|
||||
#endif
|
||||
{
|
||||
if (ckfinish) (*ckfinish)(0);
|
||||
_exit(FSCK_EXIT_SIGNALLED);
|
||||
|
||||
+8
-16
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: fsutil.h,v 1.17 2011/06/09 21:23:29 christos Exp $ */
|
||||
/* $NetBSD: fsutil.h,v 1.19 2012/04/07 16:44:10 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christos Zoulas. All rights reserved.
|
||||
@@ -27,20 +27,12 @@
|
||||
#include <stdarg.h>
|
||||
#include <signal.h>
|
||||
|
||||
void errexit(const char *, ...)
|
||||
__attribute__((__noreturn__,__format__(__printf__,1,2)));
|
||||
void pfatal(const char *, ...)
|
||||
__attribute__((__format__(__printf__,1,2)));
|
||||
void pwarn(const char *, ...)
|
||||
__attribute__((__format__(__printf__,1,2)));
|
||||
void perr(const char *, ...)
|
||||
__attribute__((__format__(__printf__,1,2)));
|
||||
void panic(const char *, ...)
|
||||
__attribute__((__noreturn__,__format__(__printf__,1,2)));
|
||||
void vmsg(int, const char *, va_list)
|
||||
__attribute__((__format__(__printf__,2,0)));
|
||||
const char *rawname(const char *);
|
||||
const char *unrawname(const char *);
|
||||
void errexit(const char *, ...) __printflike(1, 2) __dead;
|
||||
void pfatal(const char *, ...) __printflike(1, 2);
|
||||
void pwarn(const char *, ...) __printflike(1, 2);
|
||||
void perr(const char *, ...) __printflike(1, 2);
|
||||
void panic(const char *, ...) __printflike(1, 2) __dead;
|
||||
void vmsg(int, const char *, va_list) __printflike(2, 0);
|
||||
const char *blockcheck(const char *);
|
||||
const char *cdevname(void);
|
||||
void setcdevname(const char *, int);
|
||||
@@ -60,6 +52,6 @@ int checkfstab(int, int, void *(*)(struct fstab *),
|
||||
|
||||
void (*ckfinish)(int);
|
||||
volatile sig_atomic_t returntosingle;
|
||||
void catch(int);
|
||||
void catch(int) __dead;
|
||||
void catchquit(int);
|
||||
void voidquit(int);
|
||||
|
||||
+47
-81
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: partutil.c,v 1.10 2010/03/06 00:30:54 christos Exp $ */
|
||||
/* $NetBSD: partutil.c,v 1.12 2013/04/13 22:08:57 jakllsch Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
@@ -30,7 +30,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: partutil.c,v 1.10 2010/03/06 00:30:54 christos Exp $");
|
||||
__RCSID("$NetBSD: partutil.c,v 1.12 2013/04/13 22:08:57 jakllsch Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/disklabel.h>
|
||||
@@ -89,73 +89,6 @@ dict2geom(struct disk_geom *geo, prop_dictionary_t dict)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
part2wedge(struct dkwedge_info *dkw, const struct disklabel *lp, const char *s)
|
||||
{
|
||||
#ifdef __minix
|
||||
errx(1, "minix doesn't know about wedges");
|
||||
#else
|
||||
struct stat sb;
|
||||
const struct partition *pp;
|
||||
int ptn;
|
||||
|
||||
(void)memset(dkw, 0, sizeof(*dkw));
|
||||
if (stat(s, &sb) == -1)
|
||||
return;
|
||||
|
||||
ptn = strchr(s, '\0')[-1] - 'a';
|
||||
if ((unsigned)ptn >= lp->d_npartitions ||
|
||||
(devminor_t)ptn != DISKPART(sb.st_rdev))
|
||||
return;
|
||||
|
||||
pp = &lp->d_partitions[ptn];
|
||||
dkw->dkw_offset = pp->p_offset;
|
||||
dkw->dkw_size = pp->p_size;
|
||||
dkw->dkw_parent[0] = '*';
|
||||
switch (pp->p_fstype) {
|
||||
default:
|
||||
(void)strcpy(dkw->dkw_ptype, DKW_PTYPE_UNKNOWN);
|
||||
break;
|
||||
case FS_UNUSED:
|
||||
(void)strcpy(dkw->dkw_ptype, DKW_PTYPE_UNUSED);
|
||||
break;
|
||||
case FS_SWAP:
|
||||
(void)strcpy(dkw->dkw_ptype, DKW_PTYPE_SWAP);
|
||||
break;
|
||||
case FS_BSDFFS:
|
||||
(void)strcpy(dkw->dkw_ptype, DKW_PTYPE_FFS);
|
||||
break;
|
||||
case FS_BSDLFS:
|
||||
(void)strcpy(dkw->dkw_ptype, DKW_PTYPE_LFS);
|
||||
break;
|
||||
case FS_EX2FS:
|
||||
(void)strcpy(dkw->dkw_ptype, DKW_PTYPE_EXT2FS);
|
||||
break;
|
||||
case FS_ISO9660:
|
||||
(void)strcpy(dkw->dkw_ptype, DKW_PTYPE_ISO9660);
|
||||
break;
|
||||
case FS_ADOS:
|
||||
(void)strcpy(dkw->dkw_ptype, DKW_PTYPE_AMIGADOS);
|
||||
break;
|
||||
case FS_HFS:
|
||||
(void)strcpy(dkw->dkw_ptype, DKW_PTYPE_APPLEHFS);
|
||||
break;
|
||||
case FS_MSDOS:
|
||||
(void)strcpy(dkw->dkw_ptype, DKW_PTYPE_FAT);
|
||||
break;
|
||||
case FS_FILECORE:
|
||||
(void)strcpy(dkw->dkw_ptype, DKW_PTYPE_FILECORE);
|
||||
break;
|
||||
case FS_APPLEUFS:
|
||||
(void)strcpy(dkw->dkw_ptype, DKW_PTYPE_APPLEUFS);
|
||||
break;
|
||||
case FS_NTFS:
|
||||
(void)strcpy(dkw->dkw_ptype, DKW_PTYPE_NTFS);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
getdiskinfo(const char *s, int fd, const char *dt, struct disk_geom *geo,
|
||||
struct dkwedge_info *dkw)
|
||||
@@ -163,23 +96,28 @@ getdiskinfo(const char *s, int fd, const char *dt, struct disk_geom *geo,
|
||||
struct disklabel lab;
|
||||
struct disklabel *lp = &lab;
|
||||
prop_dictionary_t disk_dict, geom_dict;
|
||||
#if !defined(__minix)
|
||||
struct stat sb;
|
||||
const struct partition *pp;
|
||||
int ptn;
|
||||
#endif /* defined(__minix) */
|
||||
|
||||
if (dt) {
|
||||
#ifdef __minix
|
||||
#if defined(__minix)
|
||||
errx(1, "minix doesn't know about disk types (%s)", dt);
|
||||
#else
|
||||
lp = getdiskbyname(dt);
|
||||
if (lp == NULL)
|
||||
errx(1, "unknown disk type `%s'", dt);
|
||||
#endif
|
||||
#endif /* defined(__minix) */
|
||||
}
|
||||
|
||||
/* Get disk description dictionary */
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
if (prop_dictionary_recv_ioctl(fd, DIOCGDISKINFO, &disk_dict)) {
|
||||
#else
|
||||
if (-1) {
|
||||
#endif
|
||||
if (1) {
|
||||
#endif /* !defined(__minix) */
|
||||
/*
|
||||
* Ask for disklabel if DIOCGDISKINFO failed. This is
|
||||
* compatibility call and can be removed when all devices
|
||||
@@ -195,15 +133,43 @@ getdiskinfo(const char *s, int fd, const char *dt, struct disk_geom *geo,
|
||||
geom_dict = prop_dictionary_get(disk_dict, "geometry");
|
||||
dict2geom(geo, geom_dict);
|
||||
}
|
||||
|
||||
/* Get info about partition/wedge */
|
||||
if (ioctl(fd, DIOCGWEDGEINFO, dkw) == -1) {
|
||||
if (ioctl(fd, DIOCGDINFO, lp) == -1)
|
||||
err(1, "Please implement DIOCGWEDGEINFO or "
|
||||
"DIOCGDINFO for disk device %s", s);
|
||||
|
||||
part2wedge(dkw, lp, s);
|
||||
/* Get info about partition/wedge */
|
||||
if (ioctl(fd, DIOCGWEDGEINFO, dkw) != -1) {
|
||||
/* DIOCGWEDGEINFO didn't fail, we're done */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ioctl(fd, DIOCGDINFO, lp) == -1) {
|
||||
err(1, "Please implement DIOCGWEDGEINFO or "
|
||||
"DIOCGDINFO for disk device %s", s);
|
||||
}
|
||||
|
||||
#if !defined(__minix)
|
||||
/* DIOCGDINFO didn't fail */
|
||||
|
||||
(void)memset(dkw, 0, sizeof(*dkw));
|
||||
|
||||
if (stat(s, &sb) == -1)
|
||||
return 0;
|
||||
|
||||
ptn = strchr(s, '\0')[-1] - 'a';
|
||||
if ((unsigned)ptn >= lp->d_npartitions ||
|
||||
(devminor_t)ptn != DISKPART(sb.st_rdev))
|
||||
return 0;
|
||||
|
||||
pp = &lp->d_partitions[ptn];
|
||||
if (ptn != getrawpartition()) {
|
||||
dkw->dkw_offset = pp->p_offset;
|
||||
dkw->dkw_size = pp->p_size;
|
||||
} else {
|
||||
dkw->dkw_offset = 0;
|
||||
dkw->dkw_size = geo->dg_secperunit;
|
||||
}
|
||||
dkw->dkw_parent[0] = '*';
|
||||
strlcpy(dkw->dkw_ptype, getfstypename(pp->p_fstype),
|
||||
sizeof(dkw->dkw_ptype));
|
||||
#endif /* !defined(__minix) */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+13
-7
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: preen.c,v 1.30 2008/02/23 21:41:47 christos Exp $ */
|
||||
/* $NetBSD: preen.c,v 1.31 2012/04/07 04:52:20 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990, 1993
|
||||
@@ -34,7 +34,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)preen.c 8.5 (Berkeley) 4/28/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: preen.c,v 1.30 2008/02/23 21:41:47 christos Exp $");
|
||||
__RCSID("$NetBSD: preen.c,v 1.31 2012/04/07 04:52:20 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@@ -108,10 +108,16 @@ checkfstab(int flags, int maxrun, void *(*docheck)(struct fstab *),
|
||||
return FSCK_EXIT_CHECK_FAILED;
|
||||
}
|
||||
while ((fs = getfsent()) != 0) {
|
||||
char buf[MAXPATHLEN];
|
||||
const char *fsspec;
|
||||
if ((auxarg = (*docheck)(fs)) == NULL)
|
||||
continue;
|
||||
|
||||
name = blockcheck(fs->fs_spec);
|
||||
fsspec = getfsspecname(buf, sizeof(buf), fs->fs_spec);
|
||||
if (fsspec == NULL) {
|
||||
warn("%s", buf);
|
||||
return FSCK_EXIT_CHECK_FAILED;
|
||||
}
|
||||
name = blockcheck(fsspec);
|
||||
if (flags & CHECK_DEBUG)
|
||||
printf("pass %d, name %s\n", passno, name);
|
||||
|
||||
@@ -135,7 +141,7 @@ checkfstab(int flags, int maxrun, void *(*docheck)(struct fstab *),
|
||||
} else if (passno == 2 && fs->fs_passno > 1) {
|
||||
if (name == NULL) {
|
||||
(void) fprintf(stderr,
|
||||
"BAD DISK NAME %s\n", fs->fs_spec);
|
||||
"BAD DISK NAME %s\n", fsspec);
|
||||
sumstatus = FSCK_EXIT_CHECK_FAILED;
|
||||
continue;
|
||||
}
|
||||
@@ -271,7 +277,7 @@ finddisk(const char *name)
|
||||
const char *p;
|
||||
size_t len, dlen;
|
||||
struct diskentry *d;
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
char buf[MAXPATHLEN];
|
||||
struct dkwedge_info dkw;
|
||||
int fd;
|
||||
@@ -281,7 +287,7 @@ finddisk(const char *name)
|
||||
name = dkw.dkw_parent;
|
||||
(void)close(fd);
|
||||
}
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
|
||||
for (dlen = len = strlen(name), p = name + len - 1; p >= name; --p)
|
||||
if (isdigit((unsigned char)*p)) {
|
||||
|
||||
@@ -11,8 +11,6 @@ FSCK= ${NETBSDSRCDIR}/sbin/fsck
|
||||
CPPFLAGS+= -I${FSCK}
|
||||
.PATH: ${NETBSDSRCDIR}/sys/ufs/ext2fs ${FSCK}
|
||||
|
||||
SYMLINKS+= $(BINDIR)/$(PROG) $(BINDIR)/fsck.ext2
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
LDADD+=-lutil
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: dir.c,v 1.23 2009/10/19 18:41:07 bouyer Exp $ */
|
||||
/* $NetBSD: dir.c,v 1.28 2013/06/23 07:28:36 dholland Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1986, 1993
|
||||
@@ -58,7 +58,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)dir.c 8.5 (Berkeley) 12/8/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: dir.c,v 1.23 2009/10/19 18:41:07 bouyer Exp $");
|
||||
__RCSID("$NetBSD: dir.c,v 1.28 2013/06/23 07:28:36 dholland Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@@ -84,7 +84,7 @@ const char *lfname = "lost+found";
|
||||
int lfmode = 01700;
|
||||
struct ext2fs_dirtemplate emptydir = {
|
||||
.dot_ino = 0,
|
||||
.dot_reclen = DIRBLKSIZ,
|
||||
.dot_reclen = UFS_DIRBLKSIZ,
|
||||
};
|
||||
struct ext2fs_dirtemplate dirhead = {
|
||||
.dot_ino = 0,
|
||||
@@ -93,12 +93,12 @@ struct ext2fs_dirtemplate dirhead = {
|
||||
.dot_type = EXT2_FT_DIR,
|
||||
.dot_name = ".",
|
||||
.dotdot_ino = 0,
|
||||
.dotdot_reclen = DIRBLKSIZ - 12,
|
||||
.dotdot_reclen = UFS_DIRBLKSIZ - 12,
|
||||
.dotdot_namlen = 2,
|
||||
.dotdot_type = EXT2_FT_DIR,
|
||||
.dotdot_name = "..",
|
||||
};
|
||||
#undef DIRBLKSIZ
|
||||
#undef UFS_DIRBLKSIZ
|
||||
|
||||
static int expanddir(struct ext2fs_dinode *, char *);
|
||||
static void freedir(ino_t, ino_t);
|
||||
@@ -558,8 +558,8 @@ expanddir(struct ext2fs_dinode *dp, char *name)
|
||||
struct bufarea *bp;
|
||||
char *firstblk;
|
||||
|
||||
lastbn = lblkno(&sblock, inosize(dp));
|
||||
if (lastbn >= NDADDR - 1 || fs2h32(dp->e2di_blocks[lastbn]) == 0 ||
|
||||
lastbn = ext2_lblkno(&sblock, inosize(dp));
|
||||
if (lastbn >= EXT2FS_NDADDR - 1 || fs2h32(dp->e2di_blocks[lastbn]) == 0 ||
|
||||
inosize(dp) == 0) {
|
||||
return (0);
|
||||
}
|
||||
@@ -569,7 +569,7 @@ expanddir(struct ext2fs_dinode *dp, char *name)
|
||||
dp->e2di_blocks[lastbn + 1] = dp->e2di_blocks[lastbn];
|
||||
dp->e2di_blocks[lastbn] = h2fs32(newblk);
|
||||
inossize(dp, inosize(dp) + sblock.e2fs_bsize);
|
||||
dp->e2di_nblock = h2fs32(fs2h32(dp->e2di_nblock) + 1);
|
||||
inosnblock(dp, inonblock(dp) + btodb(sblock.e2fs_bsize));
|
||||
bp = getdirblk(fs2h32(dp->e2di_blocks[lastbn + 1]),
|
||||
sblock.e2fs_bsize);
|
||||
if (bp->b_errs)
|
||||
@@ -603,7 +603,7 @@ bad:
|
||||
dp->e2di_blocks[lastbn] = dp->e2di_blocks[lastbn + 1];
|
||||
dp->e2di_blocks[lastbn + 1] = 0;
|
||||
inossize(dp, inosize(dp) - sblock.e2fs_bsize);
|
||||
dp->e2di_nblock = h2fs32(fs2h32(dp->e2di_nblock) - 1);
|
||||
inosnblock(dp, inonblock(dp) - btodb(sblock.e2fs_bsize));
|
||||
freeblk(newblk);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
/* $NetBSD: ext2fs_bswap.c,v 1.16 2009/10/19 18:41:17 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Manuel Bouyer.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ext2fs_bswap.c,v 1.16 2009/10/19 18:41:17 bouyer Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <ufs/ext2fs/ext2fs.h>
|
||||
#include <ufs/ext2fs/ext2fs_dinode.h>
|
||||
|
||||
#if defined(_KERNEL)
|
||||
#include <sys/systm.h>
|
||||
#else
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
/* These functions are only needed if native byte order is not big endian */
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
void
|
||||
e2fs_sb_bswap(struct ext2fs *old, struct ext2fs *new)
|
||||
{
|
||||
|
||||
/* preserve unused fields */
|
||||
memcpy(new, old, sizeof(struct ext2fs));
|
||||
new->e2fs_icount = bswap32(old->e2fs_icount);
|
||||
new->e2fs_bcount = bswap32(old->e2fs_bcount);
|
||||
new->e2fs_rbcount = bswap32(old->e2fs_rbcount);
|
||||
new->e2fs_fbcount = bswap32(old->e2fs_fbcount);
|
||||
new->e2fs_ficount = bswap32(old->e2fs_ficount);
|
||||
new->e2fs_first_dblock = bswap32(old->e2fs_first_dblock);
|
||||
new->e2fs_log_bsize = bswap32(old->e2fs_log_bsize);
|
||||
new->e2fs_fsize = bswap32(old->e2fs_fsize);
|
||||
new->e2fs_bpg = bswap32(old->e2fs_bpg);
|
||||
new->e2fs_fpg = bswap32(old->e2fs_fpg);
|
||||
new->e2fs_ipg = bswap32(old->e2fs_ipg);
|
||||
new->e2fs_mtime = bswap32(old->e2fs_mtime);
|
||||
new->e2fs_wtime = bswap32(old->e2fs_wtime);
|
||||
new->e2fs_mnt_count = bswap16(old->e2fs_mnt_count);
|
||||
new->e2fs_max_mnt_count = bswap16(old->e2fs_max_mnt_count);
|
||||
new->e2fs_magic = bswap16(old->e2fs_magic);
|
||||
new->e2fs_state = bswap16(old->e2fs_state);
|
||||
new->e2fs_beh = bswap16(old->e2fs_beh);
|
||||
new->e2fs_minrev = bswap16(old->e2fs_minrev);
|
||||
new->e2fs_lastfsck = bswap32(old->e2fs_lastfsck);
|
||||
new->e2fs_fsckintv = bswap32(old->e2fs_fsckintv);
|
||||
new->e2fs_creator = bswap32(old->e2fs_creator);
|
||||
new->e2fs_rev = bswap32(old->e2fs_rev);
|
||||
new->e2fs_ruid = bswap16(old->e2fs_ruid);
|
||||
new->e2fs_rgid = bswap16(old->e2fs_rgid);
|
||||
new->e2fs_first_ino = bswap32(old->e2fs_first_ino);
|
||||
new->e2fs_inode_size = bswap16(old->e2fs_inode_size);
|
||||
new->e2fs_block_group_nr = bswap16(old->e2fs_block_group_nr);
|
||||
new->e2fs_features_compat = bswap32(old->e2fs_features_compat);
|
||||
new->e2fs_features_incompat = bswap32(old->e2fs_features_incompat);
|
||||
new->e2fs_features_rocompat = bswap32(old->e2fs_features_rocompat);
|
||||
new->e2fs_algo = bswap32(old->e2fs_algo);
|
||||
new->e2fs_reserved_ngdb = bswap16(old->e2fs_reserved_ngdb);
|
||||
}
|
||||
|
||||
void e2fs_cg_bswap(struct ext2_gd *old, struct ext2_gd *new, int size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < (size / (int)sizeof(struct ext2_gd)); i++) {
|
||||
new[i].ext2bgd_b_bitmap = bswap32(old[i].ext2bgd_b_bitmap);
|
||||
new[i].ext2bgd_i_bitmap = bswap32(old[i].ext2bgd_i_bitmap);
|
||||
new[i].ext2bgd_i_tables = bswap32(old[i].ext2bgd_i_tables);
|
||||
new[i].ext2bgd_nbfree = bswap16(old[i].ext2bgd_nbfree);
|
||||
new[i].ext2bgd_nifree = bswap16(old[i].ext2bgd_nifree);
|
||||
new[i].ext2bgd_ndirs = bswap16(old[i].ext2bgd_ndirs);
|
||||
}
|
||||
}
|
||||
|
||||
void e2fs_i_bswap(struct ext2fs_dinode *old, struct ext2fs_dinode *new)
|
||||
{
|
||||
|
||||
new->e2di_mode = bswap16(old->e2di_mode);
|
||||
new->e2di_uid = bswap16(old->e2di_uid);
|
||||
new->e2di_gid = bswap16(old->e2di_gid);
|
||||
new->e2di_nlink = bswap16(old->e2di_nlink);
|
||||
new->e2di_size = bswap32(old->e2di_size);
|
||||
new->e2di_atime = bswap32(old->e2di_atime);
|
||||
new->e2di_ctime = bswap32(old->e2di_ctime);
|
||||
new->e2di_mtime = bswap32(old->e2di_mtime);
|
||||
new->e2di_dtime = bswap32(old->e2di_dtime);
|
||||
new->e2di_nblock = bswap32(old->e2di_nblock);
|
||||
new->e2di_flags = bswap32(old->e2di_flags);
|
||||
new->e2di_gen = bswap32(old->e2di_gen);
|
||||
new->e2di_facl = bswap32(old->e2di_facl);
|
||||
new->e2di_dacl = bswap32(old->e2di_dacl);
|
||||
new->e2di_faddr = bswap32(old->e2di_faddr);
|
||||
new->e2di_uid_high = bswap16(old->e2di_uid_high);
|
||||
new->e2di_gid_high = bswap16(old->e2di_gid_high);
|
||||
memcpy(&new->e2di_blocks[0], &old->e2di_blocks[0],
|
||||
(NDADDR + NIADDR) * sizeof(uint32_t));
|
||||
}
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: extern.h,v 1.7 2011/06/09 19:57:50 christos Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.8 2012/11/25 19:42:14 jakllsch Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Manuel Bouyer.
|
||||
@@ -71,3 +71,5 @@ int reply(const char *);
|
||||
void resetinodebuf(void);
|
||||
int setup(const char *);
|
||||
struct ext2fs_dinode * getnextinode(ino_t);
|
||||
uint64_t inonblock(struct ext2fs_dinode *);
|
||||
void inosnblock(struct ext2fs_dinode *, uint64_t);
|
||||
|
||||
+92
-16
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: inode.c,v 1.31 2010/02/04 23:55:42 christos Exp $ */
|
||||
/* $NetBSD: inode.c,v 1.36 2013/06/23 07:28:36 dholland Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1986, 1993
|
||||
@@ -58,7 +58,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)inode.c 8.5 (Berkeley) 2/8/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: inode.c,v 1.31 2010/02/04 23:55:42 christos Exp $");
|
||||
__RCSID("$NetBSD: inode.c,v 1.36 2013/06/23 07:28:36 dholland Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@@ -97,6 +97,8 @@ static int iblock(struct inodesc *, long, u_int64_t);
|
||||
|
||||
static int setlarge(void);
|
||||
|
||||
static int sethuge(void);
|
||||
|
||||
static int
|
||||
setlarge(void)
|
||||
{
|
||||
@@ -115,6 +117,24 @@ setlarge(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
sethuge(void)
|
||||
{
|
||||
if (sblock.e2fs.e2fs_rev < E2FS_REV1) {
|
||||
pfatal("HUGE FILES UNSUPPORTED ON REVISION 0 FILESYSTEMS");
|
||||
return 0;
|
||||
}
|
||||
if (!(sblock.e2fs.e2fs_features_rocompat & EXT2F_ROCOMPAT_HUGE_FILE)) {
|
||||
if (preen)
|
||||
pwarn("SETTING HUGE FILE FEATURE\n");
|
||||
else if (!reply("SET HUGE FILE FEATURE"))
|
||||
return 0;
|
||||
sblock.e2fs.e2fs_features_rocompat |= EXT2F_ROCOMPAT_HUGE_FILE;
|
||||
sbdirty();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
u_int64_t
|
||||
inosize(struct ext2fs_dinode *dp)
|
||||
{
|
||||
@@ -163,7 +183,7 @@ ckinode(struct ext2fs_dinode *dp, struct inodesc *idesc)
|
||||
return (KEEPON);
|
||||
dino = *dp;
|
||||
ndb = howmany(inosize(&dino), sblock.e2fs_bsize);
|
||||
for (ap = &dino.e2di_blocks[0]; ap < &dino.e2di_blocks[NDADDR];
|
||||
for (ap = &dino.e2di_blocks[0]; ap < &dino.e2di_blocks[EXT2FS_NDADDR];
|
||||
ap++,ndb--) {
|
||||
idesc->id_numfrags = 1;
|
||||
if (*ap == 0) {
|
||||
@@ -195,9 +215,9 @@ ckinode(struct ext2fs_dinode *dp, struct inodesc *idesc)
|
||||
return (ret);
|
||||
}
|
||||
idesc->id_numfrags = 1;
|
||||
remsize = inosize(&dino) - sblock.e2fs_bsize * NDADDR;
|
||||
remsize = inosize(&dino) - sblock.e2fs_bsize * EXT2FS_NDADDR;
|
||||
sizepb = sblock.e2fs_bsize;
|
||||
for (ap = &dino.e2di_blocks[NDADDR], n = 1; n <= NIADDR; ap++, n++) {
|
||||
for (ap = &dino.e2di_blocks[EXT2FS_NDADDR], n = 1; n <= EXT2FS_NIADDR; ap++, n++) {
|
||||
if (*ap) {
|
||||
idesc->id_blkno = fs2h32(*ap);
|
||||
ret = iblock(idesc, n, remsize);
|
||||
@@ -222,7 +242,7 @@ ckinode(struct ext2fs_dinode *dp, struct inodesc *idesc)
|
||||
}
|
||||
}
|
||||
}
|
||||
sizepb *= NINDIR(&sblock);
|
||||
sizepb *= EXT2_NINDIR(&sblock);
|
||||
remsize -= sizepb;
|
||||
}
|
||||
return (KEEPON);
|
||||
@@ -253,14 +273,14 @@ iblock(struct inodesc *idesc, long ilevel, u_int64_t isize)
|
||||
bp = getdatablk(idesc->id_blkno, sblock.e2fs_bsize);
|
||||
ilevel--;
|
||||
for (sizepb = sblock.e2fs_bsize, i = 0; i < ilevel; i++)
|
||||
sizepb *= NINDIR(&sblock);
|
||||
if (isize > sizepb * NINDIR(&sblock))
|
||||
nif = NINDIR(&sblock);
|
||||
sizepb *= EXT2_NINDIR(&sblock);
|
||||
if (isize > sizepb * EXT2_NINDIR(&sblock))
|
||||
nif = EXT2_NINDIR(&sblock);
|
||||
else
|
||||
nif = howmany(isize, sizepb);
|
||||
if (idesc->id_func == pass1check &&
|
||||
nif < NINDIR(&sblock)) {
|
||||
aplim = &bp->b_un.b_indir[NINDIR(&sblock)];
|
||||
nif < EXT2_NINDIR(&sblock)) {
|
||||
aplim = &bp->b_un.b_indir[EXT2_NINDIR(&sblock)];
|
||||
for (ap = &bp->b_un.b_indir[nif]; ap < aplim; ap++) {
|
||||
if (*ap == 0)
|
||||
continue;
|
||||
@@ -412,7 +432,7 @@ getnextinode(ino_t inumber)
|
||||
(unsigned long long)inumber);
|
||||
if (inumber >= lastinum) {
|
||||
readcnt++;
|
||||
dblk = fsbtodb(&sblock, fsck_ino_to_fsba(&sblock, lastinum));
|
||||
dblk = EXT2_FSBTODB(&sblock, fsck_ino_to_fsba(&sblock, lastinum));
|
||||
if (readcnt % readpercg == 0) {
|
||||
size = partialsize;
|
||||
lastinum += partialcnt;
|
||||
@@ -437,7 +457,7 @@ resetinodebuf(void)
|
||||
nextino = 1;
|
||||
lastinum = 1;
|
||||
readcnt = 0;
|
||||
inobufsize = blkroundup(&sblock, INOBUFSIZE);
|
||||
inobufsize = ext2_blkroundup(&sblock, INOBUFSIZE);
|
||||
fullcnt = inobufsize / EXT2_DINODE_SIZE(&sblock);
|
||||
readpercg = sblock.e2fs.e2fs_ipg / fullcnt;
|
||||
partialcnt = sblock.e2fs.e2fs_ipg % fullcnt;
|
||||
@@ -479,8 +499,8 @@ cacheino(struct ext2fs_dinode *dp, ino_t inumber)
|
||||
unsigned int blks;
|
||||
|
||||
blks = howmany(inosize(dp), sblock.e2fs_bsize);
|
||||
if (blks > NDADDR)
|
||||
blks = NDADDR + NIADDR;
|
||||
if (blks > EXT2FS_NDADDR)
|
||||
blks = EXT2FS_NDADDR + EXT2FS_NIADDR;
|
||||
/* XXX ondisk32 */
|
||||
inp = malloc(sizeof(*inp) + (blks - 1) * sizeof(int32_t));
|
||||
if (inp == NULL)
|
||||
@@ -707,7 +727,7 @@ allocino(ino_t request, int type)
|
||||
dp->e2di_mtime = dp->e2di_ctime = dp->e2di_atime;
|
||||
dp->e2di_dtime = 0;
|
||||
inossize(dp, sblock.e2fs_bsize);
|
||||
dp->e2di_nblock = h2fs32(btodb(sblock.e2fs_bsize));
|
||||
inosnblock(dp, btodb(sblock.e2fs_bsize));
|
||||
n_files++;
|
||||
inodirty();
|
||||
typemap[ino] = E2IFTODT(type);
|
||||
@@ -734,3 +754,59 @@ freeino(ino_t ino)
|
||||
statemap[ino] = USTATE;
|
||||
n_files--;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
inonblock(struct ext2fs_dinode *dp)
|
||||
{
|
||||
uint64_t nblock;
|
||||
|
||||
/* XXX check for EXT2_HUGE_FILE without EXT2F_ROCOMPAT_HUGE_FILE? */
|
||||
|
||||
nblock = fs2h32(dp->e2di_nblock);
|
||||
|
||||
if ((sblock.e2fs.e2fs_features_rocompat & EXT2F_ROCOMPAT_HUGE_FILE)) {
|
||||
nblock |= (uint64_t)fs2h16(dp->e2di_nblock_high) << 32;
|
||||
if (fs2h32(dp->e2di_flags) & EXT2_HUGE_FILE) {
|
||||
nblock = EXT2_FSBTODB(&sblock, nblock);
|
||||
}
|
||||
}
|
||||
|
||||
return nblock;
|
||||
}
|
||||
|
||||
void
|
||||
inosnblock(struct ext2fs_dinode *dp, uint64_t nblock)
|
||||
{
|
||||
uint32_t flags;
|
||||
|
||||
flags = fs2h32(dp->e2di_flags);
|
||||
|
||||
if (nblock <= 0xffffffffULL) {
|
||||
flags &= ~EXT2_HUGE_FILE;
|
||||
dp->e2di_flags = h2fs32(flags);
|
||||
dp->e2di_nblock = h2fs32(nblock);
|
||||
return;
|
||||
}
|
||||
|
||||
sethuge();
|
||||
|
||||
if (nblock <= 0xffffffffffffULL) {
|
||||
flags &= ~EXT2_HUGE_FILE;
|
||||
dp->e2di_flags = h2fs32(flags);
|
||||
dp->e2di_nblock = h2fs32(nblock);
|
||||
dp->e2di_nblock_high = h2fs16((nblock >> 32));
|
||||
return;
|
||||
}
|
||||
|
||||
if (EXT2_DBTOFSB(&sblock, nblock) <= 0xffffffffffffULL) {
|
||||
flags |= EXT2_HUGE_FILE;
|
||||
dp->e2di_flags = h2fs32(flags);
|
||||
dp->e2di_nblock = h2fs32(EXT2_DBTOFSB(&sblock, nblock));
|
||||
dp->e2di_nblock_high = h2fs16((EXT2_DBTOFSB(&sblock, nblock) >> 32));
|
||||
return;
|
||||
}
|
||||
|
||||
pfatal("trying to set nblocks higher than representable");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -318,7 +318,7 @@ checkfilesys(const char *filesys, char *mntpt, long auxdata, int child)
|
||||
printf("\n***** FILE SYSTEM WAS MODIFIED *****\n");
|
||||
if (rerun)
|
||||
printf("\n***** PLEASE RERUN FSCK *****\n");
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
if (hotroot()) {
|
||||
struct statvfs stfs_buf;
|
||||
/*
|
||||
@@ -342,7 +342,7 @@ checkfilesys(const char *filesys, char *mntpt, long auxdata, int child)
|
||||
sync();
|
||||
return FSCK_EXIT_ROOT_CHANGED;
|
||||
}
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
return FSCK_EXIT_OK;
|
||||
}
|
||||
|
||||
|
||||
+18
-17
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pass1.c,v 1.21 2010/02/04 23:55:42 christos Exp $ */
|
||||
/* $NetBSD: pass1.c,v 1.24 2013/06/19 17:51:25 dholland Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1986, 1993
|
||||
@@ -58,7 +58,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)pass1.c 8.1 (Berkeley) 6/5/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: pass1.c,v 1.21 2010/02/04 23:55:42 christos Exp $");
|
||||
__RCSID("$NetBSD: pass1.c,v 1.24 2013/06/19 17:51:25 dholland Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@@ -170,7 +170,7 @@ checkinode(ino_t inumber, struct inodesc *idesc)
|
||||
if (mode == 0 || (dp->e2di_dtime != 0 && dp->e2di_nlink == 0)) {
|
||||
if (mode == 0 && (
|
||||
memcmp(dp->e2di_blocks, zino.e2di_blocks,
|
||||
(NDADDR + NIADDR) * sizeof(u_int32_t)) ||
|
||||
(EXT2FS_NDADDR + EXT2FS_NIADDR) * sizeof(u_int32_t)) ||
|
||||
dp->e2di_mode || inosize(dp))) {
|
||||
pfatal("PARTIALLY ALLOCATED INODE I=%llu",
|
||||
(unsigned long long)inumber);
|
||||
@@ -241,30 +241,30 @@ checkinode(ino_t inumber, struct inodesc *idesc)
|
||||
if (inosize(dp) < EXT2_MAXSYMLINKLEN ||
|
||||
(EXT2_MAXSYMLINKLEN == 0 && dp->e2di_blocks == 0)) {
|
||||
ndb = howmany(inosize(dp), sizeof(u_int32_t));
|
||||
if (ndb > NDADDR) {
|
||||
j = ndb - NDADDR;
|
||||
if (ndb > EXT2FS_NDADDR) {
|
||||
j = ndb - EXT2FS_NDADDR;
|
||||
for (ndb = 1; j > 1; j--)
|
||||
ndb *= NINDIR(&sblock);
|
||||
ndb += NDADDR;
|
||||
ndb *= EXT2_NINDIR(&sblock);
|
||||
ndb += EXT2FS_NDADDR;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Linux puts things in blocks for FIFO, so skip this check */
|
||||
if (mode != IFIFO) {
|
||||
for (j = ndb; j < NDADDR; j++)
|
||||
for (j = ndb; j < EXT2FS_NDADDR; j++)
|
||||
if (dp->e2di_blocks[j] != 0) {
|
||||
if (debug)
|
||||
printf("bad direct addr: %d\n",
|
||||
fs2h32(dp->e2di_blocks[j]));
|
||||
goto unknown;
|
||||
}
|
||||
for (j = 0, ndb -= NDADDR; ndb > 0; j++)
|
||||
ndb /= NINDIR(&sblock);
|
||||
for (; j < NIADDR; j++) {
|
||||
if (dp->e2di_blocks[j+NDADDR] != 0) {
|
||||
for (j = 0, ndb -= EXT2FS_NDADDR; ndb > 0; j++)
|
||||
ndb /= EXT2_NINDIR(&sblock);
|
||||
for (; j < EXT2FS_NIADDR; j++) {
|
||||
if (dp->e2di_blocks[j+EXT2FS_NDADDR] != 0) {
|
||||
if (debug)
|
||||
printf("bad indirect addr: %d\n",
|
||||
fs2h32(dp->e2di_blocks[j+NDADDR]));
|
||||
fs2h32(dp->e2di_blocks[j+EXT2FS_NDADDR]));
|
||||
goto unknown;
|
||||
}
|
||||
}
|
||||
@@ -302,16 +302,17 @@ checkinode(ino_t inumber, struct inodesc *idesc)
|
||||
idesc->id_number = inumber;
|
||||
(void)ckinode(dp, idesc);
|
||||
idesc->id_entryno *= btodb(sblock.e2fs_bsize);
|
||||
if (fs2h32(dp->e2di_nblock) != (uint32_t)idesc->id_entryno) {
|
||||
pwarn("INCORRECT BLOCK COUNT I=%llu (%d should be %d)",
|
||||
(unsigned long long)inumber, fs2h32(dp->e2di_nblock),
|
||||
if (inonblock(dp) != (uint32_t)idesc->id_entryno) {
|
||||
pwarn("INCORRECT BLOCK COUNT I=%llu (%llu should be %d)",
|
||||
(unsigned long long)inumber,
|
||||
(unsigned long long)inonblock(dp),
|
||||
idesc->id_entryno);
|
||||
if (preen)
|
||||
printf(" (CORRECTED)\n");
|
||||
else if (reply("CORRECT") == 0)
|
||||
return;
|
||||
dp = ginode(inumber);
|
||||
dp->e2di_nblock = h2fs32(idesc->id_entryno);
|
||||
inosnblock(dp, idesc->id_entryno);
|
||||
inodirty();
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pass5.c,v 1.19 2011/08/06 16:42:41 dholland Exp $ */
|
||||
/* $NetBSD: pass5.c,v 1.20 2012/08/26 09:33:18 dholland Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1986, 1993
|
||||
@@ -58,7 +58,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)pass5.c 8.6 (Berkeley) 11/30/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: pass5.c,v 1.19 2011/08/06 16:42:41 dholland Exp $");
|
||||
__RCSID("$NetBSD: pass5.c,v 1.20 2012/08/26 09:33:18 dholland Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@@ -69,7 +69,7 @@ __RCSID("$NetBSD: pass5.c,v 1.19 2011/08/06 16:42:41 dholland Exp $");
|
||||
#include <ufs/ext2fs/ext2fs.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "fsutil.h"
|
||||
|
||||
+14
-20
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: setup.c,v 1.28 2011/09/16 16:13:18 plunky Exp $ */
|
||||
/* $NetBSD: setup.c,v 1.31 2013/06/23 02:06:04 dholland Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1986, 1993
|
||||
@@ -58,7 +58,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)setup.c 8.5 (Berkeley) 11/23/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: setup.c,v 1.28 2011/09/16 16:13:18 plunky Exp $");
|
||||
__RCSID("$NetBSD: setup.c,v 1.31 2013/06/23 02:06:04 dholland Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@@ -94,11 +94,7 @@ setup(const char *dev)
|
||||
long cg, asked, i;
|
||||
long bmapsize;
|
||||
struct disklabel *lp;
|
||||
#ifndef __minix
|
||||
off_t sizepb;
|
||||
#else
|
||||
u64_t sizepb;
|
||||
#endif
|
||||
struct stat statb;
|
||||
struct m_ext2fs proto;
|
||||
int doskipclean;
|
||||
@@ -111,15 +107,13 @@ setup(const char *dev)
|
||||
printf("Can't stat %s: %s\n", dev, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
if (!S_ISCHR(statb.st_mode)) {
|
||||
pfatal("%s is not a character device", dev);
|
||||
if (reply("CONTINUE") == 0)
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !defined(__minix) */
|
||||
if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
|
||||
printf("Can't open %s: %s\n", dev, strerror(errno));
|
||||
return 0;
|
||||
@@ -155,7 +149,7 @@ setup(const char *dev)
|
||||
if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0)
|
||||
return 0;
|
||||
for (cg = 1; cg < proto.e2fs_ncg; cg++) {
|
||||
bflag = fsbtodb(&proto,
|
||||
bflag = EXT2_FSBTODB(&proto,
|
||||
cg * proto.e2fs.e2fs_bpg +
|
||||
proto.e2fs.e2fs_first_dblock);
|
||||
if (readsb(0) != 0)
|
||||
@@ -188,9 +182,9 @@ setup(const char *dev)
|
||||
maxfsblock = sblock.e2fs.e2fs_bcount;
|
||||
maxino = sblock.e2fs_ncg * sblock.e2fs.e2fs_ipg;
|
||||
sizepb = sblock.e2fs_bsize;
|
||||
maxfilesize = sblock.e2fs_bsize * NDADDR - 1;
|
||||
for (i = 0; i < NIADDR; i++) {
|
||||
sizepb *= NINDIR(&sblock);
|
||||
maxfilesize = sblock.e2fs_bsize * EXT2FS_NDADDR - 1;
|
||||
for (i = 0; i < EXT2FS_NIADDR; i++) {
|
||||
sizepb *= EXT2_NINDIR(&sblock);
|
||||
maxfilesize += sizepb;
|
||||
}
|
||||
/*
|
||||
@@ -228,7 +222,7 @@ setup(const char *dev)
|
||||
if (bread(fsreadfd,
|
||||
(char *)&sblock.e2fs_gd[i * sblock.e2fs_bsize /
|
||||
sizeof(struct ext2_gd)],
|
||||
fsbtodb(&sblock, ((sblock.e2fs_bsize > 1024) ? 0 : 1) +
|
||||
EXT2_FSBTODB(&sblock, ((sblock.e2fs_bsize > 1024) ? 0 : 1) +
|
||||
i + 1),
|
||||
sblock.e2fs_bsize) != 0 && !asked) {
|
||||
pfatal("BAD SUMMARY INFORMATION");
|
||||
@@ -343,7 +337,7 @@ readsb(int listerr)
|
||||
* so we can tell if this is an alternate later.
|
||||
*/
|
||||
super *= dev_bsize;
|
||||
dev_bsize = sblock.e2fs_bsize / fsbtodb(&sblock, 1);
|
||||
dev_bsize = sblock.e2fs_bsize / EXT2_FSBTODB(&sblock, 1);
|
||||
sblk.b_bno = super / dev_bsize;
|
||||
|
||||
if (sblock.e2fs_ncg == 1) {
|
||||
@@ -477,7 +471,7 @@ badsb(int listerr, const char *s)
|
||||
int
|
||||
calcsb(const char *dev, int devfd, struct m_ext2fs *fs)
|
||||
{
|
||||
#ifdef __minix
|
||||
#if defined(__minix)
|
||||
errexit("%s: calcsb: can't read disk label under minix", dev);
|
||||
#else
|
||||
struct disklabel *lp;
|
||||
@@ -518,7 +512,7 @@ calcsb(const char *dev, int devfd, struct m_ext2fs *fs)
|
||||
fs->e2fs_bsize / sizeof(struct ext2_gd));
|
||||
|
||||
return 1;
|
||||
#endif
|
||||
#endif /* defined(__minix) */
|
||||
}
|
||||
|
||||
static struct disklabel *
|
||||
@@ -526,7 +520,7 @@ getdisklabel(const char *s, int fd)
|
||||
{
|
||||
static struct disklabel lab;
|
||||
|
||||
#ifdef __minix
|
||||
#if defined(__minix)
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
errexit("%s: can't read disk label under minix", s);
|
||||
@@ -537,7 +531,7 @@ getdisklabel(const char *s, int fd)
|
||||
pwarn("ioctl (GCINFO): %s\n", strerror(errno));
|
||||
errexit("%s: can't read disk label", s);
|
||||
}
|
||||
#endif
|
||||
#endif /* defined(__minix) */
|
||||
return &lab;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: utilities.c,v 1.22 2011/06/09 19:57:51 christos Exp $ */
|
||||
/* $NetBSD: utilities.c,v 1.23 2013/06/23 02:06:04 dholland Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1986, 1993
|
||||
@@ -58,7 +58,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: utilities.c,v 1.22 2011/06/09 19:57:51 christos Exp $");
|
||||
__RCSID("$NetBSD: utilities.c,v 1.23 2013/06/23 02:06:04 dholland Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@@ -183,7 +183,7 @@ getdatablk(daddr_t blkno, long size)
|
||||
struct bufarea *bp;
|
||||
|
||||
for (bp = bufhead.b_next; bp != &bufhead; bp = bp->b_next)
|
||||
if (bp->b_bno == fsbtodb(&sblock, blkno))
|
||||
if (bp->b_bno == EXT2_FSBTODB(&sblock, blkno))
|
||||
goto foundit;
|
||||
for (bp = bufhead.b_prev; bp != &bufhead; bp = bp->b_prev)
|
||||
if ((bp->b_flags & B_INUSE) == 0)
|
||||
@@ -210,7 +210,7 @@ getblk(struct bufarea *bp, daddr_t blk, long size)
|
||||
{
|
||||
daddr_t dblk;
|
||||
|
||||
dblk = fsbtodb(&sblock, blk);
|
||||
dblk = EXT2_FSBTODB(&sblock, blk);
|
||||
if (bp->b_bno != dblk) {
|
||||
flush(fswritefd, bp);
|
||||
bp->b_errs = bread(fsreadfd, bp->b_un.b_buf, dblk, size);
|
||||
@@ -238,7 +238,7 @@ flush(int fd, struct bufarea *bp)
|
||||
for (i = 0; i < sblock.e2fs_ngdb; i++) {
|
||||
bwrite(fswritefd, (char *)
|
||||
&sblock.e2fs_gd[i* sblock.e2fs_bsize / sizeof(struct ext2_gd)],
|
||||
fsbtodb(&sblock, ((sblock.e2fs_bsize>1024)?0:1)+i+1),
|
||||
EXT2_FSBTODB(&sblock, ((sblock.e2fs_bsize>1024)?0:1)+i+1),
|
||||
sblock.e2fs_bsize);
|
||||
}
|
||||
}
|
||||
@@ -310,11 +310,7 @@ bread(int fd, char *buf, daddr_t blk, long size)
|
||||
{
|
||||
char *cp;
|
||||
int i, errs;
|
||||
#ifndef __minix
|
||||
off_t offset;
|
||||
#else
|
||||
u64_t offset;
|
||||
#endif
|
||||
|
||||
offset = blk;
|
||||
offset *= dev_bsize;
|
||||
@@ -350,11 +346,7 @@ bwrite(int fd, char *buf, daddr_t blk, long size)
|
||||
{
|
||||
int i;
|
||||
char *cp;
|
||||
#ifndef __minix
|
||||
off_t offset;
|
||||
#else
|
||||
u64_t offset;
|
||||
#endif
|
||||
|
||||
if (fd < 0)
|
||||
return;
|
||||
|
||||
+4
-2
@@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.38 2009/04/11 07:58:12 lukem Exp $
|
||||
# $NetBSD: Makefile,v 1.39 2013/07/15 00:18:03 khorben Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 7/19/93
|
||||
|
||||
PROG= init
|
||||
@@ -7,7 +7,9 @@ DPADD= ${LIBUTIL}
|
||||
LDADD= -lutil
|
||||
CPPFLAGS+= -DMFS_DEV_IF_NO_CONSOLE -DSUPPORT_UTMP -DSUPPORT_UTMPX
|
||||
|
||||
.ifdef SMALLPROG
|
||||
.ifdef INIT_CHROOT
|
||||
CPPFLAGS+= -DCHROOT
|
||||
.elifdef SMALLPROG
|
||||
CPPFLAGS+= -DLETS_GET_SMALL
|
||||
.else
|
||||
CPPFLAGS+= -DALTSHELL -DSECURE -DCHROOT
|
||||
|
||||
+23
-7
@@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: init.8,v 1.57 2009/05/18 14:17:31 wiz Exp $
|
||||
.\" $NetBSD: init.8,v 1.59 2013/10/02 22:07:56 apb Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@@ -32,7 +32,7 @@
|
||||
.\"
|
||||
.\" @(#)init.8 8.6 (Berkeley) 5/26/95
|
||||
.\"
|
||||
.Dd November 10, 2008
|
||||
.Dd October 2, 2013
|
||||
.Dt INIT 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
@@ -40,22 +40,38 @@
|
||||
.Nd process control initialization
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl s
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
program is the last stage of the boot process (after the kernel loads
|
||||
and initializes all the devices).
|
||||
program is the last stage of the boot process.
|
||||
It normally begins multi-user operation.
|
||||
.Pp
|
||||
.Nm
|
||||
is executed automatically by the kernel,
|
||||
after the kernel has initialised all devices
|
||||
and mounted the root file system.
|
||||
The kernel may try multiple possible paths for
|
||||
.Nm ,
|
||||
including
|
||||
.Pa /sbin/init ,
|
||||
.Pa /sbin/oinit ,
|
||||
.Pa /sbin/init.bak ,
|
||||
and
|
||||
.Pa /rescue/init .
|
||||
.Pp
|
||||
The following table describes the state machine used by
|
||||
.Nm :
|
||||
.Bl -enum
|
||||
.It
|
||||
Single user shell.
|
||||
.Nm
|
||||
may be passed
|
||||
If the kernel is booted in single user mode (see
|
||||
.Xr boothowto 9 ) ,
|
||||
then the kernel will pass the
|
||||
.Fl s
|
||||
from the boot program to prevent the system from going multi-user and
|
||||
option to
|
||||
.Nm
|
||||
to prevent the system from going multi-user and
|
||||
to instead execute a single user shell without starting the normal
|
||||
daemons.
|
||||
If the kernel is in a secure mode,
|
||||
|
||||
+33
-31
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: init.c,v 1.103 2012/03/20 18:50:31 matt Exp $ */
|
||||
/* $NetBSD: init.c,v 1.105 2012/11/09 06:27:17 msaitoh Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 1993\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)init.c 8.2 (Berkeley) 4/28/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: init.c,v 1.103 2012/03/20 18:50:31 matt Exp $");
|
||||
__RCSID("$NetBSD: init.c,v 1.105 2012/11/09 06:27:17 msaitoh Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@@ -68,6 +68,12 @@ __RCSID("$NetBSD: init.c,v 1.103 2012/03/20 18:50:31 matt Exp $");
|
||||
#include <util.h>
|
||||
#include <paths.h>
|
||||
#include <err.h>
|
||||
#ifdef SUPPORT_UTMP
|
||||
#include <utmp.h>
|
||||
#endif
|
||||
#ifdef SUPPORT_UTMPX
|
||||
#include <utmpx.h>
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
@@ -109,14 +115,12 @@ static void warning(const char *, ...) __printflike(1, 2);
|
||||
static void emergency(const char *, ...) __printflike(1, 2);
|
||||
__dead static void disaster(int);
|
||||
|
||||
#ifdef __minix
|
||||
#if defined(__minix)
|
||||
static void minixreboot(int);
|
||||
static void minixpowerdown(int);
|
||||
#endif
|
||||
|
||||
#ifndef __minix
|
||||
#else
|
||||
static void badsys(int);
|
||||
#endif
|
||||
#endif /* defined(__minix) */
|
||||
|
||||
/*
|
||||
* We really need a recursive typedef...
|
||||
@@ -255,10 +259,10 @@ main(int argc, char **argv)
|
||||
* Establish an initial user so that programs running
|
||||
* single user do not freak out and die (like passwd).
|
||||
*/
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
if (setlogin("root") < 0)
|
||||
warn("setlogin() failed");
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
|
||||
|
||||
#ifdef MFS_DEV_IF_NO_CONSOLE
|
||||
@@ -303,7 +307,7 @@ main(int argc, char **argv)
|
||||
* We catch or block signals rather than ignore them,
|
||||
* so that they get reset on exec.
|
||||
*/
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
handle(badsys, SIGSYS, 0);
|
||||
handle(disaster, SIGABRT, SIGFPE, SIGILL, SIGSEGV,
|
||||
SIGBUS, SIGXCPU, SIGXFSZ, 0);
|
||||
@@ -311,17 +315,17 @@ main(int argc, char **argv)
|
||||
handle(minixreboot, SIGABRT, 0);
|
||||
handle(minixpowerdown, SIGUSR1, 0);
|
||||
handle(disaster, SIGFPE, SIGILL, SIGSEGV, SIGBUS, 0);
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
handle(transition_handler, SIGHUP, SIGTERM, SIGTSTP, 0);
|
||||
handle(alrm_handler, SIGALRM, 0);
|
||||
(void)sigfillset(&mask);
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
delset(&mask, SIGABRT, SIGFPE, SIGILL, SIGSEGV, SIGBUS, SIGSYS,
|
||||
SIGXCPU, SIGXFSZ, SIGHUP, SIGTERM, SIGTSTP, SIGALRM, 0);
|
||||
#else
|
||||
delset(&mask, SIGABRT, SIGFPE, SIGILL, SIGSEGV, SIGBUS,
|
||||
SIGHUP, SIGTERM, SIGTSTP, SIGALRM, 0);
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
(void)sigprocmask(SIG_SETMASK, &mask, NULL);
|
||||
(void)sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
@@ -476,7 +480,7 @@ emergency(const char *message, ...)
|
||||
closelog();
|
||||
}
|
||||
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
/*
|
||||
* Catch a SIGSYS signal.
|
||||
*
|
||||
@@ -492,7 +496,7 @@ badsys(int sig)
|
||||
return;
|
||||
disaster(sig);
|
||||
}
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
|
||||
/*
|
||||
* Catch an unexpected signal.
|
||||
@@ -503,12 +507,10 @@ disaster(int sig)
|
||||
|
||||
emergency("fatal signal: %s", strsignal(sig));
|
||||
(void)sleep(STALL_TIMEOUT);
|
||||
|
||||
_exit(sig); /* reboot */
|
||||
}
|
||||
|
||||
#ifdef __minix
|
||||
|
||||
#if defined(__minix)
|
||||
/*
|
||||
* controlled reboot - minix tradition, SIGABRT by tty
|
||||
*/
|
||||
@@ -534,8 +536,7 @@ minixpowerdown(int sig)
|
||||
_exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* defined(__minix) */
|
||||
|
||||
/*
|
||||
* Check if securelevel is present.
|
||||
@@ -543,7 +544,7 @@ minixpowerdown(int sig)
|
||||
static int
|
||||
has_securelevel(void)
|
||||
{
|
||||
#ifdef __minix
|
||||
#if defined(__minix)
|
||||
return 0;
|
||||
#else
|
||||
#ifdef KERN_SECURELVL
|
||||
@@ -562,7 +563,7 @@ has_securelevel(void)
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
#endif
|
||||
#endif /* defined(__minix) */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -674,12 +675,12 @@ setctty(const char *name)
|
||||
{
|
||||
int fd;
|
||||
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
(void)revoke(name);
|
||||
#else
|
||||
if (setsid() < 0)
|
||||
warn("child setsid() failed");
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
(void)nanosleep(&dtrtime, NULL); /* leave DTR low for a bit */
|
||||
if ((fd = open(name, O_RDWR)) == -1) {
|
||||
stall("can't open %s: %m", name);
|
||||
@@ -1160,8 +1161,10 @@ new_session(session_t *sprev, int session_index, struct ttyent *typ)
|
||||
sp->se_index = session_index;
|
||||
|
||||
(void)asprintf(&sp->se_device, "%s%s", _PATH_DEV, typ->ty_name);
|
||||
if (!sp->se_device)
|
||||
if (!sp->se_device) {
|
||||
free(sp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (setupargv(sp, typ) == 0) {
|
||||
free_session(sp);
|
||||
@@ -1364,7 +1367,6 @@ start_getty(session_t *sp)
|
||||
(void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *) 0);
|
||||
|
||||
(void)execv(sp->se_getty_argv[0], sp->se_getty_argv);
|
||||
|
||||
stall("can't exec getty `%s' for port `%s': %m",
|
||||
sp->se_getty_argv[0], sp->se_device);
|
||||
_exit(8);
|
||||
@@ -1813,7 +1815,7 @@ do_setttyent(void)
|
||||
static int
|
||||
createsysctlnode(void)
|
||||
{
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
struct sysctlnode node;
|
||||
int mib[2];
|
||||
size_t len;
|
||||
@@ -1855,8 +1857,7 @@ createsysctlnode(void)
|
||||
warning("could not create init.root node: %m");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1864,7 +1865,7 @@ createsysctlnode(void)
|
||||
static int
|
||||
shouldchroot(void)
|
||||
{
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
struct sysctlnode node;
|
||||
size_t len, cnt;
|
||||
int mib;
|
||||
@@ -1901,10 +1902,11 @@ shouldchroot(void)
|
||||
|
||||
if (strcmp(rootdir, "/") == 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
}
|
||||
|
||||
#endif /* !LETS_GET_SMALL && CHROOT */
|
||||
|
||||
@@ -5,8 +5,4 @@ PROG= mknod
|
||||
SRCS= mknod.c pack_dev.c
|
||||
MAN= mknod.8
|
||||
|
||||
# LSC Does not compile without any warnings...
|
||||
NOGCCERROR:=yes
|
||||
NOCLANGERROR:=yes
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
+8
-8
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: mknod.c,v 1.40 2011/08/27 18:37:41 joerg Exp $ */
|
||||
/* $NetBSD: mknod.c,v 1.41 2013/06/14 16:28:20 tsutsui Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
|
||||
@@ -37,7 +37,7 @@
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1998\
|
||||
The NetBSD Foundation, Inc. All rights reserved.");
|
||||
__RCSID("$NetBSD: mknod.c,v 1.40 2011/08/27 18:37:41 joerg Exp $");
|
||||
__RCSID("$NetBSD: mknod.c,v 1.41 2013/06/14 16:28:20 tsutsui Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
@@ -61,7 +61,7 @@ __RCSID("$NetBSD: mknod.c,v 1.40 2011/08/27 18:37:41 joerg Exp $");
|
||||
#include "pack_dev.h"
|
||||
|
||||
static int gid_name(const char *, gid_t *);
|
||||
static portdev_t callPack(pack_t *, int, u_long *);
|
||||
static dev_t callPack(pack_t *, int, u_long *);
|
||||
|
||||
__dead static void usage(void);
|
||||
|
||||
@@ -81,7 +81,7 @@ main(int argc, char **argv)
|
||||
{
|
||||
char *name, *p;
|
||||
mode_t mode;
|
||||
portdev_t dev;
|
||||
dev_t dev;
|
||||
pack_t *pack;
|
||||
u_long numbers[MAXARGS];
|
||||
int n, ch, fifo, hasformat;
|
||||
@@ -317,10 +317,10 @@ gid_name(const char *name, gid_t *gid)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static portdev_t
|
||||
static dev_t
|
||||
callPack(pack_t *f, int n, u_long *numbers)
|
||||
{
|
||||
portdev_t d;
|
||||
dev_t d;
|
||||
const char *error = NULL;
|
||||
|
||||
d = (*f)(n, numbers, &error);
|
||||
@@ -333,7 +333,7 @@ callPack(pack_t *f, int n, u_long *numbers)
|
||||
static void
|
||||
get_device_info(void)
|
||||
{
|
||||
#ifdef __minix
|
||||
#if defined(__minix)
|
||||
err(1, "no kern.drivers on minix" );
|
||||
#else
|
||||
static int mib[2] = {CTL_KERN, KERN_DRIVERS};
|
||||
@@ -348,7 +348,7 @@ get_device_info(void)
|
||||
err(1, "kern.drivers" );
|
||||
|
||||
num_drivers = len / sizeof *kern_drivers;
|
||||
#endif
|
||||
#endif /* defined(__minix) */
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
+24
-24
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pack_dev.c,v 1.11 2011/08/27 18:37:41 joerg Exp $ */
|
||||
/* $NetBSD: pack_dev.c,v 1.12 2013/06/14 16:28:20 tsutsui Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint)
|
||||
__RCSID("$NetBSD: pack_dev.c,v 1.11 2011/08/27 18:37:41 joerg Exp $");
|
||||
__RCSID("$NetBSD: pack_dev.c,v 1.12 2013/06/14 16:28:20 tsutsui Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
@@ -63,10 +63,10 @@ static const char iMinorError[] = "invalid minor number";
|
||||
static const char tooManyFields[] = "too many fields for format";
|
||||
|
||||
/* exported */
|
||||
portdev_t
|
||||
dev_t
|
||||
pack_native(int n, u_long numbers[], const char **error)
|
||||
{
|
||||
portdev_t dev = 0;
|
||||
dev_t dev = 0;
|
||||
|
||||
if (n == 2) {
|
||||
dev = makedev(numbers[0], numbers[1]);
|
||||
@@ -80,10 +80,10 @@ pack_native(int n, u_long numbers[], const char **error)
|
||||
}
|
||||
|
||||
|
||||
static portdev_t
|
||||
static dev_t
|
||||
pack_netbsd(int n, u_long numbers[], const char **error)
|
||||
{
|
||||
portdev_t dev = 0;
|
||||
dev_t dev = 0;
|
||||
|
||||
if (n == 2) {
|
||||
dev = makedev_netbsd(numbers[0], numbers[1]);
|
||||
@@ -99,13 +99,13 @@ pack_netbsd(int n, u_long numbers[], const char **error)
|
||||
|
||||
#define major_freebsd(x) ((int32_t)(((x) & 0x0000ff00) >> 8))
|
||||
#define minor_freebsd(x) ((int32_t)(((x) & 0xffff00ff) >> 0))
|
||||
#define makedev_freebsd(x,y) ((portdev_t)((((x) << 8) & 0x0000ff00) | \
|
||||
#define makedev_freebsd(x,y) ((dev_t)((((x) << 8) & 0x0000ff00) | \
|
||||
(((y) << 0) & 0xffff00ff)))
|
||||
|
||||
static portdev_t
|
||||
static dev_t
|
||||
pack_freebsd(int n, u_long numbers[], const char **error)
|
||||
{
|
||||
portdev_t dev = 0;
|
||||
dev_t dev = 0;
|
||||
|
||||
if (n == 2) {
|
||||
dev = makedev_freebsd(numbers[0], numbers[1]);
|
||||
@@ -121,13 +121,13 @@ pack_freebsd(int n, u_long numbers[], const char **error)
|
||||
|
||||
#define major_8_8(x) ((int32_t)(((x) & 0x0000ff00) >> 8))
|
||||
#define minor_8_8(x) ((int32_t)(((x) & 0x000000ff) >> 0))
|
||||
#define makedev_8_8(x,y) ((portdev_t)((((x) << 8) & 0x0000ff00) | \
|
||||
#define makedev_8_8(x,y) ((dev_t)((((x) << 8) & 0x0000ff00) | \
|
||||
(((y) << 0) & 0x000000ff)))
|
||||
|
||||
static portdev_t
|
||||
static dev_t
|
||||
pack_8_8(int n, u_long numbers[], const char **error)
|
||||
{
|
||||
portdev_t dev = 0;
|
||||
dev_t dev = 0;
|
||||
|
||||
if (n == 2) {
|
||||
dev = makedev_8_8(numbers[0], numbers[1]);
|
||||
@@ -143,13 +143,13 @@ pack_8_8(int n, u_long numbers[], const char **error)
|
||||
|
||||
#define major_12_20(x) ((int32_t)(((x) & 0xfff00000) >> 20))
|
||||
#define minor_12_20(x) ((int32_t)(((x) & 0x000fffff) >> 0))
|
||||
#define makedev_12_20(x,y) ((portdev_t)((((x) << 20) & 0xfff00000) | \
|
||||
#define makedev_12_20(x,y) ((dev_t)((((x) << 20) & 0xfff00000) | \
|
||||
(((y) << 0) & 0x000fffff)))
|
||||
|
||||
static portdev_t
|
||||
static dev_t
|
||||
pack_12_20(int n, u_long numbers[], const char **error)
|
||||
{
|
||||
portdev_t dev = 0;
|
||||
dev_t dev = 0;
|
||||
|
||||
if (n == 2) {
|
||||
dev = makedev_12_20(numbers[0], numbers[1]);
|
||||
@@ -165,13 +165,13 @@ pack_12_20(int n, u_long numbers[], const char **error)
|
||||
|
||||
#define major_14_18(x) ((int32_t)(((x) & 0xfffc0000) >> 18))
|
||||
#define minor_14_18(x) ((int32_t)(((x) & 0x0003ffff) >> 0))
|
||||
#define makedev_14_18(x,y) ((portdev_t)((((x) << 18) & 0xfffc0000) | \
|
||||
#define makedev_14_18(x,y) ((dev_t)((((x) << 18) & 0xfffc0000) | \
|
||||
(((y) << 0) & 0x0003ffff)))
|
||||
|
||||
static portdev_t
|
||||
static dev_t
|
||||
pack_14_18(int n, u_long numbers[], const char **error)
|
||||
{
|
||||
portdev_t dev = 0;
|
||||
dev_t dev = 0;
|
||||
|
||||
if (n == 2) {
|
||||
dev = makedev_14_18(numbers[0], numbers[1]);
|
||||
@@ -187,13 +187,13 @@ pack_14_18(int n, u_long numbers[], const char **error)
|
||||
|
||||
#define major_8_24(x) ((int32_t)(((x) & 0xff000000) >> 24))
|
||||
#define minor_8_24(x) ((int32_t)(((x) & 0x00ffffff) >> 0))
|
||||
#define makedev_8_24(x,y) ((portdev_t)((((x) << 24) & 0xff000000) | \
|
||||
#define makedev_8_24(x,y) ((dev_t)((((x) << 24) & 0xff000000) | \
|
||||
(((y) << 0) & 0x00ffffff)))
|
||||
|
||||
static portdev_t
|
||||
static dev_t
|
||||
pack_8_24(int n, u_long numbers[], const char **error)
|
||||
{
|
||||
portdev_t dev = 0;
|
||||
dev_t dev = 0;
|
||||
|
||||
if (n == 2) {
|
||||
dev = makedev_8_24(numbers[0], numbers[1]);
|
||||
@@ -210,14 +210,14 @@ pack_8_24(int n, u_long numbers[], const char **error)
|
||||
#define major_12_12_8(x) ((int32_t)(((x) & 0xfff00000) >> 20))
|
||||
#define unit_12_12_8(x) ((int32_t)(((x) & 0x000fff00) >> 8))
|
||||
#define subunit_12_12_8(x) ((int32_t)(((x) & 0x000000ff) >> 0))
|
||||
#define makedev_12_12_8(x,y,z) ((portdev_t)((((x) << 20) & 0xfff00000) | \
|
||||
#define makedev_12_12_8(x,y,z) ((dev_t)((((x) << 20) & 0xfff00000) | \
|
||||
(((y) << 8) & 0x000fff00) | \
|
||||
(((z) << 0) & 0x000000ff)))
|
||||
|
||||
static portdev_t
|
||||
static dev_t
|
||||
pack_bsdos(int n, u_long numbers[], const char **error)
|
||||
{
|
||||
portdev_t dev = 0;
|
||||
dev_t dev = 0;
|
||||
|
||||
if (n == 2) {
|
||||
dev = makedev_12_20(numbers[0], numbers[1]);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pack_dev.h,v 1.7 2008/04/28 20:23:09 martin Exp $ */
|
||||
/* $NetBSD: pack_dev.h,v 1.8 2013/06/14 16:28:20 tsutsui Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
|
||||
@@ -32,12 +32,7 @@
|
||||
#ifndef _PACK_DEV_H
|
||||
#define _PACK_DEV_H
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
typedef __dev32_t portdev_t;
|
||||
#else
|
||||
typedef dev_t portdev_t;
|
||||
#endif
|
||||
typedef portdev_t pack_t(int, u_long [], const char **);
|
||||
typedef dev_t pack_t(int, u_long [], const char **);
|
||||
|
||||
pack_t *pack_find(const char *);
|
||||
pack_t pack_native;
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
# $NetBSD: Makefile,v 1.4 2012/03/24 08:22:24 joerg Exp $
|
||||
# $NetBSD: Makefile,v 1.6 2013/11/09 21:39:27 christos Exp $
|
||||
# @(#)Makefile 8.2 (Berkeley) 3/27/94
|
||||
|
||||
.if defined(__MINIX)
|
||||
WARNS=3
|
||||
.endif
|
||||
|
||||
WARNS?= 4
|
||||
|
||||
CWARNFLAGS+= -Wno-sign-compare
|
||||
|
||||
.include <bsd.own.mk>
|
||||
@@ -24,10 +18,10 @@ LDADD+= -lutil
|
||||
LDADD+=-lprop
|
||||
DPADD+=${LIBPROP}
|
||||
|
||||
SYMLINKS+= $(BINDIR)/$(PROG) $(BINDIR)/newfs_ext2 \
|
||||
$(BINDIR)/$(PROG) $(BINDIR)/mkfs.ext2
|
||||
.PATH: ${NETBSDSRCDIR}/sys/ufs/ext2fs ${FSCK}
|
||||
|
||||
#.PATH: ${NETBSDSRCDIR}/sys/ufs/ext2fs ${FSCK}
|
||||
.PATH: ${NETBSDSRCDIR}/sbin/fsck_ext2fs ${FSCK}
|
||||
.if ${MACHINE_ARCH} == "vax"
|
||||
COPTS.mke2fs.c=-O0
|
||||
.endif
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
+84
-77
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: mke2fs.c,v 1.14 2010/09/10 15:51:20 tsutsui Exp $ */
|
||||
/* $NetBSD: mke2fs.c,v 1.21 2013/10/19 13:42:10 tsutsui Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2007 Izumi Tsutsui. All rights reserved.
|
||||
@@ -100,7 +100,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: mke2fs.c,v 1.14 2010/09/10 15:51:20 tsutsui Exp $");
|
||||
__RCSID("$NetBSD: mke2fs.c,v 1.21 2013/10/19 13:42:10 tsutsui Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@@ -114,20 +114,17 @@ __RCSID("$NetBSD: mke2fs.c,v 1.14 2010/09/10 15:51:20 tsutsui Exp $");
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <lib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <uuid.h>
|
||||
#include <assert.h>
|
||||
#include <sys/termios.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
static void initcg(uint);
|
||||
static void zap_old_sblock(daddr_t);
|
||||
static void zap_old_sblock(int);
|
||||
static uint cgoverhead(uint);
|
||||
static int fsinit(const struct timeval *);
|
||||
static int makedir(struct ext2fs_direct *, int);
|
||||
@@ -180,7 +177,7 @@ static int iobufsize;
|
||||
|
||||
static uint8_t buf[MAXBSIZE]; /* for initcg() and makedir() ops */
|
||||
|
||||
static int fsi = -1, fso = -1;
|
||||
static int fsi, fso;
|
||||
|
||||
void
|
||||
mke2fs(const char *fsys, int fi, int fo)
|
||||
@@ -266,7 +263,7 @@ mke2fs(const char *fsys, int fi, int fo)
|
||||
* bsize is a power of two (i.e. 2048 bytes or more).
|
||||
*/
|
||||
sblock.e2fs.e2fs_first_dblock = (sblock.e2fs_bsize > BBSIZE) ? 0 : 1;
|
||||
minfssize = fsbtodb(&sblock,
|
||||
minfssize = EXT2_FSBTODB(&sblock,
|
||||
sblock.e2fs.e2fs_first_dblock +
|
||||
NBLOCK_SUPERBLOCK +
|
||||
1 /* at least one group descriptor */ +
|
||||
@@ -281,7 +278,7 @@ mke2fs(const char *fsys, int fi, int fo)
|
||||
errx(EXIT_FAILURE, "Filesystem size %" PRId64
|
||||
" < minimum size of %" PRId64 "\n", fssize, minfssize);
|
||||
|
||||
bcount = dbtofsb(&sblock, fssize);
|
||||
bcount = EXT2_DBTOFSB(&sblock, fssize);
|
||||
|
||||
/*
|
||||
* While many people claim that ext2fs is a (bad) clone of ufs/ffs,
|
||||
@@ -450,7 +447,7 @@ mke2fs(const char *fsys, int fi, int fo)
|
||||
* Reserved group descriptor blocks are preserved as
|
||||
* the second level double indirect reference blocks in
|
||||
* the EXT2_RESIZEINO inode, so the maximum number of
|
||||
* the blocks is NINDIR(fs).
|
||||
* the blocks is EXT2_NINDIR(fs).
|
||||
* (see also descriptions in init_resizeino() function)
|
||||
*
|
||||
* We check a number including current e2fs_ngdb here
|
||||
@@ -458,8 +455,8 @@ mke2fs(const char *fsys, int fi, int fo)
|
||||
* possible future size shrink, though e2fsprogs don't
|
||||
* seem to care about it.
|
||||
*/
|
||||
if (target_ngdb > NINDIR(&sblock))
|
||||
target_ngdb = NINDIR(&sblock);
|
||||
if (target_ngdb > EXT2_NINDIR(&sblock))
|
||||
target_ngdb = EXT2_NINDIR(&sblock);
|
||||
|
||||
reserved_ngdb = target_ngdb - sblock.e2fs_ngdb;
|
||||
|
||||
@@ -555,7 +552,7 @@ mke2fs(const char *fsys, int fi, int fo)
|
||||
|
||||
if (!Nflag) {
|
||||
static const uint pbsize[] = { 1024, 2048, 4096, 0 };
|
||||
uint pblock, epblock;
|
||||
uint pblock;
|
||||
/*
|
||||
* Validate the given file system size.
|
||||
* Verify that its last block can actually be accessed.
|
||||
@@ -569,19 +566,23 @@ mke2fs(const char *fsys, int fi, int fo)
|
||||
/*
|
||||
* Ensure there is nothing that looks like a filesystem
|
||||
* superblock anywhere other than where ours will be.
|
||||
* If fsck_ext2fs finds the wrong one all hell breaks loose!
|
||||
*
|
||||
* XXX: needs to check how fsck_ext2fs programs even
|
||||
* on other OSes determine alternate superblocks
|
||||
* Ext2fs superblock is always placed at the same SBOFF,
|
||||
* so we just zap possible first backups.
|
||||
*/
|
||||
for (i = 0; pbsize[i] != 0; i++) {
|
||||
epblock = (uint64_t)bcount * bsize / pbsize[i];
|
||||
for (pblock = ((pbsize[i] == SBSIZE) ? 1 : 0);
|
||||
pblock < epblock;
|
||||
pblock += pbsize[i] * NBBY /* bpg */)
|
||||
zap_old_sblock((daddr_t)pblock *
|
||||
pbsize[i] / sectorsize);
|
||||
pblock = (pbsize[i] > BBSIZE) ? 0 : 1; /* 1st dblk */
|
||||
pblock += pbsize[i] * NBBY; /* next bg */
|
||||
/* zap first backup */
|
||||
zap_old_sblock(pblock * pbsize[i]);
|
||||
}
|
||||
/*
|
||||
* Also zap possbile FFS magic leftover to prevent
|
||||
* kernel vfs_mountroot() and bootloadres from mis-recognizing
|
||||
* this file system as FFS.
|
||||
*/
|
||||
zap_old_sblock(8192); /* SBLOCK_UFS1 */
|
||||
zap_old_sblock(65536); /* SBLOCK_UFS2 */
|
||||
}
|
||||
|
||||
if (verbosity >= 3)
|
||||
@@ -625,7 +626,7 @@ mke2fs(const char *fsys, int fi, int fo)
|
||||
continue;
|
||||
}
|
||||
/* Print superblock numbers */
|
||||
len = printf(" %*" PRIu64 "," + !col, fld_width,
|
||||
len = printf("%s%*" PRIu64 ",", (col ? " " : ""), fld_width,
|
||||
(uint64_t)cgbase(&sblock, cylno));
|
||||
col += len;
|
||||
if (col + len < max_cols)
|
||||
@@ -673,7 +674,7 @@ mke2fs(const char *fsys, int fi, int fo)
|
||||
e2fs_sbsave(&sblock.e2fs, (struct ext2fs *)(iobuf + sboff));
|
||||
e2fs_cgsave(gd, (struct ext2_gd *)(iobuf + sblock.e2fs_bsize),
|
||||
sizeof(struct ext2_gd) * sblock.e2fs_ncg);
|
||||
wtfs(fsbtodb(&sblock, cgbase(&sblock, 0)) + sboff / sectorsize,
|
||||
wtfs(EXT2_FSBTODB(&sblock, cgbase(&sblock, 0)) + sboff / sectorsize,
|
||||
iobufsize - sboff, iobuf + sboff);
|
||||
|
||||
munmap(iobuf, iobufsize);
|
||||
@@ -706,7 +707,7 @@ initcg(uint cylno)
|
||||
sblock.e2fs_bsize * NBLOCK_SUPERBLOCK),
|
||||
sizeof(struct ext2_gd) * sblock.e2fs_ncg);
|
||||
/* write superblock and group descriptor backups */
|
||||
wtfs(fsbtodb(&sblock, cgbase(&sblock, cylno)) +
|
||||
wtfs(EXT2_FSBTODB(&sblock, cgbase(&sblock, cylno)) +
|
||||
sboff / sectorsize, iobufsize - sboff, iobuf + sboff);
|
||||
}
|
||||
|
||||
@@ -728,8 +729,8 @@ initcg(uint cylno)
|
||||
i = i * NBBY;
|
||||
for (; i < cgoverhead(cylno); i++)
|
||||
setbit(buf, i);
|
||||
wtfs(fsbtodb(&sblock, gd[cylno].ext2bgd_b_bitmap), sblock.e2fs_bsize,
|
||||
buf);
|
||||
wtfs(EXT2_FSBTODB(&sblock, gd[cylno].ext2bgd_b_bitmap),
|
||||
sblock.e2fs_bsize, buf);
|
||||
|
||||
/*
|
||||
* Initialize inode bitmap.
|
||||
@@ -738,18 +739,16 @@ initcg(uint cylno)
|
||||
* it's a multiple of e2fs_ipb (as we did above).
|
||||
* Note even (possibly smaller) the last group has the same e2fs_ipg.
|
||||
*/
|
||||
assert(!(sblock.e2fs.e2fs_ipg % NBBY));
|
||||
i = sblock.e2fs.e2fs_ipg / NBBY;
|
||||
memset(buf, 0, i);
|
||||
assert(sblock.e2fs_bsize >= i);
|
||||
memset(buf + i, ~0U, sblock.e2fs_bsize - i);
|
||||
if (cylno == 0) {
|
||||
/* mark reserved inodes */
|
||||
for (i = 1; i < EXT2_FIRSTINO; i++)
|
||||
setbit(buf, EXT2_INO_INDEX(i));
|
||||
}
|
||||
wtfs(fsbtodb(&sblock, gd[cylno].ext2bgd_i_bitmap), sblock.e2fs_bsize,
|
||||
buf);
|
||||
wtfs(EXT2_FSBTODB(&sblock, gd[cylno].ext2bgd_i_bitmap),
|
||||
sblock.e2fs_bsize, buf);
|
||||
|
||||
/*
|
||||
* Initialize inode tables.
|
||||
@@ -765,7 +764,7 @@ initcg(uint cylno)
|
||||
/* h2fs32() just for consistency */
|
||||
dp->e2di_gen = h2fs32(arc4random());
|
||||
}
|
||||
wtfs(fsbtodb(&sblock, gd[cylno].ext2bgd_i_tables + i),
|
||||
wtfs(EXT2_FSBTODB(&sblock, gd[cylno].ext2bgd_i_tables + i),
|
||||
sblock.e2fs_bsize, buf);
|
||||
}
|
||||
}
|
||||
@@ -774,9 +773,9 @@ initcg(uint cylno)
|
||||
* Zap possible lingering old superblock data
|
||||
*/
|
||||
static void
|
||||
zap_old_sblock(daddr_t sec)
|
||||
zap_old_sblock(int sblkoff)
|
||||
{
|
||||
static daddr_t cg0_data;
|
||||
static int cg0_data;
|
||||
uint32_t oldfs[SBSIZE / sizeof(uint32_t)];
|
||||
static const struct fsm {
|
||||
uint32_t offset;
|
||||
@@ -798,24 +797,25 @@ zap_old_sblock(daddr_t sec)
|
||||
return;
|
||||
|
||||
/* don't override data before superblock */
|
||||
if (sec < SBOFF / sectorsize)
|
||||
if (sblkoff < SBOFF)
|
||||
return;
|
||||
|
||||
if (cg0_data == 0) {
|
||||
cg0_data =
|
||||
((daddr_t)sblock.e2fs.e2fs_first_dblock + cgoverhead(0)) *
|
||||
sblock.e2fs_bsize / sectorsize;
|
||||
sblock.e2fs_bsize;
|
||||
}
|
||||
|
||||
/* Ignore anything that is beyond our filesystem */
|
||||
if (sec >= fssize)
|
||||
if (sblkoff / sectorsize >= fssize)
|
||||
return;
|
||||
/* Zero anything inside our filesystem... */
|
||||
if (sec >= sblock.e2fs.e2fs_first_dblock * bsize / sectorsize) {
|
||||
if (sblkoff >= sblock.e2fs.e2fs_first_dblock * bsize) {
|
||||
/* ...unless we will write that area anyway */
|
||||
if (sec >= cg0_data)
|
||||
if (sblkoff >= cg0_data)
|
||||
/* assume iobuf is zero'ed here */
|
||||
wtfs(sec, roundup(SBSIZE, sectorsize), iobuf);
|
||||
wtfs(sblkoff / sectorsize,
|
||||
roundup(SBSIZE, sectorsize), iobuf);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -825,7 +825,7 @@ zap_old_sblock(daddr_t sec)
|
||||
* XXX: ext2fs won't preserve data after SBOFF,
|
||||
* but first_dblock could have a different value.
|
||||
*/
|
||||
rdfs(sec, sizeof(oldfs), &oldfs);
|
||||
rdfs(sblkoff / sectorsize, sizeof(oldfs), &oldfs);
|
||||
for (fsm = fs_magics;; fsm++) {
|
||||
uint32_t v;
|
||||
if (fsm->mask == 0)
|
||||
@@ -838,7 +838,7 @@ zap_old_sblock(daddr_t sec)
|
||||
|
||||
/* Just zap the magic number */
|
||||
oldfs[fsm->offset] = 0;
|
||||
wtfs(sec, sizeof(oldfs), &oldfs);
|
||||
wtfs(sblkoff / sectorsize, sizeof(oldfs), &oldfs);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -932,8 +932,8 @@ fsinit(const struct timeval *tv)
|
||||
/* prepare a bit large directory for preserved files */
|
||||
nblks_lostfound = EXT2_LOSTFOUNDSIZE / sblock.e2fs_bsize;
|
||||
/* ...but only with direct blocks */
|
||||
if (nblks_lostfound > NDADDR)
|
||||
nblks_lostfound = NDADDR;
|
||||
if (nblks_lostfound > EXT2FS_NDADDR)
|
||||
nblks_lostfound = EXT2FS_NDADDR;
|
||||
|
||||
memset(&node, 0, sizeof(node));
|
||||
node.e2di_mode = EXT2_IFDIR | EXT2_LOSTFOUNDUMASK;
|
||||
@@ -945,7 +945,7 @@ fsinit(const struct timeval *tv)
|
||||
node.e2di_gid = getegid();
|
||||
node.e2di_nlink = PREDEFDIR;
|
||||
/* e2di_nblock is a number of disk blocks, not ext2fs blocks */
|
||||
node.e2di_nblock = fsbtodb(&sblock, nblks_lostfound);
|
||||
node.e2di_nblock = EXT2_FSBTODB(&sblock, nblks_lostfound);
|
||||
node.e2di_blocks[0] = alloc(sblock.e2fs_bsize, node.e2di_mode);
|
||||
if (node.e2di_blocks[0] == 0) {
|
||||
printf("%s: can't allocate block for lost+found\n", __func__);
|
||||
@@ -960,13 +960,14 @@ fsinit(const struct timeval *tv)
|
||||
}
|
||||
node.e2di_blocks[i] = blk;
|
||||
}
|
||||
wtfs(fsbtodb(&sblock, node.e2di_blocks[0]), sblock.e2fs_bsize, buf);
|
||||
wtfs(EXT2_FSBTODB(&sblock, node.e2di_blocks[0]),
|
||||
sblock.e2fs_bsize, buf);
|
||||
pad_dir.e2d_reclen = sblock.e2fs_bsize;
|
||||
for (i = 1; i < nblks_lostfound; i++) {
|
||||
memset(buf, 0, sblock.e2fs_bsize);
|
||||
copy_dir(&pad_dir, (struct ext2fs_direct *)buf);
|
||||
wtfs(fsbtodb(&sblock, node.e2di_blocks[i]), sblock.e2fs_bsize,
|
||||
buf);
|
||||
wtfs(EXT2_FSBTODB(&sblock, node.e2di_blocks[i]),
|
||||
sblock.e2fs_bsize, buf);
|
||||
}
|
||||
iput(&node, EXT2_LOSTFOUNDINO);
|
||||
#endif
|
||||
@@ -991,13 +992,14 @@ fsinit(const struct timeval *tv)
|
||||
node.e2di_gid = getegid();
|
||||
node.e2di_nlink = PREDEFROOTDIR;
|
||||
/* e2di_nblock is a number of disk block, not ext2fs block */
|
||||
node.e2di_nblock = fsbtodb(&sblock, 1);
|
||||
node.e2di_nblock = EXT2_FSBTODB(&sblock, 1);
|
||||
node.e2di_blocks[0] = alloc(node.e2di_size, node.e2di_mode);
|
||||
if (node.e2di_blocks[0] == 0) {
|
||||
printf("%s: can't allocate block for root dir\n", __func__);
|
||||
return 0;
|
||||
}
|
||||
wtfs(fsbtodb(&sblock, node.e2di_blocks[0]), sblock.e2fs_bsize, buf);
|
||||
wtfs(EXT2_FSBTODB(&sblock, node.e2di_blocks[0]),
|
||||
sblock.e2fs_bsize, buf);
|
||||
iput(&node, EXT2_ROOTINO);
|
||||
return 1;
|
||||
}
|
||||
@@ -1119,9 +1121,10 @@ init_resizeino(const struct timeval *tv)
|
||||
*/
|
||||
|
||||
/* set e2di_size which occupies whole blocks through DINDIR blocks */
|
||||
isize = (uint64_t)sblock.e2fs_bsize * NDADDR +
|
||||
(uint64_t)sblock.e2fs_bsize * NINDIR(&sblock) +
|
||||
(uint64_t)sblock.e2fs_bsize * NINDIR(&sblock) * NINDIR(&sblock);
|
||||
isize = (uint64_t)sblock.e2fs_bsize * EXT2FS_NDADDR +
|
||||
(uint64_t)sblock.e2fs_bsize * EXT2_NINDIR(&sblock) +
|
||||
(uint64_t)sblock.e2fs_bsize * EXT2_NINDIR(&sblock) *
|
||||
EXT2_NINDIR(&sblock);
|
||||
if (isize > UINT32_MAX &&
|
||||
(sblock.e2fs.e2fs_features_rocompat &
|
||||
EXT2F_ROCOMPAT_LARGEFILE) == 0) {
|
||||
@@ -1139,21 +1142,21 @@ init_resizeino(const struct timeval *tv)
|
||||
#define TRIPLE 2 /* index of triple indirect block */
|
||||
|
||||
/* zero out entries for direct references */
|
||||
for (i = 0; i < NDADDR; i++)
|
||||
for (i = 0; i < EXT2FS_NDADDR; i++)
|
||||
node.e2di_blocks[i] = 0;
|
||||
/* also zero out entries for single and triple indirect references */
|
||||
node.e2di_blocks[NDADDR + SINGLE] = 0;
|
||||
node.e2di_blocks[NDADDR + TRIPLE] = 0;
|
||||
node.e2di_blocks[EXT2FS_NDADDR + SINGLE] = 0;
|
||||
node.e2di_blocks[EXT2FS_NDADDR + TRIPLE] = 0;
|
||||
|
||||
/* allocate a block for the first level double indirect reference */
|
||||
node.e2di_blocks[NDADDR + DOUBLE] =
|
||||
node.e2di_blocks[EXT2FS_NDADDR + DOUBLE] =
|
||||
alloc(sblock.e2fs_bsize, node.e2di_mode);
|
||||
if (node.e2di_blocks[NDADDR + DOUBLE] == 0)
|
||||
if (node.e2di_blocks[EXT2FS_NDADDR + DOUBLE] == 0)
|
||||
errx(EXIT_FAILURE, "%s: Can't allocate a dindirect block",
|
||||
__func__);
|
||||
|
||||
/* account this first block */
|
||||
nblock = fsbtodb(&sblock, 1);
|
||||
nblock = EXT2_FSBTODB(&sblock, 1);
|
||||
|
||||
/* allocate buffer to set data in the dindirect block */
|
||||
dindir_block = malloc(sblock.e2fs_bsize);
|
||||
@@ -1181,12 +1184,12 @@ init_resizeino(const struct timeval *tv)
|
||||
* point reserved group descriptor block in the first
|
||||
* (i.e. master) block group
|
||||
*
|
||||
* XXX: e2fsprogs seem to use "(i % NINDIR(&sblock))" here
|
||||
* to store maximum NINDIR(&sblock) reserved gdbs.
|
||||
* XXX: e2fsprogs seem to use "(i % EXT2_NINDIR(&sblock))" here
|
||||
* to store maximum EXT2_NINDIR(&sblock) reserved gdbs.
|
||||
* I'm not sure what will be done on future filesystem
|
||||
* shrink in that case on their way.
|
||||
*/
|
||||
if (i >= NINDIR(&sblock))
|
||||
if (i >= EXT2_NINDIR(&sblock))
|
||||
errx(EXIT_FAILURE, "%s: too many reserved "
|
||||
"group descriptors (%u) for resize inode",
|
||||
__func__, sblock.e2fs.e2fs_reserved_ngdb);
|
||||
@@ -1205,7 +1208,7 @@ init_resizeino(const struct timeval *tv)
|
||||
cg_has_sb(cylno) == 0)
|
||||
continue;
|
||||
|
||||
if (n >= NINDIR(&sblock))
|
||||
if (n >= EXT2_NINDIR(&sblock))
|
||||
errx(EXIT_FAILURE, "%s: too many block groups "
|
||||
"for the resize feature", __func__);
|
||||
/*
|
||||
@@ -1214,24 +1217,24 @@ init_resizeino(const struct timeval *tv)
|
||||
*/
|
||||
reserved_gdb[n++] = h2fs32(cgbase(&sblock, cylno) +
|
||||
NBLOCK_SUPERBLOCK + i);
|
||||
nblock += fsbtodb(&sblock, 1);
|
||||
nblock += EXT2_FSBTODB(&sblock, 1);
|
||||
}
|
||||
for (; n < NINDIR(&sblock); n++)
|
||||
for (; n < EXT2_NINDIR(&sblock); n++)
|
||||
reserved_gdb[n] = 0;
|
||||
|
||||
/* write group descriptor block as the second dindirect refs */
|
||||
wtfs(fsbtodb(&sblock, fs2h32(dindir_block[i])),
|
||||
wtfs(EXT2_FSBTODB(&sblock, fs2h32(dindir_block[i])),
|
||||
sblock.e2fs_bsize, reserved_gdb);
|
||||
nblock += fsbtodb(&sblock, 1);
|
||||
nblock += EXT2_FSBTODB(&sblock, 1);
|
||||
}
|
||||
for (; i < NINDIR(&sblock); i++) {
|
||||
for (; i < EXT2_NINDIR(&sblock); i++) {
|
||||
/* leave trailing entries unallocated */
|
||||
dindir_block[i] = 0;
|
||||
}
|
||||
free(reserved_gdb);
|
||||
|
||||
/* finally write the first level dindirect block */
|
||||
wtfs(fsbtodb(&sblock, node.e2di_blocks[NDADDR + DOUBLE]),
|
||||
wtfs(EXT2_FSBTODB(&sblock, node.e2di_blocks[EXT2FS_NDADDR + DOUBLE]),
|
||||
sblock.e2fs_bsize, dindir_block);
|
||||
free(dindir_block);
|
||||
|
||||
@@ -1261,7 +1264,8 @@ alloc(uint32_t size, uint16_t mode)
|
||||
bbp = malloc(sblock.e2fs_bsize);
|
||||
if (bbp == NULL)
|
||||
return 0;
|
||||
rdfs(fsbtodb(&sblock, gd[0].ext2bgd_b_bitmap), sblock.e2fs_bsize, bbp);
|
||||
rdfs(EXT2_FSBTODB(&sblock, gd[0].ext2bgd_b_bitmap),
|
||||
sblock.e2fs_bsize, bbp);
|
||||
|
||||
/* XXX: kernel uses e2fs_fpg here */
|
||||
len = sblock.e2fs.e2fs_bpg / NBBY;
|
||||
@@ -1276,8 +1280,10 @@ alloc(uint32_t size, uint16_t mode)
|
||||
#endif
|
||||
|
||||
loc = skpc(~0U, len, bbp);
|
||||
if (loc == 0)
|
||||
if (loc == 0) {
|
||||
free(bbp);
|
||||
return 0;
|
||||
}
|
||||
loc = len - loc;
|
||||
map = bbp[loc];
|
||||
bno = loc * NBBY;
|
||||
@@ -1285,6 +1291,7 @@ alloc(uint32_t size, uint16_t mode)
|
||||
if ((map & (1 << i)) == 0)
|
||||
goto gotit;
|
||||
}
|
||||
free(bbp);
|
||||
return 0;
|
||||
|
||||
gotit:
|
||||
@@ -1292,7 +1299,8 @@ alloc(uint32_t size, uint16_t mode)
|
||||
errx(EXIT_FAILURE, "%s: inconsistent bitmap\n", __func__);
|
||||
|
||||
setbit(bbp, bno);
|
||||
wtfs(fsbtodb(&sblock, gd[0].ext2bgd_b_bitmap), sblock.e2fs_bsize, bbp);
|
||||
wtfs(EXT2_FSBTODB(&sblock, gd[0].ext2bgd_b_bitmap),
|
||||
sblock.e2fs_bsize, bbp);
|
||||
free(bbp);
|
||||
/* XXX: modified group descriptors won't be written into backups */
|
||||
gd[0].ext2bgd_nbfree--;
|
||||
@@ -1335,7 +1343,7 @@ iput(struct ext2fs_dinode *ip, ino_t ino)
|
||||
__func__, (uint64_t)ino, c);
|
||||
|
||||
/* update inode bitmap */
|
||||
rdfs(fsbtodb(&sblock, gd[0].ext2bgd_i_bitmap),
|
||||
rdfs(EXT2_FSBTODB(&sblock, gd[0].ext2bgd_i_bitmap),
|
||||
sblock.e2fs_bsize, bp);
|
||||
|
||||
/* more sanity */
|
||||
@@ -1343,7 +1351,7 @@ iput(struct ext2fs_dinode *ip, ino_t ino)
|
||||
errx(EXIT_FAILURE, "%s: inode %" PRIu64
|
||||
" already in use\n", __func__, (uint64_t)ino);
|
||||
setbit(bp, EXT2_INO_INDEX(ino));
|
||||
wtfs(fsbtodb(&sblock, gd[0].ext2bgd_i_bitmap),
|
||||
wtfs(EXT2_FSBTODB(&sblock, gd[0].ext2bgd_i_bitmap),
|
||||
sblock.e2fs_bsize, bp);
|
||||
gd[c].ext2bgd_nifree--;
|
||||
sblock.e2fs.e2fs_ficount--;
|
||||
@@ -1354,7 +1362,7 @@ iput(struct ext2fs_dinode *ip, ino_t ino)
|
||||
").\n", __func__, (uint64_t)ino);
|
||||
|
||||
/* update an inode entry in the table */
|
||||
d = fsbtodb(&sblock, ino_to_fsba(&sblock, ino));
|
||||
d = EXT2_FSBTODB(&sblock, ino_to_fsba(&sblock, ino));
|
||||
rdfs(d, sblock.e2fs_bsize, bp);
|
||||
|
||||
dp = (struct ext2fs_dinode *)(bp +
|
||||
@@ -1362,7 +1370,7 @@ iput(struct ext2fs_dinode *ip, ino_t ino)
|
||||
e2fs_isave(ip, dp);
|
||||
/* e2fs_i_bswap() doesn't swap e2di_blocks addrs */
|
||||
if ((ip->e2di_mode & EXT2_IFMT) != EXT2_IFLNK) {
|
||||
for (i = 0; i < NDADDR + NIADDR; i++)
|
||||
for (i = 0; i < EXT2FS_NDADDR + EXT2FS_NIADDR; i++)
|
||||
dp->e2di_blocks[i] = h2fs32(ip->e2di_blocks[i]);
|
||||
}
|
||||
/* h2fs32() just for consistency */
|
||||
@@ -1400,7 +1408,6 @@ wtfs(daddr_t bno, int size, void *bf)
|
||||
if (Nflag)
|
||||
return;
|
||||
offset = bno;
|
||||
errno = 0;
|
||||
n = pwrite(fso, bf, size, offset * sectorsize);
|
||||
if (n != size)
|
||||
err(EXIT_FAILURE, "%s: write error for sector %" PRId64,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: newfs_ext2fs.c,v 1.8 2009/03/02 10:38:13 tsutsui Exp $ */
|
||||
/* $NetBSD: newfs_ext2fs.c,v 1.9 2013/10/19 01:09:59 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1989, 1993, 1994
|
||||
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1993, 1994\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: newfs_ext2fs.c,v 1.8 2009/03/02 10:38:13 tsutsui Exp $");
|
||||
__RCSID("$NetBSD: newfs_ext2fs.c,v 1.9 2013/10/19 01:09:59 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@@ -68,7 +68,9 @@ __RCSID("$NetBSD: newfs_ext2fs.c,v 1.8 2009/03/02 10:38:13 tsutsui Exp $");
|
||||
#include <util.h>
|
||||
#include <mntopts.h>
|
||||
|
||||
#if defined(__minix)
|
||||
#include <minix/partition.h>
|
||||
#endif /* !defined(__minix) */
|
||||
|
||||
#include "extern.h"
|
||||
#include "partutil.h"
|
||||
@@ -82,17 +84,17 @@ static void usage(void) __dead;
|
||||
* L_DFL_*.
|
||||
*/
|
||||
#define SMALL_FSSIZE ((4 * 1024 * 1024) / sectorsize) /* 4MB */
|
||||
#ifdef __minix
|
||||
#define S_DFL_BSIZE 4096
|
||||
#else
|
||||
#if !defined(__minix)
|
||||
#define S_DFL_BSIZE 1024
|
||||
#endif
|
||||
#define MEDIUM_FSSIZE ((512 * 1024 * 1024) / sectorsize) /* 512MB */
|
||||
#ifdef __minix
|
||||
#define M_DFL_BSIZE 4096
|
||||
#else
|
||||
#define S_DFL_BSIZE 4096
|
||||
#endif /* !defined(__minix) */
|
||||
#define MEDIUM_FSSIZE ((512 * 1024 * 1024) / sectorsize) /* 512MB */
|
||||
#if !defined(__minix)
|
||||
#define M_DFL_BSIZE 1024
|
||||
#endif
|
||||
#else
|
||||
#define M_DFL_BSIZE 4096
|
||||
#endif /* !defined(__minix) */
|
||||
#define L_DFL_BSIZE 4096
|
||||
|
||||
/*
|
||||
@@ -123,9 +125,9 @@ uint density; /* number of bytes per inode */
|
||||
uint num_inodes; /* number of inodes (overrides density) */
|
||||
char *volname = NULL; /* volume name */
|
||||
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
static char *disktype = NULL;
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
static char device[MAXPATHLEN];
|
||||
|
||||
static const char lmsg[] = "%s: can't read disk label";
|
||||
@@ -133,27 +135,28 @@ static const char lmsg[] = "%s: can't read disk label";
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
struct disk_geom geo;
|
||||
struct dkwedge_info dkw;
|
||||
#else
|
||||
u64_t minix_fssize;
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
struct statvfs *mp;
|
||||
char *s2;
|
||||
int len, n;
|
||||
struct stat sb;
|
||||
int ch, fsi, fso, Fflag, Iflag, Zflag;
|
||||
char *cp, *s1, *special;
|
||||
int ch, fsi, fso, len, n, Fflag, Iflag, Zflag;
|
||||
char *s1, *s2, *special;
|
||||
const char *opstring;
|
||||
int byte_sized;
|
||||
uint blocks; /* number of blocks */
|
||||
|
||||
cp = NULL;
|
||||
fso = -1;
|
||||
fsi = fso = -1;
|
||||
Fflag = Iflag = Zflag = 0;
|
||||
verbosity = -1;
|
||||
#if !defined(__minix)
|
||||
opstring = "D:FINO:S:V:Zb:f:i:l:m:n:s:v:";
|
||||
#else
|
||||
opstring = "D:FINO:S:V:Zb:f:i:l:m:n:s:v:B:";
|
||||
#endif /* !defined(__minix) */
|
||||
byte_sized = 0;
|
||||
while ((ch = getopt(argc, argv, opstring)) != -1)
|
||||
switch (ch) {
|
||||
@@ -166,11 +169,11 @@ main(int argc, char *argv[])
|
||||
case 'F':
|
||||
Fflag = 1;
|
||||
break;
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
case 'I':
|
||||
Iflag = 1;
|
||||
break;
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
case 'N':
|
||||
Nflag = 1;
|
||||
if (verbosity == -1)
|
||||
@@ -194,12 +197,13 @@ main(int argc, char *argv[])
|
||||
case 'V':
|
||||
verbosity = strsuftoi64("verbose", optarg, 0, 4, NULL);
|
||||
break;
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
case 'Z':
|
||||
Zflag = 1;
|
||||
break;
|
||||
#endif
|
||||
#else
|
||||
case 'B':
|
||||
#endif /* !defined(__minix) */
|
||||
case 'b':
|
||||
bsize = strsuftoi64("block size",
|
||||
optarg, MINBSIZE, EXT2_MAXBSIZE, NULL);
|
||||
@@ -245,9 +249,9 @@ main(int argc, char *argv[])
|
||||
usage();
|
||||
|
||||
memset(&sb, 0, sizeof(sb));
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
memset(&dkw, 0, sizeof(dkw));
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
special = argv[0];
|
||||
if (Fflag) {
|
||||
int fl;
|
||||
@@ -311,7 +315,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
if (getdiskinfo(special, fsi, disktype, &geo, &dkw) == -1)
|
||||
errx(EXIT_FAILURE, lmsg, special);
|
||||
|
||||
@@ -343,12 +347,12 @@ main(int argc, char *argv[])
|
||||
|
||||
if (sectorsize == 0)
|
||||
sectorsize = 512;
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
}
|
||||
|
||||
if (byte_sized)
|
||||
fssize /= sectorsize;
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
if (fssize <= 0) {
|
||||
if (sb.st_size != 0)
|
||||
fssize += sb.st_size / sectorsize;
|
||||
@@ -364,22 +368,20 @@ main(int argc, char *argv[])
|
||||
"size %" PRIu64 " exceeds maximum file system size on "
|
||||
"`%s' of %" PRIu64 " sectors",
|
||||
fssize, special, dkw.dkw_size);
|
||||
#endif
|
||||
|
||||
printf("fssize = %lld %d-byte sectors\n", fssize, sectorsize);
|
||||
#endif /* !defined(__minix) */
|
||||
|
||||
/* XXXLUKEM: only ftruncate() regular files ? (dsl: or at all?) */
|
||||
if (Fflag && fso != -1
|
||||
&& ftruncate(fso, (off_t)fssize * sectorsize) == -1)
|
||||
err(1, "can't ftruncate %s to %" PRId64, special, fssize);
|
||||
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
if (Zflag && fso != -1) { /* pre-zero (and de-sparce) the file */
|
||||
char *buf;
|
||||
int bufsize, i;
|
||||
off_t bufrem;
|
||||
|
||||
struct statvfs sfs;
|
||||
|
||||
if (fstatvfs(fso, &sfs) == -1) {
|
||||
warn("can't fstatvfs `%s'", special);
|
||||
bufsize = 8192;
|
||||
@@ -393,7 +395,7 @@ main(int argc, char *argv[])
|
||||
if (verbosity > 0)
|
||||
printf("Creating file system image in `%s', "
|
||||
"size %" PRId64 " bytes, in %d byte chunks.\n",
|
||||
special, (signed long long) bufrem, bufsize);
|
||||
special, bufrem, bufsize);
|
||||
while (bufrem > 0) {
|
||||
i = write(fso, buf, MIN(bufsize, bufrem));
|
||||
if (i == -1)
|
||||
@@ -402,7 +404,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
|
||||
/* Sort out fragment and block sizes */
|
||||
if (bsize == 0) {
|
||||
@@ -416,14 +418,11 @@ main(int argc, char *argv[])
|
||||
bsize = L_DFL_BSIZE;
|
||||
}
|
||||
}
|
||||
|
||||
if (fsize == 0)
|
||||
fsize = bsize;
|
||||
|
||||
blocks = fssize * sectorsize / bsize;
|
||||
|
||||
fssize = (u64_t) blocks * bsize / sectorsize;
|
||||
|
||||
if (num_inodes == 0) {
|
||||
if (density != 0)
|
||||
num_inodes = fssize / density;
|
||||
|
||||
+10
-11
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: reboot.c,v 1.39 2011/08/27 18:46:19 joerg Exp $ */
|
||||
/* $NetBSD: reboot.c,v 1.40 2012/11/04 22:28:16 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1986, 1993
|
||||
@@ -40,7 +40,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1993\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)reboot.c 8.1 (Berkeley) 6/5/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: reboot.c,v 1.39 2011/08/27 18:46:19 joerg Exp $");
|
||||
__RCSID("$NetBSD: reboot.c,v 1.40 2012/11/04 22:28:16 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@@ -56,6 +56,9 @@ __RCSID("$NetBSD: reboot.c,v 1.39 2011/08/27 18:46:19 joerg Exp $");
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <util.h>
|
||||
#ifdef SUPPORT_UTMPX
|
||||
#include <utmpx.h>
|
||||
#endif
|
||||
|
||||
__dead static void usage(void);
|
||||
|
||||
@@ -66,7 +69,9 @@ int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const char *progname;
|
||||
/* int i; */
|
||||
#if !defined(__minix)
|
||||
int i;
|
||||
#endif /* !defined(__minix) */
|
||||
struct passwd *pw;
|
||||
int ch, howto, lflag, nflag, qflag, sverrno, len;
|
||||
const char *user;
|
||||
@@ -193,15 +198,9 @@ main(int argc, char *argv[])
|
||||
*/
|
||||
(void)signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
|
||||
/* Just stop init -- if we fail, we'll restart it. */
|
||||
#if 0 && defined(__minix)
|
||||
if (kill(1, SIGTERM) == -1)
|
||||
err(1, "SIGTERM init");
|
||||
#else
|
||||
if (kill(1, SIGTSTP) == -1)
|
||||
err(1, "SIGTSTP init");
|
||||
#endif
|
||||
|
||||
/* Send a SIGTERM first, a chance to save the buffers. */
|
||||
if (kill(-1, SIGTERM) == -1) {
|
||||
@@ -226,7 +225,7 @@ main(int argc, char *argv[])
|
||||
sync();
|
||||
sleep(3);
|
||||
|
||||
#ifndef __minix
|
||||
#if !defined(__minix)
|
||||
for (i = 1;; ++i) {
|
||||
if (kill(-1, SIGKILL) == -1) {
|
||||
if (errno == ESRCH)
|
||||
@@ -240,7 +239,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
(void)sleep(2 * i);
|
||||
}
|
||||
#endif
|
||||
#endif /* !defined(__minix) */
|
||||
|
||||
reboot(howto, bootstr);
|
||||
warn("reboot()");
|
||||
|
||||
@@ -8,8 +8,4 @@ BINOWN= root
|
||||
BINGRP= operator
|
||||
BINMODE=4554
|
||||
|
||||
.if defined(__MINIX)
|
||||
WARNS=2
|
||||
.endif
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
Reference in New Issue
Block a user