xunchang | ea2912f | 2019-03-17 16:45:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 "fuse_sdcard_install.h" |
| 18 | |
| 19 | #include <sys/mount.h> |
| 20 | #include <unistd.h> |
| 21 | |
| 22 | #include <functional> |
xunchang | 5e6832a | 2019-03-15 16:04:32 -0700 | [diff] [blame] | 23 | #include <memory> |
xunchang | ea2912f | 2019-03-17 16:45:12 -0700 | [diff] [blame] | 24 | |
| 25 | #include "fuse_provider.h" |
| 26 | #include "fuse_sideload.h" |
| 27 | |
| 28 | bool start_sdcard_fuse(const char* path) { |
xunchang | 5e6832a | 2019-03-15 16:04:32 -0700 | [diff] [blame] | 29 | auto file_data_reader = std::make_unique<FuseFileDataProvider>(path, 65536); |
xunchang | ea2912f | 2019-03-17 16:45:12 -0700 | [diff] [blame] | 30 | |
xunchang | 5e6832a | 2019-03-15 16:04:32 -0700 | [diff] [blame] | 31 | if (!file_data_reader->Valid()) { |
xunchang | ea2912f | 2019-03-17 16:45:12 -0700 | [diff] [blame] | 32 | return false; |
| 33 | } |
| 34 | |
xunchang | ea2912f | 2019-03-17 16:45:12 -0700 | [diff] [blame] | 35 | // The installation process expects to find the sdcard unmounted. Unmount it with MNT_DETACH so |
| 36 | // that our open file continues to work but new references see it as unmounted. |
| 37 | umount2("/sdcard", MNT_DETACH); |
| 38 | |
xunchang | 5e6832a | 2019-03-15 16:04:32 -0700 | [diff] [blame] | 39 | return run_fuse_sideload(std::move(file_data_reader)) == 0; |
xunchang | ea2912f | 2019-03-17 16:45:12 -0700 | [diff] [blame] | 40 | } |