aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go41
1 files changed, 29 insertions, 12 deletions
diff --git a/main.go b/main.go
index 3ad0fa4..3619bb7 100644
--- a/main.go
+++ b/main.go
@@ -1,29 +1,46 @@
package main
import (
- "bazil.org/fuse"
- fusefs "bazil.org/fuse/fs"
+ "path/filepath"
+ "flag"
+ "os"
"fmt"
- "github.com/rfjakob/cluefs/lib/cluefs"
"github.com/rfjakob/gocryptfs/frontend"
- "os"
+ "bazil.org/fuse"
+ fusefs "bazil.org/fuse/fs"
+
)
const (
PROGRAM_NAME = "gocryptfs"
USE_OPENSSL = true
+
+ ERREXIT_USAGE = 1
+ ERREXIT_NEWFS = 2
+ ERREXIT_MOUNT = 3
+ ERREXIT_SERVE = 4
+ ERREXIT_MOUNT2 = 5
)
func main() {
// Parse command line arguments
- conf, err := cluefs.ParseArguments()
- if err != nil {
- os.Exit(1)
+ 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)
}
+ cipherdir, _ := filepath.Abs(flag.Arg(0))
+ mountpoint, err := filepath.Abs(flag.Arg(1))
+
// Create the file system object
var key [16]byte
- cfs := frontend.NewFS(key, conf.GetShadowDir(), USE_OPENSSL)
+ cfs, err := frontend.NewFS(key, cipherdir, USE_OPENSSL)
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(ERREXIT_NEWFS)
+ }
// Mount the file system
mountOpts := []fuse.MountOption{
@@ -33,24 +50,24 @@ func main() {
fuse.LocalVolume(),
fuse.MaxReadahead(1024*1024),
}
- conn, err := fuse.Mount(conf.GetMountPoint(), mountOpts...)
+ conn, err := fuse.Mount(mountpoint, mountOpts...)
if err != nil {
fmt.Println(err)
- os.Exit(1)
+ os.Exit(ERREXIT_MOUNT)
}
defer conn.Close()
// Start serving requests
if err = fusefs.Serve(conn, cfs); err != nil {
fmt.Println(err)
- os.Exit(1)
+ os.Exit(ERREXIT_SERVE)
}
// Check for errors when mounting the file system
<-conn.Ready
if err = conn.MountError; err != nil {
fmt.Println(err)
- os.Exit(1)
+ os.Exit(ERREXIT_MOUNT2)
}
// We are done