Notes
main
main
  • Introduction
  • linuxKernel
    • tips
    • make_help
    • old linux
      • compile_linux0.11
      • TestEnvironment
      • load_setup
      • get_hard_data
    • list
    • plist
    • fifo
    • idr
    • xarray
    • rbtree
    • maple_tree
    • syscall
    • bitmap
    • page
    • page_flags
    • page_size
    • page mapcount
    • page refcount
    • folio
    • slub
      • proc_slabinfo
      • slub_theory
      • kmalloc_kfree
      • kmem_cache
      • slab_alloc
      • slab_free
      • proc_meminfo_SReclaimable_SReclaimable
    • vmalloc
    • brk
    • mmap
    • mremap
    • mprotect
    • madvise
    • read
    • write
    • shmem
    • huge_page
    • page_fault
    • rmap
    • lru
    • multi-gen-LRU
    • page_reclaim
    • page_cache
    • page_table
    • rcu
    • kvm
    • aarch64_boot
    • tracing_system
    • cache_coherence_and_memory_consistency
    • cpu_speculates
    • mmap_lock
    • per-vma_lock
    • cgroup
    • symbol
    • campact
    • page_ext
    • mempool
    • kernelstack
    • filesystem
    • io_stack
    • workingset
    • ioremap
    • sched_period
  • linuxDebug
    • openocd_openjtag
    • i2c_tools
    • objdump
    • addr2line
    • gdb_useage
    • debug_linux_kernel_via_gdb
    • debug_linux_module_via_gdb
    • early_boot
    • sequentially_execute
    • dynamic_debug
    • research_linuxKernel_by_patch
    • tracefs
    • ebpf
    • bpftrace
    • perf
    • flame_graph
    • crash
    • ASAN_HWASAN_MTE_check_mem_bug
    • page_owner
    • vmtouch
    • fio
    • benchmark
  • linuxSystem
    • common
      • system_version
      • procfs
      • proc_sys_vm
      • cmd_ps
      • makefile
      • file_descriptor
      • psi
      • ulimit
      • top
      • delay_accounting
    • ubuntu
      • custom_kernel
      • get_cmd_src
      • record_ssh_info
      • log
      • run_custom_script
      • repo
      • cockpit
      • nfs
      • tftp
      • misc
    • fedora
      • system_upgrade
      • custom_kernel
      • lvextend
      • yt-dlp
      • jellyfin
  • linuxDriver
    • i2c_peripherals_driver
    • spi_peripherals_driver
    • gpio_subsystem
    • IRQ_driver
    • blockIO_unblockIO_async
    • linux_own_driver
    • misc_device
    • input_device
    • timer
    • atomic_spinlock_semaphore_mutex
    • lcd
    • touch_screen
    • debugfs
    • v4l2
    • mmap
  • hardware
    • paging_mmu_pt
    • iommu
  • process_thread_scheduler
    • scheduler01
    • scheduler02
    • scheduler03
    • scheduler04
    • scheduler05
    • scheduler06
  • memory_management
    • mm1
    • mm2
    • mm3
    • mm4
    • mm5
  • input_output_filesystem
    • io_fs_01
    • io_fs_02
    • io_fs_03
    • io_fs_04
  • lock_and_lockup_detector
    • general_lock
    • hung_task
    • softLockup_hardLockup
    • crash_experiment
  • MIT_6.S081
    • 6.S081_Operating_System_Engineering
    • Schedule.md
    • Class
      • Overview
      • Administrivia
    • Labs
      • Tools
      • Guidance
      • startup
      • syscall
      • page_table
      • Calling_Convention
      • traps
    • xv6
      • xv6
    • References.md
  • qemu
    • qemu_buildroot
    • qemu_busybox.md
    • Serial.md
    • demo_mini2440
      • 0_compilation_error_summary
      • 1_compilation_steps
      • 2_operation_mode
      • 3_transplant_tools_libraries
      • 4_tools_use
      • reference_website
  • tools
    • getKernelSourceCodeList
    • nat
    • shell
    • translating
    • YouCompleteMe
    • cscope
    • global
    • vscode
    • vim
    • binary
    • markdown
    • draw
    • git
    • tig
    • tmux
    • mail_client
    • download_patchset_from_LKML
    • minicom
    • clash
  • other
    • interview
    • interview_c_base
    • know_dontknow
    • Stop-Ask-Questions-The-Stupid-Ways
    • How-To-Ask-Questions-The-Smart-Way
    • docker
    • buildroot
    • rv32_to_rv64
Powered by GitBook
On this page
  • 一切都是文件:VFS
  • 文件系统的管理
  • 硬链接与软链接
  • icache和dcache
  • 用户空间的文件系统:FUSE

Was this helpful?

  1. input_output_filesystem

io_fs_02

一切都是文件:VFS

应用层的read/write/ioctl/open都是VFS实现的虚函数,所以内核层需要提供struct file_operations,这样这此虚函数才可以生效。

例子1:各种字符设备驱动 需要实现struct file_operations

$ vim drivers/char/misc.c
static const struct file_operations misc_proc_fops = {
        .read    = seq_read,
        ...
};

例子2:Block RAW设备 需要实现struct file_operations

$ dd if=/dev/sda1 ...
$ cat /dev/sda1

$ vim fs/block_dev.c
const struct file_operations def_blk_fops = {
        .read           = new_sync_read,
        .write          = new_sync_write,
        ...
};

例子3:Ext4中的file 需要实现struct file_operations

$ mount /dev/sda1 /mnt
$ ls /mnt
1.txt 2.txt test.out

$ vim fs/ext4/file.c
const struct file_operations ext4_file_operations = {
        .read           = new_sync_read,
        .write          = new_sync_write,
        ...
};

文件系统的管理

文件系统一般由以下五部分组成

  1. Super block, stoing:

    size and location of bitmaps

    number and location of inodes

    number and location of data blocks

    index of root inodes

  2. Bitmap of indoes

  3. Bitmap of data blocks

  4. Inodes table

  5. Data blocks(4kB each)

硬链接与软链接

  • 硬链接, inodes号和原文件indoes是一样

## 注意:创建a.txt 1分钟后,才创建硬链接b.txt
$ ln a.txt b.txt
$ ls -il *.txt
50725039 -rw-rw-r-- 2 vernon vernon 0 11月 10 20:21 a.txt
50725039 -rw-rw-r-- 2 vernon vernon 0 11月 10 20:21 b.txt

b.txt是a.txt的硬链接,所以在inodes table中,a.txt inodes number 等于 b.txt inodes number

  • 软链接,也叫符号链接,inodes号和原文件indoes是不同的

## 注意:创建a.txt 1分钟后,才创建软链接c.txt
$ ln -s a.txt c.txt
$ ls -il *.txt
50725039 -rw-rw-r-- 2 vernon vernon 0 11月 10 20:21 a.txt
50725040 lrwxrwxrwx 1 vernon vernon 5 11月 10 20:22 c.txt -> a.txt

b.txt是a.txt的软链接,所以在Table of inodes中,a.txt inodes number 不等于 b.txt inodes number

icache和dcache

icache, inode cache

dcache, dentry cache

用户空间的文件系统:FUSE

FUSE需要把VFS层的请求传到用户态的fuse app,在用户态处理,然 后再返回到内核态,把结果返回给VFS层;在用户态实现文件系统必 然会引入额外的内核态/用户态切换带来的开销,对性能会产生一定影响

Previousio_fs_01Nextio_fs_03

Last updated 4 years ago

Was this helpful?