Re: FAT32 statfs(2) inode usage

From: Ben Woods <woodsb02_at_freebsd.org>
Date: Tue, 07 Mar 2023 14:11:57 UTC
On Tue, 7 Mar 2023, at 6:20 PM, Ben Woods wrote:
> On Tue, 7 Mar 2023, at 6:11 PM, Stefan Esser wrote:
>>
>> I could implement a counter that provides a useful value for f_ffree by
>> counting all file and directory creations and removals from the root
>> directory of a FAT12/FAT16 file system.
>
> If I’m right, the file system could easily be mounted outside of 
> FreeBSD on another machine that doesn’t maintain the counter. For 
> example, a USB stick shared between machines. Trying to infer state 
> from past events is always hard. Instead, how hard would it be to have 
> the kernel count the current number of root directory entries at the 
> time the statfs request is issued (live)?

I've noticed the following code is used for enforcing the limit of root directory entities when creating a file or directory on a FAT filesystem. Could msdosfs_statfs use something similar to determine the current count of root directory entities?

Source file: sys/fs/msdosfs/msdosfs_vnops.c

Functions: msdosfs_create() and msdosfs_mkdir()
----------
	/*
	 * If this is the root directory and there is no space left we
	 * can't do anything.  This is because the root directory can not
	 * change size.
	 */
	if (pdep->de_StartCluster == MSDOSFSROOT
	    && pdep->de_fndoffset >= pdep->de_FileSize) {
		error = ENOSPC;
		goto bad;
	}
----------

-- 
From: Ben Woods
woodsb02@freebsd.org