From 04a801a7c2e22179a51c49fa95e717746729dd4c Mon Sep 17 00:00:00 2001 From: hsule Date: Mon, 19 Jan 2026 16:40:56 +0800 Subject: [PATCH 1/2] Add macOS support for mkfs.simplefs mkfs.simplefs depended on Linux-only headers and ioctl calls, so the rv32emu CI could not run simplefs tests on macOS runners. Add macOS-specific endian helpers and detect block device size via DKIOCGETBLOCKCOUNT/DKIOCGETBLOCKSIZE while keeping the Linux path (BLKGETSIZE64) unchanged. Fixes: #78 Signed-off-by: hsule --- mkfs.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/mkfs.c b/mkfs.c index 59dd967..b50a009 100644 --- a/mkfs.c +++ b/mkfs.c @@ -1,5 +1,19 @@ +#if !defined(__linux__) && !defined(__APPLE__) +#error \ + "Do not manage to build this file unless your platform is Linux or macOS." +#endif + #include -#include +#if defined(__linux__) +#include /* BLKGETSIZE64 */ +#elif defined(__APPLE__) +#include +#include /* DKIOCGETBLOCKCOUNT and DKIOCGETBLOCKSIZE */ +#define htole32(x) OSSwapHostToLittleInt32(x) +#define le32toh(x) OSSwapLittleToHostInt32(x) +#define htole64(x) OSSwapHostToLittleInt64(x) +#define le64toh(x) OSSwapLittleToHostInt64(x) +#endif #include #include #include @@ -278,12 +292,31 @@ int main(int argc, char **argv) /* Get block device size */ if ((stat_buf.st_mode & S_IFMT) == S_IFBLK) { long int blk_size = 0; +#if defined(__linux__) ret = ioctl(fd, BLKGETSIZE64, &blk_size); if (ret != 0) { perror("BLKGETSIZE64:"); ret = EXIT_FAILURE; goto fclose; } +#elif defined(__APPLE__) + uint64_t block_count = 0; + uint32_t sector_size = 0; + + ret = ioctl(fd, DKIOCGETBLOCKCOUNT, &block_count); + if (ret) { + perror("DKIOCGETBLOCKCOUNT"); + ret = EXIT_FAILURE; + goto fclose; + } + ret = ioctl(fd, DKIOCGETBLOCKSIZE, §or_size); + if (ret) { + perror("DKIOCGETBLOCKSIZE"); + ret = EXIT_FAILURE; + goto fclose; + } + blk_size = block_count * sector_size; +#endif stat_buf.st_size = blk_size; } From 1889a19e7b767d77fed4eccbcc1ac6036f8e7a40 Mon Sep 17 00:00:00 2001 From: hsule Date: Tue, 20 Jan 2026 01:25:11 +0800 Subject: [PATCH 2/2] CI: add macOS job to verify mkfs.simplefs Add a CI script to build mkfs.simplefs and format a test image on macOS runners. Signed-off-by: hsule --- .ci/test-mkfs-macos.sh | 21 +++++++++++++++++++++ .github/workflows/main.yaml | 10 ++++++++++ 2 files changed, 31 insertions(+) create mode 100755 .ci/test-mkfs-macos.sh diff --git a/.ci/test-mkfs-macos.sh b/.ci/test-mkfs-macos.sh new file mode 100755 index 0000000..cc90850 --- /dev/null +++ b/.ci/test-mkfs-macos.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -e + +IMAGE=test.img +IMAGESIZE=50 +MKFS=mkfs.simplefs + +function build_mkfs() +{ + make $MKFS +} + +function test_mkfs() +{ + dd if=/dev/zero of=$IMAGE bs=1M count=$IMAGESIZE 2>/dev/null + ./$MKFS $IMAGE +} + +build_mkfs +test_mkfs diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 8edb577..33687c8 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -26,3 +26,13 @@ jobs: .ci/check-newline.sh .ci/check-format.sh shell: bash + + mkfs_macos: + runs-on: macos-latest + steps: + - name: checkout code + uses: actions/checkout@v4 + - name: test mkfs.simplefs on macOS + run: | + .ci/test-mkfs-macos.sh + shell: bash