From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ke72u-00071d-3y for qemu-devel@nongnu.org; Fri, 12 Sep 2008 07:42:40 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ke72t-00071J-3U for qemu-devel@nongnu.org; Fri, 12 Sep 2008 07:42:39 -0400 Received: from [199.232.76.173] (port=45569 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ke72t-00071G-1E for qemu-devel@nongnu.org; Fri, 12 Sep 2008 07:42:39 -0400 Received: from pelvoux.gotadsl.co.uk ([81.6.248.91]:39241) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Ke72s-0005Ik-Dy for qemu-devel@nongnu.org; Fri, 12 Sep 2008 07:42:38 -0400 Received: from localhost ([127.0.0.1] helo=ecrins ident=fozzy) by localhost with esmtp (Exim 4.69) (envelope-from ) id 1Ke6lm-0005gE-N7 for qemu-devel@nongnu.org; Fri, 12 Sep 2008 12:24:58 +0100 Date: Fri, 12 Sep 2008 12:24:58 +0100 From: Steve Fosdick Subject: Re: [Qemu-devel] How are the temporary files (-snapshot) created on Linux? In-Reply-To: <200809121218.50167.yann.morin.1998@anciens.enib.fr> (from yann.morin.1998@anciens.enib.fr on Fri Sep 12 11:18:50 2008) Message-Id: <1221218698.7793.0@ecrins> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org On 12/09/08 11:18:50, Yann E. MORIN wrote: > Hello! >=20 > On Friday 12 September 2008 08:04:02 EQX wrote: > > The code says the -snapshot temporary files are created here: =20 > > /tmp/vl.*, but they are never visible for users. Using lsof, > > they have a state of 'deleted'. How does this work exactly? > > What type of file is this? >=20 > It's done via some incantation of open(2) followed by unlink(2), > something > like: >=20 > int fd; > fd =3D open( "/tmp/vl.xxx", O_CREAT|... ); > unlink( "/tmp/vl.xxx" ); > /* Use the file somehow */ > close( fd ); >=20 > Regards, > Yann E. MORIN. There is nothing special about the files concerned. The key to this is=20 that, unlike some other operating systems, Linux (like Unix) allows an=20 open file to be deleted and has a well defined way to deal with that=20 happenning. When an open file is deleted only the file name is actually deleted. =20 The data in the file (and any new data written to the file) are kept=20 until the last process to have the file open closes the file whereupon=20 the second half of the delete happens, i.e. deallocating the disk=20 storage and returning it to the free space. This mechanism is exploited by a process that opens a file and=20 immediately deletes it like the example above for two reasons: 1. It provides a way to guarantee that the file not exist after the=20 process concerned has finished even if it finishes abnormally or gets=20 killed for some reason. 2. As a security measure. Once the file name has been deleted there is=20 no way for any other process to stumble upon the file and open it. The second point is negated somewhat by the /proc filesystem. Regards, Steve.