Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added macOS support via osxfuse #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ override CFLAGS += -D_FILE_OFFSET_BITS=64
override CFLAGS += -D_XOPEN_SOURCE=700
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
57 changes: 55 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

A FUSE wrapper that puts the littlefs in user-space.

**FUSE** - https://github.com/libfuse/libfuse
**littlefs** - https://github.com/geky/littlefs
**FUSE** - https://github.com/libfuse/libfuse
**littlefs** - https://github.com/ARMmbed/littlefs

This project allows you to mount littlefs directly in a host PC.
This allows you to easily debug an embedded system using littlefs on
Expand All @@ -18,6 +18,7 @@ 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)
- [macOS](#usage-on-macos)

## Usage on Linux

Expand Down Expand Up @@ -132,6 +133,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
12 changes: 8 additions & 4 deletions lfs_fuse_bd.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
#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>
#else
#include <sys/ioctl.h>
#include <linux/fs.h>
#endif


Expand Down