/*
* Copyright 2005 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"
#include <stdio.h>
#include <string.h>
#include <ctype.h> /* use isdigit macro rather than 4.1 libc routine */
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <malloc.h>
#include <ustat.h>
#include <sys/sysmacros.h>
#include "fsck.h"
#include <locale.h>
extern void pfatal(char *, ...);
extern void printfree();
extern void pwarn(char *, ...);
extern void pass1();
extern void dofreemap();
extern void dolvint();
extern char *getfullblkname();
extern char *getfullrawname();
char *mntopt();
int returntosingle;
static void checkfilesys();
static void check_sanity();
static void usage();
static char *subopts [] = {
#define PREEN 0
"p",
"d",
"r",
"w",
"f",
"s",
};
int
{
int c;
int suboption;
switch (c) {
case 'm':
mflag++;
break;
case 'n': /* default no answer flag */
case 'N':
nflag++;
yflag = 0;
break;
case 'o':
/*
* udfs specific options.
*/
suboptions = optarg;
while (*suboptions != '\0') {
switch (suboption) {
case PREEN:
preen++;
break;
case DEBUG:
debug++;
break;
case READ_ONLY:
break;
case ONLY_WRITES:
/* check only writable filesystems */
wflag++;
break;
case FORCE:
fflag++;
break;
case STATS:
sflag++;
break;
default:
usage();
}
}
break;
case 'V':
{
int opt_count;
char *opt_text;
opt_count++) {
if (opt_text)
opt_text);
}
}
break;
case 'y': /* default yes answer flag */
case 'Y':
yflag++;
nflag = 0;
break;
case '?':
usage();
}
}
rflag++; /* check raw devices */
}
if (preen) {
}
if (argc) {
while (argc-- > 0) {
argv++;
} else
checkfilesys(*argv++);
}
}
return (0);
}
static void
{
char *devstr;
mountfd = -1;
mountedfs = 0;
iscorrupt = 1;
if (iscorrupt == 0)
return;
if (preen)
exitstat = 32;
}
else
if (mflag)
iscorrupt = 0;
/*
* 1: scan inodes tallying blocks used
*/
if (preen == 0) {
if (mountedfs)
if (mflag) {
(void) printf(
gettext("** Phase 1 - Sanity Check only\n"));
return;
} else
(void) printf(
gettext("** Phase 1 - Check Directories "
"and Blocks\n"));
}
pass1();
if (sflag) {
if (preen)
else
(void) printf("** ");
}
if (debug)
if (debug)
printfree();
dofreemap();
dolvint();
/*
* print out summary statistics
*/
if (iscorrupt)
exitstat = 36;
if (!fsmodified)
return;
if (!preen)
(void) printf(
gettext("\n***** FILE SYSTEM WAS MODIFIED *****\n"));
if (mountedfs) {
exitstat = 40;
}
}
/*
* exit 0 - file system is unmounted and okay
* exit 32 - file system is unmounted and needs checking
* exit 33 - file system is mounted
* for root file system
* exit 34 - cannot stat device
*/
static void
{
char *devname;
int is_root = 0;
int is_usr = 0;
int is_block = 0;
gettext("udfs fsck: sanity check failed : cannot stat "
"%s\n"), filename);
exit(34);
}
is_block = 1;
is_block = 0;
else {
gettext("udfs fsck: sanity check failed: %s not "
"block or character device\n"), filename);
exit(34);
}
/*
* Determine if this is the root file system via vfstab. Give up
* silently on failures. The whole point of this is not to care
* if the root file system is already mounted.
*
* XXX - similar for /usr. This should be fixed to simply return
* a new code indicating, mounted and needs to be checked.
*/
if (is_block)
else
is_root = 1;
}
if (is_block)
else
is_usr = 1;
}
}
/*
* XXX - only works if filename is a block device or if
* character and block device has the same dev_t value
*/
gettext("udfs fsck: sanity check: %s "
"already mounted\n"), filename);
exit(33);
}
gettext("udfs fsck: sanity check: %s okay\n"),
filename);
} else {
gettext("udfs fsck: sanity check: %s needs checking\n"),
filename);
exit(32);
}
exit(0);
}
char *
{
char *dp;
return ("");
return (dp);
}
char *
{
char *dp;
return ("");
return (dp);
}
char *
{
char *f, *opts;
static char *tmpopts;
return (NULL);
if (tmpopts == 0) {
if (tmpopts == 0)
return (0);
}
}
return (NULL);
}
static void
usage()
{
"[generic options] [-o p,w,s] [special ....]\n"));
}