#ifndef FCP_TENSORFLOW_FILE_DESCRIPTOR_FILESYSTEM_H_ #define FCP_TENSORFLOW_FILE_DESCRIPTOR_FILESYSTEM_H_ #include #include #include "tensorflow/core/platform/file_system.h" namespace tensorflow { namespace fcp { // Filesystem for file descriptors that reads URIs in the form "fd:///", // where 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* 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* 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* 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* r) override; // The fd filesystem is read-only; these always return UNIMPLEMENTED tensorflow::Status NewWritableFile( const std::string& fname, std::unique_ptr* result) override; tensorflow::Status NewAppendableFile( const std::string& fname, std::unique_ptr* 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_