freebsd-src/bin
Stefan Eßer d767bf361b msdosfs: fix debug print format and parameter
Building with -DMSDOSFS_DEBUG failed due to a format mismatch and
a variable that has been renamed but not updated in the printf()
parameter list.

(cherry picked from commit 2d8cf575d5)

fs/msdosfs: add tracking of free root directory entries

This update implements tallying of free directory entries during
create, delete,	or rename operations on FAT12 and FAT16 file systems.

Prior to this change, the total number of root directory entries
was reported as number of inodes, but 0 as the number of free
inodes, causing system health monitoring software to warn about
a suspected disk full issue.

The FAT12 and FAT16 file systems provide a limited number of
root directory entries, e.g. 512 on typical hard disk formats.
The valid range of values is 1 to 65535, but the msdosfs code
will effectively round up "odd" values to the next multiple of 16
(e.g. 513 would allow for 528 root directory entries).

This update implements tracking of directory entries during create,
delete, or rename operations, with initial values determined by
scanning the directory when the file system is mounted.

Total and free directory entries are reported in the f_files and
f_ffree elements of struct statfs, despite differences in semantics
of these values:

- There is no limit on the number of files and directories that can
  be created on a FAT file system. Only the root directory of FAT12
  and FAT16 file systems is limited, any number of files can still be
  created in sub-directories, even when 0 free "inodes" are reported.

- A single file can require 1 to 21 directory entries, depending on
  the character set, structure, and length of the name. The DOS 8.3
  style file name takes up 1 entry, and if the name does not comply
  with the syntax of a DOS 8.3 file name, 1 additional entry is used
  for each 13 characters of the file name. Since all these entries
  have to be contiguous, it is possible that a file or directory with
  a long name can not be created, despite a sufficient total number of
  free directory entries.

- Renaming a file can require more directory entries than currently
  allocated to store its long name, which may prevent an in-place
  update of the name if more entries are needed. This may cause a
  rename operation to fail if no contiguous range of free entries for
  the new name can be found.

- The volume label is stored in a directory entry. An empty FAT file
  system with a volume label will therefore show 1 used "inode" in
  df.

- The perceentage of free inodes shown in df or monitoring tools does
  only represent the state of the root directory of a FAT12 or FAT16
  file system. Neither does a reported value of 0% free inodes does
  prevent files from being created in sub-directories, nor does a
  value of 50% free inodes guarantee that even a single file with
  a "long" name can be created in the root directory (if every other
  directory entry is occupied and there are no 2 contiguous entries).

The statfs(2) and df(1) man pages have been updated with a notice
regarding the possibly different semantics of values reported as
total and free inodes for non-Unix file systems.

PR:		270053
Reported by:	Ben Woods <woodsb02@freebsd.org>
Approved by:	mckusick
Differential Revision:	https://reviews.freebsd.org/D38987

(cherry picked from commit c33db74b53)

fs/msdosfs: Fix potential panic and size calculations

Some combinations of FAT12 file system parameters could cause a kernel
panic due to an unmapped access if the size of the FAT was larger than
the CPU page size. The reason is that FAT12 uses 3 bytes to store
2 FAT pointers, leading to partial FAT pointers at the end of buffers
of a size that is not a multiple of 3.

With a typical page size of 4 KB, this caused the FAT entry at byte
offsets 4095 and 4096 to cross the page boundary, with only the first
page mapped. This was fixed by adjusting the mapping to always cover
both bytes of each FAT entry.

Testing revealed 2 other inconsistencies that are fixed by this commit:

1) The calculation of the size of the data area did not take into
   account the fact that the first two data block numbers are reserved
   and that the data area starts with block 2. This could cause a
   FAT12 file system created with the maximum supported number of
   blocks to be incorrectly identified as FAT16.

2) The root directory does not take up space in the data area of a
   FAT12 or FAT16 file system, since it is placed into a reserved
   area outside of that data area. This commits makes stat() report
   the logical size of the root directory, but with 0 blocks allocated
   from the data area.

PR:		270587
Reviewed by:	mckusick
Differential Revision:	https://reviews.freebsd.org/D39386

(cherry picked from commit 0728695c63)
2023-05-01 10:09:33 +02:00
..
cat cat: style nits 2021-01-20 18:46:26 +01:00
chflags fts_read: Handle error from a NULL return better. 2020-12-08 23:38:26 +00:00
chio pkgbase: Put chio in utilities 2021-06-30 09:24:32 +02:00
chmod fts_read: Handle error from a NULL return better. 2020-12-08 23:38:26 +00:00
cp cp: Add tests involving sparse files. 2023-02-09 21:32:56 +01:00
csh csh: install hard link with same mode as target 2023-03-23 10:33:01 -04:00
date date: attempt to more accurately describe year limitations with -v 2022-09-18 01:26:39 -05:00
dd
df msdosfs: fix debug print format and parameter 2023-05-01 10:09:33 +02:00
domainname pkgbase: Put yellow pages programs to its own package 2022-01-05 18:23:51 +01:00
echo echo(1): Replace errexit() with err(3) 2022-01-07 14:12:12 +01:00
ed ed(1): Add two references in the SEE ALSO section 2021-04-16 16:25:25 +02:00
expr
freebsd-version freebsd-version(1): Add -j flag to support jails 2021-10-08 11:29:07 -05:00
getfacl bin/setfacl: Little refactoring, no functional change. 2020-11-23 17:00:06 +00:00
hostname hostname: avoid strcpy() overlap in -d flag handling 2021-10-03 00:14:58 -05:00
kenv kenv: allow listing of static kernel environments 2021-08-26 01:35:33 -05:00
kill
ln
ls ls(1): add a -v flag to sort naturally 2022-12-24 07:47:21 +01:00
mkdir src/bin/mkdir: Spell occur correctly. 2021-11-18 21:52:21 -07:00
mv
nproc nproc: denote an incompatiblity with Linux 2023-02-23 17:06:41 +00:00
pax pax: remove 4.4BSD compatibility 2022-11-02 10:39:18 +01:00
pkill pkill: tests: do a pass for case-sensitive conflicts 2023-04-20 12:29:23 -05:00
ps ps: fix ps -aa 2022-03-22 19:46:40 +01:00
pwait Fix typo in pwait.c introduced in 5bdce6ff54 2021-01-21 21:43:27 +00:00
pwd
realpath
rm fts_read: Handle error from a NULL return better. 2020-12-08 23:38:26 +00:00
rmail
rmdir
setfacl Remove unused headers. 2020-12-12 02:26:43 +00:00
sh sh: install hard link with same mode as target 2023-03-23 10:33:01 -04:00
sleep Soften caveat about fractional seconds for sleep(1) 2020-12-31 19:18:20 -08:00
stty stty(1): provide details about interaction with job control 2022-10-09 05:23:04 +03:00
sync
test Remove unused includes. 2020-12-22 21:04:36 -08:00
tests
timeout timeout: Move from /usr/bin to /bin 2023-02-07 18:37:53 +01:00
uuidgen uuidgen(1): fix another typo 2023-03-06 09:04:54 +01:00
Makefile Add nproc(1) 2023-02-23 17:06:41 +00:00
Makefile.inc