diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-09-11 08:15:27 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-09-11 08:15:27 +0000 |
commit | d9dbae43a0b5148ad80d16c0107c820b515b273f (patch) | |
tree | 2e51b56685d62ad6391bd290f17d689061bf339e /sbin | |
parent | d6cdb2f839a55626b56b418af9b4ed781c03394e (diff) |
from ws@netbsd; Fix a few bugs, especially when repairing disks:
Print correct pathname in error messages
Fix unterminating loop when trying to correct a bad fat
Require fat media byte to be the same as the one in the bpb
Fix unterminating loop when looking for free directory slot in LOST.DIR
(bad disk image provided by Christoph Badura)
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/fsck_msdos/dir.c | 25 | ||||
-rw-r--r-- | sbin/fsck_msdos/fat.c | 37 |
2 files changed, 26 insertions, 36 deletions
diff --git a/sbin/fsck_msdos/dir.c b/sbin/fsck_msdos/dir.c index 4c5fe5ee4f9..46f70a2dfd6 100644 --- a/sbin/fsck_msdos/dir.c +++ b/sbin/fsck_msdos/dir.c @@ -1,5 +1,5 @@ -/* $OpenBSD: dir.c,v 1.7 1997/03/02 05:25:53 millert Exp $ */ -/* $NetBSD: dir.c,v 1.8 1996/09/27 23:22:52 christos Exp $ */ +/* $OpenBSD: dir.c,v 1.8 1997/09/11 08:15:24 deraadt Exp $ */ +/* NetBSD: dir.c,v 1.9 1997/09/08 14:05:30 ws Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank @@ -37,7 +37,7 @@ #ifndef lint -static char rcsid[] = "$OpenBSD: dir.c,v 1.7 1997/03/02 05:25:53 millert Exp $"; +static char rcsid[] = "$OpenBSD: dir.c,v 1.8 1997/09/11 08:15:24 deraadt Exp $"; #endif /* not lint */ #include <stdio.h> @@ -186,6 +186,8 @@ fullpath(dir) } while ((dir = dir->parent) != NULL); if (dir != NULL && dir->parent != NULL) *--cp = '?'; + else + cp++; return (cp); } @@ -653,7 +655,9 @@ readDosDirSection(f, boot, fat, dir) } vallfn = NULL; /* not used any longer */ invlfn = NULL; - + dirent.parent = dir; + dirent.next = dir->child; + if (dirent.size == 0 && !(dirent.flags & ATTR_DIRECTORY)) { if (dirent.head != 0) { pwarn("%s has clusters, but size 0\n", @@ -714,8 +718,6 @@ readDosDirSection(f, boot, fat, dir) } } - dirent.parent = dir; - dirent.next = dir->child; if (dirent.head >= CLUST_FIRST && dirent.head < boot->NumClusters) fat[dirent.head].flags |= FAT_USED; @@ -768,14 +770,11 @@ readDosDirSection(f, boot, fat, dir) continue; } - boot->NumFiles++; - /* create directory tree node */ if (!(d = newDosDirEntry())) { perror("No space for directory"); return (FSFATAL); } - (void)memcpy(d, &dirent, sizeof(struct dosDirEntry)); /* link it into the tree */ dir->child = d; @@ -792,8 +791,8 @@ readDosDirSection(f, boot, fat, dir) mod |= k = checksize(boot, fat, p, &dirent); if (k & FSDIRMOD) mod |= THISMOD; - boot->NumFiles++; } + boot->NumFiles++; } if (mod & THISMOD) { last *= 32; @@ -901,7 +900,7 @@ reconnect(dosfs, boot, fat, head) p = lfbuf; while (1) { if (p) - while (p < lfbuf + boot->ClusterSize) + for (; p < lfbuf + boot->ClusterSize; p += 32) if (*p == SLOT_EMPTY || *p == SLOT_DELETED) break; @@ -916,7 +915,7 @@ reconnect(dosfs, boot, fat, head) lfoff = lfcl * boot->ClusterSize + boot->ClusterOffset * boot->BytesPerSec; if (lseek(dosfs, lfoff, SEEK_SET) != lfoff - || read(dosfs, buffer, boot->ClusterSize) != boot->ClusterSize) { + || read(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) { perror("could not read LOST.DIR"); return (FSFATAL); } @@ -945,7 +944,7 @@ reconnect(dosfs, boot, fat, head) p[31] = (u_char)(d.size >> 24); fat[head].flags |= FAT_USED; if (lseek(dosfs, lfoff, SEEK_SET) != lfoff - || write(dosfs, buffer, boot->ClusterSize) != boot->ClusterSize) { + || write(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) { perror("could not write LOST.DIR"); return (FSFATAL); } diff --git a/sbin/fsck_msdos/fat.c b/sbin/fsck_msdos/fat.c index 1c8c4a035ce..116322de1dc 100644 --- a/sbin/fsck_msdos/fat.c +++ b/sbin/fsck_msdos/fat.c @@ -1,5 +1,5 @@ -/* $OpenBSD: fat.c,v 1.5 1997/03/02 05:25:55 millert Exp $ */ -/* $NetBSD: fat.c,v 1.5 1997/01/03 14:32:49 ws Exp $ */ +/* $OpenBSD: fat.c,v 1.6 1997/09/11 08:15:26 deraadt Exp $ */ +/* $NetBSD: fat.c,v 1.6 1997/09/08 14:05:31 ws Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank @@ -35,7 +35,7 @@ #ifndef lint -static char rcsid[] = "$OpenBSD: fat.c,v 1.5 1997/03/02 05:25:55 millert Exp $"; +static char rcsid[] = "$OpenBSD: fat.c,v 1.6 1997/09/11 08:15:26 deraadt Exp $"; #endif /* not lint */ #include <stdlib.h> @@ -140,7 +140,8 @@ readfat(fs, boot, no, fp) fat[0].length = buffer[0]|(buffer[1] << 8)|(buffer[2] << 16); if (boot->Is16BitFat) fat[0].length |= buffer[3] << 24; - if (buffer[1] != 0xff || buffer[2] != 0xff + if (buffer[0] != boot->Media + || buffer[1] != 0xff || buffer[2] != 0xff || (boot->Is16BitFat && buffer[3] != 0xff)) { char *msg = boot->Is16BitFat ? "FAT starts with odd byte sequence (%02x%02x%02x%02x)\n" @@ -273,18 +274,6 @@ comparefat(boot, first, second, fatnum) cl_t cl; int ret = FSOK; - if (first[0].next != second[0].next) { - pwarn("Media bytes in cluster 1(%02x) and %d(%02x) differ\n", - first[0].next, fatnum, second[0].next); - if (ask(1, "Use media byte from FAT 1")) { - second[0].next = first[0].next; - ret |= FSFATMOD; - } else if (ask(0, "Use media byte from FAT %d", fatnum)) { - first[0].next = second[0].next; - ret |= FSFATMOD; - } else - ret |= FSERROR; - } for (cl = CLUST_FIRST; cl < boot->NumClusters; cl++) if (first[cl].next != second[cl].next) ret |= clustdiffer(cl, &first[cl].next, &second[cl].next, fatnum); @@ -326,7 +315,7 @@ checkfat(boot, fat) */ for (head = CLUST_FIRST; head < boot->NumClusters; head++) { /* find next untraveled chain */ - if (fat[head].head != 0 /* cluster already belongs to some chain*/ + if (fat[head].head != 0 /* cluster already belongs to some chain */ || fat[head].next == CLUST_FREE || fat[head].next == CLUST_BAD) continue; /* skip it. */ @@ -446,16 +435,18 @@ writefat(fs, boot, fat) } (void)memset(buffer, 0, fatsz); boot->NumFree = 0; - buffer[0] = (u_char)fat[0].length; - buffer[1] = (u_char)(fat[0].length >> 8); + p = buffer; + *p++ = (u_char)fat[0].length; + *p++ = (u_char)(fat[0].length >> 8); + *p++ = (u_char)(fat[0].length >> 16); if (boot->Is16BitFat) - buffer[3] = (u_char)(fat[0].length >> 24); - for (cl = CLUST_FIRST, p = buffer; cl < boot->NumClusters;) { + *p++ = (u_char)(fat[0].length >> 24); + for (cl = CLUST_FIRST; cl < boot->NumClusters; cl++) { if (boot->Is16BitFat) { p[0] = (u_char)fat[cl].next; if (fat[cl].next == CLUST_FREE) boot->NumFree++; - p[1] = (u_char)(fat[cl++].next >> 8); + p[1] = (u_char)(fat[cl].next >> 8); p += 2; } else { if (fat[cl].next == CLUST_FREE) @@ -466,7 +457,7 @@ writefat(fs, boot, fat) p[0] = (u_char)fat[cl].next; p[1] = (u_char)((fat[cl].next >> 8) & 0xf) |(u_char)(fat[cl+1].next << 4); - p[2] = (u_char)(fat[cl++].next >> 8); + p[2] = (u_char)(fat[++cl].next >> 4); p += 3; } } |