@@ -6,7 +6,15 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
66
77check_platform
88
9- VBLK_IMG=build/disk.img
9+ VBLK_IMGS=(
10+     build/disk_ext4.img
11+ )
12+ #  FIXME: mkfs.simplefs is not compilable on macOS, thus running the
13+ #  simplefs cases on Linux runner for now
14+ if  [[ " ${OS_TYPE} " ==  " Linux" ;  then 
15+     VBLK_IMGS+=(build/disk_simplefs.img)
16+ fi 
17+ 
1018which dd >  /dev/null 2>&1  ||  {
1119    echo  " Error: dd not found" 
1220    exit  1
@@ -25,48 +33,77 @@ ACTION=$1
2533
2634case  " $ACTION " in 
2735    setup)
28-         #  Setup a  disk image
29-         dd if=/dev/zero of= ${VBLK_IMG}  bs=4M count=32 
36+         #  Clone simplefs to use mkfs.simplefs util and create simplefs  disk image
37+         git clone https://github.com/sysprog21/simplefs.git -b rel2025.0 --depth 1 
3038
31-         #  Setup a /dev/ block device with ${VBLK_IMG} to test guestOS access to hostOS /dev/ block device
32-         case  " ${OS_TYPE} " in 
33-             Linux)
34-                 mkfs.ext4 ${VBLK_IMG} 
35-                 BLK_DEV=$( losetup -f) 
36-                 losetup ${BLK_DEV}  ${VBLK_IMG} 
37-                 ;;
38-             Darwin)
39-                 $( brew --prefix e2fsprogs) ${VBLK_IMG} 
40-                 BLK_DEV=$( hdiutil attach -nomount ${VBLK_IMG} ) 
41-                 ;;
42-         esac 
39+         #  Setup disk images
40+         for  disk_img  in  " ${VBLK_IMGS[@]} " ;  do 
41+             case  " ${OS_TYPE} " in 
42+                 Linux)
43+                     #  Setup a /dev/ block device with ext4 fs to test guestOS access to hostOS /dev/ block device
44+                     if  [[ " ${disk_img} " =~  ext4 ]];  then 
45+                         dd if=/dev/zero of=${disk_img}  bs=4M count=32
46+                         mkfs.ext4 ${disk_img} 
47+                     else 
48+                         mkdir -p simplefs/build
49+                         make IMAGE=${disk_img}  ${disk_img}  -C simplefs
50+                         mv simplefs/${disk_img}  ./build
51+                     fi 
52+                     BLK_DEV=$( losetup -f) 
53+                     losetup ${BLK_DEV}  ${disk_img} 
54+                     ;;
55+                 Darwin)
56+                     #  Setup a /dev/ block device with ext4 fs to test guestOS access to hostOS /dev/ block device
57+                     dd if=/dev/zero of=${disk_img}  bs=4M count=32
58+                     $( brew --prefix e2fsprogs) ${disk_img} 
59+                     BLK_DEV=$( hdiutil attach -nomount ${disk_img} ) 
60+                     ;;
61+             esac 
4362
44-         #  On Linux, ${VBLK_IMG } will be created by root and owned by root:root.
45-         #  Even if "others" have read and write (rw) permissions, accessing the file for certain operations may
46-         #  still require elevated privileges (e.g., setuid).
47-         #  To simplify this, we change the ownership to a non-root user.
48-         #  Use this with caution—changing ownership to runner:runner is specific to the GitHub CI environment.
49-         chown runner: ${VBLK_IMG } 
50-         #  Add other's rw permission to the disk image and device, so non-superuser can rw them
51-         chmod o+r,o+w ${VBLK_IMG } 
52-         chmod o+r,o+w ${BLK_DEV} 
63+              #  On Linux, ${disk_img } will be created by root and owned by root:root.
64+              #  Even if "others" have read and write (rw) permissions, accessing the file for certain operations may
65+              #  still require elevated privileges (e.g., setuid).
66+              #  To simplify this, we change the ownership to a non-root user.
67+              #  Use this with caution—changing ownership to runner:runner is specific to the GitHub CI environment.
68+              chown runner: ${disk_img } 
69+              #  Add other's rw permission to the disk image and device, so non-superuser can rw them
70+              chmod o+r,o+w ${disk_img } 
71+              chmod o+r,o+w ${BLK_DEV} 
5372
54-         #  Export ${BLK_DEV} to a tmp file. Then, source to "$GITHUB_ENV" in job step.
55-         echo  " export BLK_DEV=${BLK_DEV} " >  " ${TMP_FILE} " 
73+             #  Export ${BLK_DEV} to a tmp file. Then, source to "$GITHUB_ENV" in job step.
74+             if  [[ " ${disk_img} " =~  ext4 ]];  then 
75+                 echo  " export BLK_DEV_EXT4=${BLK_DEV} " >>  " ${TMP_FILE} " 
76+             else 
77+                 echo  " export BLK_DEV_SIMPLEFS=${BLK_DEV} " >>  " ${TMP_FILE} " 
78+             fi 
79+         done 
80+ 
81+         #  Put simplefs.ko into ext4 fs
82+         mkdir -p mnt
83+         mount ${VBLK_IMGS[0]}  mnt
84+         cp build/linux-image/simplefs.ko mnt
85+         umount mnt
86+         rm -rf mnt
5687        ;;
5788    cleanup)
89+         #  Remove simplefs repo
90+         rm -rf simplefs
91+ 
5892        #  Detach the /dev/loopx(Linux) or /dev/diskx(Darwin)
5993        case  " ${OS_TYPE} " in 
6094            Linux)
61-                 losetup -d ${BLK_DEV} 
95+                 losetup -d ${BLK_DEV_EXT4} 
96+                 losetup -d ${BLK_DEV_SIMPLEFS} 
6297                ;;
6398            Darwin)
64-                 hdiutil detach ${BLK_DEV } 
99+                 hdiutil detach ${BLK_DEV_EXT4 } 
65100                ;;
66101        esac 
67102
68-         #  delete disk image
69-         rm -f ${VBLK_IMG} 
103+         #  delete disk images
104+         for  disk_img  in  " ${VBLK_IMGS[@]} " ;  do 
105+             rm -f ${disk_img} 
106+         done 
70107
71108        #  delete tmp file
72109        rm " ${TMP_FILE} " 
0 commit comments