• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
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 #include "test_partition_opener.h"
18 
19 #include <errno.h>
20 
21 namespace android {
22 namespace fs_mgr {
23 
24 using android::base::unique_fd;
25 
TestPartitionOpener(const std::map<std::string,int> & partition_map,const std::map<std::string,BlockDeviceInfo> & partition_info)26 TestPartitionOpener::TestPartitionOpener(
27         const std::map<std::string, int>& partition_map,
28         const std::map<std::string, BlockDeviceInfo>& partition_info)
29     : partition_map_(partition_map), partition_info_(partition_info) {}
30 
Open(const std::string & partition_name,int flags) const31 unique_fd TestPartitionOpener::Open(const std::string& partition_name, int flags) const {
32     auto iter = partition_map_.find(partition_name);
33     if (iter == partition_map_.end()) {
34         errno = ENOENT;
35         return {};
36     }
37     return unique_fd{dup(iter->second)};
38 }
39 
GetInfo(const std::string & partition_name,BlockDeviceInfo * info) const40 bool TestPartitionOpener::GetInfo(const std::string& partition_name, BlockDeviceInfo* info) const {
41     auto iter = partition_info_.find(partition_name);
42     if (iter == partition_info_.end()) {
43         errno = ENOENT;
44         return false;
45     }
46     *info = iter->second;
47     return true;
48 }
49 
50 }  // namespace fs_mgr
51 }  // namespace android
52