取消链接的工作原理是什么? [英] How exactly does unlink work?

查看:59
本文介绍了取消链接的工作原理是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解它的工作原理.

I'm having a little difficulty understanding how exactly this works.

似乎unlink()将删除引用文件数据的inode,但实际上不会删除数据.如果是这样,

It seems that unlink() will remove the inode which refers to the file's data, but won't actually delete the data. If this is the case,

a)数据如何处理?大概它不会永远存在,否则人们会一直用光磁盘空间.最终还有其他事情可以解决删除没有关联的inode的数据的问题吗?

a) what happens to the data? Presumably it doesn't stick around forever, or people would be running out of disk space all the time. Does something else eventually get around to deleting data without associated inodes, or what?

b)如果数据什么都没有发生:如何实际删除它?如果自动发生了什么:我该如何在命令中进行?

b) if nothing happens to the data: how can I actually delete it? If something automatically happens to it: how can I make that happen on command?

(辅助问题:如果shell命令rmunlink基本上执行相同的操作,就像我在此处阅读的其他问题一样,而Perl unlink只是对此的另一个调用,那么又有什么意义呢?像File::Remove这样的模块,似乎又做了完全相同的事情?我意识到有不止一种方法可以做到这一点",但是这似乎是" say <的一种以上方法"的情况/em> it",其中"it"始终指的是同一操作.)

(Auxiliary question: if the shell commands rm and unlink do essentially the same thing, as I've read on other questions here, and Perl unlink is just another call to that, then what's the point of a module like File::Remove, which seems to do exactly the same thing again? I realize "there's more than one way to do it", but this seems to be a case of "more than one way to say it", with "it" always referring to the same operation.)

简而言之:我可以确定删除文件实际上导致立即释放其磁盘空间吗?

In short: can I make sure deleting a file actually results in its disk space being freed up immediately?

推荐答案

磁盘上的每个inode都有一个引用计数-它知道有多少地方引用它.目录条目是参考.可以存在对同一inode的多个引用. unlink删除引用.当引用计数为零时,该索引节点将不再使用,并且可以删除.这是多少项工作,例如硬链接和快照.

Each inode on your disk has a reference count - it knows how many places refer to it. A directory entry is a reference. Multiple references to the same inode can exist. unlink removes a reference. When the reference count is zero, then the inode is no longer in use and may be deleted. This is how many things work, such as hard linking and snap shots.

特别是-一个打开的文件句柄是一个引用.因此,您可以打开文件,取消链接并继续使用它-仅在关闭文件句柄后才能将其删除(前提是引用计数降至零,并且在其他任何位置均未打开/硬链接).

In particular - an open file handle is a reference. So you can open a file, unlink it, and continue to use it - it'll only be actually removed after the file handle is closed (provided the reference count drops to zero, and it's not open/hard linked anywhere else).

这篇关于取消链接的工作原理是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆