Commit Graph

92 Commits

Author SHA1 Message Date
kamil b110dc906e 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'
2020-02-22 09:59:22 +00:00
christos 08f54aa8c8 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.
2020-01-11 16:29:07 +00:00
christos 7031824410 We already incremented cl; fix indexing. Noticed by Xin Li @FreeBSD. 2019-06-04 00:08:00 +00:00
dholland 32cded6cc9 Typos. 2018-02-08 09:05:16 +00:00
christos 255de32a23 Prevent SEGV on corrupted msdos directories (Veo Zhang) 2017-04-28 11:33:00 +00:00
sevan c6b9fd9601 Document the version fsck_msdos first appeared.
Bump date.
2016-09-11 04:12:08 +00:00
jakllsch 1dac11f22d 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.
2016-05-02 17:33:03 +00:00
christos 85e7d45a39 PR/50908: David Binderman: Optimize memset's 2016-03-07 14:47:25 +00:00
christos d3037dba83 fix error messages containing \n 2015-06-16 23:18:54 +00:00
mlelstv d15e4a5d5d Avoid mixing cluster numbers and sector numbers. Makes code more readable. 2015-01-02 06:21:28 +00:00
msaitoh 48b712a059 Add #include <inttypes.h> for intmax_t to fix compile error. 2014-11-04 03:05:43 +00:00
jakllsch d8015429ba ClusterOffset actually needs to be able to be negative. 2014-11-03 18:55:04 +00:00
christos 699f31f847 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.
2014-07-11 14:59:53 +00:00
christos 698f62dfb8 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.
2014-07-10 21:06:20 +00:00
christos ffdedd8608 Bring in a regression for the previous fix from OpenBSD 2014-07-10 21:00:52 +00:00
christos 0a21325ef0 From: http://marc.info/?l=openbsd-tech&m=140354518512871&w=2
more consistency checks
2014-07-07 19:04:37 +00:00
christos d7660c3645 From: http://marc.info/?l=openbsd-tech&m=140234174104724&w=2
Avoid off-by-one on FAT12 filesystems.
2014-07-07 18:46:45 +00:00
christos 468753370f From: http://marc.info/?l=openbsd-tech&m=140275150804337&w=2
Avoid infinite loops in cluster chain linked lists.
2014-07-07 17:55:53 +00:00
christos be4e2ccbba From: http://marc.info/?t=140304310700005&r=1&w=2
When truncating cluster chains fix the length of the cluster head.
2014-07-07 17:45:42 +00:00
jakllsch ec5e5d471b An uninitialized next-free-cluster value in the file system information
block is valid; do not consider it for correction.
2013-01-17 16:45:48 +00:00
jakllsch da6f244356 The free space value in the FSInfo block is merely unitialized when it is
0xffffffff.  Fixes first part of bin/46743
2012-08-07 19:30:41 +00:00
christos 453164da22 fix compilation. 2011-06-09 21:23:29 +00:00
christos 6df320733c undo part of the previous patch, which I suspect is bad. 2011-02-20 21:42:50 +00:00
christos b805ecec3f 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.
2011-02-07 17:36:42 +00:00
wiz c4f8f360fc New sentence, new line. Sort SEE ALSO.
Improve formatting of option list.
2010-04-11 21:29:37 +00:00
hannken 738a97ca87 Add -x option which allows to run `fsck_msdos -n' on a snapshot of
a live file system.

While here modify snap_open() to accept a character device as its
first arg and remove now unneeded get_snap_device().

Reviewed by: Manuel Bouyer <bouyer@netbsd.org>
2010-04-11 08:23:51 +00:00
lukem a2b5923e3e fix sign-compare issues 2009-04-11 06:59:18 +00:00
matthias f0f728186b Do not crash when boot->FSNext contains garbage (i.e. -1). 2008-07-24 14:23:16 +00:00
martin b47f782db6 Move to 2 clause license, approved by Wolfgang Solfrank. 2008-06-13 20:46:09 +00:00
christos 358764c860 Catch signals and exit with the proper error code like all the other fsck
programs.
2008-02-24 00:59:03 +00:00
christos 742b48d55e Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
2008-02-23 21:41:47 +00:00
gdt 9da1e4cf5f Change mismatch of bytes 11 to 90 to be a warning, not an error, and
print out the values of the bytes that do not match.
Add comment explaining that there is no documented rationale for the
check.

fsck_msdos checks that several bytes are equal in the primary and
backup bootblock.  There is no documented rationale.  The kernel does
not enforce this when mounting a filesystem.  I have a FAT32
filesystem on my disk (mounted as /share) which fails this check, but
is accepted by both Windows XP and NetBSD.  My volume differs in bytes
71-81.  The primary contains "SHARE " and the backup NUL bytes.

Further, fsck_msdos does not have code to repair the mismatch.  As a
result such filesystems can be used not checked.
2007-03-19 18:30:40 +00:00
hubertf d8a2863966 - removes unused ctype.h header
- correct comment in mount_nfs/getnfsargs.c: s/Nead/Need/

From: Slava Semushin <php-coder@altlinux.ru>
2007-03-10 00:30:36 +00:00
hubertf df06563bc3 Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
2007-01-17 21:59:49 +00:00
christos 2a1607d040 Programs that use efun. 2006-08-26 18:14:28 +00:00
christos c4c1a29bd4 don't use uint32_t when you mean size_t. 2006-06-06 16:19:11 +00:00
christos 15f3040f9f - don't leak memory on allocation failure.
- s/perror/perr and print how much we were trying to allocate.
2006-06-05 16:51:18 +00:00
dbj a015786b0d the root directory of non fat32 filesystems is stored in a special area.
a couple of corner cases can cause it to fail to write out that area
after it performs repairs.
2006-04-10 03:25:11 +00:00
christos 4b15f35af4 Coverity CID 2302: Free fat if fatal error to avoid leak. 2006-03-20 01:42:47 +00:00
christos e5919d97fc Coverity CID 1078: Add assertion check for NULL pointer. 2006-03-20 01:25:14 +00:00
xtraeme 76500fc2f9 WARNS=2 is the default defined in sbin/Makefile.inc. (thanks wiz) 2005-01-20 16:39:22 +00:00
xtraeme 65e67723b5 Kill __P(), ANSIfy, remove main() prototype. 2005-01-19 20:00:45 +00:00
christos a73c2bd574 Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
2005-01-13 15:22:35 +00:00
jmmv b635f565e7 Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
2004-01-05 23:23:32 +00:00
dsl e69ce3e4bf Add a -q (quiet) option to print nothing for clean filesystems.
Support in fsck_ffs and stub in fsck_xxx.
Push a few more messages through pwarn() instead of printf() to ensure
disk name is shown.
2003-10-20 12:04:38 +00:00
ws ebd1f55e89 Only compare the interesting part of the bootblock with its backup. 2003-07-24 19:25:46 +00:00
itojun 0e4dc5229d use bounded string op 2003-07-13 08:16:15 +00:00
matt 25b98a109b Eliminate a -Wshadow warning 2003-02-28 05:50:33 +00:00
wiz 990562bfef .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
2003-02-25 10:34:36 +00:00
wiz 2fb4b1db52 New sentence, new line. By Robert Elz with minimal fixes. 2002-10-01 13:40:23 +00:00