Home | History | Annotate | Download | only in posix
      1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 #ifndef TENSORFLOW_CORE_PLATFORM_POSIX_POSIX_FILE_SYSTEM_H_
     17 #define TENSORFLOW_CORE_PLATFORM_POSIX_POSIX_FILE_SYSTEM_H_
     18 
     19 #include "tensorflow/core/lib/io/path.h"
     20 #include "tensorflow/core/platform/env.h"
     21 
     22 namespace tensorflow {
     23 
     24 class PosixFileSystem : public FileSystem {
     25  public:
     26   PosixFileSystem() {}
     27 
     28   ~PosixFileSystem() {}
     29 
     30   Status NewRandomAccessFile(
     31       const string& filename,
     32       std::unique_ptr<RandomAccessFile>* result) override;
     33 
     34   Status NewWritableFile(const string& fname,
     35                          std::unique_ptr<WritableFile>* result) override;
     36 
     37   Status NewAppendableFile(const string& fname,
     38                            std::unique_ptr<WritableFile>* result) override;
     39 
     40   Status NewReadOnlyMemoryRegionFromFile(
     41       const string& filename,
     42       std::unique_ptr<ReadOnlyMemoryRegion>* result) override;
     43 
     44   Status FileExists(const string& fname) override;
     45 
     46   Status GetChildren(const string& dir, std::vector<string>* result) override;
     47 
     48   Status Stat(const string& fname, FileStatistics* stats) override;
     49 
     50   Status DeleteFile(const string& fname) override;
     51 
     52   Status CreateDir(const string& name) override;
     53 
     54   Status DeleteDir(const string& name) override;
     55 
     56   Status GetFileSize(const string& fname, uint64* size) override;
     57 
     58   Status RenameFile(const string& src, const string& target) override;
     59 
     60   Status CopyFile(const string& src, const string& target) override;
     61 };
     62 
     63 Status IOError(const string& context, int err_number);
     64 
     65 class LocalPosixFileSystem : public PosixFileSystem {
     66  public:
     67   string TranslateName(const string& name) const override {
     68     StringPiece scheme, host, path;
     69     io::ParseURI(name, &scheme, &host, &path);
     70     return path.ToString();
     71   }
     72 };
     73 
     74 }  // namespace tensorflow
     75 
     76 #endif  // TENSORFLOW_CORE_PLATFORM_POSIX_POSIX_FILE_SYSTEM_H_
     77