1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "init_mount.h"
17
18 #include <errno.h>
19 #include <stdbool.h>
20 #include "fs_manager/fs_manager.h"
21 #include "init_log.h"
22 #include "init_utils.h"
23 #include "securec.h"
24
MountRequriedPartitions(const Fstab * fstab)25 int MountRequriedPartitions(const Fstab *fstab)
26 {
27 INIT_ERROR_CHECK(fstab != NULL, return -1, "fstab is NULL");
28 int rc;
29 INIT_LOGI("Mount required partitions");
30 rc = MountAllWithFstab(fstab, 1);
31 return rc;
32 }
33
LoadRequiredFstab(void)34 Fstab *LoadRequiredFstab(void)
35 {
36 Fstab *fstab = NULL;
37 fstab = LoadFstabFromCommandLine();
38 if (fstab == NULL) {
39 INIT_LOGI("Cannot load fstab from command line, try read from fstab.required");
40 const char *fstabFile = STARTUP_INIT_UT_PATH"/etc/fstab.required";
41 INIT_CHECK(access(fstabFile, F_OK) == 0, fstabFile = "/system/etc/fstab.required");
42 INIT_ERROR_CHECK(access(fstabFile, F_OK) == 0, return NULL, "Failed get fstab.required");
43 fstab = ReadFstabFromFile(fstabFile, false);
44 }
45 if (fstab == NULL) {
46 INIT_LOGI("[startup_failed] LoadRequiredFstab failed %d", FSTAB_MOUNT_FAILED);
47 }
48 return fstab;
49 }
50