• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINDSPORE_CCSRC_DISTRIBUTED_PERSISTENT_STORAGE_FILE_IO_UTILS_H_
18 #define MINDSPORE_CCSRC_DISTRIBUTED_PERSISTENT_STORAGE_FILE_IO_UTILS_H_
19 
20 #include <sys/stat.h>
21 #include <vector>
22 #include <string>
23 #include <utility>
24 #include "utils/os.h"
25 #ifdef CreateFile
26 #undef CreateFile
27 #endif
28 
29 namespace mindspore {
30 namespace distributed {
31 namespace storage {
32 class FileIOUtils {
33  public:
34   // Write memory buffer to the file on overwriting mode, create a new file if the file is not exist.
35   static bool Write(const std::string &file_name, const std::vector<std::pair<const void *, size_t>> &inputs);
36 
37   // Read file and load the context into memory buffer, return false if the file is not exist.
38   static bool Read(const std::string &file_name, const std::vector<std::pair<void *, size_t>> &outputs);
39 
40   // Judeg whether a file exists.
41   static bool IsFileOrDirExist(const std::string &file);
42 
43   // Create file.
44   static void CreateFile(const std::string &file_path, mode_t mode = S_IRUSR | S_IWUSR);
45 
46   // Create directory.
47   static void CreateDir(const std::string &dir_path, mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR);
48 
49   // Create directory recursively.
50   static void CreateDirRecursive(const std::string &dir_path, mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR);
51 };
52 }  // namespace storage
53 }  // namespace distributed
54 }  // namespace mindspore
55 
56 #endif  // MINDSPORE_CCSRC_DISTRIBUTED_PERSISTENT_STORAGE_FILE_IO_UTILS_H_
57