Eric Blake wrote: > rohit sharma wrote: > > but how is it possible to remove the directory in which you are > > On other implementations, such as Linux, removing the directory does > not free up any disk resources as long as a process still has a > reference to the inode occupied by that directory, but the rmdir > still succeeds by updating the parent directory to state that the > directory is no longer reachable via the filesystem. Then, when all > processes that use the unlinked directory have exited, the > filesystem can finally reclaim the disk space that the removed > directory occupied.
I like to think of it as a garbage collection system implemented using reference counting. Every file (and special files such as directories) have a reference count. Files can be hard linked and so have a large count of referencing directories pointing to them. Additionally the system keeps track of open file descriptors which also add to the reference count. Removing a file from a directory decrements the reference count because when they are removed from their parent directory then the parent directory is no longer pointing to them. Closing file descriptors also decrements the reference count. The system keeps disk blocks around as long as the reference count is non-zero. The system automatically reclaims any disk blocks that have a reference count of zero. None of that is exactly true but it is a useful mental model of filesystem operation just the same. Bob _______________________________________________ Bug-coreutils mailing list [email protected] http://lists.gnu.org/mailman/listinfo/bug-coreutils
