Add file storage adapter for Fuchsia

This skips calls to flock, since we don't support that syscall,
we should replace this with some other sort of lock if we can.

Change-Id: I19d8317beb96d081e5ecec3ad876ffd7d0164c58
diff --git a/leveldb/storage/file_storage_fuchsia.go b/leveldb/storage/file_storage_fuchsia.go
new file mode 100644
index 0000000..f0f8f0a
--- /dev/null
+++ b/leveldb/storage/file_storage_fuchsia.go
@@ -0,0 +1,76 @@
+// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
+// All rights reserved.
+//
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// +build fuchsia
+
+package storage
+
+import (
+	"os"
+	"syscall"
+)
+
+type unixFileLock struct {
+	f *os.File
+}
+
+func (fl *unixFileLock) release() error {
+	return fl.f.Close()
+}
+
+func newFileLock(path string, readOnly bool) (fl fileLock, err error) {
+	var flag int
+	if readOnly {
+		flag = os.O_RDONLY
+	} else {
+		flag = os.O_RDWR
+	}
+
+	f, err := os.OpenFile(path, flag|os.O_CREATE, 0644)
+
+	if err != nil {
+		return
+	}
+	err = setFileLock(f, readOnly, true)
+	if err != nil {
+		f.Close()
+		return
+	}
+	fl = &unixFileLock{f: f}
+	return
+}
+
+func setFileLock(f *os.File, readOnly, lock bool) error {
+	// TODO(jmatt) replace flock syscall with something else, release the
+	// mechansim is the release() call
+	return nil
+}
+
+func rename(oldpath, newpath string) error {
+	return os.Rename(oldpath, newpath)
+}
+
+func isErrInvalid(err error) bool {
+	if err == os.ErrInvalid {
+		return true
+	}
+	if syserr, ok := err.(*os.SyscallError); ok && syserr.Err == syscall.EINVAL {
+		return true
+	}
+	return false
+}
+
+func syncDir(name string) error {
+	f, err := os.Open(name)
+	if err != nil {
+		return err
+	}
+	defer f.Close()
+	if err := f.Sync(); err != nil && !isErrInvalid(err) {
+		return err
+	}
+	return nil
+}