Subject: Re: file descriptor races
To: =?iso-8859-1?Q?Jarom=EDr_Dolecek?= <>
From: Jason R Thorpe <>
List: tech-kern
Date: 06/06/2001 16:07:10
On Tue, Jun 05, 2001 at 12:16:57PM +0200, Jaromír Dolecek wrote:

 > FreeBSD seem to adopt something called fdrop(), which seems to drop
 > all references to given file. I'd much rather introduce something
 > like 'atomic falloc'. The proposed interface

fdrop() is not for that, at all.  fdrop() is sort of like our FILE_UNUSE(),
except they don't deal with the "no, the file descriptor is being closed"

 > int
 > fallocm(struct proc *p, struct file *resultfp[], int resultfd[], int nelem)
 > i.e. the function gets passed 'struct file *' array and int array with size
 > of 'nelem', and would take care to allocate either nelem descriptors, 
 > or fail and not allocate either (i.e. free those allocated so far, before
 > it would return to caller). The most simple way to provide 'atomicity'
 > would be probably to introduce e.g. special FIF_NOTREADY flag,
 > which sys_dup(), sys_fcntl(), sys_read(), sys_readv(), sys_write(),
 > sys_writev(), sys_close() would check and return EBADF if it's set.
 > Or, optionally, we may use FIF_WANTCLOSE | FIF_NOTREADY, and only
 > change sys_close() to check for FIF_NOTREADY flag (the others
 > already check the FIF_WANTCLOSE flag).
 > Opinions?

Yah, this might not be a bad idea, though I prefer FIF_LARVAL to NOTREADY :-)

Since I'm already in this code up to my elbows, I'll work on it.

        -- Jason R. Thorpe <>