34 Commits

Author SHA1 Message Date
Samanta Navarro
48e80f766d mkfs.fat: Handle case of bad root cluster
If the root cluster is bad, then mkfs.fat creates a filesystem which
fsck.fat considers to be broken and cannot fix.

Find the next free FAT cluster for root instead during creation.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2023-04-26 11:59:21 +00:00
Pali Rohár
fed19c29ae Add new test files into dist_check_DATA 2021-11-20 00:56:24 +01:00
msuhanov
0eb5a33e08 Add two tests: volumes with encryption. 2021-11-19 02:42:21 +03:00
Bjørn Forsman
94dc01ba0c testsuite: use SOURCE_DATE_EPOCH
Instead of the special --invariant flag, use SOURCE_DATE_EPOCH (and the
volume-id option) for reproducible build. (Plan for eventual removal of
the --invariant flag.)

Use "export SOURCE_DATE_EPOCH=1426325213; command" instead of the
simpler "SOURCE_DATE_EPOCH=1426325213 command". Both forms work in bash,
but apparently only the "export" version works in dash. Run in a
subshell to not leak SOURCE_DATE_EPOCH.

Signed-off-by: Bjørn Forsman <bjorn.forsman@gmail.com>
2021-08-17 23:18:17 +02:00
Pali Rohár
49755b36c3 tests: Fix running fsck tests outside of the source directory 2021-02-08 22:27:45 +01:00
Pali Rohár
2f6d8cf309 testsuite: Add reference images of fsck result tests
This ensures that fsck does not change its behavior and repair filesystems
in the same way. Repaired reference images were generated by dosfstools 4.1
to ensure that they are still same.
2021-01-29 02:10:58 +01:00
Pali Rohár
5265c64544 testsuite: Add fsck tests for fat labels 2021-01-29 02:10:22 +01:00
Pali Rohár
3a3c1d3fb7 testsuite: Update mkfs-fat32_2_res_sects.xxd test as it is now not aligned due to -a 2021-01-28 10:39:36 +01:00
Pali Rohár
b8c85310f7 testsuite: Add tests for DOS Clean Shutdown bit 2021-01-17 22:47:18 +01:00
Pali Rohár
82c2111148 testsuite: Add fsck tests with broken first FAT cluster
Extend also test-fsck script to read additional arguments from .args file.
2021-01-17 20:20:39 +01:00
Pali Rohár
94437324ed testsuite: Add mkfs test for 600MB large 4K disk 2021-01-14 22:10:52 +01:00
Pali Rohár
b29eb5be67 mkfs.fat: Align total number of sectors to be multiple of sectors per track
This requirement is needed by DOS systems and also by Linux mtools project.
Without proper alignment, mtools applications refuse to work on such
filesystem.
2021-01-14 22:10:52 +01:00
Pali Rohár
8c812329c4 testsuite: Add referenceFAT32mbr test data to dist_check_DATA 2021-01-10 22:29:48 +01:00
felix
9069ba088c fsck.fat: properly check for valid "." and ".." entries
This change makes fsck.fat check whether "." and ".." entries exist in
all non-root directories as the two very first. If those entries are
occupied by some other file, fsck.fat will offer to move them to some
later slot. "." and ".." entries found in any other slots are treated
as ordinary bad-shortname entries. The test case for this situation has
been enabled and verified to perform as expected.

The function drop_file() was also modified so that it does not mark
dropped file clusters as free. This was necessary because otherwise
dropping too-late "." and ".." entries would delete their containing
directory. If deleted entries' clusters are truly no longer used, they
shall be picked up by a later reclamation stage.

Additionally, subdirs() and check_file() were modified not to check
unused directory entries.

Additionally-fixed-by: Dave Odell <dmo2118@gmail.com>
2021-01-10 21:49:30 +01:00
Pali Rohár
da36707a6f mkfs.fat: Write FAT32 backup info sector after FAT32 backup boot sector
Write it only in the case when location does not conflict with real/primary
FAT32 info sector and reserved area is big enough.
2021-01-03 22:49:30 +01:00
Pali Rohár
5b61d9f00a testsuite: Run fsck test step always even if mkfs test step fails
fsck test step can show more details about badly created image by mkfs.
2021-01-03 22:49:30 +01:00
Pali Rohár
53bfa1f1b7 testsuite: Add test for mkfs.fat with two FAT32 sectors in reserved area 2021-01-03 22:49:30 +01:00
Pali Rohár
68e8e5420f mkfs.fat: Calculate CHS geometry according to SD Card Part 2 File System Specification
Use this CHS calculation when disk geometry is not available. This change
replaces hardcoded 64/32 value by formula based on total number of sectors.

For SD cards with more then 256MB capacity is CHS calculation according to
SD Card Part 2 File System Specification same as CHS calculation for hard
disks via LBA-Assist Translation.
2021-01-03 21:05:22 +01:00
Pali Rohár
5199d6847a mkfs.fat: Add a new option --mbr which fills MBR table with one partition
It is needed only for non-removable disks used on Microsoft Windows systems
and only when formatting whole unpartitioned disk.

Also some removable USB flash disks accessed via USB Mass Storage declares
themselves as non-removable and Microsoft Windows systems do not recognize
them without MBR partition table and MBR disk signature.

Because MBR sector and first FAT sector are very similar (starts with
boot code, ends with boot sign 0xAA55) they can live together at one
sector. Moreover location of the MBR partition table overlaps only with the
end of FAT boot code where is just place for the error message, it is
possible to fill (fake) MBR partition table with one partition which refers
to whole disk itself (starts at sector 0 and spans whole disk).

Similar thing is doing mformat (FAT12/16/32 formatting tool) from mtools
project or mkudffs (UDF formatting tool) from udftools project.
2021-01-03 20:12:09 +01:00
Pali Rohár
20092b8e2f travis: Check for fatlabel test errors only for non-static builds
Static builds have broken iconv support which is detected at configure time
as usable. This leads to usage of internal CP850 conversion table as
fallback solution which throws runtime non-fatal error.
2019-10-14 12:14:07 +02:00
Pali Rohár
a4a0d6211a tests: Check for stderr errors from fatlabel tests 2019-10-14 09:48:43 +02:00
Tobias Stoeckmann
93b4288b72 Fix out of boundary read in fsck.fat/fatlabel
Faulty filesystems are able to trigger integer overflows in read_boot which eventually lead to insufficient allocation of memory for the FAT and therefore out of boundary reads.
2019-02-24 20:55:15 +01:00
Pali Rohár
da07aa4441 Update Travis configuration
* Use both gcc and clang compilers
* Compile with -fwrapv and -fsanitize=address
* Compile in both 32 and 64 modes for x86 systems
* Cross compile for little endian arm and big endian powerpc
* Run cross compiled binaries in qemu
2019-02-09 09:25:55 +01:00
felix
4d01db7c6e fsck.fat: Allow spaces in the middle of SFNs
Also, introduce an -S option (mostly) restoring previous behaviour.
2018-05-18 02:54:44 +02:00
Pali Rohár
2112913bda Add tests for FAT32 labels
These FAT32 images were generated for FAT label test suite in October 2017.
Now fatlabel reports same FAT32 label as MS-DOS 6, 7 and Windows 98, XP, 10.

For more information about test result see email:
https://www.spinics.net/lists/kernel/msg2640891.html
2018-05-05 17:57:51 +02:00
Andreas Bombe
77371e208c testsuite: Add missing fsck test files to dist_check_DATA
Signed-off-by: Andreas Bombe <aeb@debian.org>
2016-11-04 13:10:58 +01:00
Andreas Bombe
d6df1d4184 testsuite: Test for bad characters in file names
The FAT16 test image contains four files with three errors. One has a
space in the name, one a space in the extension and one contains '>' in
the name.

Signed-off-by: Andreas Bombe <aeb@debian.org>
2016-11-03 20:03:25 +01:00
Andreas Bombe
b33424e6b6 testsuite: Test for files sharing clusters
The FAT32 test image contains three files. One shares a cluster with the
root directory and the other two share clusters among themselves.

Signed-off-by: Andreas Bombe <aeb@debian.org>
2016-09-17 23:34:07 +02:00
Andreas Bombe
db5ec045ef testsuite: Run fsck in test-mkfs
Now the test-mkfs script also runs fsck on the created image to test its
basic operation. The test fails if fsck reports seeing an error.

Signed-off-by: Andreas Bombe <aeb@debian.org>
2016-09-17 22:41:07 +02:00
Andreas Bombe
4ef83db115 Request minimum automake version 1.11 and add workaround for <1.13
Before automake 1.13, parallel-tests wasn't the default set it
explicitly in the automake options list. The parallel test harness was
introduced in 1.11 therefore that is the minimum now.

However, the AM_TESTS_ENVIRONMENT variable was only starting to work in
1.13, so there is now a version check and a conditional assignment to
TESTS_ENVIRONMENT (which should be for user setting only) in case
automake is 1.11 or 1.12.

Without it, the fact of xxd being found is not passed to the test
scripts which then skip all tests due to perceived lack of xxd.

Signed-off-by: Andreas Bombe <aeb@debian.org>
2016-09-16 03:32:12 +02:00
Andreas Bombe
ccd0a9dcc0 testsuite: Test for circular cluster chain
The test image contains a file four clusters in length where the third
cluster has been modified to point back to the second cluster.

Signed-off-by: Andreas Bombe <aeb@debian.org>
2016-09-12 20:27:10 +02:00
Andreas Bombe
8394cebdf4 testsuite: Test for too long cluster chain
The test image contains a file marked as 7 bytes in length (just a small
part of 1 cluster) in the directory entry that has 2 clusters assigned
to it in the FAT.

Signed-off-by: Andreas Bombe <aeb@debian.org>
2016-09-12 14:39:11 +02:00
Andreas Bombe
f78cb68ee4 Add fsck testsuite
Add the framework for a fsck testsuite and a few tests, including a test
for the yet unimplemented check for misordered dot/dotdot directory
entries.

The test driver runs fsck twice on a given image and fails the test if
the first run does not detect an error or the second run still detects
an error.

Signed-off-by: Andreas Bombe <aeb@debian.org>
2016-09-07 20:51:57 +02:00
Andreas Bombe
76672953a0 Add testsuite foundations
Add testsuite on the basis of the automake framework. As a start, three
tests for basic mkfs functionality compare mkfs generated images against
references images.

Signed-off-by: Andreas Bombe <aeb@debian.org>
2016-09-07 03:52:13 +02:00