feat: Vfs and Ext2 support. Code style/attribute improvements

Added VFS and Ext2 support.
Optimized attributes of methods to improve code highlighting.
Printf attribute, malloc attribute, etc.
This commit is contained in:
2021-10-06 21:45:15 +02:00
parent 073051c99e
commit 03f0ec6f88
24 changed files with 1322 additions and 90 deletions

3
rootfs/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
mnt/*
!mnt
rootfs.img

52
rootfs/mkrootfs.sh Executable file
View File

@@ -0,0 +1,52 @@
#!/bin/bash
IMG_FILE=rootfs.img
IMG_SIZE=100 # MB
function log() {
echo "$*"
}
function yes_or_no() {
while true; do
read -p "$* [y/n]: " yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*)
echo "Aborted"
return 1
;;
esac
done
}
function setup_lb() {
sudo losetup -fP --show ${IMG_FILE}
}
if [ ! -d mnt ]; then
mkdir mnt
fi
if [ -f "${IMG_FILE}" ]; then
log "${IMG_FILE} already exists"
if ! yes_or_no "Continue?"; then
exit 1
fi
fi
# build img
dd if=/dev/zero of=${IMG_FILE} bs=1M count=${IMG_SIZE}
parted -s ${IMG_FILE} mktable msdos
parted -s ${IMG_FILE} mkpart primary ext2 0 100%
LB_DEV="$(setup_lb)"
if [ -z "${LB_DEV}" ]; then
log "Failed to setup loobback"
exit 1
fi
sudo mkfs.ext2 -L rootfs "${LB_DEV}p1"
sudo mount "${LB_DEV}p1" mnt

39
rootfs/mount_rootfs.sh Executable file
View File

@@ -0,0 +1,39 @@
#!/bin/bash
IMG_FILE=rootfs.img
IMG_SIZE=100 # MB
function log() {
echo "$*"
}
function yes_or_no() {
while true; do
read -p "$* [y/n]: " yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*)
echo "Aborted"
return 1
;;
esac
done
}
function setup_lb() {
sudo losetup -fP --show ${IMG_FILE}
}
if [ ! -f "${IMG_FILE}" ]; then
log "${IMG_FILE} doesn't exist"
exit 1
fi
LB_DEV="$(setup_lb)"
if [ -z "${LB_DEV}" ]; then
log "Failed to setup loobback"
exit 1
fi
sudo mount "${LB_DEV}p1" mnt

15
rootfs/umount_rootfsh.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
function log() {
echo "$*"
}
LB_DEV=$(findmnt -n -o SOURCE mnt)
if [ -z "${LB_DEV}" ]; then
log "Not mounted"
exit 1
fi
sudo umount mnt
sudo losetup -d "${LB_DEV%p1}"