bitcoinleveldb_file/file.rs
1crate::ix!();
2
3pub trait NewSequentialFile {
4
5 /**
6 | Create an object that sequentially reads the
7 | file with the specified name.
8 |
9 | On success, stores a pointer to the new file
10 | in *result and returns OK.
11 |
12 | On failure stores nullptr in *result and
13 | returns non-OK. If the file does
14 |
15 | not exist, returns a non-OK status.
16 | Implementations should return a NotFound
17 | status when the file does not exist.
18 |
19 | The returned file will only be accessed by
20 | one thread at a time.
21 */
22 fn new_sequential_file(&mut self,
23 fname: &String,
24 result: *mut *mut Box<dyn SequentialFile>) -> crate::Status;
25}
26
27pub trait NewRandomAccessFile {
28
29 /**
30 | Create an object supporting random-access
31 | reads from the file with the specified name.
32 | On success, stores a pointer to the new file
33 | in *result and returns OK. On failure stores
34 | nullptr in *result and returns non-OK. If
35 | the file does not exist, returns a non-OK
36 | status. Implementations should return
37 | a NotFound status when the file does not
38 | exist.
39 |
40 | The returned file may be concurrently
41 | accessed by multiple threads.
42 */
43 fn new_random_access_file(&mut self,
44 fname: &String,
45 result: *mut *mut Box<dyn RandomAccessFile>) -> crate::Status;
46}
47
48pub trait NewWritableFile {
49
50 /**
51 | Create an object that writes to a new file
52 | with the specified name. Deletes any
53 | existing file with the same name and creates
54 | a new file. On success, stores a pointer to
55 | the new file in *result and returns OK. On
56 | failure stores nullptr in *result and returns
57 | non-OK.
58 |
59 | The returned file will only be accessed by
60 | one thread at a time.
61 */
62 fn new_writable_file(&mut self,
63 fname: &String,
64 result: *mut *mut Box<dyn WritableFile>) -> crate::Status;
65}
66
67pub trait NewAppendableFile {
68
69 /**
70 | Create an object that either appends to an
71 | existing file, or writes to a new file (if
72 | the file does not exist to begin with). On
73 | success, stores a pointer to the new file in
74 | *result and returns OK. On failure stores
75 | nullptr in *result and returns non-OK.
76 |
77 | The returned file will only be accessed by
78 | one thread at a time.
79 |
80 | May return an IsNotSupportedError error if
81 | this Env does not allow appending to an
82 | existing file. Users of Env (including the
83 | leveldb implementation) must be prepared to
84 | deal with an Env that does not support
85 | appending.
86 */
87 fn new_appendable_file(&mut self,
88 fname: &String,
89 result: *mut *mut Box<dyn WritableFile>) -> crate::Status;
90
91}
92
93pub trait FileExists {
94
95 /**
96 | Returns true iff the named file exists.
97 |
98 */
99 fn file_exists(&mut self, fname: &String) -> bool;
100}
101
102pub trait GetChildren {
103
104 /**
105 | Store in *result the names of the children of
106 | the specified directory.
107 |
108 | The names are relative to "dir".
109 |
110 | Original contents of *results are dropped.
111 */
112 fn get_children(&mut self,
113 dir: &String,
114 result: *mut Vec<String>) -> crate::Status;
115}
116
117pub trait DeleteFile {
118
119 /**
120 | Delete the named file.
121 |
122 */
123 fn delete_file(&mut self, fname: &String) -> crate::Status;
124}
125
126pub trait CreateDir {
127
128 /**
129 | Create the specified directory.
130 |
131 */
132 fn create_dir(&mut self, dirname: &String) -> crate::Status;
133}
134
135pub trait DeleteDir {
136
137 /**
138 | Delete the specified directory.
139 |
140 */
141 fn delete_dir(&mut self, dirname: &String) -> crate::Status;
142}
143
144pub trait GetFileSize {
145
146 /**
147 | Store the size of fname in *file_size.
148 |
149 */
150 fn get_file_size(&mut self,
151 fname: &String,
152 file_size: *mut u64) -> crate::Status;
153}
154
155pub trait RenameFile {
156
157 /**
158 | Rename file src to target.
159 |
160 */
161 fn rename_file(&mut self,
162 src: &String,
163 target: &String) -> crate::Status;
164}
165
166pub trait LockFile {
167
168 /**
169 | Lock the specified file. Used to prevent
170 | concurrent access to the same db by multiple
171 | processes. On failure, stores nullptr in
172 | *lock and returns non-OK.
173 |
174 | On success, stores a pointer to the object
175 | that represents the acquired lock in *lock
176 | and returns OK. The caller should call
177 | UnlockFile(*lock) to release the lock. If
178 | the process exits, the lock will be
179 | automatically released.
180 |
181 | If somebody else already holds the lock,
182 | finishes immediately with a failure. I.e.,
183 | this call does not wait for existing locks to
184 | go away.
185 |
186 | May create the named file if it does not
187 | already exist.
188 */
189 fn lock_file(&mut self,
190 fname: &String,
191 lock: *mut *mut Box<dyn FileLock>) -> crate::Status;
192}
193
194pub trait UnlockFile {
195
196 /**
197 | Release the lock acquired by a previous
198 | successful call to LockFile.
199 |
200 | REQUIRES: lock was returned by a successful
201 | LockFile() call
202 |
203 | REQUIRES: lock has not already been unlocked.
204 */
205 fn unlock_file(&mut self, lock: *mut Box<dyn FileLock>) -> crate::Status;
206}
207
208/**
209 | A file abstraction for reading sequentially
210 | through a file
211 |
212 */
213pub trait SequentialFile:
214SequentialFileRead
215+ SequentialFileSkip
216+ GetName { }
217
218pub trait SequentialFileRead {
219
220 /**
221 | Read up to "n" bytes from the file. "scratch[0..n-1]"
222 | may be written by this routine. Sets
223 | "*result" to the data that was read (including
224 | if fewer than "n" bytes were successfully
225 | read).
226 |
227 | May set "*result" to point at data in
228 | "scratch[0..n-1]", so "scratch[0..n-1]"
229 | must be live when "*result" is used.
230 |
231 | If an error was encountered, returns
232 | a non-OK status.
233 |
234 | REQUIRES: External synchronization
235 |
236 */
237 fn read(&mut self,
238 n: usize,
239 result: *mut Slice,
240 scratch: *mut u8) -> crate::Status;
241}
242
243pub trait SequentialFileSkip {
244
245 /**
246 | Skip "n" bytes from the file. This is
247 | guaranteed to be no slower that reading the
248 | same data, but may be faster.
249 |
250 | If end of file is reached, skipping will stop
251 | at the end of the file, and Skip will return
252 | OK.
253 |
254 | REQUIRES: External synchronization
255 */
256 fn skip(&mut self, n: u64) -> crate::Status;
257}
258
259/**
260 | A file abstraction for randomly reading
261 | the contents of a file.
262 |
263 */
264pub trait RandomAccessFile:
265RandomAccessFileRead
266+ GetName {}
267
268pub trait RandomAccessFileRead {
269
270 /**
271 | Read up to "n" bytes from the file starting
272 | at "offset". "scratch[0..n-1]" may be
273 | written by this routine. Sets "*result" to
274 | the data that was read (including if fewer
275 | than "n" bytes were successfully read). May
276 | set "*result" to point at data in
277 | "scratch[0..n-1]", so "scratch[0..n-1]" must
278 | be live when "*result" is used. If an error
279 | was encountered, returns a non-OK status.
280 |
281 | Safe for concurrent use by multiple threads.
282 */
283 fn read(&self,
284 offset: u64,
285 n: usize,
286 result: *mut Slice,
287 scratch: *mut u8) -> crate::Status;
288}
289
290/**
291 | A file abstraction for sequential writing. The
292 | implementation must provide buffering since
293 | callers may append small fragments at a time to
294 | the file.
295 */
296pub trait WritableFile:
297WritableFileAppend
298+ WritableFileClose
299+ WritableFileFlush
300+ WritableFileSync
301
302/*
303 | Get a name for the file, only for error
304 | reporting
305 |
306 */
307+ GetName {}
308
309pub trait WritableFileAppend {
310 fn append(&mut self, data: &Slice) -> crate::Status;
311}
312
313pub trait WritableFileClose {
314 fn close(&mut self) -> crate::Status;
315}
316
317pub trait WritableFileFlush {
318 fn flush(&mut self) -> crate::Status;
319}
320
321pub trait WritableFileSync {
322 fn sync(&mut self) -> crate::Status;
323}
324
325impl From<Rc<RefCell<dyn WritableFile>>> for Box<dyn WritableFile> {
326
327 /**
328 | Create a writer that will append data to
329 | "*dest".
330 |
331 | "*dest" must be initially empty.
332 |
333 | "*dest" must remain live while this LogWriter is
334 | in use.
335 */
336 fn from(dest: Rc<RefCell<dyn WritableFile>>) -> Self {
337
338 todo!();
339 /*
340 : dest(dest),
341 : block_offset(0),
342 InitTypeCrc(type_crc_);
343 */
344 }
345}
346
347/**
348 | Identifies a locked file.
349 |
350 */
351pub trait FileLock { }
352