-
Notifications
You must be signed in to change notification settings - Fork 1
/
bltfs.go
132 lines (104 loc) · 2.46 KB
/
bltfs.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package bltfs
import (
"context"
"errors"
"sync"
"hpt.space/bltfs/backend"
"hpt.space/bltfs/ltfs"
)
const (
// TapeBlockMax is the higest addressable tape block.
TapeBlockMax = 0xFFFFFFFFFFFFFFFF
)
var (
// ErrIO is an I/O error.
ErrIO = errors.New("I/O error")
// ErrEOD is an End-Of-Device error.
ErrEOD = errors.New("EOD")
// ErrBOT is an Beginning-Of-Tape error.
ErrBOT = errors.New("BOT")
// ErrNotReady signifies that the device was not ready.
ErrNotReady = errors.New("Device not ready")
)
// Store is a bLTFS store.
type Store struct {
idx *index
rw *synchronizedWriter
mu struct {
sync.Mutex
backend backend.Interface
}
ltfs struct {
curr *ltfs.Index
prev *ltfs.Index
}
sopts storeOptions
}
// Open opens a new bLTFS store using the given backend.
func Open(backend backend.Interface, opts ...StoreOption) (*Store, error) {
return OpenContext(context.Background(), backend, opts...)
}
// OpenContext opens a new bLTFS store using the given backend and
// the given context.
func OpenContext(ctx context.Context, backend backend.Interface, opts ...StoreOption) (*Store, error) {
s := &Store{}
s.mu.backend = backend
s.rw = &synchronizedWriter{}
s.rw.mu.backend = backend
s.sopts.blkSize = 512 * 1024
s.sopts.pol = DefaultRecoveryPolicy
for _, opt := range opts {
opt(&s.sopts)
}
// initialize
if err := backend.Load(); err != nil {
return nil, err
}
// seek to EOD on data partition
if err := s.mu.backend.Locate(1, TapeBlockMax); err != nil {
return nil, err
}
// set active partition
if err := s.mu.backend.SetPartition(1); err != nil {
return nil, err
}
return s, nil
}
// Close closes the bLTFS store.
func (s *Store) Close() error {
return nil
}
/*
// Recover recovers a store.
func (s *Store) Recover() error {
// seek to EOD on data partition
if err := s.mu.backend.Locate(1, TapeBlockMax); err != nil {
return errors.Wrap(err, "failed to seek to EOD")
}
// Recovery
//
// We expect that no LTFS index has been written, so we space backward one
// file mark at a time.
if err := s.mu.backend.SpaceFMB(1); err != nil {
return err
}
for {
buf, err := ioutil.ReadAll(s.mu.backend)
if err != nil {
return err
}
var pblog pb.Log
if err := proto.Unmarshal(buf, &pblog); err != nil {
return err
}
switch pblog.Class {
case pb.Log_INC:
// seek to the previous incremental
if err := s.mu.backend.Locate(1, pblog.Prev); err != nil {
return err
}
case pb.Log_DIFF:
}
}
}
*/