Date: Sun, 23 Feb 2020 18:24:11 +0000 From: Steve O'Hara-Smith <steve@sohara.org> To: freebsd-questions@freebsd.org Cc: Polytropon <freebsd@edvax.de> Subject: Re: rm | Cleaning up recycle bin Message-ID: <20200223182411.81a22ce74509b8778a39d8d3@sohara.org> In-Reply-To: <20200223184908.b35d656a.freebsd@edvax.de> References: <a589bf69-a53b-a732-08ff-74e09b723bbd@cloudzeeland.nl> <20200223184908.b35d656a.freebsd@edvax.de>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 23 Feb 2020 18:49:08 +0100 Polytropon <freebsd@edvax.de> wrote: > So if you use rm, and no process holds the file open, the disk > space occupied by the file will be freed immediately; if some > process still uses the file, its name will be removed (so you > cannot address it by that name anymore), but the disk space > will be freed when the process closes the file. Somebody needs to mention hard links here - so I'll chime in with the complicated version. The directory entry for a file is just a name pointing to the actual file defined by an inode (the data structure that holds everything there is about the file except the name). There can be many directory entries pointing to the same file (known as hard links) each one counts as a reference to the file as does every file handle held open by one or more processes. The inode and the data hanging off it becomes free and available for reuse as soon as there are no references (directory entries or open file handles) to it. Multiple entries for the same file are quite common for binaries, for example /bin/csh and /bin/tcsh are links to the same file, or for that matter nearly everything in /rescue is a link to the same file. When there are multiple links to a file none of them are special, they're all just links. The rm command, and the underlying unlink system call simply remove directory entries which reduces the reference count in the inode which is the actual file. When that count hits zero the file is freed - ie. the blocks in it and the inode are made available for use. How long it takes for freed space to get reused depends on a lot of things, not least being the amount of free space available but from the moment the last reference is gone it takes forensic effort to recover a file. -- Steve O'Hara-Smith <steve@sohara.org>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200223182411.81a22ce74509b8778a39d8d3>