2
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4
* @APPLE_LICENSE_HEADER_START@
6
* "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7
* Reserved. This file contains Original Code and/or Modifications of
8
* Original Code as defined in and that are subject to the Apple Public
9
* Source License Version 1.0 (the 'License'). You may not use this file
10
* except in compliance with the License. Please obtain a copy of the
11
* License at http://www.apple.com/publicsource and read it before using
14
* The Original Code and all software distributed under the License are
15
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19
* License for the specific language governing rights and limitations
22
* @APPLE_LICENSE_HEADER_END@
25
* Copyright (c) 1980, 1986, 1993
26
* The Regents of the University of California. All rights reserved.
28
* Redistribution and use in source and binary forms, with or without
29
* modification, are permitted provided that the following conditions
31
* 1. Redistributions of source code must retain the above copyright
32
* notice, this list of conditions and the following disclaimer.
33
* 2. Redistributions in binary form must reproduce the above copyright
34
* notice, this list of conditions and the following disclaimer in the
35
* documentation and/or other materials provided with the distribution.
36
* 3. All advertising materials mentioning features or use of this software
37
* must display the following acknowledgement:
38
* This product includes software developed by the University of
39
* California, Berkeley and its contributors.
40
* 4. Neither the name of the University nor the names of its contributors
41
* may be used to endorse or promote products derived from this software
42
* without specific prior written permission.
44
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57
#include <sys/types.h>
69
char *rawname __P((char *name));
70
char *unrawname __P((char *name));
80
pfatal("INTERNAL ERROR: GOT TO reply()");
81
persevere = !strcmp(question, "CONTINUE");
83
if (!persevere && (nflag || fswritefd < 0)) {
84
printf("%s? no\n\n", question);
87
if (yflag || (persevere && nflag)) {
88
printf("%s? yes\n\n", question);
92
printf("%s? [yn] ", question);
93
(void) fflush(stdout);
95
while (c != '\n' && getc(stdin) != '\n')
98
} while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
100
if (c == 'y' || c == 'Y')
110
// register struct bufarea *bp, *nbp;
111
// int ofsmodified, cnt = 0;
113
(void) CacheDestroy(&fscache);
116
(void)close(fsreadfd);
120
flush(fswritefd, &sblk);
121
if (havesb && sblk.b_bno != SBOFF / dev_bsize &&
122
!preen && reply("UPDATE STANDARD SUPERBLOCK")) {
123
sblk.b_bno = SBOFF / dev_bsize;
125
flush(fswritefd, &sblk);
127
flush(fswritefd, &cgblk);
128
free(cgblk.b_un.b_buf);
129
for (bp = bufhead.b_prev; bp && bp != &bufhead; bp = nbp) {
131
flush(fswritefd, bp);
133
free(bp->b_un.b_buf);
136
if (bufhead.b_size != cnt)
137
errx(EEXIT, "Panic: lost %d buffers", bufhead.b_size - cnt);
138
pbp = pdirbp = (struct bufarea *)0;
139
if (markclean && sblock.fs_clean == 0) {
142
ofsmodified = fsmodified;
143
flush(fswritefd, &sblk);
144
fsmodified = ofsmodified;
146
printf("\n***** FILE SYSTEM MARKED CLEAN *****\n");
149
printf("cache missed %ld of %ld (%d%%)\n", diskreads,
150
totalreads, (int)(diskreads * 100 / totalreads));
152
(void)close(fsreadfd);
153
(void)close(fswritefd);
158
blockcheck(char *origname)
160
struct stat stslash, stblock, stchar;
165
if (stat("/", &stslash) < 0) {
167
printf("Can't stat root\n");
172
if (stat(newname, &stblock) < 0) {
174
printf("Can't stat %s\n", newname);
177
if ((stblock.st_mode & S_IFMT) == S_IFBLK) {
178
if (stslash.st_dev == stblock.st_rdev)
180
raw = rawname(newname);
181
if (stat(raw, &stchar) < 0) {
183
printf("Can't stat %s\n", raw);
186
if ((stchar.st_mode & S_IFMT) == S_IFCHR) {
189
printf("%s is not a character device\n", raw);
192
} else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) {
193
newname = unrawname(newname);
198
* Not a block or character device, just return name and
199
* let the caller decide whether to use it.
209
static char rawbuf[32];
212
if ((dp = strrchr(name, '/')) == 0)
215
(void)strcpy(rawbuf, name);
217
(void)strcat(rawbuf, "/r");
218
(void)strcat(rawbuf, &dp[1]);
225
unrawname(char *name)
230
if ((dp = strrchr(name, '/')) == 0)
232
if (stat(name, &stb) < 0)
234
if ((stb.st_mode & S_IFMT) != S_IFCHR)
238
(void)strcpy(&dp[1], &dp[2]);
261
* An unexpected inconsistency occured.
262
* Die if preening, otherwise just print message and continue.
266
pfatal(const char *fmt, ...)
268
pfatal(fmt, va_alist)
280
(void)vfprintf(stderr, fmt, ap);
284
(void)fprintf(stderr, "%s: ", cdevname);
285
(void)vfprintf(stderr, fmt, ap);
286
(void)fprintf(stderr,
287
"\n%s: UNEXPECTED INCONSISTENCY; RUN fsck_hfs MANUALLY.\n",
293
* Pwarn just prints a message when not preening,
294
* or a warning (preceded by filename) when preening.
298
pwarn(const char *fmt, ...)
312
(void)fprintf(stderr, "%s: ", cdevname);
313
(void)vfprintf(stderr, fmt, ap);