Skip to content

Commit

Permalink
Enable macOS Support
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaharHD committed Dec 11, 2023
1 parent c7e2d65 commit 9df8491
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 11 deletions.
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ override CFLAGS += -I. -Ilittlefs
override CFLAGS += -std=c99 -Wall -pedantic
override CFLAGS += -D_FILE_OFFSET_BITS=64
override CFLAGS += -D_XOPEN_SOURCE=700
# enable multiversion support in littlefs
override CFLAGS += -DLFS_MULTIVERSION
# enable migrate support in littlefs
override CFLAGS += -DLFS_MIGRATE

ifeq ($(OS), Darwin)
override CFLAGS += -I /usr/local/include/osxfuse
override LFLAGS += -L /usr/local/lib
override LFLAGS += -losxfuse
else
override LFLAGS += -lfuse
endif

ifeq ($(OS), FreeBSD)
override CFLAGS += -I /usr/local/include
Expand Down Expand Up @@ -61,4 +64,4 @@ clean:
rm -f $(TARGET)
rm -f $(OBJ)
rm -f $(DEP)
rm -f $(ASM)
rm -f $(ASM)
61 changes: 59 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ This comes with a performance penalty, but works well for the littlefs,
since littlefs is intended for embedded systems.

Currently littlefs-fuse has been tested on the following OSs:
- [Linux](#usage-on-linux)
- [FreeBSD](#usage-on-freebsd)

- [The little filesystem in user-space](#the-little-filesystem-in-user-space)
- [Usage on Linux](#usage-on-linux)
- [Usage on FreeBSD](#usage-on-freebsd)
- [Usage on macOS](#usage-on-macos)
- [Limitations](#limitations)
- [Tips](#tips)

## Usage on Linux

Expand Down Expand Up @@ -132,6 +137,58 @@ umount mount
sudo mdconfig -du 0
```

## Usage on macOS

littlefs-fuse requires [osxfuse](https://osxfuse.github.io/) for macOS:
```bash
brew cask install osxfuse
```

Once you have cloned littlefs-fuse, you can compile the program with make:
``` bash
make
```

This should have built the `lfs` program in the top-level directory.

From here we will need a block device. If you don't have removable storage
handy, you can use a file-backed block device with FreeBSD's loop devices:
``` bash
dd if=/dev/zero of=image bs=1m count=1 # create a 1 MB image
hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount image # attach the loop device
sudo chmod 666 /dev/diskX # make loop device user accessible,
```

littlefs-fuse has two modes of operation, formatting and mounting.

To format a block device, pass the `--format` flag. Note! This will erase any
data on the block device!
``` bash
./lfs --format /dev/diskX
```

To mount, run littlefs-fuse with a block device and a mountpoint:
``` bash
mkdir mount
./lfs /dev/diskX mount
```

Once mounted, the littlefs filesystem will be accessible through the
mountpoint. You can now use the littlefs like you would any other filesystem:
``` bash
cd mount
echo "hello" > hi.txt
ls
cat hi.txt
```

After using littlefs, you can unmount and detach the loop device:
``` bash
cd ..
hdiutil unmount /dev/diskX
hdiutil detach /dev/diskX
```

## Limitations

As an embedded filesystem, littlefs is designed to be simple. By default,
Expand Down
15 changes: 10 additions & 5 deletions lfs_fuse_bd.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@
#include <fcntl.h>
#include <stdint.h>
#include <assert.h>
#if !defined(__FreeBSD__)
#include <sys/ioctl.h>
#include <linux/fs.h>
#elif defined(__FreeBSD__)
#if defined(__FreeBSD__)
#define BLKSSZGET DIOCGSECTORSIZE
#define BLKGETSIZE DIOCGMEDIASIZE
#include <sys/disk.h>
#elif defined(__APPLE__)
#define BLKSSZGET DKIOCGETBLOCKSIZE
#define BLKGETSIZE DKIOCGETBLOCKCOUNT
#include <sys/disk.h>
#elif defined(__LINUX__)
#include <sys/ioctl.h>
#include <linux/fs.h>
#else
#error ("Unsupported OS")
#endif


// Block device wrapper for user-space block devices
int lfs_fuse_bd_create(struct lfs_config *cfg, const char *path) {
int fd = open(path, O_RDWR);
Expand Down

0 comments on commit 9df8491

Please sign in to comment.