Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .ci/test-mkfs-macos.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 34 additions & 1 deletion mkfs.c
Original file line number Diff line number Diff line change
@@ -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 <fcntl.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider to add this build check:

diff --git a/mkfs.c b/mkfs.c
index 59dd967..c2f5626 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1,3 +1,8 @@
+#if !defined(__linux__) && !defined(__APPLE__)
+#error \
+    "Do not manage to build this file unless your platform is Linux or macOS."
+#endif
+
 #include <fcntl.h>
 #include <linux/fs.h>
 #include <stdint.h>

#include <linux/fs.h>
#if defined(__linux__)
#include <linux/fs.h> /* BLKGETSIZE64 */
#elif defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#include <sys/disk.h> /* 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 <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -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, &sector_size);
if (ret) {
perror("DKIOCGETBLOCKSIZE");
ret = EXIT_FAILURE;
goto fclose;
}
blk_size = block_count * sector_size;
#endif
stat_buf.st_size = blk_size;
}

Expand Down