blob: 2feb4d24240cc15529f7a6d6a822970448258b5c [file] [log] [blame]
xunchangea2912f2019-03-17 16:45:12 -07001/*
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>
xunchang5e6832a2019-03-15 16:04:32 -070023#include <memory>
xunchangea2912f2019-03-17 16:45:12 -070024
25#include "fuse_provider.h"
26#include "fuse_sideload.h"
27
28bool start_sdcard_fuse(const char* path) {
xunchang5e6832a2019-03-15 16:04:32 -070029 auto file_data_reader = std::make_unique<FuseFileDataProvider>(path, 65536);
xunchangea2912f2019-03-17 16:45:12 -070030
xunchang5e6832a2019-03-15 16:04:32 -070031 if (!file_data_reader->Valid()) {
xunchangea2912f2019-03-17 16:45:12 -070032 return false;
33 }
34
xunchangea2912f2019-03-17 16:45:12 -070035 // 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
xunchang5e6832a2019-03-15 16:04:32 -070039 return run_fuse_sideload(std::move(file_data_reader)) == 0;
xunchangea2912f2019-03-17 16:45:12 -070040}