📂
build a OS
  • Learn OS with me
  • OS Interfaces
    • OS interfaces
    • I/O and File descriptors
    • Process and Memory
    • Pipes
    • File
  • OS Organization
    • OS Organization
    • Challenge yourself
  • Memory Management
    • XV6 Virtual Memory
    • Page Table
      • Part 1: How to translate address
      • Part 2: Create an Address Space
      • Part 3: How Page Table is used
      • Part 4: Page Fault and Swap
      • Part 5: How to operate on page tables
    • xv6 buddy allocator
      • How to display physical memory
    • Memory Management Walk Through
  • Traps and Interrupts
    • Trap Home Page
      • 系统调用的核心原理
    • What is trapframe
    • What is trampoline
    • Traps from kernel space
    • How fork() works
    • How system calls get into/out of the kernel
    • How exec() works
  • Scheduling
    • XV6 CPU Scheduling
    • How unix pipes work?
    • How does wait(), exit(), kill() work?
  • File System
    • Overview and Disk Layout
    • Buffer Cache
    • Design Inode Layer
    • Inode Content
    • Block Allocator
    • Design a log system for crash recovery
    • Directory Layer
    • Path names
    • File Descriptor Layer
    • FS System Calls
    • XV6 VS Real World
    • Make Xv6 File disk management system
    • Write FS simulator in python
    • How Redirect Shell command works
  • Concurrency
    • Spinlock
    • How linux select work
    • Hardware Support Locking
    • Exercise: Implement atomic counter
    • Locking in Xv6
    • Concurrency in Xv6
    • Exercise: Socket Programming with Event loop
  • Labs
    • Lab 1 Xv6 and Unix utilities
    • Lab 2 Shell
    • Lab 3 Buddy Allocator
    • Lab 4 Lazy
    • Lab 5 Copy-on-Write Fork for xv6
    • Lab 6 RISC-V assembly
    • Lab 6 Uthread: switching between threads
    • Lab 6 Alarm
    • Lab 7 Lock
    • Lab 8 File System: Large Files
    • Lab 8 File System: Symbolic links
    • Lab 9 mmap
    • Lab 10 Networking Part 1
    • Lab 10 Networking Part 2
  • Hardware, Device, Assembly
    • RISC-V assembly
    • Assembly: Access and Store information in Memory
    • Start xv6 and the first process
    • Why first user process loads another program?
    • What does kernel.ld do in XV6?
    • XV6 Device Driver
Powered by GitBook
On this page
  • Implement a file system simulator
  • Design a crash recovery system in Python
  • A system call pattern:
  • Flow
  • Recover from log:
  • Design a simple file system
  • Support transaction

Was this helpful?

  1. File System

Write FS simulator in python

Implement a file system simulator

// Disk layout:
// [ boot block | sb block | log | inode blocks | free bit map | data blocks ]

Design a crash recovery system in Python

A system call pattern:

Begin ops Get a buffer Write data to buffer Write actions to log (Log_write) End ops

Flow

Begin ops waits until enough space in log blocks. Mark current ops as outstanding. Log_write adds a new block to the log list. End_op commits if no other outstanding system calls. Call commit. Commit does 4 steps: 1. Write modified blocks from cache to log blocks in disk 2. Write header to disk 3. Install writes from log blocks into home locations 4. Clear log 5. Clear head

Recover from log:

Triggers when the system restarts. 1. Read log head from disk. 2. Install writes into home locations. 3. Clear log. 4. Clear head.

Design a simple file system

The possible operations are:

  • mkdir() - creates a new directory

  • creat() - creates a new (empty) file

  • open(), write(), close() - appends a block to a file

  • link() - creates a hard link to a file

  • unlink() - unlinks a file (removing it if linkcnt==0)

The state of the file system is shown by printing the contents of four different data structures:

inode bitmap - indicates which inodes are allocated
inodes             - table of inodes and their contents
data bitmap   - indicates which data blocks are allocated
data                 - indicates contents of data blocks

Initial plan: 1. Read very simple fs impl. 2. Draw a PoC about how it works in the end 3. Write logging system 4. Design fs data structure 5. Implement my version of fs 6. Use mock for testing

Support transaction

Q: In actual system calls impl, each fs system call has a pattern, used for logging purpose. How do we design our simulator to work the same? A: To make it simple, let’s have batch updates: Begin Mkdir a Open a/test.txt Write a/test.txt ‘A Msg’ Link a/test.txt a/twins.txt Close a/test.txt End

With these sequences, we are making a transaction. All operations will be logged to log system, then perform the disk updates.

PreviousMake Xv6 File disk management systemNextHow Redirect Shell command works

Last updated 5 years ago

Was this helpful?