FANFNA
    • 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # file implementation [TOC] ## File-System Structure ### 基本分類 ![](https://i.imgur.com/YsBGTps.png) :::success 我們會在這邊看到 file系統(**OS跑到 disk 整個過程**) 是如何儲存在 disk ::: :::info - ==I/O Control== consists of ==device drivers==, special software programs ( often written in `assembly` ) which communicate with the devices by reading and writing special codes directly to and from memory addresses corresponding to the controller card's registers. Each controller card ( device ) on a system has a different set of addresses ( registers, a.k.a. ports ) that it listens to, and a unique set of command codes and results codes that it understands.(**machine code to assemble that we can control device**) ::: :::info - The ==basic file system== level works directly with the device drivers in terms of retrieving and storing <font color= "red">raw blocks of data</font>, without any consideration for what is in each block. Depending on the system, blocks may be referred to with a single block number, ( e.g. block # 234234 ), or with head-sector-cylinder combinations. ::: :::info - The ==file organization module== knows about files and their <font color= "red">logical blocks</font>, and how they map to <font color= "red">physical blocks</font> on the disk. In `addition` to translating from **logical to physical** blocks(**ch8**), the file organization module also maintains the list of free blocks, and allocates free blocks to files as needed. ::: :::info - The ==logical file system== deals with all of the meta data associated with a file ( UID, GID, mode, dates, etc ), i.e. everything about the file except the data itself. This level manages the directory structure and the mapping of `file names` to `file control blocks`, FCBs, which contain all of the meta data as well as block number information for finding the data on the disk.(**mapping the name to find data on disk**) ::: ### main fuction - ![](https://i.imgur.com/1ZM15O5.png) :::success 1. I/O transfer 2. data stroage - data 單位: - logical: block(size 會 change不是固定的) - phsycial: sector(512bytes to 4K) ::: :::success 3. data 儲存方式 - Linear list file names with pointer to the data block - simple to program - time-consuming to execute - FAT32(micosoft) and NTFS(UNIX) - Linear list with `hash` data structure. - decreases directory search time - collisions: situations where two file names hash to the same location - fixed size - B-trees - XFS, NTFS, ext4 - Scaling to terabyte/petabyte filesystems ::: ![](https://i.imgur.com/EURoUhv.png) :::success - Layered file system - file system (system call process) - ![](https://i.imgur.com/WROme3Q.png) ::: ### ON Disk Structure **這同時也是一個順序 disk 存儲順序** ![](https://i.imgur.com/O5oFS5v.png) ### IN Memory Structure ![](https://i.imgur.com/9sRZxfX.png) **open file & read file** ![](https://i.imgur.com/j28y3H3.png) ### Virtual File system **user 不用去擔心mounting 等問題(VFS 在上單一編輯就好)** ![](https://i.imgur.com/HorIg99.png) :::info - the VFS in Linux is based upon four key object types: - The **inode** object, representing an individual file(api) - The **file** object, representing an open file. - The **superblock** object, representing a filesystem. - The **dentry** object, representing a directory entry. ::: ## 二、Free Space Management Disk allocation/free space 單位是以 block 為主。 1. Bit Vector:用一組 bits 來代表 blocks 配置與否,一個 bit 對應一個Block。 - ![](https://i.imgur.com/LR1TUHu.png) - 優點:Simple,且易於找到連續可用空間 (即找到連續的 0) - 缺點:bit vector 儲存佔用 memory 空間,所以此法不適用於大型 disk 2. Link List:用 link list 將 free block 串接,形成一個 AV List。 - ![](https://i.imgur.com/TtNdEdp.png) 優點:加入/刪除 block 容易 缺點:效率不佳。因為在找尋可用區塊時,需從頭檢視此串列,I/O time 過長 (檢視一個 block 就須做一次 I/O) 。 3. Combination (組合法,Grouping) :向量加上 link list。取某個可用區塊記錄其它可用區塊之編號。若此區塊不足以容納所有的 free block 編號,則再以其它區塊記錄並用 link 串連。 - 優點:加入/刪除 block 容易,可迅速取得大量可用區塊。 - 缺點:效率不佳,I/O time 過長。 - ![](https://i.imgur.com/nbaocUa.png) 4. Counting:適用於連續區塊較多之情況。在一個 free block 中,記錄其後的連續可用區塊數目 (含自已)。 - ![](https://i.imgur.com/5PxGFkg.png) - 如果連續區塊數目夠多,則 link list 長度可大幅縮短。 ## 三、Allocation Methods **1. 連續性配置 (Contiguous allocation)** - 若檔案大小為 n 個 blocks,則 OS 必須在 disk 上找到 >= n 個連續 free blocks 才能配置。 - 記錄方式 :File Name, Size, Starting Block - 優點: 1. 可支援 sequential access 及 random access 2. seek time 通常較短 (檔案所佔的連續區塊大都會落在同一個 track 上) - 缺點: 1. external fragmentation 2. 檔案大小無法任意增/刪 3. 建檔時須事先宣告大小 **2. 連結配置 (Link allocation)** - 若檔案大小為 n 個區塊,則 OS 必須在 disk 上找到 >= n 個可用區塊即可配置 (不一定要連續)。各配置區塊之間以 link list 做串連。 - 記錄方式 : File Name, Start Block #, End Block # - 優點: 1. 沒有 external fragmentation 2. 檔案可任意增/刪空間建檔時無需事先宣告大小 - 缺點: 1. 不支援 random access :要讀某個檔案的某個區塊時需從頭找起,只支援 sequential access。 2. seek time比 contiguous 配置方式長,非連續性 blocks 可能散落在不同的 track。 3. Reliability 差,若連結斷裂則會資料丟失。 **3. 索引式配置 (Index Allocation)** - 每個檔案皆會多配置一些額外的 blocks 作為 index blocks,內含各配置的 data block 編號。採非連續性配置方式。 - 記錄方式 : File Name, Index Block # - 優點 : 1. 沒有 external fragmentation:linked list 的優點 2. 支援 random access 及 sequential access:contiguous 的優點 3. 可任意增/刪空間 建檔時無需事先宣告大小 - 缺點 : 1. index blocks 佔用額外空間:索引區塊佔用 free block 的空間。 2. index block 太小不夠存放一個檔案的所有 block 編號,太大又形成浪費。 - 解決 index block 不夠大的三個方法: 1. 利用多個 index blocks 儲存,且其之間以 link 方式串連。 - 缺點是資料區塊 IO 隨大小線性成長,無法 random access。 2. Multilevel index - 僅適用大檔案,小檔案不適合 (似 2-level cache table),當存到小檔案時,有可能 index 的大小會大於檔案。 3. Unix i-Node Structure **[用心去感覺] Unix i-Node Structure** 有 15 個Pointer,可逐級累加使用。 - 1~12 號指標 : 儲存 data block # (檔案的Block需求 ≤12 個時適用) - 13 號指標 : 指向 Single-level index - 14 號指標 : 指向 Two-level index - 15 號指標 : 指向 Three-level index ![](https://i.imgur.com/2RMdxFM.png) **[實例1] FAT (File Allocation Table)** 為 link allocation 的變形。將所有配置區塊之間的 link 及 free block 資訊全部記錄在一個Table(FAT)。FAT集中在磁碟某一個固定位置,或可以將它載入主記憶體內,因此雖然在找尋指標時是循序找尋,但速度相對快很多。若 disk 有 n 個 blocks,則 FAT 有 n 個項目 (不論是Free的還是使用中的Block皆需記錄)。 FAT中的項目資訊: 空白 : 表示 free block。 block # : 有 link 指向此 block,即使用中的 block。 概覽: MS-DOS 及 OS/2 採用 Physical directory 的記錄方式 : [file name, FAT Index] block 可完全都存放 data,不像 link Allocation 會有幾個 byte 用來存放連結。 優缺點和 link allocation 差不多。 **[實例2] Extent-Based Systems - ext4** 現代檔案系統使用改良式的 contiguous allocation,例如 ext4。 ext4基本資料: 發布時間:2006年10月10日 (Linux 2.6.28, 2.6.19) 目錄內容:連結串列, hashed B-tree 檔案分配:Extents/Bitmap Extents-based : Extent 指的是一連串的連續實體 block,這種方式可以增加大型檔案的效率並減少分裂檔案。 Extents 大小不用一樣。 Extents 間採用 sequential access ext4 引進了 Extent 檔案儲存方式,以取代 ext2/3 使用的 block mapping 方式。ext4 支援的單一 Extent,在單一block為4KB的系統中最高可達128MB。單一 i-node 中可儲存 4 筆 Extent;超過四筆的 Extent 會以 Htree 方式被索引。

    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