Skip to content

Commit

Permalink
Cleaned up signal handling (winfsp handles SIGINT internally)
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritpact committed Jun 16, 2023
1 parent 159f55c commit 3fb29cf
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 37 deletions.
5 changes: 0 additions & 5 deletions .bash_env

This file was deleted.

4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
iphonefs
iphonefs.exe
iphonebackupfs*
.bash_env
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

.PSEUDO: install push

build=$(shell git describe --tags)

install:
go build --tags winfsp,osusergo,netgo -o iphonefs -ldflags "-w -s" .
mv iphonefs /usr/local/bin
go build --tags winfsp,osusergo,netgo -o iphonebackupfs -ldflags "-w -s" .
mv iphonebackupfs /usr/local/bin

push:
git push "https://github.com/systemmonkey42/iphonefs" "develop:main"
Expand All @@ -12,5 +14,7 @@ push:
git push --tags "https://github.com/systemmonkey42/iphonefs" "develop:develop"

package:
env GOOS="linux" GOARCH="amd64" go build --tags winfsp,osusergo,netgo -o iphonefs -ldflags "-w -s" .
env GOOS="windows" GOARCH="amd64" go build --tags winfsp,osusergo,netgo -o iphonefs.exe -ldflags "-w -s" .
env GOOS="linux" GOARCH="amd64" go build --tags winfsp,osusergo,netgo -o iphonebackupfs -ldflags "-w -s" .
env GOOS="windows" GOARCH="amd64" go build --tags winfsp,osusergo,netgo -o iphonebackupfs.exe -ldflags "-w -s" .
zip -9 iphonebackupfs-windows-$(build)-x86_64.zip iphonebackupfs.exe README.md
tar cvfz iphonebackupfs-linux-$(build)-amd64.tgz iphonebackupfs README.md
50 changes: 36 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# iPhoneFS
# iPhoneBackupFS

A golang project to mount an unencrypted iPhone backup. It is based on the [Go FUSE file system library](https://bazil.org/fuse/) and sqlite3.
A golang project to mount an __unencrypted__ iPhone backup.

This has only been tested on linux
Tested on linux (ubuntu-20.06 and later) and Windows 10 (21H2)

# Building and Installation

Expand All @@ -14,50 +14,72 @@ The following packages (when building on ubuntu) are needed:
- fuse3
- libfuse3-dev

The following are required when building on windows:

- [WinFSP](https://winfsp.dev/rel/) (Make sure to select fuse SDK/Development files when installing)
- [MinGW-w64 Project](https://www.mingw-w64.org/)
- I recommend installing the latest from GitHub release page. (https://github.com/niXman/mingw-builds-binaries/releases)

After installation, you may need to set the following in your environment for `go build` to be able to locate WinFSP


```
set CFLAGS=C:\Program Files (x86)\WinFsp\inc\fuse
```

## Building

Build with the following command:


```
go build -tags <mode> .
go build -tags &lt;mode&gt; .
```

Where __mode__ is one of `bazil` for the `bazil/fuse` library (fast, linux only) or `winfsp` for the windows compatible implementation.

If you have issues building, or simply want a smaller executable, try the following:
Where __mode__ is one of
- `bazil` for the `bazil/fuse` library (fast, linux only) or
- `winfsp` for the windows compatible implementation.


**Note**: New features will only be added to the winfsp implementation, which will eventually become the default when building

If you have issues building (such as when building in a container), or simply want a smaller executable, try the following:

```
go build -tags osusergo,netgo -o iphonefs -ldflags "-w -s" .
go build -tags osusergo,netgo -o iphonebackupfs -ldflags "-w -s" .
```

Move the resulting binary to somewhere accessible

```
sudo mv iphonefs /usr/local/bin
sudo mv iphonebackupfs /usr/local/bin
```

# Usage

```
iphonefs [-A] [-L] [-d <domain>] <backup folder> <mount point>
iphonebackupfs [-A] [-L] [-d <domain>] <backup folder> <mount point>
```

The default mode will present the camera roll at the root of the mount point. The is the quickest and simplest way to connect and extract images and movies.
The default mode will present the camera roll at the root of the mount point. The is the quickest and simplest way to connect and extract images and videos.

To list the available domains, use the "-L" parameters.

To specify a domain, use the `-d <domain>` option. For example, to mount the SMS application and get access to received attachments folder, use the domain `MediaDomain` and browse to the `Library/SMS/Attachments` folder.

To mount the entire backup, use `-A`. The will cause the domain names to become part of the filesystem.
To mount the entire backup, use `-A`. The will cause all domain names to become part of the filesystem.


```
iphonefs /path/to/directory/containing/backup /mnt/path
iphonebackupfs /path/to/directory/containing/backup /mnt/path
```


Note that the backup directory should contain a file called "Metadata.db".

To __dismount__, unmount the destination folder with
By default, pressing <kbd>Ctrl-C</kbd> will attempt to dismount the filesystem. Under linux, you can manually unmount the filesystem to terminate the application with:


```
umount /mnt/path
Expand All @@ -76,7 +98,7 @@ MOUNT|Directory to use as mountpoint
Note: To use `$ROOT` but specify a mount point on the command line, specify the empty string `''` as the backup folder.
For example:
```
iphonefs '' /mnt/data
iphonebackupfs '' /mnt/data
```


Expand Down
4 changes: 3 additions & 1 deletion bazil.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ func mount(mountpoint string) (err error) {

filesys := &FS{}

HandleSignals(mountpoint)
HandleSignals(func() {
unmount(mountpoint)
})

debug("Serving files")
if err := fs.Serve(c, filesys); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module gitx.cf/dleblanc/iphonefs
module gitx.cf/dleblanc/iphonebackupfs

go 1.19

Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ func main() {
}
}

func HandleSignals(mountpoint string) {
func HandleSignals(unmount func()) {
ch := make(chan os.Signal, 1)
go func() {
for range ch {
fmt.Printf("\rCtrl-C detected. Unmounting %s\n", mountpoint)
debug("Unmounting filesystem")
unmount(mountpoint)
debug("Received signal..")
fmt.Fprintf(os.Stderr, "\rCtrl-C detected. Unmounting.\n")
unmount()
signal.Stop(ch)
return
}
Expand Down
13 changes: 7 additions & 6 deletions winfsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ func mount(mountpoint string) (err error) {
fs := NewFS()

host := fuse.NewFileSystemHost(fs)
host.Mount("", []string{mountpoint})

return nil
}
// cgofuse handles Ctrl-C internally and unmounts the filesystem.
// Just absorb it here.
HandleSignals(func() {
})

func unmount(mountpoint string) (err error) {
//err = fuse.Unmount(mountpoint)
return
host.Mount(mountpoint, nil)

return nil
}

func split(path string) []string {
Expand Down

0 comments on commit 3fb29cf

Please sign in to comment.