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
|
#ifndef FCP_TENSORFLOW_FILE_DESCRIPTOR_FILESYSTEM_H_
#define FCP_TENSORFLOW_FILE_DESCRIPTOR_FILESYSTEM_H_
#include <memory>
#include <vector>
#include "tensorflow/core/platform/file_system.h"
namespace tensorflow {
namespace fcp {
// Filesystem for file descriptors that reads URIs in the form "fd:///<int>",
// where <int> is a valid file descriptor number. This filesystem can be useful
// to support situations in which a file descriptor is opened in Java and passed
// to the JNI layer.
//
// CAVEATS:
// * This filesystem is non-hierarchical and read-only; many functions simply
// return tensorflow::error::code::UNIMPLEMENTED.
// * To read a file descriptor, this filesystem makes a dup and closes the dup
// when it is done with it. The code that originally created the URI is
// responsible for closing the original file descriptor.
class FileDescriptorFileSystem : public tensorflow::FileSystem {
public:
FileDescriptorFileSystem() = default;
~FileDescriptorFileSystem() override = default;
tensorflow::Status NewRandomAccessFile(
const std::string& filename,
std::unique_ptr<RandomAccessFile>* result) override;
// Clears *results and stores pattern if pattern is a literal match of a valid
// file descriptor. As such, this does not support the full pattern matching
// specification as described by FileSystem::GetMatchingPaths.
tensorflow::Status GetMatchingPaths(
const std::string& pattern, std::vector<std::string>* results) override;
tensorflow::Status Stat(const std::string& fname,
tensorflow::FileStatistics* stats) override;
tensorflow::Status GetFileSize(const std::string& fname,
uint64* size) override;
// Not necessary to read TF checkpoints; these always return UNIMPLEMENTED
tensorflow::Status NewReadOnlyMemoryRegionFromFile(
const std::string& filename,
std::unique_ptr<ReadOnlyMemoryRegion>* result) override;
tensorflow::Status FileExists(const std::string& fname) override;
// The fd filesystem is non-hierarchical; this always returns UNIMPLEMENTED
tensorflow::Status GetChildren(const std::string& dir,
std::vector<string>* r) override;
// The fd filesystem is read-only; these always return UNIMPLEMENTED
tensorflow::Status NewWritableFile(
const std::string& fname, std::unique_ptr<WritableFile>* result) override;
tensorflow::Status NewAppendableFile(
const std::string& fname, std::unique_ptr<WritableFile>* result) override;
tensorflow::Status DeleteFile(const std::string& f) override;
tensorflow::Status CreateDir(const std::string& d) override;
tensorflow::Status DeleteDir(const std::string& d) override;
tensorflow::Status RenameFile(const std::string& s,
const std::string& t) override;
tensorflow::Status CanCreateTempFile(const std::string& fname,
bool* can_create_temp_file) override;
};
} // namespace fcp
} // namespace tensorflow
#endif // FCP_TENSORFLOW_FILE_DESCRIPTOR_FILESYSTEM_H_
|