diff --git a/sbin/fsck_msdos/dir.c b/sbin/fsck_msdos/dir.c index 2c1de8e1604a..5b3e26702ede 100644 --- a/sbin/fsck_msdos/dir.c +++ b/sbin/fsck_msdos/dir.c @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.8 1996/09/27 23:22:52 christos Exp $ */ +/* $NetBSD: dir.c,v 1.9 1997/09/08 14:05:30 ws Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank @@ -36,7 +36,7 @@ #ifndef lint -static char rcsid[] = "$NetBSD: dir.c,v 1.8 1996/09/27 23:22:52 christos Exp $"; +static char rcsid[] = "$NetBSD: dir.c,v 1.9 1997/09/08 14:05:30 ws Exp $"; #endif /* not lint */ #include @@ -187,6 +187,8 @@ fullpath(dir) } while ((dir = dir->parent) != NULL); if (dir) *--cp = '?'; + else + cp++; return cp; } @@ -654,6 +656,8 @@ 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) { @@ -715,8 +719,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; @@ -769,14 +771,11 @@ readDosDirSection(f, boot, fat, dir) continue; } - boot->NumFiles++; - /* create directory tree node */ if (!(d = newDosDirEntry())) { perror("No space for directory"); return FSFATAL; } - memcpy(d, &dirent, sizeof(struct dosDirEntry)); /* link it into the tree */ dir->child = d; @@ -793,8 +792,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; @@ -902,7 +901,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; @@ -917,7 +916,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; } @@ -946,7 +945,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 9e5d3f97190e..999c95402a43 100644 --- a/sbin/fsck_msdos/fat.c +++ b/sbin/fsck_msdos/fat.c @@ -1,4 +1,4 @@ -/* $NetBSD: fat.c,v 1.5 1997/01/03 14:32:49 ws Exp $ */ +/* $NetBSD: fat.c,v 1.6 1997/09/08 14:05:31 ws Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank @@ -34,7 +34,7 @@ #ifndef lint -static char rcsid[] = "$NetBSD: fat.c,v 1.5 1997/01/03 14:32:49 ws Exp $"; +static char rcsid[] = "$NetBSD: fat.c,v 1.6 1997/09/08 14:05:31 ws Exp $"; #endif /* not lint */ #include @@ -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) } 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; } }