2023-10-16 09:18:40 +00:00
|
|
|
package vfs
|
2020-09-27 19:23:47 +00:00
|
|
|
|
|
|
|
import (
|
2023-12-21 23:15:39 +00:00
|
|
|
"errors"
|
|
|
|
"io/fs"
|
|
|
|
"path"
|
2021-11-23 12:05:49 +00:00
|
|
|
"time"
|
|
|
|
|
2023-10-08 16:46:03 +00:00
|
|
|
"git.kmsign.ru/royalcat/tstor/src/iio"
|
2020-09-27 19:23:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type File interface {
|
|
|
|
IsDir() bool
|
|
|
|
Size() int64
|
2023-12-21 23:15:39 +00:00
|
|
|
Stat() (fs.FileInfo, error)
|
2020-09-27 19:23:47 +00:00
|
|
|
|
|
|
|
iio.Reader
|
|
|
|
}
|
|
|
|
|
2023-12-21 23:15:39 +00:00
|
|
|
var ErrNotImplemented = errors.New("not implemented")
|
|
|
|
|
2020-09-27 19:23:47 +00:00
|
|
|
type Filesystem interface {
|
|
|
|
// Open opens the named file for reading. If successful, methods on the
|
|
|
|
// returned file can be used for reading; the associated file descriptor has
|
|
|
|
// mode O_RDONLY.
|
|
|
|
Open(filename string) (File, error)
|
|
|
|
|
|
|
|
// ReadDir reads the directory named by dirname and returns a list of
|
|
|
|
// directory entries.
|
2023-12-21 23:15:39 +00:00
|
|
|
ReadDir(path string) ([]fs.DirEntry, error)
|
|
|
|
|
|
|
|
Stat(filename string) (fs.FileInfo, error)
|
2023-12-25 22:11:03 +00:00
|
|
|
Unlink(filename string) error
|
2024-03-20 10:49:19 +00:00
|
|
|
|
|
|
|
fs.DirEntry
|
2020-09-27 19:23:47 +00:00
|
|
|
}
|
2021-11-23 12:05:49 +00:00
|
|
|
|
2023-12-21 23:15:39 +00:00
|
|
|
const defaultMode = fs.FileMode(0555)
|
|
|
|
|
2021-11-23 12:05:49 +00:00
|
|
|
type fileInfo struct {
|
|
|
|
name string
|
|
|
|
size int64
|
|
|
|
isDir bool
|
|
|
|
}
|
|
|
|
|
2023-12-21 23:15:39 +00:00
|
|
|
var _ fs.FileInfo = &fileInfo{}
|
|
|
|
var _ fs.DirEntry = &fileInfo{}
|
|
|
|
|
|
|
|
func newDirInfo(name string) *fileInfo {
|
|
|
|
return &fileInfo{
|
|
|
|
name: path.Base(name),
|
|
|
|
size: 0,
|
|
|
|
isDir: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFileInfo(name string, size int64) *fileInfo {
|
2021-11-23 12:05:49 +00:00
|
|
|
return &fileInfo{
|
2023-12-21 23:15:39 +00:00
|
|
|
name: path.Base(name),
|
2021-11-23 12:05:49 +00:00
|
|
|
size: size,
|
2023-12-21 23:15:39 +00:00
|
|
|
isDir: false,
|
2021-11-23 12:05:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-21 23:15:39 +00:00
|
|
|
func (fi *fileInfo) Info() (fs.FileInfo, error) {
|
|
|
|
return fi, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fi *fileInfo) Type() fs.FileMode {
|
|
|
|
if fi.isDir {
|
|
|
|
return fs.ModeDir
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-11-23 12:05:49 +00:00
|
|
|
func (fi *fileInfo) Name() string {
|
|
|
|
return fi.name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fi *fileInfo) Size() int64 {
|
|
|
|
return fi.size
|
|
|
|
}
|
|
|
|
|
2023-12-21 23:15:39 +00:00
|
|
|
func (fi *fileInfo) Mode() fs.FileMode {
|
2021-11-23 12:05:49 +00:00
|
|
|
if fi.isDir {
|
2023-12-21 23:15:39 +00:00
|
|
|
return defaultMode | fs.ModeDir
|
2021-11-23 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
2023-12-21 23:15:39 +00:00
|
|
|
return defaultMode
|
2021-11-23 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fi *fileInfo) ModTime() time.Time {
|
|
|
|
// TODO fix it
|
2023-12-21 23:15:39 +00:00
|
|
|
return time.Time{}
|
2021-11-23 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fi *fileInfo) IsDir() bool {
|
|
|
|
return fi.isDir
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fi *fileInfo) Sys() interface{} {
|
|
|
|
return nil
|
|
|
|
}
|