一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

Hard Link --loop in the filesystem graph

 一葉扁舟 2006-12-26
Hard Link
v
In a traditional UNIX filesystem, a directory is just a file that contains an association list. The entries in that list map names, which are strings, to inode numbers, which are unique file identifiers. An inode number is essentially an on-disk pointer; the file object can be efficiently located from this number. No two objects have the same inode number, and no object has more than one inode number.
 
The term "hard link" is essentially just a synonym for "directory entry". When an object is created for the first time, a directory entry is created for it as well. This is in fact a hard link, but most people usually associate "hard linking" to be the creation of additional directory entries for an existing object. But the original entry is not special in any way; all the links are equal in the sense that there is no way to tell which was the original.
Directories can contain directories, of course, and this is done by hard links as well. When a subdirectory is created, a directory entry is created in the parent which associates the name of the subdirectory with the newly created inode. Also, the new subdirectory object is automatically stuffed with two entries which associate the names . and .. (dot and dotdot) with the new directory, and the parent, respectively. Therefore, the creation of a subdirectory creates a new hard link to the parent, and two new hard links to the new object: one from the parent, and one from its own dot entry.
Directory hard links are special. Firstly, the only way to create them is to create directories; the operating system functions for hard linking will not allow the target of a hard link operation to be a directory inode. The reason for that is that it could create cycles in the filesystem‘s directory structure. Depending on the kernel, the decision to allow a directory hard link may be deferred to the filesystem module itself.
[Dumb question: if it was possible two have two directories /p1/d1 and /p2/d2 hard linked to the same inode, what would be the result of "cd .." in each of this directory ? -- FabriceGautier]
If you mean, what if d1 and d2 were the same inode (or referenced the same inode, to be strictly accurate -- a directory entry merely associates a name with an inode) -- then the question is, what is the directory entry ".." associated with? You‘re assuming d1 and d2 are the same thing. Therefore they‘re only one directory, not two different directories. Therefore "they" have the same contents, including "..". When d1 or d2 is first created, ".." is created at the same time, as a hard link to the parent directory. So it basically depends on which was created first. Simple Directed Acyclic Graphs like this in the filesystem don‘t cause catastrophes, although they‘ll create user confusion in various circumstances.
Which is why you don‘t create any ".." links in directories. Only "parent named X" or something like it. The same issue comes up in language when you switch from single dispatch to multiple dispatch; "self" no longer has any meaning.
In a traditional UNIX filesystem, cycles are bad for two reasons: firstly, the reclamation of storage is based on reference counting, which doesn‘t handle cyclic references! The only backreferences are the .. and . entries, and these are handled as special cases.
Secondly, backreferences in the tree structure can lead to nasty multithreading problems. In the traditional kernel design, like the BSD kernel, inodes that are in use are represented by in-memory structures called vnodes. These nodes are accessed concurrently, and contain locks. Certain operations retain a lock on a directory while navigating to the subdirectory. In a cycled graph, this can lead to two processes trying to acquire a pair of locks on the same two objects, but in an opposite order, which will deadlock the processes. These locking operations are often done in a way that cannot be interrupted by a signal, so the processes will stay deadlocked until a reboot.
There are special hacks in BSD to avoid this deadlock when navigating the .. reference. Basically, the lock on the originating directory vnode is relinquished, the .. lock is acquired and then the originating directory is re-locked. Yes, it‘s basically an open race. It‘s possible that the original directory is deleted by the time the lock is re-acquired, for instance.
I once implemented a cycle detection algorithm for vnode locks, to try to support cyclic hard linking in a file system for a version of BSD, but the problem was that although the code itself worked beautifully, it was just too hard to make the rest of the kernel cooperate. Too many places in the kernel, in the higher layers above the filesystem drivers, simply assume that a lock will succeed, or eventually succeed, and are consequently not prepared to correctly deal with an EDEADLK error. It‘s not entirely clear, even, what to do with the information which tells you that a deadlock would occur if you were allowed to proceed. Do you abort the whole system call? At what level do you retry? How will applications respond to having random filesystem operations bail with deadlock errors.
And so that‘s about five paragraphs more than you ever wanted to know about hard links.f
-- KazKylheku

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多

    欧美一区二区不卡专区| 色偷偷偷拍视频在线观看| 日韩国产亚洲欧美另类 | 欧美人妻一区二区三区| 国产精品一区欧美二区| 国产偷拍盗摄一区二区| 色婷婷在线视频免费播放| 91国自产精品中文字幕亚洲| 99精品国产自在现线观看| 精品精品国产自在久久高清| 欧美日韩国产精品黄片| 99久久精品久久免费| 日韩一本不卡在线观看| 午夜免费精品视频在线看| 亚洲高清亚洲欧美一区二区| 亚洲国产精品无遮挡羞羞| 一区中文字幕人妻少妇| 欧美视频在线观看一区| 人妻内射精品一区二区| 偷拍洗澡一区二区三区| 欧美成人黄色一区二区三区| 亚洲精品中文字幕一二三| 国产欧美日韩不卡在线视频| 正在播放玩弄漂亮少妇高潮 | 后入美臀少妇一区二区| 亚洲欧洲日韩综合二区| 国产精品一区二区三区激情| 国产超薄黑色肉色丝袜| 人妻少妇系列中文字幕| 国内女人精品一区二区三区| 国产又粗又猛又爽又黄| 五月婷婷六月丁香在线观看| 精品视频一区二区不卡| 激情内射亚洲一区二区三区| 夫妻性生活真人动作视频| 精品久久综合日本欧美| 亚洲中文字幕高清乱码毛片| 91欧美视频在线观看免费| 日韩中文字幕人妻精品| 夫妻性生活真人动作视频| 国产一级不卡视频在线观看|