@@ -2,26 +2,62 @@ package fs
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"io"
6
7
"os"
7
8
"sync"
8
9
9
- coreiface "github.com/ipfs/interface-go-ipfs-core"
10
+ "github.com/ipfs/go-cid"
11
+ "github.com/ipfs/go-unixfs"
10
12
corepath "github.com/ipfs/interface-go-ipfs-core/path"
11
13
)
12
14
13
15
type (
14
16
ParseFn func (ctx context.Context , name string ) (FsNode , error )
15
- FsType = coreiface.FileType
16
- OFlags = mfs.Flags
17
+ Kind int
18
+ Flag string
19
+ Flags []struct {Flag ;bool }
20
+ )
21
+
22
+ const (
23
+ FRead Flag = "File Read"
24
+ FWrite = "File Write"
25
+ FSync = "File Sync"
26
+ )
27
+
28
+ const (
29
+ UfsFile = Kind (unixfs .TFile )
30
+ UfsDirectory = Kind (unixfs .TDirectory )
31
+ UfsHAMT = Kind (unixfs .THAMTShard )
32
+ UfsSymlink = Kind (unixfs .TSymlink )
33
+ )
34
+
35
+ type FsError interface {
36
+ error
37
+ }
38
+
39
+ var (
40
+ ErrNoLink = FsError (errors .New ("not a symlink" ))
41
+ ErrInvalidHandle = FsError (errors .New ("invalid handle" ))
42
+ ErrNoKey = FsError (errors .New ("key not found" ))
43
+ ErrInvalidPath = FsError (errors .New ("invalid path" ))
44
+ ErrInvalidArg = FsError (errors .New ("invalid argument" ))
45
+ ErrReadOnly = FsError (errors .New ("read only section" ))
46
+ ErrIOType = FsError (errors .New ("node does not impliment requested interface" ))
47
+ ErrUnexpected = FsError (errors .New ("unexpected node type" ))
48
+ ErrNotInitialized = FsError (errors .New ("node metadata is not initialized" ))
49
+ ErrRoot = FsError (errors .New ("root initialization exception" ))
50
+ ErrRecurse = FsError (errors .New ("hit recursion limit" ))
51
+ //
52
+ ErrNoHandler = FsError (errors .New ("no handler registered for this request" ))
17
53
)
18
54
19
55
// Provides standard convention wrappers around an index
20
56
type FileSystem interface {
21
57
Index // a namespace registry that is used to parse `name` strings into `FsNode`s
22
58
23
59
// Create node using respective API for its namespace
24
- Create (ctx context.Context , name string , nodeType FsType ) error
60
+ Create (ctx context.Context , name string , nodeType Kind ) error
25
61
26
62
/* XXX: see PR discussion; we should avoid context.Value if we can; different requests require different arity, which may be a problem
27
63
Request specific parameters are passed via context key's and values, at an API level
@@ -38,7 +74,7 @@ type FileSystem interface {
38
74
// caller provides values necessary to complete the request (if any), inside the context
39
75
Remove (ctx context.Context , name string ) error
40
76
41
- OpenFile (name string , flags flags , perm os.FileMode ) (FsFile , error )
77
+ OpenFile (name string , flags Flags , perm os.FileMode ) (FsFile , error )
42
78
OpenDirectory (path string ) (FsDirectory , error )
43
79
OpenReference (string ) (FsReference , error )
44
80
}
@@ -47,6 +83,8 @@ type Index interface {
47
83
sync.Locker
48
84
// mounts the parser function on the filesystem at "namespace"
49
85
// returns "unmount" closer
86
+
87
+ // rename consider: Bind(Plan9, Spring)
50
88
Mount (namespace string , nodeParser ParseFn ) (unmount io.Closer , err error )
51
89
// NOTE: it may be better to return the equivalent of a "KeepAlive" function rather than a closer
52
90
// if the caller disappears, we'll never release
@@ -77,6 +115,13 @@ type Index interface {
77
115
78
116
type FsNode interface {
79
117
corepath.Path
118
+ Version () uint
119
+ // Cid shall return a cid for the FsNode itself
120
+ // the purpose is to allow for cache coherency between API boundaries
121
+ // simillar to Plan9's `qid` and `version` fields
122
+ // if CID is the same between requests, assume cache safe
123
+ Cid () cid.Cid
124
+
80
125
Metadata (context.Context ) (Metadata , error )
81
126
//RWLocker Maybe?
82
127
@@ -87,7 +132,7 @@ type FsNode interface {
87
132
YieldIo (ctx context.Context ) (io interface {}, err error )
88
133
89
134
Remove (context.Context ) error
90
- Create (context.Context , FsType ) error // should this return an FsNode?
135
+ Create (context.Context , Kind ) error // should this return an FsNode?
91
136
}
92
137
93
138
/* TODO: Move to fuse or delete
@@ -122,19 +167,13 @@ type Metadata interface {
122
167
// Go-uint (4 byte minimum)
123
168
// There's no reason for this to be signed outside of C and POSIX as far as I can tell
124
169
125
-
126
- // Cid shall return a cid for the FsNode itself
127
- // the purpose is to allow for cache coherency between API boundaries
128
- // simillar to Plan9's `version` field
129
- // if anything has changed, it is implied the Cid has changed
130
- Cid () cid.Cid
131
-
132
170
//TODO: rename? IPLD uses "kind" for these names; Kind() FsKind
133
- Type () FsType
171
+ Type () Kind
172
+ Flags () Flags
134
173
135
174
//TODO: consider renaming Cid() -> Version(); Type() -> Format()
136
175
//lines up better with both Plan9 and IPLD
137
-
176
+
138
177
//Cid() cid.Cid // can return nil
139
178
}
140
179
0 commit comments