Deleted Added
full compact
preen.c (37000) preen.c (41474)
1/*
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
1/*
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35#if 0
36static const char sccsid[] = "@(#)preen.c 8.5 (Berkeley) 4/28/95";
35static const char sccsid[] = "@(#)preen.c 8.5 (Berkeley) 4/28/95";
37#endif
38static const char rcsid[] =
39 "$Id$";
40#endif /* not lint */
41
42#include <sys/param.h>
43#include <sys/stat.h>
44#include <sys/wait.h>
45
46#include <ufs/ufs/dinode.h>
47
48#include <ctype.h>
36#endif /* not lint */
37
38#include <sys/param.h>
39#include <sys/stat.h>
40#include <sys/wait.h>
41
42#include <ufs/ufs/dinode.h>
43
44#include <ctype.h>
49#include
45#include <errno.h>
50#include <fstab.h>
51#include <string.h>
52
53#include "fsck.h"
54
55struct part {
56 struct part *next; /* forward link of partitions on disk */
57 char *name; /* device name */
58 char *fsname; /* mounted filesystem name */
59 long auxdata; /* auxillary data for application */
60} *badlist, **badnext = &badlist;
61
62struct disk {
63 char *name; /* disk base name */
64 struct disk *next; /* forward link for list of disks */
65 struct part *part; /* head of list of partitions on disk */
66 int pid; /* If != 0, pid of proc working on */
67} *disks;
68
69int nrun, ndisks;
70char hotroot;
71
72static void addpart __P((char *name, char *fsname, long auxdata));
73static struct disk *finddisk __P((char *name));
74static char *rawname __P((char *name));
75static int startdisk __P((struct disk *dk,
76 int (*checkit)(char *, char *, long, int)));
77static char *unrawname __P((char *name));
78
79int
80checkfstab(preen, maxrun, docheck, chkit)
81 int preen;
82 int maxrun;
83 int (*docheck)(struct fstab *);
84 int (*chkit)(char *, char *, long, int);
85{
86 register struct fstab *fsp;
87 register struct disk *dk, *nextdisk;
88 register struct part *pt;
89 int ret, pid, retcode, passno, sumstatus, status;
90 long auxdata;
91 char *name;
92
93 sumstatus = 0;
94 for (passno = 1; passno <= 2; passno++) {
95 if (setfsent() == 0) {
46#include <fstab.h>
47#include <string.h>
48
49#include "fsck.h"
50
51struct part {
52 struct part *next; /* forward link of partitions on disk */
53 char *name; /* device name */
54 char *fsname; /* mounted filesystem name */
55 long auxdata; /* auxillary data for application */
56} *badlist, **badnext = &badlist;
57
58struct disk {
59 char *name; /* disk base name */
60 struct disk *next; /* forward link for list of disks */
61 struct part *part; /* head of list of partitions on disk */
62 int pid; /* If != 0, pid of proc working on */
63} *disks;
64
65int nrun, ndisks;
66char hotroot;
67
68static void addpart __P((char *name, char *fsname, long auxdata));
69static struct disk *finddisk __P((char *name));
70static char *rawname __P((char *name));
71static int startdisk __P((struct disk *dk,
72 int (*checkit)(char *, char *, long, int)));
73static char *unrawname __P((char *name));
74
75int
76checkfstab(preen, maxrun, docheck, chkit)
77 int preen;
78 int maxrun;
79 int (*docheck)(struct fstab *);
80 int (*chkit)(char *, char *, long, int);
81{
82 register struct fstab *fsp;
83 register struct disk *dk, *nextdisk;
84 register struct part *pt;
85 int ret, pid, retcode, passno, sumstatus, status;
86 long auxdata;
87 char *name;
88
89 sumstatus = 0;
90 for (passno = 1; passno <= 2; passno++) {
91 if (setfsent() == 0) {
96 warnx("can't open checklist file: %s", _PATH_FSTAB);
92 fprintf(stderr, "Can't open checklist file: %s\n",
93 _PATH_FSTAB);
97 return (8);
98 }
99 while ((fsp = getfsent()) != 0) {
100 if ((auxdata = (*docheck)(fsp)) == 0)
101 continue;
102 if (preen == 0 ||
103 (passno == 1 && fsp->fs_passno == 1)) {
104 if ((name = blockcheck(fsp->fs_spec)) != 0) {
105 if ((sumstatus = (*chkit)(name,
106 fsp->fs_file, auxdata, 0)) != 0)
107 return (sumstatus);
108 } else if (preen)
109 return (8);
110 } else if (passno == 2 && fsp->fs_passno > 1) {
111 if ((name = blockcheck(fsp->fs_spec)) == NULL) {
112 fprintf(stderr, "BAD DISK NAME %s\n",
113 fsp->fs_spec);
114 sumstatus |= 8;
115 continue;
116 }
117 addpart(name, fsp->fs_file, auxdata);
118 }
119 }
120 if (preen == 0)
121 return (0);
122 }
123 if (preen) {
124 if (maxrun == 0)
125 maxrun = ndisks;
126 if (maxrun > ndisks)
127 maxrun = ndisks;
128 nextdisk = disks;
129 for (passno = 0; passno < maxrun; ++passno) {
130 while ((ret = startdisk(nextdisk, chkit)) && nrun > 0)
131 sleep(10);
132 if (ret)
133 return (ret);
134 nextdisk = nextdisk->next;
135 }
136 while ((pid = wait(&status)) != -1) {
137 for (dk = disks; dk; dk = dk->next)
138 if (dk->pid == pid)
139 break;
140 if (dk == 0) {
141 printf("Unknown pid %d\n", pid);
142 continue;
143 }
144 if (WIFEXITED(status))
145 retcode = WEXITSTATUS(status);
146 else
147 retcode = 0;
148 if (WIFSIGNALED(status)) {
149 printf("%s (%s): EXITED WITH SIGNAL %d\n",
150 dk->part->name, dk->part->fsname,
151 WTERMSIG(status));
152 retcode = 8;
153 }
154 if (retcode != 0) {
155 sumstatus |= retcode;
156 *badnext = dk->part;
157 badnext = &dk->part->next;
158 dk->part = dk->part->next;
159 *badnext = NULL;
160 } else
161 dk->part = dk->part->next;
162 dk->pid = 0;
163 nrun--;
164 if (dk->part == NULL)
165 ndisks--;
166
167 if (nextdisk == NULL) {
168 if (dk->part) {
169 while ((ret = startdisk(dk, chkit)) &&
170 nrun > 0)
171 sleep(10);
172 if (ret)
173 return (ret);
174 }
175 } else if (nrun < maxrun && nrun < ndisks) {
176 for ( ;; ) {
177 if ((nextdisk = nextdisk->next) == NULL)
178 nextdisk = disks;
179 if (nextdisk->part != NULL &&
180 nextdisk->pid == 0)
181 break;
182 }
183 while ((ret = startdisk(nextdisk, chkit)) &&
184 nrun > 0)
185 sleep(10);
186 if (ret)
187 return (ret);
188 }
189 }
190 }
191 if (sumstatus) {
192 if (badlist == 0)
193 return (sumstatus);
194 fprintf(stderr, "THE FOLLOWING FILE SYSTEM%s HAD AN %s\n\t",
195 badlist->next ? "S" : "", "UNEXPECTED INCONSISTENCY:");
196 for (pt = badlist; pt; pt = pt->next)
197 fprintf(stderr, "%s (%s)%s", pt->name, pt->fsname,
198 pt->next ? ", " : "\n");
199 return (sumstatus);
200 }
201 (void)endfsent();
202 return (0);
203}
204
205static struct disk *
206finddisk(name)
207 char *name;
208{
209 register struct disk *dk, **dkp;
210 register char *p;
211 size_t len;
212
213 p = strrchr(name, '/');
214 p = p == NULL ? name : p + 1;
215 while (*p != '\0' && !isdigit((u_char)*p))
216 p++;
217 while (isdigit((u_char)*p))
218 p++;
219 len = (size_t)(p - name);
220 for (dk = disks, dkp = &disks; dk; dkp = &dk->next, dk = dk->next) {
221 if (strncmp(dk->name, name, len) == 0 &&
222 dk->name[len] == 0)
223 return (dk);
224 }
94 return (8);
95 }
96 while ((fsp = getfsent()) != 0) {
97 if ((auxdata = (*docheck)(fsp)) == 0)
98 continue;
99 if (preen == 0 ||
100 (passno == 1 && fsp->fs_passno == 1)) {
101 if ((name = blockcheck(fsp->fs_spec)) != 0) {
102 if ((sumstatus = (*chkit)(name,
103 fsp->fs_file, auxdata, 0)) != 0)
104 return (sumstatus);
105 } else if (preen)
106 return (8);
107 } else if (passno == 2 && fsp->fs_passno > 1) {
108 if ((name = blockcheck(fsp->fs_spec)) == NULL) {
109 fprintf(stderr, "BAD DISK NAME %s\n",
110 fsp->fs_spec);
111 sumstatus |= 8;
112 continue;
113 }
114 addpart(name, fsp->fs_file, auxdata);
115 }
116 }
117 if (preen == 0)
118 return (0);
119 }
120 if (preen) {
121 if (maxrun == 0)
122 maxrun = ndisks;
123 if (maxrun > ndisks)
124 maxrun = ndisks;
125 nextdisk = disks;
126 for (passno = 0; passno < maxrun; ++passno) {
127 while ((ret = startdisk(nextdisk, chkit)) && nrun > 0)
128 sleep(10);
129 if (ret)
130 return (ret);
131 nextdisk = nextdisk->next;
132 }
133 while ((pid = wait(&status)) != -1) {
134 for (dk = disks; dk; dk = dk->next)
135 if (dk->pid == pid)
136 break;
137 if (dk == 0) {
138 printf("Unknown pid %d\n", pid);
139 continue;
140 }
141 if (WIFEXITED(status))
142 retcode = WEXITSTATUS(status);
143 else
144 retcode = 0;
145 if (WIFSIGNALED(status)) {
146 printf("%s (%s): EXITED WITH SIGNAL %d\n",
147 dk->part->name, dk->part->fsname,
148 WTERMSIG(status));
149 retcode = 8;
150 }
151 if (retcode != 0) {
152 sumstatus |= retcode;
153 *badnext = dk->part;
154 badnext = &dk->part->next;
155 dk->part = dk->part->next;
156 *badnext = NULL;
157 } else
158 dk->part = dk->part->next;
159 dk->pid = 0;
160 nrun--;
161 if (dk->part == NULL)
162 ndisks--;
163
164 if (nextdisk == NULL) {
165 if (dk->part) {
166 while ((ret = startdisk(dk, chkit)) &&
167 nrun > 0)
168 sleep(10);
169 if (ret)
170 return (ret);
171 }
172 } else if (nrun < maxrun && nrun < ndisks) {
173 for ( ;; ) {
174 if ((nextdisk = nextdisk->next) == NULL)
175 nextdisk = disks;
176 if (nextdisk->part != NULL &&
177 nextdisk->pid == 0)
178 break;
179 }
180 while ((ret = startdisk(nextdisk, chkit)) &&
181 nrun > 0)
182 sleep(10);
183 if (ret)
184 return (ret);
185 }
186 }
187 }
188 if (sumstatus) {
189 if (badlist == 0)
190 return (sumstatus);
191 fprintf(stderr, "THE FOLLOWING FILE SYSTEM%s HAD AN %s\n\t",
192 badlist->next ? "S" : "", "UNEXPECTED INCONSISTENCY:");
193 for (pt = badlist; pt; pt = pt->next)
194 fprintf(stderr, "%s (%s)%s", pt->name, pt->fsname,
195 pt->next ? ", " : "\n");
196 return (sumstatus);
197 }
198 (void)endfsent();
199 return (0);
200}
201
202static struct disk *
203finddisk(name)
204 char *name;
205{
206 register struct disk *dk, **dkp;
207 register char *p;
208 size_t len;
209
210 p = strrchr(name, '/');
211 p = p == NULL ? name : p + 1;
212 while (*p != '\0' && !isdigit((u_char)*p))
213 p++;
214 while (isdigit((u_char)*p))
215 p++;
216 len = (size_t)(p - name);
217 for (dk = disks, dkp = &disks; dk; dkp = &dk->next, dk = dk->next) {
218 if (strncmp(dk->name, name, len) == 0 &&
219 dk->name[len] == 0)
220 return (dk);
221 }
225 if ((*dkp = (struct disk *)malloc(sizeof(struct disk))) == NULL)
226 errx(8, "out of memory");
222 if ((*dkp = (struct disk *)malloc(sizeof(struct disk))) == NULL) {
223 fprintf(stderr, "out of memory");
224 exit (8);
225 }
227 dk = *dkp;
226 dk = *dkp;
228 if ((dk->name = malloc(len + 1)) == NULL)
229 errx(8, "out of memory");
227 if ((dk->name = malloc(len + 1)) == NULL) {
228 fprintf(stderr, "out of memory");
229 exit (8);
230 }
230 (void)strncpy(dk->name, name, len);
231 dk->name[len] = '\0';
232 dk->part = NULL;
233 dk->next = NULL;
234 dk->pid = 0;
235 ndisks++;
236 return (dk);
237}
238
239static void
240addpart(name, fsname, auxdata)
241 char *name, *fsname;
242 long auxdata;
243{
244 struct disk *dk = finddisk(name);
245 register struct part *pt, **ppt = &dk->part;
246
247 for (pt = dk->part; pt; ppt = &pt->next, pt = pt->next)
248 if (strcmp(pt->name, name) == 0) {
249 printf("%s in fstab more than once!\n", name);
250 return;
251 }
231 (void)strncpy(dk->name, name, len);
232 dk->name[len] = '\0';
233 dk->part = NULL;
234 dk->next = NULL;
235 dk->pid = 0;
236 ndisks++;
237 return (dk);
238}
239
240static void
241addpart(name, fsname, auxdata)
242 char *name, *fsname;
243 long auxdata;
244{
245 struct disk *dk = finddisk(name);
246 register struct part *pt, **ppt = &dk->part;
247
248 for (pt = dk->part; pt; ppt = &pt->next, pt = pt->next)
249 if (strcmp(pt->name, name) == 0) {
250 printf("%s in fstab more than once!\n", name);
251 return;
252 }
252 if ((*ppt = (struct part *)malloc(sizeof(struct part))) == NULL)
253 errx(8, "out of memory");
253 if ((*ppt = (struct part *)malloc(sizeof(struct part))) == NULL) {
254 fprintf(stderr, "out of memory");
255 exit (8);
256 }
254 pt = *ppt;
257 pt = *ppt;
255 if ((pt->name = malloc(strlen(name) + 1)) == NULL)
256 errx(8, "out of memory");
258 if ((pt->name = malloc(strlen(name) + 1)) == NULL) {
259 fprintf(stderr, "out of memory");
260 exit (8);
261 }
257 (void)strcpy(pt->name, name);
262 (void)strcpy(pt->name, name);
258 if ((pt->fsname = malloc(strlen(fsname) + 1)) == NULL)
259 errx(8, "out of memory");
263 if ((pt->fsname = malloc(strlen(fsname) + 1)) == NULL) {
264 fprintf(stderr, "out of memory");
265 exit (8);
266 }
260 (void)strcpy(pt->fsname, fsname);
261 pt->next = NULL;
262 pt->auxdata = auxdata;
263}
264
265static int
266startdisk(dk, checkit)
267 register struct disk *dk;
268 int (*checkit)(char *, char *, long, int);
269{
270 register struct part *pt = dk->part;
271
272 dk->pid = fork();
273 if (dk->pid < 0) {
267 (void)strcpy(pt->fsname, fsname);
268 pt->next = NULL;
269 pt->auxdata = auxdata;
270}
271
272static int
273startdisk(dk, checkit)
274 register struct disk *dk;
275 int (*checkit)(char *, char *, long, int);
276{
277 register struct part *pt = dk->part;
278
279 dk->pid = fork();
280 if (dk->pid < 0) {
274 warn("fork");
281 perror("fork");
275 return (8);
276 }
277 if (dk->pid == 0)
278 exit((*checkit)(pt->name, pt->fsname, pt->auxdata, 1));
279 nrun++;
280 return (0);
281}
282
283char *
284blockcheck(origname)
285 char *origname;
286{
287 struct stat stslash, stblock, stchar;
288 char *newname, *raw;
289 struct fstab *fsinfo;
282 return (8);
283 }
284 if (dk->pid == 0)
285 exit((*checkit)(pt->name, pt->fsname, pt->auxdata, 1));
286 nrun++;
287 return (0);
288}
289
290char *
291blockcheck(origname)
292 char *origname;
293{
294 struct stat stslash, stblock, stchar;
295 char *newname, *raw;
296 struct fstab *fsinfo;
290 int retried = 0, l;
297 int retried = 0, len;
291
292 hotroot = 0;
293 if (stat("/", &stslash) < 0) {
298
299 hotroot = 0;
300 if (stat("/", &stslash) < 0) {
294 warn("/");
295 printf("Can't stat root\n");
301 printf("Can't stat /: %s\n", strerror(errno));
296 return (origname);
297 }
298 newname = origname;
299retry:
300 if (stat(newname, &stblock) < 0) {
302 return (origname);
303 }
304 newname = origname;
305retry:
306 if (stat(newname, &stblock) < 0) {
301 warn("%s", newname);
302 printf("Can't stat %s\n", newname);
307 printf("Can't stat %s: %s\n", newname, strerror(errno));
303 return (origname);
304 }
305 if ((stblock.st_mode & S_IFMT) == S_IFBLK) {
306 if (stslash.st_dev == stblock.st_rdev)
307 hotroot++;
308 raw = rawname(newname);
309 if (stat(raw, &stchar) < 0) {
308 return (origname);
309 }
310 if ((stblock.st_mode & S_IFMT) == S_IFBLK) {
311 if (stslash.st_dev == stblock.st_rdev)
312 hotroot++;
313 raw = rawname(newname);
314 if (stat(raw, &stchar) < 0) {
310 warn("%s", raw);
311 printf("Can't stat %s\n", raw);
315 printf("Can't stat %s: %s\n", raw, strerror(errno));
312 return (origname);
313 }
314 if ((stchar.st_mode & S_IFMT) == S_IFCHR) {
315 return (raw);
316 } else {
317 printf("%s is not a character device\n", raw);
318 return (origname);
319 }
320 } else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) {
316 return (origname);
317 }
318 if ((stchar.st_mode & S_IFMT) == S_IFCHR) {
319 return (raw);
320 } else {
321 printf("%s is not a character device\n", raw);
322 return (origname);
323 }
324 } else if ((stblock.st_mode & S_IFMT) == S_IFCHR && !retried) {
321 newname = unrawname(origname);
325 newname = unrawname(newname);
322 retried++;
323 goto retry;
324 } else if ((stblock.st_mode & S_IFMT) == S_IFDIR && !retried) {
326 retried++;
327 goto retry;
328 } else if ((stblock.st_mode & S_IFMT) == S_IFDIR && !retried) {
325 l = strlen(origname) - 1;
326 if (l > 0 && origname[l] == '/')
329 len = strlen(origname) - 1;
330 if (len > 0 && origname[len] == '/')
327 /* remove trailing slash */
331 /* remove trailing slash */
328 origname[l] = '\0';
329 if(!(fsinfo=getfsfile(origname))) {
332 origname[len] = '\0';
333 if ((fsinfo = getfsfile(origname)) == NULL) {
330 printf("Can't resolve %s to character special device",
331 origname);
332 return (0);
333 }
334 newname = fsinfo->fs_spec;
335 retried++;
336 goto retry;
337 }
338 /*
339 * Not a block or character device, just return name and
340 * let the user decide whether to use it.
341 */
342 return (origname);
343}
344
345static char *
346unrawname(name)
347 char *name;
348{
349 char *dp;
350 struct stat stb;
351
352 if ((dp = strrchr(name, '/')) == 0)
353 return (name);
354 if (stat(name, &stb) < 0)
355 return (name);
356 if ((stb.st_mode & S_IFMT) != S_IFCHR)
357 return (name);
358 if (dp[1] != 'r')
359 return (name);
360 (void)strcpy(&dp[1], &dp[2]);
361 return (name);
362}
363
364static char *
365rawname(name)
366 char *name;
367{
368 static char rawbuf[32];
369 char *dp;
370
371 if ((dp = strrchr(name, '/')) == 0)
372 return (0);
373 *dp = 0;
374 (void)strcpy(rawbuf, name);
375 *dp = '/';
376 (void)strcat(rawbuf, "/r");
377 (void)strcat(rawbuf, &dp[1]);
378 return (rawbuf);
379}
334 printf("Can't resolve %s to character special device",
335 origname);
336 return (0);
337 }
338 newname = fsinfo->fs_spec;
339 retried++;
340 goto retry;
341 }
342 /*
343 * Not a block or character device, just return name and
344 * let the user decide whether to use it.
345 */
346 return (origname);
347}
348
349static char *
350unrawname(name)
351 char *name;
352{
353 char *dp;
354 struct stat stb;
355
356 if ((dp = strrchr(name, '/')) == 0)
357 return (name);
358 if (stat(name, &stb) < 0)
359 return (name);
360 if ((stb.st_mode & S_IFMT) != S_IFCHR)
361 return (name);
362 if (dp[1] != 'r')
363 return (name);
364 (void)strcpy(&dp[1], &dp[2]);
365 return (name);
366}
367
368static char *
369rawname(name)
370 char *name;
371{
372 static char rawbuf[32];
373 char *dp;
374
375 if ((dp = strrchr(name, '/')) == 0)
376 return (0);
377 *dp = 0;
378 (void)strcpy(rawbuf, name);
379 *dp = '/';
380 (void)strcat(rawbuf, "/r");
381 (void)strcat(rawbuf, &dp[1]);
382 return (rawbuf);
383}