aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd/sharefs/main.go
blob: 0e3072a5da86b198049dc738c194074e745abef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// The sharefs FUSE filesystem is a permissionless shared filesystem.
//
// This filesystem is the primary means of file sharing between hakurei
// application containers. It serves the same purpose in Rosa OS as /sdcard
// does in AOSP.
//
// See help message for all available options.
package main

import (
	"log"
	"os"
	"slices"
)

// sharefsName is the prefix used by log.std in the sharefs process.
const sharefsName = "sharefs"

// handleMountArgs returns an alternative, libfuse-compatible args slice for
// args passed by mount -t fuse.sharefs [options] sharefs <mountpoint>.
//
// In this case, args always has a length of 5 with index 0 being what comes
// after "fuse." in the filesystem type, 1 is the uninterpreted string passed
// to mount (sharefsName is used as the magic string to enable this hack),
// 2 is passed through to libfuse as mountpoint, and 3 is always "-o".
func handleMountArgs(args []string) []string {
	if len(args) == 5 && args[1] == sharefsName && args[3] == "-o" {
		return []string{sharefsName, args[2], "-o", args[4]}
	}
	return slices.Clone(args)
}

func main() {
	log.SetFlags(0)
	log.SetPrefix(sharefsName + ": ")

	os.Exit(_main(handleMountArgs(os.Args)...))
}