512 Commits

Author SHA1 Message Date
Maxim Suhanov
289a48b9cb manpages: Include the security considerations section to the fsck.fat
documentation

Signed-off-by: Maxim Suhanov <dfirblog@gmail.com>
2023-10-10 00:34:43 +03:00
Samanta Navarro
c483196dd4 Fix vasprintf implementation
A va_copy call must be followed by a va_end call.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2023-05-05 11:57:33 +00:00
Samanta Navarro
812eb5b840 mkfs.fat: Reduce visibility of static buffer
The blkbuf array in check_blocks is not needed. It is always given as an
argument to do_check. Keep the buffer there for easier access and
reduced visibility in code.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2023-04-28 12:02:02 +00:00
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
Samanta Navarro
aca5b2e61f mkfs.fat: Update tables in case of bad blocks
If bad cluster markers have been added to FAT, then FAT32 filesystems
contain the wrong amount of free clusters. This ultimately means that
newly created filesystems are repaired when calling fsck.fat.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2023-04-24 12:03:12 +00:00
Samanta Navarro
d2872059ac mkfs.fat: Fix badblocks style
All other variables which have multiple words in their name use
a separator. Do so for variable "badblocks" as well.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2023-04-24 12:03:12 +00:00
Samanta Navarro
837eaf2bed mkfs.fat: Switch to sigaction
According to signal(2) manual page the system call is only portable when
setting a signal's disposition to SIG_DFL or SIG_IGN.

Using sigaction(2) allows specific definition of flags, which in this
case will always instruct system calls to restart when SIGALRM is
received. This should be the default on Linux with signal(2) anyway.

This reduces the signal handler to set only a single variable.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2023-04-23 12:04:49 +00:00
Samanta Navarro
57c6059b3a mkfs.fat: Fix signal race
The signal handler used during bad block detection calls the
signal-unsafe function printf. This could get in conflict with a printf
for an error condition in do_check.

Just set a sig_atomic_t variable to indicate that current status should
be displayed and leave the signal handler again.

The main loop checks the flag and prints the status when needed.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2023-04-20 11:58:03 +00:00
Samanta Navarro
58212c59f9 fsck.fat: Reduce duplicate file name lookups
If a file has to be generated, then alloc_rootdir_entry tries to create
a unique name by using a counter curr_num for name generation and
looking for duplicates. If no duplicate is found, the counter curr_num
is not incremented, which means that the next file uses the same name
again. It is only incremented after the previously created file is
detected, just to repeat the loop again.

The improvement is simple: Increment the counter after creating the
filename. This has also the benefit that the check and use of
curr_num are closer to each other within the source code.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2023-04-04 11:53:54 +00:00
Samanta Navarro
2a868410d2 Fix typos
Typos found while reviewing lfn code.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2023-04-03 12:07:17 +00:00
Pali Rohár
240a2302e0 fsck.fat: Fix choice number again 2023-03-25 15:35:33 +01:00
Pali Rohár
bd7924ebc8 fsck.fat: In interactive mode allow to skip repairing invalid label
In interactive mode other reparations can be skipped.
So for consistency allow it also for label.
2023-03-23 21:25:56 +01:00
Pali Rohár
b81306fae8 fsck.fat: Fix choice numbers in check_boot_label() and check_label() 2023-03-23 21:25:56 +01:00
Samanta Navarro
ba972ca969 mkfs.fat: Correctly count bad blocks
If a badblocks file contains the same block number multiple times,
then the status message of mkfs.fat shows the wrong amount of bad
blocks.

Proof of Concept:
```
echo -e "30\n30\n30" > badblocks
dd if=/dev/zero of=poc.iso bs=512 count=100
mkfs.fat -l badblocks poc.iso
```

Output is `3 bad blocks`.

With this commit it is `1 bad block`.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2023-03-23 11:41:04 +00:00
Samanta Navarro
ca406a4dff mkfs.fat: Switch lineno to unsigned
A signed integer overflow could occur with huge badblocks file because
we store the current line number in lineno. The unsigned data type
should be large enough for any sane badblocks file, otherwise it still
overflows but does not lead to C language issues.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2023-03-23 11:40:59 +00:00
Pali Rohár
b54ef3546b mkfs.fat: Fix error messages 2023-03-21 22:37:35 +01:00
Michael Vrable
dc27b5ff26 fatlabel: Fix a compiler warning about a maybe-unitialized variable
Fixes a compiler error that can occur when building with clang:
error: variable 'change' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]

Previously, this variable was initialized on all code paths except for
one that called `usage(1, 1)`.  In practice that should have been safe
as `usage` should cause the program to exit.  But to make this
obviously safe, initialize `change` to false when it is declared.
2023-03-03 11:35:14 -08:00
Samanta Navarro
31c2c3a2d5 Fix typos
"less then" should be "less than" instead. I have looked for more
occurrences of then/than typos but did not find any.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2023-01-25 11:58:05 +00:00
Samanta Navarro
fc83a0ba31 Fix typos
Typos found with codespell.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2023-01-16 12:06:00 +00:00
Pali Rohár
c064e181c4 mkfs.fat: Fix reading slaves and removable sysfs entries for partitioned devices
Partitioned devices have slaves and removable sysfs entries in parent device.

Issue #186
2023-01-09 19:44:41 +01:00
Pali Rohár
3406a92301 mkfs.fat: Fix detection of badblocks EOF
Function getline() does not have to set errno to zero on EOF.
So use feof() to detect EOF.

Fixes #186
2023-01-09 19:41:53 +01:00
Samanta Navarro
2e866102d4 Support multiple codepage command line arguments.
Use last given codepage argument instead of first to comply with
other command line arguments.

Proof of Concept:

1. Prepare a filesystem with label ° in codepage 1252
```
$ dd if=/dev/zero of=poc.iso bs=512 count=100
$ mkfs.fat -c 1252 -n "°" poc.iso
```

2. Query the label
```
$ fatlabel -c 1252 poc.iso
$ fatlabel -c 850 -c 1252 poc.iso
```

The output should be identical.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2023-01-04 11:52:46 +00:00
David Gumberg
53ef9adf45 Use 'htole' for LE conversion in mkfs.fat.c 2022-08-28 14:45:44 -07:00
Pali Rohár
6bff769631 manpages: Update mkfs.fat documentation for -s SECTOR-SIZE option
Clarify filesystem sector size.
2022-08-13 12:14:35 +02:00
John Keeping
c888797b1d fatlabel: fix range check for signed characters
char may be either signed or unsigned and if it is signed the "< 0x20"
comparison will reject any values >= 0x80 even though these are valid
characters in a label.

Cast to an unsigned type to ensure the full range of valid characters
are accepted.
2022-07-25 12:11:44 +01:00
Pali Rohár
2d3125c4a7 blkdev.c: Fix check for DIOCGDINFO
Do not compile DIOCGDINFO code when DIOCGDINFO is not defined.

Fixes #177
2022-03-16 01:25:49 +01:00
Pali Rohár
58e0c95106 fsck.fat: Add missing __attribute__ ((packed)) for disk structures
It is required for proper pointer aligning and also for preventing to fill
gaps between structure members.

Fixes #176
2022-03-16 01:24:22 +01:00
Florian Warzecha
6319921da6
DOC(fatlabel.8.in): minor spelling typos
Spelling issues were reported by the manpage-l10n project.
2022-02-28 18:45:23 +01:00
Pali Rohár
ae94d63c46 fsck.fat: Do not truncate files in cluster chain of size 2^32
File with size 4294967295 (2^32-1) is stored in cluster chain of size
4294967296 (2^32). This cluster chain length cannot be represented in
32-bit integer so explicitly cast calculation to 64-bit (long long)
integer.

Before this change all files with size of 4294967295 bytes were auto
truncated to zero size because cluster chain size overflowed to zero.

This change fixes it and valid files are not automatically truncated.

Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1001845
2022-02-22 23:16:08 +01:00
Pali Rohár
1da41f0e70 fsck.fat: Fix showing invalid label with non-printable characters
Show non-printable characters of label in octal format \ooo like when
showing file names.

Also explicitly mark zero byte as non-printable.

Issue #172
2022-01-22 15:55:15 +01: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
msuhanov
6cc2a52e14 Rename lcase to ntbyte in the directory entry structure. 2021-11-18 01:01:06 +03:00
msuhanov
c3a71fd25c Remove logic related to FAT_NO_83NAME. This flag wasn't implemented in the kernel.
This flag breaks compatibility with encryption metadata from Windows.
2021-11-18 01:00:57 +03:00
Michał Szczepaniak
ac4aa79cc2
Fix typo in fat.c 2021-09-19 21:56:00 +02:00
i0ntempest
77ffb87e82 Fix building on macos 2021-08-20 22:30:15 +08:00
Pali Rohár
9c2061ea27 mkfs.fat: Fix usage of function isspace()
Function isspace() takes int as an argument and expects either unsigned
char (values 0-255) or EOF (-1). So explicitly cast not-specified char type
variables to unsigned char types.
2021-08-19 23:30:01 +02:00
Pali Rohár
58c0d808ca fsck.fat: Fix usage of function isspace()
Function isspace() takes int as an argument and expects either unsigned
char (values 0-255) or EOF (-1). So explicitly cast not-specified char type
variables to unsigned char types.
2021-08-19 23:29:42 +02:00
Pali Rohár
20e4781174 fatlabel: Fix usage of function isspace()
Function isspace() takes int as an argument and expects either unsigned
char (values 0-255) or EOF (-1). So explicitly cast not-specified char type
variables to unsigned char types.
2021-08-19 23:28:58 +02:00
Bjørn Forsman
7cf11f52df mkfs.fat: start deprecating the --invariant flag
The invariant flag is superseded by SOURCE_DATE_EPOCH and the existing
volume-id (-i) flag. Start by removing --invariant from the help text.
Later versions may print a warning, and finally remove the flag
completely.

Signed-off-by: Bjørn Forsman <bjorn.forsman@gmail.com>
2021-08-17 23:18:17 +02: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
Bjørn Forsman
8da7bc9331 Honor the SOURCE_DATE_EPOCH variable
Implement the SOURCE_DATE_EPOCH specification[1] for reproducible
builds. If SOURCE_DATE_EPOCH is set, use it as timestamp instead of the
current time.

[1] https://reproducible-builds.org/specs/source-date-epoch/

Signed-off-by: Bjørn Forsman <bjorn.forsman@gmail.com>
2021-08-17 23:18:17 +02:00
Pali Rohár
f414e322da mkfs.fat: Fix upper limit for CHS overflow in MBR
Maximal head value in MBR CHS is 255. But due to bug in MS-DOS which cause
system crash when head value in MBR CHS is 255, it is common to use only
maximal head value 254.

Head value in MBR CHS is zero indexed. So number of disk heads (stored in
FAT boot sector) is maximal head value in MBR CHS + 1.

So fix upper limit for number of heads to 255 which can be still
represented in MBR CHS without MS-DOS crash.
2021-06-12 15:00:14 +02:00
Pali Rohár
d733fb06a0 mkfs.fat: Print number of hidden sectors in decimal notation
All sector numbers are print in decimal notation, so do it also for number
of hidden sectors.
2021-06-09 21:09:55 +02:00
Pali Rohár
5fe59602a9 fsck.fat: Remove duplicate version line 2021-02-25 14:48:35 +01: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
fc6a8a4108 travis: Include Ubuntu Bionic and Ubuntu Focal 2021-02-06 00:41:46 +01:00
Pali Rohár
3c9a3f43d6 fatlabel: Show argv[0] in usage 2021-02-06 00:05:55 +01:00
Pali Rohár
9617a18f81 Show fsck.fat and fatlabel version like in mkfs.fat 2021-02-06 00:05:33 +01:00
Pali Rohár
483a44da9d Append +git to version number 2021-02-06 00:01:34 +01:00