作業系統›Ch10 檔案管理第 2 題/共 28 題
2. File Opening、File Control Block、Open File Table
#OS-10-002中File OpeningFile Control BlockOpen File Table
下圖顯示作業系統中,從檔案系統開啟一個檔案時,在 user space、kernel memory、secondary storage 中所使用的資料結構範例。圖中圓圈內的數字代表電腦系統中的一個操作步驟。
請針對上圖選出正確的敘述。

參考答案與解析
答案 (E)。
依附圖,開啟檔案的流程是:
- ① user process 呼叫
open("foo.txt"),經由 system call interface 進入 kernel。 - ② 在記憶體中的 directory structure cache 查詢檔名,找出 FCB 的位置。
- ③ cache 裡沒有時,到 secondary storage 的 directory structure 查詢。
- ④ 檔案尚未被開啟過時,從 secondary storage 讀出 FCB,在 system-wide open-file table 建立一筆 entry 存放 FCB 資訊。
- ⑤ 在這個 process 的 per-process open-file table 建立一筆 entry,指向 system-wide table 的那筆 entry,並把 file descriptor 回傳給 user process。
逐項檢查:
- (A) 錯。① 只是發出 open 系統呼叫,不負責檢查同一目錄下有沒有重複的檔名。
- (B) 錯。② 是查詢目錄,不會回傳 file descriptor。file descriptor 在 ⑤ 才產生,而且是回傳給 user process,不是給 system-wide open-file table。
- (C) 錯。③ 是在 secondary storage 的 directory structure 裡查詢檔名,不是建立新的目錄 entry。
- (D) 錯。檔案已經被別的 process 開啟過時,system-wide table 已有它的 entry,只要把 reference count 加一、不必再做 ④;但這個 process 仍然需要自己的 per-process entry 與 file descriptor,所以 ⑤ 一定會執行。
- (E) 對。檔案尚未被開啟過時,system-wide open-file table 裡沒有它的 entry,要由 ④ 把 FCB 讀進來建立一筆。
📄 台大114
▤完整推導請見《WH 資工筆記 · 作業系統》Ch10 檔案管理