setup.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that: (1) source distributions retain this entire copyright
* notice and comment, and (2) distributions including binaries display
* the following acknowledgement: ``This product includes software
* developed by the University of California, Berkeley and its contributors''
* in the documentation or other materials provided with the distribution
* and in all advertising materials mentioning features or use of this
* software. Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#define DKTYPENAMES
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/sysmacros.h>
#include <sys/int_const.h>
#include <string.h>
#include <unistd.h>
#include <ustat.h>
#include <fcntl.h>
#include "fsck.h"
#include "roll_log.h"
static void badsb(int, char *);
static int checksb(int);
int maxshadowclients = 1024;
/*
* The size of a cylinder group is calculated by CGSIZE. The maximum size
* is limited by the fact that cylinder groups are at most one block.
* Its size is derived from the size of the maps maintained in the
* cylinder group and the (struct cg) size.
*/
/* base cg */ (sizeof (struct cg) + \
extern int mflag;
extern char hotroot;
extern char *mount_point;
static int
{
int fd;
if (mount_point) {
if (fd == -1) {
perror("fsck: open mount point error");
exit(39);
}
/* get the latest super block */
perror("fsck: ioctl _FIOGETSUPERBLOCK error");
exit(39);
}
} else {
(long)SBSIZE);
}
/*
* rudimental consistency checks
*/
return (0);
}
return (0);
}
return (0);
}
return (0);
}
return (0);
}
return (0);
}
return (1);
}
void
flush_fs()
{
int fd;
if (mount_point) {
if (fd == -1) {
perror("fsck: open mount point error");
exit(39);
}
perror("fsck: ioctl _FIOFFS error");
exit(39);
}
}
}
/*
* Roll the embedded log, if any, and set up the global variables
* islog, islogok, and ismdd.
*/
static int
{
void *buf;
void *ud_buf;
int badlog;
if (bflag)
return (1); /* can't roll log while alternate sb specified */
/* Roll the log, if any */
badlog = 0;
if (!read_super_block())
return (0);
/*
* Roll the log in 3 cases:
* 1. If it's unmounted (mount_point == NULL) and it's not marked
* as fully rolled (sblock.fs_rolled != FS_ALL_ROLLED)
* 2. If it's mounted and anything other than a sanity
* check fsck (mflag) is being done, as we have the current
* super block. Note, only a sanity check is done for
* ufs_flush() gets called, leading to a slower boot.
* 3. If anything other then a sanity check (mflag) is being done
* to a mounted filesystem while it is in read-only state
* (e.g. root during early boot stages) we have to detect this
* and have to roll the log as well. NB. the read-only mount
* will flip fs_clean from FSLOG to FSSTABLE and marks the
* log as FS_NEED_ROLL.
*/
(mount_point && !mflag))) {
int roll_log_err = 0;
/*
* roll the log without a mount
*/
flush_fs();
}
roll_log_err = 1;
}
if (roll_log_err) {
/*
* There are two cases where we want to set
* an error code and return:
* - We're preening
* - We're not on a live root and the user
* chose *not* to ignore the log
* Otherwise, we want to mark the log as bad
* and continue to check the filesystem. This
* has the side effect of destroying the log.
*/
"DISCARDING THE LOG MAY DISCARD PENDING TRANSACTIONS.\n"
"DISCARD THE LOG AND CONTINUE") == 0)) {
exitstat = 39;
return (0);
}
++badlog;
}
}
/* MDD (disksuite) device */
++ismdd;
/* Logging UFS may be enabled */
++islog;
/* log is not okay; check the fs */
return (1);
/*
* If logging or (stable and mounted) then continue
*/
return (1);
/* get the log allocation block */
return (1);
}
return (1);
}
(long)dev_bsize);
/* log allocation block is not okay; check the fs */
return (1);
}
/* get the log state block(s) */
(long)dev_bsize)) {
(long)dev_bsize);
}
return (1);
}
/* log state is okay; don't need to check the fs */
++islogok;
} else if (ismdd) {
/* if it is a logging device and there are no errors */
islog++;
islogok++;
}
}
return (1);
}
char *
{
int size, i, j;
static char devstr[MAXPATHLEN];
void write_altsb();
int mountchk;
havesb = 0;
errexit("Can't stat root\n");
exitstat = 34;
return (0);
}
/*
* A mount point is specified. But the mount point doesn't
* Search mnttab, because if the fs is error locked, it is
* allowed to be fsck'd while mounted.
*/
if (errorlocked) {
return (0);
}
goto restat;
}
}
return (0);
}
mount_point = "/";
hotroot++;
exitstat = 33;
return (0);
}
}
/*
* Check vfstab for a mount point with this name
*/
}
MNTTYPE_UFS) != 0) {
/*
* found the entry but it is not a
* ufs filesystem, don't check it
*/
return (0);
}
if (rflag) {
}
goto restat;
}
}
if (preen)
pwarn("file is not a block or character device.\n");
else if (reply("file is not a block or character device; OK")
== 0)
return (0);
/*
* To fsck regular files (fs images)
* we need to clear the rflag since
* regular files don't have raw names. --CW
*/
rflag = 0;
}
if (rflag) {
mountedfs++;
/*
* Get confirmation we should continue UNLESS:
* this is the root (since that is always
* mounted), we are running in preen mode, we
* are running in "just say no" mode, the fs is
* mounted read-only, or we are running in check
* only mode.
*/
if (reply("FILE SYSTEM IS CURRENTLY MOUNTED."
" CONTINUE") == 0) {
exitstat = 33;
return (0);
}
}
} else {
printf("%s is mounted, fsck on BLOCK device ignored\n",
devstr);
exit(33);
}
if (!errorlocked)
sync(); /* call sync, only when devstr's mounted */
}
if (rflag) {
char blockname[MAXPATHLEN];
/*
* For root device check, must check
* block devices.
*/
exitstat = 34;
return (0);
}
}
hotroot++;
mount_point = "/";
}
exitstat = 34;
return (0);
}
if (errorlocked) {
if (debug && elock_combuf)
fflag = 1;
}
fswritefd = -1;
pfatal("(NO WRITE ACCESS)\n");
printf(" (NO WRITE)");
}
if (preen == 0)
printf("\n");
else if (debug)
if (hotroot)
printf(" is root fs%s",
if (mountedfs)
if (errorlocked)
printf(" is error-locked");
printf(".\n");
}
fsmodified = 0;
if (errorlocked)
isdirty = 1;
lfdir = 0;
errexit("cannot allocate space for superblock\n");
/* Check log state (embedded and SDS) */
return (0);
/*
* Flush fs if we're going to do anything other than a sanity check.
* Note, if logging then the fs was flushed if needed in logsetup().
*/
flush_fs();
if (!read_super_block()) /* re-read sb after possibly rolling the log */
return (0);
/*
* Check the superblock, looking for alternates if necessary
*/
if (checksb(1) == 0)
return (0);
/*
* Check and potentially fix certain fields in the super block.
*/
pfatal("UNDEFINED OPTIMIZATION IN SUPERBLOCK");
sbdirty();
}
}
pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK",
sbdirty();
}
}
if (cvtflag) {
/*
* Requested to convert from old format to new format
*/
if (preen)
pwarn("CONVERTING TO NEW FILE SYSTEM FORMAT\n");
else if (!reply("CONVERT TO NEW FILE SYSTEM FORMAT"))
return (0);
isconvert = 1;
(char *)(&sblock.fs_opostbl[0][0]) -
/*
* Planning now for future expansion.
*/
#if defined(_BIG_ENDIAN)
#endif
#if defined(_LITTLE_ENDIAN)
#endif
/* make mountable */
sbdirty();
/*
* Requested to convert from new format to old format
*/
"PARAMETERS OF CURRENT FILE SYSTEM DO NOT\n\t");
"ALLOW CONVERSION TO OLD FILE SYSTEM FORMAT\n");
}
if (preen)
pwarn("CONVERTING TO OLD FILE SYSTEM FORMAT\n");
else if (!reply("CONVERT TO OLD FILE SYSTEM FORMAT"))
return (0);
isconvert = 1;
/* make mountable */
sbdirty();
} else {
errexit("UNKNOWN FILE SYSTEM FORMAT\n");
}
}
if (errorlocked) {
/* do this right away to prevent any other fscks on this fs */
case FSBAD:
break;
case FSFIX:
if (preen)
errexit("ERROR-LOCKED; MARKED \"FSFIX\"\n");
if (reply("marked FSFIX, CONTINUE") == 0)
return (0);
break;
case FSCLEAN:
if (preen)
errexit("ERROR-LOCKED; MARKED \"FSCLEAN\"\n");
if (reply("marked FSCLEAN, CONTINUE") == 0)
return (0);
break;
default:
if (preen) {
if (debug)
pwarn("ERRORLOCKED; NOT MARKED \"FSBAD\"\n");
else
errexit("ERRORLOCKED; NOT MARKED \"FSBAD\"\n");
} else {
if (reply("error-locked, but not marked \"FSBAD\"; CONTINUE") == 0)
return (0);
}
break;
}
if (!do_errorlock(LOCKFS_ELOCK)) {
if (preen)
return (0);
if (reply("error-lock reset failed; CONTINUE") == 0)
return (0);
}
sbdirty();
}
/*
* read in the summary info.
*/
errexit("cannot allocate space for cylinder group summary\n");
(long)size) != 0)
return (0);
}
/*
* if not error-locked,
* not bad log, not forced, preening, not converting, and is clean;
* stop checking
*/
if (!errorlocked &&
iscorrupt = 0;
printclean();
return (0);
}
/*
* allocate and initialize the necessary maps
*/
sizeof (short));
goto badsb;
}
goto badsb;
}
printf("cannot alloc %d bytes for lncntp\n",
(maxino + 1) * sizeof (short));
goto badsb;
}
sizeof (struct inoinfo *));
sizeof (struct inoinfo *));
printf("cannot alloc %d bytes for inphead\n",
goto badsb;
}
sizeof (struct aclinfo *));
sizeof (struct aclinfo *));
printf("cannot alloc %d bytes for aclphead\n",
goto badsb;
}
aclplast = 0L;
inplast = 0L;
bufinit();
return (devstr);
ckfini();
exitstat = 39;
return (0);
}
/*
* mkfs limits the size of the inode map to be no more than a third of
* the cylinder group space. We'll use that value for sanity checking
* the superblock's inode per group value.
*/
/*
* Check the super block and its summary info.
*/
static int
{
/*
* When the fs check is successfully completed, the alternate super
* block at sblk.b_bno will be overwritten by ckfini() with the
* repaired super block.
*/
/*
* Add some extra hardening checks per bug 1253090. Also sanity
* check some of the values we are going to use later in allocation
* requests.
*/
return (0);
}
return (0);
}
return (0);
}
return (0);
}
return (0);
}
return (0);
}
/*
* Check that the number of inodes per group isn't less than or
* equal to zero. Also makes sure it isn't more than the
* maximum number mkfs enforces.
*/
return (0);
}
/*
* Set all possible fields that could differ, then do check
* of whole super block against an alternate super block.
* When an alternate super-block is specified this check is skipped.
*/
return (0);
if (bflag) {
/*
* Invalidate clean flag and state information
*/
sblock.fs_reclaim = 0;
sbdirty();
havesb = 1;
return (1);
}
/*
* fsck should ignore deleted files because the reclaim thread
* will run at mount and reclaim them
*/
/*
* The following should not have to be copied.
*/
}
havesb = 1;
return (1);
}
static void
{
if (!listerr)
return;
if (preen)
printf("BAD SUPER BLOCK: %s\n", s);
pwarn("USE AN ALTERNATE SUPER-BLOCK TO SUPPLY NEEDED INFORMATION;\n");
pwarn("eg. fsck [-F ufs] -o b=# [special ...] \n");
pfatal("where # is the alternate super block. SEE fsck_ufs(1M). \n");
exitstat = 39;
}
/*
* Write out the super block into each of the alternate super blocks.
*/
void
write_altsb(int fd)
{
int cylno;
}