CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: gutteridge Date: Sun Sep 24 20:41:52 UTC 2023 Modified Files: src/sbin/fsck_msdos: ext.h Log Message: ext.h: fix spelling and grammar in a comment To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sbin/fsck_msdos/ext.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: gutteridge Date: Sun Sep 24 20:41:52 UTC 2023 Modified Files: src/sbin/fsck_msdos: ext.h Log Message: ext.h: fix spelling and grammar in a comment To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sbin/fsck_msdos/ext.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/ext.h diff -u src/sbin/fsck_msdos/ext.h:1.13 src/sbin/fsck_msdos/ext.h:1.14 --- src/sbin/fsck_msdos/ext.h:1.13 Sat Apr 11 07:14:50 2009 +++ src/sbin/fsck_msdos/ext.h Sun Sep 24 20:41:52 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: ext.h,v 1.13 2009/04/11 07:14:50 lukem Exp $ */ +/* $NetBSD: ext.h,v 1.14 2023/09/24 20:41:52 gutteridge Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -69,7 +69,7 @@ int checkfilesys(const char *); #define FSFIXFAT 64 /* Fix file system FAT */ /* - * read a boot block in a machine independend fashion and translate + * Read a boot block in a machine independent fashion and translate * it into our struct bootblock. */ int readboot(int, struct bootblock *);
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: mlelstv Date: Sun Aug 28 11:32:19 UTC 2022 Modified Files: src/sbin/fsck_msdos: boot.c Log Message: fix 32bit builds To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 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.26 src/sbin/fsck_msdos/boot.c:1.27 --- src/sbin/fsck_msdos/boot.c:1.26 Sun Aug 28 10:20:25 2022 +++ src/sbin/fsck_msdos/boot.c Sun Aug 28 11:32:19 2022 @@ -27,7 +27,7 @@ #include #ifndef lint -__RCSID("$NetBSD: boot.c,v 1.26 2022/08/28 10:20:25 mlelstv Exp $"); +__RCSID("$NetBSD: boot.c,v 1.27 2022/08/28 11:32:19 mlelstv Exp $"); #endif /* not lint */ #include @@ -159,7 +159,7 @@ readboot(int dosfs, struct bootblock *bo fsinfo[0x3ff] = 0xaa; if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET) != boot->FSInfo * boot->BytesPerSec -|| write(dosfs, fsinfo, 2 * secsize) +|| (size_t)write(dosfs, fsinfo, 2 * secsize) != 2 * secsize) { perr("Unable to write FSInfo"); free(fsinfo);
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: mlelstv Date: Sun Aug 28 11:32:19 UTC 2022 Modified Files: src/sbin/fsck_msdos: boot.c Log Message: fix 32bit builds To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 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.
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: mlelstv Date: Sun Aug 28 10:20:25 UTC 2022 Modified Files: src/sbin/fsck_msdos: boot.c check.c Log Message: Fix writing of corrected fsinfo. Continue when fsinfo has been rewritten. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sbin/fsck_msdos/boot.c cvs rdiff -u -r1.19 -r1.20 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.
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: mlelstv Date: Sun Aug 28 10:20:25 UTC 2022 Modified Files: src/sbin/fsck_msdos: boot.c check.c Log Message: Fix writing of corrected fsinfo. Continue when fsinfo has been rewritten. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sbin/fsck_msdos/boot.c cvs rdiff -u -r1.19 -r1.20 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/boot.c diff -u src/sbin/fsck_msdos/boot.c:1.25 src/sbin/fsck_msdos/boot.c:1.26 --- src/sbin/fsck_msdos/boot.c:1.25 Sun Apr 24 10:35:15 2022 +++ src/sbin/fsck_msdos/boot.c Sun Aug 28 10:20:25 2022 @@ -27,7 +27,7 @@ #include #ifndef lint -__RCSID("$NetBSD: boot.c,v 1.25 2022/04/24 10:35:15 hannken Exp $"); +__RCSID("$NetBSD: boot.c,v 1.26 2022/08/28 10:20:25 mlelstv Exp $"); #endif /* not lint */ #include @@ -147,7 +147,7 @@ readboot(int dosfs, struct bootblock *bo || fsinfo[0x3fd] || fsinfo[0x3fe] != 0x55 || fsinfo[0x3ff] != 0xaa) { - pwarn("Invalid signature in fsinfo block"); + pwarn("Invalid signature in fsinfo block\n"); if (ask(0, "fix")) { memcpy(fsinfo, "RRaA", 4); memcpy(fsinfo + 0x1e4, "rrAa", 4); @@ -159,8 +159,8 @@ readboot(int dosfs, struct bootblock *bo fsinfo[0x3ff] = 0xaa; if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET) != boot->FSInfo * boot->BytesPerSec -|| write(dosfs, fsinfo, sizeof fsinfo) -!= sizeof fsinfo) { +|| write(dosfs, fsinfo, 2 * secsize) +!= 2 * secsize) { perr("Unable to write FSInfo"); free(fsinfo); free(backup); Index: src/sbin/fsck_msdos/check.c diff -u src/sbin/fsck_msdos/check.c:1.19 src/sbin/fsck_msdos/check.c:1.20 --- src/sbin/fsck_msdos/check.c:1.19 Thu Jul 10 21:06:20 2014 +++ src/sbin/fsck_msdos/check.c Sun Aug 28 10:20:25 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: check.c,v 1.19 2014/07/10 21:06:20 christos Exp $ */ +/* $NetBSD: check.c,v 1.20 2022/08/28 10:20:25 mlelstv Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -28,7 +28,7 @@ #include #ifndef lint -__RCSID("$NetBSD: check.c,v 1.19 2014/07/10 21:06:20 christos Exp $"); +__RCSID("$NetBSD: check.c,v 1.20 2022/08/28 10:20:25 mlelstv Exp $"); #endif /* not lint */ #include @@ -72,7 +72,8 @@ checkfilesys(const char *filename) return FSCK_EXIT_CHECK_FAILED; } - if (readboot(dosfs, ) != FSOK) { + mod = readboot(dosfs, ); + if (mod & FSFATAL) { close(dosfs); printf("\n"); return FSCK_EXIT_CHECK_FAILED;
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: hannken Date: Sun Apr 24 10:35:15 UTC 2022 Modified Files: src/sbin/fsck_msdos: boot.c Log Message: Cast read()/write() result to size_t to make this compile again. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 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.24 src/sbin/fsck_msdos/boot.c:1.25 --- src/sbin/fsck_msdos/boot.c:1.24 Sat Apr 23 22:40:28 2022 +++ src/sbin/fsck_msdos/boot.c Sun Apr 24 10:35:15 2022 @@ -27,7 +27,7 @@ #include #ifndef lint -__RCSID("$NetBSD: boot.c,v 1.24 2022/04/23 22:40:28 mlelstv Exp $"); +__RCSID("$NetBSD: boot.c,v 1.25 2022/04/24 10:35:15 hannken Exp $"); #endif /* not lint */ #include @@ -132,7 +132,8 @@ readboot(int dosfs, struct bootblock *bo if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET) != boot->FSInfo * boot->BytesPerSec - || read(dosfs, fsinfo, 2 * secsize) != 2 * secsize) { + || (size_t)read(dosfs, fsinfo, 2 * secsize) + != 2 * secsize) { perr("could not read fsinfo block"); return FSFATAL; } @@ -181,7 +182,7 @@ readboot(int dosfs, struct bootblock *bo if (lseek(dosfs, boot->Backup * boot->BytesPerSec, SEEK_SET) != boot->Backup * boot->BytesPerSec - || read(dosfs, backup, secsize) != secsize) { + || (size_t)read(dosfs, backup, secsize) != secsize) { perr("could not read backup bootblock"); free(fsinfo); free(backup); @@ -307,7 +308,8 @@ writefsinfo(int dosfs, struct bootblock if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET) != boot->FSInfo * boot->BytesPerSec - || read(dosfs, fsinfo, 2 * boot->BytesPerSec) != 2 * boot->BytesPerSec) { + || (size_t)read(dosfs, fsinfo, 2 * boot->BytesPerSec) + != 2 * boot->BytesPerSec) { perr("could not read fsinfo block"); free(fsinfo); return FSFATAL; @@ -322,7 +324,8 @@ writefsinfo(int dosfs, struct bootblock fsinfo[0x1ef] = (u_char)(boot->FSNext >> 24); if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET) != boot->FSInfo * boot->BytesPerSec - || write(dosfs, fsinfo, 2 * boot->BytesPerSec) != 2 * boot->BytesPerSec) { + || (size_t)write(dosfs, fsinfo, 2 * boot->BytesPerSec) + != 2 * boot->BytesPerSec) { perr("Unable to write FSInfo"); free(fsinfo); return FSFATAL;
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: hannken Date: Sun Apr 24 10:35:15 UTC 2022 Modified Files: src/sbin/fsck_msdos: boot.c Log Message: Cast read()/write() result to size_t to make this compile again. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 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.
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: mlelstv Date: Sat Apr 23 22:40:28 UTC 2022 Modified Files: src/sbin/fsck_msdos: boot.c Log Message: Support large disk sectors. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 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.23 src/sbin/fsck_msdos/boot.c:1.24 --- src/sbin/fsck_msdos/boot.c:1.23 Sat Feb 22 09:59:22 2020 +++ src/sbin/fsck_msdos/boot.c Sat Apr 23 22:40:28 2022 @@ -27,7 +27,7 @@ #include #ifndef lint -__RCSID("$NetBSD: boot.c,v 1.23 2020/02/22 09:59:22 kamil Exp $"); +__RCSID("$NetBSD: boot.c,v 1.24 2022/04/23 22:40:28 mlelstv Exp $"); #endif /* not lint */ #include @@ -36,6 +36,8 @@ __RCSID("$NetBSD: boot.c,v 1.23 2020/02/ #include #include #include +#include +#include #include "ext.h" #include "fsutil.h" @@ -43,19 +45,34 @@ __RCSID("$NetBSD: boot.c,v 1.23 2020/02/ int readboot(int dosfs, struct bootblock *boot) { - u_char block[DOSBOOTBLOCKSIZE]; - u_char fsinfo[2 * DOSBOOTBLOCKSIZE]; - u_char backup[DOSBOOTBLOCKSIZE]; + u_char *block; + u_char *fsinfo; + u_char *backup; int ret = FSOK; - int i; + int i, err; + u_int secsize; + + secsize = 0; + err = ioctl(dosfs, DIOCGSECTORSIZE, ); + if (err != 0 || secsize == 0) + secsize = DOSBOOTBLOCKSIZE; + + if (secsize < DOSBOOTBLOCKSIZE) + pfatal("Invalid sector size %u\n", secsize); + + block = calloc(1, secsize); + if (block == NULL) + pfatal("Out of memory"); - if ((size_t)read(dosfs, block, sizeof block) != sizeof block) { + if ((size_t)read(dosfs, block, secsize) != secsize) { perr("could not read boot block"); + free(block); return FSFATAL; } if (block[510] != 0x55 || block[511] != 0xaa) { pfatal("Invalid signature in boot block: %02x%02x", block[511], block[510]); + free(block); return FSFATAL; } @@ -86,6 +103,13 @@ readboot(int dosfs, struct bootblock *bo boot->FATsecs = boot->FATsmall; + fsinfo = calloc(2, secsize); + if (fsinfo == NULL) + pfatal("Out of memory"); + backup = calloc(1, secsize); + if (backup == NULL) + pfatal("Out of memory"); + if (!boot->RootDirEnts) boot->flags |= FAT32; if (boot->flags & FAT32) { @@ -108,8 +132,7 @@ readboot(int dosfs, struct bootblock *bo if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET) != boot->FSInfo * boot->BytesPerSec - || read(dosfs, fsinfo, sizeof fsinfo) - != sizeof fsinfo) { + || read(dosfs, fsinfo, 2 * secsize) != 2 * secsize) { perr("could not read fsinfo block"); return FSFATAL; } @@ -138,6 +161,9 @@ readboot(int dosfs, struct bootblock *bo || write(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) { perr("Unable to write FSInfo"); + free(fsinfo); + free(backup); + free(block); return FSFATAL; } ret = FSBOOTMOD; @@ -155,8 +181,11 @@ readboot(int dosfs, struct bootblock *bo if (lseek(dosfs, boot->Backup * boot->BytesPerSec, SEEK_SET) != boot->Backup * boot->BytesPerSec - || read(dosfs, backup, sizeof backup) != sizeof backup) { + || read(dosfs, backup, secsize) != secsize) { perr("could not read backup bootblock"); + free(fsinfo); + free(backup); + free(block); return FSFATAL; } backup[65] = block[65];/* XXX */ @@ -180,6 +209,11 @@ readboot(int dosfs, struct bootblock *bo } /* Check backup FSInfo? XXX */ } + + free(fsinfo); + free(backup); + free(block); + if (boot->FATsecs == 0) { pfatal("Invalid number of FAT sectors: %u\n", boot->FATsecs); return FSFATAL; @@ -265,12 +299,17 @@ readboot(int dosfs, struct bootblock *bo int writefsinfo(int dosfs, struct bootblock *boot) { - u_char fsinfo[2 * DOSBOOTBLOCKSIZE]; + u_char *fsinfo; + + fsinfo = calloc(2, boot->BytesPerSec); + if (fsinfo == NULL) + pfatal("Out of memory"); if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET) != boot->FSInfo * boot->BytesPerSec - || read(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) { + || read(dosfs, fsinfo, 2 * boot->BytesPerSec) != 2 * boot->BytesPerSec) { perr("could not read fsinfo block"); + free(fsinfo); return FSFATAL; } fsinfo[0x1e8] = (u_char)boot->FSFree; @@ -283,11 +322,14 @@ writefsinfo(int dosfs, struct bootblock fsinfo[0x1ef] = (u_char)(boot->FSNext >> 24); if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET) != boot->FSInfo * boot->BytesPerSec - || write(dosfs, fsinfo, sizeof fsinfo) - != sizeof fsinfo) { + || write(dosfs, fsinfo, 2 * boot->BytesPerSec) != 2 * boot->BytesPerSec) { perr("Unable to write FSInfo"); + free(fsinfo); return FSFATAL; } + + free(fsinfo); + /* * Technically, we should return FSBOOTMOD here. *
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: mlelstv Date: Sat Apr 23 22:40:28 UTC 2022 Modified Files: src/sbin/fsck_msdos: boot.c Log Message: Support large disk sectors. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 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.
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: christos Date: Tue Jun 4 00:08:00 UTC 2019 Modified Files: src/sbin/fsck_msdos: fat.c Log Message: We already incremented cl; fix indexing. Noticed by Xin Li @FreeBSD. To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 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.29 src/sbin/fsck_msdos/fat.c:1.30 --- src/sbin/fsck_msdos/fat.c:1.29 Fri Jul 11 10:59:53 2014 +++ src/sbin/fsck_msdos/fat.c Mon Jun 3 20:08:00 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: fat.c,v 1.29 2014/07/11 14:59:53 christos Exp $ */ +/* $NetBSD: fat.c,v 1.30 2019/06/04 00:08:00 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank @@ -28,7 +28,7 @@ #include #ifndef lint -__RCSID("$NetBSD: fat.c,v 1.29 2014/07/11 14:59:53 christos Exp $"); +__RCSID("$NetBSD: fat.c,v 1.30 2019/06/04 00:08:00 christos Exp $"); #endif /* not lint */ #include @@ -562,8 +562,8 @@ writefat(int fs, struct bootblock *boot, 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].next << 4); + *p++ = (u_char)(fat[cl].next >> 4); break; } }
CVS commit: src/sbin/fsck_msdos
Module Name:src Committed By: christos Date: Tue Jun 4 00:08:00 UTC 2019 Modified Files: src/sbin/fsck_msdos: fat.c Log Message: We already incremented cl; fix indexing. Noticed by Xin Li @FreeBSD. To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 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.