/usr/share/gocode/src/github.com/mitchellh/go-fs/file_disk.go is in golang-github-mitchellh-go-fs-dev 0.0~git20150611.0.a34c1b9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | package fs
import (
"errors"
"os"
)
// A FileDisk is an implementation of a BlockDevice that uses a
// *os.File as its backing store.
type FileDisk struct {
f *os.File
size int64
}
// NewFileDisk creates a new FileDisk from the given *os.File. The
// file must already be created and set the to the proper size.
func NewFileDisk(f *os.File) (*FileDisk, error) {
fi, err := f.Stat()
if err != nil {
return nil, err
}
if fi.IsDir() {
return nil, errors.New("file is a directory")
}
return &FileDisk{
f: f,
size: fi.Size(),
}, nil
}
func (f *FileDisk) Close() error {
return f.f.Close()
}
func (f *FileDisk) Len() int64 {
return f.size
}
func (f *FileDisk) ReadAt(p []byte, off int64) (int, error) {
return f.f.ReadAt(p, off)
}
func (f *FileDisk) SectorSize() int {
// Hardcoded for now, one day we may want to make this customizable
return 512
}
func (f *FileDisk) WriteAt(p []byte, off int64) (int, error) {
return f.f.WriteAt(p, off)
}
|