All Projects → jserv → Simplefs

jserv / Simplefs

Licence: other
A simple file system for Linux kernel

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Simplefs

camflow-dev
Generates kernel patch for CamFlow Linux Provenance Capture.
Stars: ✭ 19 (-70.77%)
Mutual labels:  kernel, linux-kernel
Spy
👀 Linux kernel mode debugfs keylogger
Stars: ✭ 546 (+740%)
Mutual labels:  kernel, linux-kernel
Sphinx-Beryllium
Sphinx Custom Kernel for Pocophone F1 (Beryllium)
Stars: ✭ 23 (-64.62%)
Mutual labels:  kernel, linux-kernel
linux kernel wiki
linux内核学习资料:200+经典内核文章,100+内核论文,50+内核项目,500+内核面试题,80+内核视频
Stars: ✭ 1,653 (+2443.08%)
Mutual labels:  kernel, linux-kernel
Sutekh
An example rootkit that gives a userland process root permissions
Stars: ✭ 62 (-4.62%)
Mutual labels:  kernel, linux-kernel
Microdot
The Microdot Project guides you to create a fully functional but compact Linux system from scratch
Stars: ✭ 41 (-36.92%)
Mutual labels:  kernel, linux-kernel
Kernel Exploits
Various kernel exploits
Stars: ✭ 397 (+510.77%)
Mutual labels:  kernel, linux-kernel
OpenHarmony
华为鸿蒙分布式操作系统(Huawei OpenHarmony)开发技术交流,鸿蒙技术资料,手册,指南,共建国产操作系统万物互联新生态。
Stars: ✭ 373 (+473.85%)
Mutual labels:  kernel, linux-kernel
Diamorphine
LKM rootkit for Linux Kernels 2.6.x/3.x/4.x/5.x (x86/x86_64 and ARM64)
Stars: ✭ 725 (+1015.38%)
Mutual labels:  kernel, linux-kernel
Paper collection
Academic papers related to fuzzing, binary analysis, and exploit dev, which I want to read or have already read
Stars: ✭ 710 (+992.31%)
Mutual labels:  kernel, linux-kernel
ksmbd
ksmbd kernel server(SMB/CIFS server)
Stars: ✭ 98 (+50.77%)
Mutual labels:  filesystem, linux-kernel
Proton zf6
Proton Kernel for the Asus Zenfone 6 (2019), codename Kirin and also known as I01WD and ZS630KL.
Stars: ✭ 42 (-35.38%)
Mutual labels:  kernel, linux-kernel
execmon
Advanced process execution monitoring utility for linux (procmon like)
Stars: ✭ 77 (+18.46%)
Mutual labels:  kernel, linux-kernel
kernel-ci
Continuous integration for the Linux Kernel - Built within Docker
Stars: ✭ 34 (-47.69%)
Mutual labels:  kernel, linux-kernel
Sphinx-Dipper
Sphinx Custom Kernel for Mi 8 (Dipper)
Stars: ✭ 17 (-73.85%)
Mutual labels:  kernel, linux-kernel
Winfsp
Windows File System Proxy - FUSE for Windows
Stars: ✭ 4,071 (+6163.08%)
Mutual labels:  kernel, filesystem
Linux-Kernel-Exploitation
Linux kernel development & exploitation lab.
Stars: ✭ 130 (+100%)
Mutual labels:  kernel, linux-kernel
SimpleOS
Operating System Coded in Assembly and C
Stars: ✭ 72 (+10.77%)
Mutual labels:  kernel, filesystem
Buildxl
Microsoft Build Accelerator
Stars: ✭ 676 (+940%)
Mutual labels:  kernel, filesystem
Simplefs
A simple, kernel-space, on-disk filesystem from the scratch
Stars: ✭ 831 (+1178.46%)
Mutual labels:  kernel, filesystem

simplefs - a simple file system for Linux

The file system "simplefs" is helpful to understand Linux VFS and file system basics. The Linux VFS supports multiple file systems. The kernel does most of the work while the file system specific tasks are delegated to the individual file systems through the handlers. Instead of calling the functions directly the kernel uses various Operation Tables, which are a collection of handlers for each operation (these are actually structures of function pointers for each handlers/callbacks).

The super block operations are set at the time of mounting. The operation tables for inodes and files are set when the inode is opened. The first step before opening an inode is lookup. The inode of a file is looked up by calling the lookup handler of the parent inode.

Current features

  • Directories: create, remove, list, rename;
  • Regular files: create, remove, read/write (through page cache), rename;
  • Hard/Symbolic links (also symlink or soft link): create, remove, rename;
  • No extended attribute support

Prerequisite

Install linux kernel header in advance.

$ sudo apt install linux-headers-$(uname -r)

Build and Run

You can build the kernel module and tool with make. Generate test image via make test.img, which creates a zeroed file of 50 MiB.

You can then mount this image on a system with the simplefs kernel module installed. Let's test kernel module:

$ sudo insmod simplefs.ko

Correspoinding kernel message:

simplefs: module loaded

Generate test image by creating a zeroed file of 50 MiB. We can then mount this image on a system with the simplefs kernel module installed.

$ mkdir -p test
$ dd if=/dev/zero of=test.img bs=1M count=50
$ ./mkfs.simplefs test.img
$ sudo mount -o loop -t simplefs test.img test

You shall get the following kernel messages:

simplefs: '/dev/loop?' mount success

Here /dev/loop? might be loop1, loop2, loop3, etc.

Perform regular file system operations: (as root)

$ echo "Hello World" > test/hello
$ cat test/hello
$ ls -lR

Remove kernel mount point and module:

$ sudo umount test
$ sudo rmmod simplefs

Design

At present, simplefs only provides straightforward features.

Partition layout

+------------+-------------+-------------------+-------------------+-------------+
| superblock | inode store | inode free bitmap | block free bitmap | data blocks |
+------------+-------------+-------------------+-------------------+-------------+

Each block is 4 KiB large.

Superblock

The superblock is the first block of the partition (block 0). It contains the partition's metadata, such as the number of blocks, number of inodes, number of free inodes/blocks, ...

Inode store

Contains all the inodes of the partition. The maximum number of inodes is equal to the number of blocks of the partition. Each inode contains 72 B of data: standard data such as file size and number of used blocks, as well as a simplefs-specific union field contain dir_block and ei_block. This block contains:

  • for a directory: the list of files in this directory. A directory can contain at most 128 files, and filenames are limited to 28 characters to fit in a single block.
inode
+-----------------------+
| i_mode = IFDIR | 0755 |            block 123
| dir_block = 123   ----|-------->  +-----------+
| i_size = 4 KiB        |         0 | 24 (foo)  |
| i_blocks = 1          |           |-----------|
+-----------------------+         1 | 45 (bar)  |
                                    |-----------|
                                    | ...       |
                                    |-----------|
                                127 | 0         |
                                    +-----------+
  • for a file: the list of extents containing the actual data of this file. Since block IDs are stored as sizeof(struct simplefs_extent) bytes values, at most 341 links fit in a single block, limiting the size of a file to around 10.65 MiB (10912 KiB).
inode                                                
+-----------------------+                           
| i_mode = IFDIR | 0644 |          block 93       
| ei_block = 93     ----|------>  +----------------+      
| i_size = 10 KiB       |       0 | ee_block  = 0  |     
| i_blocks = 25         |         | ee_len    = 8  |      extent 94 
+-----------------------+         | ee_start  = 94 |---> +--------+
                                  |----------------|     |        |     
                                1 | ee_block  = 8  |     +--------+
                                  | ee_len    = 8  |      extent 99
                                  | ee_start  = 99 |---> +--------+ 
                                  |----------------|     |        |
                                2 | ee_block  = 16 |     +--------+
                                  | ee_len    = 8  |      extent 66 
                                  | ee_start  = 66 |---> +--------+
                                  |----------------|     |        |
                                  | ...            |     +--------+
                                  |----------------|  
                              341 | ee_block  = 0  | 
                                  | ee_len    = 0  |
                                  | ee_start  = 0  |
                                  +----------------+

Extent support

The extent covers consecutive blocks, we allocate consecutive disk blocks for it at a single time. It is described by struct simplefs_extent which contains three members:

  • ee_block: first logical block extent covers.
  • ee_len: number of blocks covered by extent.
  • ee_start: first physical block extent covers.
struct simplefs_extent
  +----------------+                           
  | ee_block =  0  |    
  | ee_len   =  200|              extent
  | ee_start =  12 |-----------> +---------+
  +----------------+    block 12 |         |
                                 +---------+
                              13 |         |
                                 +---------+
                                 | ...     |
                                 +---------+
                             211 |         |
                                 +---------+

TODO

  • Bugs
    • Fail to support longer filename
    • Directory will be full if more than 128 files
    • Fail to show . and .. with ls -a command
  • journalling support

License

simplefs is released under the BSD 2 clause license. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].