Kipper
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    2
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # OS筆記-Chapter 10: File-System Interface ###### tags: `OS` --- #### 目錄 * 總論 [Chapter 1: Introduction](https://hackmd.io/NoZq3J7IQvOQpcbo_tctjA) [Chapter 2: Operating-System Structures](https://hackmd.io/OKykRLBESI6v9a13HgS35A) * 行程管理 [Chapter 3: Processes](https://hackmd.io/HOqN-iQ3RIKIC-NB9QjBIQ) [Chapter 4: Threads](https://hackmd.io/qzAIHeSASmKuecdkqidmHw) [Chapter 5: CPU Scheduling](https://hackmd.io/IT5g2wHzTdOtMSDXPVEpOw) [Chapter 6: Process Synchronization](https://hackmd.io/rv-PNe3ESxi08PElyUTc4Q) [Chapter 7: Deadlocks](https://hackmd.io/Uu0jDK-rSyKNKq690y146g) * 記憶體管理 [Chapter 8: Main Memory](https://hackmd.io/4KS_yPkBQzGZfHDisPciog) [Chapter 9: Virtual Memory](https://hackmd.io/yirxZFn8Rz2wT56AAR7Sxw) * 儲存裝置 <font color="red">Chapter 10: File-System Interface</font> [Chapter 11: File System Implementation](https://hackmd.io/bFcrlmefQsGp6hZdbI1MHQ) [Chapter 12: Mass-Storage Systems](https://hackmd.io/9Y7Qo0OERda6htK7OOI36Q) [Chapter 13: I/O Systems](https://hackmd.io/VNwXrhJPSo-l_t9tUBhYIg) * 保護和安全 [Chapter 14: Protection](https://hackmd.io/izkd4JwXRwub_ZmhSMTlNw) [Chapter 15: Security](https://hackmd.io/ofyvDidvQf-PxLMMZYhtsg) --- ### 檔案的觀念 * 檔案系統組成 * 一群檔案(資料) * 目錄結構(directory structure) * 檔案(file):邏輯上的儲存單位 * 資料必須放入檔案中,否則無法寫入儲存裝置 * 文字檔案(text file) * 原始檔案(source file) * 可執行檔案(executable file) * 檔案特性 * 名稱(Name) * 識別符號(Identifier):獨一無二的標籤,通常是數字,用來辨識檔案系統內的檔案 * 型態(Type) * 位置(Location) * 大小(Size) * 保護(Protection):讀、寫、執行等權限 * 時間、日期和使用者辨識(Time, date, and user identification ) * 檔案資訊視窗(file info window): ![](https://i.imgur.com/XA7YtZt.png) * 檔案運作 * 建立檔案(Create) * 寫入檔案(Write):必須更新寫入指標(write pointer)到檔案的位置 * 讀取檔案(Read):必須更新讀出指標(read pointer)到檔案的位置 * 目前檔案位置指標(current-file-position pointer):通常一個行程只會讀取或寫入一個檔案,因此讀和寫使用共同的指標,能減省目錄空間 * 重置檔案(Reposition within file):搜尋目錄以找到相關的進入點,也稱為搜尋(seek) * 刪除檔案(Delete) * 縮減檔案(Truncate):將檔案長度重置,並將檔案空間釋放 * 開啟檔案列表(open-file table) * 包含所有已開啟檔案的資訊 * 不須搜尋整個目錄,只需搜尋此表格 * 每一個開啟的檔案包含 * 檔案指標:作為目前檔案位置的指標 * 檔案開啟計數(open count):因為許多行程可開啟同一檔案,當檔案開啟計數為零,系統就可以將該檔從開啟檔案列表上移去 * 檔案的磁碟位置 * 存取權限 * 對多行程存取同一開啟檔案提供鎖 * 共用鎖(shared lock):類似讀取者鎖,可多個行程同時獲得 * 互斥鎖(exclusive lock):類似寫入者鎖,每次只有一個行程能獲得 * 強制(mandatory):作業系統確認上鎖的狀態 * 建議(advisory):取決於軟體開發者,鎖是否獲得與釋放 * 檔案型態(File Types) * 檔名包含檔案型態 * 主檔名 * 副檔名:檔案型態 ![](https://i.imgur.com/SBXiBdJ.jpg) * 檔案結構 * 檔案型態用來指出檔案內部的結構 * 所有作業系統至少必須支援可執行檔的結構 * 檔案可視為一連串的區段(每個區段固定大小) * 檔案可能存在內部斷裂 ### 存取方式(Access Methods) * 循序存取(Sequential Access) * 依照記錄次序一一存取區段 * 可以向前或向後n個紀錄 ![](https://i.imgur.com/UDabDs3.png) * 直接存取(Direct Access) * 檔案由邏輯紀錄(logical record)組成 * 相對性的區段號碼(relative block number):開頭為0,下一個是1,實際上開頭對應的實體記憶體可能是14703,而下一個實體記憶體是3192之類的 * 可直接讀入指定的區段,使用cp代表現在的位置 ![](https://i.imgur.com/zk7mEvP.png) * 其他存取方式 * 索引(index) ![](https://i.imgur.com/nvgdf4T.png) * 若有索引檔案本身太大的問題,則設定索引檔案的索引 * 主索引指向副索引,再指向檔案 ### 目錄和磁碟結構(Disk Structure and Directory Structure) * 磁碟可被分割成多個檔案系統 ![](https://i.imgur.com/gMbMhew.png) * 卷(volume):每個包含一個檔案系統的實體 * 每個檔案系統將系統中的檔案資訊存放在裝置目錄(device directory)或卷表內容(volume table of content) * 目錄概觀 * 目錄可視為把檔名轉換成目錄進入點的符號表 * 目錄操作 * 搜尋 * 建檔 * 刪除 * 列出目錄 * 更改檔名 * 追蹤檔案系統 * 單層目錄(Single-Level Directory) * 最簡單的目錄結構 * 當檔案增加,追蹤變得困難 * 必須使用獨一無二的檔案名稱(不同使用者也是) ![](https://i.imgur.com/R8V30B3.png) * 雙層目錄(Two-Level Directory) * 每個使用者擁有自己的使用者檔案目錄(UFD,user file directory) * 主目錄檔使用使用者的名稱作為索引 * 如果要指定一個檔案 * 路徑名稱(path name) * 例如:使用者A希望使用自己的測試檔,他只需使用test.txt,若使用者A希望使用使用者B的測試檔,他則需使用/userb/test.txt ![](https://i.imgur.com/9OpBagV.png) * 樹狀目錄 * 允許使用者建立自己的子目錄 ![](https://i.imgur.com/Yg0KQOT.png) * 現用目錄(currrent directory):包含使用者目前最感興趣的大部分檔案 * 如果要指定一個檔案 * 以上圖first來說 * 絕對路徑名稱(absolute path name):root/spell/mail/ptr/first * 相對路徑名稱(relative path name):/ptr/first(目前目錄為root/spell/mail) * 非循環圖形目錄(Acyclic-Graph Directories) * 允許共用的子目錄或檔案共享 * 鍊(link):指向其他檔案或目錄的指標 * 不會有循環,但要避免循環的代價高 ![](https://i.imgur.com/x3t8PTT.png) * 一般圖形目錄(General Graph Directory) * 會有循環,可能導致搜尋時無限迴圈(解決:限制目錄被存取的次數) * 廢置空間收集法(garbage collection):判斷資料何時被刪除及磁碟空間可否重新分配 ![](https://i.imgur.com/K9RCO73.png) ### 檔案系統安裝(File System Mounting) * 檔案系統必須先安裝才可以被系統的行程取得 * 安裝點(mount point):系統和連結上此檔案系統的檔案結構中的位置 ![](https://i.imgur.com/f5U5Hw7.png) ![](https://i.imgur.com/G0NLM2I.png) ### 檔案分享(File Sharing) * 多位使用者 * 系統必須對分享製作保護 * 檔案或目錄的 * 擁有者(owner)/使用者(user):可以更改屬性、授予存取權利、最大控制權的使用者 * 群組(group):可以分享檔案的一小組使用者 * 遠端檔案系統 * 遠端檔案分享的方法 * 使用檔案傳輸協定(FTP,File Transfer Protocol):在機器間傳輸 * 分散式的檔案系統(DFS,distributed file system):讓遠端的目錄在本地端能被發現 * 全球資訊網(World Wide Web):網頁瀏覽器用來取得遠端檔案的存取權 * 匿名存取(anonymous access):允許使用者在遠端系統上沒有帳號就可以傳輸 * 客戶-伺服器模型(Client-server) * 伺服器(sever):包含檔案 * 客戶(client):希望存取檔案 * 認證客戶較難,辨識符號(IP等等)可以偽造 * 分散式資訊系統(distributed information system) * 領域名稱系統(DNS,domain name system):提供主機名稱到網路位址的轉換 * 使客戶-伺服器的管理更簡單 * 失效模式 * 因為網路或伺服器的錯誤,遠端檔案系統有許多失效模式 * 製作從失效復原的模式,需維護客戶及伺服器的狀態資訊(state information) * UNIX的網路檔案系統(NFS,network file system)傳送所有必要的資訊來找到檔案,容易復原,但安全性低 * 一致性語意(consistency semantics) * 規定多個使用者同時存取一個共同檔案的語意 * 檔案會議(file session):一個使用者對檔案存取的一連串動作 * UNIX系統 * 一位使用者寫入時,可被其他也開啟該檔案的使用者看見 * Andrew系統(OpenAFS): * 一位使用者寫入時,無法被其他也開啟該檔案的使用者看見 * 所做的改變只能在下一次到會議中看見(其他使用者要重開才看的到改變) * 不變共用檔案(immutable shared file):唯讀,不會改變 ### 保護(Protection) * 保護需要的是帶有管制的存取 * 存取型態(Types of access) * 讀取 * 寫入 * 執行 * 附加 * 刪除 * 列出 * 存取控制 * 存取控制列表(ACL,access-control list):對應使用者與他被允許的存取類型 * 如果每個使用者都要對應,ACL可能會很長,將使用者分為三類 * 擁有者(owner) * 群組(group) * 其他人(iniverse) * UNIX系統中使用九個位元紀錄三類使用者的權限(rwxrwxrwx) * r-讀取 * w-寫入 * x-執行 ![](https://i.imgur.com/HQ98OqM.png) * Windows經由GUI管理存取控制列表 ![](https://i.imgur.com/EacUzs8.png) * 其他保護方法 * 使用密碼 * 除了保護檔案,還要保護目錄 * 例如:刪除或列出目錄中的檔案

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully