Пример #1
0
func makeFlushFS() (server fuse.Server, err error) {
	// Check the flags.
	if *fFlushesFile == 0 || *fFsyncsFile == 0 {
		err = fmt.Errorf("You must set the flushfs flags.")
		return
	}

	// Set up the files.
	flushes := os.NewFile(uintptr(*fFlushesFile), "(flushes file)")
	fsyncs := os.NewFile(uintptr(*fFsyncsFile), "(fsyncs file)")

	// Set up errors.
	var flushErr error
	var fsyncErr error

	if *fFlushError != 0 {
		flushErr = bazilfuse.Errno(*fFlushError)
	}

	if *fFsyncError != 0 {
		fsyncErr = bazilfuse.Errno(*fFsyncError)
	}

	// Report flushes and fsyncs by writing the contents followed by a newline.
	report := func(f *os.File, outErr error) func(string) error {
		return func(s string) (err error) {
			buf := []byte(s)
			buf = append(buf, '\n')

			_, err = f.Write(buf)
			if err != nil {
				err = fmt.Errorf("Write: %v", err)
				return
			}

			err = outErr
			return
		}
	}

	reportFlush := report(flushes, flushErr)
	reportFsync := report(fsyncs, fsyncErr)

	// Create the file system.
	server, err = flushfs.NewFileSystem(reportFlush, reportFsync)

	return
}
Пример #2
0
func (f *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) {
	if !req.Flags.IsReadOnly() {
		return nil, fuse.Errno(syscall.EACCES)
	}
	resp.Flags |= fuse.OpenKeepCache
	return f, nil
}
Пример #3
0
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package fuse

import (
	"syscall"

	"github.com/jacobsa/bazilfuse"
)

const (
	// Errors corresponding to kernel error numbers. These may be treated
	// specially by fuseops.Op.Respond methods.
	EEXIST    = bazilfuse.EEXIST
	EINVAL    = bazilfuse.Errno(syscall.EINVAL)
	EIO       = bazilfuse.EIO
	ENOENT    = bazilfuse.ENOENT
	ENOSYS    = bazilfuse.ENOSYS
	ENOTDIR   = bazilfuse.Errno(syscall.ENOTDIR)
	ENOTEMPTY = bazilfuse.Errno(syscall.ENOTEMPTY)
)