CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: kamil Date: Sat Feb 22 09:59:22 UTC 2020 Modified Files: src/sbin/fsck_msdos: boot.c Log Message: Avoid unportable shift construct boot.c:150:29, left shift of 255 by 24 places cannot be represented in type 'int' boot.c:153:29, left shift of 255 by 24 places cannot be represented in type 'int' To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/sbin/fsck_msdos/boot.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/boot.c diff -u src/sbin/fsck_msdos/boot.c:1.22 src/sbin/fsck_msdos/boot.c:1.23 --- src/sbin/fsck_msdos/boot.c:1.22 Sat Jan 11 16:29:07 2020 +++ src/sbin/fsck_msdos/boot.c Sat Feb 22 09:59:22 2020 @@ -27,7 +27,7 @@ #include #ifndef lint -__RCSID("$NetBSD: boot.c,v 1.22 2020/01/11 16:29:07 christos Exp $"); +__RCSID("$NetBSD: boot.c,v 1.23 2020/02/22 09:59:22 kamil Exp $"); #endif /* not lint */ #include @@ -81,8 +81,8 @@ readboot(int dosfs, struct bootblock *bo boot->FATsmall = block[22] + (block[23] << 8); boot->SecPerTrack = block[24] + (block[25] << 8); boot->Heads = block[26] + (block[27] << 8); - boot->HiddenSecs = block[28] + (block[29] << 8) + (block[30] << 16) + (block[31] << 24); - boot->HugeSectors = block[32] + (block[33] << 8) + (block[34] << 16) + (block[35] << 24); + boot->HiddenSecs = block[28] + (block[29] << 8) + (block[30] << 16) + ((uint32_t)block[31] << 24); + boot->HugeSectors = block[32] + (block[33] << 8) + (block[34] << 16) + ((uint32_t)block[35] << 24); boot->FATsecs = boot->FATsmall; @@ -90,7 +90,7 @@ readboot(int dosfs, struct bootblock *bo boot->flags |= FAT32; if (boot->flags & FAT32) { boot->FATsecs = block[36] + (block[37] << 8) -+ (block[38] << 16) + (block[39] << 24); ++ (block[38] << 16) + ((uint32_t)block[39] << 24); if (block[40] & 0x80) boot->ValidFat = block[40] & 0x0f; @@ -102,7 +102,7 @@ readboot(int dosfs, struct bootblock *bo return FSFATAL; } boot->RootCl = block[44] + (block[45] << 8) - + (block[46] << 16) + (block[47] << 24); + + (block[46] << 16) + ((uint32_t)block[47] << 24); boot->FSInfo = block[48] + (block[49] << 8); boot->Backup = block[50] + (block[51] << 8); @@ -147,10 +147,10 @@ readboot(int dosfs, struct bootblock *bo if (boot->FSInfo) { boot->FSFree = fsinfo[0x1e8] + (fsinfo[0x1e9] << 8) + (fsinfo[0x1ea] << 16) - + (fsinfo[0x1eb] << 24); + + ((uint32_t)fsinfo[0x1eb] << 24); boot->FSNext = fsinfo[0x1ec] + (fsinfo[0x1ed] << 8) + (fsinfo[0x1ee] << 16) - + (fsinfo[0x1ef] << 24); + + ((uint32_t)fsinfo[0x1ef] << 24); } if (lseek(dosfs, boot->Backup * boot->BytesPerSec, SEEK_SET)
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: christos Date: Sat Jan 11 16:29:07 UTC 2020 Modified Files: src/sbin/fsck_msdos: boot.c Log Message: Don't add the 2 reserved clusters before we determine if we using fat16/fat32. >From FreeBSD: https://reviews.freebsd.org/D23082: Correct off-by-two issue when determining FAT type. In the code we used NumClusters as the upper (non-inclusive) boundary of valid cluster number, so the actual value was 2 (CLUST_FIRST) more than the real number of clusters. This causes a FAT16 media with 65524 clusters be treated as FAT32 and might affect FAT12 media with 4084 clusters as well. To fix this, we increment NumClusters by CLUST_FIRST after the type determination. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/sbin/fsck_msdos/boot.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/boot.c diff -u src/sbin/fsck_msdos/boot.c:1.21 src/sbin/fsck_msdos/boot.c:1.22 --- src/sbin/fsck_msdos/boot.c:1.21 Thu Feb 8 04:05:17 2018 +++ src/sbin/fsck_msdos/boot.c Sat Jan 11 11:29:07 2020 @@ -27,7 +27,7 @@ #include #ifndef lint -__RCSID("$NetBSD: boot.c,v 1.21 2018/02/08 09:05:17 dholland Exp $"); +__RCSID("$NetBSD: boot.c,v 1.22 2020/01/11 16:29:07 christos Exp $"); #endif /* not lint */ #include @@ -210,8 +210,12 @@ readboot(int dosfs, struct bootblock *bo return FSFATAL; } - boot->NumClusters = (boot->NumSectors - boot->FirstCluster) / boot->SecPerClust - + CLUST_FIRST; + /* + * The number of clusters is derived from available data sectors, + * divided by sectors per cluster. + */ + boot->NumClusters = + (boot->NumSectors - boot->FirstCluster) / boot->SecPerClust; if (boot->flags) boot->ClustMask = CLUST32_MASK; @@ -237,11 +241,19 @@ readboot(int dosfs, struct bootblock *bo break; } - if (boot->NumFatEntries < boot->NumClusters - CLUST_FIRST) { + if (boot->NumFatEntries < boot->NumClusters) { pfatal("FAT size too small, %u entries won't fit into %u sectors\n", boot->NumClusters, boot->FATsecs); return FSFATAL; } + + /* + * There are two reserved clusters. To avoid adding CLUST_FIRST every + * time we perform boundary checks, we increment the NumClusters by 2, + * which is CLUST_FIRST to denote the first out-of-range cluster number. + */ + boot->NumClusters += CLUST_FIRST; + boot->ClusterSize = boot->BytesPerSec * boot->SecPerClust; boot->NumFiles = 1;
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: christos Date: Fri Apr 28 11:33:00 UTC 2017 Modified Files: src/sbin/fsck_msdos: dir.c Log Message: Prevent SEGV on corrupted msdos directories (Veo Zhang) To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/sbin/fsck_msdos/dir.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/dir.c diff -u src/sbin/fsck_msdos/dir.c:1.28 src/sbin/fsck_msdos/dir.c:1.29 --- src/sbin/fsck_msdos/dir.c:1.28 Mon Mar 7 09:47:25 2016 +++ src/sbin/fsck_msdos/dir.c Fri Apr 28 07:33:00 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.28 2016/03/07 14:47:25 christos Exp $ */ +/* $NetBSD: dir.c,v 1.29 2017/04/28 11:33:00 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -30,7 +30,7 @@ #include #ifndef lint -__RCSID("$NetBSD: dir.c,v 1.28 2016/03/07 14:47:25 christos Exp $"); +__RCSID("$NetBSD: dir.c,v 1.29 2017/04/28 11:33:00 christos Exp $"); #endif /* not lint */ #include @@ -623,7 +623,7 @@ readDosDirSection(int f, struct bootbloc dirent.name[8] = '\0'; for (k = 7; k >= 0 && dirent.name[k] == ' '; k--) dirent.name[k] = '\0'; - if (dirent.name[k] != '\0') + if (k < 0 || dirent.name[k] != '\0') k++; if (dirent.name[0] == SLOT_E5) dirent.name[0] = 0xe5;
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: sevan Date: Sun Sep 11 04:12:08 UTC 2016 Modified Files: src/sbin/fsck_msdos: fsck_msdos.8 Log Message: Document the version fsck_msdos first appeared. Bump date. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/sbin/fsck_msdos/fsck_msdos.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/fsck_msdos.8 diff -u src/sbin/fsck_msdos/fsck_msdos.8:1.17 src/sbin/fsck_msdos/fsck_msdos.8:1.18 --- src/sbin/fsck_msdos/fsck_msdos.8:1.17 Sun Apr 11 21:29:37 2010 +++ src/sbin/fsck_msdos/fsck_msdos.8 Sun Sep 11 04:12:08 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: fsck_msdos.8,v 1.17 2010/04/11 21:29:37 wiz Exp $ +.\" $NetBSD: fsck_msdos.8,v 1.18 2016/09/11 04:12:08 sevan Exp $ .\" .\" Copyright (C) 1995 Wolfgang Solfrank .\" Copyright (c) 1995 Martin Husemann @@ -24,7 +24,7 @@ .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .\" -.Dd April 11, 2010 +.Dd September 11, 2016 .Dt FSCK_MSDOS 8 .Os .Sh NAME @@ -109,6 +109,11 @@ to assume yes as the answer to all opera .Xr fsck 8 , .Xr fsck_ffs 8 , .Xr mount_msdos 8 +.Sh HISTORY +A +.Nm +utility appeared in +.Nx 1.2 . .Sh BUGS .Nm is still under construction.
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: jakllsch Date: Mon May 2 17:33:04 UTC 2016 Modified Files: src/sbin/fsck_msdos: boot.c Log Message: The on-disk FAT array does not include anything before CLUST_FIRST, compensate in size check. This was tickled by my SanDisk Sansa Clip 4GB, which exactly filled the FAT array. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sbin/fsck_msdos/boot.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/boot.c diff -u src/sbin/fsck_msdos/boot.c:1.19 src/sbin/fsck_msdos/boot.c:1.20 --- src/sbin/fsck_msdos/boot.c:1.19 Fri Jan 2 06:21:28 2015 +++ src/sbin/fsck_msdos/boot.c Mon May 2 17:33:03 2016 @@ -27,7 +27,7 @@ #include #ifndef lint -__RCSID("$NetBSD: boot.c,v 1.19 2015/01/02 06:21:28 mlelstv Exp $"); +__RCSID("$NetBSD: boot.c,v 1.20 2016/05/02 17:33:03 jakllsch Exp $"); #endif /* not lint */ #include @@ -237,7 +237,7 @@ readboot(int dosfs, struct bootblock *bo break; } - if (boot->NumFatEntries < boot->NumClusters) { + if (boot->NumFatEntries < boot->NumClusters - CLUST_FIRST) { pfatal("FAT size too small, %u entries won't fit into %u sectors\n", boot->NumClusters, boot->FATsecs); return FSFATAL;
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: christos Date: Mon Mar 7 14:47:25 UTC 2016 Modified Files: src/sbin/fsck_msdos: dir.c Log Message: PR/50908: David Binderman: Optimize memset's To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/sbin/fsck_msdos/dir.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/dir.c diff -u src/sbin/fsck_msdos/dir.c:1.27 src/sbin/fsck_msdos/dir.c:1.28 --- src/sbin/fsck_msdos/dir.c:1.27 Fri Jan 2 01:21:28 2015 +++ src/sbin/fsck_msdos/dir.c Mon Mar 7 09:47:25 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.27 2015/01/02 06:21:28 mlelstv Exp $ */ +/* $NetBSD: dir.c,v 1.28 2016/03/07 14:47:25 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -30,7 +30,7 @@ #include #ifndef lint -__RCSID("$NetBSD: dir.c,v 1.27 2015/01/02 06:21:28 mlelstv Exp $"); +__RCSID("$NetBSD: dir.c,v 1.28 2016/03/07 14:47:25 christos Exp $"); #endif /* not lint */ #include @@ -929,6 +929,7 @@ int reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head) { struct dosDirEntry d; + int len; u_char *p; if (!ask(1, "Reconnect")) @@ -980,14 +981,15 @@ reconnect(int dosfs, struct bootblock *b boot->NumFiles++; /* Ensure uniqueness of entry here!XXX */ memset(, 0, sizeof d); - (void)snprintf(d.name, sizeof(d.name), "%u", head); + /* worst case -1 = 4294967295, 10 digits */ + len = snprintf(d.name, sizeof(d.name), "%u", head); d.flags = 0; d.head = head; d.size = fat[head].length * boot->ClusterSize; - memset(p, 0, 32); - memset(p, ' ', 11); - memcpy(p, d.name, strlen(d.name)); + memcpy(p, d.name, len); + memset(p + len, ' ', 11 - len); + memset(p + 11, 0, 32 - 11); p[26] = (u_char)d.head; p[27] = (u_char)(d.head >> 8); if (boot->ClustMask == CLUST32_MASK) {
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: mlelstv Date: Fri Jan 2 06:21:28 UTC 2015 Modified Files: src/sbin/fsck_msdos: boot.c dir.c dosfs.h Log Message: Avoid mixing cluster numbers and sector numbers. Makes code more readable. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sbin/fsck_msdos/boot.c cvs rdiff -u -r1.26 -r1.27 src/sbin/fsck_msdos/dir.c cvs rdiff -u -r1.7 -r1.8 src/sbin/fsck_msdos/dosfs.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/boot.c diff -u src/sbin/fsck_msdos/boot.c:1.18 src/sbin/fsck_msdos/boot.c:1.19 --- src/sbin/fsck_msdos/boot.c:1.18 Tue Nov 4 03:05:43 2014 +++ src/sbin/fsck_msdos/boot.c Fri Jan 2 06:21:28 2015 @@ -27,7 +27,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: boot.c,v 1.18 2014/11/04 03:05:43 msaitoh Exp $); +__RCSID($NetBSD: boot.c,v 1.19 2015/01/02 06:21:28 mlelstv Exp $); #endif /* not lint */ #include stdlib.h @@ -185,11 +185,10 @@ readboot(int dosfs, struct bootblock *bo return FSFATAL; } - boot-ClusterOffset = (int)(boot-RootDirEnts * 32 + boot-BytesPerSec - 1) + boot-FirstCluster = (boot-RootDirEnts * 32 + boot-BytesPerSec - 1) / boot-BytesPerSec + boot-ResSectors - + boot-FATs * boot-FATsecs - - CLUST_FIRST * boot-SecPerClust; + + boot-FATs * boot-FATsecs; if (boot-BytesPerSec % DOSBOOTBLOCKSIZE != 0) { pfatal(Invalid sector size: %u, boot-BytesPerSec); @@ -204,14 +203,16 @@ readboot(int dosfs, struct bootblock *bo boot-NumSectors = boot-Sectors; } else boot-NumSectors = boot-HugeSectors; - boot-NumClusters = (boot-NumSectors - boot-ClusterOffset) / boot-SecPerClust; - if (boot-ClusterOffset (intmax_t)boot-NumSectors) { - pfatal(Cluster offset too large (%d sectors)\n, - boot-ClusterOffset); + if (boot-FirstCluster + boot-SecPerClust boot-NumSectors) { + pfatal(Cluster offset too large (%u clusters)\n, + boot-FirstCluster); return FSFATAL; } + boot-NumClusters = (boot-NumSectors - boot-FirstCluster) / boot-SecPerClust + + CLUST_FIRST; + if (boot-flagsFAT32) boot-ClustMask = CLUST32_MASK; else if (boot-NumClusters (CLUST_RSRVDCLUST12_MASK)) Index: src/sbin/fsck_msdos/dir.c diff -u src/sbin/fsck_msdos/dir.c:1.26 src/sbin/fsck_msdos/dir.c:1.27 --- src/sbin/fsck_msdos/dir.c:1.26 Mon Jul 7 17:45:42 2014 +++ src/sbin/fsck_msdos/dir.c Fri Jan 2 06:21:28 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.26 2014/07/07 17:45:42 christos Exp $ */ +/* $NetBSD: dir.c,v 1.27 2015/01/02 06:21:28 mlelstv Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -30,7 +30,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: dir.c,v 1.26 2014/07/07 17:45:42 christos Exp $); +__RCSID($NetBSD: dir.c,v 1.27 2015/01/02 06:21:28 mlelstv Exp $); #endif /* not lint */ #include stdio.h @@ -326,7 +326,7 @@ delete(int f, struct bootblock *boot, st break; e = delbuf + endoff; } - off = startcl * boot-SecPerClust + boot-ClusterOffset; + off = (startcl - CLUST_FIRST) * boot-SecPerClust + boot-FirstCluster; off *= boot-BytesPerSec; if (lseek(f, off, SEEK_SET) != off || read(f, delbuf, clsz) != clsz) { @@ -491,7 +491,7 @@ readDosDirSection(int f, struct bootbloc off = boot-ResSectors + boot-FATs * boot-FATsecs; } else { last = boot-SecPerClust * boot-BytesPerSec; - off = cl * boot-SecPerClust + boot-ClusterOffset; + off = (cl - CLUST_FIRST) * boot-SecPerClust + boot-FirstCluster; } off *= boot-BytesPerSec; @@ -967,8 +967,8 @@ reconnect(int dosfs, struct bootblock *b pwarn(No space in %s\n, LOSTDIR); return FSERROR; } - lfoff = lfcl * boot-ClusterSize - + boot-ClusterOffset * boot-BytesPerSec; + lfoff = (lfcl - CLUST_FIRST) * boot-ClusterSize + + boot-FirstCluster * boot-BytesPerSec; if (lseek(dosfs, lfoff, SEEK_SET) != lfoff || (size_t)read(dosfs, lfbuf, boot-ClusterSize) != boot-ClusterSize) { perr(could not read LOST.DIR); Index: src/sbin/fsck_msdos/dosfs.h diff -u src/sbin/fsck_msdos/dosfs.h:1.7 src/sbin/fsck_msdos/dosfs.h:1.8 --- src/sbin/fsck_msdos/dosfs.h:1.7 Mon Nov 3 18:55:04 2014 +++ src/sbin/fsck_msdos/dosfs.h Fri Jan 2 06:21:28 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: dosfs.h,v 1.7 2014/11/03 18:55:04 jakllsch Exp $ */ +/* $NetBSD: dosfs.h,v 1.8 2015/01/02 06:21:28 mlelstv Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -70,7 +70,7 @@ struct bootblock { u_int32_t NumSectors; /* how many sectors are there */ u_int32_t FATsecs; /* how many sectors are in FAT */ u_int32_t NumFatEntries; /* how many entries really are there */ - int ClusterOffset; /* at what sector would sector 0 start */ + u_int FirstCluster; /* at what sector is Cluster CLUST_FIRST */ u_int ClusterSize; /* Cluster size in bytes */ /* Now some statistics: */
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: jakllsch Date: Mon Nov 3 18:55:04 UTC 2014 Modified Files: src/sbin/fsck_msdos: boot.c dosfs.h Log Message: ClusterOffset actually needs to be able to be negative. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sbin/fsck_msdos/boot.c cvs rdiff -u -r1.6 -r1.7 src/sbin/fsck_msdos/dosfs.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/boot.c diff -u src/sbin/fsck_msdos/boot.c:1.16 src/sbin/fsck_msdos/boot.c:1.17 --- src/sbin/fsck_msdos/boot.c:1.16 Mon Jul 7 19:04:37 2014 +++ src/sbin/fsck_msdos/boot.c Mon Nov 3 18:55:04 2014 @@ -27,7 +27,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: boot.c,v 1.16 2014/07/07 19:04:37 christos Exp $); +__RCSID($NetBSD: boot.c,v 1.17 2014/11/03 18:55:04 jakllsch Exp $); #endif /* not lint */ #include stdlib.h @@ -184,7 +184,7 @@ readboot(int dosfs, struct bootblock *bo return FSFATAL; } - boot-ClusterOffset = (boot-RootDirEnts * 32 + boot-BytesPerSec - 1) + boot-ClusterOffset = (int)(boot-RootDirEnts * 32 + boot-BytesPerSec - 1) / boot-BytesPerSec + boot-ResSectors + boot-FATs * boot-FATsecs @@ -205,8 +205,8 @@ readboot(int dosfs, struct bootblock *bo boot-NumSectors = boot-HugeSectors; boot-NumClusters = (boot-NumSectors - boot-ClusterOffset) / boot-SecPerClust; - if (boot-ClusterOffset boot-NumSectors) { - pfatal(Cluster offset too large (%u clusters)\n, + if (boot-ClusterOffset (intmax_t)boot-NumSectors) { + pfatal(Cluster offset too large (%d sectors)\n, boot-ClusterOffset); return FSFATAL; } Index: src/sbin/fsck_msdos/dosfs.h diff -u src/sbin/fsck_msdos/dosfs.h:1.6 src/sbin/fsck_msdos/dosfs.h:1.7 --- src/sbin/fsck_msdos/dosfs.h:1.6 Fri Jun 13 20:46:09 2008 +++ src/sbin/fsck_msdos/dosfs.h Mon Nov 3 18:55:04 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: dosfs.h,v 1.6 2008/06/13 20:46:09 martin Exp $ */ +/* $NetBSD: dosfs.h,v 1.7 2014/11/03 18:55:04 jakllsch Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -70,7 +70,7 @@ struct bootblock { u_int32_t NumSectors; /* how many sectors are there */ u_int32_t FATsecs; /* how many sectors are in FAT */ u_int32_t NumFatEntries; /* how many entries really are there */ - u_int ClusterOffset; /* at what sector would sector 0 start */ + int ClusterOffset; /* at what sector would sector 0 start */ u_int ClusterSize; /* Cluster size in bytes */ /* Now some statistics: */
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: msaitoh Date: Tue Nov 4 03:05:43 UTC 2014 Modified Files: src/sbin/fsck_msdos: boot.c Log Message: Add #include inttypes.h for intmax_t to fix compile error. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/sbin/fsck_msdos/boot.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/boot.c diff -u src/sbin/fsck_msdos/boot.c:1.17 src/sbin/fsck_msdos/boot.c:1.18 --- src/sbin/fsck_msdos/boot.c:1.17 Mon Nov 3 18:55:04 2014 +++ src/sbin/fsck_msdos/boot.c Tue Nov 4 03:05:43 2014 @@ -27,12 +27,13 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: boot.c,v 1.17 2014/11/03 18:55:04 jakllsch Exp $); +__RCSID($NetBSD: boot.c,v 1.18 2014/11/04 03:05:43 msaitoh Exp $); #endif /* not lint */ #include stdlib.h #include string.h #include strings.h +#include inttypes.h #include stdio.h #include unistd.h
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: christos Date: Fri Jul 11 14:59:53 UTC 2014 Modified Files: src/sbin/fsck_msdos: fat.c Log Message: Another infinite loop fix from OpenBSD from Tobias Stoeckmann: You can download a proof of concept from my website: http://www.stoeckmann.org/openbsd/poc.iso. Take FAT1 and it'll infinitely loop. This fix will complete your previous commit. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/sbin/fsck_msdos/fat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/fat.c diff -u src/sbin/fsck_msdos/fat.c:1.28 src/sbin/fsck_msdos/fat.c:1.29 --- src/sbin/fsck_msdos/fat.c:1.28 Thu Jul 10 17:00:52 2014 +++ src/sbin/fsck_msdos/fat.c Fri Jul 11 10:59:53 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: fat.c,v 1.28 2014/07/10 21:00:52 christos Exp $ */ +/* $NetBSD: fat.c,v 1.29 2014/07/11 14:59:53 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -28,7 +28,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fat.c,v 1.28 2014/07/10 21:00:52 christos Exp $); +__RCSID($NetBSD: fat.c,v 1.29 2014/07/11 14:59:53 christos Exp $); #endif /* not lint */ #include stdlib.h @@ -392,7 +392,8 @@ checkfat(struct bootblock *boot, struct /* follow the chain and mark all clusters on the way */ for (len = 0, p = head; - p = CLUST_FIRST p boot-NumClusters; + p = CLUST_FIRST p boot-NumClusters + fat[p].head != head; p = fat[p].next) { fat[p].head = head; len++;
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: christos Date: Thu Jul 10 21:00:52 UTC 2014 Modified Files: src/sbin/fsck_msdos: fat.c Log Message: Bring in a regression for the previous fix from OpenBSD To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/sbin/fsck_msdos/fat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/fat.c diff -u src/sbin/fsck_msdos/fat.c:1.27 src/sbin/fsck_msdos/fat.c:1.28 --- src/sbin/fsck_msdos/fat.c:1.27 Mon Jul 7 14:46:45 2014 +++ src/sbin/fsck_msdos/fat.c Thu Jul 10 17:00:52 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: fat.c,v 1.27 2014/07/07 18:46:45 christos Exp $ */ +/* $NetBSD: fat.c,v 1.28 2014/07/10 21:00:52 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -28,7 +28,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fat.c,v 1.27 2014/07/07 18:46:45 christos Exp $); +__RCSID($NetBSD: fat.c,v 1.28 2014/07/10 21:00:52 christos Exp $); #endif /* not lint */ #include stdlib.h @@ -555,13 +555,13 @@ writefat(int fs, struct bootblock *boot, if (fat[cl].next == CLUST_FREE) boot-NumFree++; *p++ = (u_char)fat[cl].next; - *p++ = (u_char)((fat[cl].next 8) 0xf); + *p = (u_char)((fat[cl].next 8) 0xf); cl++; if (cl = boot-NumClusters) break; if (fat[cl].next == CLUST_FREE) boot-NumFree++; - *p |= (u_char)(fat[cl + 1].next 4); + *p++ |= (u_char)(fat[cl + 1].next 4); *p++ = (u_char)(fat[cl + 1].next 4); break; }
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: christos Date: Thu Jul 10 21:06:20 UTC 2014 Modified Files: src/sbin/fsck_msdos: check.c Log Message: Well, if you set FSFIXFAT, better do it... Try running fsck on: $ newfs_msdos -C 1M ./poc.fs $ dd if=/dev/zero of=poc.fs conv=notrunc bs=1 count=1 seek=512 multiple times and see that it does not get fixed. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sbin/fsck_msdos/check.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/check.c diff -u src/sbin/fsck_msdos/check.c:1.18 src/sbin/fsck_msdos/check.c:1.19 --- src/sbin/fsck_msdos/check.c:1.18 Sat Apr 11 03:14:50 2009 +++ src/sbin/fsck_msdos/check.c Thu Jul 10 17:06:20 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: check.c,v 1.18 2009/04/11 07:14:50 lukem Exp $ */ +/* $NetBSD: check.c,v 1.19 2014/07/10 21:06:20 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -28,7 +28,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: check.c,v 1.18 2009/04/11 07:14:50 lukem Exp $); +__RCSID($NetBSD: check.c,v 1.19 2014/07/10 21:06:20 christos Exp $); #endif /* not lint */ #include stdlib.h @@ -135,7 +135,7 @@ checkfilesys(const char *filename) goto out; /* now write the FATs */ - if (mod FSFATMOD) { + if (mod (FSFATMOD|FSFIXFAT)) { if (ask(1, Update FATs)) { mod |= writefat(dosfs, boot, fat, mod FSFIXFAT); if (mod FSFATAL)
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: christos Date: Mon Jul 7 17:45:42 UTC 2014 Modified Files: src/sbin/fsck_msdos: dir.c fat.c Log Message: From: http://marc.info/?t=14030431075r=1w=2 When truncating cluster chains fix the length of the cluster head. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sbin/fsck_msdos/dir.c cvs rdiff -u -r1.24 -r1.25 src/sbin/fsck_msdos/fat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/dir.c diff -u src/sbin/fsck_msdos/dir.c:1.25 src/sbin/fsck_msdos/dir.c:1.26 --- src/sbin/fsck_msdos/dir.c:1.25 Sun Feb 20 16:42:50 2011 +++ src/sbin/fsck_msdos/dir.c Mon Jul 7 13:45:42 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.25 2011/02/20 21:42:50 christos Exp $ */ +/* $NetBSD: dir.c,v 1.26 2014/07/07 17:45:42 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -30,7 +30,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: dir.c,v 1.25 2011/02/20 21:42:50 christos Exp $); +__RCSID($NetBSD: dir.c,v 1.26 2014/07/07 17:45:42 christos Exp $); #endif /* not lint */ #include stdio.h @@ -420,12 +420,14 @@ checksize(struct bootblock *boot, struct fullpath(dir)); if (ask(1, Drop superfluous clusters)) { cl_t cl; - u_int32_t sz = 0; + u_int32_t sz, len; - for (cl = dir-head; (sz += boot-ClusterSize) dir-size;) + for (cl = dir-head, len = sz = 0; + (sz += boot-ClusterSize) dir-size; len++) cl = fat[cl].next; clearchain(boot, fat, fat[cl].next); fat[cl].next = CLUST_EOF; + fat[dir-head].length = len; return FSFATMOD; } else return FSERROR; Index: src/sbin/fsck_msdos/fat.c diff -u src/sbin/fsck_msdos/fat.c:1.24 src/sbin/fsck_msdos/fat.c:1.25 --- src/sbin/fsck_msdos/fat.c:1.24 Thu Jan 17 11:45:48 2013 +++ src/sbin/fsck_msdos/fat.c Mon Jul 7 13:45:42 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: fat.c,v 1.24 2013/01/17 16:45:48 jakllsch Exp $ */ +/* $NetBSD: fat.c,v 1.25 2014/07/07 17:45:42 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -28,7 +28,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fat.c,v 1.24 2013/01/17 16:45:48 jakllsch Exp $); +__RCSID($NetBSD: fat.c,v 1.25 2014/07/07 17:45:42 christos Exp $); #endif /* not lint */ #include stdlib.h @@ -355,7 +355,15 @@ tryclear(struct bootblock *boot, struct clearchain(boot, fat, head); return FSFATMOD; } else if (ask(0, Truncate)) { + uint32_t len; + cl_t p; + + for (p = head, len = 0; + p = CLUST_FIRST p boot-NumClusters; + p = fat[p].next, len++) + continue; *truncp = CLUST_EOF; + fat[head].length = len; return FSFATMOD; } else return FSERROR;
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: christos Date: Mon Jul 7 17:55:53 UTC 2014 Modified Files: src/sbin/fsck_msdos: fat.c Log Message: From: http://marc.info/?l=openbsd-techm=140275150804337w=2 Avoid infinite loops in cluster chain linked lists. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sbin/fsck_msdos/fat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/fat.c diff -u src/sbin/fsck_msdos/fat.c:1.25 src/sbin/fsck_msdos/fat.c:1.26 --- src/sbin/fsck_msdos/fat.c:1.25 Mon Jul 7 13:45:42 2014 +++ src/sbin/fsck_msdos/fat.c Mon Jul 7 13:55:53 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: fat.c,v 1.25 2014/07/07 17:45:42 christos Exp $ */ +/* $NetBSD: fat.c,v 1.26 2014/07/07 17:55:53 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -28,7 +28,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fat.c,v 1.25 2014/07/07 17:45:42 christos Exp $); +__RCSID($NetBSD: fat.c,v 1.26 2014/07/07 17:55:53 christos Exp $); #endif /* not lint */ #include stdlib.h @@ -413,10 +413,10 @@ checkfat(struct bootblock *boot, struct continue; /* follow the chain to its end (hopefully) */ - for (p = head; + for (len = fat[head].length, p = head; (n = fat[p].next) = CLUST_FIRST n boot-NumClusters; p = n) - if (fat[n].head != head) + if (fat[n].head != head || len-- 2) break; if (n = CLUST_EOFS) continue; @@ -424,14 +424,20 @@ checkfat(struct bootblock *boot, struct if (n == CLUST_FREE || n = CLUST_RSRVD) { pwarn(Cluster chain starting at %u ends with cluster marked %s\n, head, rsrvdcltype(n)); +clear: ret |= tryclear(boot, fat, head, fat[p].next); continue; } if (n CLUST_FIRST || n = boot-NumClusters) { pwarn(Cluster chain starting at %u ends with cluster out of range (%u)\n, - head, n); - ret |= tryclear(boot, fat, head, fat[p].next); - continue; + head, n); + goto clear; + } + if (head == fat[n].head) { + pwarn(Cluster chain starting at %u loops at cluster %u\n, + + head, p); + goto clear; } pwarn(Cluster chains starting at %u and %u are linked at cluster %u\n, head, fat[n].head, n);
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: christos Date: Mon Jul 7 18:46:45 UTC 2014 Modified Files: src/sbin/fsck_msdos: fat.c Log Message: From: http://marc.info/?l=openbsd-techm=140234174104724w=2 Avoid off-by-one on FAT12 filesystems. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/sbin/fsck_msdos/fat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/fat.c diff -u src/sbin/fsck_msdos/fat.c:1.26 src/sbin/fsck_msdos/fat.c:1.27 --- src/sbin/fsck_msdos/fat.c:1.26 Mon Jul 7 13:55:53 2014 +++ src/sbin/fsck_msdos/fat.c Mon Jul 7 14:46:45 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: fat.c,v 1.26 2014/07/07 17:55:53 christos Exp $ */ +/* $NetBSD: fat.c,v 1.27 2014/07/07 18:46:45 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -28,7 +28,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fat.c,v 1.26 2014/07/07 17:55:53 christos Exp $); +__RCSID($NetBSD: fat.c,v 1.27 2014/07/07 18:46:45 christos Exp $); #endif /* not lint */ #include stdlib.h @@ -554,13 +554,15 @@ writefat(int fs, struct bootblock *boot, default: if (fat[cl].next == CLUST_FREE) boot-NumFree++; - if (cl + 1 boot-NumClusters - fat[cl + 1].next == CLUST_FREE) -boot-NumFree++; *p++ = (u_char)fat[cl].next; - *p++ = (u_char)((fat[cl].next 8) 0xf) - |(u_char)(fat[cl+1].next 4); - *p++ = (u_char)(fat[++cl].next 4); + *p++ = (u_char)((fat[cl].next 8) 0xf); + cl++; + if (cl = boot-NumClusters) +break; + if (fat[cl].next == CLUST_FREE) +boot-NumFree++; + *p |= (u_char)(fat[cl + 1].next 4); + *p++ = (u_char)(fat[cl + 1].next 4); break; } }
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: christos Date: Mon Jul 7 19:04:37 UTC 2014 Modified Files: src/sbin/fsck_msdos: boot.c Log Message: From: http://marc.info/?l=openbsd-techm=140354518512871w=2 more consistency checks To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/sbin/fsck_msdos/boot.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/boot.c diff -u src/sbin/fsck_msdos/boot.c:1.15 src/sbin/fsck_msdos/boot.c:1.16 --- src/sbin/fsck_msdos/boot.c:1.15 Sat Apr 11 03:14:50 2009 +++ src/sbin/fsck_msdos/boot.c Mon Jul 7 15:04:37 2014 @@ -1,4 +1,3 @@ -/* $NetBSD: boot.c,v 1.15 2009/04/11 07:14:50 lukem Exp $ */ /* * Copyright (C) 1995, 1997 Wolfgang Solfrank @@ -28,11 +27,12 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: boot.c,v 1.15 2009/04/11 07:14:50 lukem Exp $); +__RCSID($NetBSD: boot.c,v 1.16 2014/07/07 19:04:37 christos Exp $); #endif /* not lint */ #include stdlib.h #include string.h +#include strings.h #include stdio.h #include unistd.h @@ -64,8 +64,16 @@ readboot(int dosfs, struct bootblock *bo /* decode bios parameter block */ boot-BytesPerSec = block[11] + (block[12] 8); boot-SecPerClust = block[13]; + if (boot-SecPerClust == 0 || popcount(boot-SecPerClust) != 1) { + pfatal(Invalid cluster size: %u\n, boot-SecPerClust); + return FSFATAL; + } boot-ResSectors = block[14] + (block[15] 8); boot-FATs = block[16]; + if (boot-FATs == 0) { + pfatal(Invalid number of FATs: %u\n, boot-FATs); + return FSFATAL; + } boot-RootDirEnts = block[17] + (block[18] 8); boot-Sectors = block[19] + (block[20] 8); boot-Media = block[21]; @@ -171,6 +179,10 @@ readboot(int dosfs, struct bootblock *bo } /* Check backup FSInfo? XXX */ } + if (boot-FATsecs == 0) { + pfatal(Invalid number of FAT sectors: %u\n, boot-FATsecs); + return FSFATAL; + } boot-ClusterOffset = (boot-RootDirEnts * 32 + boot-BytesPerSec - 1) / boot-BytesPerSec @@ -193,6 +205,12 @@ readboot(int dosfs, struct bootblock *bo boot-NumSectors = boot-HugeSectors; boot-NumClusters = (boot-NumSectors - boot-ClusterOffset) / boot-SecPerClust; + if (boot-ClusterOffset boot-NumSectors) { + pfatal(Cluster offset too large (%u clusters)\n, + boot-ClusterOffset); + return FSFATAL; + } + if (boot-flagsFAT32) boot-ClustMask = CLUST32_MASK; else if (boot-NumClusters (CLUST_RSRVDCLUST12_MASK))
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: jakllsch Date: Thu Jan 17 16:45:48 UTC 2013 Modified Files: src/sbin/fsck_msdos: fat.c Log Message: An uninitialized next-free-cluster value in the file system information block is valid; do not consider it for correction. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/sbin/fsck_msdos/fat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/fat.c diff -u src/sbin/fsck_msdos/fat.c:1.23 src/sbin/fsck_msdos/fat.c:1.24 --- src/sbin/fsck_msdos/fat.c:1.23 Tue Aug 7 19:30:41 2012 +++ src/sbin/fsck_msdos/fat.c Thu Jan 17 16:45:48 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fat.c,v 1.23 2012/08/07 19:30:41 jakllsch Exp $ */ +/* $NetBSD: fat.c,v 1.24 2013/01/17 16:45:48 jakllsch Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -28,7 +28,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: fat.c,v 1.23 2012/08/07 19:30:41 jakllsch Exp $); +__RCSID($NetBSD: fat.c,v 1.24 2013/01/17 16:45:48 jakllsch Exp $); #endif /* not lint */ #include stdlib.h @@ -605,7 +605,9 @@ checklost(int dosfs, struct bootblock *b ret = 1; } } - if (boot-FSNext = boot-NumClusters || (boot-NumFree fat[boot-FSNext].next != CLUST_FREE)) { + if (boot-FSNext != 0xU + (boot-FSNext = boot-NumClusters || + (boot-NumFree fat[boot-FSNext].next != CLUST_FREE))) { pwarn(Next free cluster in FSInfo block (%u) %s\n, boot-FSNext, (boot-FSNext = boot-NumClusters) ? invalid : not free);
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: christos Date: Sun Feb 20 21:42:50 UTC 2011 Modified Files: src/sbin/fsck_msdos: dir.c Log Message: undo part of the previous patch, which I suspect is bad. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/sbin/fsck_msdos/dir.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/dir.c diff -u src/sbin/fsck_msdos/dir.c:1.24 src/sbin/fsck_msdos/dir.c:1.25 --- src/sbin/fsck_msdos/dir.c:1.24 Mon Feb 7 12:36:42 2011 +++ src/sbin/fsck_msdos/dir.c Sun Feb 20 16:42:50 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.24 2011/02/07 17:36:42 christos Exp $ */ +/* $NetBSD: dir.c,v 1.25 2011/02/20 21:42:50 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -30,7 +30,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: dir.c,v 1.24 2011/02/07 17:36:42 christos Exp $); +__RCSID($NetBSD: dir.c,v 1.25 2011/02/20 21:42:50 christos Exp $); #endif /* not lint */ #include stdio.h @@ -560,7 +560,7 @@ vallfn = p; valcl = cl; } else if (shortSum != p[13] - || lidx != lrnomask || lrnomask != 0) { + || lidx != lrnomask) { if (!invlfn) { invlfn = vallfn; invcl = valcl;
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: christos Date: Mon Feb 7 17:36:42 UTC 2011 Modified Files: src/sbin/fsck_msdos: dir.c Log Message: PR/44529: Martin Danielsson: fsck_msdos crashes when verifying corrupt file system. Avoid using the long name index when it is 0. Refactor the code to avoid duplication. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/sbin/fsck_msdos/dir.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/dir.c diff -u src/sbin/fsck_msdos/dir.c:1.23 src/sbin/fsck_msdos/dir.c:1.24 --- src/sbin/fsck_msdos/dir.c:1.23 Sat Apr 11 03:14:50 2009 +++ src/sbin/fsck_msdos/dir.c Mon Feb 7 12:36:42 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.23 2009/04/11 07:14:50 lukem Exp $ */ +/* $NetBSD: dir.c,v 1.24 2011/02/07 17:36:42 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -30,7 +30,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: dir.c,v 1.23 2009/04/11 07:14:50 lukem Exp $); +__RCSID($NetBSD: dir.c,v 1.24 2011/02/07 17:36:42 christos Exp $); #endif /* not lint */ #include stdio.h @@ -204,6 +204,7 @@ * Global variables temporarily used during a directory scan */ static char longName[DOSLONGNAMELEN] = ; +static char *eLongName = longName + sizeof(longName); static u_char *buffer = NULL; static u_char *delbuf = NULL; @@ -432,6 +433,26 @@ return FSOK; } +static int +procName(int from, int to, char **dst, const u_char *src) +{ + int k; + char *t = *dst; + + for (k = from; k to t eLongName; k += 2) { + if (!src[k] !src[k + 1]) + break; + *t++ = src[k]; + /* + * Warn about those unusable chars in msdosfs here? XXX + */ + if (src[k + 1]) + t[-1] = '?'; + } + *dst = t; + return k; +} + /* * Read a directory and * - resolve long name records @@ -526,6 +547,7 @@ } if (p[11] == ATTR_WIN95) { +u_int lrnomask = *p LRNOMASK; if (*p LRFIRST) { if (shortSum != -1) { if (!invlfn) { @@ -538,7 +560,7 @@ vallfn = p; valcl = cl; } else if (shortSum != p[13] - || lidx != (*p LRNOMASK)) { + || lidx != lrnomask || lrnomask != 0) { if (!invlfn) { invlfn = vallfn; invcl = valcl; @@ -549,52 +571,35 @@ } vallfn = NULL; } -lidx = *p LRNOMASK; -t = longName + --lidx * 13; -for (k = 1; k 11 t longName + sizeof(longName); k += 2) { - if (!p[k] !p[k + 1]) - break; - *t++ = p[k]; - /* - * Warn about those unusable chars in msdosfs here? XXX - */ - if (p[k + 1]) - t[-1] = '?'; -} -if (k = 11) - for (k = 14; k 26 t longName + sizeof(longName); k += 2) { - if (!p[k] !p[k + 1]) - break; - *t++ = p[k]; - if (p[k + 1]) - t[-1] = '?'; - } -if (k = 26) - for (k = 28; k 32 t longName + sizeof(longName); k += 2) { - if (!p[k] !p[k + 1]) - break; - *t++ = p[k]; - if (p[k + 1]) - t[-1] = '?'; - } -if (t = longName + sizeof(longName)) { - pwarn(long filename too long\n); - if (!invlfn) { - invlfn = vallfn; - invcl = valcl; +lidx = lrnomask; +if (lidx != 0) { + t = longName + --lidx * 13; + k = procName(1, 11, t, p); + if (k = 11) + k = procName(14, 26, t, p); + if (k = 26) + k = procName(28, 32, t, p); + if (t = eLongName) { + pwarn( + long filename too long\n); + if (!invlfn) { + invlfn = vallfn; + invcl = valcl; + } + vallfn = NULL; } - vallfn = NULL; } if (p[26] | (p[27] 8)) { - pwarn(long filename record cluster start != 0\n); + pwarn(long filename record cluster + start != 0\n); if (!invlfn) { invlfn = vallfn; invcl = cl; } vallfn = NULL; } -continue; /* long records don't carry further - * information */ +continue; /* long records don't carry + * further information */ } /*
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: wiz Date: Sun Apr 11 21:29:38 UTC 2010 Modified Files: src/sbin/fsck_msdos: fsck_msdos.8 Log Message: New sentence, new line. Sort SEE ALSO. Improve formatting of option list. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sbin/fsck_msdos/fsck_msdos.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/fsck_msdos.8 diff -u src/sbin/fsck_msdos/fsck_msdos.8:1.16 src/sbin/fsck_msdos/fsck_msdos.8:1.17 --- src/sbin/fsck_msdos/fsck_msdos.8:1.16 Sun Apr 11 08:23:52 2010 +++ src/sbin/fsck_msdos/fsck_msdos.8 Sun Apr 11 21:29:37 2010 @@ -1,4 +1,4 @@ -.\ $NetBSD: fsck_msdos.8,v 1.16 2010/04/11 08:23:52 hannken Exp $ +.\ $NetBSD: fsck_msdos.8,v 1.17 2010/04/11 21:29:37 wiz Exp $ .\ .\ Copyright (C) 1995 Wolfgang Solfrank .\ Copyright (c) 1995 Martin Husemann @@ -72,7 +72,7 @@ making any changes. .Pp The options are as follows: -.Bl -hang -offset indent +.Bl -tag -width XxXsnapXbackupXX .It Fl f This option is ignored by .Nm , @@ -90,7 +90,8 @@ .It Fl x Ar snap-backup Use a snapshot with .Ar snap-backup -as backup to check a read-write mounted filesystem. Must be used with +as backup to check a read-write mounted filesystem. +Must be used with .Fl n . See .Xr fss 4 @@ -104,9 +105,9 @@ to assume yes as the answer to all operator questions. .El .Sh SEE ALSO +.Xr fss 4 , .Xr fsck 8 , .Xr fsck_ffs 8 , -.Xr fss 4 , .Xr mount_msdos 8 .Sh BUGS .Nm
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: lukem Date: Sat Apr 11 07:14:50 UTC 2009 Modified Files: src/sbin/fsck_msdos: boot.c check.c dir.c ext.h fat.c Log Message: fix sign-compare issues To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/sbin/fsck_msdos/boot.c cvs rdiff -u -r1.17 -r1.18 src/sbin/fsck_msdos/check.c cvs rdiff -u -r1.22 -r1.23 src/sbin/fsck_msdos/dir.c cvs rdiff -u -r1.12 -r1.13 src/sbin/fsck_msdos/ext.h cvs rdiff -u -r1.21 -r1.22 src/sbin/fsck_msdos/fat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/fsck_msdos/boot.c diff -u src/sbin/fsck_msdos/boot.c:1.14 src/sbin/fsck_msdos/boot.c:1.15 --- src/sbin/fsck_msdos/boot.c:1.14 Fri Jun 13 20:46:09 2008 +++ src/sbin/fsck_msdos/boot.c Sat Apr 11 07:14:50 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: boot.c,v 1.14 2008/06/13 20:46:09 martin Exp $ */ +/* $NetBSD: boot.c,v 1.15 2009/04/11 07:14:50 lukem Exp $ */ /* * Copyright (C) 1995, 1997 Wolfgang Solfrank @@ -28,7 +28,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: boot.c,v 1.14 2008/06/13 20:46:09 martin Exp $); +__RCSID($NetBSD: boot.c,v 1.15 2009/04/11 07:14:50 lukem Exp $); #endif /* not lint */ #include stdlib.h @@ -48,7 +48,7 @@ int ret = FSOK; int i; - if (read(dosfs, block, sizeof block) sizeof block) { + if ((size_t)read(dosfs, block, sizeof block) != sizeof block) { perr(could not read boot block); return FSFATAL; } Index: src/sbin/fsck_msdos/check.c diff -u src/sbin/fsck_msdos/check.c:1.17 src/sbin/fsck_msdos/check.c:1.18 --- src/sbin/fsck_msdos/check.c:1.17 Fri Jun 13 20:46:09 2008 +++ src/sbin/fsck_msdos/check.c Sat Apr 11 07:14:50 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: check.c,v 1.17 2008/06/13 20:46:09 martin Exp $ */ +/* $NetBSD: check.c,v 1.18 2009/04/11 07:14:50 lukem Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -28,7 +28,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: check.c,v 1.17 2008/06/13 20:46:09 martin Exp $); +__RCSID($NetBSD: check.c,v 1.18 2009/04/11 07:14:50 lukem Exp $); #endif /* not lint */ #include stdlib.h @@ -47,7 +47,8 @@ int dosfs; struct bootblock boot; struct fatEntry *fat = NULL; - int i, finish_dosdirsection=0; + int finish_dosdirsection=0; + u_int i; int mod = 0; int ret = FSCK_EXIT_CHECK_FAILED; Index: src/sbin/fsck_msdos/dir.c diff -u src/sbin/fsck_msdos/dir.c:1.22 src/sbin/fsck_msdos/dir.c:1.23 --- src/sbin/fsck_msdos/dir.c:1.22 Fri Jun 13 20:46:09 2008 +++ src/sbin/fsck_msdos/dir.c Sat Apr 11 07:14:50 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.22 2008/06/13 20:46:09 martin Exp $ */ +/* $NetBSD: dir.c,v 1.23 2009/04/11 07:14:50 lukem Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -30,7 +30,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: dir.c,v 1.22 2008/06/13 20:46:09 martin Exp $); +__RCSID($NetBSD: dir.c,v 1.23 2009/04/11 07:14:50 lukem Exp $); #endif /* not lint */ #include stdio.h @@ -393,7 +393,7 @@ /* * Check size on ordinary files */ - int32_t physicalSize; + u_int32_t physicalSize; if (dir-head == CLUST_FREE) physicalSize = 0; @@ -963,7 +963,7 @@ lfoff = lfcl * boot-ClusterSize + boot-ClusterOffset * boot-BytesPerSec; if (lseek(dosfs, lfoff, SEEK_SET) != lfoff - || read(dosfs, lfbuf, boot-ClusterSize) != boot-ClusterSize) { + || (size_t)read(dosfs, lfbuf, boot-ClusterSize) != boot-ClusterSize) { perr(could not read LOST.DIR); return FSFATAL; } @@ -993,7 +993,7 @@ p[31] = (u_char)(d.size 24); fat[head].flags |= FAT_USED; if (lseek(dosfs, lfoff, SEEK_SET) != lfoff - || write(dosfs, lfbuf, boot-ClusterSize) != boot-ClusterSize) { + || (size_t)write(dosfs, lfbuf, boot-ClusterSize) != boot-ClusterSize) { perr(could not write LOST.DIR); return FSFATAL; } Index: src/sbin/fsck_msdos/ext.h diff -u src/sbin/fsck_msdos/ext.h:1.12 src/sbin/fsck_msdos/ext.h:1.13 --- src/sbin/fsck_msdos/ext.h:1.12 Fri Jun 13 20:46:09 2008 +++ src/sbin/fsck_msdos/ext.h Sat Apr 11 07:14:50 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: ext.h,v 1.12 2008/06/13 20:46:09 martin Exp $ */ +/* $NetBSD: ext.h,v 1.13 2009/04/11 07:14:50 lukem Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -83,13 +83,13 @@ * Read one of the FAT copies and return a pointer to the new * allocated array holding our description of it. */ -int readfat(int, struct bootblock *, int, struct fatEntry **); +int readfat(int, struct bootblock *, u_int, struct fatEntry **); /* * Check two FAT copies for consistency and merge changes into the * first if necessary. */ -int comparefat(struct bootblock *, struct fatEntry *, struct fatEntry *, int); +int comparefat(struct bootblock *, struct fatEntry *, struct fatEntry *, u_int); /* * Check a FAT Index: src/sbin/fsck_msdos/fat.c diff -u src/sbin/fsck_msdos/fat.c:1.21 src/sbin/fsck_msdos/fat.c:1.22 ---