freebsd-dev/sys/fs/msdosfs
Stefan Eßer c33db74b53 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
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D38987
2023-03-29 08:46:01 +02:00
..
bootsect.h
bpb.h
denode.h msdosfs: drop now unused DE_RENAME 2021-08-27 18:39:45 +03:00
direntry.h
fat.h msdosfs: clusterfree() is used only in error handling cases 2022-01-08 05:41:44 +02:00
msdosfs_conv.c fs: clean up empty lines in .c and .h files 2020-09-01 21:18:40 +00:00
msdosfs_denode.c msdosfs: fix debug print format and parameter 2023-03-08 17:58:00 +01:00
msdosfs_fat.c msdosfs: on integrity error, fire a task to remount filesystem to ro 2022-01-08 06:20:48 +02:00
msdosfs_iconv.c
msdosfs_lookup.c fs/msdosfs: add tracking of free root directory entries 2023-03-29 08:46:01 +02:00
msdosfs_vfsops.c fs/msdosfs: add tracking of free root directory entries 2023-03-29 08:46:01 +02:00
msdosfs_vnops.c vfs: retire the now unused SAVESTART flag 2022-12-19 08:11:08 +00:00
msdosfsmount.h fs/msdosfs: add tracking of free root directory entries 2023-03-29 08:46:01 +02:00