Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mkfs.fat number of reserved sectors has changed. #67

Open
SByer opened this issue Oct 26, 2017 · 8 comments
Open

mkfs.fat number of reserved sectors has changed. #67

SByer opened this issue Oct 26, 2017 · 8 comments

Comments

@SByer
Copy link

SByer commented Oct 26, 2017

An explicit -R switch is ignored. 3.0.28 vs. 4.1:

[⋐]$ mkfs.fat -v -F16 -R1 -D0x80 -I -M0xF8 -n RPIBOOT out/target/product/rpi3/rpi_boot.img
mkfs.fat 3.0.28 (2015-05-16)
out/target/product/rpi3/rpi_boot.img has 64 heads and 32 sectors per track,
hidden sectors 0x0000;
logical sector size is 512,
using 0xf8 media descriptor, with 131072 sectors;
drive number 0x80;
filesystem has 2 16-bit FATs and 4 sectors per cluster.
FAT size is 128 sectors, and provides 32695 clusters.
There is 1 reserved sector.
Root directory contains 512 slots and uses 32 sectors.
Volume ID is 01ce154f, volume label RPIBOOT .

[⋐]$ /sbin/mkfs.fat -v -F16 -R1 -D0x80 -I -M0xF8 -n RPIBOOT out/target/product/rpi3/rpi_boot.img
mkfs.fat 4.1 (2017-01-24)
out/target/product/rpi3/rpi_boot.img has 64 heads and 32 sectors per track,
hidden sectors 0x0000;
logical sector size is 512,
using 0xf8 media descriptor, with 131072 sectors;
drive number 0x80;
filesystem has 2 16-bit FATs and 4 sectors per cluster.
FAT size is 128 sectors, and provides 32695 clusters.
There are 4 reserved sectors.
Root directory contains 512 slots and uses 32 sectors.
Volume ID is 0235d0f0, volume label RPIBOOT .

@andreasbombe
Copy link
Contributor

This is caused by the automatic alignment of filesystem structures, which worked on versions a bit older than 3.0.28 and now works again. If you want it to lay it out exactly as you want disable alignment with the option -a.

I'm leaving this open since mkfs should do something different. Either respect the option even with alignment somehow (may not be possible since reserved sectors is how it aligns), automatically disable alignment when -R is given or at least warn that reserved sectors may be increased with alignment in effect.

@pali
Copy link
Member

pali commented Aug 19, 2018

In my opinion, mkfs.fat should throw a warning when automatic alignment is enabled and number of reserved sectors does not match with value what user specified. And warning should contain information how to achieve/force exact number of reserved sectors.

@pali
Copy link
Member

pali commented Aug 19, 2018

Duplicate of #44

@echelonxray
Copy link

I second the addition of a warning message when manually specifying a configuration that will be ignored due to alignment. And I agree that included in the warning message should be the information to use the -a switch to achieve said desired configuration. I spent a decent amount of time trying to trace down why my -R setting was being ignored and even hexedited my FS to check/force the right settings.

@pali
Copy link
Member

pali commented Jan 15, 2021

@EchelonX-Ray: What about for now at least following documentation change?

diff --git a/manpages/mkfs.fat.8.in b/manpages/mkfs.fat.8.in
--- a/manpages/mkfs.fat.8.in
+++ b/manpages/mkfs.fat.8.in
@@ -171,12 +177,18 @@ The default is no label.
 Use DOS codepage \fIPAGE\fP to encode label.
 By default codepage 850 is used.
 .IP "\fB\-r\fP \fIROOT-DIR-ENTRIES\fP" 4
-Select the number of entries available in the root directory.
+Select the minimal number of entries available in the root directory.
 The default is 112 or 224 for floppies and 512 for hard disks.
+Note that this is minimal number and it may be increased by \fBmkfs.fat\fP
+due to alignment of structures.
+See also \fBmkfs.fat\fP option \fB\-a\fP.
 .IP "\fB\-R\fP \fINUMBER-OF-RESERVED-SECTORS\fP" 4
-Select the number of reserved sectors.
+Select the minimal number of reserved sectors.
 With FAT32 format at least 2 reserved sectors are needed, the default is 32.
 Otherwise the default is 1 (only the boot sector).
+Note that this is minimal number and it may be increased by \fBmkfs.fat\fP
+due to alignment of structures.
+See also \fBmkfs.fat\fP option \fB\-a\fP.
 .IP "\fB\-s\fP \fISECTORS-PER-CLUSTER\fP" 4
 Specify the number of disk sectors per cluster.
 Must be a power of 2, i.e. 1, 2, 4, 8, ... 128.
diff --git a/src/mkfs.fat.c b/src/mkfs.fat.c
--- a/src/mkfs.fat.c
+++ b/src/mkfs.fat.c
@@ -1450,8 +1452,8 @@ static void usage(const char *name, int exitval)
     fprintf(stderr, "  --mbr[=y|n|a]   Fill (fake) MBR table with one partition which spans whole disk\n");
     fprintf(stderr, "  -n LABEL        Set volume name to LABEL (up to 11 characters long)\n");
     fprintf(stderr, "  --codepage=N    use DOS codepage N to encode label (default: %d)\n", DEFAULT_DOS_CODEPAGE);
-    fprintf(stderr, "  -r COUNT        Make room for COUNT entries in the root directory\n");
-    fprintf(stderr, "  -R COUNT        Set number of reserved sectors to COUNT\n");
+    fprintf(stderr, "  -r COUNT        Make room for at least COUNT entries in the root directory\n");
+    fprintf(stderr, "  -R COUNT        Set minimal number of reserved sectors to COUNT\n");
     fprintf(stderr, "  -s COUNT        Set number of sectors per cluster to COUNT\n");
     fprintf(stderr, "  -S SIZE         Select a sector size of SIZE (a power of two, at least 512)\n");
     fprintf(stderr, "  -v              Verbose execution\n");

@pali
Copy link
Member

pali commented Jan 28, 2021

I pushed above change which updates documentation in commit 7deb97d.

@echelonxray
Copy link

Thank you. Sorry about not getting back to you sooner. I was distracted by other parts of the project.

@pali
Copy link
Member

pali commented May 6, 2023

So remaining part of this issue is to print a warning when number of root entries or reserved sector changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants