MingJin Lu
    • 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 New
    • Engagement control
    • Make a copy
    • 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 Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # A1 ###### tags: `csc369` ### Simplify diagram ![](https://i.imgur.com/c2fT4W8.png) <img src="https://i.imgur.com/c2fT4W8.png" width=256 height=256/> ### Partition Description > A description of how you are partitioning space. This will include how you are keeping track of free inodes and data blocks, and where those data structures are stored, how you determine which blocks are used for inodes. Note that the size of the disk image and the number of inodes are parameters to mkfs. We will partition the disk into super block, inode bitmap block, data bitmap block, data block (including inode extend block). Free inode and data blocks are stored in inode bitmap block data bitmap block respectively. In the super block, we have 1. num_inode_count: to record the maximum number of inodes in the system. 2. s_nr_inode and s_inode: to determine the starting inode and the starting non reserved inode. Based on this, we can determine which blocks are used for inodes, it will be (s_inode + num_inode_count) * s_inode_size. ### Extend Description Inode total size:128 Meta data:32 bytes mode_t mode; uint32_t links; uint64_t size; struct timespec mtime; Extends 8 bytes 11 extents => 88 bytes extent_block => 4 byte num_extents_used => 4 byte The first 11 extents will be stored directly in the inode after the meta data, if there are more extents required, the inode will allocate a block to store extents, a block can store 512 extents, so it is enough to store the maximum number of extents in a inode. ### Allocate Disk Blocks To allocate disk blocks to a file: 1. Find the last extent of the current inode according to the value of num_extends_used field of this inode. 2. Check whether the last last block of the last available extent is enough to store the extra content. * if yes, directly store the extra content in the last block. * if no, go to step 3. 3. Check whether there is enough available block(s) after the last extent by checking the data bitmap: * if yes, allocate enough new block(s) and go to step 5. * if no, go to step 4. 4. Check if num_extents_used is below 512, if is above 512, abort. Else create a new extent by checking the block bitmap, find enough free block(s) to allocate and add this new a1fs_extent to the extent_block of this inode. 5. Store the extended content in the newly allocated data block(s). 6. Modify data bitmap accordingly. ### Free Disk Blocks 1. Find the last extent of the current inode according to the value of num_extends_used field of this inode. 2. Free blocks from the end to the beginning of a file. If the freed size exceeds the size of the last block(s), then free the last block(s) by the length of the extent. Otherwise, 3. Modify the data bitmap accordingly. ### Algorithm to Seek To seek to a specific byte in a file: 1. Compute the number of the blocks before that specific byte. Assume that byte is $b$, then the blocks before it is $floor(b / A1FS\_BLOCK\_SIZE$). Denote it as $block\_num$. 2. Add the length of each extent, and find the correct extent that byte is in. For example, if the length of each extent is $l_1$, $l_2$,....,$l_n$ and $l_1+l_2+...+l_{i-1} < block\_num$, $l_1+l_2+...+l_{i-1}+l_{i} > block\_num$, then the extent the byte in is $i$. 3. Find that byte in $block\_num - (l_1+l_2+...+l_i)$ block of extent $i$. 4. Seek to block $i$ and byte $block\_num - (l_1+l_2+...+l_i)$. ### How to Allocate and Free Inodes To allocate inodes, we can use s_nr_inode in superblock to find the first non-reserved inode and allocate that space and update s_nr_inode to the first non-reserved inode based on inode_bitmap (may or may not be the one after the allocated inode, we will loop over the inode_bitmap until we counter the first 0). Then we need to update the inode_bitmap. To free inodes, we can simply set the inode location on the inode_bitmap to be 0. ### Allocate and Free Directory Entries within the Data Block To allocate directory entries, 1. Allocate an inode based on the algorithm decribed above 2. Use this inode as a directory 3. Change the mode to directory mode 4. Modify the link of this inode accordingly 5. Find the parent of this inode 6. Modify all the parents' reference To free directory entries, 1. Find current directory inode and see if it is empty, if not empty abort. 2. Else continue 3. Check its reference 4. If it is less than or equal to 2: * Iterate over the extents of this inode, and free all of its data blocks by modifying the data bitmap. * Free this inode by modifying the inode bitmap 5. If it is greater than 2 * Find all the directories that reference this directory, and modify the links of the parent directory and change the address to this inode from the parent directory to -1. * Iterate over the extents of this inode, and free all of its data blocks by modifying the data bitmap. * Free this inode by modifying the inode bitmap ### How to Lookup a File Given a Full Path to It 1. Lookup starts from the inode of root directory. 2. If the path has not been completely traversed, find the inode address of the next level in this path. Then check that inode. 3. Then repeat step 2, until the last level of this full path.

    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