libgocryptfs/main.go

75 lines
1.4 KiB
Go
Raw Normal View History

2015-09-03 19:27:07 +02:00
package main
import (
2015-09-06 12:12:14 +02:00
"bazil.org/fuse"
fusefs "bazil.org/fuse/fs"
"flag"
2015-09-05 11:49:05 +02:00
"fmt"
frontend "github.com/rfjakob/gocryptfs/cluefs_frontend"
2015-09-06 12:12:14 +02:00
"os"
"path/filepath"
2015-09-03 19:27:07 +02:00
)
2015-09-05 11:49:05 +02:00
const (
PROGRAM_NAME = "gocryptfs"
2015-09-06 12:12:14 +02:00
USE_OPENSSL = true
2015-09-06 12:12:14 +02:00
ERREXIT_USAGE = 1
ERREXIT_NEWFS = 2
ERREXIT_MOUNT = 3
ERREXIT_SERVE = 4
ERREXIT_MOUNT2 = 5
2015-09-05 11:49:05 +02:00
)
2015-09-03 19:27:07 +02:00
func main() {
// Parse command line arguments
flag.Parse()
if flag.NArg() < 2 {
fmt.Printf("NArg=%d\n", flag.NArg())
fmt.Printf("usage: %s CIPHERDIR MOUNTPOINT\n", PROGRAM_NAME)
os.Exit(ERREXIT_USAGE)
2015-09-03 19:27:07 +02:00
}
cipherdir, _ := filepath.Abs(flag.Arg(0))
mountpoint, err := filepath.Abs(flag.Arg(1))
// Create the file system object
2015-09-03 19:27:07 +02:00
var key [16]byte
cfs, err := frontend.NewFS(key, cipherdir, USE_OPENSSL)
if err != nil {
fmt.Println(err)
os.Exit(ERREXIT_NEWFS)
}
2015-09-03 19:27:07 +02:00
2015-09-05 11:49:05 +02:00
// Mount the file system
mountOpts := []fuse.MountOption{
fuse.FSName(PROGRAM_NAME),
fuse.Subtype(PROGRAM_NAME),
fuse.VolumeName(PROGRAM_NAME),
fuse.LocalVolume(),
2015-09-06 12:12:14 +02:00
fuse.MaxReadahead(1024 * 1024),
2015-09-05 11:49:05 +02:00
}
conn, err := fuse.Mount(mountpoint, mountOpts...)
2015-09-05 11:49:05 +02:00
if err != nil {
fmt.Println(err)
os.Exit(ERREXIT_MOUNT)
2015-09-05 11:49:05 +02:00
}
defer conn.Close()
// Start serving requests
if err = fusefs.Serve(conn, cfs); err != nil {
fmt.Println(err)
os.Exit(ERREXIT_SERVE)
2015-09-05 11:49:05 +02:00
}
// Check for errors when mounting the file system
<-conn.Ready
if err = conn.MountError; err != nil {
fmt.Println(err)
os.Exit(ERREXIT_MOUNT2)
2015-09-03 19:27:07 +02:00
}
// We are done
os.Exit(0)
2015-09-03 19:27:07 +02:00
}