~ubuntu-branches/ubuntu/maverick/hfsprogs/maverick

« back to all changes in this revision

Viewing changes to .pc/10-linux_specific_code.patch/fsck_hfs.tproj/utilities.c

  • Committer: Bazaar Package Importer
  • Author(s): Rogério Brito
  • Date: 2010-01-31 07:01:54 UTC
  • mfrom: (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100131070154-tn5dfg5fjiejd6hn
Tags: 332.25-8
* Use a FTBFS bug revealed by the kfreebsd-* ports.
  This was reported by Cyril Brulebois, and patched by: Petr Salinger.
  Closes: #566916
* Remove b-dep on kfreebsd-kernel-headers, as it is build-essential.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
 
3
 *
 
4
 * @APPLE_LICENSE_HEADER_START@
 
5
 * 
 
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
 
12
 * this file.
 
13
 * 
 
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
 
20
 * under the License."
 
21
 * 
 
22
 * @APPLE_LICENSE_HEADER_END@
 
23
 */
 
24
/*
 
25
 * Copyright (c) 1980, 1986, 1993
 
26
 *      The Regents of the University of California.  All rights reserved.
 
27
 *
 
28
 * Redistribution and use in source and binary forms, with or without
 
29
 * modification, are permitted provided that the following conditions
 
30
 * are met:
 
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.
 
43
 *
 
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
 
54
 * SUCH DAMAGE.
 
55
 */
 
56
 
 
57
#include <sys/types.h>
 
58
#include <sys/stat.h>
 
59
 
 
60
#include <ctype.h>
 
61
#include <err.h>
 
62
#include <stdio.h>
 
63
#include <string.h>
 
64
#include <unistd.h> 
 
65
#include <stdlib.h>
 
66
 
 
67
#include "fsck_hfs.h"
 
68
 
 
69
char *rawname __P((char *name));
 
70
char *unrawname __P((char *name));
 
71
 
 
72
 
 
73
int
 
74
reply(char *question)
 
75
{
 
76
        int persevere;
 
77
        char c;
 
78
 
 
79
        if (preen)
 
80
                pfatal("INTERNAL ERROR: GOT TO reply()");
 
81
        persevere = !strcmp(question, "CONTINUE");
 
82
        printf("\n");
 
83
        if (!persevere && (nflag || fswritefd < 0)) {
 
84
                printf("%s? no\n\n", question);
 
85
                return (0);
 
86
        }
 
87
        if (yflag || (persevere && nflag)) {
 
88
                printf("%s? yes\n\n", question);
 
89
                return (1);
 
90
        }
 
91
        do      {
 
92
                printf("%s? [yn] ", question);
 
93
                (void) fflush(stdout);
 
94
                c = getc(stdin);
 
95
                while (c != '\n' && getc(stdin) != '\n')
 
96
                        if (feof(stdin))
 
97
                                return (0);
 
98
        } while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
 
99
        printf("\n");
 
100
        if (c == 'y' || c == 'Y')
 
101
                return (1);
 
102
        return (0);
 
103
}
 
104
 
 
105
 
 
106
void
 
107
ckfini(markclean)
 
108
        int markclean;
 
109
{
 
110
//      register struct bufarea *bp, *nbp;
 
111
//      int ofsmodified, cnt = 0;
 
112
 
 
113
        (void) CacheDestroy(&fscache);
 
114
 
 
115
        if (fswritefd < 0) {
 
116
                (void)close(fsreadfd);
 
117
                return;
 
118
        }
 
119
#if 0
 
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;
 
124
                sbdirty();
 
125
                flush(fswritefd, &sblk);
 
126
        }
 
127
        flush(fswritefd, &cgblk);
 
128
        free(cgblk.b_un.b_buf);
 
129
        for (bp = bufhead.b_prev; bp && bp != &bufhead; bp = nbp) {
 
130
                cnt++;
 
131
                flush(fswritefd, bp);
 
132
                nbp = bp->b_prev;
 
133
                free(bp->b_un.b_buf);
 
134
                free((char *)bp);
 
135
        }
 
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) {
 
140
                sblock.fs_clean = 1;
 
141
                sbdirty();
 
142
                ofsmodified = fsmodified;
 
143
                flush(fswritefd, &sblk);
 
144
                fsmodified = ofsmodified;
 
145
                if (!preen)
 
146
                        printf("\n***** FILE SYSTEM MARKED CLEAN *****\n");
 
147
        }
 
148
        if (debug)
 
149
                printf("cache missed %ld of %ld (%d%%)\n", diskreads,
 
150
                    totalreads, (int)(diskreads * 100 / totalreads));
 
151
#endif
 
152
        (void)close(fsreadfd);
 
153
        (void)close(fswritefd);
 
154
}
 
155
 
 
156
 
 
157
char *
 
158
blockcheck(char *origname)
 
159
{
 
160
        struct stat stslash, stblock, stchar;
 
161
        char *newname, *raw;
 
162
        int retried = 0;
 
163
 
 
164
        hotroot = 0;
 
165
        if (stat("/", &stslash) < 0) {
 
166
                perror("/");
 
167
                printf("Can't stat root\n");
 
168
                return (origname);
 
169
        }
 
170
        newname = origname;
 
171
retry:
 
172
        if (stat(newname, &stblock) < 0) {
 
173
                perror(newname);
 
174
                printf("Can't stat %s\n", newname);
 
175
                return (origname);
 
176
        }
 
177
        if ((stblock.st_mode & S_IFMT) == S_IFBLK) {
 
178
                if (stslash.st_dev == stblock.st_rdev)
 
179
                        hotroot++;
 
180
                raw = rawname(newname);
 
181
                if (stat(raw, &stchar) < 0) {
 
182
                        perror(raw);
 
183
                        printf("Can't stat %s\n", raw);
 
184
                        return (origname);
 
185
                }
 
186
                if ((stchar.st_mode & S_IFMT) == S_IFCHR) {
 
187
                        return (raw);
 
188
                } else {
 
189
                        printf("%s is not a character device\n", raw);
 
190
                        return (origname);
 
191
                }
 
192
        } else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) {
 
193
                newname = unrawname(newname);
 
194
                retried++;
 
195
                goto retry;
 
196
        }
 
197
        /*
 
198
         * Not a block or character device, just return name and
 
199
         * let the caller decide whether to use it.
 
200
         */
 
201
        return (origname);
 
202
}
 
203
 
 
204
 
 
205
char *
 
206
rawname(char *name)
 
207
 
 
208
{
 
209
        static char rawbuf[32];
 
210
        char *dp;
 
211
 
 
212
        if ((dp = strrchr(name, '/')) == 0)
 
213
                return (0);
 
214
        *dp = 0;
 
215
        (void)strcpy(rawbuf, name);
 
216
        *dp = '/';
 
217
        (void)strcat(rawbuf, "/r");
 
218
        (void)strcat(rawbuf, &dp[1]);
 
219
 
 
220
        return (rawbuf);
 
221
}
 
222
 
 
223
 
 
224
char *
 
225
unrawname(char *name)
 
226
{
 
227
        char *dp;
 
228
        struct stat stb;
 
229
 
 
230
        if ((dp = strrchr(name, '/')) == 0)
 
231
                return (name);
 
232
        if (stat(name, &stb) < 0)
 
233
                return (name);
 
234
        if ((stb.st_mode & S_IFMT) != S_IFCHR)
 
235
                return (name);
 
236
        if (dp[1] != 'r')
 
237
                return (name);
 
238
        (void)strcpy(&dp[1], &dp[2]);
 
239
 
 
240
        return (name);
 
241
}
 
242
 
 
243
 
 
244
void
 
245
catch(sig)
 
246
        int sig;
 
247
{
 
248
        if (!upgrading)
 
249
                ckfini(0);
 
250
        exit(12);
 
251
}
 
252
 
 
253
 
 
254
#if __STDC__
 
255
#include <stdarg.h>
 
256
#else
 
257
#include <varargs.h>
 
258
#endif
 
259
 
 
260
/*
 
261
 * An unexpected inconsistency occured.
 
262
 * Die if preening, otherwise just print message and continue.
 
263
 */
 
264
void
 
265
#if __STDC__
 
266
pfatal(const char *fmt, ...)
 
267
#else
 
268
pfatal(fmt, va_alist)
 
269
        char *fmt;
 
270
        va_dcl
 
271
#endif
 
272
{
 
273
        va_list ap;
 
274
#if __STDC__
 
275
        va_start(ap, fmt);
 
276
#else
 
277
        va_start(ap);
 
278
#endif
 
279
        if (!preen) {
 
280
                (void)vfprintf(stderr, fmt, ap);
 
281
                va_end(ap);
 
282
                return;
 
283
        }
 
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",
 
288
            cdevname);
 
289
        exit(EEXIT);
 
290
}
 
291
 
 
292
/*
 
293
 * Pwarn just prints a message when not preening,
 
294
 * or a warning (preceded by filename) when preening.
 
295
 */
 
296
void
 
297
#if __STDC__
 
298
pwarn(const char *fmt, ...)
 
299
#else
 
300
pwarn(fmt, va_alist)
 
301
        char *fmt;
 
302
        va_dcl
 
303
#endif
 
304
{
 
305
        va_list ap;
 
306
#if __STDC__
 
307
        va_start(ap, fmt);
 
308
#else
 
309
        va_start(ap);
 
310
#endif
 
311
        if (preen)
 
312
                (void)fprintf(stderr, "%s: ", cdevname);
 
313
        (void)vfprintf(stderr, fmt, ap);
 
314
        va_end(ap);
 
315
}
 
316