Linux中的“过时文件处理"是什么意思? [英] What does 'stale file handle' in Linux mean?

查看:104
本文介绍了Linux中的“过时文件处理"是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我打开了一个终端,并通过该终端将cd编辑到某个目录.通过另一个终端,我删除该目录,然后从相同的备份将其还原.当我尝试从第一个终端的vim文件位于同一目录中时,为什么会收到有关陈旧文件句柄的错误消息?这是什么意思? (从侧面看,我发现可以通过cd $(pwd)绕过此问题.)

Say I have a terminal open, and through that terminal I have cd'ed to some directory. Through another terminal, I delete that directory and restore it back from an identical backup. When I try to vim a file from the first terminal, in the same directory, why do I get an error about a stale file handle? What does it mean? (On a side note, I have found that it is possible to bypass this issue through cd $(pwd).)

推荐答案

删除目录后, inode 用于该目录(及其内容的索引节点)被回收.您的外壳程序指向该目录的索引节点(及其内容的索引节点)的指针现在不再有效.从备份中还原目录后,旧的inode不会(必须)被重用.该目录及其内容存储在随机索引节点上.唯一保持相同的地方是 parent 目录为恢复的目录重用了相同的名称(因为您告诉过它).

When the directory is deleted, the inode for that directory (and the inodes for its contents) are recycled. The pointer your shell has to that directory's inode (and its contents's inodes) are now no longer valid. When the directory is restored from backup, the old inodes are not (necessarily) reused; the directory and its contents are stored on random inodes. The only thing that stays the same is that the parent directory reuses the same name for the restored directory (because you told it to).

现在,如果您尝试访问原始Shell仍指向的目录的内容,它将把该请求传达给文件系统,作为对原始inode的请求,此原始inode已被回收(甚至可能位于现在用于完全不同的东西).这样您会收到一条stale file handle消息,因为您要求提供一些不存在的数据.

Now if you attempt to access the contents of the directory that your original shell is still pointing to, it communicates that request to the file system as a request for the original inode, which has since been recycled (and may even be in use for something entirely different now). So you get a stale file handle message because you asked for some nonexistent data.

当执行cd操作时,shell将重新评估您提供给它的任何目的地的inode位置.现在,您的外壳程序知道目录的新索引节点(及其内容的索引节点),以后对其内容的请求将是有效的.

When you perform a cd operation, the shell reevaluates the inode location of whatever destination you give it. Now that your shell knows the new inode for the directory (and the new inodes for its contents), future requests for its contents will be valid.

这篇关于Linux中的“过时文件处理"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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