blob: 79ef16bbc0c5a719d597bf3ee0fae7ff2275d7d4 [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>
23
24#include "fuse_provider.h"
25#include "fuse_sideload.h"
26
27bool start_sdcard_fuse(const char* path) {
28 FuseFileDataProvider file_data_reader(path, 65536);
29
30 if (!file_data_reader) {
31 return false;
32 }
33
34 provider_vtab vtab;
35 vtab.read_block = std::bind(&FuseFileDataProvider::ReadBlockAlignedData, &file_data_reader,
36 std::placeholders::_2, std::placeholders::_3, std::placeholders::_1);
37 vtab.close = [&file_data_reader]() { file_data_reader.Close(); };
38
39 // The installation process expects to find the sdcard unmounted. Unmount it with MNT_DETACH so
40 // that our open file continues to work but new references see it as unmounted.
41 umount2("/sdcard", MNT_DETACH);
42
43 return run_fuse_sideload(vtab, file_data_reader.file_size(),
44 file_data_reader.fuse_block_size()) == 0;
45}