Re: FAT32 statfs(2) inode usage

From: Stefan Esser <se_at_FreeBSD.org>
Date: Wed, 08 Mar 2023 16:40:34 UTC
Am 07.03.23 um 15:11 schrieb Ben Woods:
> 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;
> 	}
> ----------
> 

Hi Ben,

I have created a patch that has been tested with both FAT12 and FAT16
and which has passed all my tests with different file system parameters
(e.g. number of root directory entries) and all operations (create,
rename and delete files and directories with DOS-8.3 or Win95 names).

Could you please create a PR that describes the issue you had (wrong
report of no free inodes on a FAT16 file system) and assign it to me?

I'll reference the PR in the review I'm going to create and hope that
this will help get the issue reviewed and the patch set approved ...

Best regards, STefan