關於 link 的問題,這兩天在 news 上也有討論。
下面是我發表的其中兩篇:
netman@junk.com> 在郵件 news:c8s6dg$9qd$1@news.seed.net.tw 中撰寫...
>
> "國父" <
d2207197.bbs@bbs.sayya.org> 在郵件 news:4CLUSJ$1vm@bbs.sayya.org 中撰寫
> ...
> > ※ 引述《ycheng (ycheng)》之銘言:
> > > 這個一定錯. 因為 soft link 是 by name, 不是 by inode.
> > > 有一個可能是, soft_inode 指到 另一個 file_block, file block 裡面放
> > > 字串, 內容就是指過去的 file_path_name, 在此就是 "file"
> > 根據
> >
http://phorum.study-area.org/viewtopic.php?t=12235&highlight=hard+link+soft> > octapult 大的說法是
> > 「在建立 soft link 的時候才會建立一個新的 inode 指到原始檔案的 inode」
> >
> > 而 netman 說
> > 「要是 soft link ,因為本身就要消耗 inode table entry,
> > 因此肯定回用掉一些空間。但是否為 data block 上的空間呢?不需要,
> > 用掉 inode table 的空間而已。 」
> > 所以說創建一個 soft link 並沒有多一個 file block
> >
> > 當然前提是他們倆個講的都對囉 ^^
>
> 我可以肯定的是:
> * soft link 的 pointer 不是指向別的 inode ,而是一個 path_name 。
>
> 至於 pointer 寫在 inode table 裡還是在另一個 data-block?
> 我之前是以為在 inode table 。
> 不過,數星期前去參觀一位朋友的 office 時,
> 在空餘時翻到一本 O'Reilly 的 Unix 管理手冊(全名我忘了),
> 在談到 soft link 時有一個圖解,卻是:
> * inode 指到 data-block ,再指到 path_name 去。
>
> 嗯,由於我沒有深入追過 Linux kernel 這方面的資料,
> 我也不確定 soft link 究竟耗不耗 data-block 。
> 我想,這得請其它朋友幫忙解釋了...
>
>
> --
>
> =======
http://www.study-area.org =======
> 飛雪迎春到﹐風雨送春歸
> 已是寒崖百丈冰﹐尤有花枝俏
> 俏也不爭春﹐只把春來報
> 待得山花爛漫時﹐他在叢中笑﹗
>
"網中人" <
netman@junk.com> 在郵件 news:c8s8ao$a7c$1@news.seed.net.tw 中撰寫...
>
> "夏天來了 小肚不要來" <
Quota.bbs@bbs.mcu.edu.tw> 在郵件
> news:4CMDOb$0GU@bbs.mcu.edu.tw 中撰寫...
> > ※ 引述《Neisseria.bbs@ptt.cc (Neisseria)》之銘言:
> > > 那請問一下
> > > 就"功能"上來說
> > > 為什麼需要兩種 link
> > > 看了討論串不是很懂 @@
> > > 大概是我用得太少了
> > > 我都只用 soft link 而已
> > 這部分我也很好奇
> > 不知其他大大 在怎樣的情況下會用hard link?
>
> 我不知那些大大們如何用的,以在下之愚,大概想到的如下:
>
> 1) 防止檔案被誤刪
> 當然,你有做 backup 或用 copy 也行。
> 但這些方法有同步上的不足,以及空間的消耗。
> 假設你習慣了用 root 來操作系統(這是非常不好的習慣﹗),
> 某天意外的不小心的刪了某一重要的檔又沒有備份,
> 這時,你的脊骨應該整根透著濃濃的寒意吧?﹗
> 若,被刪的檔案還有一個 hard link 呢?
> 哈哈,simple: link it back! ^_^
>
> 2) 版本兼容策略
> 再以前面所引的酷學園討論為例:gcat 與 gzip 與 gunzip 都是 hard link 。
> 我不清楚原程式設計者的真正意圖。
> 但換作是我,我或許會想到:
> * 這幾個 program 的 code 有大部份是相同的。
> * 要更新的話,我只想改一個 file 就好。
> * 若有人不想要其中一個 program ,砍掉即可。
> 那,或許還有人說:用 library 就好...
> fine ~~~ 若我"就是偏偏"不喜歡用 library 呢?
> (或許是我懶,或許我不想動系統函式庫,或許....)
> 那,用 soft link 不可以嗎?
> 也 fine ~~~~ 但我本想砍掉 zcat 不用呢?(別問我理由了,可以"掰"很多... ^_^)
> 若 zcat 是個 soft link ,那 okay ,若好死不死,他是本尊呢?﹗
>
> 3) 降低 inode 消耗
> 若你還用 ext2/ext3 這種"落後(相較於先進而言)"的 file system,
> 都應該知到 inode block 是有限的,且不能調整的(除非重做 mkfs)。
> 那麼,用 soft link 與用 hard link 對 inode 的消耗來說,不言而諭了吧﹗
>
> 不過,用 soft link 還是有其好處的:
> * 可以跨不同 file system
> * 可以 link directory
> 前者我可以解釋為何 hard link 做不到。
> 但是,hard link 為何不能 link directory ? 卻是我一直想不透的地方。
> 不知哪位朋友出來解惑一下呢?謝謝﹗
>
>
> --
>
> =======
http://www.study-area.org =======
> 飛雪迎春到﹐風雨送春歸
> 已是寒崖百丈冰﹐尤有花枝俏
> 俏也不爭春﹐只把春來報
> 待得山花爛漫時﹐他在叢中笑﹗
>
[/list]
還有更多後續討論(我會隨時補充):
lcp.bbs@bbs.sayya.org> 在郵件 news:4CMN09$2zz@bbs.sayya.org 中撰寫...
> ※ 引述《d2207197 (國父)》之銘言:
> > 假使某個目錄下面有一個叫做 file 的檔案
> > ln file hard
> > ln -s file soft
> > 當進到這個目錄時 ┌─────────────┐
> > Directory Inode --> │ Directory Block │
> > ├─────────────┤
> > ┌─────┼>file file_inode_number ┼─┬─> file_inode ─┐
> > │ │ hard file_inode_number ┼─┘ V
> > │ │ soft soft_inode_number │ file_block
> > │ └───────┼─────┘
> > │ V
> > └ soft_block存在呼?? <─ soft_inode
> 根據Advanced Programming in the Unix Environment這本書裡面的p.94
> .. symbolic link, the actual contents of the file(the data blocks)
> contains the name of the file that the symbolic link points to.
> 所以應該是有佔block
>
> 小實驗:
> ln email em ; ln -s email ems ; ls -l
>
> -rw-r--r-- 2 lcp lcp 60 11月 21 2003 em
> -rw-r--r-- 2 lcp lcp 60 11月 21 2003 email
> lrwxr-xr-x 1 lcp lcp 5 5月 24 20:38 ems -> email
>
> 我的小結論:
> em是hard link,所佔的大小跟email一樣,所以應該是直接用inode指向email的
> block。而ems是symbolic link,所佔的大小剛剛好是5bytes,所以是一個檔案
> 包了email這個string。
>
> 有錯歡迎指正^^
"lloyd huang" <
lloyd@nomail.com> 在郵件 news:c8st0m$101d$1@adenine.netfront.net 中撰寫...
> 網中人 wrote:
> > 不過,用 soft link 還是有其好處的:
> > * 可以跨不同 file system
> > * 可以 link directory
> > 前者我可以解釋為何 hard link 做不到。
> > 但是,hard link 為何不能 link directory ? 卻是我一直想不透的地方。
> > 不知哪位朋友出來解惑一下呢?謝謝﹗
> ========>
> 1)
> GNU OPTIONS
> -d, -F, --directory
> Allow the super-user to make hard links to directories.
> 2)
> -d, -F, --directory
> hard link directories (super-user only)
>
> 3)
> -d, -F, --directory allow the superuser to attempt to hard link
> directories (note: will probably fail due to
> system restrictions, even for the superuser)
>
>
http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?hard+links> <%
> The standard ln command does not usually allow you to create a hard link to
> a directory, chiefly because the standard rm and rmdir commands do not
> allow you to delete such a link. Some systems provide link and unlink
> commands which give direct access to the system calls of the same name, for
> which no such restrictions apply.
> %>
>
>
http://www.dewassoc.com/kbase/hard_drives/file_systems_unix.htm> <%
> Links:
>
> A link is a pointer to another file. Remember that a directory is
> nothing more than a list of the names and i-numbers of files. A directory
> entry can be a hard link, in which the i-number points directly to another
> file. A hard link to a file is indistinguishable from the file itself. When
> a hard link is made, then the i-numbers of two different directory file
> entries point to the same inode. For that reason, hard links cannot span
> across file systems. A soft link (or symbolic link) provides an indirect
> pointer to a file. A soft link is implemented as a directory file entry
> containing a pathname. Soft links are distinguishable from files, and can
> span across file systems. Not all versions of UNIX support soft links.
> %>
>
> Advanced Programming in the UNIX Environment (國際中文版)
> 3.14 檔案系統 (page 92 頁)
> 3.16 符號連結 (page 101 頁)
> (書上的解釋十分詳細)
> --
> ◢◣
> □□□ ██ □□□□
> □ ◢█□ 造形.空間.秩序.
> □ ███◣ 主從.對比.韻律
>
"網中人" <
netman@junk.com> 在郵件 news:c8svvk$ht9$1@news.seed.net.tw 中撰寫...
>
> "lloyd huang" <
lloyd@nomail.com> 在郵件 news:c8st0m$101d$1@adenine.netfront.net
> 中撰寫...
> > Links:
> >
> > A link is a pointer to another file. Remember that a directory is
> > nothing more than a list of the names and i-numbers of files. A directory
> > entry can be a hard link, in which the i-number points directly to another
> > file. A hard link to a file is indistinguishable from the file itself. When
> > a hard link is made, then the i-numbers of two different directory file
> > entries point to the same inode. For that reason, hard links cannot span
> > across file systems. A soft link (or symbolic link) provides an indirect
> > pointer to a file. A soft link is implemented as a directory file entry
> > containing a pathname. Soft links are distinguishable from files, and can
> > span across file systems. Not all versions of UNIX support soft links.
> > %>
> >
> > Advanced Programming in the UNIX Environment (國際中文版)
> > 3.14 檔案系統 (page 92 頁)
> > 3.16 符號連結 (page 101 頁)
> > (書上的解釋十分詳細)
>
> 嗯,感謝黃老師說明﹗過然有所獲~~~ ^_^
>
> 從如下這句來看:
> > A soft link (or symbolic link) provides an indirect pointer to a file.
> 似乎所耗的也不是 data-block 而是 indirect block 而已。
> 根據 ext2 file system 的設計,
> 是透過所謂的 direction + three level indirection 來找到所有的 data-block 的:
> * directly address 在 inode 內,可有 12 個位址指標。
> * first indirect block 可有定址 256 個 data-block
> * second indirect block 可定址 65536(256^2) 個 data-block
> * third indirect block 可定址 16777216(256^3) 個 data-block
>
> 這裡,我想請教黃老師的是:
> --- 究竟 soft link 的 pointer 是寫在如下那一個部份呢?
> 1) inode 之 direct address field
> 2) indirect blocks (1st/2nd/3rd)
>
> 因為手上沒有您提到的書本,一時偷懶,先來請教您了... ^_^
> 謝謝﹗
>
>
"lloyd huang" <
lloyd@nomail.com> 在郵件 news:c8tc87$1ve6$1@adenine.netfront.net 中撰寫...
> 網中人 wrote:
> > "lloyd huang" <
lloyd@nomail.com> 在郵件
> >> Advanced Programming in the UNIX Environment (國際中文版)
> >> 3.14 檔案系統 (page 92 頁)
> >> 3.16 符號連結 (page 101 頁)
> >> (書上的解釋十分詳細)
>
> 強烈建議去翻翻這本書,翻過之後在多的解釋我都會認為很多餘.. ^_^
>
> > 嗯,感謝黃老師說明﹗過然有所獲~~~ ^_^
> >
> > 從如下這句來看:
> >> A soft link (or symbolic link) provides an indirect pointer to a file.
> > 似乎所耗的也不是 data-block 而是 indirect block 而已。
> > 根據 ext2 file system 的設計,
> > 是透過所謂的 direction + three level indirection 來找到所有的 data-block 的:
> > * directly address 在 inode 內,可有 12 個位址指標。
> > * first indirect block 可有定址 256 個 data-block
> > * second indirect block 可定址 65536(256^2) 個 data-block
> > * third indirect block 可定址 16777216(256^3) 個 data-block
> >
> > 這裡,我想請教黃老師的是:
> > --- 究竟 soft link 的 pointer 是寫在如下那一個部份呢?
> > 1) inode 之 direct address field
> > 2) indirect blocks (1st/2nd/3rd)
> >
> > 因為手上沒有您提到的書本,一時偷懶,先來請教您了... ^_^
> > 謝謝﹗
>
> -_-||| 冒冷汗... 抖抖抖抖....實在是很害怕,
> 你翻出來的資料,我才疏學淺實在是有看而不是很懂,可能要麻煩你
> 引出全文來好好研究看看。
>
> Advanced Programming in the UNIX Environment (國際中文版)
> (page 92)
> * 其他形式的連結稱為符號連結(symbolic link)。符號連結檔案的實際內容
> (資料區塊)包括該符號連結所指的檔案名稱.........
>
> 3.1.17 symlink 與 readlink 函式 (page 102)
> 略『 open 函式會使用符號連結.......可透過 readlink 完成.』
> PS: 書云: readlink 是結合 open , read , close 三個動作
> 我實際試過直接 open read close, 其實是讀不出內容來的。
> 非得用 readlink () 不可。
>
> 查了一下 readlink 在 linux 應該是 kernel system call
> $> less fs/ext2/symlink.c
> $> less fs/ext3/symlink.c
> $> less fs/sysv/symlink.c
> $> less fs/ufs/symlink.c
> ......
> static int ext2_readlink(struct dentry *dentry, char *buffer, int buflen)
> {
> char *s = (char *)dentry->d_inode->u.ext2_i.i_data;
> return vfs_readlink(dentry, buffer, buflen, s);
> }
>
> 其實到了 kernel system call 之後,我就無能為力了。
> --
> ◢◣
> □□□ ██ □□□□
> □ ◢█□ 造形.空間.秩序.
> □ ███◣ 主從.對比.韻律
>
"小州" <
kenduest.bbs@bbs.sayya.org> 在郵件 news:4CMSCR$2Xo@bbs.sayya.org 中撰寫...
> ※ 引述《lloyd@nomail.com (lloyd huang)》之銘言:
> > 網中人 wrote:
> > > 不過,用 soft link 還是有其好處的:
> > > * 可以跨不同 file system
> > > * 可以 link directory
> > > 前者我可以解釋為何 hard link 做不到。
> > > 但是,hard link 為何不能 link directory ? 卻是我一直想不透的地方。
> > > 不知哪位朋友出來解惑一下呢?謝謝﹗
> > ========>
> > 1)
> > GNU OPTIONS
> > -d, -F, --directory
> > Allow the super-user to make hard links to directories.
> > 2)
> > -d, -F, --directory
> > hard link directories (super-user only)
> > 3)
> > -d, -F, --directory allow the superuser to attempt to hard link
> > directories (note: will probably fail due to
> > system restrictions, even for the superuser)
>
> 這參數目前只有提供 "參考" 而已。
>
> 一般 hard link 用於目錄目前暫時是無法達成的,一但使用都會出現 operation
> not permitted 這類訊息。
>
> 目錄不大允許使用 hard link,這其中原因一般來說在於 hard link 要於目錄
> 使用的話,表示該目錄內的所有檔案與包含子目錄都要被進行 hard link 動作,
> 結果層面已經脫離了單純一般檔案項目的 hard link 情況。
>
> 再來,一但可以允許 hard link 於該目錄,若你在該目錄內建立一個檔案
> 與目錄,這表示這兩個目錄的檔案都要再處理 hard link 情況,那整個
> 環境會變得非常複雜。
>
> --
> 相信一種真誠存在於心與心之間...
> --
"lloyd huang" <
lloyd@nomail.com> 在郵件 news:c8te11$22rr$1@adenine.netfront.net 中撰寫...
> 小州 wrote:
> > ※ 引述《lloyd@nomail.com (lloyd huang)》之銘言:
> >> 網中人 wrote:
> >> > 不過,用 soft link 還是有其好處的:
> >> > * 可以跨不同 file system
> >> > * 可以 link directory
> >> > 前者我可以解釋為何 hard link 做不到。
> >> > 但是,hard link 為何不能 link directory ? 卻是我一直想不透的地方。
> >> > 不知哪位朋友出來解惑一下呢?謝謝﹗
> >> ========>
> >> 1)
> >> GNU OPTIONS
> >> -d, -F, --directory
> >> Allow the super-user to make hard links to directories.
> >> 2)
> >> -d, -F, --directory
> >> hard link directories (super-user only)
> >> 3)
> >> -d, -F, --directory allow the superuser to attempt to hard link
> >> directories (note: will probably fail due
> >> to system restrictions, even for the
> >> superuser)
> >
> > 這參數目前只有提供 "參考" 而已。
> >
> > 一般 hard link 用於目錄目前暫時是無法達成的,一但使用都會出現 operation
> > not permitted 這類訊息。
> >
> > 目錄不大允許使用 hard link,這其中原因一般來說在於 hard link 要於目錄
> > 使用的話,表示該目錄內的所有檔案與包含子目錄都要被進行 hard link 動作,
> > 結果層面已經脫離了單純一般檔案項目的 hard link 情況。
> >
> > 再來,一但可以允許 hard link 於該目錄,若你在該目錄內建立一個檔案
> > 與目錄,這表示這兩個目錄的檔案都要再處理 hard link 情況,那整個
> > 環境會變得非常複雜。
>
> 州大說的沒錯不會動
>
> hard link 也有可能會造成檔案系統的 loop
> $> mkdir foo
> $> touch foo/a
> $> ln ../foo foo/testdir
>
> foo
> foo/a
> foo/testdir
> foo/testdir/testdir/a
> foo/testdir/testdir/testdir
> foo/testdir/testdir/testdir/a
> .......
>
> 書註解:作者實際測試,結果檔案系統毀損......fsck 修復無效,需動用 clri dcheck 云云.
> 目錄無法 hard link 看來並非沒有道理
> --
> ◢◣
> □□□ ██ □□□□
> □ ◢█□ 造形.空間.秩序.
> □ ███◣ 主從.對比.韻律
>
"阿西" <
yuhsi.bbs@bbs.cis.nctu.edu.tw> 在郵件 news:4CMh9f$J5b@bbs.cis.nctu.edu.tw 中撰寫...
> ==> 在 lloyd huang <
lloyd@nomail.com> 的文章中提到:
> > 網中人 wrote:
> > > "lloyd huang" <
lloyd@nomail.com> 在郵件
> > 強烈建議去翻翻這本書,翻過之後在多的解釋我都會認為很多餘.. ^_^
> > > 嗯,感謝黃老師說明﹗過然有所獲~~~ ^_^
> > > 從如下這句來看:
> > > 似乎所耗的也不是 data-block 而是 indirect block 而已。
> > > 根據 ext2 file system 的設計,
> > > 是透過所謂的 direction + three level indirection 來找到所有的 data-block 的:
> > > * directly address 在 inode 內,可有 12 個位址指標。
> > > * first indirect block 可有定址 256 個 data-block
> > > * second indirect block 可定址 65536(256^2) 個 data-block
> > > * third indirect block 可定址 16777216(256^3) 個 data-block
> > > 這裡,我想請教黃老師的是:
> > > --- 究竟 soft link 的 pointer 是寫在如下那一個部份呢?
> > > 1) inode 之 direct address field
> > > 2) indirect blocks (1st/2nd/3rd)
> > > 因為手上沒有您提到的書本,一時偷懶,先來請教您了... ^_^
> > > 謝謝﹗
> > -_-||| 冒冷汗... 抖抖抖抖....實在是很害怕,
> > 你翻出來的資料,我才疏學淺實在是有看而不是很懂,可能要麻煩你
> > 引出全文來好好研究看看。
> > Advanced Programming in the UNIX Environment (國際中文版)
> > (page 92)
> > * 其他形式的連結稱為符號連結(symbolic link)。符號連結檔案的實際內容
> > (資料區塊)包括該符號連結所指的檔案名稱.........
> > 3.1.17 symlink 與 readlink 函式 (page 102)
> > 略『 open 函式會使用符號連結.......可透過 readlink 完成.』
> > PS: 書云: readlink 是結合 open , read , close 三個動作
> > 我實際試過直接 open read close, 其實是讀不出內容來的。
> > 非得用 readlink () 不可。
> > 查了一下 readlink 在 linux 應該是 kernel system call
> > $> less fs/ext2/symlink.c
> > $> less fs/ext3/symlink.c
> > $> less fs/sysv/symlink.c
> > $> less fs/ufs/symlink.c
> > .......
> > static int ext2_readlink(struct dentry *dentry, char *buffer, int buflen)
> > {
> > char *s = (char *)dentry->d_inode->u.ext2_i.i_data;
> > return vfs_readlink(dentry, buffer, buflen, s);
> > }
> > 其實到了 kernel system call 之後,我就無能為力了。
>
> 網中人 好久不見了
> 這篇我本來昨晚有回 不過後來看到"黃老師"一詞 我又把他給刪了
> 想說你本來問別人的 阿 我又姓黃 不好意思
> 現在看了回答 所以現在又來越狙代庖一下
>
> 其實這個不用去看到kernel code啦
>
> soft link 是在所謂的directory entry放檔名跟inode的對應
> 那... 啥米是directory entry???
> directory entry 其實就是一個檔案
> 所以他是會佔data block的
> 只不過指著這個特殊檔案的inode會說明這個檔案是directory entry檔
> 會用特別的function去讀他 如果OS中檔案大小有限制 檔案個數有限制等等
>
> 在一般unix like的OS的file system都差不多是這樣
> linux比教科書多了block group吧 這是為甚麼 linux/unix系統
> 不需要defrag的原因
>
> 這個去看
>
http://www.tldp.org/LDP/tlk/fs/filesystem.html> 的directory entry那邊
>
> In the EXT2 file system, directories are special files that are used to
> create and hold access paths to the files in the file system. Figure 9.3
> shows the layout of a directory entry in memory.
>
> A directory file is a list of directory entries, each one containing the
> following information:
>
> inode
> The inode for this directory entry. This is an index into the array of
> inodes held in the Inode Table of the Block Group. In figure 9.3,
> the directory entry for the file called file has a reference to inode
> number i1,
> name length
> The length of this directory entry in bytes,
> name
> The name of this directory entry.
>
> The first two entries for every directory are always the standard ``.''
> and ``..'' entries meaning ``this directory'' and ``the parent directory''
> respectively.
>
>
> 至於direct indirect reference那是檔案大小跟搜尋效率的平衡作法
> 檔案小時 用那12個direct對應就一下直接找到對應的block
> 檔案大時 就要用複雜點的indirect去找
> 所以要看這個directory下的檔案多不多 檔名長不長 使得directory entry太大
>
> 所以direct indirect跟soft link沒甚麼關係 只是檔案大小跟定址的關係
>
"網中人" <
netman@junk.com> 在郵件 news:c8ukj6$4b1$1@news.seed.net.tw 中撰寫...
>
> "阿西" <
yuhsi.bbs@bbs.cis.nctu.edu.tw> 在郵件
> news:4CMh9f$J5b@bbs.cis.nctu.edu.tw 中撰寫...
> >
> > 至於direct indirect reference那是檔案大小跟搜尋效率的平衡作法
> > 檔案小時 用那12個direct對應就一下直接找到對應的block
> > 檔案大時 就要用複雜點的indirect去找
> > 所以要看這個directory下的檔案多不多 檔名長不長 使得directory entry太大
> >
> > 所以direct indirect跟soft link沒甚麼關係 只是檔案大小跟定址的關係
>
> 哦,謝謝 Cyril 兄的說明﹗看來是我理解了 宇新兄 的貼子了:
> > A soft link (or symbolic link) provides an indirect pointer to a file.
> 上句的 indirect 並不是指 indirect block ,
> 而是一個定語冠詞,以修飾 pointer 之用的... ^_^
>
> 不過,我的疑問還沒解決:
> --> 究竟 soft link 的 indirect pointer 寫在哪?
>
> 能否再請兩位黃老師及其他前輩解惑嗎?
>
>
> 回宇新:
> 我的資料主要來源於:
> 1) 百資出版的"Linux 核心"(ISBN:957-97830-4-7)第128-130頁
> 2) IBM Linux 教材(LX03, ERC3.0)第10節
> 3) John's spec of the second extended filesystem
>
http://uranus.it.swin.edu.au/~jn/explore2fs/es2fs.htm> 4) Design and Implementation of the Second Extended Filesystem
>
http://e2fsprogs.sourceforge.net/ext2intro.html>
> --
>
> =======
http://www.study-area.org =======
> 飛雪迎春到﹐風雨送春歸
> 已是寒崖百丈冰﹐尤有花枝俏
> 俏也不爭春﹐只把春來報
> 待得山花爛漫時﹐他在叢中笑﹗
"阿西" <
yuhsi.bbs@bbs.cis.nctu.edu.tw> 在郵件 news:4CN4Qe$JPk@bbs.cis.nctu.edu.tw 中撰寫...
> ==> 在 "網中人" <
netman@junk.com> 的文章中提到:
> > "阿西" <
yuhsi.bbs@bbs.cis.nctu.edu.tw> 在郵件
> > news:4CMh9f$J5b@bbs.cis.nctu.edu.tw 中撰寫...
> > > 至於direct indirect reference那是檔案大小跟搜尋效率的平衡作法
> > > 檔案小時 用那12個direct對應就一下直接找到對應的block
> > > 檔案大時 就要用複雜點的indirect去找
> > > 所以要看這個directory下的檔案多不多 檔名長不長 使得directory entry太大
> > > 所以direct indirect跟soft link沒甚麼關係 只是檔案大小跟定址的關係
> > 哦,謝謝 Cyril 兄的說明﹗看來是我理解了 宇新兄 的貼子了:
> > > A soft link (or symbolic link) provides an indirect pointer to a file.
> > 上句的 indirect 並不是指 indirect block ,
> > 而是一個定語冠詞,以修飾 pointer 之用的... ^_^
> 好吧 forget about anything about the 12 direct, indirect, doubly indirect...
> ^_^
>
> 這邊講的是非直接的指向某個神秘地方
> 那就是那個soft link的檔案內容
> 我想in memory inode或 in disk indoe應該沒有indirect pointer這樣名詞
>
> > 不過,我的疑問還沒解決:
> > --> 究竟 soft link 的 indirect pointer 寫在哪?
> > 能否再請兩位黃老師及其他前輩解惑嗎?
> 好像前面lcp 與lloyd兄已經有答案了
> 就是那個symbolic檔內的內容 是link的那個檔名
> 所以還是要佔data block的 其實通通都要佔data block 只是hard link佔的少
> 只有directory entry
>
> readlink(1) readlink(2)都可以看到soft link檔內容
> ?
> ext2的readlink
> static int ext2_readlink(struct dentry *dentry, char *buffer, int buflen)
> {
> char *s = (char *)dentry->d_inode->u.ext2_i.i_data;
> return vfs_readlink(dentry, buffer, buflen, s);
> }
> 只是很單純的把inode的檔案內容還回去 在vfs_readlink就是copy_to_user();
> 所以要檢查的是
> symlink這個system call怎麼寫下去的
> 所以在ext2_symlink裡面有一段
>
> inode = ext2_new_inode (dir, S_IFLNK | S_IRWXUGO);
> err = PTR_ERR(inode);
> if (IS_ERR(inode))
> goto out;
>
> if (l > sizeof (inode->u.ext2_i.i_data)) {
> /* slow symlink */
> inode->i_op = &page_symlink_inode_operations;
> inode->i_mapping->a_ops = &ext2_aops;
> err = block_symlink(inode, symname, l);
> if (err)
> goto out_fail;
> } else {
> /* fast symlink */
> inode->i_op = &ext2_fast_symlink_inode_operations;
> memcpy((char*)&inode->u.ext2_i.i_data,symname,l);
> inode->i_size = l-1;
> }
> symname在這邊被memcpy到inode->u.ext2_i.i_data了
> 最後會被ext2_update_inode寫入
>
[/list]